From 72d19ec9c141eb471e30c81f4be29228dd9ba939 Mon Sep 17 00:00:00 2001 From: Maxime Bouveron Date: Mon, 29 Apr 2024 18:33:53 +0200 Subject: [PATCH] PR review --- src/api/customObservations.ts | 21 +++++++++++-------- src/api/postObservation.ts | 8 +------ .../[locale]/map/observation/[path]/page.tsx | 4 ++-- ...n-form.tsx => custom-observation-form.tsx} | 4 ++-- src/components/map.tsx | 3 +++ src/components/observation.page.tsx | 17 +++------------ 6 files changed, 23 insertions(+), 34 deletions(-) rename src/components/{new-observation-form.tsx => custom-observation-form.tsx} (98%) diff --git a/src/api/customObservations.ts b/src/api/customObservations.ts index 4496571..6cf9174 100644 --- a/src/api/customObservations.ts +++ b/src/api/customObservations.ts @@ -1,5 +1,7 @@ import { JSONSchema } from 'json-schema-yup-transformer/dist/schema'; +import { Attachement } from './settings'; + export type Observation = { id: number; label: string; @@ -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 { @@ -59,7 +62,7 @@ async function fetchObservation(id: string): Promise { async function fetchObservationDetails( id: string, -): Promise { +): Promise { const res = await fetch( `${process.env.apiHost}/api/portal/fr/${process.env.portal}/custom-contribution-types/${id}/contributions`, { @@ -78,7 +81,7 @@ async function fetchObservationDetails( export async function getObservationDetails( type: string, id: string, -): Promise { +): Promise { const schema = await fetchObservation(type); const detailsList = await fetchObservationDetails(type); const values = detailsList?.find(detail => detail.id === parseInt(id)); diff --git a/src/api/postObservation.ts b/src/api/postObservation.ts index defcc49..0765d18 100644 --- a/src/api/postObservation.ts +++ b/src/api/postObservation.ts @@ -1,9 +1,3 @@ -export type PostObservationProps = { - geom?: string; - properties: string; - files?: string; -}; - async function postObservation( props: { [key: string]: string | Blob }, id: string, @@ -53,7 +47,7 @@ async function postObservation( } export async function handleSubmitCustomObservation( - body: PostObservationProps, + body: { [key: string]: string | Blob }, id: string, formData: FormData, ) { diff --git a/src/app/[locale]/map/observation/[path]/page.tsx b/src/app/[locale]/map/observation/[path]/page.tsx index 9ff6f7f..3d445c3 100644 --- a/src/app/[locale]/map/observation/[path]/page.tsx +++ b/src/app/[locale]/map/observation/[path]/page.tsx @@ -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 = { @@ -60,7 +60,7 @@ export default async function ObservationPage({ params: { path } }: Props) { handleSubmit={handleSubmitObservation} /> ) : ( - - {content?.attachments?.length > 0 && ( + {content.attachments && content.attachments?.length > 0 && (