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.

206 rader
6.2 KiB

  1. import {
  2. useEffect,
  3. useState
  4. } from "react";
  5. // material-ui
  6. import {
  7. Button,
  8. // Link,
  9. Stack,
  10. Typography,
  11. Dialog,
  12. DialogActions,
  13. DialogContent,
  14. DialogContentText,
  15. DialogTitle,
  16. FormLabel,
  17. Autocomplete,
  18. TextField
  19. } from '@mui/material';
  20. import { Grid } from "../../../node_modules/@mui/material/index";
  21. import * as ComboData from "utils/ComboData";
  22. import { useFormik, FormikProvider } from 'formik';
  23. import * as yup from 'yup';
  24. const StatusChangeDialog = (props) => {
  25. const [content, setContent] = useState();
  26. const [dialogTitle, setDialogTitle] = useState("Confirm");
  27. const [prositiveBtnText, setPrositiveBtnText] = useState("Confirm");
  28. const [remarks, setRemarks] = useState("");
  29. const [helperText, setHelperText] = useState("");
  30. const [comboInputValue, setComboInputValue] = useState({});
  31. const groupTitleComboList = ComboData.groupTitle;
  32. useEffect(() => {
  33. setComboInputValue({});
  34. if (props.getStatus == "genGazetteCode") {
  35. setDialogTitle("Gen Gazette Code");
  36. setPrositiveBtnText("Submit");
  37. return getGazetteCodeContent()
  38. } else if (props.getStatus == "notAccepted") {
  39. setDialogTitle("Not Accept Reason");
  40. setPrositiveBtnText("Mark Not Accept");
  41. return getNotAcceptedContent();
  42. } else {
  43. setDialogTitle("Action Confirm");
  44. setPrositiveBtnText("Confirm");
  45. let str = "Are you sure you want to "+props.getStatus+" this application?"
  46. return getConfirmContent(str);
  47. }
  48. }, [props.getStatus]);
  49. const acceptedHandle = () => () => {
  50. const getStatus = props.getStatus.status;
  51. if(getStatus == "notAccepted"){
  52. if(!remarks || remarks=="" )
  53. setHelperText("Please enter reason");
  54. }
  55. if(!helperText){
  56. props.setReason({"reason": remarks});
  57. if (remarks!=null&&remarks!=""){
  58. console.log(remarks)
  59. // props.setStatusWindowAccepted(true);
  60. }
  61. }
  62. if(getStatus != "notAccepted"){
  63. props.setStatusWindowAccepted(true);
  64. }
  65. };
  66. const formik = useFormik({
  67. initialValues: ({
  68. username: '',
  69. }),
  70. validationSchema: yup.object().shape({
  71. }),
  72. });
  73. const getConfirmContent = (text) => {
  74. setContent(<Grid container direction="row" justifyContent="center" alignItems="center">
  75. <FormLabel sx={{ fontSize: "20px", color: "#000000", textAlign: "center" }}>
  76. {text}
  77. </FormLabel>
  78. </Grid>);
  79. }
  80. const getNotAcceptedContent = () => {
  81. setContent(<Grid container direction="row" justifyContent="center" alignItems="center">
  82. <Grid item xs={12} md={12} lg={12} sx={{ mb: 1, }}>
  83. <TextField
  84. fullWidth
  85. multiline
  86. row={10}
  87. minRows={4}
  88. maxRows={4}
  89. inputProps={{ maxLength: 255 }}
  90. placeholder="Please enter reason"
  91. helperText={helperText}
  92. onChange={(newValues)=>{
  93. setRemarks(newValues.target.value);
  94. setHelperText("");
  95. }}
  96. >
  97. </TextField>
  98. </Grid>
  99. </Grid>
  100. );
  101. }
  102. const getGazetteCodeContent = () => {
  103. setContent(<Grid container direction="row" justifyContent="center" alignItems="center">
  104. <Grid item xs={12} md={8} lg={8} sx={{ mb: 1, }}>
  105. <Grid container alignItems={"center"}>
  106. <Grid item xs={12} md={2} lg={3}
  107. sx={{ display: 'flex', alignItems: 'center' }}>
  108. <Typography>Target Issue:</Typography>
  109. </Grid>
  110. <Grid item xs={12} md={9} lg={9}>
  111. <FormLabel>
  112. {props.gazetteIssue + ", "}{props.issueNum + ", "}{props.issueDate}
  113. </FormLabel>
  114. </Grid>
  115. </Grid>
  116. </Grid>
  117. <Grid item xs={12} md={8} lg={8} sx={{ mb: 1, height: "180px" }}>
  118. <Grid container alignItems={"center"}>
  119. <Grid item xs={12} md={3} lg={3}
  120. sx={{ display: 'flex', alignItems: 'center' }}>
  121. <Typography>Gazette Group:</Typography>
  122. </Grid>
  123. <Grid item xs={12} md={9} lg={9}>
  124. <Autocomplete
  125. disablePortal
  126. id="gazetteGroup"
  127. options={groupTitleComboList}
  128. filterOptions={(options) => options}
  129. inputValue={comboInputValue.label}
  130. onChange={(event, newValue) => {
  131. if (newValue != null && newValue != {}) {
  132. console.log(comboInputValue)
  133. props.setSelectedGazetteGroupInputType(newValue.label);
  134. setComboInputValue(newValue);
  135. props.setSelectedGazetteGroup(newValue);
  136. formik.setFieldValue("", "")
  137. } else {gazetteGroup
  138. props.setSelectedGazetteGroupInputType("");
  139. }
  140. }}
  141. // sx={{"& .MuiInputBase-root": { height: "41px" },"#idDocType":{padding: "0px 0px 0px 0px"}, "& .MuiAutocomplete-endAdornment": { top: "auto" },}}
  142. renderInput={(params) => <TextField {...params} placeholder="" />}
  143. />
  144. </Grid>
  145. </Grid>
  146. </Grid>
  147. </Grid>
  148. );
  149. }
  150. return (
  151. <Dialog
  152. open={props.open}
  153. onClose={props.handleClose}
  154. fullWidth={true}
  155. maxWidth={'md'}
  156. >
  157. <DialogTitle >
  158. <Grid container>
  159. <Grid item>
  160. <Stack direction="row" height='70px' justifyContent="flex-start" alignItems="center">
  161. <Typography variant="h4">
  162. {dialogTitle}
  163. </Typography>
  164. </Stack>
  165. </Grid>
  166. </Grid>
  167. </DialogTitle>
  168. <FormikProvider value={formik}>
  169. <form>
  170. <DialogContent>
  171. <DialogContentText>
  172. {content}
  173. </DialogContentText>
  174. </DialogContent>
  175. </form>
  176. </FormikProvider>
  177. <Stack direction="row" justifyContent="space-around">
  178. <DialogActions>
  179. <Button variant="contained" onClick={props.handleClose} autoFocus >
  180. Cancel
  181. </Button>
  182. </DialogActions>
  183. <DialogActions>
  184. <Button variant="contained" color="success" onClick={acceptedHandle()} autoFocus disabled={Object.keys(props.selectedGazetteGroup).length === 0 && props.getStatus === "genGazetteCode"}>
  185. {prositiveBtnText}
  186. </Button>
  187. </DialogActions>
  188. </Stack>
  189. </Dialog>
  190. );
  191. };
  192. export default StatusChangeDialog;