Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 

294 řádky
14 KiB

  1. // material-ui
  2. import {
  3. Grid,
  4. Typography,
  5. Button,
  6. RadioGroup,
  7. Dialog, DialogTitle, DialogContent, DialogActions,
  8. Stack, Box
  9. } from '@mui/material';
  10. import { useFormik } from 'formik';
  11. import * as yup from 'yup';
  12. import * as React from "react";
  13. import * as HttpUtils from "utils/HttpUtils";
  14. import * as UrlUtils from "utils/ApiPathConst";
  15. import * as FieldUtils from "utils/FieldUtils";
  16. import titleBackgroundImg from 'assets/images/dashboard/gazette-bar.png'
  17. import ForwardIcon from '@mui/icons-material/Forward';
  18. import {
  19. isORGLoggedIn,
  20. } from "utils/Utils";
  21. import { useNavigate } from "react-router-dom";
  22. import { notifyActionSuccess } from 'utils/CommonFunction';
  23. import {PNSPS_LONG_BUTTON_THEME} from "../../../themes/buttonConst";
  24. import {ThemeProvider} from "@emotion/react";
  25. import {FormattedMessage, useIntl} from "react-intl";
  26. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  27. const PublicNoticeApplyForm = ({ loadedData, selections }) => {
  28. const [isWarningPopUp, setIsWarningPopUp] = React.useState(false);
  29. const [warningText, setWarningText] = React.useState("");
  30. const [attachment, setAttachment] = React.useState({});
  31. const intl = useIntl();
  32. const [issueId, setIssueId] = React.useState(loadedData.issueId);
  33. const navigate = useNavigate();
  34. const BackgroundHead = {
  35. backgroundImage: `url(${titleBackgroundImg})`,
  36. width: 'auto',
  37. height: 'auto',
  38. backgroundSize: 'contain',
  39. backgroundRepeat: 'no-repeat',
  40. backgroundColor: '#0C489E',
  41. backgroundPosition: 'right'
  42. }
  43. // React.useEffect(()=>{
  44. // loadedData.careOf = loadedData.contactPerson
  45. // },[]);
  46. const formik = useFormik({
  47. enableReinitialize: true,
  48. initialValues: loadedData,
  49. validationSchema: yup.object().shape({
  50. contactPerson: yup.string().max(40, intl.formatMessage({id: 'noMoreThen40Words'})).required(intl.formatMessage({id: 'requireContactPerson'})),
  51. tel_countryCode: yup.string().min(3, intl.formatMessage({id: 'require3Number'})).required(intl.formatMessage({id: 'requireDialingCode'})),
  52. fax_countryCode: yup.string().min(3, intl.formatMessage({id: 'require3Number'})),
  53. phoneNumber: yup.string().min(8, intl.formatMessage({id: 'require8Number'})).required(intl.formatMessage({id: 'requireContactNumber'})),
  54. faxNumber: yup.string().min(8, intl.formatMessage({id: 'require8Number'})),
  55. remarks: yup.string().max(255,intl.formatMessage({id: 'noMoreThen255Words'})).nullable(),
  56. }),
  57. onSubmit: values => {
  58. if (!values.issueId) {
  59. setWarningText(intl.formatMessage({id: 'requireTargetVol'}));
  60. setIsWarningPopUp(true);
  61. return;
  62. }
  63. if (!attachment) {
  64. setWarningText(intl.formatMessage({id: 'requireFile'}));
  65. setIsWarningPopUp(true);
  66. return;
  67. } else if (!attachment.size || attachment.size <= 0) {
  68. setWarningText(intl.formatMessage({id: 'requireValidFile'}));
  69. setIsWarningPopUp(true);
  70. return;
  71. } else if (attachment.size >= (10 * 1024 * 1034)) {
  72. setWarningText(intl.formatMessage({id: 'fileSizeWarning'}));
  73. setIsWarningPopUp(true);
  74. return;
  75. }
  76. HttpUtils.postWithFiles({
  77. url: UrlUtils.POST_PUBLIC_NOTICE_APPLY,
  78. params: {
  79. id: 0,
  80. contactPerson: values.contactPerson,
  81. contactTelNo: {
  82. countryCode: values.tel_countryCode,
  83. phoneNumber: values.phoneNumber
  84. },
  85. contactFaxNo: {
  86. countryCode: values.fax_countryCode,
  87. faxNumber: values.faxNumber
  88. },
  89. issueId: issueId,
  90. careOf: values.careOf ? values.careOf: "",
  91. remarks: values.remarks ? values.remarks : "",
  92. },
  93. files: [attachment],
  94. onSuccess: function () {
  95. notifyActionSuccess(intl.formatMessage({id: 'submissionSuccess'}) + '!')
  96. navigate("/publicNotice");
  97. // location.reload();
  98. }
  99. });
  100. }
  101. });
  102. const readFile = (event) => {
  103. let file = event.target.files[0];
  104. if (file) {
  105. if (file.name.toLowerCase().substr(file.name.length - 4).includes(".doc")
  106. || file.name.toLowerCase().substr(file.name.length - 5).includes(".docx")
  107. || file.name.toLowerCase().substr(file.name.length - 4).includes(".xls")
  108. || file.name.toLowerCase().substr(file.name.length - 5).includes(".xlsx")
  109. ) {
  110. setAttachment(event.target.files[0]);
  111. } else {
  112. setWarningText(intl.formatMessage({id: 'requireValidFileWithFormat'}));
  113. setIsWarningPopUp(true);
  114. setAttachment({});
  115. document.getElementById("uploadFileBtn").value = "";
  116. return;
  117. }
  118. }
  119. }
  120. return (
  121. <Grid container sx={{ minHeight: '95vh', backgroundColor: '#ffffff', mb: 3 }} direction="column" alignItems="center">
  122. <Grid item xs={12} md={12} width="100%" >
  123. <div style={BackgroundHead}>
  124. <Stack direction="row" height='70px' justifyContent="flex-start" alignItems="center">
  125. <Typography ml={15} color='#FFF' variant="h4">
  126. <FormattedMessage id="applyPublicNotice"/>
  127. </Typography>
  128. </Stack>
  129. </div>
  130. </Grid>
  131. <Grid item xs={12} width={{xs:"90%", sm:"90%", md:"60%", lg:"60%"}}>
  132. <Button title={intl.formatMessage({id: 'back'})} sx={{ ml: 0, mt: 2.5 }} style={{ border: '2px solid' }} variant="outlined" onClick={() => { navigate(-1) }}>
  133. <ForwardIcon style={{ height: 30, width: 50, transform: "rotate(180deg)" }} />
  134. </Button>
  135. </Grid>
  136. {/* <Grid item xs={12}>
  137. <Typography variant="h5">申請公共啟事</Typography>
  138. </Grid> */}
  139. <Grid item xs={12} md={12} width={{ md: "60%", xs: "90%" }}>
  140. <Box xs={12} mt={1} sx={{ p: 2, border: '3px groove grey', borderRadius: '10px' }}>
  141. <form onSubmit={formik.handleSubmit}>
  142. <Grid container spacing={1} sx={{ minHeight: '80vh' }} direction="row" justifyContent="flex-start" alignItems="center">
  143. <Grid item xs={12} md={12} lg={12} sx={{ mb: 1 }}>
  144. {FieldUtils.getTextField({
  145. label: intl.formatMessage({id: 'contactPerson'}) + ":",
  146. valueName: "contactPerson",
  147. form: formik,
  148. disabled: true
  149. })}
  150. </Grid>
  151. <Grid item xs={12} md={12}>
  152. {FieldUtils.getPhoneField({
  153. label: intl.formatMessage({id: 'userContactNumber'}) + ":",
  154. disabled: true,
  155. valueName: {
  156. code: "tel_countryCode",
  157. num: "phoneNumber",
  158. },
  159. form: formik
  160. })}
  161. </Grid>
  162. <Grid item xs={12} md={12}>
  163. {FieldUtils.getPhoneField({
  164. label: intl.formatMessage({id: 'contactFaxNumber'}) + ":",
  165. disabled: true,
  166. valueName: {
  167. code: "fax_countryCode",
  168. num: "faxNumber",
  169. },
  170. form: formik
  171. })}
  172. </Grid>
  173. <Grid item xs={12} lg={12}>
  174. <Grid container alignItems={"center"}>
  175. <Grid item xs={12} md={3} lg={3}
  176. sx={{ display: 'flex', alignItems: 'center' }}>
  177. <Typography variant="h5">
  178. <FormattedMessage id="targetVol" />:
  179. </Typography>
  180. </Grid>
  181. <Grid item xs={12} md={9} lg={6}>
  182. <RadioGroup
  183. aria-labelledby="demo-radio-buttons-group-label"
  184. id="issueId"
  185. name="issueId"
  186. defaultValue={issueId}
  187. onChange={(event) => {
  188. setIssueId(event.target.value);
  189. }}
  190. >
  191. {
  192. selections
  193. }
  194. </RadioGroup>
  195. </Grid>
  196. </Grid>
  197. </Grid>
  198. <Grid item xs={12} md={12} lg={12}>
  199. <Grid container direction="row" justifyContent="flex-start" alignItems="center">
  200. <Grid item xs={12} md={3} lg={3}
  201. sx={{ display: 'flex', alignItems: 'center' }}>
  202. <Typography variant="h5">
  203. <FormattedMessage id="draftFile"/> ({intl.formatMessage({id: 'fileSizeWarning'})}):
  204. </Typography>
  205. </Grid>
  206. <Grid item xs={12} md={6} lg={6} sx={{ wordBreak: 'break-word' }}>
  207. <input
  208. id="uploadFileBtn"
  209. name="file"
  210. type="file"
  211. accept=".doc,.docx,.xls,.xlsx"
  212. style={{ display: 'none' }}
  213. onChange={(event) => {
  214. readFile(event)
  215. }}
  216. />
  217. {attachment.name}
  218. </Grid>
  219. <Grid item xs={12} md={3} lg={3}>
  220. <label htmlFor="uploadFileBtn">
  221. <Button
  222. component="span"
  223. variant="outlined"
  224. size="large"
  225. >{attachment ? intl.formatMessage({id: 'uploadFileBtn'}) : intl.formatMessage({id: 'reUpload'})}</Button>
  226. </label>
  227. </Grid>
  228. </Grid>
  229. </Grid>
  230. {isORGLoggedIn()?
  231. <Grid item xs={12} md={12} lg={12} sx={{ mb: 1 }}>
  232. {FieldUtils.getTextField({
  233. label: "Care Of:",
  234. valueName: "careOf",
  235. form: formik,
  236. // disabled: true
  237. })}
  238. </Grid>:null
  239. }
  240. <Grid item xs={12} md={12} lg={12}>
  241. {FieldUtils.getTextArea({
  242. label: intl.formatMessage({id: 'extraMark'}) + ":",
  243. valueName: "remarks",
  244. form: formik,
  245. inputProps: { maxLength: 255 }
  246. })}
  247. </Grid>
  248. <Grid item xs={12}>
  249. <center>
  250. <ThemeProvider theme={PNSPS_LONG_BUTTON_THEME}>
  251. <Button
  252. variant="contained"
  253. type="submit"
  254. >
  255. <FormattedMessage id="applyPublicNotice"/>
  256. </Button>
  257. </ThemeProvider>
  258. </center>
  259. </Grid>
  260. </Grid>
  261. </form>
  262. </Box>
  263. </Grid>
  264. <div>
  265. <Dialog open={isWarningPopUp} onClose={() => setIsWarningPopUp(false)} >
  266. <DialogTitle>
  267. <FormattedMessage id="attention"/>
  268. </DialogTitle>
  269. <DialogContent style={{ display: 'flex', }}>
  270. <Typography variant="h3" style={{ padding: '16px' }}>{warningText}</Typography>
  271. </DialogContent>
  272. <DialogActions>
  273. <Button onClick={() => setIsWarningPopUp(false)}>OK</Button>
  274. </DialogActions>
  275. </Dialog>
  276. </div>
  277. </Grid>
  278. );
  279. };
  280. export default PublicNoticeApplyForm;