@@ -13,7 +13,10 @@ import { useRef } from 'react';
1313import { useTranslation } from 'react-i18next' ;
1414import { appTheme } from 'src/app/theme' ;
1515import { 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' ;
1720import { ProfileFormValues } from '../valuesType' ;
1821import { Loader } from './cardLoader' ;
1922import {
@@ -25,12 +28,16 @@ import {
2528
2629export 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
0 commit comments