From 352c8a2b3c8f3de41fe0439675ef9855c58f277e Mon Sep 17 00:00:00 2001 From: Clemence Date: Tue, 14 Jan 2025 09:57:35 +0100 Subject: [PATCH 1/5] feat(from): add from fields in user registration form --- .../StructureFormStep.controller.test.ts | 29 +++++++++++++- .../StructureFormStep.controller.ts | 23 ++++++++++- .../StructureFormStep.svelte | 39 +++++++++++++++++++ .../src/lib/resources/users/user.port.js | 3 ++ 4 files changed, 92 insertions(+), 2 deletions(-) diff --git a/packages/front/src/lib/components/StructureFormStep/StructureFormStep.controller.test.ts b/packages/front/src/lib/components/StructureFormStep/StructureFormStep.controller.test.ts index 9434f3f52..cf3398895 100644 --- a/packages/front/src/lib/components/StructureFormStep/StructureFormStep.controller.test.ts +++ b/packages/front/src/lib/components/StructureFormStep/StructureFormStep.controller.test.ts @@ -1,4 +1,4 @@ -import { AgentTypeEnum } from "dto"; +import { AgentTypeEnum, FromTypeEnum } from "dto"; import type { MockInstance } from "vitest"; import { beforeEach } from "vitest"; import StructureFormStepController from "./StructureFormStep.controller"; @@ -208,4 +208,31 @@ describe("StructureFormStepController", () => { expect(values.centralSomething).toBeUndefined(); }); }); + + describe("updateFrom", () => { + it("fromEmail and fromOther are set to empty strings", () => { + const values = { + from: [FromTypeEnum.DEMO], + fromEmail: "test@email.com", + fromOther: "Other", + }; + const expected = { + from: [FromTypeEnum.DEMO], + fromEmail: "", + fromOther: "", + }; + ctrl.onUpdateFrom(values); + expect(values).toStrictEqual(expected); + }); + it("fromEmail and fromOther are not set to empty strings", () => { + const values = { + from: [FromTypeEnum.COLLEAGUES_HIERARCHY, FromTypeEnum.OTHER], + fromEmail: "test@email.com", + fromOther: "Other", + }; + const expected = { ...values }; + ctrl.onUpdateFrom(values); + expect(values).toStrictEqual(expected); + }); + }); }); diff --git a/packages/front/src/lib/components/StructureFormStep/StructureFormStep.controller.ts b/packages/front/src/lib/components/StructureFormStep/StructureFormStep.controller.ts index 18bf10b96..3978b37bd 100644 --- a/packages/front/src/lib/components/StructureFormStep/StructureFormStep.controller.ts +++ b/packages/front/src/lib/components/StructureFormStep/StructureFormStep.controller.ts @@ -1,4 +1,4 @@ -import { AgentTypeEnum, AgentJobTypeEnum } from "dto"; +import { AgentTypeEnum, AgentJobTypeEnum, FromTypeEnum } from "dto"; import type { ComponentType, SvelteComponent } from "svelte"; import OperatorSubStep from "./OperatorSubStep/OperatorSubStep.svelte"; import CentralSubStep from "./CentralSubStep/CentralSubStep.svelte"; @@ -48,6 +48,13 @@ export default class StructureFormStepController { { value: AgentJobTypeEnum.CONTROLLER, label: "Contrôleur / Inspecteur" }, { value: AgentJobTypeEnum.OTHER, label: "Autre" }, ]; + public readonly fromOptions: Option[] = [ + { value: FromTypeEnum.DEMO, label: "Lors d’une présentation avec une personne de Data.Subvention" }, + { value: FromTypeEnum.SEARCH_ENGINE, label: "Via des recherches sur internet" }, + { value: FromTypeEnum.COLLEAGUES_HIERARCHY, label: "Un de mes collègues ou de ma hiérarchie m’en a parlé" }, + { value: FromTypeEnum.SOCIALS, label: "Via une publication sur les réseaux sociaux" }, + { value: FromTypeEnum.OTHER, label: "Autre" }, + ]; private static subStepByAgentType: Record = { [AgentTypeEnum.CENTRAL_ADMIN]: CentralSubStep, @@ -102,6 +109,20 @@ export default class StructureFormStepController { this.dispatch(shouldBlockStep ? "error" : "valid"); } + onUpdateFrom(values: Record) { + this.onUpdate(values, "from"); + if (values["from"] && Array.isArray(values["from"])) { + if (!values["from"].includes(FromTypeEnum.COLLEAGUES_HIERARCHY) && values["fromEmail"] !== "") { + values["fromEmail"] = ""; + this.onUpdate(values, "fromEmail"); + } + if (!values["from"].includes(FromTypeEnum.OTHER) && values["fromOther"] !== "") { + values["fromOther"] = ""; + this.onUpdate(values, "fromOther"); + } + } + } + cleanSubStepValues(values: Record, contextAgentType: AgentTypeEnum) { const prefixes: string[] = []; for (const [agentType, prefix] of Object.entries(StructureFormStepController.subFieldsPrefixByAgentType)) { diff --git a/packages/front/src/lib/components/StructureFormStep/StructureFormStep.svelte b/packages/front/src/lib/components/StructureFormStep/StructureFormStep.svelte index 4b621f7f4..61176de00 100644 --- a/packages/front/src/lib/components/StructureFormStep/StructureFormStep.svelte +++ b/packages/front/src/lib/components/StructureFormStep/StructureFormStep.svelte @@ -1,4 +1,5 @@