From dc1a68f50dc97a7ee88912bc9365b3d6990bba11 Mon Sep 17 00:00:00 2001 From: Xavier Jp Date: Tue, 4 Jun 2024 17:28:02 +0200 Subject: [PATCH] feat: merge RCS and RNE for agents (#1092) * feat: merge RCS and RNE for agents * refactor: use API routes for protected labels and certifs * refactor: carte FNTP * fix: build * refactor: usa client data section for conformite * test: update 401 and 403 tests on data-fetching * chore: remigration of dirigeants and justificatif to plain old boring async API calls * fix: typo in rcs route --- .../_component/sections/beneficiaires.tsx | 0 .../_component/sections/dirigeant-content.tsx | 0 .../[slug]/_component/sections/index.tsx | 47 ++++++ .../_component/sections/is-personne-morale.ts | 0 .../sections/protected-dirigeants.tsx | 136 +++++++++++++++++ .../_component/sections/rne-dirigeants.tsx | 14 +- .../sections/service-public-responsables.tsx | 0 .../sections/service-public-subservices.tsx | 0 .../_component/sections/summary.tsx | 46 +++--- .../dirigeants/[slug]/page.tsx | 23 ++- .../dirigeants/_component/sections/index.tsx | 59 -------- .../_component/sections/mandataires-rcs.tsx | 99 ------------- .../[slug]/_components/actes-section.tsx | 2 +- .../carte-professionnelle-TP-section.tsx | 13 +- .../documents/[slug]/page.tsx | 2 +- .../justificatif/[slug]/_components/index.tsx | 30 ++-- .../justificatif/[slug]/page.tsx | 14 +- .../_components/protected-certificats.tsx | 57 ------- .../labels-certificats/[slug]/page.tsx | 14 +- .../espace-agent/_helper/index.ts | 38 +++++ .../[slug]/routes.ts | 22 +++ .../espace-agent/opqibi/[slug]/route.ts | 22 +++ .../espace-agent/qualibat/[slug]/route.ts | 22 +++ .../espace-agent/qualifelec/[slug]/route.ts | 22 +++ .../rcs-mandataires/[slug]/route.ts | 22 +++ .../documents}/[slug]/route.ts | 2 +- app/api/data-fetching/rne/[slug]/route.ts | 20 +++ .../index.ts | 4 +- clients/api-entreprise/opqibi/index.ts | 4 +- clients/api-entreprise/qualibat/index.ts | 2 +- clients/api-entreprise/qualifelec/index.ts | 2 +- clients/routes.ts | 26 ++-- components-ui/horizontal-separator/index.tsx | 6 +- .../horizontal-separator/styles.module.css | 4 +- .../protected-certificats.tsx | 115 ++++++++------ .../certifications/opqibi-section.tsx | 31 +++- .../certifications/qualibat-section.tsx | 34 +++-- .../certifications/qualifelec-section.tsx | 37 +++-- .../conformite-section.tsx | 20 +-- .../documents/actes-walled.tsx | 6 +- .../documents/bilans-walled.tsx | 6 +- .../documents/data-section/actes.tsx | 98 ++++++------ .../documents/data-section/bilans.tsx | 140 +++++++++--------- components/page-loader/index.tsx | 12 -- components/page-loader/style.module.css | 16 -- components/search-results/results-list.tsx | 2 +- .../section/data-section/style.module.css | 19 ++- components/unite-legale-section/index.tsx | 33 ++--- cypress/e2e/data-fetching.cy.js | 21 +++ hooks/fetch/RCS-mandataires.ts | 37 +++++ hooks/fetch/RNE-documents.ts | 2 +- hooks/fetch/RNE-immatriculation copy.ts | 34 +++++ hooks/fetch/carte-professionnelle-TP.ts | 2 +- hooks/fetch/conformite.ts | 4 +- ...professionnelle-travaux-publics-section.ts | 33 +++++ hooks/fetch/espace-agent/opqibi.ts | 33 +++++ hooks/fetch/espace-agent/qualibat.ts | 33 +++++ hooks/fetch/espace-agent/qualifelec.ts | 34 +++++ .../carte-professionnelle-travaux-publics.ts | 6 +- models/espace-agent/certificats/opqibi.ts | 4 +- models/espace-agent/certificats/qualibat.ts | 2 +- models/espace-agent/certificats/qualifelec.ts | 2 +- 62 files changed, 1013 insertions(+), 577 deletions(-) rename app/(header-default)/dirigeants/{ => [slug]}/_component/sections/beneficiaires.tsx (100%) rename app/(header-default)/dirigeants/{ => [slug]}/_component/sections/dirigeant-content.tsx (100%) create mode 100644 app/(header-default)/dirigeants/[slug]/_component/sections/index.tsx rename app/(header-default)/dirigeants/{ => [slug]}/_component/sections/is-personne-morale.ts (100%) create mode 100644 app/(header-default)/dirigeants/[slug]/_component/sections/protected-dirigeants.tsx rename app/(header-default)/dirigeants/{ => [slug]}/_component/sections/rne-dirigeants.tsx (87%) rename app/(header-default)/dirigeants/{ => [slug]}/_component/sections/service-public-responsables.tsx (100%) rename app/(header-default)/dirigeants/{ => [slug]}/_component/sections/service-public-subservices.tsx (100%) rename app/(header-default)/dirigeants/{ => [slug]}/_component/sections/summary.tsx (72%) delete mode 100644 app/(header-default)/dirigeants/_component/sections/index.tsx delete mode 100644 app/(header-default)/dirigeants/_component/sections/mandataires-rcs.tsx delete mode 100644 app/(header-default)/labels-certificats/[slug]/_components/protected-certificats.tsx create mode 100644 app/api/data-fetching/espace-agent/_helper/index.ts create mode 100644 app/api/data-fetching/espace-agent/carte-professionnelle-travaux-public/[slug]/routes.ts create mode 100644 app/api/data-fetching/espace-agent/opqibi/[slug]/route.ts create mode 100644 app/api/data-fetching/espace-agent/qualibat/[slug]/route.ts create mode 100644 app/api/data-fetching/espace-agent/qualifelec/[slug]/route.ts create mode 100644 app/api/data-fetching/espace-agent/rcs-mandataires/[slug]/route.ts rename app/api/data-fetching/espace-agent/{RNE-documents => rne/documents}/[slug]/route.ts (91%) create mode 100644 app/api/data-fetching/rne/[slug]/route.ts delete mode 100644 components/page-loader/index.tsx delete mode 100644 components/page-loader/style.module.css create mode 100644 hooks/fetch/RCS-mandataires.ts create mode 100644 hooks/fetch/RNE-immatriculation copy.ts create mode 100644 hooks/fetch/espace-agent/carte-professionnelle-travaux-publics-section.ts create mode 100644 hooks/fetch/espace-agent/opqibi.ts create mode 100644 hooks/fetch/espace-agent/qualibat.ts create mode 100644 hooks/fetch/espace-agent/qualifelec.ts diff --git a/app/(header-default)/dirigeants/_component/sections/beneficiaires.tsx b/app/(header-default)/dirigeants/[slug]/_component/sections/beneficiaires.tsx similarity index 100% rename from app/(header-default)/dirigeants/_component/sections/beneficiaires.tsx rename to app/(header-default)/dirigeants/[slug]/_component/sections/beneficiaires.tsx diff --git a/app/(header-default)/dirigeants/_component/sections/dirigeant-content.tsx b/app/(header-default)/dirigeants/[slug]/_component/sections/dirigeant-content.tsx similarity index 100% rename from app/(header-default)/dirigeants/_component/sections/dirigeant-content.tsx rename to app/(header-default)/dirigeants/[slug]/_component/sections/dirigeant-content.tsx diff --git a/app/(header-default)/dirigeants/[slug]/_component/sections/index.tsx b/app/(header-default)/dirigeants/[slug]/_component/sections/index.tsx new file mode 100644 index 000000000..201a90837 --- /dev/null +++ b/app/(header-default)/dirigeants/[slug]/_component/sections/index.tsx @@ -0,0 +1,47 @@ +'use client'; + +import BreakPageForPrint from '#components-ui/print-break-page'; +import { IUniteLegale } from '#models/core/types'; +import { EScope, hasRights } from '#models/user/rights'; +import { ISession } from '#models/user/session'; +import useFetchRNEImmatriculation from 'hooks/fetch/RNE-immatriculation copy'; +import BeneficiairesSection from './beneficiaires'; +import DirigeantsProtectedSection from './protected-dirigeants'; +import DirigeantsSection from './rne-dirigeants'; +import DirigeantSummary from './summary'; + +export function DirigeantInformation({ + uniteLegale, + session, +}: { + uniteLegale: IUniteLegale; + session: ISession | null; +}) { + const immatriculationRNE = useFetchRNEImmatriculation(uniteLegale); + + return ( + <> + + {!hasRights(session, EScope.mandatairesRCS) ? ( + + ) : ( + + )} + + + + + ); +} diff --git a/app/(header-default)/dirigeants/_component/sections/is-personne-morale.ts b/app/(header-default)/dirigeants/[slug]/_component/sections/is-personne-morale.ts similarity index 100% rename from app/(header-default)/dirigeants/_component/sections/is-personne-morale.ts rename to app/(header-default)/dirigeants/[slug]/_component/sections/is-personne-morale.ts diff --git a/app/(header-default)/dirigeants/[slug]/_component/sections/protected-dirigeants.tsx b/app/(header-default)/dirigeants/[slug]/_component/sections/protected-dirigeants.tsx new file mode 100644 index 000000000..70e6a76fe --- /dev/null +++ b/app/(header-default)/dirigeants/[slug]/_component/sections/protected-dirigeants.tsx @@ -0,0 +1,136 @@ +import routes from '#clients/routes'; +import { Info, Warning } from '#components-ui/alerts'; +import { INPI } from '#components/administrations'; +import { DataSectionClient } from '#components/section/data-section'; +import { EAdministration } from '#models/administrations/EAdministration'; +import { IAPILoading, isAPILoading } from '#models/api-loading'; +import { + IAPINotRespondingError, + isAPI404, + isAPINotResponding, +} from '#models/api-not-responding'; +import { IUniteLegale } from '#models/core/types'; +import { IDirigeant, IImmatriculationRNE } from '#models/immatriculation'; +import useFetchRCSMandataires from 'hooks/fetch/RCS-mandataires'; +import { DirigeantContent } from './dirigeant-content'; +import DirigeantsSection from './rne-dirigeants'; + +type IProps = { + immatriculationRNE: + | IImmatriculationRNE + | IAPINotRespondingError + | IAPILoading; + uniteLegale: IUniteLegale; +}; + +function RCSDiffersFromRNE({ + mandatairesRCS, + immatriculationRNE, + uniteLegale, +}: { + mandatairesRCS: Array; + immatriculationRNE: + | IImmatriculationRNE + | IAPINotRespondingError + | IAPILoading; + uniteLegale: IUniteLegale; +}) { + if ( + isAPILoading(immatriculationRNE) || + isAPINotResponding(immatriculationRNE) + ) { + return null; + } + + if (immatriculationRNE.dirigeants.length === mandatairesRCS.length) { + return null; + } + + return ( + + Les données d’Infogreffe sont issues du RNE mais il y a une différence + entre le nombre de dirigeant(s) retourné(s) par l’ + ({immatriculationRNE.dirigeants.length}) et par Infogreffe ( + {mandatairesRCS.length}). Pour comparer, vous pouvez consulter la page de + cette entreprise sur{' '} + + data.inpi.fr + + . + + ); +} + +/** + * Dirigeants for agents : either from Infogreffe or from RNE + */ +function DirigeantsProtectedSection({ + uniteLegale, + immatriculationRNE, +}: IProps) { + const mandatairesRCS = useFetchRCSMandataires(uniteLegale); + + if (!isAPILoading(mandatairesRCS)) { + if ( + isAPI404(mandatairesRCS) || + (!isAPINotResponding(mandatairesRCS) && mandatairesRCS.length === 0) + ) { + return ( + + ); + } + } + + return ( + + {(mandatairesRCS) => ( + <> + + Ces informations proviennent d’ + + Infogreffe + {' '} + et incluent la date de naissance des dirigeant(e)s. + + +

+ Cette entreprise possède {mandatairesRCS.length} dirigeant(s) + enregistré(s) au RNE : +

+ + + )} +
+ ); +} + +export default DirigeantsProtectedSection; diff --git a/app/(header-default)/dirigeants/_component/sections/rne-dirigeants.tsx b/app/(header-default)/dirigeants/[slug]/_component/sections/rne-dirigeants.tsx similarity index 87% rename from app/(header-default)/dirigeants/_component/sections/rne-dirigeants.tsx rename to app/(header-default)/dirigeants/[slug]/_component/sections/rne-dirigeants.tsx index 7cf627596..bc475e3ce 100644 --- a/app/(header-default)/dirigeants/_component/sections/rne-dirigeants.tsx +++ b/app/(header-default)/dirigeants/[slug]/_component/sections/rne-dirigeants.tsx @@ -1,25 +1,29 @@ import routes from '#clients/routes'; import InpiPartiallyDownWarning from '#components-ui/alerts-with-explanations/inpi-partially-down'; import { INPI } from '#components/administrations'; -import { DataSection } from '#components/section/data-section'; +import { AsyncDataSectionClient } from '#components/section/data-section/client'; import { UniteLegalePageLink } from '#components/unite-legale-page-link'; import { EAdministration } from '#models/administrations/EAdministration'; +import { IAPILoading } from '#models/api-loading'; import { IAPINotRespondingError } from '#models/api-not-responding'; import { IUniteLegale } from '#models/core/types'; import { IImmatriculationRNE } from '#models/immatriculation'; import { DirigeantContent } from './dirigeant-content'; type IProps = { - immatriculationRNE: IImmatriculationRNE | IAPINotRespondingError; + immatriculationRNE: + | IImmatriculationRNE + | IAPINotRespondingError + | IAPILoading; uniteLegale: IUniteLegale; }; /** * Dirigeants section */ -async function DirigeantsSection({ uniteLegale, immatriculationRNE }: IProps) { +function DirigeantsSection({ uniteLegale, immatriculationRNE }: IProps) { return ( - ); }} - + ); } diff --git a/app/(header-default)/dirigeants/_component/sections/service-public-responsables.tsx b/app/(header-default)/dirigeants/[slug]/_component/sections/service-public-responsables.tsx similarity index 100% rename from app/(header-default)/dirigeants/_component/sections/service-public-responsables.tsx rename to app/(header-default)/dirigeants/[slug]/_component/sections/service-public-responsables.tsx diff --git a/app/(header-default)/dirigeants/_component/sections/service-public-subservices.tsx b/app/(header-default)/dirigeants/[slug]/_component/sections/service-public-subservices.tsx similarity index 100% rename from app/(header-default)/dirigeants/_component/sections/service-public-subservices.tsx rename to app/(header-default)/dirigeants/[slug]/_component/sections/service-public-subservices.tsx diff --git a/app/(header-default)/dirigeants/_component/sections/summary.tsx b/app/(header-default)/dirigeants/[slug]/_component/sections/summary.tsx similarity index 72% rename from app/(header-default)/dirigeants/_component/sections/summary.tsx rename to app/(header-default)/dirigeants/[slug]/_component/sections/summary.tsx index 7b9fe5a88..a05948a43 100644 --- a/app/(header-default)/dirigeants/_component/sections/summary.tsx +++ b/app/(header-default)/dirigeants/[slug]/_component/sections/summary.tsx @@ -1,7 +1,7 @@ import { HttpNotFound } from '#clients/exceptions'; import { Loader } from '#components-ui/loader'; import { INPI, INSEE, MI } from '#components/administrations'; -import { isAPILoading } from '#models/api-loading'; +import { IAPILoading, isAPILoading } from '#models/api-loading'; import { IAPINotRespondingError, isAPINotResponding, @@ -41,40 +41,46 @@ const NoDirigeantDefault = () => ( ); type IDirigeantSummaryProps = { - immatriculationRNE: IImmatriculationRNE | IAPINotRespondingError; + immatriculationRNE: + | IImmatriculationRNE + | IAPINotRespondingError + | IAPILoading; uniteLegale: IUniteLegale; }; -const DirigeantSummary: React.FC = async ({ +const DirigeantSummary: React.FC = ({ uniteLegale, immatriculationRNE, }) => { const summaries = []; - if (!isAPINotResponding(immatriculationRNE)) { - const dirigeantsCount = (immatriculationRNE?.dirigeants || []).length; - summaries.push( - - {dirigeantsCount} dirigeants inscrits au Registre National des - Entreprises (RNE) - - ); - - const beneficiairesCount = (immatriculationRNE?.beneficiaires || []).length; - summaries.push( - - {beneficiairesCount} bénéficiaires inscrits à Référentiel des - Bénéficiaires Effectifs - - ); - } if (isAPILoading(immatriculationRNE)) { summaries.push( chargement des données des dirigeants en cours ); + } else { + if (!isAPINotResponding(immatriculationRNE)) { + const dirigeantsCount = (immatriculationRNE?.dirigeants || []).length; + summaries.push( + + {dirigeantsCount} dirigeants inscrits au Registre National des + Entreprises (RNE) + + ); + + const beneficiairesCount = (immatriculationRNE?.beneficiaires || []) + .length; + summaries.push( + + {beneficiairesCount} bénéficiaires inscrits à Référentiel des + Bénéficiaires Effectifs + + ); + } } + const hasNoDirigeant = summaries.length === 0; if (hasNoDirigeant) { if (uniteLegale.association.idAssociation) { diff --git a/app/(header-default)/dirigeants/[slug]/page.tsx b/app/(header-default)/dirigeants/[slug]/page.tsx index 74cc14889..df671b611 100644 --- a/app/(header-default)/dirigeants/[slug]/page.tsx +++ b/app/(header-default)/dirigeants/[slug]/page.tsx @@ -1,9 +1,10 @@ import { Metadata } from 'next'; -import { Suspense } from 'react'; -import { PageLoader } from '#components/page-loader'; +import { DonneesPriveesSection } from '#components/donnees-privees-section'; import Title from '#components/title-section'; import { FICHE } from '#components/title-section/tabs'; +import { estDiffusible } from '#models/core/statut-diffusion'; import { getServicePublicByUniteLegale } from '#models/service-public'; +import { EScope, hasRights } from '#models/user/rights'; import { uniteLegalePageDescription, uniteLegalePageTitle, @@ -13,9 +14,9 @@ import extractParamsAppRouter, { AppRouterProps, } from '#utils/server-side-helper/app/extract-params'; import getSession from '#utils/server-side-helper/app/get-session'; -import ResponsableSection from 'app/(header-default)/dirigeants/_component/sections/service-public-responsables'; -import { DirigeantInformation } from '../_component/sections'; -import SubServicesSection from '../_component/sections/service-public-subservices'; +import ResponsableSection from 'app/(header-default)/dirigeants/[slug]/_component/sections/service-public-responsables'; +import { DirigeantInformation } from './_component/sections'; +import SubServicesSection from './_component/sections/service-public-subservices'; export const generateMetadata = async ( props: AppRouterProps @@ -64,15 +65,11 @@ const DirigeantsPage = async (props: AppRouterProps) => { uniteLegale={uniteLegale} /> + ) : !estDiffusible(uniteLegale) && + !hasRights(session, EScope.nonDiffusible) ? ( + ) : ( - !isBot && ( - }> - - - ) + )} diff --git a/app/(header-default)/dirigeants/_component/sections/index.tsx b/app/(header-default)/dirigeants/_component/sections/index.tsx deleted file mode 100644 index e5167882b..000000000 --- a/app/(header-default)/dirigeants/_component/sections/index.tsx +++ /dev/null @@ -1,59 +0,0 @@ -import BreakPageForPrint from '#components-ui/print-break-page'; -import { DonneesPriveesSection } from '#components/donnees-privees-section'; -import { estDiffusible } from '#models/core/statut-diffusion'; -import { IUniteLegale } from '#models/core/types'; -import { getMandatairesRCS } from '#models/espace-agent/mandataires-rcs'; -import { getImmatriculationRNE } from '#models/immatriculation/rne'; -import { EScope, hasRights } from '#models/user/rights'; -import { ISession } from '#models/user/session'; -import BeneficiairesSection from './beneficiaires'; -import MandatairesRCSSection from './mandataires-rcs'; -import DirigeantsSection from './rne-dirigeants'; -import DirigeantSummary from './summary'; - -export async function DirigeantInformation({ - uniteLegale, - session, -}: { - uniteLegale: IUniteLegale; - session: ISession | null; -}) { - if ( - !estDiffusible(uniteLegale) && - !hasRights(session, EScope.nonDiffusible) - ) { - return ; - } - - const [immatriculationRNE, mandatairesRCS] = await Promise.all([ - getImmatriculationRNE(uniteLegale.siren), - hasRights(session, EScope.mandatairesRCS) && - getMandatairesRCS(uniteLegale.siren, session?.user?.siret), - ]); - - return ( - <> - - - {mandatairesRCS && ( - - )} - - - - - ); -} diff --git a/app/(header-default)/dirigeants/_component/sections/mandataires-rcs.tsx b/app/(header-default)/dirigeants/_component/sections/mandataires-rcs.tsx deleted file mode 100644 index 2f2331a8a..000000000 --- a/app/(header-default)/dirigeants/_component/sections/mandataires-rcs.tsx +++ /dev/null @@ -1,99 +0,0 @@ -import routes from '#clients/routes'; -import { Warning } from '#components-ui/alerts'; -import { DataSection } from '#components/section/data-section'; -import { EAdministration } from '#models/administrations/EAdministration'; -import { IAPILoading, isAPILoading } from '#models/api-loading'; -import { - IAPINotRespondingError, - isAPINotResponding, -} from '#models/api-not-responding'; -import { IUniteLegale } from '#models/core/types'; -import { IDirigeant, IImmatriculationRNE } from '#models/immatriculation'; -import { DirigeantContent } from './dirigeant-content'; - -type IProps = { - immatriculationRNE: IImmatriculationRNE | IAPINotRespondingError; - uniteLegale: IUniteLegale; - mandatairesRCS: Array | IAPINotRespondingError; -}; - -/** - * Dirigeants from RCS section - */ -async function MandatairesRCSSection({ - uniteLegale, - immatriculationRNE, - mandatairesRCS, -}: IProps) { - return ( - - {(mandatairesRCS) => - mandatairesRCS.length === 0 ? ( -

Cette entreprise ne possède aucun dirigeant.

- ) : ( - <> - {RCSDiffersFromRNE(mandatairesRCS, immatriculationRNE) && ( - - Le nombre de dirigeants enregistrés sur Infogreffe (ex-RCS) - diffère de celui du RNE. Cette situation est anormale. Pour en - savoir plus vous pouvez consulter la page de cette entreprise - sur{' '} - - data.inpi.fr - {' '} - ou sur{' '} - - Infogreffe - - . - - )} -

- Cette entreprise possède {mandatairesRCS.length} mandataire(s) - enregistrés sur Infogreffe (ex-RCS). Nous vous - affichons cette liste en complément du RNE car elle permet - d’accèder à la date de naissance complète des personnes physiques - : -

- - - ) - } -
- ); -} -export default MandatairesRCSSection; - -function RCSDiffersFromRNE( - mandatairesRCS: Array, - immatriculationRNE: IImmatriculationRNE | IAPINotRespondingError | IAPILoading -) { - if ( - isAPILoading(immatriculationRNE) || - isAPINotResponding(immatriculationRNE) - ) { - return null; - } - return mandatairesRCS.length !== immatriculationRNE.dirigeants.length; -} diff --git a/app/(header-default)/documents/[slug]/_components/actes-section.tsx b/app/(header-default)/documents/[slug]/_components/actes-section.tsx index fa452112f..077b7ddd3 100644 --- a/app/(header-default)/documents/[slug]/_components/actes-section.tsx +++ b/app/(header-default)/documents/[slug]/_components/actes-section.tsx @@ -90,7 +90,7 @@ function ActesTable({ actes }: IActesTableProps) { target="_blank" alt small - to={`${routes.api.rne.documents.download}${a.id}?type=acte`} + to={`${routes.api.espaceAgent.rne.documents.download}${a.id}?type=acte`} > Télécharger , diff --git a/app/(header-default)/documents/[slug]/_components/carte-professionnelle-TP-section.tsx b/app/(header-default)/documents/[slug]/_components/carte-professionnelle-TP-section.tsx index ab48896c5..fdb121014 100644 --- a/app/(header-default)/documents/[slug]/_components/carte-professionnelle-TP-section.tsx +++ b/app/(header-default)/documents/[slug]/_components/carte-professionnelle-TP-section.tsx @@ -21,7 +21,18 @@ export default function CarteProfessionnelleTPSection({ id="carte-professionnelle-travaux-publics" isProtected notFoundInfo={ - 'Aucune carte professionnelle trouvée pour cette entreprise' + <> + Cette entreprise n’a pas de{' '} + + carte professionnelle d’entrepreneur de travaux publics + + . + } sources={[EAdministration.FNTP]} data={carteProfessionnelleTravauxPublics} diff --git a/app/(header-default)/documents/[slug]/page.tsx b/app/(header-default)/documents/[slug]/page.tsx index bef438a3c..e85ae0796 100644 --- a/app/(header-default)/documents/[slug]/page.tsx +++ b/app/(header-default)/documents/[slug]/page.tsx @@ -55,7 +55,7 @@ const UniteLegaleDocumentPage = async (props: AppRouterProps) => { /> {hasRights(session, EScope.conformite) && ( - + )} {!hasRights(session, EScope.documentsRne) ? ( = async ({ uniteLegale, immatriculationJOAFE, session }) => { - const immatriculationRNE = await getImmatriculationRNE(uniteLegale.siren); +}> = ({ uniteLegale, immatriculationJOAFE, session }) => { + const immatriculationRNE = useFetchRNEImmatriculation(uniteLegale); return ( - + <> + {isAPILoading(immatriculationRNE) ? ( + <> + Chargement des données en cours + + ) : ( + + )} + ); }; diff --git a/app/(header-default)/justificatif/[slug]/page.tsx b/app/(header-default)/justificatif/[slug]/page.tsx index 8cfd6ef13..463eb7bb0 100644 --- a/app/(header-default)/justificatif/[slug]/page.tsx +++ b/app/(header-default)/justificatif/[slug]/page.tsx @@ -1,6 +1,4 @@ import { Metadata } from 'next'; -import { Suspense } from 'react'; -import { PageLoader } from '#components/page-loader'; import Title from '#components/title-section'; import { FICHE } from '#components/title-section/tabs'; import { getImmatriculationJOAFE } from '#models/immatriculation/joafe'; @@ -50,13 +48,11 @@ const JustificatifPage = async (props: AppRouterProps) => { session={session} /> {!isBot && ( - }> - - + )} diff --git a/app/(header-default)/labels-certificats/[slug]/_components/protected-certificats.tsx b/app/(header-default)/labels-certificats/[slug]/_components/protected-certificats.tsx deleted file mode 100644 index d240fc6d8..000000000 --- a/app/(header-default)/labels-certificats/[slug]/_components/protected-certificats.tsx +++ /dev/null @@ -1,57 +0,0 @@ -import { Suspense } from 'react'; -import { OpqibiSection } from '#components/espace-agent-components/certifications/opqibi-section'; -import { QualifelecSection } from '#components/espace-agent-components/certifications/qualifelec-section'; -import { - IAPINotRespondingError, - isAPINotResponding, -} from '#models/api-not-responding'; -import { IUniteLegale } from '#models/core/types'; -import { getOpqibi } from '#models/espace-agent/certificats/opqibi'; -import { getQualibat } from '#models/espace-agent/certificats/qualibat'; -import { getQualifelec } from '#models/espace-agent/certificats/qualifelec'; -import { ISession } from '#models/user/session'; - -type IProps = { - uniteLegale: IUniteLegale; - session: ISession | null; - hasOtherCertificates: boolean; -}; - -export async function ProtectedCertificats({ - uniteLegale, - session, - hasOtherCertificates, -}: IProps) { - const opqibi = getOpqibi(uniteLegale.siren, session?.user?.siret); - const qualifelec = getQualifelec( - uniteLegale.siege.siret, - session?.user?.siret - ); - const qualibat = getQualibat(uniteLegale.siege.siret, session?.user?.siret); - - return ( - <> - {!hasOtherCertificates && ( - - - - )} - {/* Qualibat API is down. When it's back up, uncomment this line - */} - - - - ); -} - -async function NoCertificatsWarning({ - certificats: certificatsPromise, -}: { - certificats: Promise[]; -}) { - const certificats = await Promise.all(certificatsPromise); - if (certificats.every((certificat) => isAPINotResponding(certificat))) { - return

Aucun certificat n’a été trouvé pour cette entreprise.

; - } - return null; -} diff --git a/app/(header-default)/labels-certificats/[slug]/page.tsx b/app/(header-default)/labels-certificats/[slug]/page.tsx index 8c23a9b08..df673a629 100644 --- a/app/(header-default)/labels-certificats/[slug]/page.tsx +++ b/app/(header-default)/labels-certificats/[slug]/page.tsx @@ -4,6 +4,8 @@ import { checkHasLabelsAndCertificates, checkHasQuality, } from '#components/badges-section/labels-and-certificates'; +import { OpqibiSection } from '#components/espace-agent-components/certifications/opqibi-section'; +import { QualifelecSection } from '#components/espace-agent-components/certifications/qualifelec-section'; import { CertificationsBioSection } from '#components/labels-and-certificates/bio'; import { EgaproSection } from '#components/labels-and-certificates/egapro'; import { CertificationsEntrepreneurSpectaclesSection } from '#components/labels-and-certificates/entrepreneur-spectacles'; @@ -25,7 +27,6 @@ import extractParamsAppRouter, { AppRouterProps, } from '#utils/server-side-helper/app/extract-params'; import getSession from '#utils/server-side-helper/app/get-session'; -import { ProtectedCertificats } from './_components/protected-certificats'; export const generateMetadata = async ( props: AppRouterProps @@ -116,11 +117,12 @@ const LabelsAndCertificatsPage = async (props: AppRouterProps) => { )} {hasRights(session, EScope.protectedCertificats) && ( - + <> + + {/* */} + + + )} diff --git a/app/api/data-fetching/espace-agent/_helper/index.ts b/app/api/data-fetching/espace-agent/_helper/index.ts new file mode 100644 index 000000000..137eda437 --- /dev/null +++ b/app/api/data-fetching/espace-agent/_helper/index.ts @@ -0,0 +1,38 @@ +import { HttpForbiddenError } from '#clients/exceptions'; +import { EAdministration } from '#models/administrations/EAdministration'; +import { FetchRessourceException } from '#models/exceptions'; +import { EScope, hasRights } from '#models/user/rights'; +import { logFatalErrorInSentry } from '#utils/sentry'; +import getSession from '#utils/server-side-helper/app/get-session'; + +export async function ProtectedAPIRoute( + routeLabel: string, + slug: string, + administration: EAdministration, + scope: EScope, + run: (agentSiret: string) => Promise +) { + const session = await getSession(); + try { + if (!hasRights(session, scope)) { + throw new HttpForbiddenError('Unauthorized account'); + } + + const agentSiret = session?.user?.siret || 'Inconnu'; + + const data = await run(agentSiret); + return Response.json(data, { status: 200 }); + } catch (e: any) { + const message = `Failed to get donnees ${routeLabel}`; + logFatalErrorInSentry( + new FetchRessourceException({ + ressource: routeLabel, + context: { slug }, + cause: e, + message, + administration, + }) + ); + return Response.json({ message }, { status: e.status || 500 }); + } +} diff --git a/app/api/data-fetching/espace-agent/carte-professionnelle-travaux-public/[slug]/routes.ts b/app/api/data-fetching/espace-agent/carte-professionnelle-travaux-public/[slug]/routes.ts new file mode 100644 index 000000000..e268abd7a --- /dev/null +++ b/app/api/data-fetching/espace-agent/carte-professionnelle-travaux-public/[slug]/routes.ts @@ -0,0 +1,22 @@ +import { EAdministration } from '#models/administrations/EAdministration'; +import { getCarteProfessionnelleTravauxPublic } from '#models/espace-agent/carte-professionnelle-travaux-publics'; +import { EScope } from '#models/user/rights'; +import { verifySiren } from '#utils/helpers'; +import { ProtectedAPIRoute } from '../../_helper'; + +export async function GET( + _request: Request, + { params }: { params: { slug: string } } +) { + const slug = params.slug; + return ProtectedAPIRoute( + 'CarteProfessionnelleTravauxPublics', + slug, + EAdministration.DINUM, + EScope.protectedCertificats, + async (agentSiret: string) => { + const siren = verifySiren(slug as string); + return await getCarteProfessionnelleTravauxPublic(siren, agentSiret); + } + ); +} diff --git a/app/api/data-fetching/espace-agent/opqibi/[slug]/route.ts b/app/api/data-fetching/espace-agent/opqibi/[slug]/route.ts new file mode 100644 index 000000000..3230dcba3 --- /dev/null +++ b/app/api/data-fetching/espace-agent/opqibi/[slug]/route.ts @@ -0,0 +1,22 @@ +import { EAdministration } from '#models/administrations/EAdministration'; +import { getOpqibi } from '#models/espace-agent/certificats/opqibi'; +import { EScope } from '#models/user/rights'; +import { verifySiren } from '#utils/helpers'; +import { ProtectedAPIRoute } from '../../_helper'; + +export async function GET( + _request: Request, + { params }: { params: { slug: string } } +) { + const slug = params.slug; + return ProtectedAPIRoute( + 'Opqibi', + slug, + EAdministration.DINUM, + EScope.protectedCertificats, + async (agentSiret: string) => { + const siren = verifySiren(slug as string); + return await getOpqibi(siren, agentSiret); + } + ); +} diff --git a/app/api/data-fetching/espace-agent/qualibat/[slug]/route.ts b/app/api/data-fetching/espace-agent/qualibat/[slug]/route.ts new file mode 100644 index 000000000..853ccd0e8 --- /dev/null +++ b/app/api/data-fetching/espace-agent/qualibat/[slug]/route.ts @@ -0,0 +1,22 @@ +import { EAdministration } from '#models/administrations/EAdministration'; +import { getQualibat } from '#models/espace-agent/certificats/qualibat'; +import { EScope } from '#models/user/rights'; +import { verifySiret } from '#utils/helpers'; +import { ProtectedAPIRoute } from '../../_helper'; + +export async function GET( + _request: Request, + { params }: { params: { slug: string } } +) { + const slug = params.slug; + return ProtectedAPIRoute( + 'Qualibat', + slug, + EAdministration.DINUM, + EScope.protectedCertificats, + async (agentSiret: string) => { + const siret = verifySiret(slug as string); + return await getQualibat(siret, agentSiret); + } + ); +} diff --git a/app/api/data-fetching/espace-agent/qualifelec/[slug]/route.ts b/app/api/data-fetching/espace-agent/qualifelec/[slug]/route.ts new file mode 100644 index 000000000..333999c1c --- /dev/null +++ b/app/api/data-fetching/espace-agent/qualifelec/[slug]/route.ts @@ -0,0 +1,22 @@ +import { EAdministration } from '#models/administrations/EAdministration'; +import { getQualifelec } from '#models/espace-agent/certificats/qualifelec'; +import { EScope } from '#models/user/rights'; +import { verifySiret } from '#utils/helpers'; +import { ProtectedAPIRoute } from '../../_helper'; + +export async function GET( + _request: Request, + { params }: { params: { slug: string } } +) { + const slug = params.slug; + return ProtectedAPIRoute( + 'Qualifelec', + slug, + EAdministration.DINUM, + EScope.protectedCertificats, + async (agentSiret: string) => { + const siret = verifySiret(slug as string); + return await getQualifelec(siret, agentSiret); + } + ); +} diff --git a/app/api/data-fetching/espace-agent/rcs-mandataires/[slug]/route.ts b/app/api/data-fetching/espace-agent/rcs-mandataires/[slug]/route.ts new file mode 100644 index 000000000..98d3acd60 --- /dev/null +++ b/app/api/data-fetching/espace-agent/rcs-mandataires/[slug]/route.ts @@ -0,0 +1,22 @@ +import { EAdministration } from '#models/administrations/EAdministration'; +import { getMandatairesRCS } from '#models/espace-agent/mandataires-rcs'; +import { EScope } from '#models/user/rights'; +import { verifySiren } from '#utils/helpers'; +import { ProtectedAPIRoute } from '../../_helper'; + +export async function GET( + _request: Request, + { params }: { params: { slug: string } } +) { + const slug = params.slug; + return ProtectedAPIRoute( + 'RCSMandataires', + slug, + EAdministration.INFOGREFFE, + EScope.documentsRne, + async () => { + const siren = verifySiren(slug as string); + return getMandatairesRCS(siren); + } + ); +} diff --git a/app/api/data-fetching/espace-agent/RNE-documents/[slug]/route.ts b/app/api/data-fetching/espace-agent/rne/documents/[slug]/route.ts similarity index 91% rename from app/api/data-fetching/espace-agent/RNE-documents/[slug]/route.ts rename to app/api/data-fetching/espace-agent/rne/documents/[slug]/route.ts index 0d827ab4a..197cd1a80 100644 --- a/app/api/data-fetching/espace-agent/RNE-documents/[slug]/route.ts +++ b/app/api/data-fetching/espace-agent/rne/documents/[slug]/route.ts @@ -2,7 +2,7 @@ import { EAdministration } from '#models/administrations/EAdministration'; import { getDocumentsRNEProtected } from '#models/immatriculation/rne'; import { EScope } from '#models/user/rights'; import { verifySiren } from '#utils/helpers'; -import { ProtectedAPIRoute } from '../../_helper'; +import { ProtectedAPIRoute } from '../../../_helper'; export async function GET( _request: Request, diff --git a/app/api/data-fetching/rne/[slug]/route.ts b/app/api/data-fetching/rne/[slug]/route.ts new file mode 100644 index 000000000..b85d1a036 --- /dev/null +++ b/app/api/data-fetching/rne/[slug]/route.ts @@ -0,0 +1,20 @@ +import { getImmatriculationRNE } from '#models/immatriculation/rne'; +import { verifySiren } from '#utils/helpers'; +import { withIgnoreBot } from '#utils/server-side-helper/app/with-anti-bot'; + +export const GET = withIgnoreBot(async function ( + _request: Request, + { params }: { params: { slug: string } } +) { + const slug = params.slug; + try { + const siren = verifySiren(slug); + const immatriculation = await getImmatriculationRNE(siren); + return Response.json(immatriculation, { status: 200 }); + } catch (e: any) { + return Response.json( + { message: 'failed to fetch RNEImmatriculation' }, + { status: 500 } + ); + } +}); diff --git a/clients/api-entreprise/carte-professionnelle-travaux-publics/index.ts b/clients/api-entreprise/carte-professionnelle-travaux-publics/index.ts index a47eda98c..63d7bd298 100644 --- a/clients/api-entreprise/carte-professionnelle-travaux-publics/index.ts +++ b/clients/api-entreprise/carte-professionnelle-travaux-publics/index.ts @@ -1,6 +1,6 @@ import routes from '#clients/routes'; import { ICarteProfessionnelleTravauxPublics } from '#models/espace-agent/carte-professionnelle-travaux-publics'; -import { Siren, Siret } from '#utils/helpers'; +import { Siren } from '#utils/helpers'; import clientAPIEntreprise, { IAPIEntrepriseResponse } from '../client'; export type IAPIEntrepriseCarteProfessionnelleTravauxPublics = @@ -14,7 +14,7 @@ export type IAPIEntrepriseCarteProfessionnelleTravauxPublics = */ export const clientApiEntrepriseCarteProfessionnelleTravauxPublics = async ( siren: Siren, - recipientSiret: Siret | undefined + recipientSiret?: string ) => { return await clientAPIEntreprise< IAPIEntrepriseCarteProfessionnelleTravauxPublics, diff --git a/clients/api-entreprise/opqibi/index.ts b/clients/api-entreprise/opqibi/index.ts index 37a40a7c1..9aa937444 100644 --- a/clients/api-entreprise/opqibi/index.ts +++ b/clients/api-entreprise/opqibi/index.ts @@ -1,6 +1,6 @@ import routes from '#clients/routes'; import { IOpqibi } from '#models/espace-agent/certificats/opqibi'; -import { Siren, Siret } from '#utils/helpers'; +import { Siren } from '#utils/helpers'; import clientAPIEntreprise, { IAPIEntrepriseResponse } from '../client'; export type IAPIEntrepriseOpqibi = IAPIEntrepriseResponse<{ @@ -30,7 +30,7 @@ export type IAPIEntrepriseOpqibi = IAPIEntrepriseResponse<{ */ export const clientApiEntrepriseOpqibi = async ( siren: Siren, - recipientSiret: Siret | undefined + recipientSiret?: string ) => { return await clientAPIEntreprise( `${ diff --git a/clients/api-entreprise/qualibat/index.ts b/clients/api-entreprise/qualibat/index.ts index cece23e27..fd110215a 100644 --- a/clients/api-entreprise/qualibat/index.ts +++ b/clients/api-entreprise/qualibat/index.ts @@ -31,7 +31,7 @@ export type IAPIEntrepriseQualibat = IAPIEntrepriseResponse<{ */ export const clientApiEntrepriseQualibat = async ( siret: Siret, - recipientSiret: Siret | undefined + recipientSiret?: string ) => { return await clientAPIEntreprise( `${ diff --git a/clients/api-entreprise/qualifelec/index.ts b/clients/api-entreprise/qualifelec/index.ts index 06cf518d0..bbe24fc54 100644 --- a/clients/api-entreprise/qualifelec/index.ts +++ b/clients/api-entreprise/qualifelec/index.ts @@ -53,7 +53,7 @@ export type IAPIEntrepriseQualifelec = IAPIEntrepriseResponse< */ export const clientApiEntrepriseQualifelec = async ( siret: Siret, - recipientSiret: Siret | undefined + recipientSiret?: string ) => { return await clientAPIEntreprise( `${ diff --git a/clients/routes.ts b/clients/routes.ts index 5e53ded71..8538a1e46 100644 --- a/clients/routes.ts +++ b/clients/routes.ts @@ -1,16 +1,23 @@ const routes = { api: { - rne: { - documents: { - download: '/api/download/espace-agent/documents/', - list: '/api/data-fetching/espace-agent/RNE-documents/', - }, - }, tva: '/api/data-fetching/verify-tva/', - conformite: '/api/data-fetching/espace-agent/conformite/', - carteProfessionnelleTravauxPublics: - '/api/data-fetching/espace-agent/carte-professionnelle-TP/', association: '/api/data-fetching/association/', + rne: '/api/data-fetching/rne/', + espaceAgent: { + qualibat: '/api/data-fetching/espace-agent/qualibat/', + qualifelec: '/api/data-fetching/espace-agent/qualifelec/', + opqibi: '/api/data-fetching/espace-agent/opqibi/', + conformite: '/api/data-fetching/espace-agent/conformite/', + carteProfessionnelleTravauxPublics: + '/api/data-fetching/espace-agent/carte-professionnelle-TP/', + rcsMandataires: '/api/data-fetching/espace-agent/rcs-mandataires/', + rne: { + documents: { + download: '/api/download/espace-agent/documents/', + list: '/api/data-fetching/espace-agent/rne/documents/', + }, + }, + }, }, apiEntreprise: { conformite: { @@ -169,6 +176,7 @@ const routes = { }, infogreffe: { portail: { + home: 'https://www.infogreffe.fr', entreprise: 'https://www.infogreffe.fr/entreprise/', }, }, diff --git a/components-ui/horizontal-separator/index.tsx b/components-ui/horizontal-separator/index.tsx index 1ba9a861f..db405a3f0 100644 --- a/components-ui/horizontal-separator/index.tsx +++ b/components-ui/horizontal-separator/index.tsx @@ -6,8 +6,8 @@ export const SimpleSeparator = () => ( export const HorizontalSeparator = () => (
- - - + + +
); diff --git a/components-ui/horizontal-separator/styles.module.css b/components-ui/horizontal-separator/styles.module.css index e086d0982..75ba997b9 100644 --- a/components-ui/horizontal-separator/styles.module.css +++ b/components-ui/horizontal-separator/styles.module.css @@ -9,14 +9,14 @@ width: 100%; margin: 40px 0; } -.horizontalSeparator > span.line { +.horizontalSeparatorLine { width: 50px; background-color: var(--annuaire-colors-pastelBlue); height: 2px; margin: 0 10px; } -.horizontalSeparator > span.circle { +.horizontalSeparatorCircle { width: 7px; height: 7px; border-radius: 20px; diff --git a/components/badges-section/labels-and-certificates/protected-certificats.tsx b/components/badges-section/labels-and-certificates/protected-certificats.tsx index 2ba4263d7..399a96f62 100644 --- a/components/badges-section/labels-and-certificates/protected-certificats.tsx +++ b/components/badges-section/labels-and-certificates/protected-certificats.tsx @@ -1,68 +1,87 @@ +'use client'; + import { Icon } from '#components-ui/icon/wrapper'; +import { Loader } from '#components-ui/loader'; import NonRenseigne from '#components/non-renseigne'; +import { isAPILoading } from '#models/api-loading'; import { isAPINotResponding } from '#models/api-not-responding'; import constants from '#models/constants'; -import { getOpqibi } from '#models/espace-agent/certificats/opqibi'; -import { getQualibat } from '#models/espace-agent/certificats/qualibat'; -import { getQualifelec } from '#models/espace-agent/certificats/qualifelec'; -import { ISession } from '#models/user/session'; +import { useFetchOpqibi } from 'hooks/fetch/espace-agent/opqibi'; +import { useFetchQualibat } from 'hooks/fetch/espace-agent/qualibat'; +import { useFetchQualifelec } from 'hooks/fetch/espace-agent/qualifelec'; +import { + LabelsAndCertificatesBadgesSection, + checkHasLabelsAndCertificates, +} from '.'; import { IUniteLegale } from '../../../models/core/types'; import { LabelWithLinkToSection } from './label-with-link-to-section'; export const ProtectedCertificatesBadgesSection: React.FC<{ uniteLegale: IUniteLegale; - session: ISession | null; - hasOtherCertificates: boolean; -}> = async ({ uniteLegale, session, hasOtherCertificates }) => { - const [opqibi, qualifelec, qualibat] = await Promise.all([ - getOpqibi(uniteLegale.siren, session?.user?.siret), - getQualifelec(uniteLegale.siege.siret, session?.user?.siret), - getQualibat(uniteLegale.siege.siret, session?.user?.siret), - ]); +}> = ({ uniteLegale }) => { + const hasOtherCertificates = checkHasLabelsAndCertificates(uniteLegale); + const opqibi = useFetchOpqibi(uniteLegale); + const qualibat = useFetchQualibat(uniteLegale); + const qualifelec = useFetchQualifelec(uniteLegale); if ( isAPINotResponding(opqibi) && isAPINotResponding(qualibat) && isAPINotResponding(qualifelec) ) { - return hasOtherCertificates ? null : ; + return hasOtherCertificates ? ( + + ) : ( + + ); + } + + if ( + isAPILoading(opqibi) || + isAPILoading(qualibat) || + isAPILoading(qualifelec) + ) { + return ; } return ( -
- - {!isAPINotResponding(opqibi) && ( - - )} - {!isAPINotResponding(qualibat) && ( - - )} - {!isAPINotResponding(qualifelec) && ( - - )} - -
+ <> + +
+ + {!isAPINotResponding(opqibi) && ( + + )} + {!isAPINotResponding(qualibat) && ( + + )} + {!isAPINotResponding(qualifelec) && ( + + )} + +
+ ); }; diff --git a/components/espace-agent-components/certifications/opqibi-section.tsx b/components/espace-agent-components/certifications/opqibi-section.tsx index 9da630c8f..c6fafccd9 100644 --- a/components/espace-agent-components/certifications/opqibi-section.tsx +++ b/components/espace-agent-components/certifications/opqibi-section.tsx @@ -1,20 +1,37 @@ +'use client'; + import FAQLink from '#components-ui/faq-link'; -import { AsyncDataSectionServer } from '#components/section/data-section/server'; +import { DataSectionClient } from '#components/section/data-section'; import { TwoColumnTable } from '#components/table/simple'; import { EAdministration } from '#models/administrations/EAdministration'; -import { IAPINotRespondingError } from '#models/api-not-responding'; +import { IUniteLegale } from '#models/core/types'; import { IOpqibi } from '#models/espace-agent/certificats/opqibi'; import { formatDateLong } from '#utils/helpers'; +import { useFetchOpqibi } from 'hooks/fetch/espace-agent/opqibi'; export const OpqibiSection: React.FC<{ - opqibi: Promise; -}> = ({ opqibi }) => { + uniteLegale: IUniteLegale; +}> = ({ uniteLegale }) => { + const opqibi = useFetchOpqibi(uniteLegale); return ( - + Cette entreprise n’a pas de{' '} + + certificat Opqibi + + . + + } sources={[EAdministration.DINUM]} data={opqibi} > @@ -100,7 +117,7 @@ export const OpqibiSection: React.FC<{ )} )} - + ); }; diff --git a/components/espace-agent-components/certifications/qualibat-section.tsx b/components/espace-agent-components/certifications/qualibat-section.tsx index 1e52facae..acfebe83c 100644 --- a/components/espace-agent-components/certifications/qualibat-section.tsx +++ b/components/espace-agent-components/certifications/qualibat-section.tsx @@ -1,21 +1,37 @@ +'use client'; + import ButtonLink from '#components-ui/button'; -import { AsyncDataSectionServer } from '#components/section/data-section/server'; +import { DataSectionClient } from '#components/section/data-section'; import { TwoColumnTable } from '#components/table/simple'; import { EAdministration } from '#models/administrations/EAdministration'; -import { IAPINotRespondingError } from '#models/api-not-responding'; -import { IQualibat } from '#models/espace-agent/certificats/qualibat'; +import { IUniteLegale } from '#models/core/types'; import { formatDateLong } from '#utils/helpers'; +import { useFetchQualibat } from 'hooks/fetch/espace-agent/qualibat'; -export const QualibatSection: React.FC<{ - qualibat: Promise; -}> = ({ qualibat }) => { +export const QualibatSection: React.FC<{ uniteLegale: IUniteLegale }> = ({ + uniteLegale, +}) => { + const qualibat = useFetchQualibat(uniteLegale); return ( - + Cette entreprise n’a pas de{' '} + + certificat Qualibat + + . + + } data={qualibat} > {(qualibat) => ( @@ -78,6 +94,6 @@ export const QualibatSection: React.FC<{ /> )} - + ); }; diff --git a/components/espace-agent-components/certifications/qualifelec-section.tsx b/components/espace-agent-components/certifications/qualifelec-section.tsx index 861df5973..d568e3864 100644 --- a/components/espace-agent-components/certifications/qualifelec-section.tsx +++ b/components/espace-agent-components/certifications/qualifelec-section.tsx @@ -1,21 +1,38 @@ +'use client'; + import ButtonLink from '#components-ui/button'; -import { AsyncDataSectionServer } from '#components/section/data-section/server'; +import { DataSectionClient } from '#components/section/data-section'; import { FullTable } from '#components/table/full'; import { EAdministration } from '#models/administrations/EAdministration'; -import { IAPINotRespondingError } from '#models/api-not-responding'; -import { IQualifelec } from '#models/espace-agent/certificats/qualifelec'; +import { IUniteLegale } from '#models/core/types'; import { formatDate, formatDateLong } from '#utils/helpers'; +import { useFetchQualifelec } from 'hooks/fetch/espace-agent/qualifelec'; -type IProps = { - qualifelec: Promise; -}; -export async function QualifelecSection({ qualifelec }: IProps) { +export function QualifelecSection({ + uniteLegale, +}: { + uniteLegale: IUniteLegale; +}) { + const qualifelec = useFetchQualifelec(uniteLegale); return ( - + Cette entreprise n’a pas de{' '} + + certificat Qualifelec + + . + + } sources={[EAdministration.DINUM]} data={qualifelec} > @@ -72,6 +89,6 @@ export async function QualifelecSection({ qualifelec }: IProps) { /> )} - + ); } diff --git a/components/espace-agent-components/conformite-section.tsx b/components/espace-agent-components/conformite-section.tsx index 051545c83..07f535f27 100644 --- a/components/espace-agent-components/conformite-section.tsx +++ b/components/espace-agent-components/conformite-section.tsx @@ -1,26 +1,22 @@ +'use client'; + import { PrintNever } from '#components-ui/print-visibility'; -import { DataSectionServer } from '#components/section/data-section'; +import { AsyncDataSectionClient } from '#components/section/data-section/client'; import { TwoColumnTable } from '#components/table/simple'; import { EAdministration } from '#models/administrations/EAdministration'; import { IUniteLegale } from '#models/core/types'; -import { getConformiteEntreprise } from '#models/espace-agent/conformite'; -import { ISession } from '#models/user/session'; +import useFetchConformite from 'hooks/fetch/conformite'; import Conformite from './conformite'; interface IProps { uniteLegale: IUniteLegale; - session: ISession | null; } -async function ConformiteSection({ uniteLegale, session }: IProps) { - const conformite = getConformiteEntreprise( - uniteLegale.siren, - uniteLegale.siege.siret, - session?.user?.siret - ); +function ConformiteSection({ uniteLegale }: IProps) { + const conformite = useFetchConformite(uniteLegale); return ( - )} - + ); } diff --git a/components/espace-agent-components/documents/actes-walled.tsx b/components/espace-agent-components/documents/actes-walled.tsx index a10480c92..7fc07cd3a 100644 --- a/components/espace-agent-components/documents/actes-walled.tsx +++ b/components/espace-agent-components/documents/actes-walled.tsx @@ -1,5 +1,4 @@ import { IUniteLegale } from '#models/core/types'; -import { getDocumentsRNEProtected } from '#models/immatriculation/rne'; import { EScope, hasRights } from '#models/user/rights'; import { ISession } from '#models/user/session'; import AgentWallDocuments from '../agent-wall/document'; @@ -8,7 +7,7 @@ import { AgentActesSection } from './data-section/actes'; const ActesSection: React.FC<{ uniteLegale: IUniteLegale; session: ISession | null; -}> = async ({ uniteLegale, session }) => { +}> = ({ uniteLegale, session }) => { if (!hasRights(session, EScope.actesRne)) { return ( ); } - const documents = getDocumentsRNEProtected(uniteLegale.siren); - return ; + return ; }; export default ActesSection; diff --git a/components/espace-agent-components/documents/bilans-walled.tsx b/components/espace-agent-components/documents/bilans-walled.tsx index 9ac295dd8..8a562604e 100644 --- a/components/espace-agent-components/documents/bilans-walled.tsx +++ b/components/espace-agent-components/documents/bilans-walled.tsx @@ -1,5 +1,4 @@ import { IUniteLegale } from '#models/core/types'; -import { getDocumentsRNEProtected } from '#models/immatriculation/rne'; import { EScope, hasRights } from '#models/user/rights'; import { ISession } from '#models/user/session'; import AgentWallDocuments from '../agent-wall/document'; @@ -8,7 +7,7 @@ import AgentBilansSection from './data-section/bilans'; const BilansSection: React.FC<{ uniteLegale: IUniteLegale; session: ISession | null; -}> = async ({ uniteLegale, session }) => { +}> = ({ uniteLegale, session }) => { if (!hasRights(session, EScope.bilansRne)) { return ( ); } - const documents = getDocumentsRNEProtected(uniteLegale.siren); - return ; + return ; }; export default BilansSection; diff --git a/components/espace-agent-components/documents/data-section/actes.tsx b/components/espace-agent-components/documents/data-section/actes.tsx index 563da177a..3057b8f0e 100644 --- a/components/espace-agent-components/documents/data-section/actes.tsx +++ b/components/espace-agent-components/documents/data-section/actes.tsx @@ -3,12 +3,10 @@ import routes from '#clients/routes'; import { Warning } from '#components-ui/alerts'; import ButtonLink from '#components-ui/button'; -import { PrintNever } from '#components-ui/print-visibility'; import ShowMore from '#components-ui/show-more'; -import { AsyncDataSectionServer } from '#components/section/data-section/server'; +import { DataSectionClient } from '#components/section/data-section'; import { FullTable } from '#components/table/full'; import { EAdministration } from '#models/administrations/EAdministration'; -import { IAPINotRespondingError } from '#models/api-not-responding'; import { IUniteLegale, isAssociation, @@ -16,6 +14,7 @@ import { } from '#models/core/types'; import { IActesRNE } from '#models/immatriculation'; import { formatDateLong } from '#utils/helpers'; +import useFetchRNEDocuments from 'hooks/fetch/RNE-documents'; const NoDocument = () => ( <>Aucun document n’a été retrouvé dans le RNE pour cette entreprise. @@ -23,56 +22,55 @@ const NoDocument = () => ( export const AgentActesSection: React.FC<{ uniteLegale: IUniteLegale; - documents: Promise; -}> = ({ uniteLegale, documents }) => { +}> = ({ uniteLegale }) => { + const documents = useFetchRNEDocuments(uniteLegale); + return ( - - + {(isAssociation(uniteLegale) || isServicePublic(uniteLegale)) && ( + <> + + Les associations et les services publics ne sont pas + immatriculés au RNE. + +
+ + )} + + + } + > + {(documents) => + documents.actes?.length === 0 ? ( + + ) : ( <> - {(isAssociation(uniteLegale) || isServicePublic(uniteLegale)) && ( - <> - - Les associations et les services publics ne sont pas - immatriculés au RNE. - -
- +

+ Cette entreprise possède {documents.actes.length} document(s) au + RNE. Chaque document peut contenir un ou plusieurs actes : +

+ {documents.actes.length >= 5 ? ( + + + + ) : ( + )} - - } - > - {(documents) => - documents.actes?.length === 0 ? ( - - ) : ( - <> -

- Cette entreprise possède {documents.actes.length} document(s) au - RNE. Chaque document peut contenir un ou plusieurs actes : -

- {documents.actes.length >= 5 ? ( - - - - ) : ( - - )} - - ) - } -
-
+ ) + } + ); }; @@ -96,7 +94,7 @@ function ActesTable({ actes }: IActesTableProps) { target="_blank" alt small - to={`${routes.api.rne.documents.download}${a.id}?type=acte`} + to={`${routes.api.espaceAgent.rne.documents.download}${a.id}?type=acte`} > Télécharger , diff --git a/components/espace-agent-components/documents/data-section/bilans.tsx b/components/espace-agent-components/documents/data-section/bilans.tsx index 6b29ad78d..be61bc26d 100644 --- a/components/espace-agent-components/documents/data-section/bilans.tsx +++ b/components/espace-agent-components/documents/data-section/bilans.tsx @@ -4,20 +4,18 @@ import routes from '#clients/routes'; import { Warning } from '#components-ui/alerts'; import ButtonLink from '#components-ui/button'; import FAQLink from '#components-ui/faq-link'; -import { PrintNever } from '#components-ui/print-visibility'; import { Tag } from '#components-ui/tag'; -import { AsyncDataSectionServer } from '#components/section/data-section/server'; +import { AsyncDataSectionClient } from '#components/section/data-section/client'; import { FullTable } from '#components/table/full'; import { EAdministration } from '#models/administrations/EAdministration'; -import { IAPINotRespondingError } from '#models/api-not-responding'; import { IUniteLegale, isAssociation, isServicePublic, } from '#models/core/types'; -import { IActesRNE } from '#models/immatriculation'; import { formatDateLong } from '#utils/helpers'; import { getFiscalYear } from '#utils/helpers/formatting/format-fiscal-year'; +import useFetchRNEDocuments from 'hooks/fetch/RNE-documents'; const NoBilans = () => ( <>Aucun comptes n’a été déposé au RNE pour cette entreprise. @@ -25,77 +23,75 @@ const NoBilans = () => ( const AgentBilansSection: React.FC<{ uniteLegale: IUniteLegale; - documents: Promise; -}> = ({ uniteLegale, documents }) => { +}> = ({ uniteLegale }) => { + const documents = useFetchRNEDocuments(uniteLegale); return ( - - - {(isAssociation(uniteLegale) || isServicePublic(uniteLegale)) && ( - <> - - Les associations et les services publics ne sont pas - immatriculés au RNE. - -
- - )} - - - } - > - {(documents) => - documents.bilans?.length === 0 ? ( - - ) : ( + + {(isAssociation(uniteLegale) || isServicePublic(uniteLegale)) && ( <> -

- Cette entreprise possède {documents.bilans.length} bilan(s) - déposé(s) au RNE{' '} - {documents.hasBilanConsolide && ( - <> - , dont certains sont des{' '} - - Qu’est-ce qu’un bilan consolidé ? - - - )}{' '} - : -

- [ - formatDateLong(a.dateDepot), - <> - {getFiscalYear(a.dateCloture)}{' '} - {a.typeBilan === 'K' && ( - bilan consolidé - )} - , - - Télécharger - , - ])} - /> + + Les associations et les services publics ne sont pas + immatriculés au RNE. + +
- ) - } -
-
+ )} + + + } + > + {(documents) => + documents.bilans?.length === 0 ? ( + + ) : ( + <> +

+ Cette entreprise possède {documents.bilans.length} bilan(s) + déposé(s) au RNE{' '} + {documents.hasBilanConsolide && ( + <> + , dont certains sont des{' '} + + Qu’est-ce qu’un bilan consolidé ? + + + )}{' '} + : +

+ [ + formatDateLong(a.dateDepot), + <> + {getFiscalYear(a.dateCloture)}{' '} + {a.typeBilan === 'K' && ( + bilan consolidé + )} + , + + Télécharger + , + ])} + /> + + ) + } + ); }; diff --git a/components/page-loader/index.tsx b/components/page-loader/index.tsx deleted file mode 100644 index bb511b1da..000000000 --- a/components/page-loader/index.tsx +++ /dev/null @@ -1,12 +0,0 @@ -'use client'; - -import { Loader } from '#components-ui/loader'; -import style from './style.module.css'; - -export function PageLoader() { - return ( -
- Chargement des données en cours -
- ); -} diff --git a/components/page-loader/style.module.css b/components/page-loader/style.module.css deleted file mode 100644 index 9e8201e5e..000000000 --- a/components/page-loader/style.module.css +++ /dev/null @@ -1,16 +0,0 @@ -.loader { - min-height: 500px; - opacity: 0; - /* animate after 500ms during 200ms */ - animation: fadeIn 200ms 300ms forwards; -} - -@keyframes fadeIn { - 0% { - opacity: 0; - } - - 100% { - opacity: 1; - } -} \ No newline at end of file diff --git a/components/search-results/results-list.tsx b/components/search-results/results-list.tsx index 2d4dd4670..b7fef51f4 100644 --- a/components/search-results/results-list.tsx +++ b/components/search-results/results-list.tsx @@ -10,7 +10,7 @@ import { import { isCollectiviteTerritoriale } from '#models/core/types'; import { IDirigeant } from '#models/immatriculation'; import { ISearchResult } from '#models/search'; -import { isPersonneMorale } from 'app/(header-default)/dirigeants/_component/sections/is-personne-morale'; +import { isPersonneMorale } from 'app/(header-default)/dirigeants/[slug]/_component/sections/is-personne-morale'; import styles from './style.module.css'; type IProps = { diff --git a/components/section/data-section/style.module.css b/components/section/data-section/style.module.css index dfa209f60..94cd8c89c 100644 --- a/components/section/data-section/style.module.css +++ b/components/section/data-section/style.module.css @@ -1,5 +1,16 @@ .loader { - /* Composes loader from page-loader */ - composes: loader from 'components/page-loader/style.module.css'; - min-height: 0px; -} \ No newline at end of file + min-height: 0px; + opacity: 0; + /* animate after 500ms during 200ms */ + animation: fadeIn 200ms 300ms forwards; +} + +@keyframes fadeIn { + 0% { + opacity: 0; + } + + 100% { + opacity: 1; + } +} diff --git a/components/unite-legale-section/index.tsx b/components/unite-legale-section/index.tsx index 161633bac..20e1ec132 100644 --- a/components/unite-legale-section/index.tsx +++ b/components/unite-legale-section/index.tsx @@ -1,4 +1,4 @@ -import React, { Suspense } from 'react'; +import React from 'react'; import FAQLink from '#components-ui/faq-link'; import { HorizontalSeparator } from '#components-ui/horizontal-separator'; import { ConventionCollectivesBadgesSection } from '#components/badges-section/convention-collectives'; @@ -102,30 +102,29 @@ const UniteLegaleSection: React.FC<{ siren={uniteLegale.siren} />, ], - // jump line and add label and certificates - ...(hasLabelsAndCertificates || - hasRights(session, EScope.protectedCertificats) + // agents : we dont know yet if there are labels and certifs + ...(hasRights(session, EScope.protectedCertificats) ? [ ['',
], [ `${ checkHasQuality(uniteLegale) ? 'Qualités, l' : 'L' }abels et certificats`, - <> - - {hasRights(session, EScope.protectedCertificats) && ( - - - - )} - , + , ], ] - : []), + : hasLabelsAndCertificates + ? [ + ['',
], + [ + `${ + checkHasQuality(uniteLegale) ? 'Qualités, l' : 'L' + }abels et certificats`, + , + ], + ] + : // open data and no certif : we can hide the whole line + []), ['',
], [ 'Justificatif(s) d’existence', diff --git a/cypress/e2e/data-fetching.cy.js b/cypress/e2e/data-fetching.cy.js index a3e248fc7..b6014819f 100644 --- a/cypress/e2e/data-fetching.cy.js +++ b/cypress/e2e/data-fetching.cy.js @@ -6,6 +6,20 @@ describe('Data fetching routes', () => { }).then((resp) => { expect(resp.status).to.eq(403); }); + + cy.request({ + url: '/api/data-fetching/espace-agent/conformite/552032534', + failOnStatusCode: false, + }).then((resp) => { + expect(resp.status).to.eq(403); + }); + + cy.request({ + url: '/api/data-fetching/espace-agent/rne/documents/552032534', + failOnStatusCode: false, + }).then((resp) => { + expect(resp.status).to.eq(403); + }); }); it('Bot-Protected routes are unauthorized', () => { cy.request({ @@ -14,5 +28,12 @@ describe('Data fetching routes', () => { }).then((resp) => { expect(resp.status).to.eq(401); }); + + cy.request({ + url: '/api/data-fetching/association/552032534', + failOnStatusCode: false, + }).then((resp) => { + expect(resp.status).to.eq(401); + }); }); }); diff --git a/hooks/fetch/RCS-mandataires.ts b/hooks/fetch/RCS-mandataires.ts new file mode 100644 index 000000000..c7c631c75 --- /dev/null +++ b/hooks/fetch/RCS-mandataires.ts @@ -0,0 +1,37 @@ +import routes from '#clients/routes'; +import { EAdministration } from '#models/administrations/EAdministration'; +import { IUniteLegale } from '#models/core/types'; +import { FetchRessourceException } from '#models/exceptions'; +import { IDirigeant } from '#models/immatriculation'; +import { httpGet } from '#utils/network'; +import logErrorInSentry from '#utils/sentry'; +import { useFetchData } from './use-fetch-data'; + +export function useFetchRCSMandataires(uniteLegale: IUniteLegale) { + const { siren } = uniteLegale; + + return useFetchData( + { + fetchData: () => + httpGet>( + routes.api.espaceAgent.rcsMandataires + siren + ), + administration: EAdministration.INFOGREFFE, + logError: (e: any) => { + if (e.status) { + return; + } + logErrorInSentry( + new FetchRessourceException({ + ressource: 'RCSMandataires', + administration: EAdministration.INFOGREFFE, + cause: e, + }) + ); + }, + }, + [siren] + ); +} + +export default useFetchRCSMandataires; diff --git a/hooks/fetch/RNE-documents.ts b/hooks/fetch/RNE-documents.ts index 92c8e82c7..96b3cfba2 100644 --- a/hooks/fetch/RNE-documents.ts +++ b/hooks/fetch/RNE-documents.ts @@ -12,7 +12,7 @@ export function useFetchRNEDocuments(uniteLegale: IUniteLegale) { return useFetchData( { fetchData: () => - httpGet(routes.api.rne.documents.list + siren), + httpGet(routes.api.espaceAgent.rne.documents.list + siren), administration: EAdministration.INPI, logError: (e: any) => { if (e.status) { diff --git a/hooks/fetch/RNE-immatriculation copy.ts b/hooks/fetch/RNE-immatriculation copy.ts new file mode 100644 index 000000000..f66407d7f --- /dev/null +++ b/hooks/fetch/RNE-immatriculation copy.ts @@ -0,0 +1,34 @@ +import routes from '#clients/routes'; +import { EAdministration } from '#models/administrations/EAdministration'; +import { IUniteLegale } from '#models/core/types'; +import { FetchRessourceException } from '#models/exceptions'; +import { IImmatriculationRNE } from '#models/immatriculation'; +import { httpGet } from '#utils/network'; +import logErrorInSentry from '#utils/sentry'; +import { useFetchData } from './use-fetch-data'; + +export function useFetchRNEImmatriculation(uniteLegale: IUniteLegale) { + const { siren } = uniteLegale; + + return useFetchData( + { + fetchData: () => httpGet(routes.api.rne + siren), + administration: EAdministration.INPI, + logError: (e: any) => { + if (e.status) { + return; + } + logErrorInSentry( + new FetchRessourceException({ + ressource: 'RNEImmatriculation', + administration: EAdministration.INPI, + cause: e, + }) + ); + }, + }, + [siren] + ); +} + +export default useFetchRNEImmatriculation; diff --git a/hooks/fetch/carte-professionnelle-TP.ts b/hooks/fetch/carte-professionnelle-TP.ts index 081f39f2b..54fdcb710 100644 --- a/hooks/fetch/carte-professionnelle-TP.ts +++ b/hooks/fetch/carte-professionnelle-TP.ts @@ -15,7 +15,7 @@ export function useFetchCarteProfessionnelleTP(uniteLegale: IUniteLegale) { { fetchData: () => httpGet( - routes.api.carteProfessionnelleTravauxPublics + siret + routes.api.espaceAgent.carteProfessionnelleTravauxPublics + siret ), administration: EAdministration.FNTP, logError: (e: any) => { diff --git a/hooks/fetch/conformite.ts b/hooks/fetch/conformite.ts index d2a73cb2c..8170192be 100644 --- a/hooks/fetch/conformite.ts +++ b/hooks/fetch/conformite.ts @@ -14,7 +14,9 @@ export function useFetchConformite(uniteLegale: IUniteLegale) { return useFetchData( { fetchData: () => - httpGet(routes.api.conformite + siret), + httpGet( + routes.api.espaceAgent.conformite + siret + ), administration: EAdministration.DINUM, logError: (e: any) => { if (e.status) { diff --git a/hooks/fetch/espace-agent/carte-professionnelle-travaux-publics-section.ts b/hooks/fetch/espace-agent/carte-professionnelle-travaux-publics-section.ts new file mode 100644 index 000000000..4a608eb31 --- /dev/null +++ b/hooks/fetch/espace-agent/carte-professionnelle-travaux-publics-section.ts @@ -0,0 +1,33 @@ +import routes from '#clients/routes'; +import { EAdministration } from '#models/administrations/EAdministration'; +import { IUniteLegale } from '#models/core/types'; +import { ICarteProfessionnelleTravauxPublics } from '#models/espace-agent/carte-professionnelle-travaux-publics'; +import { FetchRessourceException } from '#models/exceptions'; +import { verifySiren } from '#utils/helpers'; +import { httpGet } from '#utils/network'; +import logErrorInSentry from '#utils/sentry'; +import { useFetchData } from '../use-fetch-data'; + +export function useFetchCarteProfessionnelle(uniteLegale: IUniteLegale) { + return useFetchData( + { + fetchData: () => + httpGet( + routes.api.espaceAgent.opqibi + verifySiren(uniteLegale.siren) + ), + administration: EAdministration.DINUM, + logError: (e: any) => { + const exception = new FetchRessourceException({ + ressource: 'Opqibi', + administration: EAdministration.DINUM, + cause: e, + context: { + siren: uniteLegale.siren, + }, + }); + logErrorInSentry(exception); + }, + }, + [uniteLegale] + ); +} diff --git a/hooks/fetch/espace-agent/opqibi.ts b/hooks/fetch/espace-agent/opqibi.ts new file mode 100644 index 000000000..929d67375 --- /dev/null +++ b/hooks/fetch/espace-agent/opqibi.ts @@ -0,0 +1,33 @@ +import routes from '#clients/routes'; +import { EAdministration } from '#models/administrations/EAdministration'; +import { IUniteLegale } from '#models/core/types'; +import { IOpqibi } from '#models/espace-agent/certificats/opqibi'; +import { FetchRessourceException } from '#models/exceptions'; +import { verifySiren } from '#utils/helpers'; +import { httpGet } from '#utils/network'; +import logErrorInSentry from '#utils/sentry'; +import { useFetchData } from '../use-fetch-data'; + +export function useFetchOpqibi(uniteLegale: IUniteLegale) { + return useFetchData( + { + fetchData: () => + httpGet( + routes.api.espaceAgent.opqibi + verifySiren(uniteLegale.siren) + ), + administration: EAdministration.DINUM, + logError: (e: any) => { + const exception = new FetchRessourceException({ + ressource: 'Opqibi', + administration: EAdministration.DINUM, + cause: e, + context: { + siren: uniteLegale.siren, + }, + }); + logErrorInSentry(exception); + }, + }, + [uniteLegale] + ); +} diff --git a/hooks/fetch/espace-agent/qualibat.ts b/hooks/fetch/espace-agent/qualibat.ts new file mode 100644 index 000000000..f85755425 --- /dev/null +++ b/hooks/fetch/espace-agent/qualibat.ts @@ -0,0 +1,33 @@ +import routes from '#clients/routes'; +import { EAdministration } from '#models/administrations/EAdministration'; +import { IUniteLegale } from '#models/core/types'; +import { IQualibat } from '#models/espace-agent/certificats/qualibat'; +import { FetchRessourceException } from '#models/exceptions'; +import { verifySiret } from '#utils/helpers'; +import { httpGet } from '#utils/network'; +import logErrorInSentry from '#utils/sentry'; +import { useFetchData } from '../use-fetch-data'; + +export function useFetchQualibat(uniteLegale: IUniteLegale) { + return useFetchData( + { + fetchData: () => + httpGet( + routes.api.espaceAgent.qualibat + verifySiret(uniteLegale.siege.siret) + ), + administration: EAdministration.DINUM, + logError: (e: any) => { + const exception = new FetchRessourceException({ + ressource: 'Qualibat', + administration: EAdministration.DINUM, + cause: e, + context: { + siren: uniteLegale.siren, + }, + }); + logErrorInSentry(exception); + }, + }, + [uniteLegale] + ); +} diff --git a/hooks/fetch/espace-agent/qualifelec.ts b/hooks/fetch/espace-agent/qualifelec.ts new file mode 100644 index 000000000..7f51cf083 --- /dev/null +++ b/hooks/fetch/espace-agent/qualifelec.ts @@ -0,0 +1,34 @@ +import routes from '#clients/routes'; +import { EAdministration } from '#models/administrations/EAdministration'; +import { IUniteLegale } from '#models/core/types'; +import { IQualifelec } from '#models/espace-agent/certificats/qualifelec'; +import { FetchRessourceException } from '#models/exceptions'; +import { verifySiret } from '#utils/helpers'; +import { httpGet } from '#utils/network'; +import logErrorInSentry from '#utils/sentry'; +import { useFetchData } from '../use-fetch-data'; + +export function useFetchQualifelec(uniteLegale: IUniteLegale) { + return useFetchData( + { + fetchData: () => + httpGet( + routes.api.espaceAgent.qualifelec + + verifySiret(uniteLegale.siege.siret) + ), + administration: EAdministration.DINUM, + logError: (e: any) => { + const exception = new FetchRessourceException({ + ressource: 'Qualifelec', + administration: EAdministration.DINUM, + cause: e, + context: { + siren: uniteLegale.siren, + }, + }); + logErrorInSentry(exception); + }, + }, + [uniteLegale] + ); +} diff --git a/models/espace-agent/carte-professionnelle-travaux-publics.ts b/models/espace-agent/carte-professionnelle-travaux-publics.ts index 87b3fd17d..01d07deaa 100644 --- a/models/espace-agent/carte-professionnelle-travaux-publics.ts +++ b/models/espace-agent/carte-professionnelle-travaux-publics.ts @@ -1,16 +1,16 @@ import { clientApiEntrepriseCarteProfessionnelleTravauxPublics } from '#clients/api-entreprise/carte-professionnelle-travaux-publics'; import { IAPINotRespondingError } from '#models/api-not-responding'; -import { Siren, Siret } from '#utils/helpers'; +import { Siren } from '#utils/helpers'; import { handleApiEntrepriseError } from './utils'; export type ICarteProfessionnelleTravauxPublics = { documentUrl: string; }; export const getCarteProfessionnelleTravauxPublic = async ( siren: Siren, - siret?: Siret + recipientSiret?: string ): Promise => { return clientApiEntrepriseCarteProfessionnelleTravauxPublics( siren, - siret + recipientSiret ).catch((error) => handleApiEntrepriseError(error, { siren })); }; diff --git a/models/espace-agent/certificats/opqibi.ts b/models/espace-agent/certificats/opqibi.ts index 79457c883..a7ec3ba0a 100644 --- a/models/espace-agent/certificats/opqibi.ts +++ b/models/espace-agent/certificats/opqibi.ts @@ -1,6 +1,6 @@ import { clientApiEntrepriseOpqibi } from '#clients/api-entreprise/opqibi'; import { IAPINotRespondingError } from '#models/api-not-responding'; -import { Siren, Siret } from '#utils/helpers'; +import { Siren } from '#utils/helpers'; import { handleApiEntrepriseError } from '../utils'; type Qualification = { nom: string; @@ -22,7 +22,7 @@ export type IOpqibi = { export const getOpqibi = async ( siren: Siren, - recipientSiret: Siret | undefined + recipientSiret?: string ): Promise => { return clientApiEntrepriseOpqibi(siren, recipientSiret).catch((error) => handleApiEntrepriseError(error, { siren }) diff --git a/models/espace-agent/certificats/qualibat.ts b/models/espace-agent/certificats/qualibat.ts index 79620e5ae..8eb231b38 100644 --- a/models/espace-agent/certificats/qualibat.ts +++ b/models/espace-agent/certificats/qualibat.ts @@ -26,7 +26,7 @@ export type IQualibat = { export const getQualibat = async ( siret: Siret, - recipientSiret: Siret | undefined + recipientSiret?: string ): Promise => { return clientApiEntrepriseQualibat(siret, recipientSiret).catch((error) => handleApiEntrepriseError(error, { siret }) diff --git a/models/espace-agent/certificats/qualifelec.ts b/models/espace-agent/certificats/qualifelec.ts index 1c6bd5bd9..869058613 100644 --- a/models/espace-agent/certificats/qualifelec.ts +++ b/models/espace-agent/certificats/qualifelec.ts @@ -42,7 +42,7 @@ export type IQualifelec = Array<{ }>; export const getQualifelec = async ( siret: Siret, - recipientSiret: Siret | undefined + recipientSiret?: string ): Promise => { return clientApiEntrepriseQualifelec(siret, recipientSiret).catch((error) => handleApiEntrepriseError(error, { siret })