|
|
|
@@ -6,7 +6,7 @@ import { |
|
|
|
IconButton |
|
|
|
} from '@mui/material'; |
|
|
|
import MainCard from "components/MainCard"; |
|
|
|
import { useEffect, useState, lazy } from "react"; |
|
|
|
import { useEffect, useState, useRef, lazy } from "react"; |
|
|
|
import * as yup from 'yup'; |
|
|
|
|
|
|
|
import { useFormik } from 'formik'; |
|
|
|
@@ -14,6 +14,7 @@ import * as FieldUtils from "utils/FieldUtils"; |
|
|
|
import * as HttpUtils from 'utils/HttpUtils'; |
|
|
|
import * as UrlUtils from "utils/ApiPathConst"; |
|
|
|
import * as ComboData from "utils/ComboData"; |
|
|
|
import en from "translations/en.json"; |
|
|
|
const LoadingComponent = Loadable(lazy(() => import('../../extra-pages/LoadingComponent'))); |
|
|
|
import Loadable from 'components/Loadable'; |
|
|
|
import { notifyActiveSuccess, notifyLockSuccess, notifySaveSuccess, notifyVerifySuccess } from 'utils/CommonFunction'; |
|
|
|
@@ -34,7 +35,7 @@ const UserInformationCard_Individual = ({ formData, loadDataFun }) => { |
|
|
|
const [onReady, setOnReady] = useState(false); |
|
|
|
const [errorMsg, setErrorMsg] = useState(""); |
|
|
|
const [showId, setshowId] = useState(false); |
|
|
|
const [selectedIdDocInputType, setSelectedIdDocInputType] = useState(""); |
|
|
|
const selectedIdDocInputTypeRef = useRef(""); |
|
|
|
|
|
|
|
const handleClickShowId = () => { |
|
|
|
setshowId(!showId); |
|
|
|
@@ -44,11 +45,20 @@ const UserInformationCard_Individual = ({ formData, loadDataFun }) => { |
|
|
|
event.preventDefault(); |
|
|
|
}; |
|
|
|
|
|
|
|
const getIdDocTypeLabel = (option) => { |
|
|
|
if (!option) return ""; |
|
|
|
if (typeof option === "string") { |
|
|
|
const item = ComboData.idDocType.find((o) => o.type === option); |
|
|
|
return item?.label ? (en[item.label] ?? option) : option; |
|
|
|
} |
|
|
|
return option.label ? (en[option.label] ?? "") : ""; |
|
|
|
}; |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
//if state data are ready and assign to different field |
|
|
|
// console.log(currentApplicationDetailData) |
|
|
|
if (Object.keys(currentUserData).length > 0) { |
|
|
|
setSelectedIdDocInputType(currentUserData.idDocType) |
|
|
|
selectedIdDocInputTypeRef.current = currentUserData.idDocType; |
|
|
|
setOnReady(true); |
|
|
|
} |
|
|
|
}, [currentUserData]); |
|
|
|
@@ -66,6 +76,22 @@ const UserInformationCard_Individual = ({ formData, loadDataFun }) => { |
|
|
|
return <Typography variant="errorMessage1">{errorMsg}</Typography> |
|
|
|
} |
|
|
|
|
|
|
|
function getIdDocTypeDisplayName(docType) { |
|
|
|
if (!docType) return ""; |
|
|
|
switch (docType) { |
|
|
|
case "HKID": |
|
|
|
return "Hong Kong ID Card"; |
|
|
|
case "passport": |
|
|
|
return "Passport"; |
|
|
|
case "CNID": |
|
|
|
return "Mainland ID Card"; |
|
|
|
case "otherCert": |
|
|
|
return "Professional Practice Certificate"; |
|
|
|
default: |
|
|
|
return docType; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
const formik = useFormik({ |
|
|
|
enableReinitialize: true, |
|
|
|
initialValues: currentUserData, |
|
|
|
@@ -84,16 +110,16 @@ const UserInformationCard_Individual = ({ formData, loadDataFun }) => { |
|
|
|
is: (verifiedBy) => verifiedBy != null, |
|
|
|
then: (schema) => schema.notRequired(), |
|
|
|
otherwise: (schema) => schema.required(getRequiredErrStr('number')) |
|
|
|
.matches(/^[aA-zZ0-9\s]+$/, { message: displayErrorMsg(`${selectedIdDocInputType}${intl.formatMessage({ id: 'noSpecialCharacter' })}`) }) |
|
|
|
.matches(/^\S*$/, { message: displayErrorMsg(`${selectedIdDocInputType}${intl.formatMessage({ id: 'noSpace' })}`) }) |
|
|
|
.test('checkIDCardFormat', displayErrorMsg(`${intl.formatMessage({ id: 'requiredValid' })}${selectedIdDocInputType}${intl.formatMessage({ id: 'number' })}`), function (value) { |
|
|
|
.matches(/^[aA-zZ0-9\s]+$/, { message: displayErrorMsg(`${selectedIdDocInputTypeRef.current}${intl.formatMessage({ id: 'noSpecialCharacter' })}`) }) |
|
|
|
.matches(/^\S*$/, { message: displayErrorMsg(`${selectedIdDocInputTypeRef.current}${intl.formatMessage({ id: 'noSpace' })}`) }) |
|
|
|
.test('checkIDCardFormat', displayErrorMsg(`${intl.formatMessage({ id: 'requiredValid' })}${getIdDocTypeDisplayName(selectedIdDocInputTypeRef.current)}${intl.formatMessage({ id: 'number' })}`), function (value) { |
|
|
|
var pattern_HKIDv1 = /^[A-Z]{1}[0-9]{6}$/; |
|
|
|
var pattern_HKIDv2 = /^[A-Z]{2}[0-9]{6}$/; |
|
|
|
var pattern_passport = /^[A-Z]{1}[0-9]{8}$/; |
|
|
|
var pattern_passport = /^[A-Za-z0-9]{6,9}$/; |
|
|
|
var pattern_CHID = /^[0-9]{6}(20|19)[0-9]{2}(0[1-9]|1[012])(0[1-9]|[12][0-9]|3[01])[0-9]{3}[0-9X]{1}/; |
|
|
|
var pattern_otherCert = /^[A-Z]{1}[0-9]{5,}/; |
|
|
|
if (value !== undefined) { |
|
|
|
switch (selectedIdDocInputType) { |
|
|
|
switch (selectedIdDocInputTypeRef.current) { |
|
|
|
case "HKID": |
|
|
|
if (value.match(pattern_HKIDv1)) { |
|
|
|
return true |
|
|
|
@@ -141,11 +167,10 @@ const UserInformationCard_Individual = ({ formData, loadDataFun }) => { |
|
|
|
is: (verifiedBy) => verifiedBy != null, |
|
|
|
then: (schema) => schema.notRequired(), |
|
|
|
otherwise: (schema) => schema.max(1, getMaxErrStr(1)).nullable() |
|
|
|
.matches(/^[A-Z0-9\s]+$/, { message: displayErrorMsg(`${selectedIdDocInputType}${intl.formatMessage({ id: 'noSpecialCharacter' })}`) }) |
|
|
|
.matches(/^[A-Z0-9\s]+$/, { message: displayErrorMsg(`${selectedIdDocInputTypeRef.current}${intl.formatMessage({ id: 'noSpecialCharacter' })}`) }) |
|
|
|
.test('checkIDCardFormat', displayErrorMsg(`${intl.formatMessage({ id: 'requiredNumberInQuote' })}`), function (value) { |
|
|
|
// console.log(selectedIdDocInputType) |
|
|
|
if (value != undefined || value != null) { |
|
|
|
switch (selectedIdDocInputType) { |
|
|
|
switch (selectedIdDocInputTypeRef.current) { |
|
|
|
case "HKID": |
|
|
|
if (value.length == 1) { |
|
|
|
return true |
|
|
|
@@ -162,7 +187,7 @@ const UserInformationCard_Individual = ({ formData, loadDataFun }) => { |
|
|
|
break; |
|
|
|
} |
|
|
|
} else { |
|
|
|
if (selectedIdDocInputType != "HKID"){ |
|
|
|
if (selectedIdDocInputTypeRef.current != "HKID"){ |
|
|
|
return true |
|
|
|
} else { |
|
|
|
return false |
|
|
|
@@ -392,28 +417,33 @@ const UserInformationCard_Individual = ({ formData, loadDataFun }) => { |
|
|
|
|
|
|
|
<Grid item xs={12} sm={12} md={12} lg={4}> |
|
|
|
{FieldUtils.getComboField({ |
|
|
|
label: "ID Type:", |
|
|
|
label: `${en.idDocType}:`, |
|
|
|
valueName: "idDocType", |
|
|
|
disabled: (!editMode), |
|
|
|
disabled: !editMode || currentUserData.verifiedBy != null, |
|
|
|
dataList: ComboData.idDocType, |
|
|
|
filterOptions: (options) => options, |
|
|
|
getOptionLabel: (item) => item ? typeof item === 'string' ? item : (item["type"] ? item["type"] + "-" + item["label"] : "") : "", |
|
|
|
getOptionLabel: getIdDocTypeLabel, |
|
|
|
isOptionEqualToValue: (option, value) => { |
|
|
|
if (typeof value === "string") { |
|
|
|
return option?.type === value; |
|
|
|
} |
|
|
|
return option?.type === value?.type; |
|
|
|
}, |
|
|
|
onInputChange: (event, newValue, setInputValue) => { |
|
|
|
if (newValue == null) { |
|
|
|
setInputValue(""); |
|
|
|
return; |
|
|
|
} |
|
|
|
let _val = newValue.split("-"); |
|
|
|
if (_val[0]) { |
|
|
|
setInputValue(_val[0]); |
|
|
|
} |
|
|
|
setInputValue(newValue); |
|
|
|
}, |
|
|
|
onChange: (event, newValue) => { |
|
|
|
if (newValue == null) { |
|
|
|
formik.setFieldValue("idDocType", ""); |
|
|
|
selectedIdDocInputTypeRef.current = ""; |
|
|
|
return; |
|
|
|
} |
|
|
|
formik.setFieldValue("idDocType", newValue.type); |
|
|
|
setSelectedIdDocInputType(newValue.type); |
|
|
|
selectedIdDocInputTypeRef.current = newValue.type; |
|
|
|
if (newValue.type !== "HKID") { |
|
|
|
formik.setFieldValue("checkDigit", "") |
|
|
|
} |
|
|
|
@@ -496,7 +526,7 @@ const UserInformationCard_Individual = ({ formData, loadDataFun }) => { |
|
|
|
form: formik, |
|
|
|
placeholder: intl.formatMessage({ id: 'idDocNumber' }), |
|
|
|
inputProps: { |
|
|
|
maxLength: 7, |
|
|
|
maxLength: 8, |
|
|
|
onKeyDown: (e) => { |
|
|
|
if (e.key === 'Enter') { |
|
|
|
e.preventDefault(); |
|
|
|
|