Skip to content

Commit 60114df

Browse files
committed
feat(admin): added alerts to certification structure page when the structure has no certification authority or no certification registry manager
1 parent 6779605 commit 60114df

File tree

5 files changed

+63
-26
lines changed

5 files changed

+63
-26
lines changed

packages/reva-admin-react/src/app/(admin)/certifications-v2/[certificationId]/page.tsx

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import { format } from "date-fns";
88
import { Accordion } from "@codegouvfr/react-dsfr/Accordion";
99
import Tag from "@codegouvfr/react-dsfr/Tag";
1010
import { SectionCard } from "@/components/card/section-card/SectionCard";
11-
import Alert from "@codegouvfr/react-dsfr/Alert";
1211
import { graphqlErrorToast, successToast } from "@/components/toast/toast";
12+
import { NoCertificationRegistryManagerAlert } from "./structure/_components/NoCertificationRegistryManagerAlert";
13+
import { NoCertificationAuthorityAlert } from "./structure/_components/NoCertificationAuthorityAlert";
1314

1415
type CertificationForPage = Exclude<
1516
ReturnType<typeof useUpdateCertificationPage>["certification"],
@@ -194,13 +195,7 @@ const PageContent = ({
194195
</Info>
195196
{!certification.certificationAuthorityStructure
196197
?.certificationRegistryManager && (
197-
<Alert
198-
data-test="no-certification-registry-manager-alert"
199-
className="mt-4"
200-
severity="warning"
201-
title="Cette structure certificatrice n’a aucun responsable des certifications pour le moment"
202-
description="Vous pouvez éditer et envoyer cette certification mais elle ne pourra être validée et publiée que par un responsable des certifications."
203-
/>
198+
<NoCertificationRegistryManagerAlert className="mt-4" />
204199
)}
205200
{certification.certificationAuthorities.length ? (
206201
<>
@@ -222,13 +217,7 @@ const PageContent = ({
222217
</ul>
223218
</>
224219
) : (
225-
<Alert
226-
data-test="no-certification-authority-alert"
227-
className="mt-4"
228-
severity="warning"
229-
title="Il n’y a pas de gestionnaire des candidatures pour cette certification"
230-
description="Malgré cela, elle sera visible des candidats et des AAP dès sa validation par le responsable des certifications. Lors du premier dossier de faisabilité envoyé, et s’il n’y a toujours pas de gestionnaire des candidatures, le support sera averti du problème."
231-
/>
220+
<NoCertificationAuthorityAlert className="mt-4" />
232221
)}
233222
</>
234223
)}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Alert } from "@codegouvfr/react-dsfr/Alert";
2+
3+
export const NoCertificationAuthorityAlert = ({
4+
className,
5+
}: {
6+
className?: string;
7+
}) => (
8+
<Alert
9+
data-test="no-certification-authority-alert"
10+
className={className}
11+
severity="warning"
12+
title="Il n’y a pas de gestionnaire des candidatures pour cette certification"
13+
description="Malgré cela, elle sera visible des candidats et des AAP dès sa validation par le responsable des certifications. Lors du premier dossier de faisabilité envoyé, et s’il n’y a toujours pas de gestionnaire des candidatures, le support sera averti du problème."
14+
/>
15+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Alert } from "@codegouvfr/react-dsfr/Alert";
2+
3+
export const NoCertificationRegistryManagerAlert = ({
4+
className,
5+
}: {
6+
className?: string;
7+
}) => (
8+
<Alert
9+
data-test="no-certification-registry-manager-alert"
10+
className={className}
11+
severity="warning"
12+
title="Cette structure certificatrice n’a aucun responsable des certifications pour le moment"
13+
description="Vous pouvez éditer et envoyer cette certification mais elle ne pourra être validée et publiée que par un responsable des certifications."
14+
/>
15+
);

packages/reva-admin-react/src/app/(admin)/certifications-v2/[certificationId]/structure/_components/StructureForm.tsx

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { z } from "zod";
88
import { useStructureForm } from "./structureForm.hook";
99
import { Checkbox } from "@codegouvfr/react-dsfr/Checkbox";
1010
import { useCallback, useEffect } from "react";
11+
import { NoCertificationAuthorityAlert } from "./NoCertificationAuthorityAlert";
12+
import { NoCertificationRegistryManagerAlert } from "./NoCertificationRegistryManagerAlert";
1113

1214
type CertificationForForm = {
1315
id: string;
@@ -60,6 +62,7 @@ export const StructureForm = ({
6062

6163
const {
6264
availableCertificationAuthorities,
65+
certificationRegistryManagerPresent,
6366
getCertificationAuthoritiesQueryStatus,
6467
} = useStructureForm({ certificationAuthorityStructureId });
6568

@@ -149,18 +152,24 @@ export const StructureForm = ({
149152
</option>
150153
))}
151154
</Select>
152-
{getCertificationAuthoritiesQueryStatus === "success" && (
153-
<Checkbox
154-
legend="Gestionnaire(s) des candidatures"
155-
options={certificationAuthoritiesFields.map((ca, caIndex) => ({
156-
label: ca.label,
157-
nativeInputProps: {
158-
key: ca.id,
159-
...register(`certificationAuthorities.${caIndex}.checked`),
160-
},
161-
}))}
162-
/>
155+
{!certificationRegistryManagerPresent && (
156+
<NoCertificationRegistryManagerAlert className="my-4" />
163157
)}
158+
{getCertificationAuthoritiesQueryStatus === "success" &&
159+
(certificationAuthoritiesFields.length ? (
160+
<Checkbox
161+
legend="Gestionnaire(s) des candidatures"
162+
options={certificationAuthoritiesFields.map((ca, caIndex) => ({
163+
label: ca.label,
164+
nativeInputProps: {
165+
key: ca.id,
166+
...register(`certificationAuthorities.${caIndex}.checked`),
167+
},
168+
}))}
169+
/>
170+
) : (
171+
<NoCertificationAuthorityAlert className="my-4" />
172+
))}
164173
<FormButtons
165174
backUrl={`/certifications-v2/${certification.id}`}
166175
formState={{

packages/reva-admin-react/src/app/(admin)/certifications-v2/[certificationId]/structure/_components/structureForm.hook.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ const getCertificationAuthoritiesQuery = graphql(`
88
) {
99
certification_authority_getCertificationAuthorityStructure(id: $id) {
1010
id
11+
certificationRegistryManager {
12+
id
13+
}
1114
certificationAuthorities {
1215
id
1316
label
@@ -44,8 +47,14 @@ export const useStructureForm = ({
4447
?.certification_authority_getCertificationAuthorityStructure
4548
?.certificationAuthorities || [];
4649

50+
const certificationRegistryManagerPresent =
51+
getCertificationAuthoritiesResponse
52+
?.certification_authority_getCertificationAuthorityStructure
53+
?.certificationRegistryManager;
54+
4755
return {
4856
getCertificationAuthoritiesQueryStatus,
4957
availableCertificationAuthorities,
58+
certificationRegistryManagerPresent,
5059
};
5160
};

0 commit comments

Comments
 (0)