Skip to content

Commit

Permalink
fix: ajout des erps en bdd (#3853)
Browse files Browse the repository at this point in the history
Co-authored-by: Paul Gaucher <[email protected]>
  • Loading branch information
Pomarom and Pomarom authored Oct 11, 2024
1 parent 6363fd7 commit 3f56fbb
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 115 deletions.
99 changes: 0 additions & 99 deletions shared/constants/erps.ts

This file was deleted.

1 change: 0 additions & 1 deletion shared/constants/index.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
22 changes: 22 additions & 0 deletions ui/hooks/useErp.ts
Original file line number Diff line number Diff line change
@@ -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<any, any>(["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,
};
};
13 changes: 9 additions & 4 deletions ui/modules/organismes/BandeauTransmission.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -23,9 +24,12 @@ function BandeauTransmission({
modeIndicateurs,
...props
}: BandeauTransmissionProps & SystemProps) {
const { erpsById } = useErp();
return (
<Ribbons variant="alert" {...props}>
<Text color="grey.800">{getContenuBandeauTransmission({ organisme, modePublique, modeIndicateurs })}</Text>
<Text color="grey.800">
{getContenuBandeauTransmission({ organisme, modePublique, modeIndicateurs, erpsById })}
</Text>
</Ribbons>
);
}
Expand All @@ -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<IErp> }): 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.</>;
Expand Down
35 changes: 24 additions & 11 deletions ui/pages/parametres.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";
Expand All @@ -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) {
Expand Down Expand Up @@ -91,7 +96,7 @@ const ParametresPage = () => {
<>
<Text fontSize="gamma" fontWeight="bold">
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(", ")}.
</Text>
{organisme.mode_de_transmission_configuration_date && (
<Text>
Expand Down Expand Up @@ -242,11 +247,13 @@ const ParametresPage = () => {
<option selected hidden disabled value="">
ERP...
</option>
{ERPS.filter(({ disabled }) => !disabled).map((erp) => (
<option value={erp.id} key={erp.id}>
{erp.name}
</option>
))}
{erps
.filter(({ disabled }) => !disabled)
.map((erp) => (
<option value={erp.unique_id} key={erp.unique_id}>
{erp.name}
</option>
))}

<option value="other" key="other">
J’utilise un autre ERP
Expand All @@ -271,7 +278,9 @@ const ParametresPage = () => {
px={6}
isDisabled={!selectedERPId}
onClick={() => {
setStepConfigurationERP(selectedERPId === "other" ? "unsupported_erp" : erp.apiV3 ? "v3" : "v2");
setStepConfigurationERP(
selectedERPId === "other" ? "unsupported_erp" : selectedERP.apiV3 ? "v3" : "v2"
);
}}
>
Confirmer
Expand Down Expand Up @@ -325,6 +334,7 @@ const ParametresPage = () => {
)}
{stepConfigurationERP === "v2" && (
<ConfigurationERPV2
erpsById={erpsById}
erpId={selectedERPId}
onBack={() => {
setStepConfigurationERP("choix_erp");
Expand All @@ -344,6 +354,7 @@ const ParametresPage = () => {

{stepConfigurationERP === "v3" && (
<ConfigurationERPV3
erpsById={erpsById}
organisme={organisme}
erpId={selectedERPId}
onGenerateKey={async () => {
Expand Down Expand Up @@ -381,10 +392,11 @@ interface ConfigurationERPV2Props {
erpId: string;
onBack: () => any;
onSubmit: () => any;
erpsById: Array<IErp>;
}
function ConfigurationERPV2(props: ConfigurationERPV2Props) {
const [configurationFinished, setConfigurationFinished] = useState(false);
const erp = ERPS_BY_ID[props.erpId];
const erp = props.erpsById[props.erpId];

return (
<VStack alignItems="start" gap={8}>
Expand Down Expand Up @@ -449,12 +461,13 @@ interface ConfigurationERPV3Props {
onConfigurationMismatch: () => any;
onBack: () => any;
onSubmit: () => any;
erpsById: Array<IErp>;
}
function ConfigurationERPV3(props: ConfigurationERPV3Props) {
const { toastSuccess } = useToaster();
const [copied, setCopied] = useState(false);

const erp = ERPS_BY_ID[props.erpId];
const erp = props.erpsById[props.erpId];
const verified = !!props.organisme.api_siret && !!props.organisme.api_uai;

if (!erp) {
Expand Down

0 comments on commit 3f56fbb

Please sign in to comment.