Skip to content

Commit 5d60713

Browse files
committed
chore: insert growthbook feature value for country code dropdown
1 parent 720c4ef commit 5d60713

File tree

4 files changed

+44
-14
lines changed

4 files changed

+44
-14
lines changed

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

+6-4
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

+23
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'),
@@ -44,6 +45,11 @@ jest.mock('@deriv-com/analytics', () => ({
4445
},
4546
}));
4647

48+
jest.mock('@deriv/hooks', () => ({
49+
...jest.requireActual('@deriv/hooks'),
50+
useGrowthbookGetFeatureValue: jest.fn(),
51+
}));
52+
4753
type TPersonalDetailsSectionForm = ComponentProps<typeof PersonalDetails>['value'];
4854

4955
const mock_warnings = {};
@@ -266,6 +272,10 @@ describe('<PersonalDetails/>', () => {
266272
real_account_signup_target: '',
267273
};
268274

275+
beforeEach(() => {
276+
(useGrowthbookGetFeatureValue as jest.Mock).mockReturnValue([false, false]);
277+
});
278+
269279
afterEach(() => {
270280
jest.clearAllMocks();
271281
});
@@ -440,6 +450,19 @@ describe('<PersonalDetails/>', () => {
440450
expect(mrs_radio_btn).not.toBeChecked();
441451
});
442452

453+
it('should display country code dropdown when isCountryCodeDropdownEnabled is true ', () => {
454+
(useGrowthbookGetFeatureValue as jest.Mock).mockReturnValue([true, true]);
455+
renderwithRouter({});
456+
457+
expect(screen.getByText(/code\*/i)).toBeInTheDocument();
458+
});
459+
460+
it('should not display country code dropdown when isCountryCodeDropdownEnabled is false ', () => {
461+
renderwithRouter({});
462+
463+
expect(screen.queryByText(/code\*/i)).not.toBeInTheDocument();
464+
});
465+
443466
it('should display the correct field details ', () => {
444467
renderwithRouter({});
445468

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

+7-4
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

+8-6
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)