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 fe4a4fe commit 64ddb33
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
17 changes: 13 additions & 4 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 @@ -19,10 +21,10 @@ export type ObservationDetails = {
};
};

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

async function fetchObservations(): Promise<Observation[]> {
Expand Down Expand Up @@ -59,7 +61,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 +80,14 @@ async function fetchObservationDetails(
export async function getObservationDetails(
type: string,
id: string,
): Promise<any> {
): Promise<{
values: { id: string; value: any; label?: string }[];
id: string;
contributedAt: string;
label?: string;
description?: string;
attachments?: Attachement[];
} | 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

0 comments on commit 64ddb33

Please sign in to comment.