Skip to content

Commit e1a9f1f

Browse files
Merge pull request #1409 from AppQuality/UN-1694
UN-1694 - Add companies sizes to profile page
2 parents 0ba3dbd + 7239b8a commit e1a9f1f

File tree

17 files changed

+163
-33
lines changed

17 files changed

+163
-33
lines changed

src/common/schema.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,9 @@ export interface paths {
305305
};
306306
};
307307
};
308+
"/companies/sizes": {
309+
get: operations["get-companies-sizes"];
310+
};
308311
"/insights/{iid}": {
309312
get: operations["get-insights-iid"];
310313
delete: operations["delete-insights-iid"];
@@ -623,9 +626,6 @@ export interface paths {
623626
};
624627
};
625628
};
626-
"/companies/sizes": {
627-
get: operations["get-companies-sizes"];
628-
};
629629
}
630630

631631
export interface components {
@@ -1526,6 +1526,7 @@ export interface components {
15261526
};
15271527
/** User */
15281528
User: {
1529+
company_size: string;
15291530
customer_role: string;
15301531
/** Format: email */
15311532
email: string;
@@ -3107,6 +3108,19 @@ export interface operations {
31073108
500: components["responses"]["Error"];
31083109
};
31093110
};
3111+
"get-companies-sizes": {
3112+
responses: {
3113+
/** OK */
3114+
200: {
3115+
content: {
3116+
"application/json": {
3117+
id: number;
3118+
name: string;
3119+
}[];
3120+
};
3121+
};
3122+
};
3123+
};
31103124
"get-insights-iid": {
31113125
parameters: {
31123126
path: {
@@ -3636,6 +3650,7 @@ export interface operations {
36363650
200: {
36373651
content: {
36383652
"application/json": {
3653+
companySize?: string;
36393654
name?: string;
36403655
role?: string;
36413656
surname?: string;
@@ -3648,6 +3663,7 @@ export interface operations {
36483663
requestBody: {
36493664
content: {
36503665
"application/json": {
3666+
companySizeId?: number;
36513667
name?: string;
36523668
password?: {
36533669
current: string;
@@ -4432,19 +4448,6 @@ export interface operations {
44324448
};
44334449
};
44344450
};
4435-
"get-companies-sizes": {
4436-
responses: {
4437-
/** OK */
4438-
200: {
4439-
content: {
4440-
"application/json": {
4441-
id: number;
4442-
name: string;
4443-
}[];
4444-
};
4445-
};
4446-
};
4447-
};
44484451
}
44494452

44504453
export interface external {}

src/features/api/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,12 +1664,14 @@ export type HeadUsersByEmailByEmailApiArg = {
16641664
export type GetUsersMeApiResponse = /** status 200 */ User;
16651665
export type GetUsersMeApiArg = void;
16661666
export type PatchUsersMeApiResponse = /** status 200 OK */ {
1667+
companySize?: string;
16671668
name?: string;
16681669
role?: string;
16691670
surname?: string;
16701671
};
16711672
export type PatchUsersMeApiArg = {
16721673
body: {
1674+
companySizeId?: number;
16731675
name?: string;
16741676
password?: {
16751677
current: string;
@@ -2768,6 +2770,7 @@ export type Feature = {
27682770
slug?: string;
27692771
};
27702772
export type User = {
2773+
company_size: string;
27712774
customer_role: string;
27722775
email: string;
27732776
features?: Feature[];

src/locales/en/translation.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,7 @@
11361136
"__PROFILE_MODAL_NOTIFICATIONS_TOGGLE_TITLE": "Allow notifications",
11371137
"__PROFILE_MODAL_NOTIFICATIONS_UPDATED": "Changes saved",
11381138
"__PROFILE_MODAL_PRIVACY_ITEM_LABEL": "Privacy settings",
1139+
"__PROFILE_PAGE_COMPANY_SIZE_REQUIRED_ERROR": "Company size is required",
11391140
"__PROFILE_PAGE_CONFIRM_PASSWORD_MUST_MATCH_NEW_PASSWORD": "The confirmation password must match the new password",
11401141
"__PROFILE_PAGE_NAME_REQUIRED_ERROR": "Name is required",
11411142
"__PROFILE_PAGE_NAV_ITEM_PASSWORD": "Password settings",
@@ -1151,6 +1152,8 @@
11511152
"__PROFILE_PAGE_TOAST_ERROR_UPDATING_PROFILE": "An error occurred while updating your profile. Please try again.",
11521153
"__PROFILE_PAGE_TOAST_SUCCESS_PASSWORD_UPDATED": "Password updated successfully",
11531154
"__PROFILE_PAGE_UPDATE_SUCCESS": "Profile updated successfully",
1155+
"__PROFILE_PAGE_USER_CARD_COMPANY_SIZE_LABEL": "Company size",
1156+
"__PROFILE_PAGE_USER_CARD_COMPANY_SIZE_PLACEHOLDER": "Select a Company size",
11541157
"__PROFILE_PAGE_USER_CARD_EMAIL_LABEL": "Work email",
11551158
"__PROFILE_PAGE_USER_CARD_LABEL": "Profile settings",
11561159
"__PROFILE_PAGE_USER_CARD_NAME_LABEL": "First name",
@@ -1319,7 +1322,7 @@
13191322
"_CAMPAIGN_WIDGET_UX_TEST_PROGRESS_MONITORING_HEADER": "Test Progress",
13201323
"_CAMPAIGN_WIDGET_UX_USER_ANALYSIS_DESCRIPTION_HEADER": "There are observations on",
13211324
"_CAMPAIGN_WIDGET_UX_USER_ANALYSIS_HEADER": "Analyzed User Contributions",
1322-
"_PAGE_PROFILE_HEADER_TEXT": "Keep your profile up to date: edit your name, role, or password anytime to make UNGUESS truly yours.",
1325+
"_PAGE_PROFILE_HEADER_TEXT": "Manage your profile anytime: check and update your personal information whenever you need.",
13231326
"_PLAN_PAGE_MODULE_LANGUAGE_DESCRIPTION": "You’ll receive feedback in the language you’re selecting",
13241327
"_PLAN_PAGE_MODULE_LANGUAGE_SUBTITLE": "Select participants' preferred language",
13251328
"_PROJECT_PAGE_PLANS_GROUP_SEE_ALL": "View more",

src/locales/it/translation.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,7 @@
11671167
"__PROFILE_MODAL_NOTIFICATIONS_TOGGLE_TITLE": "Vuoi ricevere le notifiche?",
11681168
"__PROFILE_MODAL_NOTIFICATIONS_UPDATED": "Modifiche salvate",
11691169
"__PROFILE_MODAL_PRIVACY_ITEM_LABEL": "Opzioni Privacy",
1170+
"__PROFILE_PAGE_COMPANY_SIZE_REQUIRED_ERROR": "",
11701171
"__PROFILE_PAGE_CONFIRM_PASSWORD_MUST_MATCH_NEW_PASSWORD": "",
11711172
"__PROFILE_PAGE_NAME_REQUIRED_ERROR": "",
11721173
"__PROFILE_PAGE_NAV_ITEM_PASSWORD": "",
@@ -1182,6 +1183,8 @@
11821183
"__PROFILE_PAGE_TOAST_ERROR_UPDATING_PROFILE": "",
11831184
"__PROFILE_PAGE_TOAST_SUCCESS_PASSWORD_UPDATED": "",
11841185
"__PROFILE_PAGE_UPDATE_SUCCESS": "",
1186+
"__PROFILE_PAGE_USER_CARD_COMPANY_SIZE_LABEL": "",
1187+
"__PROFILE_PAGE_USER_CARD_COMPANY_SIZE_PLACEHOLDER": "",
11851188
"__PROFILE_PAGE_USER_CARD_EMAIL_LABEL": "",
11861189
"__PROFILE_PAGE_USER_CARD_LABEL": "",
11871190
"__PROFILE_PAGE_USER_CARD_NAME_LABEL": "",

src/pages/Profile/FormProfile.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const FormProfile = () => {
1616

1717
const initialValues: ProfileFormValues = {
1818
roleId: data?.roleId || 0,
19+
companySizeId: data?.companySizeId || 0,
1920
name: data?.name || '',
2021
surname: data?.surname || '',
2122
email: data?.email || '',
@@ -29,6 +30,9 @@ export const FormProfile = () => {
2930
roleId: Yup.number()
3031
.min(1, t('__PROFILE_PAGE_ROLE_REQUIRED_ERROR'))
3132
.required(t('__PROFILE_PAGE_ROLE_REQUIRED_ERROR')),
33+
companySizeId: Yup.number()
34+
.min(1, t('__PROFILE_PAGE_COMPANY_SIZE_REQUIRED_ERROR'))
35+
.required(t('__PROFILE_PAGE_COMPANY_SIZE_REQUIRED_ERROR')),
3236
});
3337

3438
return (
@@ -45,6 +49,7 @@ export const FormProfile = () => {
4549
name: values.name,
4650
surname: values.surname,
4751
roleId: values.roleId,
52+
companySizeId: values.companySizeId,
4853
},
4954
})
5055
.unwrap()

src/pages/Profile/parts/ProfileCard.tsx

Lines changed: 81 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ import { useRef } from 'react';
1313
import { useTranslation } from 'react-i18next';
1414
import { appTheme } from 'src/app/theme';
1515
import { ReactComponent as UserIcon } from 'src/assets/icons/user.svg';
16-
import { useGetUsersRolesQuery } from 'src/features/api';
16+
import {
17+
useGetUsersRolesQuery,
18+
useGetCompaniesSizesQuery,
19+
} from 'src/features/api';
1720
import { ProfileFormValues } from '../valuesType';
1821
import { Loader } from './cardLoader';
1922
import {
@@ -25,12 +28,16 @@ import {
2528

2629
export const ProfileCard = () => {
2730
const { t } = useTranslation();
28-
const { data, isLoading } = useGetUsersRolesQuery();
29-
const selectRef = useRef<HTMLDivElement>(null);
31+
const { data: userRolesData, isLoading: userRoleIsLoading } =
32+
useGetUsersRolesQuery();
33+
const { data: userCompanySizesData, isLoading: userCompanySizesIsLoading } =
34+
useGetCompaniesSizesQuery();
35+
const selectRoleRef = useRef<HTMLDivElement>(null);
36+
const selectCompanyRef = useRef<HTMLDivElement>(null);
3037
const { setFieldValue, touched, isSubmitting, submitForm } =
3138
useFormikContext<ProfileFormValues>();
3239

33-
if (isLoading) return <Loader />;
40+
if (userRoleIsLoading || userCompanySizesIsLoading) return <Loader />;
3441

3542
return (
3643
<StyledContainerCard
@@ -124,15 +131,15 @@ export const ProfileCard = () => {
124131
{({ field, meta }: FieldProps) => {
125132
const hasError = meta.touched && Boolean(meta.error);
126133
return (
127-
<div ref={selectRef}>
134+
<div ref={selectRoleRef}>
128135
<Select
129136
placeholder={t('__PROFILE_PAGE_USER_CARD_ROLE_PLACEHOLDER')}
130137
data-qa="roleId-select"
131138
{...field}
132139
inputValue={field.value}
133140
selectionValue={field.value}
134141
renderValue={(value) =>
135-
data?.find(
142+
userRolesData?.find(
136143
(role) =>
137144
role.id === Number.parseInt(value.inputValue ?? '', 10)
138145
)?.name
@@ -152,13 +159,13 @@ export const ProfileCard = () => {
152159
onSelect={(role) => {
153160
setFieldValue('roleId', Number.parseInt(role, 10));
154161
(
155-
selectRef.current?.querySelector(
162+
selectRoleRef.current?.querySelector(
156163
'[role="combobox"]'
157164
) as HTMLElement | null
158165
)?.blur();
159166
}}
160167
>
161-
{data?.map((role) => (
168+
{userRolesData?.map((role) => (
162169
<Select.Option key={role.id} value={role.id.toString()}>
163170
{role.name}
164171
</Select.Option>
@@ -177,6 +184,72 @@ export const ProfileCard = () => {
177184
}}
178185
</Field>
179186

187+
<Field name="companySizeId">
188+
{({ field, meta }: FieldProps) => {
189+
const hasError = meta.touched && Boolean(meta.error);
190+
return (
191+
<div ref={selectCompanyRef}>
192+
<Select
193+
placeholder={t(
194+
'__PROFILE_PAGE_USER_CARD_COMPANY_SIZE_PLACEHOLDER'
195+
)}
196+
data-qa="companySizeId-select"
197+
{...field}
198+
inputValue={field.value}
199+
selectionValue={field.value}
200+
renderValue={(value) =>
201+
userCompanySizesData?.find(
202+
(companySize) =>
203+
companySize.id ===
204+
Number.parseInt(value.inputValue ?? '', 10)
205+
)?.name
206+
}
207+
label={
208+
<>
209+
{t('__PROFILE_PAGE_USER_CARD_COMPANY_SIZE_LABEL')}
210+
<Span
211+
style={{
212+
color: appTheme.palette.red[600],
213+
}}
214+
>
215+
*
216+
</Span>
217+
</>
218+
}
219+
onSelect={(companySize) => {
220+
setFieldValue(
221+
'companySizeId',
222+
Number.parseInt(companySize, 10)
223+
);
224+
(
225+
selectCompanyRef.current?.querySelector(
226+
'[role="combobox"]'
227+
) as HTMLElement | null
228+
)?.blur();
229+
}}
230+
>
231+
{userCompanySizesData?.map((companySize) => (
232+
<Select.Option
233+
key={companySize.id}
234+
value={companySize.id.toString()}
235+
>
236+
{companySize.name}
237+
</Select.Option>
238+
))}
239+
</Select>
240+
{hasError && (
241+
<Message
242+
data-qa="update-profile-companySizeId-error"
243+
validation="error"
244+
>
245+
{meta.error}
246+
</Message>
247+
)}
248+
</div>
249+
);
250+
}}
251+
</Field>
252+
180253
<StyledFooter>
181254
<Button
182255
isAccent
Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { useEffect, useState } from 'react';
2-
import { useGetUsersMeQuery, useGetUsersRolesQuery } from 'src/features/api';
2+
import {
3+
useGetUsersMeQuery,
4+
useGetUsersRolesQuery,
5+
useGetCompaniesSizesQuery,
6+
} from 'src/features/api';
37
import { ProfileFormValues } from './valuesType';
48

59
export const useProfileData = () => {
@@ -8,15 +12,22 @@ export const useProfileData = () => {
812
const { data: userData, isLoading: isUserDataLoading } = useGetUsersMeQuery();
913
const { data: rolesData, isLoading: isRolesDataLoading } =
1014
useGetUsersRolesQuery();
15+
const { data: companySizesData, isLoading: isCompanySizesLoading } =
16+
useGetCompaniesSizesQuery();
1117

1218
useEffect(() => {
13-
if (userData && rolesData) {
19+
if (userData && rolesData && companySizesData) {
1420
const roleObj = rolesData.find(
1521
(role) => role.name === userData.customer_role
1622
);
23+
const companySizeObj = companySizesData.find(
24+
(size) => size.name === userData.company_size
25+
);
1726
const initialValues: ProfileFormValues = {
1827
role: roleObj?.name || undefined,
1928
roleId: roleObj?.id || 0,
29+
companySize: companySizeObj?.name || '',
30+
companySizeId: companySizeObj?.id || 0,
2031
name: userData.first_name || '',
2132
surname: userData.last_name || '',
2233
email: userData.email || '',
@@ -27,7 +38,8 @@ export const useProfileData = () => {
2738

2839
return {
2940
data: profile,
30-
isLoading: isUserDataLoading || isRolesDataLoading,
31-
isFetching: isUserDataLoading || isRolesDataLoading,
41+
isLoading: isUserDataLoading || isRolesDataLoading || isCompanySizesLoading,
42+
isFetching:
43+
isUserDataLoading || isRolesDataLoading || isCompanySizesLoading,
3244
};
3345
};

src/pages/Profile/valuesType.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ export type ProfileFormValues = {
44
roleId: number;
55
email?: string;
66
role?: string;
7+
companySize?: string;
8+
companySizeId: number;
79
};
810

911
export type PasswordFormValues = {

tests/api/users/_post/request_invited_user_request.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2+
"companySizeId": 3,
23
"name": "string",
34
"password": "string",
45
"profileId": 11111,
56
"roleId": 0,
6-
"companySizeId": 3,
77
"surname": "string",
88
"token": "th1s1s4f4k3t0k3n",
99
"type": "invite"

tests/api/users/_post/request_new_user_request.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2+
"companySizeId": 3,
23
"email": "jhon.doe@example.com",
34
"name": "string",
45
"password": "string",
56
"roleId": 0,
6-
"companySizeId": 3,
77
"surname": "string",
88
"type": "new",
99
"workspace": "My new Workspace"

0 commit comments

Comments
 (0)