diff --git a/src/pages/PublicNotice/ApplyForm/PublicNoticeApplyForm.js b/src/pages/PublicNotice/ApplyForm/PublicNoticeApplyForm.js index 26589c6..9fbee97 100644 --- a/src/pages/PublicNotice/ApplyForm/PublicNoticeApplyForm.js +++ b/src/pages/PublicNotice/ApplyForm/PublicNoticeApplyForm.js @@ -18,6 +18,7 @@ import titleBackgroundImg from 'assets/images/dashboard/gazette-bar.png' import ForwardIcon from '@mui/icons-material/Forward'; import { isORGLoggedIn, + isDummyLoggedIn } from "utils/Utils"; import { useNavigate } from "react-router-dom"; @@ -37,6 +38,8 @@ const PublicNoticeApplyForm = ({ loadedData, _selections , gazetteIssueList}) => const [attachment, setAttachment] = useState({}); const [selections, setsSelections] = useState(<>); const intl = useIntl(); + const { locale } = intl; + const dft = locale === 'en' ?"DD MMM YYYY":"YYYY年MM月DD日"; const [val, setVal] = useState({}); const [reloadPage, setReloadPage] = useState(false); @@ -84,18 +87,43 @@ const PublicNoticeApplyForm = ({ loadedData, _selections , gazetteIssueList}) => }, [issueId]); + // function displayErrorMsg(errorMsg) { + // return {errorMsg} + // } const formik = useFormik({ enableReinitialize: true, initialValues: loadedData, validationSchema: yup.object().shape({ - contactPerson: yup.string().max(40, intl.formatMessage({ id: 'noMoreThen40Words' })).required(intl.formatMessage({ id: 'requireContactPerson' })), + contactPerson: yup.string().max(40, intl.formatMessage({ id: 'noMoreThen40Words' })).required(intl.formatMessage({ id: 'requireContactPerson' })).nullable(), 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' })), remarks: yup.string().max(100, getMaxErrStr(100)).nullable(), careOf: yup.string().max(60, getMaxErrStr(60)).nullable(), + emailAddress: yup.string().email(intl.formatMessage({ id: 'validEmailFormat' })).max(255).test('checkEmailFormat', intl.formatMessage({ id: 'requireEmail' }), function (value) { + if (isDummyLoggedIn()) { + if (value !== undefined) { + return true + } else { + return false + } + }else{ + return true + } + }), + careOfDum: yup.string().max(60, getMaxErrStr(60)).test('checkCareOfDumFormat',intl.formatMessage({ id: 'requireCareOf' }), function (value) { + if (isDummyLoggedIn()) { + if (value !== undefined) { + return true + } else { + return false + } + }else{ + return true + } + }), }), onSubmit: values => { if (!values.issueId) { @@ -138,6 +166,14 @@ const PublicNoticeApplyForm = ({ loadedData, _selections , gazetteIssueList}) => const apply = (values) => { setSubmitting(true) + let careOf = values.careOf ? values.careOf : "" + let remarks = values.remarks ? values.remarks : "" + if (isDummyLoggedIn){ + careOf = values.careOfDum + } + if (isDummyLoggedIn){ + remarks = values.emailAddress + } HttpUtils.postWithFiles({ url: UrlUtils.POST_PUBLIC_NOTICE_APPLY, params: { @@ -152,8 +188,8 @@ const PublicNoticeApplyForm = ({ loadedData, _selections , gazetteIssueList}) => faxNumber: values.faxNumber }, issueId: issueId, - careOf: values.careOf ? values.careOf : "", - remarks: values.remarks ? values.remarks : "", + careOf: careOf, + remarks: remarks, }, files: [attachment], onSuccess: function (responData) { @@ -230,7 +266,8 @@ const PublicNoticeApplyForm = ({ loadedData, _selections , gazetteIssueList}) => label: intl.formatMessage({ id: 'contactPerson' }) + ":", valueName: "contactPerson", form: formik, - disabled: true + disabled: !isDummyLoggedIn(), + autoFocus: isDummyLoggedIn() })} @@ -290,18 +327,18 @@ const PublicNoticeApplyForm = ({ loadedData, _selections , gazetteIssueList}) => - {DateUtils.dateFormat(closeDate, "YYYY年MM月DD日")} 2:00 p.m. - {DateUtils.dateFormat(closeDate, "YYYY年MM月DD日")} 2:30 p.m. + {DateUtils.dateFormat(closeDate, dft)} 2:00 p.m. + {DateUtils.dateFormat(closeDate, dft)} 2:30 p.m. - {DateUtils.dateFormat(beforeClosingDate, "YYYY年MM月DD日")} 5:00 p.m. - {DateUtils.dateFormat(closeDate, "YYYY年MM月DD日")} 12:30 p.m. + {DateUtils.dateFormat(beforeClosingDate, dft)} 5:00 p.m. + {DateUtils.dateFormat(closeDate, dft)} 12:30 p.m. - {DateUtils.dateFormat(closeDate, "YYYY年MM月DD日")} 12:00 p.m. - {DateUtils.dateFormat(closeDate, "YYYY年MM月DD日")} 12:30 p.m. + {DateUtils.dateFormat(closeDate, dft)} 12:00 p.m. + {DateUtils.dateFormat(closeDate, dft)} 12:30 p.m. @@ -361,14 +398,26 @@ const PublicNoticeApplyForm = ({ loadedData, _selections , gazetteIssueList}) => {isORGLoggedIn() ? <> - - {FieldUtils.getCarOfField({ - label: intl.formatMessage({ id: 'careOf' }) + ":", - valueName: "careOf", - form: formik, - // disabled: true - })} - + {isDummyLoggedIn()? + + {FieldUtils.getCarOfField({ + label: intl.formatMessage({ id: 'careOf' }) + ":", + valueName: "careOfDum", + form: formik, + // disabled: true + })} + + : + + {FieldUtils.getCarOfField({ + label: intl.formatMessage({ id: 'careOf' }) + ":", + valueName: "careOf", + form: formik, + // disabled: true + })} + + + } @@ -379,14 +428,26 @@ const PublicNoticeApplyForm = ({ loadedData, _selections , gazetteIssueList}) => null } - - {FieldUtils.getTextArea({ - label: intl.formatMessage({ id: 'extraMark' }) + ":", - valueName: "remarks", - form: formik, - inputProps: { maxLength: 255 } - })} - + + { + isDummyLoggedIn()? + + {FieldUtils.getTextField({ + label: intl.formatMessage({ id: 'userContactEmail' }), + valueName: "emailAddress", + form: formik + })} + + : + + {FieldUtils.getTextArea({ + label: intl.formatMessage({ id: 'extraMark' }) + ":", + valueName: "remarks", + form: formik, + inputProps: { maxLength: 255 } + })} + + } diff --git a/src/translations/en.json b/src/translations/en.json index 8f2b75f..b9ad1d0 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -339,6 +339,7 @@ "payReceipt": "Payment receipt", "contactPerson": "Contact Person", "requireContactPerson": "Please enter contact person", + "requireCareOf": "Please enter client remark", "search": "Search", "searchForm": "Search Form", "cancel": "Cancel", diff --git a/src/translations/zh-CN.json b/src/translations/zh-CN.json index 5ca833b..bddd2cf 100644 --- a/src/translations/zh-CN.json +++ b/src/translations/zh-CN.json @@ -353,6 +353,7 @@ "payReceipt": "付款收据", "contactPerson": "联络人", "requireContactPerson": "请输入联络人", + "requireCareOf": "请输入客戶備註", "search": "搜寻", "searchForm": "搜寻表格", "cancel": "取消", diff --git a/src/translations/zh-HK.json b/src/translations/zh-HK.json index 1b383bf..064e2d2 100644 --- a/src/translations/zh-HK.json +++ b/src/translations/zh-HK.json @@ -356,6 +356,7 @@ "payReceipt": "付款收據", "contactPerson": "聯絡人", "requireContactPerson": "請輸入聯絡人", + "requireCareOf": "請輸入客戶備註", "search": "搜尋", "searchForm": "搜尋表格", "cancel": "取消", diff --git a/src/utils/FieldUtils.js b/src/utils/FieldUtils.js index 37ff6e8..fc7a891 100644 --- a/src/utils/FieldUtils.js +++ b/src/utils/FieldUtils.js @@ -26,7 +26,7 @@ export const getDateField = ({ label, valueName, form, disabled }) => { ; } -export const getTextField = ({ label, valueName, form, disabled }) => { +export const getTextField = ({ label, valueName, form, disabled, autoFocus }) => { return @@ -39,7 +39,8 @@ export const getTextField = ({ label, valueName, form, disabled }) => { type: "text", valueName: valueName, form: form, - disabled: disabled + disabled: disabled, + autoFocus:autoFocus })} @@ -203,7 +204,7 @@ export const getComboField = ({ label, dataList, valueName, form, disabled, getO ; } -export const initField = ({ type, valueName, form, disabled, multiline, handleChange, placeholder, inputProps, InputProps, width, ...props }) => { +export const initField = ({ type, valueName, form, disabled, autoFocus, multiline, handleChange, placeholder, inputProps, InputProps, width, ...props }) => { let err = Boolean(form.errors[valueName]); return { return JSON.parse(localStorage.getItem('userData')).creditor } } +export const isDummyLoggedIn = () =>{ + if (localStorage.getItem('userData') != null){ + return JSON.parse(localStorage.getItem('userData')).role === 'dummy' + } +} /** ** This function is used for demo purpose route navigation ** In real app you won't need this function because your app will navigate to same route for each users regardless of ability