Skip to content

Commit

Permalink
PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
Bo-Duke committed Apr 29, 2024
1 parent ba5d2fb commit 40f9a78
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 34 deletions.
21 changes: 12 additions & 9 deletions src/api/customObservations.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { JSONSchema } from 'json-schema-yup-transformer/dist/schema';

import { Attachement } from './settings';

export type Observation = {
id: number;
label: string;
Expand All @@ -9,20 +11,21 @@ export type Observation = {
};

export type ObservationDetails = {
value: number;
values: { id: string; value: any; label?: string }[];
id: string;
label: string;
description: string;
customContributionTypes: number[];
geometry: {
contributedAt: string;
label?: string;
description?: string;
attachments?: Attachement[];
geometry?: {
coordinates: number[];
};
};

type ObservationList = {
type ObservationListItem = {
id: number;
contributed_at: string;
attachments: any[];
attachments: Attachement[];
};

async function fetchObservations(): Promise<Observation[]> {
Expand Down Expand Up @@ -59,7 +62,7 @@ async function fetchObservation(id: string): Promise<Observation | null> {

async function fetchObservationDetails(
id: string,
): Promise<ObservationList[] | null> {
): Promise<ObservationListItem[] | null> {
const res = await fetch(
`${process.env.apiHost}/api/portal/fr/${process.env.portal}/custom-contribution-types/${id}/contributions`,
{
Expand All @@ -78,7 +81,7 @@ async function fetchObservationDetails(
export async function getObservationDetails(
type: string,
id: string,
): Promise<any> {
): Promise<ObservationDetails | null> {
const schema = await fetchObservation(type);
const detailsList = await fetchObservationDetails(type);
const values = detailsList?.find(detail => detail.id === parseInt(id));
Expand Down
8 changes: 1 addition & 7 deletions src/api/postObservation.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
export type PostObservationProps = {
geom?: string;
properties: string;
files?: string;
};

async function postObservation(
props: { [key: string]: string | Blob },
id: string,
Expand Down Expand Up @@ -53,7 +47,7 @@ async function postObservation(
}

export async function handleSubmitCustomObservation(
body: PostObservationProps,
body: { [key: string]: string | Blob },
id: string,
formData: FormData,
) {
Expand Down
4 changes: 2 additions & 2 deletions src/app/[locale]/map/observation/[path]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { JSONSchema } from 'json-schema-yup-transformer/dist/schema';
import { getTranslations } from 'next-intl/server';

import ButtonClose from '@/components/button-close';
import NewObservationForm from '@/components/new-observation-form';
import CustomObservationForm from '@/components/custom-observation-form';
import ObservationForm from '@/components/observation-form';

type Props = {
Expand Down Expand Up @@ -60,7 +60,7 @@ export default async function ObservationPage({ params: { path } }: Props) {
handleSubmit={handleSubmitObservation}
/>
) : (
<NewObservationForm
<CustomObservationForm
id={observation.id}
schema={jsonSchema}
stations={observation.stations}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { useTranslations } from 'next-intl';
import { Icons, propsForSVGPresentation } from './icons';
import { Button } from './ui/button';

const NewObservationForm = ({
const CustomObservationForm = ({
schema,
id,
stations,
Expand Down Expand Up @@ -194,4 +194,4 @@ const NewObservationForm = ({
);
};

export default NewObservationForm;
export default CustomObservationForm;
3 changes: 3 additions & 0 deletions src/components/map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@ export default function SearchMap() {
const obs = await getObservation(id);
if (obs?.stations?.length === 0) setHasObservationMarker(true);
};

if (pathName.startsWith('/map/observation')) {
const observationType = pathName.match(
/\/map\/observation\/([^?/]+)/,
)?.[1];

if (!observationType) return;

if (DEFAULT_OBSERVATION_TYPES.includes(observationType)) {
setHasObservationMarker(true);
} else {
Expand Down
17 changes: 3 additions & 14 deletions src/components/observation.page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Attachement } from '@/api/settings';
import { ObservationDetails } from '@/api/customObservations';
import { LatLngTuple } from 'leaflet';
import { useTranslations } from 'next-intl';

Expand All @@ -9,18 +9,7 @@ import ButtonClose from './button-close';
import Carousel from './carousel';

type Props = {
content: {
values: any[];
contributedAt: string;
id: string;
label: string;
description: string;
customContributionTypes: number[];
geometry: {
coordinates: number[];
};
attachments: Attachement[];
};
content: ObservationDetails;
};

export default function ObservationDetailsPageUI({ content }: Props) {
Expand All @@ -30,7 +19,7 @@ export default function ObservationDetailsPageUI({ content }: Props) {

return (
<article>
{content?.attachments?.length > 0 && (
{content.attachments && content.attachments?.length > 0 && (
<div className="-m-8 mb-6">
<Carousel
className="w-full"
Expand Down

0 comments on commit 40f9a78

Please sign in to comment.