From 33addbdeec8fe8fd2bc3bb6cead9b69b414d9b48 Mon Sep 17 00:00:00 2001 From: Laurent Paoletti Date: Thu, 30 May 2024 14:52:59 +0200 Subject: [PATCH] =?UTF-8?q?Correctifs=20r=C3=A9visions=20bsdasris?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../revisionRequest/createRevisionRequest.ts | 5 + .../Components/Revision/revisionMapper.ts | 6 +- .../bsdasri/RhfReviewableField.tsx | 10 +- .../request/BsdasriRequestRevision.tsx | 121 ++++++++---------- .../components/packagings/RhfPackagings.tsx | 45 +++++-- ...ending-revision-request-admin-details.html | 5 + 6 files changed, 109 insertions(+), 83 deletions(-) diff --git a/back/src/bsdasris/resolvers/mutations/revisionRequest/createRevisionRequest.ts b/back/src/bsdasris/resolvers/mutations/revisionRequest/createRevisionRequest.ts index b045a09faf..66afe41c99 100644 --- a/back/src/bsdasris/resolvers/mutations/revisionRequest/createRevisionRequest.ts +++ b/back/src/bsdasris/resolvers/mutations/revisionRequest/createRevisionRequest.ts @@ -110,6 +110,11 @@ async function checkIfUserCanRequestRevisionOnBsdasri( "Impossible de créer une révision sur un bordereau de synthèse ou de groupement." ); } + if (bsdasri.groupedInId || bsdasri.synthesizedInId) { + throw new ForbiddenError( + "Impossible de créer une révision sur un bordereau inclus dans une synthèse ou un groupement." + ); + } if (bsdasri.status === BsdasriStatus.INITIAL) { throw new ForbiddenError( "Impossible de créer une révision sur ce bordereau. Vous pouvez le modifier directement, aucune signature bloquante n'a encore été apposée." diff --git a/front/src/Apps/Dashboard/Components/Revision/revisionMapper.ts b/front/src/Apps/Dashboard/Components/Revision/revisionMapper.ts index f856927eb9..e18e764500 100644 --- a/front/src/Apps/Dashboard/Components/Revision/revisionMapper.ts +++ b/front/src/Apps/Dashboard/Components/Revision/revisionMapper.ts @@ -152,7 +152,7 @@ export const mapRevision = ( } ${review?.[bsdName]?.emitter?.pickupSite?.city} ${ review?.[bsdName]?.emitter?.pickupSite?.infos ?? "" }` - : "", + : "Non renseigné", dataNewValue: review?.content?.emitter?.pickupSite ? `${review?.content?.emitter?.pickupSite?.address}, ${ review?.content?.emitter?.pickupSite?.postalCode @@ -166,11 +166,13 @@ export const mapRevision = ( dataOldValue: review?.[bsdName]?.wasteDetails?.code, dataNewValue: review?.content?.wasteDetails?.code }, + { dataName: DataNameEnum.WASTE_CODE, - dataOldValue: review?.bsda?.waste?.code, + dataOldValue: review?.[bsdName]?.waste?.code, dataNewValue: review?.content?.waste?.code }, + { dataName: DataNameEnum.POP, dataOldValue: review?.bsda?.waste?.pop diff --git a/front/src/dashboard/components/RevisionRequestList/bsdasri/RhfReviewableField.tsx b/front/src/dashboard/components/RevisionRequestList/bsdasri/RhfReviewableField.tsx index 191b860edc..d17d25fe4d 100644 --- a/front/src/dashboard/components/RevisionRequestList/bsdasri/RhfReviewableField.tsx +++ b/front/src/dashboard/components/RevisionRequestList/bsdasri/RhfReviewableField.tsx @@ -10,11 +10,13 @@ type Props = { readonly hint?: string; // The variable path: eg; `destination.operation.weight` readonly path: string; + // The value to display + readonly value: string | number | React.ReactNode; // Value coming from revised bsd, allowing reset when component is closed readonly defaultValue: any; // Optional value to initialize children field value, useful for booleans readonly initialValue?: any; - readonly value: string | number | React.ReactNode; + // is the field disabled readonly disabled?: boolean; @@ -24,7 +26,6 @@ type Props = { const LabelContent = ({ labelText, suffix, - value }: { labelText: string; @@ -46,11 +47,11 @@ const LabelContent = ({ export function RhfReviewableField({ title, suffix, - defaultValue, value, + defaultValue, + initialValue, path, hint, - initialValue, children, disabled = false @@ -61,7 +62,6 @@ export function RhfReviewableField({ function handleIsEditingChange() { if (isEditing) { // When toggling visibility to off, set children value to pre-existing value - setValue(path, defaultValue); } else { // When toggling visibility to on, set children value to optional initialValue (to tell apart empty strings from boolean) diff --git a/front/src/dashboard/components/RevisionRequestList/bsdasri/request/BsdasriRequestRevision.tsx b/front/src/dashboard/components/RevisionRequestList/bsdasri/request/BsdasriRequestRevision.tsx index cb7b18ce96..29cda5b8c2 100644 --- a/front/src/dashboard/components/RevisionRequestList/bsdasri/request/BsdasriRequestRevision.tsx +++ b/front/src/dashboard/components/RevisionRequestList/bsdasri/request/BsdasriRequestRevision.tsx @@ -38,26 +38,42 @@ type Props = { readonly bsdasri: Bsdasri; }; -const bsdasriPackagingSchema = z.object({ - type: z.enum( - [ - "BOITE_CARTON", - "FUT", - "BOITE_PERFORANTS", - "GRAND_EMBALLAGE", - "GRV", - "AUTRE" - ], - { - required_error: "Ce champ est requis", - invalid_type_error: "Ce champ est requis" +const bsdasriPackagingSchema = z + .object({ + type: z.enum( + [ + "BOITE_CARTON", + "FUT", + "BOITE_PERFORANTS", + "GRAND_EMBALLAGE", + "GRV", + "AUTRE" + ], + { + required_error: "Ce champ est requis", + invalid_type_error: "Ce champ est requis" + } + ), + other: z.string(), + volume: z.coerce + .number() + .positive("Ce champ est requis est doit être supérieur à 0"), + + quantity: z.coerce + .number() + .positive("Ce champ est requis est doit être supérieur à 0") + }) + .superRefine((values, context) => { + if (values.type === "AUTRE" && !values.other) { + context.addIssue({ + code: z.ZodIssueCode.custom, + + message: "Veuillez préciser le conditionnement", + + path: ["other"] + }); } - ), - other: z.string(), - volume: z.coerce.number().positive().nullish(), - - quantity: z.coerce.number().positive() -}); + }); const getSchema = () => z.object({ @@ -87,7 +103,9 @@ const getSchema = () => .nullish(), waste: z.object({ code: z.string().nullish() }), isCanceled: z.boolean().nullish(), - comment: z.string().min(3) + comment: z + .string() + .min(3, "Le commentaire doit faire au moins 3 caractères") }); const revisionRules = { @@ -130,28 +148,6 @@ export function BsdasriRequestRevision({ bsdasri }: Props) { MutationCreateBsdasriRevisionRequestArgs >(CREATE_BSDASRI_REVISION_REQUEST); - // const defaultValues = { - // emitter: { - // pickupSite: { - // name: "", - // address: "", - // city: "", - // postalCode: "", - // infos: "" - // } - // }, - // destination: { - // reception: { packagings: [] }, - // operation: { - // weight: null, - // code: null, - // mode: null - // } - // }, - // waste: { code: null }, - // isCanceled: false - // }; - const initialReview = { emitter: { pickupSite: { @@ -236,13 +232,17 @@ export function BsdasriRequestRevision({ bsdasri }: Props) { bsdasri?.destination?.reception?.packagings || [] ); - const pickuSiteSummary = [ - bsdasri.emitter?.pickupSite?.address, - bsdasri.emitter?.pickupSite?.postalCode, - bsdasri.emitter?.pickupSite?.city - ] - .filter(Boolean) - .join(" "); + const pickuSiteSummary = + [ + bsdasri.emitter?.pickupSite?.address, + bsdasri.emitter?.pickupSite?.postalCode, + bsdasri.emitter?.pickupSite?.city + ] + .filter(Boolean) + .join(" ") || "Non renseigné"; + + const status = bsdasri["bsdasriStatus"]; + return (

@@ -260,10 +260,7 @@ export function BsdasriRequestRevision({ bsdasri }: Props) { path="emitter.pickupSite" value={pickuSiteSummary} defaultValue={initialReview?.emitter?.pickupSite} - disabled={isDisabled( - "emitter.pickupSite", - bsdasri["bsdasriStatus"] - )} + disabled={isDisabled("emitter.pickupSite", status)} > @@ -318,7 +313,7 @@ export function BsdasriRequestRevision({ bsdasri }: Props) { value={bsdasri?.waste?.code} defaultValue={initialReview?.waste?.code} initialValue={null} - disabled={isDisabled("waste.code", bsdasri["bsdasriStatus"])} + disabled={isDisabled("waste.code", status)} >

@@ -43,8 +60,6 @@ const PaohPackaging = ({ idx, remove, disabled }) => { state={typeError && "error"} stateRelatedMessage={(typeError?.message as string) ?? ""} > - - {( Object.entries(PACKAGINGS_NAMES) as Array< [keyof typeof PACKAGINGS_NAMES, string] @@ -59,6 +74,12 @@ const PaohPackaging = ({ idx, remove, disabled }) => {
{ + />
@@ -95,14 +118,16 @@ const PaohPackaging = ({ idx, remove, disabled }) => { }; export const BsdasriPackagings = ({ disabled = false }) => { + const { control } = useFormContext(); // retrieve control for initial values const { fields, append, remove } = useFieldArray({ + control, name: path }); return (
{fields.map((packaging, index) => ( - ➡️ Modifier certains champs du BSDA grâce à la révision +
+ ➡️ Modifier certains champs du DASRI grâce à la révision