Skip to content

Commit

Permalink
fix: updated with latest master
Browse files Browse the repository at this point in the history
  • Loading branch information
nada-deriv committed Mar 13, 2023
2 parents 021036a + e914919 commit 9fc1696
Show file tree
Hide file tree
Showing 229 changed files with 1,798 additions and 11,369 deletions.
5 changes: 5 additions & 0 deletions global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@ declare global {
}
}

declare module '*.svg' {
const content: React.SVGAttributes<SVGElement>;
export default content;
}

export {};
22 changes: 7 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const LanguageRadioButton = ({ is_current_language, id, language_code, name, onC
value={language_code}
className='settings-language__language--radio-button'
/>
<label htmlFor={id}>
<label htmlFor={id} className='settings-language__language--center-label'>
<div>
<Icon
icon={`IcFlag${id.replace('_', '-')}`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -727,4 +727,18 @@ describe('<PersonalDetails/>', () => {
expect(screen.queryByText(tax_residence_pop_over_text)).not.toBeInTheDocument();
expect(screen.queryByRole('link', { name: 'here' })).not.toBeInTheDocument();
});

it('should autopopulate tax_residence for MF clients', () => {
const new_props = {
...props,
is_mf: true,
value: {
...props.value,
tax_residence: 'Malta',
},
};
renderwithRouter(<PersonalDetails {...new_props} />);
const el_tax_residence = screen.getByTestId('selected_value');
expect(el_tax_residence).toHaveTextContent('Malta');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import { Formik, Field } from 'formik';
import { localize, Localize } from '@deriv/translations';
import { formatInput, WS } from '@deriv/shared';
import {
isSequentialNumber,
isRecurringNumberRegex,
documentAdditionalError,
getDocumentData,
getRegex,
isRecurringNumberRegex,
isSequentialNumber,
preventEmptyClipboardPaste,
} from './utils';
import { useToggleValidation } from '../../hooks/useToggleValidation';
Expand Down Expand Up @@ -47,7 +48,21 @@ const IdvDocumentSubmit = ({ handleBack, handleViewComplete, selected_country, i
filtered_documents.map(key => {
const { display_name, format } = document_data[key];
const { new_display_name, example_format, sample_image } = getDocumentData(country_code, key) || {};
const needs_additional_document = !!document_data[key].additional;

if (needs_additional_document) {
return {
id: key,
text: new_display_name || display_name,
additional: {
display_name: document_data[key].additional?.display_name,
format: document_data[key].additional?.format,
},
value: format,
sample_image,
example_format,
};
}
return {
id: key,
text: new_display_name || display_name,
Expand All @@ -59,6 +74,16 @@ const IdvDocumentSubmit = ({ handleBack, handleViewComplete, selected_country, i
);
}, [country_code, document_data]);

const onKeyUp = (e, document_name, values, setFieldValue) => {
const { example_format } =
document_name === 'document_number' ? values.document_type : values.document_type.additional;
const current_input = example_format.includes('-')
? formatInput(example_format, current_input || e.target.value, '-')
: e.target.value;
setFieldValue(document_name, current_input, true);
validateFields(values);
};

const resetDocumentItemSelected = setFieldValue => {
setFieldValue(
'document_type',
Expand Down Expand Up @@ -89,16 +114,24 @@ const IdvDocumentSubmit = ({ handleBack, handleViewComplete, selected_country, i

const validateFields = values => {
const errors = {};
const { document_type, document_number } = values;
const { document_type, document_number, document_additional } = values;
const is_sequential_number = isSequentialNumber(document_number);
const is_recurring_number = isRecurringNumberRegex(document_number);
const needs_additional_document = !!document_type.additional;

if (!document_type || !document_type.text || !document_type.value) {
errors.document_type = localize('Please select a document type.');
} else {
setInputDisable(false);
}

if (needs_additional_document) {
const error_message = documentAdditionalError(document_additional, document_type.additional?.format);
if (error_message)
errors.document_additional =
localize(error_message) + getExampleFormat(document_type.additional?.example_format);
}

if (!document_number) {
errors.document_number =
localize('Please enter your document number. ') + getExampleFormat(document_type.example_format);
Expand All @@ -120,11 +153,11 @@ const IdvDocumentSubmit = ({ handleBack, handleViewComplete, selected_country, i

const submitHandler = (values, { setSubmitting, setErrors }) => {
setSubmitting(true);
const { document_number, document_type } = values;
const submit_data = {
identity_verification_document_add: 1,
document_number,
document_type: document_type.id,
document_number: values.document_number,
document_additional: values.document_additional || '',
document_type: values.document_type.id,
issuing_country: country_code,
};

Expand Down Expand Up @@ -232,34 +265,55 @@ const IdvDocumentSubmit = ({ handleBack, handleViewComplete, selected_country, i
<fieldset className='proof-of-identity__fieldset-input'>
<Field name='document_number'>
{({ field }) => (
<Input
{...field}
name='document_number'
bottom_label={
values.document_type &&
getExampleFormat(values.document_type.example_format)
}
disabled={is_input_disable}
error={
(touched.document_number && errors.document_number) ||
errors.error_message
}
autoComplete='off'
placeholder='Enter your document number'
value={values.document_number}
onPaste={preventEmptyClipboardPaste}
onBlur={handleBlur}
onChange={handleChange}
onKeyUp={e => {
const { example_format } = values.document_type;
const current_input = example_format.includes('-')
? formatInput(example_format, current_input || e.target.value, '-')
: e.target.value;
setFieldValue('document_number', current_input, true);
validateFields(values);
}}
required
/>
<React.Fragment>
<Input
{...field}
name='document_number'
bottom_label={
values.document_type &&
getExampleFormat(values.document_type.example_format)
}
disabled={is_input_disable}
error={
(touched.document_number && errors.document_number) ||
errors.error_message
}
autoComplete='off'
placeholder='Enter your document number'
value={values.document_number}
onPaste={preventEmptyClipboardPaste}
onBlur={handleBlur}
onChange={handleChange}
onKeyUp={e => onKeyUp(e, 'document_number', values, setFieldValue)}
required
/>
{values.document_type.additional?.display_name && (
<Input
{...field}
name='document_additional'
bottom_label={
values.document_type.additional &&
getExampleFormat(
values.document_type.additional?.example_format
)
}
disabled={is_input_disable}
error={
(touched.document_additional && errors.document_additional) ||
errors.error_message
}
autoComplete='off'
placeholder={`Enter your ${values.document_type.additional?.display_name.toLowerCase()}`}
value={values.document_additional}
onPaste={preventEmptyClipboardPaste}
onBlur={handleBlur}
onChange={handleChange}
onKeyUp={e =>
onKeyUp(e, 'document_additional', values, setFieldValue)
}
/>
)}
</React.Fragment>
)}
</Field>
</fieldset>
Expand Down
14 changes: 14 additions & 0 deletions packages/account/src/Components/poi/idv-document-submit/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ const createDocumentPatterns = () => {
return pattern_array;
};

export const documentAdditionalError = (document_additional, document_additional_format) => {
let error_message = null;
if (!document_additional) {
error_message = 'Please enter your document number. ';
} else {
const format_regex = getRegex(document_additional_format);
if (!format_regex.test(document_additional)) {
error_message = 'Please enter the correct format. ';
}
}

return error_message;
};

export const isSequentialNumber = document_number => {
const trimmed_document_number = document_number.replace(/[.-]*/g, '');
const pattern_results = [];
Expand Down
Loading

0 comments on commit 9fc1696

Please sign in to comment.