diff --git a/front/src/app/components/forms/convention/ConventionFeedbackNotification.tsx b/front/src/app/components/forms/convention/ConventionFeedbackNotification.tsx index 64fd25fe77..a8fc999200 100644 --- a/front/src/app/components/forms/convention/ConventionFeedbackNotification.tsx +++ b/front/src/app/components/forms/convention/ConventionFeedbackNotification.tsx @@ -45,10 +45,6 @@ export const createConventionFeedbackMessageByKind = ( title: "Succès", message: "Vous avez renvoyé la demande pour modification.", }, - signedSuccessfully: { - title: "Succès", - message: "Votre accord a été enregistré.", - }, rejected: { title: "Succès", message: diff --git a/front/src/app/pages/convention/ConventionSignPage.tsx b/front/src/app/pages/convention/ConventionSignPage.tsx index 5b8fb27aab..b43ed54268 100644 --- a/front/src/app/pages/convention/ConventionSignPage.tsx +++ b/front/src/app/pages/convention/ConventionSignPage.tsx @@ -2,12 +2,7 @@ import { fr } from "@codegouvfr/react-dsfr"; import { Alert } from "@codegouvfr/react-dsfr/Alert"; import { Badge } from "@codegouvfr/react-dsfr/Badge"; import React, { useEffect } from "react"; -import { - ConventionSummary, - Loader, - MainWrapper, - PageHeader, -} from "react-design-system"; +import { Loader, MainWrapper, PageHeader } from "react-design-system"; import { useDispatch } from "react-redux"; import { ConventionJwtPayload, @@ -16,10 +11,8 @@ import { decodeMagicLinkJwtWithoutSignatureCheck, errors, isSignatory, - toDisplayedDate, } from "shared"; import { ConventionSignForm } from "src/app/components/forms/convention/ConventionSignForm"; -import { makeConventionSections } from "src/app/contents/convention/conventionSummary.helpers"; import { labelAndSeverityByStatus } from "src/app/contents/convention/labelAndSeverityByStatus"; import { P, match } from "ts-pattern"; import { useStyles } from "tss-react/dsfr"; @@ -48,7 +41,7 @@ const useClearConventionOnUnmount = () => { export const ConventionSignPage = ({ route }: ConventionSignPageProperties) => { useClearConventionOnUnmount(); - if (!route.params.jwt) throw errors.routeParams.missingJwt(); + if (!route.params?.jwt) throw errors.routeParams.missingJwt(); if ( !isSignatory( decodeMagicLinkJwtWithoutSignatureCheck( @@ -116,30 +109,6 @@ const ConventionSignPageContent = ({ /> ), ) - .with({ submitFeedback: { kind: "signedSuccessfully" } }, () => ( - - - {convention && ( - - )} - - )) .with({ hasConvention: false }, () => ( action$.pipe( - filter(conventionSlice.actions.fetchConventionRequested.match), + filter( + (action) => + conventionSlice.actions.fetchConventionRequested.match(action) || + conventionSlice.actions.signConventionSucceeded.match(action), + ), switchMap(({ payload }) => conventionGateway.retrieveFromToken$(payload)), map(conventionSlice.actions.fetchConventionSucceeded), catchEpicError((error: Error) => @@ -91,10 +95,13 @@ const signConventionEpic: ConventionEpic = ( ) => action$.pipe( filter(conventionSlice.actions.signConventionRequested.match), - switchMap(({ payload: { jwt, conventionId } }) => - conventionGateway.signConvention$(conventionId, jwt), + switchMap(({ payload }) => + conventionGateway + .signConvention$(payload.conventionId, payload.jwt) + .pipe( + map(() => conventionSlice.actions.signConventionSucceeded(payload)), + ), ), - map(conventionSlice.actions.signConventionSucceeded), catchEpicError((error: Error) => conventionSlice.actions.signConventionFailed(error.message), ), diff --git a/front/src/core-logic/domain/convention/convention.slice.ts b/front/src/core-logic/domain/convention/convention.slice.ts index 245f94069e..a14cd102e0 100644 --- a/front/src/core-logic/domain/convention/convention.slice.ts +++ b/front/src/core-logic/domain/convention/convention.slice.ts @@ -28,7 +28,6 @@ type ConventionValidationFeedbackKind = type ConventionSignatoryFeedbackKind = | "justSubmitted" - | "signedSuccessfully" | "modificationsAskedFromSignatory"; export type ConventionFeedbackKind = @@ -175,9 +174,14 @@ export const conventionSlice = createSlice({ ) => { state.isLoading = true; }, - signConventionSucceeded: (state) => { + signConventionSucceeded: ( + state, + _action: PayloadAction<{ + conventionId: ConventionId; + jwt: ConventionJwt | InclusionConnectJwt; + }>, + ) => { state.isLoading = false; - state.feedback = { kind: "signedSuccessfully" }; }, signConventionFailed: setFeedbackAsErrored, diff --git a/front/src/core-logic/domain/convention/convention.test.ts b/front/src/core-logic/domain/convention/convention.test.ts index b920b4d727..5d68352686 100644 --- a/front/src/core-logic/domain/convention/convention.test.ts +++ b/front/src/core-logic/domain/convention/convention.test.ts @@ -722,8 +722,20 @@ describe("Convention slice", () => { describe("Convention signature", () => { it("signs the conventions with role from jwt", () => { const jwt = "some-correct-jwt"; - const convention = - new ConventionDtoBuilder().build() as ConventionReadDto; + const agencyFields = { + agencyCounsellorEmails: [], + agencyDepartment: "75", + agencyKind: "mission-locale" as const, + agencyName: "Agence Mission Locale", + agencyRefersTo: undefined, + agencySiret: "11110000111155", + agencyValidatorEmails: [], + }; + const convention: ConventionReadDto = { + ...agencyFields, + ...new ConventionDtoBuilder().notSigned().build(), + }; + ({ store, dependencies } = createTestStore({ convention: { ...initialConventionState, @@ -736,15 +748,29 @@ describe("Convention slice", () => { jwt, }), ); + expectConventionState({ isLoading: true, }); feedGatewayWithSignSuccess(); expectConventionState({ isLoading: false, - feedback: { kind: "signedSuccessfully" }, convention, }); + + const signedConvention: ConventionReadDto = { + ...agencyFields, + ...new ConventionDtoBuilder(convention) + .signedByEstablishmentRepresentative(new Date().toISOString()) + .build(), + }; + + feedGatewayWithConvention(signedConvention); + + expectConventionState({ + isLoading: false, + convention: signedConvention, + }); }); it("gets error message when signature fails", () => { diff --git a/shared/src/convention/convention.ts b/shared/src/convention/convention.ts index cbc1fbf63a..4b3c767fa2 100644 --- a/shared/src/convention/convention.ts +++ b/shared/src/convention/convention.ts @@ -1,6 +1,6 @@ import { keys, mapObjIndexed, values } from "ramda"; import { Role, SignatoryRole, allSignatoryRoles } from "../role/role.dto"; -import { DotNestedKeys, ExtractFromExisting } from "../utils"; +import { DotNestedKeys } from "../utils"; import { ConventionDto, ConventionRenewed, @@ -93,12 +93,6 @@ export type ConventionField = DotNestedKeys; export const getConventionFieldName = (name: ConventionField) => name; -type SignatoryField = ExtractFromExisting; - -export const getSignatoryKey = ( - v: `${SignatoryField}.${keyof ConventionDto["signatories"]}`, -) => v; - export const isEstablishmentTutorIsEstablishmentRepresentative = ( convention: Pick, ): boolean => { @@ -118,13 +112,6 @@ export const isBeneficiaryMinor = ( convention: Pick, ): boolean => !!convention.signatories.beneficiaryRepresentative; -export const signatoryKeyFromRole: Record = { - "beneficiary-current-employer": "beneficiaryCurrentEmployer", - "beneficiary-representative": "beneficiaryRepresentative", - "establishment-representative": "establishmentRepresentative", - beneficiary: "beneficiary", -}; - export const hasBeneficiaryCurrentEmployer = ( convention: Pick, ): boolean => !!convention.signatories.beneficiaryCurrentEmployer;