Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

315 rader
15 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" sx={{display: { xs: 'none', sm: 'none', md: 'block' }}}>
  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
  133. aria-label={intl.formatMessage({id: 'back'})}
  134. title={intl.formatMessage({id: 'back'})}
  135. sx={{ ml: 0, mt: 2.5 }} style={{ border: '2px solid' }} variant="outlined" onClick={() => { navigate(-1) }}
  136. >
  137. <ForwardIcon style={{ height: 30, width: 50, transform: "rotate(180deg)" }} />
  138. </Button>
  139. </Grid>
  140. {/* <Grid item xs={12}>
  141. <Typography variant="pnspsFormParagraphBold">申請公共啟事</Typography>
  142. </Grid> */}
  143. <Grid item xs={12} md={12} width={{ md: "60%", xs: "90%" }}>
  144. <Box xs={12} mt={1} sx={{ p: 2, border: '3px groove grey', borderRadius: '10px' }}>
  145. <form onSubmit={formik.handleSubmit}>
  146. <Grid container spacing={1} sx={{ minHeight: '80vh' }} direction="row" justifyContent="flex-start" alignItems="center">
  147. <Grid item xs={12} md={12} lg={12} sx={{ mb: 1 }}>
  148. {FieldUtils.getTextField({
  149. label: intl.formatMessage({id: 'contactPerson'}) + ":",
  150. valueName: "contactPerson",
  151. form: formik,
  152. disabled: true
  153. })}
  154. </Grid>
  155. <Grid item xs={12} md={12}>
  156. {FieldUtils.getPhoneField({
  157. label: intl.formatMessage({id: 'userContactNumber'}) + ":",
  158. disabled: true,
  159. valueName: {
  160. code: "tel_countryCode",
  161. num: "phoneNumber",
  162. },
  163. form: formik
  164. })}
  165. </Grid>
  166. <Grid item xs={12} md={12}>
  167. {FieldUtils.getPhoneField({
  168. label: intl.formatMessage({id: 'contactFaxNumber'}) + ":",
  169. disabled: true,
  170. valueName: {
  171. code: "fax_countryCode",
  172. num: "faxNumber",
  173. },
  174. form: formik
  175. })}
  176. </Grid>
  177. <Grid item xs={12} lg={12}>
  178. <Grid container alignItems={"center"}>
  179. <Grid item xs={12} md={3} lg={3}
  180. sx={{ display: 'flex', alignItems: 'center' }}>
  181. <Typography variant="pnspsFormParagraphBold">
  182. <FormattedMessage id="targetVol" />:
  183. </Typography>
  184. </Grid>
  185. <Grid item xs={12} md={9} lg={6}>
  186. <RadioGroup
  187. aria-labelledby="radio-buttons-group-label"
  188. id="issueId"
  189. name="issueId"
  190. defaultValue={issueId}
  191. onChange={(event) => {
  192. setIssueId(event.target.value);
  193. }}
  194. >
  195. {
  196. selections
  197. }
  198. </RadioGroup>
  199. </Grid>
  200. </Grid>
  201. </Grid>
  202. <Grid item xs={12} md={12} lg={12}>
  203. <Grid container direction="row" justifyContent="flex-start" alignItems="center">
  204. <Grid item xs={12} md={3} lg={3}
  205. sx={{ display: 'flex', alignItems: 'center' }}>
  206. <Typography variant="pnspsFormParagraphBold">
  207. <FormattedMessage id="draftFile"/> ({intl.formatMessage({id: 'fileSizeWarning'})}):
  208. </Typography>
  209. </Grid>
  210. <Grid item xs={12} md={6} lg={6} sx={{ wordBreak: 'break-word' }}>
  211. <input
  212. id="uploadFileBtn"
  213. name="file"
  214. type="file"
  215. accept=".doc,.docx,.xls,.xlsx"
  216. style={{ display: 'none' }}
  217. onChange={(event) => {
  218. readFile(event)
  219. }}
  220. />
  221. {attachment.name}
  222. </Grid>
  223. <Grid item xs={12} md={3} lg={3}>
  224. <label htmlFor="uploadFileBtn">
  225. <Button
  226. aria-label={intl.formatMessage({id: 'uploadFileBtn'})}
  227. component="span"
  228. variant="outlined"
  229. size="large"
  230. >{attachment ? intl.formatMessage({id: 'uploadFileBtn'}) : intl.formatMessage({id: 'reUpload'})}</Button>
  231. </label>
  232. </Grid>
  233. </Grid>
  234. </Grid>
  235. {isORGLoggedIn()?
  236. <Grid item xs={12} md={12} lg={12} sx={{ mb: 1 }}>
  237. {FieldUtils.getTextField({
  238. label: "Care Of:",
  239. valueName: "careOf",
  240. form: formik,
  241. // disabled: true
  242. })}
  243. </Grid>:null
  244. }
  245. <Grid item xs={12} md={12} lg={12}>
  246. {FieldUtils.getTextArea({
  247. label: intl.formatMessage({id: 'extraMark'}) + ":",
  248. valueName: "remarks",
  249. form: formik,
  250. inputProps: { maxLength: 255 }
  251. })}
  252. </Grid>
  253. <Grid item xs={12}>
  254. <center>
  255. <ThemeProvider theme={PNSPS_LONG_BUTTON_THEME}>
  256. <Button
  257. aria-label={intl.formatMessage({id: 'applyPublicNotice'})}
  258. variant="contained"
  259. type="submit"
  260. >
  261. <FormattedMessage id="applyPublicNotice"/>
  262. </Button>
  263. </ThemeProvider>
  264. </center>
  265. </Grid>
  266. </Grid>
  267. </form>
  268. </Box>
  269. </Grid>
  270. <div>
  271. <Dialog
  272. open={isWarningPopUp}
  273. onClose={() => setIsWarningPopUp(false)}
  274. PaperProps={{
  275. sx: {
  276. minWidth: '40vw',
  277. maxWidth: { xs: '90vw', s: '90vw', m: '70vw', lg: '70vw' },
  278. maxHeight: { xs: '90vh', s: '70vh', m: '70vh', lg: '60vh' }
  279. }
  280. }}
  281. >
  282. <DialogTitle>
  283. <FormattedMessage id="attention"/>
  284. </DialogTitle>
  285. <DialogContent style={{ display: 'flex', }}>
  286. <Typography variant="h3" style={{ padding: '16px' }}>{warningText}</Typography>
  287. </DialogContent>
  288. <DialogActions>
  289. <Button
  290. aria-label={intl.formatMessage({id: 'ok'})}
  291. onClick={() => setIsWarningPopUp(false)}
  292. >
  293. <FormattedMessage id="ok" />
  294. </Button>
  295. </DialogActions>
  296. </Dialog>
  297. </div>
  298. </Grid>
  299. );
  300. };
  301. export default PublicNoticeApplyForm;