You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

324 lines
14 KiB

  1. // material-ui
  2. import {
  3. Button,
  4. Typography,
  5. Grid, TextField, InputLabel, CardActions
  6. } from '@mui/material';
  7. import MainCard from "../../../components/MainCard";
  8. import {useForm} from "react-hook-form";
  9. import {useContext, useState} from "react";
  10. // import {useContext, useEffect, useState} from "react";
  11. import Autocomplete from '@mui/material/Autocomplete';
  12. import * as React from "react";
  13. // import axios from "axios";
  14. // import {apiPath, getUserData} from "../../../auth/utils";
  15. // import {
  16. // GET_CONSULTANT_COMBO_LIST, GET_EVENT_EXPORT,
  17. // GET_SUB_CONSULTANT_COMBO_LIST, POST_SEARCH_TEMPLATE_PATH, VALIDATE_TEMPLATE_NAME_PATH,
  18. // } from "../../../utils/ApiPathConst";
  19. import {LIONER_BUTTON_THEME} from "../../../themes/colorConst";
  20. // import {
  21. // GeneralCreateTemplateWindow,
  22. // getComboValueByIdList, getComboValueByLabel,
  23. // getIdList, isOptionEqualToValue, notifySaveSuccess,
  24. // } from "../../../utils/CommonFunction";
  25. // import Qs from 'qs';
  26. import {useNavigate} from "react-router";
  27. import {ThemeProvider} from "@emotion/react";
  28. // import UploadContext from "../../../components/UploadProvider";
  29. // import {EVENT_REGION_COMBO, EVENT_TYPE_COMBO} from "../../../utils/ComboConst";
  30. import {LocalizationProvider} from "@mui/x-date-pickers/LocalizationProvider";
  31. import {AdapterDayjs} from "@mui/x-date-pickers/AdapterDayjs";
  32. import {DemoItem} from "@mui/x-date-pickers/internals/demo";
  33. import {DatePicker} from "@mui/x-date-pickers/DatePicker";
  34. import dayjs from "dayjs";
  35. // import {isObjEmpty} from "../../../utils/Utils";
  36. // import {useLocation} from "react-router-dom";
  37. import AbilityContext from "../../../components/AbilityProvider";
  38. import {LIONER_FORM_THEME, CARD_MAX_WIDTH} from "../../../themes/themeConst";
  39. import Collapse from '@mui/material/Collapse';
  40. import {ExpandMore} from "@mui/icons-material";
  41. import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
  42. import { isNull } from 'lodash';
  43. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  44. // const EventSearchForm = ({applySearch, refTemplateData, isUpdating,
  45. // setIsUpdating, getTemplateList,setExpanded,expanded,userConsultant}) => {
  46. const PdfSearchForm = ({applySearch, setExpanded,expanded, clientId}) => {
  47. const navigate = useNavigate()
  48. const ability = useContext(AbilityContext);
  49. const [createDateFrom, setCreateDateFrom] = useState(null);
  50. const [createDateTo, setCreateDateTo] = useState(null);
  51. const { setValue, reset, register, handleSubmit, getValues } = useForm()
  52. const handleExpandClick = () => {
  53. setExpanded(!expanded);
  54. };
  55. const [createDateFromError, setCreateDateFromError] = React.useState(null);
  56. const [createDateToError, setCreateDateToError] = React.useState(null);
  57. const createDateFromErrorMessage = React.useMemo(() => {
  58. switch (createDateFromError) {
  59. case 'invalidDate': {
  60. return "Invalid date";
  61. }
  62. }
  63. }, [createDateFromError]);
  64. const createDateToErrorMessage = React.useMemo(() => {
  65. switch (createDateToError) {
  66. case 'invalidDate': {
  67. return "Invalid date";
  68. }
  69. }
  70. }, [createDateToError]);
  71. const createNewForm = () => {
  72. navigate(`/pdf/maintain/-${clientId}T${1}`);
  73. };
  74. const createFormUpDown = () => {
  75. navigate(`/pdf/form-up-down/-${clientId}T${1}`);
  76. };
  77. const onSubmit = (data) => {
  78. const criteria = {
  79. ...data,
  80. createDateFrom: createDateFrom === null ? null : dayjs(createDateFrom).format('YYYY-MM-DD'),
  81. createDateTo: createDateTo === null ? null : dayjs(createDateTo).format('YYYY-MM-DD'),
  82. };
  83. applySearch(criteria);
  84. };
  85. // function onExport(){
  86. // const data = getValues();
  87. // const temp = {
  88. // ...data,
  89. // fromDate: fromDate === null ? null : dayjs(fromDate).format('YYYY-MM-DD'),
  90. // createDateTo: createDateTo === null ? null : dayjs(createDateTo).format('YYYY-MM-DD'),
  91. // region: selectedRegion === null ? null : selectedRegion.label,
  92. // type: selectedType === null ? null :selectedType.label,
  93. // consultantIdList: getIdList(selectedConsultants),
  94. // caseManagerIdList: getIdList(selectedCaseManager),
  95. // };
  96. // setIsUploading(true);
  97. // axios.get(`${apiPath}${GET_EVENT_EXPORT}`,{
  98. // responseType: 'blob',
  99. // params: temp,
  100. // paramsSerializer: function (params) {
  101. // return Qs.stringify(params, { arrayFormat: 'repeat' });
  102. // },
  103. // })
  104. // .then((response) => {
  105. // if (response.status === 200) {
  106. // setIsUploading(false);
  107. // const url = URL.createObjectURL(new Blob([response.data]));
  108. // const link = document.createElement("a");
  109. // link.href = url;
  110. // link.setAttribute("download", "event_export_"+ Date.now() + ".xlsx");
  111. // link.click();
  112. // }
  113. // })
  114. // .catch(error => {
  115. // setIsUploading(false);
  116. // console.log(error);
  117. // return false;
  118. // });
  119. // }
  120. function resetForm(){
  121. setCreateDateFrom(null);
  122. setCreateDateTo(null);
  123. reset();
  124. }
  125. const handleBack = () => {
  126. navigate('/client');
  127. };
  128. return (
  129. <MainCard xs={12} md={12} lg={12}
  130. content={false}
  131. sx={{width:CARD_MAX_WIDTH}}
  132. >
  133. <Grid item onClick={handleExpandClick}>
  134. <CardActions disableSpacing>
  135. {/*row 1*/}
  136. <Grid item justifyContent="space-between" alignItems="center" sx={{mt:1,ml:2,mb:1}}>
  137. <Typography variant="lionerSubLabel" >
  138. Search Criteria(s)
  139. </Typography>
  140. </Grid>
  141. <ExpandMore
  142. expand={expanded.toString()}
  143. onClick={handleExpandClick}
  144. aria-expanded={expanded}
  145. aria-label="show more"
  146. style={{ marginLeft: 'auto' }} // Align the button to the right
  147. >
  148. <ExpandMoreIcon />
  149. </ExpandMore>
  150. </CardActions>
  151. </Grid>
  152. <Collapse in={expanded} timeout="auto" unmountOnExit>
  153. <form onSubmit={handleSubmit(onSubmit)}>
  154. <ThemeProvider theme={LIONER_FORM_THEME}>
  155. {/*row 2*/}
  156. <Grid container alignItems={"flex-start"} >
  157. <Grid item xs={9} s={6} md={5} lg={3} sx={{ml:3, mr:3, mb:0.5}}>
  158. <InputLabel htmlFor="template">Form</InputLabel>
  159. <TextField
  160. fullWidth
  161. {...register("templateId")}
  162. id='templateId'
  163. inputProps={{maxLength: 255}}
  164. // label="Client Name"
  165. autoComplete="off"
  166. />
  167. </Grid>
  168. <Grid item xs={9} s={6} md={5} lg={3} sx={{ml:3, mr:3, mb:0.5}}>
  169. <InputLabel htmlFor="createDateFrom">Form Create Date</InputLabel>
  170. <Grid container>
  171. <Grid item xs={5.25} s={5.25} md={5.25} lg={5.5}>
  172. <LocalizationProvider dateAdapter={AdapterDayjs}>
  173. <DemoItem>
  174. <DatePicker
  175. id="createDateFrom"
  176. onError={(newError) => setCreateDateFromError(newError)}
  177. slotProps={{
  178. field: { clearable: true },
  179. textField: {
  180. helperText: createDateFromErrorMessage,
  181. },
  182. }}
  183. format="DD/MM/YYYY"
  184. value={createDateFrom === null ? null : dayjs(createDateFrom)}
  185. onChange={(newValue) => setCreateDateFrom(newValue)}
  186. // label="From"
  187. />
  188. </DemoItem >
  189. </LocalizationProvider>
  190. </Grid>
  191. <Grid item xs={1.5} s={1.5} md={1.5} lg={1} sx={{mt:1.3, display: 'flex', justifyContent:"center", alignItems: 'flex-start'}}>
  192. To
  193. </Grid>
  194. <Grid item xs={5.25} s={5.25} md={5.25} lg={5.5}>
  195. <LocalizationProvider dateAdapter={AdapterDayjs}>
  196. <DemoItem components={['DatePicker']}>
  197. <DatePicker
  198. format="DD/MM/YYYY"
  199. onError={(newError) => setCreateDateToError(newError)}
  200. slotProps={{
  201. field: { clearable: true },
  202. textField: {
  203. helperText: createDateToErrorMessage,
  204. },
  205. }}
  206. id="createDateTo"
  207. //label="To Date"
  208. value={createDateTo === null ? null : dayjs(createDateTo)}
  209. onChange={(newValue) => setCreateDateTo(newValue)}
  210. />
  211. </DemoItem >
  212. </LocalizationProvider>
  213. </Grid>
  214. </Grid>
  215. </Grid>
  216. <Grid item xs={9} s={6} md={5} lg={3} sx={{ml:3, mr:3, mb:0.5}}>
  217. <InputLabel htmlFor="remarks">Remarks</InputLabel>
  218. <TextField
  219. fullWidth
  220. {...register("remarks")}
  221. inputProps={{maxLength: 500}}
  222. id="remarks"
  223. autoComplete="off"
  224. />
  225. </Grid>
  226. </Grid>
  227. {/*last row*/}
  228. <Grid container maxWidth justifyContent="space-between" sx={{mt:1.5}}>
  229. <ThemeProvider theme={LIONER_BUTTON_THEME}>
  230. <Grid item>
  231. <Grid container>
  232. <Grid item sx={{ml:3, mr:1.5, mb:2}}>
  233. <Button
  234. variant="contained"
  235. type="submit"
  236. color="save"
  237. disabled={createDateFromError || createDateToError}
  238. onClick={applySearch}
  239. >
  240. Search
  241. </Button>
  242. </Grid>
  243. <Grid item sx={{ml:{xs:1.5, md:1.5, lg:1.5}, mr:1.5, mb:2}}>
  244. <Button
  245. variant="contained"
  246. color="cancel"
  247. onClick={resetForm}
  248. >
  249. Reset
  250. </Button>
  251. </Grid>
  252. <Grid item sx={{ml:{xs:1.5, md:1.5, lg:1.5}, mr:1.5, mb:2}}>
  253. <Button
  254. variant="contained"
  255. color="cancel"
  256. onClick={handleBack}
  257. >
  258. Back
  259. </Button>
  260. </Grid>
  261. </Grid>
  262. </Grid>
  263. <Grid item>
  264. <Grid container>
  265. {ability.can('EDIT','EVENT') ?
  266. <Grid item sx={{ml:3, mr:3, mb:0.5}}>
  267. <Button
  268. variant="contained"
  269. color="create"
  270. onClick={createNewForm}
  271. >
  272. New Form
  273. </Button>
  274. <Button
  275. variant="contained"
  276. color="create"
  277. onClick={createFormUpDown}
  278. >
  279. New Form By Upload/Download
  280. </Button>
  281. </Grid>
  282. :
  283. <Grid/>
  284. }
  285. </Grid>
  286. </Grid>
  287. </ThemeProvider>
  288. </Grid>
  289. </ThemeProvider>
  290. </form>
  291. </Collapse>
  292. </MainCard>
  293. );
  294. };
  295. export default PdfSearchForm;