diff --git a/shared/constants/erps.ts b/shared/constants/erps.ts deleted file mode 100644 index 8f3a2b66e..000000000 --- a/shared/constants/erps.ts +++ /dev/null @@ -1,99 +0,0 @@ -import { sortAlphabeticallyBy } from "../utils"; - -interface ERP { - id: string; - name: string; - helpFilePath?: string; - helpFileSize?: string; - apiV3?: boolean; - disabled?: boolean; -} - -export const ERPS = sortAlphabeticallyBy("name", [ - { - id: "gesti", - name: "Gesti", - apiV3: true, - helpFilePath: "/Gestibase-2024.pdf", - }, - { - id: "ymag", - name: "Ypareo", - apiV3: true, - helpFilePath: "/Ypareo-2024.pdf", - }, - { - id: "scform", - name: "SC Form", - apiV3: true, - helpFilePath: "/SC-form-2024.pdf", - }, - { - id: "formasup", - name: "Formasup", - }, - { - id: "fcamanager", - name: "FCA Manager", - helpFilePath: "https://files.tableau-de-bord.apprentissage.beta.gouv.fr/pas-a-pas/fcamanager.pdf", - helpFileSize: "288 ko", - }, - { - id: "aimaira", - name: "Aimaira", - apiV3: true, - helpFilePath: "/Aimaira-2024.pdf", - }, - { - id: "filiz", - name: "Filiz", - apiV3: true, - }, - { - id: "hyperplanning", - name: "Hyperplanning", - apiV3: true, - }, - { - id: "gescicca", - name: "Gescicca (CNAM)", - apiV3: true, - }, - { - id: "charlemagne", - name: "Charlemagne", - apiV3: true, - }, - { - id: "formasup-hdf", - name: "Formasup HDF", - apiV3: true, - }, - { - id: "ammon", - name: "Ammon", - apiV3: true, - disabled: true, - }, - { - id: "formasup-paca", - name: "Cactus", - apiV3: true, - disabled: false, - }, -] satisfies ERP[]); - -export const ERPS_BY_ID = ERPS.reduce( - (acc, erp) => { - acc[erp.id] = erp; - return acc; - }, - {} as Record -); - -// obsolète, utilisé par les anciens composants uniquement -export const ERPS_FORM: any[] = [ - ...ERPS, - { id: "AUTRE", name: "Autre ERP", state: "otherErp" }, - { id: "NON", name: "Je n'ai pas d'ERP", state: "noErp" }, -]; diff --git a/shared/constants/index.ts b/shared/constants/index.ts index bee54895f..611ff2891 100644 --- a/shared/constants/index.ts +++ b/shared/constants/index.ts @@ -1,7 +1,6 @@ export * from "./aide"; export * from "./dossierApprenant"; export * from "./effectifs"; -export * from "./erps"; export * from "./fiabilisation"; export * from "./indicateurs"; export * from "./networks"; diff --git a/ui/hooks/useErp.ts b/ui/hooks/useErp.ts new file mode 100644 index 000000000..1f319a4b6 --- /dev/null +++ b/ui/hooks/useErp.ts @@ -0,0 +1,22 @@ +import { useQuery } from "@tanstack/react-query"; + +import { _get } from "@/common/httpClient"; + +export const useErp = () => { + const { data: erps, isLoading, error, refetch } = useQuery(["erps"], () => _get("/api/v1/erps")); + + const erpsById = erps + ? erps.reduce((acc, erp) => { + acc[erp.unique_id] = erp; + return acc; + }, {}) + : []; + + return { + erps, + erpsById, + isLoading, + error, + refetch, + }; +}; diff --git a/ui/modules/organismes/BandeauTransmission.tsx b/ui/modules/organismes/BandeauTransmission.tsx index 976349bdb..7315c5382 100644 --- a/ui/modules/organismes/BandeauTransmission.tsx +++ b/ui/modules/organismes/BandeauTransmission.tsx @@ -1,12 +1,13 @@ import { SystemProps, Text } from "@chakra-ui/react"; import { differenceInDays } from "date-fns"; -import { ERPS_BY_ID, TRANSMISSION_DONNEES_GROUP } from "shared"; +import { IErp, TRANSMISSION_DONNEES_GROUP } from "shared"; import { _get } from "@/common/httpClient"; import { Organisme } from "@/common/internal/Organisme"; import { formatDateDayMonthYear } from "@/common/utils/dateUtils"; import Link from "@/components/Links/Link"; import Ribbons from "@/components/Ribbons/Ribbons"; +import { useErp } from "@/hooks/useErp"; interface BandeauTransmissionProps { organisme: Organisme; @@ -23,9 +24,12 @@ function BandeauTransmission({ modeIndicateurs, ...props }: BandeauTransmissionProps & SystemProps) { + const { erpsById } = useErp(); return ( - {getContenuBandeauTransmission({ organisme, modePublique, modeIndicateurs })} + + {getContenuBandeauTransmission({ organisme, modePublique, modeIndicateurs, erpsById })} + ); } @@ -36,8 +40,9 @@ function getContenuBandeauTransmission({ organisme, modePublique, modeIndicateurs, -}: BandeauTransmissionProps): JSX.Element { - const erpName = organisme.erps?.map((erpId) => ERPS_BY_ID[erpId]?.name).join(", "); // généralement 1 seul ERP + erpsById, +}: BandeauTransmissionProps & { erpsById: Array }): JSX.Element { + const erpName = organisme.erps?.map((erpId) => erpsById[erpId]?.name).join(", "); // généralement 1 seul ERP if (modePublique) { return <>Cet établissement ne transmet pas encore ses effectifs au tableau de bord.; diff --git a/ui/pages/parametres.tsx b/ui/pages/parametres.tsx index d95f0548a..0d6a9492c 100644 --- a/ui/pages/parametres.tsx +++ b/ui/pages/parametres.tsx @@ -21,7 +21,7 @@ import { import { useRouter } from "next/router"; import { ReactNode, useEffect, useState } from "react"; import { CopyToClipboard } from "react-copy-to-clipboard"; -import { ERPS, ERPS_BY_ID } from "shared"; +import { IErp } from "shared"; import { CONTACT_ADDRESS } from "@/common/constants/product"; import { _delete, _post, _put } from "@/common/httpClient"; @@ -34,6 +34,7 @@ import SimplePage from "@/components/Page/SimplePage"; import Ribbons from "@/components/Ribbons/Ribbons"; import withAuth from "@/components/withAuth"; import { useOrganisationOrganisme } from "@/hooks/organismes"; +import { useErp } from "@/hooks/useErp"; import useToaster from "@/hooks/useToaster"; import { FileDownloadIcon } from "@/modules/dashboard/icons"; import NewTable from "@/modules/indicateurs/NewTable"; @@ -51,14 +52,18 @@ const ParametresPage = () => { "none" | "choix_erp" | "unsupported_erp" | "v2" | "v3" >("none"); const [selectedERPId, setSelectedERPId] = useState(""); + const [selectedERP, setSelectedERP] = useState({} as IErp); const [unsupportedERPName, setUnsupportedERPName] = useState(""); - const erp = ERPS_BY_ID[selectedERPId]; + const { erps, erpsById } = useErp(); const { organisme, refetch: refetchOrganisme } = useOrganisationOrganisme(); const erpV3 = (router.query.erpV3 as string | undefined)?.toLowerCase(); + useEffect(() => { + setSelectedERP(erpsById[selectedERPId]); + }, [selectedERPId]); // redirige vers la finalisation API v3 si le paramètre est présent (= on vient de connexion-api) useEffect(() => { if (!erpV3) { @@ -91,7 +96,7 @@ const ParametresPage = () => { <> Votre moyen de transmission est paramétré avec{" "} - {organisme.erps?.map((erpId) => ERPS_BY_ID[erpId]?.name).join(", ")}. + {organisme.erps?.map((erpId) => erpsById[erpId]?.name).join(", ")}. {organisme.mode_de_transmission_configuration_date && ( @@ -242,11 +247,13 @@ const ParametresPage = () => { - {ERPS.filter(({ disabled }) => !disabled).map((erp) => ( - - ))} + {erps + .filter(({ disabled }) => !disabled) + .map((erp) => ( + + ))}