Skip to content

Commit

Permalink
wip: signalement form
Browse files Browse the repository at this point in the history
  • Loading branch information
MaGOs92 committed Oct 25, 2024
1 parent 6e9e975 commit e26a723
Show file tree
Hide file tree
Showing 14 changed files with 431 additions and 537 deletions.
4 changes: 2 additions & 2 deletions components/bal/address-preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const getAddressPreview = (numero, suffixe, toponyme, voie, commune) => {
interface AddressPreviewProps {
numero: string | number;
suffixe?: string;
selectedNomToponyme: string;
voie: string;
selectedNomToponyme?: string;
voie?: string;
commune: CommuneType;
}

Expand Down
6 changes: 0 additions & 6 deletions components/certification-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,12 @@ function CertificationButton({
position: sticky;
width: 100%;
bottom: -12px;
// bottom: 0;
display: flex;
align-items: center;
justify-content: center;
flex-wrap: wrap;
padding: 10px 0;
background-color: #e6e8f0;
// background-color: white;
// border-radius: 8px;
// border: 1px solid #c1c4d6;
}
.certification-button-wrapper > div {
Expand Down
55 changes: 33 additions & 22 deletions components/signalement/numero/signalement-create-numero.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { Button, Pane } from "evergreen-ui";
import React from "react";
import React, { useContext } from "react";
import NumeroEditor from "../../bal/numero-editor";
import { CommuneType } from "@/types/commune";
import { Numero } from "@/lib/openapi";
import { Numero, NumerosService, VoiesService } from "@/lib/openapi";
import { Signalement } from "@/lib/openapi-signalement";
import BalDataContext from "@/contexts/bal-data";
import MapContext from "@/contexts/map";
import LayoutContext from "@/contexts/layout";

interface SignalementCreateNumeroProps {
signalement: Signalement;
initialVoieId: string;
handleSubmit: () => Promise<void>;
handleSubmit: (status: Signalement.status) => Promise<void>;
handleClose: () => void;
commune: CommuneType;
}
Expand All @@ -20,25 +23,33 @@ function SignalementCreateNumero({
handleClose,
commune,
}: SignalementCreateNumeroProps) {
return (
<Pane position="relative" height="100%">
<NumeroEditor
hasPreview
initialValue={signalement.changesRequested as unknown as Numero}
initialVoieId={initialVoieId}
commune={commune}
closeForm={handleClose}
onSubmitted={handleSubmit}
certificationBtnProps={{
children: (
<Button type="button" intent="danger" onClick={handleSubmit}>
Ignorer
</Button>
),
}}
/>
</Pane>
);
const { reloadNumeros, reloadParcelles, refreshBALSync } =
useContext(BalDataContext);
const { reloadTiles } = useContext(MapContext);
const { toaster } = useContext(LayoutContext);

const handleCreate = async (idNumero) => {
const createNumero = toaster(
async () => {
await VoiesService.createNumero(initialVoieId, {
numero: idNumero,
suffixe: "",
positions: [],
parcelles: [],
});
await reloadNumeros();
await reloadParcelles();
reloadTiles();
refreshBALSync();
},
"Le numéro a bien été créé",
"Le numéro n’a pas pu être créé"
);

await createNumero();
};

return <Pane position="relative" height="100%"></Pane>;
}

export default SignalementCreateNumero;
34 changes: 5 additions & 29 deletions components/signalement/numero/signalement-delete-numero.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Button, Pane } from "evergreen-ui";
import { Pane } from "evergreen-ui";
import React, { useContext } from "react";
import NumeroEditor from "../../bal/numero-editor";
import { CommuneType } from "@/types/commune";
import BalDataContext from "@/contexts/bal-data";
import MapContext from "@/contexts/map";
import { Numero, NumerosService, Voie } from "@/lib/openapi";
import LayoutContext from "@/contexts/layout";
import { Signalement } from "@/lib/openapi-signalement";

interface SignalementDeleteNumeroProps {
existingLocation: Numero & { voie: Voie };
handleSubmit: () => Promise<void>;
handleSubmit: (status: Signalement.status) => Promise<void>;
handleClose: () => void;
commune: CommuneType;
}
Expand Down Expand Up @@ -37,35 +37,11 @@ function SignalementDeleteNumero({
"Le numéro a bien été archivé",
"Le numéro n’a pas pu être archivé"
);

await softDeleteNumero();
await handleSubmit();
};

return (
<Pane position="relative" height="100%">
<NumeroEditor
hasPreview
initialValue={existingLocation}
initialVoieId={existingLocation.voie?.id}
commune={commune}
closeForm={handleClose}
onSubmitted={handleSubmit}
certificationBtnProps={{
onConfirm: undefined,
children: (
<Button
type="button"
appearance="primary"
intent="danger"
onClick={() => handleRemove(existingLocation.id)}
>
Supprimer
</Button>
),
}}
/>
</Pane>
);
return <Pane position="relative" height="100%"></Pane>;
}

export default SignalementDeleteNumero;
59 changes: 59 additions & 0 deletions components/signalement/signalement-form-existing-location.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { Pane, Text } from "evergreen-ui";
import React from "react";
import { Numero, Toponyme, Voie } from "@/lib/openapi";
import AddressPreview from "../bal/address-preview";
import { CommuneType } from "@/types/commune";

interface SignalementFormExistingLocationProps {
existingLocation: Voie | Toponyme | Numero;
commune: CommuneType;
}

function SignalementFormExistingLocation({
existingLocation,
commune,
}: SignalementFormExistingLocationProps) {
if ((existingLocation as Numero).numero) {
const {
numero: existingNumero,
suffixe: existingSuffixe,
toponyme: { nom: existingNomToponyme },
voie: { nom: existingNomVoie },
} = existingLocation as Numero;
return (
<AddressPreview
numero={existingNumero}
suffixe={existingSuffixe}
selectedNomToponyme={existingNomToponyme}
voie={existingNomVoie}
commune={commune}
/>
);
} else if ((existingLocation as Toponyme | Voie).nom) {
const { nom: existingNom } = existingLocation as Toponyme | Voie;
const address = `${existingNom} - ${commune.nom} (${commune.code})`;
return (
<Pane
position="sticky"
top={-12}
marginLeft={-12}
marginRight={-12}
transition="left 0.3s"
boxSizing="border-box"
zIndex={3}
background="blue300"
paddingY={8}
paddingX={12}
marginTop={-24}
>
<Text fontSize={address.length > 110 ? "12px" : "13px"} color="white">
{address}
</Text>
</Pane>
);
}

return null;
}

export default SignalementFormExistingLocation;
Loading

0 comments on commit e26a723

Please sign in to comment.