|
|
@@ -21,6 +21,21 @@ import dayjs from "dayjs"; |
|
|
import {DemoItem} from "@mui/x-date-pickers/internals/demo"; |
|
|
import {DemoItem} from "@mui/x-date-pickers/internals/demo"; |
|
|
import {LocalizationProvider} from "@mui/x-date-pickers/LocalizationProvider"; |
|
|
import {LocalizationProvider} from "@mui/x-date-pickers/LocalizationProvider"; |
|
|
import {AdapterDayjs} from "@mui/x-date-pickers/AdapterDayjs"; |
|
|
import {AdapterDayjs} from "@mui/x-date-pickers/AdapterDayjs"; |
|
|
|
|
|
|
|
|
|
|
|
const getDefaultDateFrom = () => DateUtils.dateValue(new Date().setDate(new Date().getDate() - 14)); |
|
|
|
|
|
const getDefaultDateTo = () => DateUtils.dateValue(new Date()); |
|
|
|
|
|
|
|
|
|
|
|
const isSubmitDateEmpty = (value) => |
|
|
|
|
|
value == null || value === "" || value === "dd / mm / yyyy"; |
|
|
|
|
|
|
|
|
|
|
|
const isBlank = (value) => value == null || String(value).trim() === ""; |
|
|
|
|
|
|
|
|
|
|
|
const toDayjsOrNull = (value) => { |
|
|
|
|
|
if (isSubmitDateEmpty(value)) return null; |
|
|
|
|
|
const d = dayjs(value); |
|
|
|
|
|
return d.isValid() ? d : null; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
// ==============================|| DASHBOARD - DEFAULT ||============================== // |
|
|
// ==============================|| DASHBOARD - DEFAULT ||============================== // |
|
|
const SearchPublicNoticeForm = ({ applySearch, searchCriteria, issueComboData, onGridReady |
|
|
const SearchPublicNoticeForm = ({ applySearch, searchCriteria, issueComboData, onGridReady |
|
|
}) => { |
|
|
}) => { |
|
|
@@ -37,6 +52,7 @@ const SearchPublicNoticeForm = ({ applySearch, searchCriteria, issueComboData, o |
|
|
const [maxDate, setMaxDate] = React.useState(searchCriteria.dateTo); |
|
|
const [maxDate, setMaxDate] = React.useState(searchCriteria.dateTo); |
|
|
const [fromDateValue, setFromDateValue] = React.useState("dd / mm / yyyy"); |
|
|
const [fromDateValue, setFromDateValue] = React.useState("dd / mm / yyyy"); |
|
|
const [toDateValue, setToDateValue] = React.useState("dd / mm / yyyy"); |
|
|
const [toDateValue, setToDateValue] = React.useState("dd / mm / yyyy"); |
|
|
|
|
|
const prevHasOtherRef = React.useRef(null); |
|
|
|
|
|
|
|
|
React.useEffect(() => { |
|
|
React.useEffect(() => { |
|
|
if(searchCriteria.status!=undefined){ |
|
|
if(searchCriteria.status!=undefined){ |
|
|
@@ -64,7 +80,53 @@ const SearchPublicNoticeForm = ({ applySearch, searchCriteria, issueComboData, o |
|
|
const { locale } = intl; |
|
|
const { locale } = intl; |
|
|
|
|
|
|
|
|
const marginBottom = 2.5; |
|
|
const marginBottom = 2.5; |
|
|
const { reset, register, handleSubmit } = useForm() |
|
|
|
|
|
|
|
|
const { reset, register, handleSubmit, watch } = useForm({ |
|
|
|
|
|
defaultValues: { |
|
|
|
|
|
appNo: searchCriteria.appNo || "", |
|
|
|
|
|
contact: searchCriteria.contact || "", |
|
|
|
|
|
groupNo: searchCriteria.groupNo || "" |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
const appNo = watch("appNo"); |
|
|
|
|
|
const contact = watch("contact"); |
|
|
|
|
|
const groupNo = watch("groupNo"); |
|
|
|
|
|
|
|
|
|
|
|
const clearSubmitDates = () => { |
|
|
|
|
|
setMinDate(null); |
|
|
|
|
|
setMaxDate(null); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const restoreDefaultSubmitDates = () => { |
|
|
|
|
|
setMinDate(getDefaultDateFrom()); |
|
|
|
|
|
setMaxDate(getDefaultDateTo()); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const hasOtherCriteria = (textFields = {}) => { |
|
|
|
|
|
if (!isBlank(textFields.appNo)) return true; |
|
|
|
|
|
if (!isBlank(textFields.contact)) return true; |
|
|
|
|
|
if (!isBlank(textFields.groupNo)) return true; |
|
|
|
|
|
if (groupSelected?.title) return true; |
|
|
|
|
|
if (orgSelected?.key && orgSelected.key > 0) return true; |
|
|
|
|
|
if (issueSelected?.id) return true; |
|
|
|
|
|
if (selectedStatus?.type && selectedStatus.type !== "all" && selectedStatus.type !== "") return true; |
|
|
|
|
|
if (selectedMode?.type && selectedMode.type !== "all" && selectedMode.type !== "") return true; |
|
|
|
|
|
return false; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
React.useEffect(() => { |
|
|
|
|
|
const hasOther = hasOtherCriteria({ appNo, contact, groupNo }); |
|
|
|
|
|
if (prevHasOtherRef.current === null) { |
|
|
|
|
|
prevHasOtherRef.current = hasOther; |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
if (hasOther && !prevHasOtherRef.current) { |
|
|
|
|
|
clearSubmitDates(); |
|
|
|
|
|
} else if (!hasOther && prevHasOtherRef.current) { |
|
|
|
|
|
restoreDefaultSubmitDates(); |
|
|
|
|
|
} |
|
|
|
|
|
prevHasOtherRef.current = hasOther; |
|
|
|
|
|
}, [appNo, contact, groupNo, groupSelected, orgSelected, issueSelected, selectedStatus, selectedMode]); |
|
|
|
|
|
|
|
|
const onSubmit = (data) => { |
|
|
const onSubmit = (data) => { |
|
|
// localStorage.setItem('searchCriteria',"") |
|
|
// localStorage.setItem('searchCriteria',"") |
|
|
data.status = selectedStatus?.type |
|
|
data.status = selectedStatus?.type |
|
|
@@ -76,10 +138,25 @@ const SearchPublicNoticeForm = ({ applySearch, searchCriteria, issueComboData, o |
|
|
for (let i = 0; i < type.length; i++) { |
|
|
for (let i = 0; i < type.length; i++) { |
|
|
typeArray.push(type[i].label); |
|
|
typeArray.push(type[i].label); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (fromDateValue != "dd / mm / yyyy" && toDateValue != "dd / mm / yyyy") { |
|
|
|
|
|
sentDateFrom = DateUtils.dateValue(fromDateValue) |
|
|
|
|
|
sentDateTo = DateUtils.dateValue(toDateValue) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const hasOther = hasOtherCriteria({ |
|
|
|
|
|
appNo: data.appNo, |
|
|
|
|
|
contact: data.contact, |
|
|
|
|
|
groupNo: data.groupNo |
|
|
|
|
|
}); |
|
|
|
|
|
const datesEmpty = isSubmitDateEmpty(fromDateValue) || isSubmitDateEmpty(toDateValue) |
|
|
|
|
|
|| minDate == null || maxDate == null; |
|
|
|
|
|
|
|
|
|
|
|
if (!hasOther && datesEmpty) { |
|
|
|
|
|
const dateFrom = getDefaultDateFrom(); |
|
|
|
|
|
const dateTo = getDefaultDateTo(); |
|
|
|
|
|
setMinDate(dateFrom); |
|
|
|
|
|
setMaxDate(dateTo); |
|
|
|
|
|
sentDateFrom = dateFrom; |
|
|
|
|
|
sentDateTo = dateTo; |
|
|
|
|
|
} else if (!datesEmpty) { |
|
|
|
|
|
sentDateFrom = DateUtils.dateValue(fromDateValue); |
|
|
|
|
|
sentDateTo = DateUtils.dateValue(toDateValue); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const temp = { |
|
|
const temp = { |
|
|
@@ -121,8 +198,8 @@ const SearchPublicNoticeForm = ({ applySearch, searchCriteria, issueComboData, o |
|
|
setGroupSelected({}); |
|
|
setGroupSelected({}); |
|
|
setSelectedStatus({key: 0, label: 'All', type: 'all'}); |
|
|
setSelectedStatus({key: 0, label: 'All', type: 'all'}); |
|
|
setSelectedMode({key: 0, label: 'All', type: 'all'}); |
|
|
setSelectedMode({key: 0, label: 'All', type: 'all'}); |
|
|
const dateFrom = DateUtils.dateValue(new Date().setDate(new Date().getDate() - 14)); |
|
|
|
|
|
const dateTo = DateUtils.dateValue(new Date()); |
|
|
|
|
|
|
|
|
const dateFrom = getDefaultDateFrom(); |
|
|
|
|
|
const dateTo = getDefaultDateTo(); |
|
|
setMinDate(dateFrom); |
|
|
setMinDate(dateFrom); |
|
|
setMaxDate(dateTo); |
|
|
setMaxDate(dateTo); |
|
|
reset({ |
|
|
reset({ |
|
|
@@ -130,6 +207,7 @@ const SearchPublicNoticeForm = ({ applySearch, searchCriteria, issueComboData, o |
|
|
contact:"", |
|
|
contact:"", |
|
|
groupNo:"" |
|
|
groupNo:"" |
|
|
}); |
|
|
}); |
|
|
|
|
|
prevHasOtherRef.current = false; |
|
|
localStorage.setItem('searchCriteria',""); |
|
|
localStorage.setItem('searchCriteria',""); |
|
|
// Reset form criteria and sorting first, then reload with backend default sort |
|
|
// Reset form criteria and sorting first, then reload with backend default sort |
|
|
applySearch({ |
|
|
applySearch({ |
|
|
@@ -209,22 +287,21 @@ const SearchPublicNoticeForm = ({ applySearch, searchCriteria, issueComboData, o |
|
|
<DemoItem components={['DatePicker']}> |
|
|
<DemoItem components={['DatePicker']}> |
|
|
<DatePicker |
|
|
<DatePicker |
|
|
id="dateFrom" |
|
|
id="dateFrom" |
|
|
// onError={(newError) => setReceiptFromError(newError)} |
|
|
|
|
|
|
|
|
onError={() => {}} |
|
|
slotProps={{ |
|
|
slotProps={{ |
|
|
field: { readOnly: true, }, |
|
|
|
|
|
// textField: { |
|
|
|
|
|
// helperText: receiptFromErrorMessage, |
|
|
|
|
|
// }, |
|
|
|
|
|
|
|
|
field: { readOnly: true, clearable: true }, |
|
|
|
|
|
textField: { |
|
|
|
|
|
InputLabelProps: { shrink: true }, |
|
|
|
|
|
error: false, |
|
|
|
|
|
helperText: null |
|
|
|
|
|
}, |
|
|
}} |
|
|
}} |
|
|
format="DD/MM/YYYY" |
|
|
format="DD/MM/YYYY" |
|
|
label={"Submit Date (From)"} |
|
|
label={"Submit Date (From)"} |
|
|
value={minDate === null ? null : dayjs(minDate)} |
|
|
|
|
|
maxDate={maxDate === null ? null : dayjs(maxDate)} |
|
|
|
|
|
|
|
|
value={toDayjsOrNull(minDate)} |
|
|
|
|
|
maxDate={toDayjsOrNull(maxDate)} |
|
|
onChange={(newValue) => { |
|
|
onChange={(newValue) => { |
|
|
// console.log(newValue) |
|
|
|
|
|
if(newValue!=null){ |
|
|
|
|
|
setMinDate(newValue); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
setMinDate(newValue && newValue.isValid?.() ? newValue : null); |
|
|
}} |
|
|
}} |
|
|
/> |
|
|
/> |
|
|
</DemoItem > |
|
|
</DemoItem > |
|
|
@@ -236,22 +313,21 @@ const SearchPublicNoticeForm = ({ applySearch, searchCriteria, issueComboData, o |
|
|
<DemoItem components={['DatePicker']}> |
|
|
<DemoItem components={['DatePicker']}> |
|
|
<DatePicker |
|
|
<DatePicker |
|
|
id="dateTo" |
|
|
id="dateTo" |
|
|
// onError={(newError) => setReceiptFromError(newError)} |
|
|
|
|
|
|
|
|
onError={() => {}} |
|
|
slotProps={{ |
|
|
slotProps={{ |
|
|
field: { readOnly: true, }, |
|
|
|
|
|
// textField: { |
|
|
|
|
|
// helperText: receiptFromErrorMessage, |
|
|
|
|
|
// }, |
|
|
|
|
|
|
|
|
field: { readOnly: true, clearable: true }, |
|
|
|
|
|
textField: { |
|
|
|
|
|
InputLabelProps: { shrink: true }, |
|
|
|
|
|
error: false, |
|
|
|
|
|
helperText: null |
|
|
|
|
|
}, |
|
|
}} |
|
|
}} |
|
|
format="DD/MM/YYYY" |
|
|
format="DD/MM/YYYY" |
|
|
label={"Submit Date (To)"} |
|
|
label={"Submit Date (To)"} |
|
|
value={maxDate === null ? null : dayjs(maxDate)} |
|
|
|
|
|
minDate={minDate === null ? null : dayjs(minDate)} |
|
|
|
|
|
|
|
|
value={toDayjsOrNull(maxDate)} |
|
|
|
|
|
minDate={toDayjsOrNull(minDate)} |
|
|
onChange={(newValue) => { |
|
|
onChange={(newValue) => { |
|
|
// console.log(newValue) |
|
|
|
|
|
if(newValue!=null){ |
|
|
|
|
|
setMaxDate(newValue); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
setMaxDate(newValue && newValue.isValid?.() ? newValue : null); |
|
|
}} |
|
|
}} |
|
|
/> |
|
|
/> |
|
|
</DemoItem > |
|
|
</DemoItem > |
|
|
|