Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dossiers languages #312

Merged
merged 4 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"dependencies": {
"@appquality/appquality-design-system": "2.0.1",
"@appquality/craft-blocks": "^0.1.27",
"@appquality/languages": "^1.4.3",
"@datadog/browser-logs": "^3.4.1",
"@reduxjs/toolkit": "^1.8.2",
"@sentry/react": "^7.83.0",
Expand Down
8 changes: 3 additions & 5 deletions src/pages/Profile/TabBase/LanguageSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import { FieldProps } from "formik";
import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import API from "src/utils/api";
import { getAllLanguages } from "@appquality/languages";

export const LanguageSelect = ({
name,
Expand All @@ -20,10 +20,8 @@ export const LanguageSelect = ({

useEffect(() => {
const getLanguages = async () => {
const results = await API.languages();
setLanguages(
results.map((item) => ({ label: item.name, value: item.id.toString() }))
);
const results = getAllLanguages();
setLanguages(results.map((item) => ({ label: item, value: item })));
};
getLanguages();
}, []);
Expand Down
12 changes: 5 additions & 7 deletions src/pages/Profile/TabBase/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ const TabBase = () => {
countryCode: countries.getAlpha2Code(user?.country || "Italy", "en"),
city: user?.city || "",
languages:
(user?.languages || [])?.map((l: any) => ({
label: l.name,
value: l.id.toString(),
user?.languages?.map((lang) => ({
label: lang.name || "",
value: lang.name || "",
})) || [],
};
const validationSchema = {
Expand Down Expand Up @@ -103,11 +103,9 @@ const TabBase = () => {
initialTouched={initialTouched}
initialValues={initialUserValues}
onSubmit={async (values, helpers) => {
let newLanguages: number[] = [];
let newLanguages: string[] = [];
values.languages.forEach((val) => {
if (typeof val.value === "string") {
newLanguages.push(parseInt(val.value));
}
newLanguages.push(val.label);
});
const profileDataToSend: any = { ...values };
if (profileDataToSend.email === user?.email) {
Expand Down
140 changes: 57 additions & 83 deletions src/services/tryberApi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1464,34 +1464,8 @@ export type PutCampaignsByCampaignTasksAndTaskApiArg = {
};
export type GetCampaignsByCampaignUxApiResponse =
/** status 200 A UseCase linked with the Campaign */ {
status: "draft" | "published" | "draft-modified";
goal: string;
usersNumber: number;
insights?: {
id: number;
title: string;
severity: {
id: number;
name: string;
};
description: string;
clusters:
| "all"
| {
id: number;
name: string;
}[];
videoParts: {
id: number;
start: number;
end: number;
mediaId: number;
url: string;
streamUrl: string;
description: string;
poster?: string;
}[];
}[];
sentiments: {
id: number;
value: number;
Expand All @@ -1510,6 +1484,7 @@ export type GetCampaignsByCampaignUxApiResponse =
id: number;
name: string;
}[];
visible: number;
};
export type GetCampaignsByCampaignUxApiArg = {
/** A campaign id */
Expand All @@ -1519,44 +1494,25 @@ export type PatchCampaignsByCampaignUxApiResponse = /** status 200 OK */ {};
export type PatchCampaignsByCampaignUxApiArg = {
/** A campaign id */
campaign: string;
body:
| {
goal: string;
usersNumber: number;
insights: {
id?: number;
title: string;
description: string;
severityId: number;
order: number;
clusterIds: number[] | "all";
videoParts: {
id?: number;
start: number;
end: number;
mediaId: number;
description: string;
order: number;
}[];
}[];
sentiments: {
id?: number;
clusterId: number;
value: number;
comment: string;
}[];
methodology: {
type: "qualitative" | "quantitative" | "quali-quantitative";
description: string;
};
questions: {
id?: number;
name: string;
}[];
}
| {
status: "publish";
};
body: {
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;
}[];
};
};
export type PostCampaignsFormsApiResponse = /** status 201 Created */ {
id: number;
Expand Down Expand Up @@ -1899,7 +1855,6 @@ export type GetUsersMeApiResponse = /** status 200 OK */ {
gross: Currency;
};
languages?: {
id?: number;
name?: string;
}[];
onboarding_completed?: boolean;
Expand Down Expand Up @@ -2173,7 +2128,9 @@ export type GetUsersMeCampaignsByCampaignIdDevicesApiArg = {
campaignId: string;
};
export type GetUsersMeCampaignsByCampaignIdFormsApiResponse =
/** status 200 OK */ (PreselectionFormQuestion & {
/** status 200 OK */ ({
question: string;
short_name?: string;
value?:
| number
| {
Expand All @@ -2187,7 +2144,19 @@ export type GetUsersMeCampaignsByCampaignIdFormsApiResponse =
error?: string;
};
id: number;
})[];
} & (
| {
type: PreselectionQuestionSimple;
}
| {
type: PreselectionQuestionMultiple;
options: string[];
}
| {
type: PreselectionQuestionCuf;
options?: number[];
}
))[];
export type GetUsersMeCampaignsByCampaignIdFormsApiArg = {
campaignId: string;
};
Expand Down Expand Up @@ -2412,20 +2381,18 @@ export type PutUsersMeFiscalApiArg = {
};
};
export type PostUsersMeLanguagesApiResponse = /** status 201 Created */ {
id: string;
name: string;
};
export type PostUsersMeLanguagesApiArg = {
body: {
languageId?: number;
language_name?: string;
};
};
export type PutUsersMeLanguagesApiResponse = /** status 200 OK */ {
id?: number;
name?: string;
}[];
export type PutUsersMeLanguagesApiArg = {
body: number[];
body: string[];
};
export type DeleteUsersMeLanguagesByLanguageIdApiResponse =
/** status 200 OK */ {
Expand Down Expand Up @@ -2670,7 +2637,6 @@ export type GetDossiersByCampaignApiResponse = /** status 200 OK */ {
};
countries?: CountryCode[];
languages?: {
id: number;
name: string;
}[];
browsers?: {
Expand Down Expand Up @@ -2872,25 +2838,33 @@ export type TaskRequired = {
campaign_id: number;
};
export type Task = TaskOptional & TaskRequired;
export type PreselectionQuestionSimple =
| "gender"
| "text"
| "phone_number"
| "address";
export type PreselectionQuestionMultiple = "multiselect" | "select" | "radio";
export type PreselectionQuestionCuf = string;
export type PreselectionFormQuestion = {
question: string;
short_name?: string;
} & (
| {
type: "text";
}
| {
type: "multiselect" | "select" | "radio";
options: string[];
invalidOptions?: string[];
type: PreselectionQuestionSimple;
}
| {
type: string;
options?: number[];
invalidOptions?: number[];
type: PreselectionQuestionMultiple;
options?: {
value: string;
isInvalid?: boolean;
}[];
}
| {
type: "gender" | "phone_number" | "address";
type: PreselectionQuestionCuf;
options?: {
value: number;
isInvalid?: boolean;
}[];
}
);
export type CustomUserFieldsType = "text" | "select" | "multiselect";
Expand Down Expand Up @@ -3044,7 +3018,7 @@ export type DossierCreationData = {
cap?: number;
};
countries?: CountryCode[];
languages?: number[];
languages?: string[];
browsers?: number[];
productType?: number;
notes?: string;
Expand Down
Loading
Loading