Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

265 righe
8.1 KiB

  1. import {
  2. useEffect,
  3. useState,
  4. useRef
  5. } from "react";
  6. // material-ui
  7. import {
  8. Button,
  9. Stack,
  10. Typography,
  11. Dialog,
  12. DialogActions,
  13. DialogContent,
  14. DialogContentText,
  15. DialogTitle,
  16. FormLabel,
  17. Autocomplete,
  18. TextField,
  19. Grid,
  20. } from '@mui/material';
  21. import LoadingButton from '@mui/lab/LoadingButton';
  22. import * as ComboData from "utils/ComboData";
  23. import { useFormik, FormikProvider } from 'formik';
  24. import * as yup from 'yup';
  25. const StatusChangeDialog = (props) => {
  26. const [content, setContent] = useState();
  27. const [dialogTitle, setDialogTitle] = useState("Confirm");
  28. const [prositiveBtnText, setPrositiveBtnText] = useState("Confirm");
  29. const [remarks, setRemarks] = useState("");
  30. const [helperText, setHelperText] = useState("");
  31. const [comboInputValue, setComboInputValue] = useState({});
  32. const [positiveSubmitting, setPositiveSubmitting] = useState(false);
  33. const positiveOnceRef = useRef(false);
  34. const groupTitleComboList = ComboData.groupTitle;
  35. const confirmLoading = Boolean(props.confirmLoading) || positiveSubmitting;
  36. const gazetteGroupMissing =
  37. props.getStatus === "genGazetteCode" &&
  38. Object.keys(props.selectedGazetteGroup ?? {}).length === 0;
  39. useEffect(() => {
  40. setComboInputValue({});
  41. if (props.getStatus == "genGazetteCode") {
  42. setDialogTitle("Gen Gazette Code");
  43. setPrositiveBtnText("Submit");
  44. return getGazetteCodeContent()
  45. } else if (props.getStatus == "notAccepted") {
  46. setDialogTitle("Not Accept Reason");
  47. setPrositiveBtnText("Mark Not Accept");
  48. return getNotAcceptedContent();
  49. }if (props.getStatus == "resubmit") {
  50. setDialogTitle("Re-Submit Reason");
  51. setPrositiveBtnText("Mark Re-Submit");
  52. return getNotAcceptedContent();
  53. }if (props.getStatus == "paid") {
  54. setDialogTitle("Action Confirm");
  55. setPrositiveBtnText("Confirm");
  56. return getConfirmContent("Are you sure to mark this application as paid?");
  57. } else {
  58. setDialogTitle("Action Confirm");
  59. setPrositiveBtnText("Confirm");
  60. let str = "Do you want to set the application status to '" + props.getStatus + "'?"
  61. return getConfirmContent(str);
  62. }
  63. }, [props.getStatus]);
  64. useEffect(() => {
  65. if (!props.open) {
  66. positiveOnceRef.current = false;
  67. setPositiveSubmitting(false);
  68. }
  69. }, [props.open]);
  70. const wasConfirmLoadingRef = useRef(false);
  71. useEffect(() => {
  72. if (wasConfirmLoadingRef.current && !props.confirmLoading) {
  73. positiveOnceRef.current = false;
  74. setPositiveSubmitting(false);
  75. }
  76. wasConfirmLoadingRef.current = Boolean(props.confirmLoading);
  77. }, [props.confirmLoading]);
  78. const acceptedHandle = () => () => {
  79. if (confirmLoading) return;
  80. if (positiveOnceRef.current) return;
  81. const statusKey = props.getStatus;
  82. if (statusKey === "notAccepted" || statusKey === "resubmit") {
  83. if (!remarks || remarks === "") {
  84. setHelperText("Please enter reason");
  85. return;
  86. }
  87. setHelperText("");
  88. props.setReason({ "reason": remarks });
  89. }
  90. positiveOnceRef.current = true;
  91. setPositiveSubmitting(true);
  92. props.setStatusWindowAccepted(true);
  93. };
  94. const formik = useFormik({
  95. initialValues: ({
  96. username: '',
  97. }),
  98. validationSchema: yup.object().shape({
  99. }),
  100. });
  101. const getConfirmContent = (text) => {
  102. setContent(<Grid container direction="row" justifyContent="center" alignItems="center">
  103. <FormLabel sx={{ fontSize: "20px", color: "#000000", textAlign: "center" }}>
  104. <Typography variant="h5">{text}</Typography>
  105. </FormLabel>
  106. </Grid>);
  107. }
  108. const getNotAcceptedContent = () => {
  109. setContent(<Grid container direction="row" justifyContent="center" alignItems="center">
  110. <Grid item xs={12} md={12} lg={12}>
  111. <TextField
  112. multiline
  113. fullWidth
  114. rows={6}
  115. placeholder="Please enter reason"
  116. helperText={helperText}
  117. onChange={(newValues) => {
  118. setRemarks(newValues.target.value);
  119. setHelperText("");
  120. }}
  121. variant="outlined"
  122. InputProps={
  123. {
  124. style: { minHeight: '42.5px', maxHeight: '50vh', height: 'auto' },
  125. }
  126. }
  127. />
  128. </Grid>
  129. </Grid>
  130. );
  131. }
  132. const getGazetteCodeContent = () => {
  133. setContent(<Grid container direction="row" justifyContent="center" alignItems="center">
  134. <Grid item xs={12} md={8} lg={8} sx={{ mb: 1, }}>
  135. <Grid container alignItems={"center"}>
  136. <Grid item xs={12} md={2} lg={3}
  137. sx={{ display: 'flex', alignItems: 'center' }}>
  138. <Typography variant="h5">Target Issue:</Typography>
  139. </Grid>
  140. <Grid item xs={12} md={9} lg={9}>
  141. <FormLabel>
  142. <Typography variant="h5">{props.gazetteIssue + ", "}{props.issueNum + ", "}{props.issueDate}</Typography>
  143. </FormLabel>
  144. </Grid>
  145. </Grid>
  146. </Grid>
  147. <Grid item xs={12} md={8} lg={8} sx={{ mb: 1, height: "180px" }}>
  148. <Grid container alignItems={"center"}>
  149. <Grid item xs={12} md={3} lg={3}
  150. sx={{ display: 'flex', alignItems: 'center' }}>
  151. <Typography variant="h5">Gazette Group:</Typography>
  152. </Grid>
  153. <Grid item xs={12} md={9} lg={9}>
  154. <Autocomplete
  155. disablePortal
  156. id="gazetteGroup"
  157. options={groupTitleComboList}
  158. filterOptions={(options) => options}
  159. getOptionLabel={(option) => {
  160. if (option == null) return "";
  161. if (typeof option === "string") return option;
  162. return option.label != null ? String(option.label) : "";
  163. }}
  164. inputValue={comboInputValue.label}
  165. onChange={(event, newValue) => {
  166. if (newValue != null && newValue != {}) {
  167. // console.log(comboInputValue)
  168. props.setSelectedGazetteGroupInputType(newValue.label);
  169. setComboInputValue(newValue);
  170. props.setSelectedGazetteGroup(newValue);
  171. formik.setFieldValue("", "")
  172. } else {
  173. props.setSelectedGazetteGroupInputType("");
  174. }
  175. }}
  176. sx={{
  177. '& .MuiInputBase-root': { alignItems: 'center' },
  178. '& .MuiAutocomplete-endAdornment': { top: '50%', transform: 'translateY(-50%)' },
  179. '& .MuiOutlinedInput-root': { height: 40 }
  180. }}
  181. renderInput={(params) => <TextField {...params} placeholder="" />}
  182. />
  183. </Grid>
  184. </Grid>
  185. </Grid>
  186. </Grid>
  187. );
  188. }
  189. return (
  190. <Dialog
  191. open={props.open}
  192. onClose={() => {
  193. if (confirmLoading) return;
  194. props.handleClose();
  195. }}
  196. fullWidth={true}
  197. maxWidth={'md'}
  198. >
  199. <DialogTitle >
  200. <Grid container>
  201. <Grid item>
  202. <Stack direction="row" height='70px' justifyContent="flex-start" alignItems="center">
  203. <Typography variant="h4">
  204. {dialogTitle}
  205. </Typography>
  206. </Stack>
  207. </Grid>
  208. </Grid>
  209. </DialogTitle>
  210. <FormikProvider value={formik}>
  211. <form>
  212. <DialogContent>
  213. <DialogContentText component="div">
  214. {content}
  215. </DialogContentText>
  216. </DialogContent>
  217. </form>
  218. </FormikProvider>
  219. <Stack direction="row" justifyContent="space-around">
  220. <DialogActions>
  221. <Button variant="contained" onClick={props.handleClose} autoFocus disabled={confirmLoading}>
  222. <Typography variant="h5">
  223. Cancel
  224. </Typography>
  225. </Button>
  226. </DialogActions>
  227. <DialogActions>
  228. <LoadingButton
  229. variant="contained"
  230. color="success"
  231. onClick={acceptedHandle()}
  232. loading={confirmLoading}
  233. disabled={gazetteGroupMissing}
  234. >
  235. <Typography variant="h5" component="span">
  236. {prositiveBtnText}
  237. </Typography>
  238. </LoadingButton>
  239. </DialogActions>
  240. </Stack>
  241. </Dialog>
  242. );
  243. };
  244. export default StatusChangeDialog;