Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 

318 rindas
14 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 }) => {
  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. setFromDateValue(minDate);
  38. }, [minDate]);
  39. React.useEffect(() => {
  40. setToDateValue(maxDate);
  41. }, [maxDate]);
  42. const onSubmit = (data) => {
  43. data.status = status.type;
  44. let typeArray = [];
  45. let sentDateFrom = "";
  46. let sentDateTo = "";
  47. for (let i = 0; i < type.length; i++) {
  48. typeArray.push(type[i].label);
  49. }
  50. if (fromDateValue != "dd / mm / yyyy" && toDateValue != "dd / mm / yyyy") {
  51. sentDateFrom = DateUtils.dateValue(fromDateValue)
  52. sentDateTo = DateUtils.dateValue(toDateValue)
  53. }
  54. const temp = {
  55. appNo: data.appNo,
  56. dateFrom: sentDateFrom,
  57. dateTo: sentDateTo,
  58. contact: data.contact,
  59. careOf: data.careOf?data.careOf:"",
  60. status: (data.status === "" || data.status.includes('all')) ? "" : data.status,
  61. };
  62. applySearch(temp);
  63. };
  64. function resetForm() {
  65. setType([]);
  66. setStatus(localStorage.getItem('userData').creditor?ComboData.publicNoticeStatic_Creditor[0]:ComboData.publicNoticeStatic[0]);
  67. setMinDate(DateUtils.dateValue(new Date().setDate(new Date().getDate()-14)))
  68. setMaxDate(DateUtils.dateValue(new Date()))
  69. reset();
  70. }
  71. return (
  72. <MainCard xs={12} md={12} lg={12}
  73. border={false}
  74. content={false}>
  75. <form onSubmit={handleSubmit(onSubmit)}>
  76. {/*row 1*/}
  77. <Grid item justifyContent="space-between" alignItems="center" sx={{mt:1,ml:3,mb:marginBottom}}>
  78. <Typography variant="pnspsFormHeader" >
  79. <FormattedMessage id="searchForm"/>
  80. </Typography>
  81. </Grid>
  82. {/*row 2*/}
  83. <Grid container alignItems={"center"}>
  84. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  85. <TextField
  86. fullWidth
  87. {...register("appNo")}
  88. id='appNo'
  89. aria-label={intl.formatMessage({id: 'applicationId'})}
  90. label={intl.formatMessage({id: 'applicationId'})}
  91. defaultValue={searchCriteria.appNo}
  92. InputLabelProps={{
  93. shrink: true
  94. }}
  95. />
  96. </Grid>
  97. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  98. <LocalizationProvider dateAdapter={AdapterDayjs}>
  99. <DemoItem components={['DatePicker']}>
  100. <DatePicker
  101. id="dateFrom"
  102. // onError={(newError) => setReceiptFromError(newError)}
  103. slotProps={{
  104. field: { readOnly: true, },
  105. // textField: {
  106. // helperText: receiptFromErrorMessage,
  107. // },
  108. }}
  109. format="DD/MM/YYYY"
  110. aria-label={intl.formatMessage({id: 'submitDateFrom'})}
  111. label={intl.formatMessage({id: 'submitDateFrom'})}
  112. value={minDate === null ? null : dayjs(minDate)}
  113. maxDate={maxDate === null ? null : dayjs(maxDate)}
  114. onChange={(newValue) => {
  115. // console.log(newValue)
  116. if(newValue!=null){
  117. setMinDate(newValue);
  118. }
  119. }}
  120. />
  121. </DemoItem >
  122. </LocalizationProvider>
  123. </Grid>
  124. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  125. <LocalizationProvider dateAdapter={AdapterDayjs}>
  126. <DemoItem components={['DatePicker']}>
  127. <DatePicker
  128. id="dateTo"
  129. // onError={(newError) => setReceiptFromError(newError)}
  130. slotProps={{
  131. field: { readOnly: true, },
  132. // textField: {
  133. // helperText: receiptFromErrorMessage,
  134. // },
  135. }}
  136. format="DD/MM/YYYY"
  137. label={intl.formatMessage({id: 'submitDateTo'})}
  138. value={maxDate === null ? null : dayjs(maxDate)}
  139. minDate={minDate === null ? null : dayjs(minDate)}
  140. onChange={(newValue) => {
  141. // console.log(newValue)
  142. if(newValue!=null){
  143. setMaxDate(newValue);
  144. }
  145. }}
  146. />
  147. </DemoItem >
  148. </LocalizationProvider>
  149. </Grid>
  150. {isORGLoggedIn()?
  151. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  152. <TextField
  153. fullWidth
  154. {...register("careOf")}
  155. id="careOf"
  156. label={intl.formatMessage({id: 'careOf'})}
  157. aria-label={intl.formatMessage({id: 'careOf'})}
  158. defaultValue={searchCriteria.careOf}
  159. InputLabelProps={{
  160. shrink: true
  161. }}
  162. />
  163. </Grid>:null
  164. }
  165. {/* <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  166. <TextField
  167. fullWidth
  168. {...register("contact")}
  169. id="contact"
  170. label={intl.formatMessage({id: 'contactPerson'})}
  171. aria-label={intl.formatMessage({id: 'contactPerson'})}
  172. defaultValue={searchCriteria.contact}
  173. InputLabelProps={{
  174. shrink: true
  175. }}
  176. />
  177. </Grid> */}
  178. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  179. <Autocomplete
  180. {...register("status")}
  181. id="status"
  182. size="small"
  183. // filterOptions={(options)=>options}
  184. options={
  185. localStorage.getItem('userData').creditor ?
  186. ComboData.publicNoticeStatic_Creditor :
  187. ComboData.publicNoticeStatic
  188. }
  189. value={status}
  190. // inputValue={status?.labelCht}
  191. getOptionLabel={(option) => intl.formatMessage({id: option.label})}
  192. onChange={(event, newValue) => {
  193. if(newValue ==null){
  194. setStatus(localStorage.getItem('userData').creditor?ComboData.publicNoticeStatic_Creditor[0]:ComboData.publicNoticeStatic[0]);
  195. }else{
  196. setStatus(newValue);
  197. }
  198. }}
  199. renderInput={(params) => (
  200. <TextField {...params}
  201. label={intl.formatMessage({id: 'status'})}
  202. aria-label={intl.formatMessage({id: 'status'})}
  203. InputLabelProps={{
  204. shrink: true
  205. }}
  206. />
  207. )}
  208. // InputLabelProps={{
  209. // shrink: true
  210. // }}
  211. />
  212. </Grid>
  213. {/* <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  214. <Autocomplete
  215. multiple
  216. {...register("status")}
  217. id="status"
  218. size="small"
  219. // filterOptions={(options)=>options}
  220. options={
  221. localStorage.getItem('userData').creditor ?
  222. ComboData.publicNoticeStatic_Creditor :
  223. ComboData.publicNoticeStatic
  224. }
  225. value={status}
  226. // inputValue={status?.labelCht}
  227. getOptionLabel={(option) => intl.formatMessage({id: option.label})}
  228. onChange={(event, newValue) => {
  229. console.log(newValue)
  230. const findAllIndex = newValue.findIndex((ele) => {
  231. return ele.type === "all"
  232. })
  233. if (findAllIndex > -1) {
  234. setStatus([newValue[findAllIndex]]);
  235. setSelectedLabelsString('all')
  236. } else {
  237. const selectedLabels = newValue.map(option => option.type);
  238. const selectedLabelsString = `${selectedLabels.join(',')}`;
  239. setStatus(newValue);
  240. console.log(newValue)
  241. setSelectedLabelsString(selectedLabelsString);
  242. }
  243. console.log(selectedLabelsString)
  244. console.log(status)
  245. }}
  246. renderInput={(params) => (
  247. <TextField {...params}
  248. label={intl.formatMessage({id: 'status'})}
  249. aria-label={intl.formatMessage({id: 'status'})}
  250. InputLabelProps={{
  251. shrink: true
  252. }}
  253. />
  254. )}
  255. // InputLabelProps={{
  256. // shrink: true
  257. // }}
  258. />
  259. </Grid> */}
  260. </Grid>
  261. {/*last row*/}
  262. <Grid container maxWidth justifyContent="flex-end">
  263. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  264. <Grid item sx={{ ml: 3, mr: 3 }}>
  265. <Button
  266. variant="contained"
  267. color="cancel"
  268. onClick={resetForm}
  269. aria-label={intl.formatMessage({id: 'reset'})}
  270. >
  271. <Typography variant="pnspsButtonText">
  272. <FormattedMessage id="reset"/>
  273. </Typography>
  274. </Button>
  275. </Grid>
  276. <Grid item>
  277. <Button
  278. variant="contained"
  279. type="submit"
  280. aria-label={intl.formatMessage({id: 'search'})}
  281. >
  282. <Typography variant="pnspsButtonText">
  283. <FormattedMessage id="search"/>
  284. </Typography>
  285. </Button>
  286. </Grid>
  287. </ThemeProvider>
  288. </Grid>
  289. </form>
  290. </MainCard>
  291. );
  292. };
  293. export default SearchPublicNoticeForm;