From 1b03de3b9692665cd83ae171b7a905c2c4146601 Mon Sep 17 00:00:00 2001 From: Kariamos Date: Tue, 15 Oct 2024 18:26:25 +0200 Subject: [PATCH] (wip) refactor: Update language handling in FormProvider and schema.ts --- .../components/campaignForm/FormProvider.tsx | 6 +- src/utils/schema.ts | 89 +++++++++++-------- 2 files changed, 55 insertions(+), 40 deletions(-) diff --git a/src/pages/campaigns/components/campaignForm/FormProvider.tsx b/src/pages/campaigns/components/campaignForm/FormProvider.tsx index c0d147bb..9bf7f233 100644 --- a/src/pages/campaigns/components/campaignForm/FormProvider.tsx +++ b/src/pages/campaigns/components/campaignForm/FormProvider.tsx @@ -125,7 +125,7 @@ const FormProvider = ({ deviceTypes: selectedTypes, deviceList: selectedDevices, countries: dossier?.countries || [], - languages: dossier?.languages?.map((lang) => lang.id.toString()) || [], + languages: dossier?.languages?.map((lang) => lang.name) || [], description: dossier?.description || "", productLink: dossier?.productLink || "", goal: dossier?.goal || "", @@ -233,9 +233,7 @@ const FormProvider = ({ deviceList: values.deviceList.map((device) => parseInt(device, 10)), csm: parseInt(values.csm), roles: roles, - languages: values.languages.map((language) => - parseInt(language, 10) - ), + languages: values.languages.map((language) => language), countries: values.countries, description: values.description, productLink: values.productLink, diff --git a/src/utils/schema.ts b/src/utils/schema.ts index bae05e84..e95af990 100644 --- a/src/utils/schema.ts +++ b/src/utils/schema.ts @@ -805,19 +805,17 @@ export interface components { short_name?: string; } & ( | { - /** @enum {string} */ - type: "text" | "gender" | "phone_number" | "address"; + type: components["schemas"]["PreselectionQuestionSimple"]; } | { - /** @enum {string} */ - type: "multiselect" | "select" | "radio"; - options: { + type: components["schemas"]["PreselectionQuestionMultiple"]; + options?: { value: string; isInvalid?: boolean; }[]; } | { - type: string; + type: components["schemas"]["PreselectionQuestionCuf"]; options?: { value: number; isInvalid?: boolean; @@ -942,11 +940,23 @@ export interface components { cap?: number; }; countries?: components["schemas"]["CountryCode"][]; - languages?: number[]; + languages?: string[]; browsers?: number[]; productType?: number; notes?: string; }; + /** + * PreselectionQuestionSimple + * @enum {string} + */ + PreselectionQuestionSimple: "gender" | "text" | "phone_number" | "address"; + /** + * PreselectionQuestionMultiple + * @enum {string} + */ + PreselectionQuestionMultiple: "multiselect" | "select" | "radio"; + /** PreselectionQuestionCuf */ + PreselectionQuestionCuf: string; }; responses: { /** A user */ @@ -1966,8 +1976,6 @@ export interface operations { 200: { content: { "application/json": { - /** @enum {string} */ - status: "draft" | "published" | "draft-modified"; goal: string; usersNumber: number; sentiments: { @@ -1989,6 +1997,7 @@ export interface operations { id: number; name: string; }[]; + visible: number; }; }; }; @@ -2015,30 +2024,25 @@ export interface operations { }; requestBody: { content: { - "application/json": - | { - goal: string; - usersNumber: number; - sentiments: { - id?: number; - clusterId: number; - value: number; - comment: string; - }[]; - methodology: { - /** @enum {string} */ - type: "qualitative" | "quantitative" | "quali-quantitative"; - description: string; - }; - questions: { - id?: number; - name: string; - }[]; - } - | { - /** @enum {string} */ - status: "publish"; - }; + "application/json": { + goal?: string; + usersNumber?: number; + visible?: number; + methodology?: { + description: string; + type: string; + }; + sentiments?: { + clusterId: number; + value: number; + comment: string; + id?: number; + }[]; + questions?: { + name: string; + id?: number; + }[]; + }; }; }; }; @@ -3305,7 +3309,9 @@ export interface operations { /** OK */ 200: { content: { - "application/json": (components["schemas"]["PreselectionFormQuestion"] & { + "application/json": ({ + question: string; + short_name?: string; value?: | number | { @@ -3319,7 +3325,19 @@ export interface operations { error?: string; }; id: number; - })[]; + } & ( + | { + type: components["schemas"]["PreselectionQuestionSimple"]; + } + | { + type: components["schemas"]["PreselectionQuestionMultiple"]; + options: string[]; + } + | { + type: components["schemas"]["PreselectionQuestionCuf"]; + options?: number[]; + } + ))[]; }; }; 403: components["responses"]["NotAuthorized"]; @@ -4195,7 +4213,6 @@ export interface operations { }; countries?: components["schemas"]["CountryCode"][]; languages?: { - id: number; name: string; }[]; browsers?: {