// material-ui import { Grid, Button, // Checkbox, FormControlLabel, Typography, Dialog, DialogTitle, DialogContent, DialogActions, } from '@mui/material'; // import { FormControlLabel } from '@material-ui/core'; import MainCard from "components/MainCard"; import * as React from "react"; import { useFormik } from 'formik'; import * as yup from 'yup'; import { useEffect, useState } from "react"; import * as HttpUtils from 'utils/HttpUtils'; import * as UrlUtils from "utils/ApiPathConst"; import * as FieldUtils from "utils/FieldUtils"; 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 OrganizationPubCard = ({ userData, loadDataFun, id, setEditModeFun }) => { const intl = useIntl(); const [creditorConfirmPopUp, setCreditorConfirmPopUp] = React.useState(false); const [nonCreditorConfirmPopUp, setNonCreditorConfirmPopUp] = React.useState(false); const [currentUserData, setCurrentUserData] = useState({}); const [editMode, setEditMode] = useState(false); const [createMode, setCreateMode] = 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]); function displayErrorMsg(errorMsg) { return {errorMsg} } const formik = useFormik({ enableReinitialize: true, initialValues: currentUserData, validationSchema: yup.object().shape({ addressLine1: yup.string().max(40).required(displayErrorMsg(intl.formatMessage({id: 'validateAddressLine1'}))), addressLine2: yup.string().max(40, displayErrorMsg(intl.formatMessage({id: 'noMoreThen255Words'}))), addressLine3: yup.string().max(40, displayErrorMsg(intl.formatMessage({id: 'noMoreThen255Words'}))), tel_countryCode: yup.string().min(3, displayErrorMsg(intl.formatMessage({id: 'requireDialingCode'}))), phoneNumber: yup.string().min(8, displayErrorMsg(intl.formatMessage({id: 'requiredValidNumber'}))).required(displayErrorMsg(intl.formatMessage({id: 'requireContactNumber'}))), }), onSubmit: vaule => { console.log(vaule) HttpUtils.post({ url: UrlUtils.POST_PUB_ORG_SAVE_PATH, params: { contactPerson: vaule.contactPerson, contactTel: { countryCode: vaule.tel_countryCode, phoneNumber: vaule.phoneNumber }, addressTemp: { country: vaule.country.id, district: vaule.district.id, addressLine1: vaule.addressLine1, addressLine2: vaule.addressLine2, addressLine3: vaule.addressLine3, }, //creditor: vaule.creditor, }, onSuccess: function () { notifySaveSuccess() loadDataFun(); setEditMode(false); } }); } }); useEffect(()=>{ setEditModeFun(editMode); },[editMode]); useEffect(() => { if (Object.keys(userData).length > 0) { setCreateMode(id <= 0); setEditMode(id <= 0); setCurrentUserData(userData); } }, [userData]); // useEffect(() => { // if (Object.keys(userData).length > 0) { // if(userData.creditor === undefined||userData.creditor === null){ // userData.creditor = false // } // setCurrentUserData(userData); // } // }, []); const onEditClick = () => { setEditMode(true); }; return ( {/*top*/} {editMode ? <> {createMode ? <> > : <> > } > : <> < FormattedMessage id="edit" /> > } {/*top*/} {!onReady ? : {FieldUtils.getTextField({ label: intl.formatMessage({id: 'brNo'}) + ":", valueName: "brNo", disabled: true, form: formik })} {FieldUtils.getTextField({ label: intl.formatMessage({id: 'creditorAccount'}) + ":", valueName: "creditor", disabled: true, form: formik })} {/* } label="is Creditor" name="creditor" onChange={() => { formik.setFieldValue("creditor", !formik.values.creditor); }} disabled={true} //disabled={!editMode && !createMode} /> */} {FieldUtils.getTextField({ label: FieldUtils.notNullFieldLabel(intl.formatMessage({id: 'nameEng'}) + ":"), valueName: "enCompanyName", disabled: true, form: formik })} {FieldUtils.getTextField({ label: intl.formatMessage({id: 'nameChi'}) + ":", valueName: "chCompanyName", disabled: true, form: formik })} {FieldUtils.getDateField({ label: FieldUtils.notNullFieldLabel(intl.formatMessage({id: 'expiryDate'}) + ":"), valueName: "brExpiryDate", disabled: true, form: formik })} {FieldUtils.getTextField({ label: FieldUtils.notNullFieldLabel(intl.formatMessage({id: 'contactPerson'}) + ":"), valueName: "contactPerson", disabled: (!editMode && !createMode), form: formik })} {FieldUtils.getPhoneField({ label: FieldUtils.notNullFieldLabel(intl.formatMessage({id: 'userContactNumber'}) + ":"), valueName: { code: "tel_countryCode", num: "phoneNumber" }, disabled: (!editMode && !createMode), form: formik })} {FieldUtils.getPhoneField({ label: intl.formatMessage({id: 'contactFaxNumber'}) + ":", valueName: { code: "fax_countryCode", num: "faxNumber" }, disabled: true, form: formik })} {FieldUtils.getComboField({ label: FieldUtils.notNullFieldLabel(intl.formatMessage({id: 'country'}) + ":"), valueName: "country", disabled: (!editMode && !createMode), dataList: ComboData.country, getOptionLabel: (option) => option.type? intl.formatMessage({ id: option.type }) : "", form: formik })} {FieldUtils.getComboField({ label: FieldUtils.notNullFieldLabel(intl.formatMessage({id: 'district'}) + ":"), valueName: "district", disabled: (!editMode && !createMode), dataList: ComboData.district, getOptionLabel: (option) => option.type? intl.formatMessage({ id: option.type }) : "", form: formik })} {FieldUtils.getAddressField({ label: FieldUtils.notNullFieldLabel(intl.formatMessage({id: 'formAddress'}) + ":"), valueName: ["addressLine1", "addressLine2", "addressLine3"], disabled: (!editMode && !createMode), form: formik })} } setCreditorConfirmPopUp(false)} PaperProps={{ sx: { minWidth: '40vw', maxWidth: { xs: '90vw', s: '90vw', m: '70vw', lg: '70vw' }, maxHeight: { xs: '90vh', s: '70vh', m: '70vh', lg: '60vh' } } }} > Confirm Are you sure mark as Creditor? setCreditorConfirmPopUp(false)}>Cancel markAsCreditor()}>Confirm setNonCreditorConfirmPopUp(false)} PaperProps={{ sx: { minWidth: '40vw', maxWidth: { xs: '90vw', s: '90vw', m: '70vw', lg: '70vw' }, maxHeight: { xs: '90vh', s: '70vh', m: '70vh', lg: '60vh' } } }} > Confirm Are you sure mark as Non-Creditor? setNonCreditorConfirmPopUp(false)}>Cancel markAsNonCreditor()}>Confirm ); }; export default OrganizationPubCard;