// material-ui import { Grid, Button, Typography } from '@mui/material'; import MainCard from "components/MainCard"; import * as React from "react"; import { useEffect, useState } 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 { lazy } from 'react'; import {notifySaveSuccess,} from 'utils/CommonFunction'; import {FormattedMessage, useIntl} from "react-intl"; import {PNSPS_BUTTON_THEME} from "../../../themes/buttonConst"; import {ThemeProvider} from "@emotion/react"; // ==============================|| DASHBOARD - DEFAULT ||============================== // const UserInformationCard_Individual_Pub = ({ formData, loadDataFun }) => { const intl = useIntl(); const [currentUserData, setCurrentUserData] = useState(formData); const [editMode, setEditMode] = useState(false); const [onReady, setOnReady] = useState(false); useEffect(() => { //if state data are ready and assign to different field // console.log(currentApplicationDetailData) if (Object.keys(currentUserData).length > 0) { setOnReady(true); } }, [currentUserData]); const formik = useFormik({ enableReinitialize: true, initialValues: currentUserData, validationSchema: yup.object().shape({ enName: yup.string().max(255).required(intl.formatMessage({id: 'userRequireEnglishName'})), chName: yup.string().max(255).required(intl.formatMessage({id: 'userRequireChineseName'})), addressLine1: yup.string().max(255).required(intl.formatMessage({id: 'validateAddressLine1'})), addressLine2: yup.string().max(255).nullable(), addressLine3: yup.string().max(255).nullable(), emailAddress: yup.string().email(intl.formatMessage({id: 'validEmailFormat'})).max(255).required(intl.formatMessage({id: 'requireEmail'})), 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 => { console.log(values); HttpUtils.post({ url: UrlUtils.POST_PUB_IND_USER, params: { enName: values.enName, chName: values.chName, mobileNumber: { countryCode: values.tel_countryCode, phoneNumber: values.phoneNumber }, faxNo: { countryCode: values.fax_countryCode, faxNumber: values.faxNumber }, address: { country: values.country.key, district: values.district.key, addressLine1: values.addressLine1, addressLine2: values.addressLine2, addressLine3: values.addressLine3, }, }, onSuccess: function () { notifySaveSuccess(); loadDataFun(); } }); } }); useEffect(() => { if (Object.keys(formData).length > 0) { setCurrentUserData(formData); } }, [formData]); useEffect(() => { }, [currentUserData]); const onEditClick = () => { setEditMode(true); }; return ( {!onReady ? :
{/*top button*/} {editMode ? <> : <> } {/*end top button*/} {FieldUtils.getTextField({ label: intl.formatMessage({id: 'userLoginName'}) + ":", valueName: "username", disabled: true, form: formik })} {FieldUtils.getTextField({ label: intl.formatMessage({id: 'userEnglishName'}) + ":", valueName: "enName", disabled: true, form: formik })} {FieldUtils.getTextField({ label: intl.formatMessage({id: 'userChineseName'}) + ":", valueName: "chName", disabled: true, form: formik })} {FieldUtils.getComboField({ label: intl.formatMessage({id: 'idType'}) + ":", valueName: "idDocType", disabled: true, 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); }, form: formik })} : {formik.values.idDocType === "HKID" ? <> {FieldUtils.initField({ valueName: "identification", disabled: true, form: formik, placeholder: intl.formatMessage({id: 'idDocNumber'}), inputProps: { maxLength: 7, onKeyDown: (e) => { if (e.key === 'Enter') { e.preventDefault(); } }, } })} {FieldUtils.initField({ valueName: "checkDigit", disabled: true, form: formik })} : {FieldUtils.initField({ valueName: "identification", disabled: true, form: formik })} } {FieldUtils.getPhoneField({ label: intl.formatMessage({id: 'userContactNumber'}) + ":", valueName: { code: "tel_countryCode", num: "phoneNumber" }, disabled: (!editMode), form: formik })} {FieldUtils.getComboField({ label: intl.formatMessage({id: 'country'}) + ":", valueName: "country", getOptionLabel: (option) => option.type? intl.formatMessage({ id: option.type }) : "", dataList: ComboData.country, disabled: (!editMode), form: formik })} {FieldUtils.getTextField({ label: intl.formatMessage({id: 'userContactEmail'}) + ":", valueName: "emailAddress", disabled: true, form: formik })} {FieldUtils.getPhoneField({ label: intl.formatMessage({id: 'userFaxNumber'}) + ":", valueName: { code: "fax_countryCode", num: "faxNumber" }, disabled: (!editMode), form: formik })} {FieldUtils.getAddressField({ label: intl.formatMessage({id: 'userAddress'}) + ":", valueName: ["addressLine1", "addressLine2", "addressLine3"], disabled: (!editMode), form: formik })} {FieldUtils.getComboField({ label: intl.formatMessage({id: 'district'}) + ":", valueName: "district", dataList: ComboData.district, getOptionLabel: (option) => option.type? intl.formatMessage({ id: option.type }) : "", disabled: (!editMode), form: formik })}
}
); }; export default UserInformationCard_Individual_Pub;