Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shahzaib / KYC-805 / remove expiry date for nimc slip from manual upload screen #10702

Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,14 @@
.manual-poi-details--mobile & {
flex-wrap: wrap;
}
}
&__field {
&:first-of-type {
margin-right: 2.4rem;
margin-bottom: 1.75rem;

.manual-poi-details--mobile & {
margin-right: 0;
}
.dc-datepicker {
margin-left: 2.4rem;
}
}
&__field {
margin-bottom: 1.75rem;
}
&__divider {
height: 2px;
background-color: var(--general-section-1);
Expand Down Expand Up @@ -145,6 +142,7 @@
display: flex;
flex-wrap: wrap;
margin-bottom: 1.7rem;
justify-content: center;
}
&__icons-item {
flex: 0.25;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from 'react';
import DocumentsUpload from './documents-upload';
import SelfieUpload from './selfie-upload';
import { SELFIE_DOCUMENT } from '../constants';
import { SELFIE_DOCUMENT, getDocumentIndex } from '../constants';
import './card-details.scss';
import { FormikValues } from 'formik';

type TCardDetails = {
data: FormikValues;
data: ReturnType<typeof getDocumentIndex>[number]['details'];
onComplete: (e: object) => void;
goToCards: () => void;
is_from_external?: boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React from 'react';
import classNames from 'classnames';
import { Formik, Form, FormikValues } from 'formik';
import { localize } from '@deriv/translations';
import { Localize, localize } from '@deriv/translations';
import { isMobile } from '@deriv/shared';
import { Button, Icon, Text } from '@deriv/components';
import InputField from './input-field';
import Uploader from './uploader';
import { setInitialValues, validateFields } from './utils';
import { ROOT_CLASS } from '../constants';
import { ROOT_CLASS, date_field, getDocumentIndex } from '../constants';

const icons = [
{
Expand All @@ -33,6 +33,7 @@ type TDocumentsUpload = {
is_from_external?: boolean;
goToCards: () => void;
onSubmit: () => void;
data: ReturnType<typeof getDocumentIndex>[number]['details'];
};

type TIconsItem = {
Expand All @@ -48,18 +49,25 @@ const IconsItem = ({ data }: TIconsItem) => (
</div>
);

const DocumentsUpload = ({
initial_values,
is_from_external,
data,
goToCards,
onSubmit,
}: TDocumentsUpload & TIconsItem) => {
const DocumentsUpload = ({ initial_values, is_from_external, data, goToCards, onSubmit }: TDocumentsUpload) => {
const { fields, documents_title, documents } = data;
const is_expiry_date_required = fields.some(field => field.name === date_field.name);

const fields_title = localize('First, enter your {{label}} and the expiry date.', {
label: fields?.[0].label,
});
const fields_title = is_expiry_date_required ? (
<Localize
i18n_default_text='First, enter your {{label}} and the expiry date.'
values={{
label: fields?.[0].label,
}}
/>
) : (
<Localize
i18n_default_text='First, enter your {{label}}.'
values={{
label: fields?.[0].label,
}}
/>
);

return (
<div
Expand Down Expand Up @@ -104,9 +112,11 @@ const DocumentsUpload = ({
))}
</div>
<div className={`${ROOT_CLASS}__icons`}>
{icons.map(item => (
<IconsItem key={item.icon} data={item} />
))}
{icons.map(item =>
item.icon === 'IcPoiDocExpiry' && !is_expiry_date_required ? null : (
<IconsItem key={item.icon} data={item} />
)
)}
</div>
</div>
<div className={`${ROOT_CLASS}__btns`}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,22 @@ export const checkIsEmpty = (value: unknown) => {
return typeof value === 'string' ? !value.trim() : !value;
};

export const validateFields = (values: FormikValues, fields = [], documents = []) => {
type TFields = {
name: string;
label: string;
type: string;
required: boolean;
}[];

type TDocument = {
document_type: string;
pageType: string;
name: string;
icon: string;
info: string;
}[];

export const validateFields = (values: FormikValues, fields: TFields = [], documents: TDocument = []) => {
const errors: FormikErrors<FormikValues> = {};

fields.forEach((field: { name: string; label: string; type: string; required: boolean }) => {
Expand All @@ -31,13 +46,13 @@ export const validateFields = (values: FormikValues, fields = [], documents = []
}
});

documents.forEach((document: { name: string; label: string }) => {
const { name, label } = document;
documents.forEach((document: { name: string }) => {
const { name } = document;
const value = values[name];

if (checkIsEmpty(value)) {
errors[name] = localize('{{label}} is required.', {
label,
errors[name] = localize('{{name}} is required.', {
name,
});
} else if (value.errors?.length) {
errors[name] = value.errors[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const SELFIE_DOCUMENT = {
info: localize('Upload your selfie.'),
};

const date_field = {
export const date_field = {
name: 'expiry_date',
label: localize('Expiry date'),
type: 'date',
Expand Down Expand Up @@ -154,7 +154,6 @@ export const getDocumentIndex = ({ country_code }: FormikValues) => [
type: 'text',
required: true,
},
{ ...date_field, required: false },
],
documents_title: localize('Next, upload both of the following documents.'),
documents: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import uploadFile from '../../../file-uploader-container/upload-file';
import OnfidoUpload from '../../../../Sections/Verification/ProofOfIdentity/onfido-sdk-view-container';

import CardDetails from './card-details';
import { SELFIE_DOCUMENT } from './constants';
import { SELFIE_DOCUMENT, getDocumentIndex } from './constants';
import { FormikValues } from 'formik';

const STATUS = {
Expand All @@ -18,24 +18,7 @@ const STATUS = {
};

type TDetailComponent = {
document: {
onfido_name?: string;
card: {
title: string;
description: string;
icon: string;
};
details: {
fields: {
name: string;
label: string;
type: string;
required: boolean;
}[];
documents_title: string;
documents: object[];
};
};
document: ReturnType<typeof getDocumentIndex>[number];
onClickBack: () => void;
root_class: string;
country_code_key?: string;
Expand Down