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.
 
 

358 regels
16 KiB

  1. // material-uistatus
  2. import {
  3. Button,
  4. Grid, TextField,
  5. Autocomplete,
  6. Typography
  7. } from '@mui/material';
  8. import MainCard from "components/MainCard";
  9. import { useForm } from "react-hook-form";
  10. import * as React from "react";
  11. import * as ComboData from "utils/ComboData";
  12. import * as DateUtils from "utils/DateUtils";
  13. import {
  14. isORGLoggedIn,
  15. } from "utils/Utils";
  16. import {PNSPS_BUTTON_THEME} from "../../../themes/buttonConst";
  17. import {ThemeProvider} from "@emotion/react";
  18. import {FormattedMessage, useIntl} from "react-intl";
  19. import {DatePicker} from "@mui/x-date-pickers/DatePicker";
  20. import dayjs from "dayjs";
  21. import {DemoItem} from "@mui/x-date-pickers/internals/demo";
  22. import {LocalizationProvider} from "@mui/x-date-pickers/LocalizationProvider";
  23. import {AdapterDayjs} from "@mui/x-date-pickers/AdapterDayjs";
  24. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  25. const SearchPublicNoticeForm = ({ applySearch, searchCriteria, onGridReady }) => {
  26. const intl = useIntl();
  27. const [type, setType] = React.useState([]);
  28. const [status, setStatus] = React.useState(localStorage.getItem('userData').creditor?ComboData.publicNoticeStatic_Creditor[0]:ComboData.publicNoticeStatic[0]);
  29. const [minDate, setMinDate] = React.useState(searchCriteria.dateFrom);
  30. const [maxDate, setMaxDate] = React.useState(searchCriteria.dateTo);
  31. const [fromDateValue, setFromDateValue] = React.useState("dd / mm / yyyy");
  32. const [toDateValue, setToDateValue] = React.useState("dd / mm / yyyy");
  33. // const [selectedLabelsString, setSelectedLabelsString] = React.useState('');
  34. const { reset, register, handleSubmit } = useForm()
  35. const marginBottom = 2.5;
  36. React.useEffect(() => {
  37. if(searchCriteria.status!=undefined){
  38. if(localStorage.getItem('userData').creditor){
  39. if(searchCriteria.status === ""){
  40. ComboData.publicNoticeStatic_Creditor[0]
  41. }else{
  42. setStatus(ComboData.publicNoticeStatic_Creditor.find(item => item.type === searchCriteria.status))
  43. }
  44. }else{
  45. if(searchCriteria.status === ""){
  46. ComboData.publicNoticeStatic[0]
  47. }else{
  48. setStatus(ComboData.publicNoticeStatic.find(item => item.type === searchCriteria.status))
  49. }
  50. }
  51. }else{
  52. if(localStorage.getItem('userData').creditor){
  53. setStatus(ComboData.publicNoticeStatic_Creditor[0])
  54. }else{
  55. setStatus(ComboData.publicNoticeStatic[0])
  56. }
  57. }
  58. }, [searchCriteria]);
  59. React.useEffect(() => {
  60. setFromDateValue(minDate);
  61. }, [minDate]);
  62. React.useEffect(() => {
  63. setToDateValue(maxDate);
  64. }, [maxDate]);
  65. const onSubmit = (data) => {
  66. data.status = status.type;
  67. let typeArray = [];
  68. let sentDateFrom = "";
  69. let sentDateTo = "";
  70. for (let i = 0; i < type.length; i++) {
  71. typeArray.push(type[i].label);
  72. }
  73. if (fromDateValue != "dd / mm / yyyy" && toDateValue != "dd / mm / yyyy") {
  74. sentDateFrom = DateUtils.dateValue(fromDateValue)
  75. sentDateTo = DateUtils.dateValue(toDateValue)
  76. }
  77. const temp = {
  78. appNo: data.appNo,
  79. dateFrom: sentDateFrom,
  80. dateTo: sentDateTo,
  81. contact: data.contact,
  82. careOf: data.careOf?data.careOf:"",
  83. status: (data.status === "" || data.status.includes('all')) ? "" : data.status,
  84. start:0,
  85. limit:10
  86. };
  87. applySearch(temp);
  88. };
  89. function resetForm() {
  90. setType([]);
  91. setStatus(localStorage.getItem('userData').creditor?ComboData.publicNoticeStatic_Creditor[0]:ComboData.publicNoticeStatic[0]);
  92. setMinDate(DateUtils.dateValue(new Date().setDate(new Date().getDate()-14)))
  93. setMaxDate(DateUtils.dateValue(new Date()))
  94. reset({
  95. appNo:""
  96. });
  97. localStorage.setItem('searchCriteria',"")
  98. }
  99. return (
  100. <MainCard xs={12} md={12} lg={12}
  101. border={false}
  102. content={false}>
  103. <form onSubmit={handleSubmit(onSubmit)}>
  104. {/*row 1*/}
  105. <Grid item justifyContent="space-between" alignItems="center" sx={{mt:1,ml:3,mb:marginBottom}}>
  106. <Typography variant="pnspsFormHeader" >
  107. <FormattedMessage id="searchForm"/>
  108. </Typography>
  109. </Grid>
  110. {/*row 2*/}
  111. <Grid container alignItems={"center"}>
  112. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  113. <TextField
  114. fullWidth
  115. {...register("appNo")}
  116. id='appNo'
  117. aria-label={intl.formatMessage({id: 'applicationId'})}
  118. label={intl.formatMessage({id: 'applicationId'})}
  119. defaultValue={searchCriteria.appNo}
  120. InputLabelProps={{
  121. shrink: true
  122. }}
  123. />
  124. </Grid>
  125. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  126. <LocalizationProvider dateAdapter={AdapterDayjs} localeText={DateUtils.getPickerLocaleText(intl.locale)}>
  127. <DemoItem components={['DatePicker']}>
  128. <DatePicker
  129. id="dateFrom"
  130. // onError={(newError) => setReceiptFromError(newError)}
  131. slotProps={{
  132. field: { readOnly: true, },
  133. // textField: {
  134. // helperText: receiptFromErrorMessage,
  135. // },
  136. }}
  137. format="DD/MM/YYYY"
  138. aria-label={intl.formatMessage({id: 'submitDateFrom'})}
  139. label={intl.formatMessage({id: 'submitDateFrom'})}
  140. value={minDate === null ? null : dayjs(minDate)}
  141. maxDate={maxDate === null ? null : dayjs(maxDate)}
  142. onChange={(newValue) => {
  143. // console.log(newValue)
  144. if(newValue!=null){
  145. setMinDate(newValue);
  146. }
  147. }}
  148. />
  149. </DemoItem >
  150. </LocalizationProvider>
  151. </Grid>
  152. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  153. <LocalizationProvider dateAdapter={AdapterDayjs} localeText={DateUtils.getPickerLocaleText(intl.locale)}>
  154. <DemoItem components={['DatePicker']}>
  155. <DatePicker
  156. id="dateTo"
  157. // onError={(newError) => setReceiptFromError(newError)}
  158. slotProps={{
  159. field: { readOnly: true, },
  160. // textField: {
  161. // helperText: receiptFromErrorMessage,
  162. // },
  163. }}
  164. format="DD/MM/YYYY"
  165. label={intl.formatMessage({id: 'submitDateTo'})}
  166. value={maxDate === null ? null : dayjs(maxDate)}
  167. minDate={minDate === null ? null : dayjs(minDate)}
  168. onChange={(newValue) => {
  169. // console.log(newValue)
  170. if(newValue!=null){
  171. setMaxDate(newValue);
  172. }
  173. }}
  174. />
  175. </DemoItem >
  176. </LocalizationProvider>
  177. </Grid>
  178. {isORGLoggedIn()?
  179. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  180. <TextField
  181. fullWidth
  182. {...register("careOf")}
  183. id="careOf"
  184. label={intl.formatMessage({id: 'careOf'})}
  185. aria-label={intl.formatMessage({id: 'careOf'})}
  186. defaultValue={searchCriteria.careOf}
  187. InputLabelProps={{
  188. shrink: true
  189. }}
  190. />
  191. </Grid>:null
  192. }
  193. {/* <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  194. <TextField
  195. fullWidth
  196. {...register("contact")}
  197. id="contact"
  198. label={intl.formatMessage({id: 'contactPerson'})}
  199. aria-label={intl.formatMessage({id: 'contactPerson'})}
  200. defaultValue={searchCriteria.contact}
  201. InputLabelProps={{
  202. shrink: true
  203. }}
  204. />
  205. </Grid> */}
  206. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  207. <Autocomplete
  208. {...register("status")}
  209. id="status"
  210. size="small"
  211. disableClearable
  212. // filterOptions={(options)=>options}
  213. options={
  214. localStorage.getItem('userData').creditor ?
  215. ComboData.publicNoticeStatic_Creditor :
  216. ComboData.publicNoticeStatic
  217. }
  218. value={status}
  219. // inputValue={status?.labelCht}
  220. getOptionLabel={(option) => intl.formatMessage({id: option.label})}
  221. onChange={(event, newValue) => {
  222. if(newValue ==null){
  223. setStatus(localStorage.getItem('userData').creditor?ComboData.publicNoticeStatic_Creditor[0]:ComboData.publicNoticeStatic[0]);
  224. }else{
  225. setStatus(newValue);
  226. }
  227. }}
  228. sx={{
  229. '& .MuiInputBase-root': { alignItems: 'center' },
  230. '& .MuiAutocomplete-endAdornment': { top: '50%', transform: 'translateY(-50%)' },
  231. '& .MuiOutlinedInput-root': { height: 40 }
  232. }}
  233. renderInput={(params) => (
  234. <TextField {...params}
  235. label={intl.formatMessage({id: 'status'})}
  236. aria-label={intl.formatMessage({id: 'status'})}
  237. InputLabelProps={{
  238. shrink: true
  239. }}
  240. />
  241. )}
  242. clearText={intl.formatMessage({ id: "muiClear" })}
  243. closeText={intl.formatMessage({ id: "muiClose" })}
  244. openText={intl.formatMessage({ id: "muiOpen" })}
  245. noOptionsText={intl.formatMessage({ id: "muiNoOptions" })}
  246. // InputLabelProps={{
  247. // shrink: true
  248. // }}
  249. />
  250. </Grid>
  251. {/* <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  252. <Autocomplete
  253. multiple
  254. {...register("status")}
  255. id="status"
  256. size="small"
  257. // filterOptions={(options)=>options}
  258. options={
  259. localStorage.getItem('userData').creditor ?
  260. ComboData.publicNoticeStatic_Creditor :
  261. ComboData.publicNoticeStatic
  262. }
  263. value={status}
  264. // inputValue={status?.labelCht}
  265. getOptionLabel={(option) => intl.formatMessage({id: option.label})}
  266. onChange={(event, newValue) => {
  267. console.log(newValue)
  268. const findAllIndex = newValue.findIndex((ele) => {
  269. return ele.type === "all"
  270. })
  271. if (findAllIndex > -1) {
  272. setStatus([newValue[findAllIndex]]);
  273. setSelectedLabelsString('all')
  274. } else {
  275. const selectedLabels = newValue.map(option => option.type);
  276. const selectedLabelsString = `${selectedLabels.join(',')}`;
  277. setStatus(newValue);
  278. console.log(newValue)
  279. setSelectedLabelsString(selectedLabelsString);
  280. }
  281. console.log(selectedLabelsString)
  282. console.log(status)
  283. }}
  284. renderInput={(params) => (
  285. <TextField {...params}
  286. label={intl.formatMessage({id: 'status'})}
  287. aria-label={intl.formatMessage({id: 'status'})}
  288. InputLabelProps={{
  289. shrink: true
  290. }}
  291. />
  292. )}
  293. // InputLabelProps={{
  294. // shrink: true
  295. // }}
  296. />
  297. </Grid> */}
  298. </Grid>
  299. {/*last row*/}
  300. <Grid container maxWidth justifyContent="flex-end">
  301. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  302. <Grid item sx={{ ml: 3, mr: 3 }}>
  303. <Button
  304. variant="contained"
  305. color="cancel"
  306. onClick={resetForm}
  307. aria-label={intl.formatMessage({id: 'reset'})}
  308. >
  309. <Typography variant="pnspsButtonText">
  310. <FormattedMessage id="reset"/>
  311. </Typography>
  312. </Button>
  313. </Grid>
  314. <Grid item>
  315. <Button
  316. variant="contained"
  317. type="submit"
  318. disabled={onGridReady}
  319. aria-label={intl.formatMessage({id: 'search'})}
  320. >
  321. <Typography variant="pnspsButtonText">
  322. <FormattedMessage id="search"/>
  323. </Typography>
  324. </Button>
  325. </Grid>
  326. </ThemeProvider>
  327. </Grid>
  328. </form>
  329. </MainCard>
  330. );
  331. };
  332. export default SearchPublicNoticeForm;