Skip to content

Commit

Permalink
chore: insert growthbook feature value for country code dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
suisin-deriv committed Feb 10, 2025
1 parent 720c4ef commit 5d60713
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 14 deletions.
10 changes: 6 additions & 4 deletions packages/account/src/Components/forms/personal-details-form.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import clsx from 'clsx';
import { Field, useFormikContext } from 'formik';

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

const is_country_code_dropdown_enabled = false;
const [isCountryCodeDropdownEnabled, isCountryCodeLoaded] = useGrowthbookGetFeatureValue({
featureFlag: 'enable_country_code_dropdown',
});

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

Expand Down Expand Up @@ -388,7 +390,7 @@ const PersonalDetailsForm = props => {
)}
{!is_svg_only && 'phone' in values && (
<PhoneField
is_country_code_dropdown_enabled={is_country_code_dropdown_enabled}
is_country_code_dropdown_enabled={isCountryCodeLoaded && isCountryCodeDropdownEnabled}
handleChange={handleChange}
setFieldValue={setFieldValue}
country_code_list={legacy_core_countries_list}
Expand Down Expand Up @@ -432,7 +434,7 @@ const PersonalDetailsForm = props => {
<FormSubHeader title={localize('Additional information')} />
{'phone' in values && (
<PhoneField
is_country_code_dropdown_enabled={is_country_code_dropdown_enabled}
is_country_code_dropdown_enabled={isCountryCodeLoaded && isCountryCodeDropdownEnabled}
handleChange={handleChange}
setFieldValue={setFieldValue}
country_code_list={legacy_core_countries_list}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { FormikErrors } from 'formik';
import { getIDVFormValidationSchema } from '../../../Configs/kyc-validation-config';
import { useDevice } from '@deriv-com/ui';
import { APIProvider } from '@deriv/api';
import { useGrowthbookGetFeatureValue } from '@deriv/hooks';

jest.mock('@deriv-com/ui', () => ({
...jest.requireActual('@deriv-com/ui'),
Expand Down Expand Up @@ -44,6 +45,11 @@ jest.mock('@deriv-com/analytics', () => ({
},
}));

jest.mock('@deriv/hooks', () => ({
...jest.requireActual('@deriv/hooks'),
useGrowthbookGetFeatureValue: jest.fn(),
}));

type TPersonalDetailsSectionForm = ComponentProps<typeof PersonalDetails>['value'];

const mock_warnings = {};
Expand Down Expand Up @@ -266,6 +272,10 @@ describe('<PersonalDetails/>', () => {
real_account_signup_target: '',
};

beforeEach(() => {
(useGrowthbookGetFeatureValue as jest.Mock).mockReturnValue([false, false]);
});

afterEach(() => {
jest.clearAllMocks();
});
Expand Down Expand Up @@ -440,6 +450,19 @@ describe('<PersonalDetails/>', () => {
expect(mrs_radio_btn).not.toBeChecked();
});

it('should display country code dropdown when isCountryCodeDropdownEnabled is true ', () => {
(useGrowthbookGetFeatureValue as jest.Mock).mockReturnValue([true, true]);
renderwithRouter({});

expect(screen.getByText(/code\*/i)).toBeInTheDocument();
});

it('should not display country code dropdown when isCountryCodeDropdownEnabled is false ', () => {
renderwithRouter({});

expect(screen.queryByText(/code\*/i)).not.toBeInTheDocument();
});

it('should display the correct field details ', () => {
renderwithRouter({});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { TIDVFormValues, TListItem, TPersonalDetailsBaseForm } from '../../Types
import { GetAccountStatus, GetSettings, ResidenceList } from '@deriv/api-types';
import { getPersonalDetailsBaseValidationSchema } from '../../Configs/user-profile-validation-config';
import { getIDVFormValidationSchema } from '../../Configs/kyc-validation-config';
import { useGrowthbookGetFeatureValue } from '@deriv/hooks';

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

const is_country_code_dropdown_enabled = false;
const [isCountryCodeDropdownEnabled, isCountryCodeLoaded] = useGrowthbookGetFeatureValue({
featureFlag: 'enable_country_code_dropdown',
});
const { isDesktop } = useDevice();
const handleCancel = (values: TPersonalDetailsSectionForm) => {
const current_step = getCurrentStep() - 1;
Expand Down Expand Up @@ -127,13 +130,13 @@ const PersonalDetails = observer(
is_rendered_for_idv
? getPersonalDetailsBaseValidationSchema(
real_account_signup_target,
is_country_code_dropdown_enabled
isCountryCodeLoaded && isCountryCodeDropdownEnabled
).concat(getIDVFormValidationSchema())
: getPersonalDetailsBaseValidationSchema(
real_account_signup_target,
is_country_code_dropdown_enabled
isCountryCodeLoaded && isCountryCodeDropdownEnabled
),
[is_rendered_for_idv, real_account_signup_target, is_country_code_dropdown_enabled]
[is_rendered_for_idv, real_account_signup_target, isCountryCodeLoaded, isCountryCodeDropdownEnabled]
);

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ const StepperHeader = ({ has_target, has_real_account, items, getCurrentStep, ge
const AccountWizard = observer(props => {
const { client, notifications, ui, traders_hub } = useStore();

const is_country_code_dropdown_enabled = false;
const [isCountryCodeDropdownEnabled, isCountryCodeLoaded] = useGrowthbookGetFeatureValue({
featureFlag: 'enable_country_code_dropdown',
});
const { selected_phone_code } = useGetPhoneNumberList();

const { is_eu_user } = traders_hub;
Expand All @@ -66,7 +68,7 @@ const AccountWizard = observer(props => {
...props,
account_settings: {
...client.account_settings,
...(is_country_code_dropdown_enabled && { calling_country_code: '' }),
...(isCountryCodeLoaded && isCountryCodeDropdownEnabled && { calling_country_code: '' }),
},
account_status: client.account_status,
fetchAccountSettings: client.fetchAccountSettings,
Expand Down Expand Up @@ -155,12 +157,12 @@ const AccountWizard = observer(props => {
selected_phone_code,
};
React.useEffect(() => {
if (selected_phone_code && is_country_code_dropdown_enabled) {
if (selected_phone_code && isCountryCodeLoaded && isCountryCodeDropdownEnabled) {
const updated_items = getItems(get_items_props);
setStateItems(updated_items);
setRealAccountSignupFormData(updated_items);
}
}, [selected_phone_code, setRealAccountSignupFormData, is_country_code_dropdown_enabled]);
}, [selected_phone_code, setRealAccountSignupFormData, isCountryCodeLoaded, isCountryCodeDropdownEnabled]);

React.useEffect(() => {
setIsTradingAssessmentForNewUserEnabled(true);
Expand Down Expand Up @@ -201,15 +203,15 @@ const AccountWizard = observer(props => {
items = getItems(get_items_props);
}

if (items.length > 1 && 'phone' in items[1]?.form_value && !is_country_code_dropdown_enabled) {
if (items.length > 1 && 'phone' in items[1]?.form_value && !isCountryCodeDropdownEnabled) {
items[1].form_value.phone = items[1].form_value.phone || country_code || '';
setStateItems(items);
setRealAccountSignupFormData(items);
}
};
getCountryCode(residence_list).then(setDefaultPhone);
}
}, [residence_list, setRealAccountSignupFormData]);
}, [residence_list, setRealAccountSignupFormData, isCountryCodeDropdownEnabled]);

const fetchFromStorage = () => {
const stored_items = localStorage.getItem('real_account_signup_wizard');
Expand Down

0 comments on commit 5d60713

Please sign in to comment.