Skip to content

Commit ce2e51d

Browse files
committed
chore: insert growthbook feature value for country code dropdown
1 parent 0eba1f1 commit ce2e51d

File tree

4 files changed

+53
-23
lines changed

4 files changed

+53
-23
lines changed

packages/account/src/Components/forms/personal-details-form.jsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import clsx from 'clsx';
44
import { Field, useFormikContext } from 'formik';
55

66
import { Autocomplete, Checkbox, InlineMessage, RadioGroup, SelectNative, Text } from '@deriv/components';
7-
import { useGetPhoneNumberList, useResidenceList } from '@deriv/hooks';
7+
import { useGetPhoneNumberList, useGrowthbookGetFeatureValue, useResidenceList } from '@deriv/hooks';
88
import { routes, validPhone } from '@deriv/shared';
99
import { Localize, localize } from '@deriv/translations';
1010
import { useDevice } from '@deriv-com/ui';
@@ -43,7 +43,9 @@ const PersonalDetailsForm = props => {
4343
// need to put this check related to DIEL clients
4444
const is_svg_only = is_svg && !is_eu_user;
4545

46-
const is_country_code_dropdown_enabled = false;
46+
const [isCountryCodeDropdownEnabled, isCountryCodeLoaded] = useGrowthbookGetFeatureValue({
47+
featureFlag: 'enable_country_code_dropdown',
48+
});
4749

4850
const { errors, touched, values, setFieldValue, handleChange, handleBlur } = useFormikContext();
4951

@@ -388,7 +390,7 @@ const PersonalDetailsForm = props => {
388390
)}
389391
{!is_svg_only && 'phone' in values && (
390392
<PhoneField
391-
is_country_code_dropdown_enabled={is_country_code_dropdown_enabled}
393+
is_country_code_dropdown_enabled={isCountryCodeLoaded && isCountryCodeDropdownEnabled}
392394
handleChange={handleChange}
393395
setFieldValue={setFieldValue}
394396
country_code_list={legacy_core_countries_list}
@@ -432,7 +434,7 @@ const PersonalDetailsForm = props => {
432434
<FormSubHeader title={localize('Additional information')} />
433435
{'phone' in values && (
434436
<PhoneField
435-
is_country_code_dropdown_enabled={is_country_code_dropdown_enabled}
437+
is_country_code_dropdown_enabled={isCountryCodeLoaded && isCountryCodeDropdownEnabled}
436438
handleChange={handleChange}
437439
setFieldValue={setFieldValue}
438440
country_code_list={legacy_core_countries_list}

packages/account/src/Components/personal-details/__tests__/personal-details.spec.tsx

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { FormikErrors } from 'formik';
1010
import { getIDVFormValidationSchema } from '../../../Configs/kyc-validation-config';
1111
import { useDevice } from '@deriv-com/ui';
1212
import { APIProvider } from '@deriv/api';
13+
import { useGrowthbookGetFeatureValue } from '@deriv/hooks';
1314

1415
jest.mock('@deriv-com/ui', () => ({
1516
...jest.requireActual('@deriv-com/ui'),
@@ -38,6 +39,11 @@ jest.mock('Helpers/utils', () => ({
3839
isAdditionalDocumentValid: jest.fn(),
3940
}));
4041

42+
jest.mock('@deriv/hooks', () => ({
43+
...jest.requireActual('@deriv/hooks'),
44+
useGrowthbookGetFeatureValue: jest.fn(),
45+
}));
46+
4147
type TPersonalDetailsSectionForm = ComponentProps<typeof PersonalDetails>['value'];
4248

4349
const mock_warnings = {};
@@ -260,6 +266,10 @@ describe('<PersonalDetails/>', () => {
260266
real_account_signup_target: '',
261267
};
262268

269+
beforeEach(() => {
270+
(useGrowthbookGetFeatureValue as jest.Mock).mockReturnValue([false, false]);
271+
});
272+
263273
afterEach(() => {
264274
jest.clearAllMocks();
265275
});
@@ -296,9 +306,9 @@ describe('<PersonalDetails/>', () => {
296306
const citizenship = screen.getByTestId('citizenship');
297307
const phone = screen.getByTestId('phone');
298308

299-
userEvent.clear(first_name);
309+
await userEvent.clear(first_name);
300310
fireEvent.blur(date_of_birth);
301-
userEvent.clear(last_name);
311+
await userEvent.clear(last_name);
302312
fireEvent.blur(place_of_birth);
303313
fireEvent.blur(citizenship);
304314
fireEvent.blur(phone);
@@ -343,8 +353,8 @@ describe('<PersonalDetails/>', () => {
343353
const date_of_birth = screen.getByTestId('date_of_birth');
344354
const phone = screen.getByTestId('phone');
345355

346-
userEvent.type(first_name, 'test firstname');
347-
userEvent.type(last_name, 'test lastname');
356+
await userEvent.type(first_name, 'test firstname');
357+
await userEvent.type(last_name, 'test lastname');
348358
fireEvent.change(date_of_birth, { target: { value: '2000-12-12' } });
349359
fireEvent.change(phone, { target: { value: '+931234567890' } });
350360

@@ -358,7 +368,7 @@ describe('<PersonalDetails/>', () => {
358368

359369
expect(previous_btn).toBeEnabled();
360370
expect(next_btn).toBeEnabled();
361-
userEvent.click(next_btn);
371+
await userEvent.click(next_btn);
362372

363373
await waitFor(() => {
364374
expect(new_props.onSubmit).toBeCalled();
@@ -426,12 +436,25 @@ describe('<PersonalDetails/>', () => {
426436
const mrs_radio_btn: HTMLInputElement = screen.getByRole('radio', { name: /ms/i }) as HTMLInputElement;
427437
expect(mr_radio_btn).toBeInTheDocument();
428438
expect(mrs_radio_btn).toBeInTheDocument();
429-
expect(mr_radio_btn.checked).toEqual(false);
439+
expect(mr_radio_btn).not.toBeChecked();
430440

431441
fireEvent.click(mr_radio_btn);
432442

433-
expect(mr_radio_btn.checked).toEqual(true);
434-
expect(mrs_radio_btn.checked).toEqual(false);
443+
expect(mr_radio_btn).toBeChecked();
444+
expect(mrs_radio_btn).not.toBeChecked();
445+
});
446+
447+
it('should display country code dropdown when isCountryCodeDropdownEnabled is true ', () => {
448+
(useGrowthbookGetFeatureValue as jest.Mock).mockReturnValue([true, true]);
449+
renderwithRouter({});
450+
451+
expect(screen.getByText(/code\*/i)).toBeInTheDocument();
452+
});
453+
454+
it('should not display country code dropdown when isCountryCodeDropdownEnabled is false ', () => {
455+
renderwithRouter({});
456+
457+
expect(screen.queryByText(/code\*/i)).not.toBeInTheDocument();
435458
});
436459

437460
it('should display the correct field details ', () => {
@@ -608,7 +631,7 @@ describe('<PersonalDetails/>', () => {
608631
fireEvent.change(date_of_birth, { target: { value: '2000-12-12' } });
609632
fireEvent.change(phone, { target: { value: '+49123456789012' } });
610633

611-
expect(mr_radio_btn.checked).toEqual(true);
634+
expect(mr_radio_btn).toBeChecked();
612635
const next_btn = screen.getByRole('button', { name: /next/i });
613636

614637
expect(next_btn).toBeEnabled();

packages/account/src/Components/personal-details/personal-details.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { TIDVFormValues, TListItem, TPersonalDetailsBaseForm } from '../../Types
1717
import { GetAccountStatus, GetSettings, ResidenceList } from '@deriv/api-types';
1818
import { getPersonalDetailsBaseValidationSchema } from '../../Configs/user-profile-validation-config';
1919
import { getIDVFormValidationSchema } from '../../Configs/kyc-validation-config';
20+
import { useGrowthbookGetFeatureValue } from '@deriv/hooks';
2021

2122
type TPersonalDetailsSectionForm = Partial<TIDVFormValues & TPersonalDetailsBaseForm> & {
2223
confirmation_checkbox?: boolean;
@@ -79,7 +80,9 @@ const PersonalDetails = observer(
7980
} = useStore();
8081
const { account_status, account_settings, residence, real_account_signup_target } = props;
8182

82-
const is_country_code_dropdown_enabled = false;
83+
const [isCountryCodeDropdownEnabled, isCountryCodeLoaded] = useGrowthbookGetFeatureValue({
84+
featureFlag: 'enable_country_code_dropdown',
85+
});
8386
const { isDesktop } = useDevice();
8487
const handleCancel = (values: TPersonalDetailsSectionForm) => {
8588
const current_step = getCurrentStep() - 1;
@@ -127,13 +130,13 @@ const PersonalDetails = observer(
127130
is_rendered_for_idv
128131
? getPersonalDetailsBaseValidationSchema(
129132
real_account_signup_target,
130-
is_country_code_dropdown_enabled
133+
isCountryCodeLoaded && isCountryCodeDropdownEnabled
131134
).concat(getIDVFormValidationSchema())
132135
: getPersonalDetailsBaseValidationSchema(
133136
real_account_signup_target,
134-
is_country_code_dropdown_enabled
137+
isCountryCodeLoaded && isCountryCodeDropdownEnabled
135138
),
136-
[is_rendered_for_idv, real_account_signup_target, is_country_code_dropdown_enabled]
139+
[is_rendered_for_idv, real_account_signup_target, isCountryCodeLoaded, isCountryCodeDropdownEnabled]
137140
);
138141

139142
/*

packages/core/src/App/Containers/RealAccountSignup/account-wizard.jsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ const StepperHeader = ({ has_target, has_real_account, items, getCurrentStep, ge
5757
const AccountWizard = observer(props => {
5858
const { client, notifications, ui, traders_hub } = useStore();
5959

60-
const is_country_code_dropdown_enabled = false;
60+
const [isCountryCodeDropdownEnabled, isCountryCodeLoaded] = useGrowthbookGetFeatureValue({
61+
featureFlag: 'enable_country_code_dropdown',
62+
});
6163
const { selected_phone_code } = useGetPhoneNumberList();
6264

6365
const { is_eu_user } = traders_hub;
@@ -66,7 +68,7 @@ const AccountWizard = observer(props => {
6668
...props,
6769
account_settings: {
6870
...client.account_settings,
69-
...(is_country_code_dropdown_enabled && { calling_country_code: '' }),
71+
...(isCountryCodeLoaded && isCountryCodeDropdownEnabled && { calling_country_code: '' }),
7072
},
7173
account_status: client.account_status,
7274
fetchAccountSettings: client.fetchAccountSettings,
@@ -155,12 +157,12 @@ const AccountWizard = observer(props => {
155157
selected_phone_code,
156158
};
157159
React.useEffect(() => {
158-
if (selected_phone_code && is_country_code_dropdown_enabled) {
160+
if (selected_phone_code && isCountryCodeLoaded && isCountryCodeDropdownEnabled) {
159161
const updated_items = getItems(get_items_props);
160162
setStateItems(updated_items);
161163
setRealAccountSignupFormData(updated_items);
162164
}
163-
}, [selected_phone_code, setRealAccountSignupFormData, is_country_code_dropdown_enabled]);
165+
}, [selected_phone_code, setRealAccountSignupFormData, isCountryCodeLoaded, isCountryCodeDropdownEnabled]);
164166

165167
React.useEffect(() => {
166168
setIsTradingAssessmentForNewUserEnabled(true);
@@ -201,15 +203,15 @@ const AccountWizard = observer(props => {
201203
items = getItems(get_items_props);
202204
}
203205

204-
if (items.length > 1 && 'phone' in items[1]?.form_value && !is_country_code_dropdown_enabled) {
206+
if (items.length > 1 && 'phone' in items[1]?.form_value && !isCountryCodeDropdownEnabled) {
205207
items[1].form_value.phone = items[1].form_value.phone || country_code || '';
206208
setStateItems(items);
207209
setRealAccountSignupFormData(items);
208210
}
209211
};
210212
getCountryCode(residence_list).then(setDefaultPhone);
211213
}
212-
}, [residence_list, setRealAccountSignupFormData]);
214+
}, [residence_list, setRealAccountSignupFormData, isCountryCodeDropdownEnabled]);
213215

214216
const fetchFromStorage = () => {
215217
const stored_items = localStorage.getItem('real_account_signup_wizard');

0 commit comments

Comments
 (0)