Skip to content

Commit 2dff6d0

Browse files
Merge pull request #130 from likhith-deriv/likhith/TRAH-4189/change-fa-employment-status-logic
chore: incorporated changes to Financial assessment
2 parents 8128bc3 + 0250eda commit 2dff6d0

File tree

9 files changed

+179
-8
lines changed

9 files changed

+179
-8
lines changed

packages/account/src/Components/forms/form-fields/employment-status.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import { Dropdown, SelectNative } from '@deriv/components';
44
import { useTranslations } from '@deriv-com/translations';
55
import { getEmploymentStatusList } from '../../../Constants/financial-information-list';
66
import { useDevice } from '@deriv-com/ui';
7+
import clsx from 'clsx';
78

89
type TEmploymentStatusFieldProps = {
910
required: boolean;
1011
is_disabled: boolean;
12+
fieldFocused?: boolean;
1113
};
1214

13-
const EmploymentStatusField = ({ required, is_disabled }: TEmploymentStatusFieldProps) => {
15+
const EmploymentStatusField = ({ required, is_disabled, fieldFocused }: TEmploymentStatusFieldProps) => {
1416
const { isDesktop } = useDevice();
1517
const { localize } = useTranslations();
1618

@@ -21,7 +23,6 @@ const EmploymentStatusField = ({ required, is_disabled }: TEmploymentStatusField
2123
{isDesktop ? (
2224
<Dropdown
2325
{...field}
24-
className='dropdown-field'
2526
placeholder={required ? localize('Employment status*') : localize('Employment status')}
2627
is_align_text_left
2728
name={field.name}
@@ -34,6 +35,7 @@ const EmploymentStatusField = ({ required, is_disabled }: TEmploymentStatusField
3435
handleBlur={handleBlur}
3536
error={meta.touched ? meta.error : undefined}
3637
disabled={is_disabled}
38+
className={clsx('dropdown-field', { 'focus-field': fieldFocused })}
3739
/>
3840
) : (
3941
<SelectNative
@@ -49,6 +51,7 @@ const EmploymentStatusField = ({ required, is_disabled }: TEmploymentStatusField
4951
handleChange(e);
5052
}}
5153
disabled={is_disabled}
54+
className={clsx({ 'focus-field': fieldFocused })}
5255
/>
5356
)}
5457
</div>

packages/account/src/Components/forms/form-fields/tax-indentification-number.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ import FormInputField from './form-input-field';
33
import { Popover } from '@deriv/components';
44
import { OECD_TIN_FORMAT_URL } from '../../../Constants/external-urls';
55
import { useDevice } from '@deriv-com/ui';
6+
import clsx from 'clsx';
67

78
type TTaxIdentificationNumberFieldProps = {
89
required?: boolean;
910
disabled: boolean;
1011
is_tin_popover_open: boolean;
1112
setIsTinPopoverOpen: (is_open: boolean) => void;
1213
setIsTaxResidencePopoverOpen: (is_open: boolean) => void;
14+
fieldFocused?: boolean;
1315
};
1416

1517
const TaxIdentificationNumberField = ({
@@ -18,6 +20,7 @@ const TaxIdentificationNumberField = ({
1820
setIsTinPopoverOpen,
1921
setIsTaxResidencePopoverOpen,
2022
disabled,
23+
fieldFocused,
2124
}: TTaxIdentificationNumberFieldProps) => {
2225
const { localize } = useTranslations();
2326

@@ -32,6 +35,7 @@ const TaxIdentificationNumberField = ({
3235
data-testid='tax_identification_number'
3336
disabled={disabled}
3437
required={required}
38+
className={clsx({ 'focus-field': fieldFocused })}
3539
/>
3640
<div
3741
data-testid='tax_identification_number_pop_over'

packages/account/src/Components/forms/form-fields/tax-residence.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ import { useResidenceList } from '@deriv/hooks';
99
import { TItem } from '@deriv/components/src/components/dropdown-list';
1010
import { useTranslations } from '@deriv-com/translations';
1111
import { useDevice } from '@deriv-com/ui';
12+
import clsx from 'clsx';
1213

1314
type TTaxResidenceFieldProps = {
1415
required?: boolean;
1516
setIsTaxResidencePopoverOpen: (is_open: boolean) => void;
1617
setIsTinPopoverOpen: (is_open: boolean) => void;
1718
is_tax_residence_popover_open: boolean;
1819
disabled: boolean;
20+
fieldFocused?: boolean;
1921
};
2022

2123
const TaxResidenceField = ({
@@ -24,6 +26,7 @@ const TaxResidenceField = ({
2426
setIsTinPopoverOpen,
2527
is_tax_residence_popover_open,
2628
disabled,
29+
fieldFocused,
2730
}: TTaxResidenceFieldProps) => {
2831
const { data: residence_list } = useResidenceList();
2932
const { isDesktop } = useDevice();
@@ -51,6 +54,7 @@ const TaxResidenceField = ({
5154
data-testid='tax_residence'
5255
disabled={disabled}
5356
required={required}
57+
className={clsx({ 'focus-field': fieldFocused })}
5458
/>
5559
) : (
5660
<SelectNative
@@ -69,6 +73,7 @@ const TaxResidenceField = ({
6973
required={required}
7074
data_testid='tax_residence_mobile'
7175
disabled={disabled}
76+
className={clsx({ 'focus-field': fieldFocused })}
7277
/>
7378
)}
7479
<div

packages/account/src/Containers/employment-tax-details-container/employment-tax-details-container.tsx

+21-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type TEmploymentTaxDetailsContainerProps = {
2222
handleChange: (value: string) => void;
2323
tin_validation_config: TinValidations;
2424
id?: string;
25+
should_focus_fields?: boolean;
2526
};
2627

2728
const EmploymentTaxDetailsContainer = observer(
@@ -31,12 +32,15 @@ const EmploymentTaxDetailsContainer = observer(
3132
should_display_long_message,
3233
tin_validation_config,
3334
handleChange,
35+
should_focus_fields,
3436
}: TEmploymentTaxDetailsContainerProps) => {
3537
const { values, setFieldValue, touched, errors, setValues } = useFormikContext<FormikValues>();
3638
const { isDesktop } = useDevice();
3739
const { data: residence_list } = useResidenceList();
3840
const { client } = useStore();
3941

42+
const { is_virtual, account_settings } = client;
43+
4044
const [is_tax_residence_popover_open, setIsTaxResidencePopoverOpen] = useState(false);
4145
const [is_tin_popover_open, setIsTinPopoverOpen] = useState(false);
4246

@@ -117,22 +121,26 @@ const EmploymentTaxDetailsContainer = observer(
117121

118122
const { tin_employment_status_bypass } = tin_validation_config;
119123

120-
const is_tin_required = !client.is_virtual && !tin_employment_status_bypass?.includes(values.employment_status);
124+
const is_tin_required = !is_virtual && !tin_employment_status_bypass?.includes(values.employment_status);
121125

122126
const should_show_no_tax_details_checkbox =
123127
(tin_employment_status_bypass?.includes(values.employment_status) && !!values.tax_residence) ||
124128
Boolean(values.tin_skipped);
125129

126130
const should_show_tax_confirm_checkbox =
127-
!client.account_settings.tax_identification_number || touched.tax_identification_number;
131+
!account_settings.tax_identification_number || touched.tax_identification_number;
128132

129133
const isFieldDisabled = (field_name: string) => isFieldImmutable(field_name, editable_fields);
130134

131135
return (
132136
<div id={'employment-tax-section'}>
133-
<EmploymentStatusField required is_disabled={isFieldDisabled('employment_status')} />
137+
<EmploymentStatusField
138+
required
139+
is_disabled={isFieldDisabled('employment_status')}
140+
fieldFocused={should_focus_fields && !account_settings.employment_status}
141+
/>
134142

135-
{!client.account_settings.tax_identification_number && should_show_no_tax_details_checkbox && (
143+
{!account_settings.tax_identification_number && should_show_no_tax_details_checkbox && (
136144
<Checkbox
137145
name='tin_skipped'
138146
className='employment_tax_detail_field-checkbox'
@@ -164,6 +172,9 @@ const EmploymentTaxDetailsContainer = observer(
164172
setIsTaxResidencePopoverOpen={setIsTaxResidencePopoverOpen}
165173
setIsTinPopoverOpen={setIsTinPopoverOpen}
166174
required={(should_display_long_message && !values.tin_skipped) || is_tin_required}
175+
fieldFocused={
176+
should_focus_fields && (!account_settings.tax_residence || !account_settings.residence)
177+
}
167178
/>
168179
</div>
169180
<div ref={tin_ref} className='account-form__fieldset'>
@@ -173,6 +184,12 @@ const EmploymentTaxDetailsContainer = observer(
173184
setIsTinPopoverOpen={setIsTinPopoverOpen}
174185
setIsTaxResidencePopoverOpen={setIsTaxResidencePopoverOpen}
175186
required={(should_display_long_message && !values.tin_skipped) || is_tin_required}
187+
fieldFocused={
188+
should_focus_fields &&
189+
values.employment_status &&
190+
!values.tin_skipped &&
191+
(should_display_long_message || is_tin_required)
192+
}
176193
/>
177194
</div>
178195
{should_show_tax_confirm_checkbox && (
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { Button, Text } from '@deriv/components';
2+
import { Localize, useTranslations } from '@deriv-com/translations';
3+
import { useDevice } from '@deriv-com/ui';
4+
import { useHistory } from 'react-router';
5+
import { routes } from '@deriv/shared';
6+
import FormFooter from '../../../Components/form-footer';
7+
import { DerivLightOrdersDefaultIcon } from '@deriv/quill-icons';
8+
import { observer, useStore } from '@deriv/stores';
9+
import './navigate-to-personal-details.scss';
10+
11+
const NavigateToPersonalDetails = observer(() => {
12+
const { localize } = useTranslations();
13+
const { isDesktop } = useDevice();
14+
const { ui, client } = useStore();
15+
const history = useHistory();
16+
17+
const { account_settings } = client;
18+
19+
const handleOnclick = () => {
20+
let field_to_scroll;
21+
22+
if (!account_settings.account_opening_reason) {
23+
field_to_scroll = 'account-opening-reason';
24+
} else {
25+
field_to_scroll = 'employment-tax-section';
26+
}
27+
28+
ui.setFieldRefToFocus(field_to_scroll);
29+
history.push(routes.personal_details);
30+
};
31+
32+
const icon_size = isDesktop ? { height: '200px', width: '200px' } : { height: '124px', width: '124px' };
33+
34+
return (
35+
<div className='navigate-to-personal-details'>
36+
<div className='navigate-to-personal-details__body'>
37+
<DerivLightOrdersDefaultIcon {...icon_size} />
38+
<Text
39+
as='p'
40+
size={isDesktop ? 'sm' : 's'}
41+
className='navigate-to-personal-details__body--text'
42+
align='center'
43+
>
44+
<Localize i18n_default_text='Update your personal details in account settings before starting your financial assessment.' />
45+
</Text>
46+
</div>
47+
{isDesktop ? (
48+
<div className='navigate-to-personal-details__footer'>
49+
<Button
50+
type='button'
51+
has_effect
52+
text={localize('Update now')}
53+
primary
54+
large
55+
onClick={handleOnclick}
56+
/>
57+
</div>
58+
) : (
59+
<FormFooter className='navigate-to-personal-details__footer--layout'>
60+
<Button
61+
onClick={handleOnclick}
62+
has_effect
63+
is_loading={false}
64+
text={localize('Update now')}
65+
large
66+
primary
67+
/>
68+
</FormFooter>
69+
)}
70+
</div>
71+
);
72+
});
73+
74+
export default NavigateToPersonalDetails;

packages/account/src/Sections/Assessment/FinancialAssessment/financial-assessment.tsx

+11
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import { getFormattedOccupationList } from 'Configs/financial-details-config';
4040
import { TFinancialInformationForm } from 'Types';
4141
import { EmploymentStatusField } from 'Components/forms/form-fields';
4242
import { useDevice } from '@deriv-com/ui';
43+
import NavigateToPersonalDetails from './NavigateToPersonalDetails';
4344

4445
type TConfirmationPage = {
4546
toggleModal: (prop: boolean) => void;
@@ -194,6 +195,7 @@ const FinancialAssessment = observer(() => {
194195
updateAccountStatus,
195196
is_authentication_needed,
196197
is_financial_information_incomplete,
198+
account_settings,
197199
} = client;
198200
const { isMobile, isTablet, isDesktop } = useDevice();
199201
const { platform, routeBackInApp } = common;
@@ -390,6 +392,15 @@ const FinancialAssessment = observer(() => {
390392
return form_data;
391393
};
392394

395+
if (
396+
!employment_status ||
397+
!account_settings.account_opening_reason ||
398+
!account_settings.tax_residence ||
399+
!account_settings.tax_identification_number
400+
) {
401+
return <NavigateToPersonalDetails />;
402+
}
403+
393404
return (
394405
<Formik initialValues={setInitialFormData()} enableReinitialize validate={validateFields} onSubmit={onSubmit}>
395406
{({
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
.navigate-to-personal-details {
2+
display: flex;
3+
flex-direction: column;
4+
5+
@include desktop-screen {
6+
position: relative;
7+
top: 10%;
8+
row-gap: 2.6rem;
9+
width: 50%;
10+
height: 100%;
11+
align-self: center;
12+
}
13+
14+
&__body {
15+
display: flex;
16+
flex-direction: column;
17+
align-items: center;
18+
19+
@include mobile-or-tablet-screen {
20+
margin-top: 45%;
21+
}
22+
23+
&--text {
24+
@include desktop-screen {
25+
line-height: 3rem;
26+
}
27+
28+
@include mobile-or-tablet-screen {
29+
line-height: 2.4rem;
30+
padding: 0 3.2rem;
31+
}
32+
}
33+
34+
@include desktop-screen {
35+
row-gap: 2.6rem;
36+
}
37+
38+
@include mobile-or-tablet-screen {
39+
row-gap: 1.6rem;
40+
flex-grow: 1;
41+
}
42+
}
43+
44+
&__footer {
45+
width: 100%;
46+
display: flex;
47+
justify-content: center;
48+
49+
&--layout {
50+
padding: 1.6rem;
51+
}
52+
}
53+
}

packages/account/src/Sections/Profile/PersonalDetails/personal-details-form.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,10 @@ const PersonalDetailsForm = observer(() => {
439439
Boolean(account_settings?.account_opening_reason)
440440
}
441441
required
442-
fieldFocused={field_ref_to_focus === 'account-opening-reason'}
442+
fieldFocused={
443+
!account_settings.account_opening_reason &&
444+
field_ref_to_focus === 'account-opening-reason'
445+
}
443446
/>
444447
</Fragment>
445448
)}
@@ -452,6 +455,7 @@ const PersonalDetailsForm = observer(() => {
452455
handleChange={mutate}
453456
tin_validation_config={tin_validation_config}
454457
should_display_long_message={is_mf_account}
458+
should_focus_fields={field_ref_to_focus === 'employment-tax-section'}
455459
/>
456460
{!is_virtual && (
457461
<Fragment>

packages/core/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
"@deriv/hooks": "^1.0.0",
115115
"@deriv/p2p": "^0.7.3",
116116
"@deriv/quill-design": "^1.3.2",
117-
"@deriv/quill-icons": "2.1.0",
117+
"@deriv/quill-icons": "2.1.0",
118118
"@deriv/reports": "^1.0.0",
119119
"@deriv/shared": "^1.0.0",
120120
"@deriv/stores": "^1.0.0",

0 commit comments

Comments
 (0)