// material-ui import { Grid, Button, Typography, FormHelperText, Stack, IconButton } from '@mui/material'; import MainCard from "components/MainCard"; import { useEffect, useState, lazy } from "react"; import * as yup from 'yup'; import { useFormik } from 'formik'; import * as FieldUtils from "utils/FieldUtils"; import * as HttpUtils from 'utils/HttpUtils'; import * as UrlUtils from "utils/ApiPathConst"; import * as ComboData from "utils/ComboData"; const LoadingComponent = Loadable(lazy(() => import('../../extra-pages/LoadingComponent'))); import Loadable from 'components/Loadable'; import { notifyActiveSuccess, notifyLockSuccess, notifySaveSuccess, notifyVerifySuccess } from 'utils/CommonFunction'; import { useIntl } from "react-intl"; import { PNSPS_BUTTON_THEME } from "themes/buttonConst"; import { ThemeProvider } from "@emotion/react"; import { EyeInvisibleOutlined, EyeOutlined } from '@ant-design/icons'; import { isGrantedAny } from "auth/utils"; // ==============================|| DASHBOARD - DEFAULT ||============================== // const UserInformationCard_Individual = ({ formData, loadDataFun }) => { const intl = useIntl(); const [currentUserData, setCurrentUserData] = useState(formData); const [editMode, setEditMode] = useState(false); const [locked, setLocked] = useState(false); const [onReady, setOnReady] = useState(false); const [errorMsg, setErrorMsg] = useState(""); const [showId, setshowId] = useState(false); const handleClickShowId = () => { setshowId(!showId); }; const handleMouseDownId = (event) => { event.preventDefault(); }; useEffect(() => { //if state data are ready and assign to different field // console.log(currentApplicationDetailData) if (Object.keys(currentUserData).length > 0) { setOnReady(true); } }, [currentUserData]); function getMaxErrStr(num, fieldname) { return intl.formatMessage({ id: 'noMoreThenNWords' }, { num: num, fieldname: fieldname ? intl.formatMessage({ id: fieldname }) + ": " : "" }); } const formik = useFormik({ enableReinitialize: true, initialValues: currentUserData, validationSchema: yup.object().shape({ enName: yup.string().max(40, getMaxErrStr(40)).when('chName', { is: (chName) => chName?false:true, then: yup.string().required(intl.formatMessage({ id: 'userRequireEnglishName' })) }).nullable(), chName: yup.string().max(6, getMaxErrStr(6)).nullable(), addressLine1: yup.string().max(40, getMaxErrStr(40)).required(intl.formatMessage({ id: 'validateAddressLine1' })), addressLine2: yup.string().max(40, getMaxErrStr(40)).nullable(), addressLine3: yup.string().max(40, getMaxErrStr(40)).nullable(), emailAddress: yup.string().email(intl.formatMessage({ id: 'validEmailFormat' })).max(255).required(intl.formatMessage({ id: 'requireEmail' })), identification: yup.string().min(7, intl.formatMessage({ id: 'requireIdDocNumber' })).required(intl.formatMessage({ id: 'requireIdDocNumber' })), checkDigit: yup.string().max(1, getMaxErrStr(1)).required(intl.formatMessage({ id: 'requiredNumberInQuote' })).nullable(), idDocType: yup.string().max(255, getMaxErrStr(255)).required(intl.formatMessage({ id: 'requireIdDocType' })), tel_countryCode: yup.string().min(3, intl.formatMessage({ id: 'require3Number' })).required(intl.formatMessage({ id: 'requireDialingCode' })), fax_countryCode: yup.string().min(3, intl.formatMessage({ id: 'require3Number' })), phoneNumber: yup.string().min(8, intl.formatMessage({ id: 'require8Number' })).required(intl.formatMessage({ id: 'requireContactNumber' })), faxNumber: yup.string().min(8, intl.formatMessage({ id: 'require8Number' })).nullable(), }), onSubmit: values => { if (values.country == null) { setErrorMsg(intl.formatMessage({ id: 'pleaseFillInCountry' })) } else { if (values.country.type == "hongKong" && values.district == null) { setErrorMsg(intl.formatMessage({ id: 'pleaseFillInDistrict' })) } else { HttpUtils.post({ url: UrlUtils.POST_IND_USER + "/" + formData.id, params: { prefix: values.prefix, enName: values.enName, chName: values.chName, idDocType: values.idDocType, mobileNumber: { countryCode: values.tel_countryCode, phoneNumber: values.phoneNumber }, identification: values.identification, checkDigit: values.checkDigit, faxNo: { countryCode: values.fax_countryCode, faxNumber: values.faxNumber }, emailAddress: values.emailAddress, address: { country: values.country.type, district: values.district?.type, addressLine1: values.addressLine1, addressLine2: values.addressLine2, addressLine3: values.addressLine3, }, preferLocale: values.preferLocale.type }, onSuccess: function () { notifySaveSuccess(); loadDataFun(); } }); } } } }); useEffect(() => { if (Object.keys(formData).length > 0) { setCurrentUserData(formData); } }, [formData]); useEffect(() => { setLocked(currentUserData.locked); }, [currentUserData]); const onEditClick = () => { setEditMode(true); }; const onVerifiedClick = () => { HttpUtils.get({ url: UrlUtils.GET_IND_USER_VERIFY + "/" + formData.id, onSuccess: function () { notifyVerifySuccess() loadDataFun(); } }); }; const doLock = () => { HttpUtils.get({ url: UrlUtils.GET_USER_LOCK + "/" + formData.id, onSuccess: function () { notifyLockSuccess() loadDataFun(); } }); }; const doUnlock = () => { HttpUtils.get({ url: UrlUtils.GET_USER_UNLOCK + "/" + formData.id, onSuccess: function () { notifyActiveSuccess() loadDataFun(); } }); }; return ( {!onReady ? :
{/*top button*/} { isGrantedAny("MAINTAIN_USER") ? {editMode ? <> : <> } : <> } {/*end top button*/} Individual User Details {errorMsg} {FieldUtils.getTextField({ label: "Username:", valueName: "username", disabled: true, form: formik })} {FieldUtils.getTextField({ label: "English Name:", valueName: "enName", disabled: (!editMode), form: formik })} {FieldUtils.getTextField({ label: "Created Date:", valueName: "createDate", disabled: true, form: formik })} {FieldUtils.getTextField({ label: "Prefix:", valueName: "prefix", disabled: (!editMode), form: formik })} {FieldUtils.getTextField({ label: "Chinese Name:", valueName: "chName", disabled: (!editMode), form: formik })} {FieldUtils.getTextField({ label: "Last Updated:", valueName: "modifieDate", disabled: true, form: formik })} {FieldUtils.getComboField({ label: "ID Type:", valueName: "idDocType", disabled: (!editMode), dataList: ComboData.idDocType, filterOptions: (options) => options, getOptionLabel: (item) => item ? typeof item === 'string' ? item : (item["type"] ? item["type"] + "-" + item["label"] : "") : "", onInputChange: (event, newValue, setInputValue) => { if (newValue == null) { setInputValue(""); } let _val = newValue.split("-"); if (_val[0]) { setInputValue(_val[0]); } }, onChange: (event, newValue) => { if (newValue == null) { formik.setFieldValue("idDocType", ""); return; } formik.setFieldValue("idDocType", newValue.type); if (newValue.type !== "HKID") { formik.setFieldValue("checkDigit", "") } }, form: formik })} {FieldUtils.getPhoneField({ label: "Contact Tel:", valueName: { code: "tel_countryCode", num: "phoneNumber" }, disabled: (!editMode), form: formik })} Verified: { !isGrantedAny("MAINTAIN_USER") || currentUserData.verifiedBy || editMode ? {FieldUtils.initField({ valueName: "verifiedStatus", disabled: true, form: formik, })} : <> {FieldUtils.initField({ valueName: "verifiedStatus", disabled: true, form: formik, })} } ID No.: {formik.values.idDocType === "HKID" ? editMode ? <> {FieldUtils.initField({ valueName: "identification", disabled: (!editMode), form: formik, placeholder: intl.formatMessage({ id: 'idDocNumber' }), inputProps: { maxLength: 7, onKeyDown: (e) => { if (e.key === 'Enter') { e.preventDefault(); } }, } })} {FieldUtils.initField({ valueName: "checkDigit", disabled: (!editMode), form: formik, })} : {formik.values.identification.slice(0, 4)} {showId ? formik.values.identification.slice(4) : "****"}{showId ? '(' + formik.values.checkDigit + ')' : null} {showId ? : } : editMode ? {FieldUtils.initField({ valueName: "identification", disabled: (!editMode), form: formik })} : {formik.values.identification.slice(0, 4)} {showId ? formik.values.identification.slice(4) : "****"} {showId ? : } } {FieldUtils.getPhoneField({ label: "Fax No.:", valueName: { code: "fax_countryCode", num: "faxNumber" }, disabled: (!editMode), form: formik })} {FieldUtils.getTextField({ label: "Last Login:", valueName: "lastLoginDate", disabled: true, form: formik })} {FieldUtils.getComboField({ label: "Country:", valueName: "country", getOptionLabel: (option) => option.type ? intl.formatMessage({ id: option.type }) : "", dataList: ComboData.country, disabled: (!editMode), form: formik })} {FieldUtils.getTextField({ label: "Email:", valueName: "emailAddress", disabled: (!editMode), form: formik })} Status: { !isGrantedAny("MAINTAIN_USER") || editMode ? {FieldUtils.initField({ valueName: "status", disabled: true, form: formik, })} : <> {FieldUtils.initField({ valueName: "status", disabled: true, form: formik, })} { locked ? : } } {FieldUtils.getComboField({ label: "District:", valueName: "district", dataList: ComboData.district, getOptionLabel: (option) => option.type ? intl.formatMessage({ id: option.type }) : "", disabled: (!editMode), form: formik })} {FieldUtils.getComboField({ label: intl.formatMessage({ id: 'language' }) + ":", valueName: "preferLocale", dataList: ComboData.Locale, getOptionLabel: (option) => option.label ? option.label : "", disabled: (!editMode), form: formik })} {FieldUtils.getAddressField({ label: "Address:", valueName: ["addressLine1", "addressLine2", "addressLine3"], disabled: (!editMode), form: formik })}
}
); }; export default UserInformationCard_Individual;