Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 

434 рядки
18 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. import {SelectTemplateWindow} from "./SelectTemplateWindow";
  44. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  45. // const EventSearchForm = ({applySearch, refTemplateData, isUpdating,
  46. // setIsUpdating, getTemplateList,setExpanded,expanded,userConsultant}) => {
  47. const PdfSearchForm = ({applySearch, setExpanded,expanded, clientId}) => {
  48. const navigate = useNavigate()
  49. const ability = useContext(AbilityContext);
  50. const [isWindowOpen, setIsWindowOpen] = useState(false);
  51. const [createDateFrom, setCreateDateFrom] = useState(null);
  52. const [createDateTo, setCreateDateTo] = useState(null);
  53. const { setValue, reset, register, handleSubmit, getValues } = useForm()
  54. const handleExpandClick = () => {
  55. setExpanded(!expanded);
  56. };
  57. const [createDateFromError, setCreateDateFromError] = React.useState(null);
  58. const [createDateToError, setCreateDateToError] = React.useState(null);
  59. const createDateFromErrorMessage = React.useMemo(() => {
  60. switch (createDateFromError) {
  61. case 'invalidDate': {
  62. return "Invalid date";
  63. }
  64. }
  65. }, [createDateFromError]);
  66. const createDateToErrorMessage = React.useMemo(() => {
  67. switch (createDateToError) {
  68. case 'invalidDate': {
  69. return "Invalid date";
  70. }
  71. }
  72. }, [createDateToError]);
  73. // const createFormUpDown = () => {
  74. // navigate(`/pdf/form-up-down/-${clientId}T${1}`);
  75. // };
  76. // const createFormIDA = () => {
  77. // navigate(`/pdf/newIDA/${clientId}`);
  78. // };
  79. // const createFormFNA = () => {
  80. // navigate(`/pdf/newFNA/${clientId}`);
  81. // };
  82. // const createFormHSBCFIN = () => {
  83. // navigate(`/pdf/newHSBCFIN/${clientId}`);
  84. // };
  85. const onSubmit = (data) => {
  86. const criteria = {
  87. ...data,
  88. createDateFrom: createDateFrom === null ? null : dayjs(createDateFrom).format('YYYY-MM-DD'),
  89. createDateTo: createDateTo === null ? null : dayjs(createDateTo).format('YYYY-MM-DD'),
  90. };
  91. applySearch(criteria);
  92. };
  93. // function onExport(){
  94. // const data = getValues();
  95. // const temp = {
  96. // ...data,
  97. // fromDate: fromDate === null ? null : dayjs(fromDate).format('YYYY-MM-DD'),
  98. // createDateTo: createDateTo === null ? null : dayjs(createDateTo).format('YYYY-MM-DD'),
  99. // region: selectedRegion === null ? null : selectedRegion.label,
  100. // type: selectedType === null ? null :selectedType.label,
  101. // consultantIdList: getIdList(selectedConsultants),
  102. // caseManagerIdList: getIdList(selectedCaseManager),
  103. // };
  104. // setIsUploading(true);
  105. // axios.get(`${apiPath}${GET_EVENT_EXPORT}`,{
  106. // responseType: 'blob',
  107. // params: temp,
  108. // paramsSerializer: function (params) {
  109. // return Qs.stringify(params, { arrayFormat: 'repeat' });
  110. // },
  111. // })
  112. // .then((response) => {
  113. // if (response.status === 200) {
  114. // setIsUploading(false);
  115. // const url = URL.createObjectURL(new Blob([response.data]));
  116. // const link = document.createElement("a");
  117. // link.href = url;
  118. // link.setAttribute("download", "event_export_"+ Date.now() + ".xlsx");
  119. // link.click();
  120. // }
  121. // })
  122. // .catch(error => {
  123. // setIsUploading(false);
  124. // console.log(error);
  125. // return false;
  126. // });
  127. // }
  128. function resetForm(){
  129. setCreateDateFrom(null);
  130. setCreateDateTo(null);
  131. reset();
  132. }
  133. const handleBack = () => {
  134. navigate('/client');
  135. };
  136. return (
  137. <MainCard xs={12} md={12} lg={12}
  138. content={false}
  139. sx={{width:CARD_MAX_WIDTH}}
  140. >
  141. <Grid item onClick={handleExpandClick}>
  142. <CardActions disableSpacing>
  143. {/*row 1*/}
  144. <Grid item justifyContent="space-between" alignItems="center" sx={{mt:1,ml:2,mb:1}}>
  145. <Typography variant="lionerSubLabel" >
  146. Search Criteria(s)
  147. </Typography>
  148. </Grid>
  149. <ExpandMore
  150. expand={expanded.toString()}
  151. onClick={handleExpandClick}
  152. aria-expanded={expanded}
  153. aria-label="show more"
  154. style={{ marginLeft: 'auto' }} // Align the button to the right
  155. >
  156. <ExpandMoreIcon />
  157. </ExpandMore>
  158. </CardActions>
  159. </Grid>
  160. <Collapse in={expanded} timeout="auto" unmountOnExit>
  161. <form onSubmit={handleSubmit(onSubmit)}>
  162. <ThemeProvider theme={LIONER_FORM_THEME}>
  163. {/*row 2*/}
  164. <Grid container alignItems={"flex-start"} >
  165. <Grid item xs={9} s={6} md={5} lg={3} sx={{ml:3, mr:3, mb:0.5}}>
  166. <InputLabel htmlFor="template">Form</InputLabel>
  167. <TextField
  168. fullWidth
  169. {...register("templateId")}
  170. id='templateId'
  171. inputProps={{maxLength: 255}}
  172. // label="Client Name"
  173. autoComplete="off"
  174. />
  175. </Grid>
  176. <Grid item xs={9} s={6} md={5} lg={3} sx={{ml:3, mr:3, mb:0.5}}>
  177. <InputLabel htmlFor="createDateFrom">Form Create Date</InputLabel>
  178. <Grid container>
  179. <Grid item xs={5.25} s={5.25} md={5.25} lg={5.5}>
  180. <LocalizationProvider dateAdapter={AdapterDayjs}>
  181. <DemoItem>
  182. <DatePicker
  183. id="createDateFrom"
  184. onError={(newError) => setCreateDateFromError(newError)}
  185. slotProps={{
  186. field: { clearable: true },
  187. textField: {
  188. helperText: createDateFromErrorMessage,
  189. },
  190. }}
  191. format="DD/MM/YYYY"
  192. value={createDateFrom === null ? null : dayjs(createDateFrom)}
  193. onChange={(newValue) => setCreateDateFrom(newValue)}
  194. // label="From"
  195. />
  196. </DemoItem >
  197. </LocalizationProvider>
  198. </Grid>
  199. <Grid item xs={1.5} s={1.5} md={1.5} lg={1} sx={{mt:1.3, display: 'flex', justifyContent:"center", alignItems: 'flex-start'}}>
  200. To
  201. </Grid>
  202. <Grid item xs={5.25} s={5.25} md={5.25} lg={5.5}>
  203. <LocalizationProvider dateAdapter={AdapterDayjs}>
  204. <DemoItem components={['DatePicker']}>
  205. <DatePicker
  206. format="DD/MM/YYYY"
  207. onError={(newError) => setCreateDateToError(newError)}
  208. slotProps={{
  209. field: { clearable: true },
  210. textField: {
  211. helperText: createDateToErrorMessage,
  212. },
  213. }}
  214. id="createDateTo"
  215. //label="To Date"
  216. value={createDateTo === null ? null : dayjs(createDateTo)}
  217. onChange={(newValue) => setCreateDateTo(newValue)}
  218. />
  219. </DemoItem >
  220. </LocalizationProvider>
  221. </Grid>
  222. </Grid>
  223. </Grid>
  224. {/* <Grid item xs={9} s={6} md={5} lg={3} sx={{ml:3, mr:3, mb:0.5}}>
  225. <InputLabel htmlFor="remarks">Remarks</InputLabel>
  226. <TextField
  227. fullWidth
  228. {...register("remarks")}
  229. inputProps={{maxLength: 500}}
  230. id="remarks"
  231. autoComplete="off"
  232. />
  233. </Grid> */}
  234. </Grid>
  235. {/*last row*/}
  236. <Grid container maxWidth justifyContent="space-between" sx={{mt:1.5}}>
  237. <ThemeProvider theme={LIONER_BUTTON_THEME}>
  238. <Grid item>
  239. <Grid container>
  240. <Grid item sx={{ml:3, mr:1.5, mb:2}}>
  241. <Button
  242. variant="contained"
  243. type="submit"
  244. color="save"
  245. disabled={createDateFromError || createDateToError}
  246. onClick={applySearch}
  247. >
  248. Search
  249. </Button>
  250. </Grid>
  251. <Grid item sx={{ml:{xs:1.5, md:1.5, lg:1.5}, mr:1.5, mb:2}}>
  252. <Button
  253. variant="contained"
  254. color="cancel"
  255. onClick={resetForm}
  256. >
  257. Reset
  258. </Button>
  259. </Grid>
  260. <Grid item sx={{ml:{xs:1.5, md:1.5, lg:1.5}, mr:1.5, mb:2}}>
  261. <Button
  262. variant="contained"
  263. color="cancel"
  264. onClick={handleBack}
  265. >
  266. Back
  267. </Button>
  268. </Grid>
  269. </Grid>
  270. </Grid>
  271. <Grid item>
  272. <Grid container>
  273. {ability.can('MAINTAIN','CLIENT') ?
  274. <Grid item sx={{ml:3, mr:3, mb:0.5}}>
  275. <Button
  276. variant="contained"
  277. color="create"
  278. onClick={() => setIsWindowOpen(true)}
  279. >
  280. New Form
  281. </Button>
  282. <SelectTemplateWindow
  283. isWindowOpen={isWindowOpen}
  284. onNormalClose={() => {setIsWindowOpen(false)}}
  285. onConfirmClose={() => {setIsWindowOpen(false)}}
  286. clientId={clientId}
  287. />
  288. </Grid>
  289. :
  290. <Grid/>
  291. }
  292. </Grid>
  293. {/* <Grid item>
  294. <Button
  295. variant="contained"
  296. color="create"
  297. onClick={createFormIDA}
  298. >
  299. New Lioner IDA
  300. </Button>
  301. </Grid>
  302. <Grid item>
  303. <Button
  304. variant="contained"
  305. color="create"
  306. onClick={createFormFNA}
  307. >
  308. New Lioner FNA
  309. </Button>
  310. </Grid>
  311. <Grid item>
  312. <Button
  313. variant="contained"
  314. color="create"
  315. onClick={createFormHSBCFIN}
  316. >
  317. New HSBCFIN
  318. </Button>
  319. </Grid>
  320. <Grid item>
  321. <Button
  322. variant="contained"
  323. color="create"
  324. onClick={() => {}}
  325. >
  326. New HSBCA31
  327. </Button>
  328. </Grid>
  329. <Grid item>
  330. <Button
  331. variant="contained"
  332. color="create"
  333. onClick={() => {}}
  334. >
  335. New MLB035
  336. </Button>
  337. </Grid>
  338. <Grid item>
  339. <Button
  340. variant="contained"
  341. color="create"
  342. onClick={() => {}}
  343. >
  344. New MLFNA ENG
  345. </Button>
  346. </Grid>
  347. <Grid item>
  348. <Button
  349. variant="contained"
  350. color="create"
  351. onClick={() => {}}
  352. >
  353. New MLFNA CHI
  354. </Button>
  355. </Grid>
  356. <Grid item>
  357. <Button
  358. variant="contained"
  359. color="create"
  360. onClick={() => {}}
  361. >
  362. New SLFNA ENG
  363. </Button>
  364. </Grid>
  365. <Grid item>
  366. <Button
  367. variant="contained"
  368. color="create"
  369. onClick={() => {}}
  370. >
  371. New SLFNA CHI
  372. </Button>
  373. </Grid>
  374. <Grid item>
  375. <Button
  376. variant="contained"
  377. color="create"
  378. onClick={() => {}}
  379. >
  380. New SLGII
  381. </Button>
  382. </Grid>
  383. <Grid item>
  384. <Button
  385. variant="contained"
  386. color="create"
  387. onClick={() => {}}
  388. >
  389. New SL Saving
  390. </Button>
  391. </Grid> */}
  392. </Grid>
  393. </ThemeProvider>
  394. </Grid>
  395. </ThemeProvider>
  396. </form>
  397. </Collapse>
  398. </MainCard>
  399. );
  400. };
  401. export default PdfSearchForm;