Skip to content

Commit

Permalink
automatically update convention content after signature is done succe…
Browse files Browse the repository at this point in the history
…ssfully
  • Loading branch information
JeromeBu committed Dec 10, 2024
1 parent 5d7f73a commit 1314375
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
35 changes: 2 additions & 33 deletions front/src/app/pages/convention/ConventionSignPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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";
Expand Down Expand Up @@ -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<ConventionJwtPayload>(
Expand Down Expand Up @@ -116,30 +109,6 @@ const ConventionSignPageContent = ({
/>
),
)
.with({ submitFeedback: { kind: "signedSuccessfully" } }, () => (
<MainWrapper layout="default">
<Alert
severity="success"
{...t.conventionAlreadySigned}
title="Convention signée"
description={`Votre convention (${conventionId}) a bien été signée, merci. Quand toutes les parties l'auront signée et qu'elle aura été validée par ${
convention?.agencyRefersTo
? convention?.agencyRefersTo.name
: convention?.agencyName
}, vous la recevrez par email.`}
className={fr.cx("fr-mb-5v")}
/>
{convention && (
<ConventionSummary
submittedAt={toDisplayedDate({
date: new Date(convention.dateSubmission),
})}
summary={makeConventionSections(convention, cx)}
conventionId={convention.id}
/>
)}
</MainWrapper>
))
.with({ hasConvention: false }, () => (
<Alert
severity="error"
Expand Down
15 changes: 11 additions & 4 deletions front/src/core-logic/domain/convention/convention.epics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ const getConventionEpic: ConventionEpic = (
{ conventionGateway },
) =>
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) =>
Expand Down Expand Up @@ -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),
),
Expand Down
10 changes: 7 additions & 3 deletions front/src/core-logic/domain/convention/convention.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ type ConventionValidationFeedbackKind =

type ConventionSignatoryFeedbackKind =
| "justSubmitted"
| "signedSuccessfully"
| "modificationsAskedFromSignatory";

export type ConventionFeedbackKind =
Expand Down Expand Up @@ -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,

Expand Down
32 changes: 29 additions & 3 deletions front/src/core-logic/domain/convention/convention.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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", () => {
Expand Down
15 changes: 1 addition & 14 deletions shared/src/convention/convention.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -93,12 +93,6 @@ export type ConventionField = DotNestedKeys<ConventionDto>;

export const getConventionFieldName = (name: ConventionField) => name;

type SignatoryField = ExtractFromExisting<keyof ConventionDto, "signatories">;

export const getSignatoryKey = (
v: `${SignatoryField}.${keyof ConventionDto["signatories"]}`,
) => v;

export const isEstablishmentTutorIsEstablishmentRepresentative = (
convention: Pick<ConventionDto, "signatories" | "establishmentTutor">,
): boolean => {
Expand All @@ -118,13 +112,6 @@ export const isBeneficiaryMinor = (
convention: Pick<ConventionDto, "signatories">,
): boolean => !!convention.signatories.beneficiaryRepresentative;

export const signatoryKeyFromRole: Record<SignatoryRole, keyof Signatories> = {
"beneficiary-current-employer": "beneficiaryCurrentEmployer",
"beneficiary-representative": "beneficiaryRepresentative",
"establishment-representative": "establishmentRepresentative",
beneficiary: "beneficiary",
};

export const hasBeneficiaryCurrentEmployer = (
convention: Pick<ConventionDto, "signatories">,
): boolean => !!convention.signatories.beneficiaryCurrentEmployer;
Expand Down

0 comments on commit 1314375

Please sign in to comment.