Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 

281 wiersze
14 KiB

  1. // material-ui
  2. import {
  3. FormControl,
  4. Button,
  5. Grid,
  6. Stack,
  7. Typography, FormLabel,
  8. OutlinedInput,
  9. Dialog, DialogTitle, DialogContent, DialogActions,
  10. } from '@mui/material';
  11. import MainCard from "../../../components/MainCard";
  12. import * as React from "react";
  13. import {useForm} from "react-hook-form";
  14. import {
  15. useEffect,
  16. useState
  17. } from "react";
  18. // import Checkbox from "@mui/material/Checkbox";
  19. import Loadable from 'components/Loadable';
  20. import { lazy } from 'react';
  21. const LoadingComponent = Loadable(lazy(() => import('../../extra-pages/LoadingComponent')));
  22. //import {useParams} from "react-router-dom";
  23. import * as DateUtils from "utils/DateUtils";
  24. import EditNoteIcon from '@mui/icons-material/EditNote';
  25. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  26. const GazetteDetailCard = (
  27. { applicationDetailData,
  28. setStatus
  29. // isCollectData,
  30. // updateUserObject,
  31. // isNewRecord
  32. }
  33. ) => {
  34. // const params = useParams();
  35. // const [currentApplicationDetailData, setCurrentApplicationDetailData] = useState({});
  36. const [onReady,setOnReady] = useState(false);
  37. const [issueNum,setIssueNum] = useState("");
  38. const [issueDate,setIssueDate] = useState("");
  39. const [gazetteCode,setGazetteCode] = useState("");
  40. const [groupTitle,setGroupTitle] = useState("");
  41. const [verified, setVerified] = useState(null);
  42. const [currentStatus, setCurrentStatus] = useState({});
  43. const [isWarningPopUp, setIsWarningPopUp] = useState(false);
  44. const [warningText, setWarningText] = useState("");
  45. const {register,
  46. // getValues
  47. } = useForm()
  48. useEffect(() => {
  49. //if user data from parent are not null
  50. // console.log(applicationDetailData)
  51. if (Object.keys(applicationDetailData).length > 0) {
  52. setCurrentStatus(applicationDetailData.data.status);
  53. setVerified(applicationDetailData.userData.verifiedBy ? true : false);
  54. setIssueNum(applicationDetailData.gazetteIssueDetail.volume+"/"+applicationDetailData.gazetteIssueDetail.year
  55. +" No. "+applicationDetailData.gazetteIssueDetail.issueNo);
  56. setIssueDate(DateUtils.dateFormat(applicationDetailData.gazetteIssueDetail.issueDate, "D MMM YYYY (ddd)"));
  57. setGazetteCode(applicationDetailData.data.groupNo)
  58. console.log(gazetteCode)
  59. setGroupTitle(applicationDetailData.data.groupTitle)
  60. }
  61. }, [applicationDetailData]);
  62. useEffect(() => {
  63. //if state data are ready and assign to different field
  64. // console.log(currentApplicationDetailData)
  65. if (issueNum.length > 0) {
  66. setOnReady(true);
  67. }
  68. }, [issueNum]);
  69. const groupDetailClick = () => () => {
  70. if(gazetteCode==null){
  71. setStatus("genGazetteCode");
  72. return;
  73. }
  74. setWarningText("Gazette Code is already generated, are you sure to re-generate?");
  75. setIsWarningPopUp(true);
  76. };
  77. const callback =()=>{
  78. setIsWarningPopUp(false);
  79. setStatus("genGazetteCode");
  80. }
  81. // useEffect(() => {
  82. // //upload latest data to parent
  83. // const values = getValues();
  84. // const objectData ={
  85. // ...values,
  86. // locked: locked,
  87. // }
  88. // updateUserObject(objectData);
  89. // }, [isCollectData]);
  90. return (
  91. !onReady ?
  92. <LoadingComponent/>
  93. :
  94. <MainCard elevation={0}
  95. border={false}
  96. content={false}
  97. >
  98. {verified && currentStatus != "notAccepted" ?
  99. <Grid container spacing={4} direction="row">
  100. <Grid item xs={12} md={4} >
  101. <Stack
  102. direction="row"
  103. justifyContent="space-between"
  104. alignItems="center"
  105. spacing={2}
  106. mb={2}
  107. >
  108. <Button
  109. // size="large"
  110. variant="contained"
  111. onClick={groupDetailClick()}
  112. sx={{
  113. textTransform: 'capitalize',
  114. alignItems: 'end'
  115. }}>
  116. <EditNoteIcon />
  117. <Typography variant="h5" ml={1}> Gen Gazette Code</Typography>
  118. </Button>
  119. </Stack>
  120. </Grid>
  121. </Grid>
  122. :null}
  123. <Typography variant="h5" sx={{mb: 2, borderBottom: "1px solid black"}}>
  124. Gazette Details
  125. </Typography>
  126. <form>
  127. <Grid container direction="column">
  128. <Grid item xs={12} md={12}>
  129. <Grid container direction="row" justifyContent="space-between"
  130. alignItems="center">
  131. <Grid item xs={12} md={6} lg={6} sx={{mb: 1}}>
  132. <Grid container alignItems={"center"}>
  133. <Grid item xs={12} md={4} lg={4}
  134. sx={{display: 'flex', alignItems: 'center'}}>
  135. <FormLabel><Typography variant="h5">Issue Number:</Typography></FormLabel>
  136. </Grid>
  137. <Grid item xs={12} md={8} lg={8}>
  138. <FormControl variant="outlined" fullWidth disabled >
  139. <OutlinedInput
  140. fullWidth
  141. size="small"
  142. {...register("issueNum",
  143. {
  144. value: issueNum,
  145. })}
  146. value={issueNum}
  147. id='issueNum'
  148. sx={{
  149. "& .MuiInputBase-input.Mui-disabled": {
  150. WebkitTextFillColor: "#000000",
  151. background: "#f8f8f8",
  152. },
  153. }}
  154. />
  155. </FormControl>
  156. </Grid>
  157. </Grid>
  158. </Grid>
  159. <Grid item xs={12} md={5.5} lg={5.5} sx={{mb: 1, ml:1}}>
  160. <Grid container alignItems={"center"}>
  161. <Grid item xs={12} md={4} lg={4}
  162. sx={{display: 'flex', alignItems: 'center'}}>
  163. <FormLabel><Typography variant="h5">Gazette Code:</Typography></FormLabel>
  164. </Grid>
  165. <Grid item xs={12} md={8} lg={8}>
  166. <FormControl variant="outlined" fullWidth disabled >
  167. <OutlinedInput
  168. fullWidth
  169. size="small"
  170. {...register("gazetteCode",
  171. {
  172. value: gazetteCode,
  173. })}
  174. value={gazetteCode}
  175. id='gazetteCode'
  176. sx={{
  177. "& .MuiInputBase-input.Mui-disabled": {
  178. WebkitTextFillColor: "#000000",
  179. background: "#f8f8f8",
  180. },
  181. }}
  182. />
  183. </FormControl>
  184. </Grid>
  185. </Grid>
  186. </Grid>
  187. </Grid>
  188. <Grid container direction="row" justifyContent="space-between"
  189. alignItems="center" sx={{mb:{lg:-3}}}>
  190. <Grid item xs={12} md={6} lg={6} sx={{mb: 1}}>
  191. <Grid container alignItems={"center"}>
  192. <Grid item xs={12} md={4} lg={4}
  193. sx={{display: 'flex', alignItems: 'center'}}>
  194. <FormLabel><Typography variant="h5">Issue Date:</Typography></FormLabel>
  195. </Grid>
  196. <Grid item xs={12} md={8} lg={8}>
  197. <FormControl variant="outlined" fullWidth disabled >
  198. <OutlinedInput
  199. fullWidth
  200. size="small"
  201. {...register("issueDate",
  202. {
  203. value: issueDate,
  204. })}
  205. value={issueDate}
  206. id='issueDate'
  207. sx={{
  208. "& .MuiInputBase-input.Mui-disabled": {
  209. WebkitTextFillColor: "#000000",
  210. background: "#f8f8f8",
  211. },
  212. }}
  213. />
  214. </FormControl>
  215. </Grid>
  216. </Grid>
  217. </Grid>
  218. <Grid item xs={12} md={5.5} lg={5.5} sx={{mb: 1, ml:1}}>
  219. <Grid container alignItems={"center"}>
  220. <Grid item xs={12} md={4} lg={4}
  221. sx={{display: 'flex', alignItems: 'center'}}>
  222. <FormLabel><Typography variant="h5">Group Title:</Typography></FormLabel>
  223. </Grid>
  224. <Grid item xs={12} md={8} lg={8}>
  225. <FormControl variant="outlined" fullWidth disabled >
  226. <OutlinedInput
  227. fullWidth
  228. size="small"
  229. {...register("groupTitle",
  230. {
  231. value: groupTitle,
  232. })}
  233. value={groupTitle}
  234. id='groupTitle'
  235. sx={{
  236. "& .MuiInputBase-input.Mui-disabled": {
  237. WebkitTextFillColor: "#000000",
  238. background: "#f8f8f8",
  239. },
  240. }}
  241. />
  242. </FormControl>
  243. </Grid>
  244. </Grid>
  245. </Grid>
  246. </Grid>
  247. </Grid>
  248. </Grid>
  249. </form>
  250. <div>
  251. <Dialog open={isWarningPopUp} onClose={() => setIsWarningPopUp(false)} >
  252. <DialogTitle><Typography variant="h3">Warning</Typography></DialogTitle>
  253. <DialogContent style={{ display: 'flex', }}>
  254. <Typography variant="h4" style={{ padding: '16px' }}>{warningText}</Typography>
  255. </DialogContent>
  256. <DialogActions>
  257. <Button onClick={() => setIsWarningPopUp(false)}><Typography variant="h5">No</Typography></Button>
  258. <Button color="success" onClick={()=>callback()}><Typography variant="h5">Yes</Typography></Button>
  259. </DialogActions>
  260. </Dialog>
  261. </div>
  262. </MainCard>
  263. );
  264. };
  265. export default GazetteDetailCard;