From c4fe9b4b3a3e028f9c39316944ebe33bd2ae30fc Mon Sep 17 00:00:00 2001 From: Florian Bonniec Date: Tue, 12 Nov 2024 17:24:48 +0100 Subject: [PATCH] feat(admin): added skeleton of CertificationDescription page for certification v2 --- .../description/addCertification.hook.ts | 50 ++++++ .../add-certification/description/page.tsx | 169 ++++++++++++++++++ .../migration.sql | 12 ++ packages/reva-api/prisma/schema.prisma | 8 + 4 files changed, 239 insertions(+) create mode 100644 packages/reva-admin-react/src/app/(admin)/certifications-v2/add-certification/description/addCertification.hook.ts create mode 100644 packages/reva-admin-react/src/app/(admin)/certifications-v2/add-certification/description/page.tsx create mode 100644 packages/reva-api/prisma/migrations/20241112150829_add_certification_satus_v2/migration.sql diff --git a/packages/reva-admin-react/src/app/(admin)/certifications-v2/add-certification/description/addCertification.hook.ts b/packages/reva-admin-react/src/app/(admin)/certifications-v2/add-certification/description/addCertification.hook.ts new file mode 100644 index 000000000..049d032ae --- /dev/null +++ b/packages/reva-admin-react/src/app/(admin)/certifications-v2/add-certification/description/addCertification.hook.ts @@ -0,0 +1,50 @@ +import { useGraphQlClient } from "@/components/graphql/graphql-client/GraphqlClient"; +import { graphql } from "@/graphql/generated"; +import { useQuery } from "@tanstack/react-query"; + +const getFCCertificationQuery = graphql(` + query getFCCertificationForAddCertificationPage($rncp: ID!) { + getFCCertification(rncp: $rncp) { + ID_FICHE + NUMERO_FICHE + INTITULE + ABREGE { + CODE + LIBELLE + } + NOMENCLATURE_EUROPE { + NIVEAU + INTITULE + } + DATE_FIN_ENREGISTREMENT + DATE_LIMITE_DELIVRANCE + FORMACODES { + CODE + LIBELLE + } + } + } +`); + +export const useAddCertificationPage = ({ rncp }: { rncp: string }) => { + const { graphqlClient } = useGraphQlClient(); + + const { + data: getCertificationQueryResponse, + status: getCertificationQueryStatus, + } = useQuery({ + queryKey: [ + rncp, + "certifications", + "getFCCertificationForAddCertificationPage", + ], + queryFn: () => + graphqlClient.request(getFCCertificationQuery, { + rncp, + }), + }); + + const certification = getCertificationQueryResponse?.getFCCertification; + + return { certification, getCertificationQueryStatus }; +}; diff --git a/packages/reva-admin-react/src/app/(admin)/certifications-v2/add-certification/description/page.tsx b/packages/reva-admin-react/src/app/(admin)/certifications-v2/add-certification/description/page.tsx new file mode 100644 index 000000000..6f6de39f1 --- /dev/null +++ b/packages/reva-admin-react/src/app/(admin)/certifications-v2/add-certification/description/page.tsx @@ -0,0 +1,169 @@ +"use client"; +import { ReactNode } from "react"; +import { format } from "date-fns"; +import { useForm } from "react-hook-form"; +import * as z from "zod"; + +import { EnhancedSectionCard } from "@/components/card/enhanced-section-card/EnhancedSectionCard"; +import { Button } from "@codegouvfr/react-dsfr/Button"; +import Alert from "@codegouvfr/react-dsfr/Alert"; +import Input from "@codegouvfr/react-dsfr/Input"; + +import { zodResolver } from "@hookform/resolvers/zod"; + +import { useAddCertificationPage } from "./addCertification.hook"; +import { graphqlErrorToast, successToast } from "@/components/toast/toast"; + +const zodSchema = z.object({ + rncp: z.string().min(3, "obligatoire"), +}); + +type CompanySiretStepFormSchema = z.infer; + +export default function CertificationDescriptionPage() { + const { + register, + handleSubmit, + reset, + formState: { errors, isSubmitting }, + watch, + } = useForm({ + resolver: zodResolver(zodSchema), + defaultValues: { rncp: "" }, + }); + + const rncp = watch("rncp"); + + const { certification } = useAddCertificationPage({ rncp }); + + const handleFormSubmit = handleSubmit(async (_data) => { + try { + console.warn("Do something"); + + successToast("La certification a bien été ajoutée"); + } catch (error) { + graphqlErrorToast(error); + } + }); + + return ( +
+

Descriptif de la certification

+

+ Pour faciliter l’ajout, renseignez le code RNCP pour pré-remplir le + document avec les informations de France compétences et du Formacode. + Ensuite, vous pourrez renseigner une structure certificatrice et (à + minima) un gestionnaire des candidatures. +

+
+
+ + {errors.rncp ? ( + + ) : ( +
+ )} + + + {certification && ( +
+

+ Descriptif de la certification avec France compétences +

+ {certification.INTITULE} +
+ + {certification?.NOMENCLATURE_EUROPE.INTITULE} + + + {certification.ABREGE + ? `${certification.ABREGE.LIBELLE} (${certification.ABREGE.CODE})` + : "Inconnue"} + + + {certification.DATE_FIN_ENREGISTREMENT + ? format( + certification.DATE_FIN_ENREGISTREMENT, + "dd/MM/yyyy", + ) + : ""} + + + {certification.DATE_LIMITE_DELIVRANCE + ? format(certification.DATE_LIMITE_DELIVRANCE, "dd/MM/yyyy") + : ""} + +
+ +

Domaines et sous-domaines du Formacode

+
+ )} +
+
+ +
+ + + + +
+
+ ); +} + +const Info = ({ + title, + children, + className, +}: { + title: string; + children: ReactNode; + className?: string; +}) => ( +
+
{title}
+
{children}
+
+); diff --git a/packages/reva-api/prisma/migrations/20241112150829_add_certification_satus_v2/migration.sql b/packages/reva-api/prisma/migrations/20241112150829_add_certification_satus_v2/migration.sql new file mode 100644 index 000000000..03f32557f --- /dev/null +++ b/packages/reva-api/prisma/migrations/20241112150829_add_certification_satus_v2/migration.sql @@ -0,0 +1,12 @@ +-- CreateEnum +CREATE TYPE "CertificationStatusV2" AS ENUM ('BROUILLON', 'A_VALIDER_PAR_CERTIFICATEUR', 'VALIDE_PAR_CERTIFICATEUR', 'INACTIVE'); + +-- AlterTable +ALTER TABLE "certification" ADD COLUMN "status_v2" "CertificationStatusV2" DEFAULT 'BROUILLON'; + +UPDATE "certification" SET "status_v2" = 'BROUILLON' WHERE STATUS = 'SOON'; +UPDATE "certification" SET "status_v2" = 'INACTIVE' WHERE STATUS = 'INACTIVE'; +UPDATE "certification" SET "status_v2" = 'VALIDE_PAR_CERTIFICATEUR' WHERE STATUS = 'AVAILABLE'; + +-- AlterTable +ALTER TABLE "certification" ALTER COLUMN "status_v2" SET NOT NULL; diff --git a/packages/reva-api/prisma/schema.prisma b/packages/reva-api/prisma/schema.prisma index 7d00d8fe7..fa50383f3 100644 --- a/packages/reva-api/prisma/schema.prisma +++ b/packages/reva-api/prisma/schema.prisma @@ -14,6 +14,13 @@ enum CertificationStatus { AVAILABLE } +enum CertificationStatusV2 { + BROUILLON + A_VALIDER_PAR_CERTIFICATEUR + VALIDE_PAR_CERTIFICATEUR + INACTIVE +} + enum ExperienceDuration { unknown lessThanOneYear @@ -38,6 +45,7 @@ model Certification { abilities String? summary String? status CertificationStatus @default(INACTIVE) + statusV2 CertificationStatusV2 @default(BROUILLON) @map("status_v2") rncpId String @map("rncp_id") @db.VarChar(255) organismsAndRegions OrganismsOnRegionsAndCertifications[] createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)