Skip to content

Commit

Permalink
[tra-15022]fix recette (#3678)
Browse files Browse the repository at this point in the history
* [tra-15022]fix recette

* fix agrement number

* paoh add name in schema (side effect vhu irregular situation)
  • Loading branch information
JulianaJM authored Oct 17, 2024
1 parent 8a1c98c commit edce0d5
Show file tree
Hide file tree
Showing 10 changed files with 326 additions and 223 deletions.
61 changes: 29 additions & 32 deletions front/src/Apps/Dashboard/Creation/FormStepsContent.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useRef, useState } from "react";
import React, { useState } from "react";
import { FormProvider, UseFormReturn } from "react-hook-form";
import { useNavigate } from "react-router-dom";
import FormStepsTabs from "../../Forms/Components/FormStepsTabs/FormStepsTabs";
Expand Down Expand Up @@ -47,15 +47,11 @@ const FormStepsContent = ({
const tabIds = tabList.map(tab => tab.tabId);
const lastTabId = tabIds[tabIds.length - 1];
const firstTabId = tabIds[0];
const ref = useRef<HTMLDivElement>(null);

const scrollToTop = () => {
const element = ref.current;
const element = document.getElementById("formStepsTabsContent");
if (element) {
const scrollPos = element.scrollHeight - window.innerHeight;
if (scrollPos > 0) {
ref.current?.scrollIntoView({ behavior: "instant", block: "start" });
}
element.scroll({ top: 0, behavior: "smooth" });
}
};
const onSubmit = (data, e) => {
Expand All @@ -76,38 +72,39 @@ const FormStepsContent = ({
};
const onTabChange = tabId => {
setSelectedTabId(tabId);
scrollToTop();
};

return (
<>
<SealedFieldsContext.Provider value={sealedFields}>
<FormProvider {...useformMethods}>
{!isLoading && (
<div ref={ref}>
<FormStepsTabs
//@ts-ignore
tabList={tabList}
draftCtaLabel={draftCtaLabel}
mainCtaLabel={mainCtaLabel}
selectedTabId={selectedTabId}
isPrevStepDisabled={selectedTabId === firstTabId}
isNextStepDisabled={selectedTabId === lastTabId}
onSubmit={useformMethods.handleSubmit(
(data, e) => onSubmit(data, e),
() => onErrors()
)}
onCancel={() => navigate(-1)}
onPrevTab={() =>
setSelectedTabId(getPrevTab(tabIds, selectedTabId))
}
onNextTab={() =>
setSelectedTabId(getNextTab(tabIds, selectedTabId))
}
onTabChange={onTabChange}
>
{tabsContent[selectedTabId] ?? <p></p>}
</FormStepsTabs>
</div>
<FormStepsTabs
//@ts-ignore
tabList={tabList}
draftCtaLabel={draftCtaLabel}
mainCtaLabel={mainCtaLabel}
selectedTabId={selectedTabId}
isPrevStepDisabled={selectedTabId === firstTabId}
isNextStepDisabled={selectedTabId === lastTabId}
onSubmit={useformMethods.handleSubmit(
(data, e) => onSubmit(data, e),
() => onErrors()
)}
onCancel={() => navigate(-1)}
onPrevTab={() => {
setSelectedTabId(getPrevTab(tabIds, selectedTabId));
scrollToTop();
}}
onNextTab={() => {
setSelectedTabId(getNextTab(tabIds, selectedTabId));
scrollToTop();
}}
onTabChange={onTabChange}
>
{tabsContent[selectedTabId] ?? <p></p>}
</FormStepsTabs>
)}
</FormProvider>
</SealedFieldsContext.Provider>
Expand Down
1 change: 1 addition & 0 deletions front/src/Apps/Dashboard/Creation/bspaoh/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const bspaohPackagingSchema = z.object({

const zodCompany = z.object({
siret: z.string(),
name: z.string(),
contact: z.string().nullish(),
phone: z.string().nullish(),
mail: z.string().nullish(),
Expand Down
3 changes: 2 additions & 1 deletion front/src/Apps/Dashboard/Creation/bsvhu/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { z } from "zod";
import { BSVHU_WASTE_CODES } from "@td/constants";

const zodCompany = z.object({
siret: z.string(),
siret: z.string().nullish(),
name: z.string(),
contact: z.string().nullish(),
phone: z.string().nullish(),
mail: z.string().nullish(),
Expand Down
134 changes: 79 additions & 55 deletions front/src/Apps/Dashboard/Creation/bsvhu/steps/Destination.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Input from "@codegouvfr/react-dsfr/Input";
import RadioButtons from "@codegouvfr/react-dsfr/RadioButtons";
import Select from "@codegouvfr/react-dsfr/Select";
import { CompanySearchResult, FavoriteType } from "@td/codegen-ui";
import { CompanySearchResult, CompanyType, FavoriteType } from "@td/codegen-ui";
import React, { useEffect, useMemo, useState, useContext } from "react";
import { useFormContext } from "react-hook-form";
import { useParams } from "react-router-dom";
Expand Down Expand Up @@ -32,67 +32,77 @@ const DestinationBsvhu = ({ errors }) => {
}, [isDangerousWasteCode, setValue]);

useEffect(() => {
if (
errors?.length &&
errors?.length !== Object.keys(formState.errors)?.length &&
!destination?.company?.siret
) {
setFieldError(
errors,
`${actor}.company.siret`,
formState.errors?.[actor]?.["company"]?.siret,
setError
);

setFieldError(
errors,
`${actor}.company.contact`,
formState.errors?.[actor]?.["company"]?.contact,
setError
);

setFieldError(
errors,
`${actor}.company.address`,
formState.errors?.[actor]?.["company"]?.address,
setError
);

setFieldError(
errors,
`${actor}.company.phone`,
formState.errors?.[actor]?.["company"]?.phone,
setError
);

setFieldError(
errors,
`${actor}.company.mail`,
formState.errors?.[actor]?.["company"]?.mail,
setError
);

setFieldError(
errors,
`${actor}.company.vatNumber`,
formState.errors?.[actor]?.["company"]?.vatNumber,
setError
);

setFieldError(
errors,
`${actor}.agrementNumber`,
formState.errors?.[actor]?.["agrementNumber"],
setError
);
if (errors?.length) {
if (!destination?.company?.siret) {
setFieldError(
errors,
`${actor}.company.siret`,
formState.errors?.[actor]?.["company"]?.siret,
setError
);
}
if (!destination?.company?.contact) {
setFieldError(
errors,
`${actor}.company.contact`,
formState.errors?.[actor]?.["company"]?.contact,
setError
);
}
if (!destination?.company?.address) {
setFieldError(
errors,
`${actor}.company.address`,
formState.errors?.[actor]?.["company"]?.address,
setError
);
}
if (!destination?.company?.phone) {
setFieldError(
errors,
`${actor}.company.phone`,
formState.errors?.[actor]?.["company"]?.phone,
setError
);
}
if (!destination?.company?.mail) {
setFieldError(
errors,
`${actor}.company.mail`,
formState.errors?.[actor]?.["company"]?.mail,
setError
);
}
if (!destination?.company?.vatNumber) {
setFieldError(
errors,
`${actor}.company.vatNumber`,
formState.errors?.[actor]?.["company"]?.vatNumber,
setError
);
}
if (!destination?.agrementNumber) {
setFieldError(
errors,
`${actor}.agrementNumber`,
formState.errors?.[actor]?.["agrementNumber"],
setError
);
}
}
}, [
errors,
errors?.length,
formState.errors,
formState.errors.length,
setError,
destination?.company?.siret
destination?.company?.siret,
destination?.company?.contact,
destination?.company?.address,
destination?.company?.phone,
destination?.company?.mail,
destination?.company?.vatNumber,
destination?.agrementNumber
]);

const updateAgrementNumber = (destination, type?) => {
Expand Down Expand Up @@ -144,6 +154,19 @@ const DestinationBsvhu = ({ errors }) => {
]
);

const selectedCompanyError = (company?: CompanySearchResult) => {
// Le destinatiare doit être inscrit et avec un profil crématorium ou sous-type crémation
// Le profil crématorium sera bientôt supprimé
if (company) {
if (!company.isRegistered) {
return "Cet établissement n'est pas inscrit sur Trackdéchets, il ne peut pas être ajouté sur le bordereau.";
} else if (!company.companyTypes?.includes(CompanyType.WasteVehicles)) {
return "Cet établissement n'a pas le profil Installation de traitement de VHU.";
}
}
return null;
};

return (
<>
{!!sealedFields.length && <DisabledParagraphStep />}
Expand Down Expand Up @@ -189,6 +212,7 @@ const DestinationBsvhu = ({ errors }) => {
favoriteType={FavoriteType.Destination}
disabled={sealedFields.includes(`${actor}.company.siret`)}
selectedCompanyOrgId={orgId}
selectedCompanyError={selectedCompanyError}
onCompanySelected={company => {
if (company) {
setValue(`${actor}.company.orgId`, company.orgId);
Expand Down
Loading

0 comments on commit edce0d5

Please sign in to comment.