Skip to content

Commit

Permalink
[TRA-15377] Fixes VHU actors (#3829)
Browse files Browse the repository at this point in the history
  • Loading branch information
kornifex authored Dec 16, 2024
1 parent ee02b33 commit 7081472
Show file tree
Hide file tree
Showing 13 changed files with 239 additions and 103 deletions.
3 changes: 3 additions & 0 deletions front/src/Apps/Dashboard/Creation/FormStepsContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const FormStepsContent = ({
element.scroll({ top: 0 });
}
};

const onSubmit = (data, e) => {
const draft = e.nativeEvent.submitter.id === "id_save_draft";
const { id, ...input } = data;
Expand All @@ -72,9 +73,11 @@ const FormStepsContent = ({
scrollToTop();
});
};

const onErrors = () => {
scrollToTop();
};

const onTabChange = tabId => {
setSelectedTabId(tabId);
scrollToTop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export function Destination({ errors }) {

<CompanyContactInfo
fieldName={`${actor}.company`}
name={actor}
errorObject={formState.errors?.destination?.["company"]}
disabled={sealedFields.includes(`${actor}.company.siret`)}
key={orgId}
/>
Expand Down
2 changes: 1 addition & 1 deletion front/src/Apps/Dashboard/Creation/bspaoh/steps/Emitter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export function Emitter({ errors }) {

<CompanyContactInfo
fieldName={`${actor}.company`}
name={actor}
errorObject={formState.errors?.emitter?.["company"]}
disabled={sealedFields.includes(`emitter.company.siret`)}
key={orgId}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export function Transporter({ errors }) {
)}
<CompanyContactInfo
fieldName={`${actor}.company`}
name={actor}
errorObject={formState.errors?.transporter?.["company"]}
disabled={sealedFields.includes(`transporter.company.siret`)}
key={orgId}
/>
Expand Down
8 changes: 7 additions & 1 deletion front/src/Apps/Dashboard/Creation/bsvhu/BsvhuFormSteps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ import {
import OtherActors from "./steps/OtherActors";

const vhuToInput = (vhu: BsvhuInput): BsvhuInput => {
return omitDeep(vhu, ["isDraft", "ecoOrganisme.hasEcoOrganisme"]);
return omitDeep(vhu, [
"isDraft",
"ecoOrganisme.hasEcoOrganisme",
"hasTrader",
"hasBroker",
"hasIntermediaries"
]);
};
interface Props {
bsdId?: string;
Expand Down
165 changes: 119 additions & 46 deletions front/src/Apps/Dashboard/Creation/bsvhu/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,45 +92,46 @@ const zodDestination = z.object({
type: z.enum(["BROYEUR", "DEMOLISSEUR"]).nullish()
});

export const rawBsvhuSchema = z.object({
customId: z.string().nullish(),
wasteCode: z.enum(BSVHU_WASTE_CODES).nullish(),
emitter: zodEmitter,
transporter: zodTransporter,
destination: zodDestination,
packaging: z.enum(["LOT", "UNITE"]).nullish(),
identification: z.object({
numbers: z.array(z.string()).nullish(),
type: z
.enum([
"NUMERO_ORDRE_LOTS_SORTANTS",
"NUMERO_ORDRE_REGISTRE_POLICE",
"NUMERO_IMMATRICULATION"
])
.nullish()
}),
quantity: z.coerce.number().nonnegative().nullish(),
weight: z.object({
isEstimate: z.boolean().nullish(),
value: z.coerce.number().nonnegative().nullish()
}),
ecoOrganisme: z
.object({
siret: z.string().nullish(),
name: z.string().nullish(),
hasEcoOrganisme: z.boolean().nullish()
})
.superRefine((val, ctx) => {
if (val?.hasEcoOrganisme && !val.siret) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
path: ["siret"],
message: `Veuillez sélectionner un éco-organisme`
});
}
export const rawBsvhuSchema = z
.object({
customId: z.string().nullish(),
wasteCode: z.enum(BSVHU_WASTE_CODES).nullish(),
emitter: zodEmitter,
transporter: zodTransporter,
destination: zodDestination,
packaging: z.enum(["LOT", "UNITE"]).nullish(),
identification: z.object({
numbers: z.array(z.string()).nullish(),
type: z
.enum([
"NUMERO_ORDRE_LOTS_SORTANTS",
"NUMERO_ORDRE_REGISTRE_POLICE",
"NUMERO_IMMATRICULATION"
])
.nullish()
}),
broker: z
.object({
quantity: z.coerce.number().nonnegative().nullish(),
weight: z.object({
isEstimate: z.boolean().nullish(),
value: z.coerce.number().nonnegative().nullish()
}),
ecoOrganisme: z
.object({
siret: z.string().nullish(),
name: z.string().nullish(),
hasEcoOrganisme: z.boolean().nullish()
})
.superRefine((val, ctx) => {
if (val?.hasEcoOrganisme && !val.siret) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
path: ["siret"],
message: `Veuillez sélectionner un éco-organisme`
});
}
}),
hasBroker: z.boolean().nullish(),
broker: z.object({
company: zodCompany,
recepisse: z
.object({
Expand All @@ -139,10 +140,9 @@ export const rawBsvhuSchema = z.object({
validityLimit: z.string().nullish()
})
.nullish()
})
.nullish(),
trader: z
.object({
}),
hasTrader: z.boolean().nullish(),
trader: z.object({
company: zodCompany,
recepisse: z
.object({
Expand All @@ -151,9 +151,82 @@ export const rawBsvhuSchema = z.object({
validityLimit: z.string().nullish()
})
.nullish()
})
.nullish(),
intermediaries: z.array(zodCompany).nullish()
});
}),
hasIntermediaries: z.boolean().nullish(),
intermediaries: z.array(zodCompany).nullish()
})
.superRefine((val, ctx) => {
if (val?.hasBroker && !val.broker.company.siret) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
path: ["hasBroker"],
message: `Veuillez sélectionner un courtier`
});
ctx.addIssue({
code: z.ZodIssueCode.custom,
path: ["broker.company.contact"],
message: `La personne à contacter chez le courtier est un champ requis.`
});
ctx.addIssue({
code: z.ZodIssueCode.custom,
path: ["broker.company.phone"],
message: `Le N° de téléphone du courtier est un champ requis.`
});
ctx.addIssue({
code: z.ZodIssueCode.custom,
path: ["broker.company.mail"],
message: `L'adresse e-mail du courtier est un champ requis.`
});
}

if (val?.hasTrader && !val.trader.company.siret) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
path: ["hasTrader"],
message: `Veuillez sélectionner un négociant`
});
ctx.addIssue({
code: z.ZodIssueCode.custom,
path: ["trader.company.contact"],
message: `La personne à contacter chez le négociant est un champ requis.`
});
ctx.addIssue({
code: z.ZodIssueCode.custom,
path: ["trader.company.phone"],
message: `Le N° de téléphone du négociant est un champ requis.`
});
ctx.addIssue({
code: z.ZodIssueCode.custom,
path: ["trader.company.mail"],
message: `L'adresse e-mail du négociant est un champ requis.`
});
}

if (
val?.hasIntermediaries &&
(!val.intermediaries || !val.intermediaries[0].siret)
) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
path: ["hasIntermediaries"],
message: `Veuillez sélectionner au moins un intermédiaire`
});
ctx.addIssue({
code: z.ZodIssueCode.custom,
path: ["intermediaries", 0, "contact"],
message: `La personne à contacter chez l'intermédiaire est un champ requis.`
});
ctx.addIssue({
code: z.ZodIssueCode.custom,
path: ["intermediaries", 0, "phone"],
message: `Le N° de téléphone de l'intermédiaire est un champ requis.`
});
ctx.addIssue({
code: z.ZodIssueCode.custom,
path: ["intermediaries", 0, "mail"],
message: `L'adresse e-mail de l'intermédiaire est un champ requis.`
});
}
});

export type ZodBsvhu = z.infer<typeof rawBsvhuSchema>;
Loading

0 comments on commit 7081472

Please sign in to comment.