diff --git a/src/components/I18nProvider.js b/src/components/I18nProvider.js index cd09a53..fdcd9f0 100644 --- a/src/components/I18nProvider.js +++ b/src/components/I18nProvider.js @@ -1,11 +1,11 @@ -import React, {useState, useEffect, createContext} from 'react'; +import { useState, useEffect, createContext } from 'react'; import { IntlProvider } from 'react-intl'; import enMessages from '../translations/en.json'; import cnMessages from '../translations/zh-CN.json'; import hkMessages from '../translations/zh-HK.json'; -import { GET_COMBO, POST_TERMS_N_CONDITIONS } from "utils/ApiPathConst"; -import * as HttpUtils from "utils/HttpUtils"; +import { GET_COMBO, GET_CONTENT } from "utils/ApiPathConst"; +import { get } from "utils/HttpUtils"; const LocaleContext = createContext(); @@ -16,46 +16,50 @@ export const I18nProvider = ({ children }) => { "zh-HK": hkMessages, "zh-CN": cnMessages }; - + const [locale, setLocale] = useState('en'); // Default locale, you can change this as per your requirement const [messages, setMessages] = useState(systemMessages[locale]); const loadTermsAndConditions = () => { - HttpUtils.get({ - url: POST_TERMS_N_CONDITIONS, + get({ + url: GET_CONTENT, onSuccess: (responseData) => { - enMessages["termsAndCon"]= responseData.en; - cnMessages["termsAndCon"]= responseData.cn; - hkMessages["termsAndCon"]= responseData.zh; + for (const key in responseData) { + const value = responseData[key]; + enMessages[key] = value.en??""; + cnMessages[key] = value.cn??""; + hkMessages[key] = value.zh??""; + } } }); - HttpUtils.get({ + + get({ url: GET_COMBO, onSuccess: (responseData) => { - for(let i =0; i { loadTermsAndConditions(); - if(localStorage.getItem('locale') === null){ + if (localStorage.getItem('locale') === null) { //no locale case - localStorage.setItem('locale','en'); + localStorage.setItem('locale', 'en'); } - else{ + else { setLocale(localStorage.getItem('locale')); } }, []); - + useEffect(() => { // Load the messages for the selected locale const fetchMessages = async () => { @@ -66,7 +70,7 @@ export const I18nProvider = ({ children }) => { }, [locale]); return ( - + {children} diff --git a/src/pages/PublicNotice/ApplyForm/PublicNoticeApplyForm.js b/src/pages/PublicNotice/ApplyForm/PublicNoticeApplyForm.js index 9dad89e..04805c5 100644 --- a/src/pages/PublicNotice/ApplyForm/PublicNoticeApplyForm.js +++ b/src/pages/PublicNotice/ApplyForm/PublicNoticeApplyForm.js @@ -17,13 +17,13 @@ import titleBackgroundImg from 'assets/images/dashboard/gazette-bar.png' import ForwardIcon from '@mui/icons-material/Forward'; import { isORGLoggedIn, - } from "utils/Utils"; +} from "utils/Utils"; import { useNavigate } from "react-router-dom"; import { notifyActionSuccess } from 'utils/CommonFunction'; -import {PNSPS_LONG_BUTTON_THEME} from "../../../themes/buttonConst"; -import {ThemeProvider} from "@emotion/react"; -import {FormattedMessage, useIntl} from "react-intl"; +import { PNSPS_LONG_BUTTON_THEME } from "../../../themes/buttonConst"; +import { ThemeProvider } from "@emotion/react"; +import { FormattedMessage, useIntl } from "react-intl"; import Loadable from 'components/Loadable'; import { lazy } from 'react'; const LoadingComponent = Loadable(lazy(() => import('../../extra-pages/LoadingComponent'))); @@ -58,8 +58,8 @@ const PublicNoticeApplyForm = ({ loadedData, _selections }) => { // loadedData.careOf = loadedData.contactPerson // },[]); - function getMaxErrStr(num, fieldname){ - return intl.formatMessage({ id: 'noMoreThenNWords' },{num:num, fieldname:fieldname?intl.formatMessage({ id: fieldname})+": ":""}); + function getMaxErrStr(num, fieldname) { + return intl.formatMessage({ id: 'noMoreThenNWords' }, { num: num, fieldname: fieldname ? intl.formatMessage({ id: fieldname }) + ": " : "" }); } React.useEffect(() => { @@ -70,54 +70,54 @@ const PublicNoticeApplyForm = ({ loadedData, _selections }) => { enableReinitialize: true, initialValues: loadedData, validationSchema: yup.object().shape({ - contactPerson: yup.string().max(40, intl.formatMessage({id: 'noMoreThen40Words'})).required(intl.formatMessage({id: 'requireContactPerson'})), - 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(), + contactPerson: yup.string().max(40, intl.formatMessage({ id: 'noMoreThen40Words' })).required(intl.formatMessage({ id: 'requireContactPerson' })), + 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(), }), onSubmit: values => { if (!values.issueId) { - setWarningText(intl.formatMessage({id: 'requireTargetVol'})); + setWarningText(intl.formatMessage({ id: 'requireTargetVol' })); setIsWarningPopUp(true); return; } if (!attachment) { - setWarningText(intl.formatMessage({id: 'requireFile'})); + setWarningText(intl.formatMessage({ id: 'requireFile' })); setIsWarningPopUp(true); return; } else if (!attachment.size || attachment.size <= 0) { - setWarningText(intl.formatMessage({id: 'requireValidFile'})); + setWarningText(intl.formatMessage({ id: 'requireValidFile' })); setIsWarningPopUp(true); return; } else if (attachment.size >= (10 * 1024 * 1034)) { - setWarningText(intl.formatMessage({id: 'fileSizeWarning'})); + setWarningText(intl.formatMessage({ id: 'fileSizeWarning' })); setIsWarningPopUp(true); return; } - if(isORGLoggedIn()){ + if (isORGLoggedIn()) { HttpUtils.get({ url: UrlUtils.CHECK_OVERDUE, - onSuccess: (responData)=>{ - if(responData.haveOverdue){ + onSuccess: (responData) => { + if (responData.haveOverdue) { setVal(values); - setWarningText(intl.formatMessage({id: 'dnOverdueWarning'})); + setWarningText(intl.formatMessage({ id: 'dnOverdueWarning' })); setIsWarningPopUp(true); - }else{ + } else { apply(values); } } }); - }else{ + } else { apply(values); } - + } }); - const apply = (values)=>{ + const apply = (values) => { setSubmitting(true) HttpUtils.postWithFiles({ url: UrlUtils.POST_PUBLIC_NOTICE_APPLY, @@ -133,20 +133,20 @@ const PublicNoticeApplyForm = ({ loadedData, _selections }) => { faxNumber: values.faxNumber }, issueId: issueId, - careOf: values.careOf ? values.careOf: "", + careOf: values.careOf ? values.careOf : "", remarks: values.remarks ? values.remarks : "", }, files: [attachment], onSuccess: function (responData) { - if(responData.msg){ + if (responData.msg) { setVal({}); setReloadPage(true); - setWarningText(intl.formatMessage({id: responData.msg})); + setWarningText(intl.formatMessage({ id: responData.msg })); setIsWarningPopUp(true); return; } setSubmitting(false) - notifyActionSuccess(intl.formatMessage({id: 'submissionSuccess'}) + '!') + notifyActionSuccess(intl.formatMessage({ id: 'submissionSuccess' }) + '!') navigate("/publicNotice"); // location.reload(); } @@ -163,7 +163,7 @@ const PublicNoticeApplyForm = ({ loadedData, _selections }) => { ) { setAttachment(event.target.files[0]); } else { - setWarningText(intl.formatMessage({id: 'requireValidFileWithFormat'})); + setWarningText(intl.formatMessage({ id: 'requireValidFileWithFormat' })); setIsWarningPopUp(true); setAttachment({}); document.getElementById("uploadFileBtn").value = ""; @@ -178,16 +178,16 @@ const PublicNoticeApplyForm = ({ loadedData, _selections }) => {
- - + +
- + + >{attachment ? intl.formatMessage({ id: 'uploadFileBtn' }) : intl.formatMessage({ id: 'reUpload' })} - {isORGLoggedIn()? + {isORGLoggedIn() ? <> {FieldUtils.getCarOfField({ - label: intl.formatMessage({id: 'careOf'}) + ":", + label: intl.formatMessage({ id: 'careOf' }) + ":", valueName: "careOf", form: formik, // disabled: true @@ -325,35 +325,47 @@ const PublicNoticeApplyForm = ({ loadedData, _selections }) => { - + - : + : null - + } {FieldUtils.getTextArea({ - label: intl.formatMessage({id: 'extraMark'}) + ":", + label: intl.formatMessage({ id: 'extraMark' }) + ":", valueName: "remarks", form: formik, inputProps: { maxLength: 255 } })} + + + +
+ + + +
- +
+ + + + @@ -372,21 +384,21 @@ const PublicNoticeApplyForm = ({ loadedData, _selections }) => { }} > - + {warningText}