Jason Chuang 8 часов назад
Родитель
Сommit
1260cd4800
3 измененных файлов: 34 добавлений и 19 удалений
  1. +30
    -15
      src/pages/User/DetailsPage_Individual/UserInformationCard_Individual.js
  2. +2
    -2
      src/pages/authentication/auth-forms/CustomFormWizard.js
  3. +2
    -2
      src/translations/en.json

+ 30
- 15
src/pages/User/DetailsPage_Individual/UserInformationCard_Individual.js Просмотреть файл

@@ -6,7 +6,7 @@ import {
IconButton IconButton
} from '@mui/material'; } from '@mui/material';
import MainCard from "components/MainCard"; import MainCard from "components/MainCard";
import { useEffect, useState, lazy } from "react";
import { useEffect, useState, useRef, lazy } from "react";
import * as yup from 'yup'; import * as yup from 'yup';


import { useFormik } from 'formik'; import { useFormik } from 'formik';
@@ -36,7 +36,7 @@ const UserInformationCard_Individual = ({ formData, loadDataFun }) => {
const [onReady, setOnReady] = useState(false); const [onReady, setOnReady] = useState(false);
const [errorMsg, setErrorMsg] = useState(""); const [errorMsg, setErrorMsg] = useState("");
const [showId, setshowId] = useState(false); const [showId, setshowId] = useState(false);
const [selectedIdDocInputType, setSelectedIdDocInputType] = useState("");
const selectedIdDocInputTypeRef = useRef("");


const handleClickShowId = () => { const handleClickShowId = () => {
setshowId(!showId); setshowId(!showId);
@@ -59,7 +59,7 @@ const UserInformationCard_Individual = ({ formData, loadDataFun }) => {
//if state data are ready and assign to different field //if state data are ready and assign to different field
// console.log(currentApplicationDetailData) // console.log(currentApplicationDetailData)
if (Object.keys(currentUserData).length > 0) { if (Object.keys(currentUserData).length > 0) {
setSelectedIdDocInputType(currentUserData.idDocType);
selectedIdDocInputTypeRef.current = currentUserData.idDocType;
setOnReady(true); setOnReady(true);
} }
}, [currentUserData]); }, [currentUserData]);
@@ -77,6 +77,22 @@ const UserInformationCard_Individual = ({ formData, loadDataFun }) => {
return <Typography variant="errorMessage1">{errorMsg}</Typography> 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({ const formik = useFormik({
enableReinitialize: true, enableReinitialize: true,
initialValues: currentUserData, initialValues: currentUserData,
@@ -95,16 +111,16 @@ const UserInformationCard_Individual = ({ formData, loadDataFun }) => {
is: (verifiedBy) => verifiedBy != null, is: (verifiedBy) => verifiedBy != null,
then: (schema) => schema.notRequired(), then: (schema) => schema.notRequired(),
otherwise: (schema) => schema.required(getRequiredErrStr('number')) 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_HKIDv1 = /^[A-Z]{1}[0-9]{6}$/;
var pattern_HKIDv2 = /^[A-Z]{2}[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_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,}/; var pattern_otherCert = /^[A-Z]{1}[0-9]{5,}/;
if (value !== undefined) { if (value !== undefined) {
switch (selectedIdDocInputType) {
switch (selectedIdDocInputTypeRef.current) {
case "HKID": case "HKID":
if (value.match(pattern_HKIDv1)) { if (value.match(pattern_HKIDv1)) {
return true return true
@@ -152,11 +168,10 @@ const UserInformationCard_Individual = ({ formData, loadDataFun }) => {
is: (verifiedBy) => verifiedBy != null, is: (verifiedBy) => verifiedBy != null,
then: (schema) => schema.notRequired(), then: (schema) => schema.notRequired(),
otherwise: (schema) => schema.max(1, getMaxErrStr(1)).nullable() 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) { .test('checkIDCardFormat', displayErrorMsg(`${intl.formatMessage({ id: 'requiredNumberInQuote' })}`), function (value) {
// console.log(selectedIdDocInputType)
if (value != undefined || value != null) { if (value != undefined || value != null) {
switch (selectedIdDocInputType) {
switch (selectedIdDocInputTypeRef.current) {
case "HKID": case "HKID":
if (value.length == 1) { if (value.length == 1) {
return true return true
@@ -173,7 +188,7 @@ const UserInformationCard_Individual = ({ formData, loadDataFun }) => {
break; break;
} }
} else { } else {
if (selectedIdDocInputType != "HKID"){
if (selectedIdDocInputTypeRef.current != "HKID"){
return true return true
} else { } else {
return false return false
@@ -425,11 +440,11 @@ const UserInformationCard_Individual = ({ formData, loadDataFun }) => {
onChange: (event, newValue) => { onChange: (event, newValue) => {
if (newValue == null) { if (newValue == null) {
formik.setFieldValue("idDocType", ""); formik.setFieldValue("idDocType", "");
setSelectedIdDocInputType("");
selectedIdDocInputTypeRef.current = "";
return; return;
} }
formik.setFieldValue("idDocType", newValue.type); formik.setFieldValue("idDocType", newValue.type);
setSelectedIdDocInputType(newValue.type);
selectedIdDocInputTypeRef.current = newValue.type;
if (newValue.type !== "HKID") { if (newValue.type !== "HKID") {
formik.setFieldValue("checkDigit", "") formik.setFieldValue("checkDigit", "")
} }
@@ -512,7 +527,7 @@ const UserInformationCard_Individual = ({ formData, loadDataFun }) => {
form: formik, form: formik,
placeholder: intl.formatMessage({ id: 'idDocNumber' }), placeholder: intl.formatMessage({ id: 'idDocNumber' }),
inputProps: { inputProps: {
maxLength: 7,
maxLength: 8,
onKeyDown: (e) => { onKeyDown: (e) => {
if (e.key === 'Enter') { if (e.key === 'Enter') {
e.preventDefault(); e.preventDefault();


+ 2
- 2
src/pages/authentication/auth-forms/CustomFormWizard.js Просмотреть файл

@@ -641,7 +641,7 @@ const CustomFormWizard = (props) => {
// var pattern = /^[A-Z][0-9]*$/; // var pattern = /^[A-Z][0-9]*$/;
var pattern_HKIDv1 = /^[A-Z]{1}[0-9]{6}$/; var pattern_HKIDv1 = /^[A-Z]{1}[0-9]{6}$/;
var pattern_HKIDv2 = /^[A-Z]{2}[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_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,}/; var pattern_otherCert = /^[A-Z]{1}[0-9]{5,}/;
// var space = /\s/; // var space = /\s/;
@@ -816,7 +816,7 @@ const CustomFormWizard = (props) => {
const idDocType = selectedIdDocType.type; const idDocType = selectedIdDocType.type;
var pattern_HKIDv1 = /^[A-Z]{1}[0-9]{6}$/; var pattern_HKIDv1 = /^[A-Z]{1}[0-9]{6}$/;
var pattern_HKIDv2 = /^[A-Z]{2}[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_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,}/; var pattern_otherCert = /^[A-Z]{1}[0-9]{5,}/;
if (value !== undefined) { if (value !== undefined) {


+ 2
- 2
src/translations/en.json Просмотреть файл

@@ -348,8 +348,8 @@
"passport": "Passport", "passport": "Passport",
"HKIDcard": "Hong Kong ID Card", "HKIDcard": "Hong Kong ID Card",
"HKID": "Hong Kong ID Card", "HKID": "Hong Kong ID Card",
"mainlandIDCard": "Mainland ID card",
"CNID": "Mainland ID card",
"mainlandIDCard": "Mainland ID Card",
"CNID": "Mainland ID Card",
"proCert": "Professional Practice Certificate", "proCert": "Professional Practice Certificate",
"otherCert": "Professional Practice Certificate", "otherCert": "Professional Practice Certificate",
"idDocType": "Document Category", "idDocType": "Document Category",


Загрузка…
Отмена
Сохранить