From 4ae2543f67d0c9e0e6932b54886171969d9b018a Mon Sep 17 00:00:00 2001 From: cnesmithsalus <69365683+cnesmithsalus@users.noreply.github.com> Date: Fri, 27 Oct 2023 10:55:30 -0700 Subject: [PATCH] Preventing future dates (#178) --- frontend/package-lock.json | 18 ++++---- .../details/complaint-details-create.tsx | 41 ++++++++++--------- .../details/complaint-details-edit.tsx | 3 ++ 3 files changed, 34 insertions(+), 28 deletions(-) diff --git a/frontend/package-lock.json b/frontend/package-lock.json index ac0effbde..2b0786b8b 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -3740,9 +3740,9 @@ } }, "node_modules/@popperjs/core": { - "version": "2.11.7", - "resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.7.tgz", - "integrity": "sha512-Cr4OjIkipTtcXKjAsm8agyleBuDHvxzeBoa1v543lbv1YaIwQjESsVcmjiWiPEbC1FIeHOG/Op9kdCmAmiS3Kw==", + "version": "2.11.8", + "resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.8.tgz", + "integrity": "sha512-P1st0aksCrn9sGZhp8GMYwBnQsbvAWsZAX44oXNNvLHGqAOcoVxmjZiohstwQ7SqKnbR47akdNi+uleWD8+g6A==", "funding": { "type": "opencollective", "url": "https://opencollective.com/popperjs" @@ -19935,15 +19935,15 @@ } }, "node_modules/react-datepicker": { - "version": "4.14.0", - "resolved": "https://registry.npmjs.org/react-datepicker/-/react-datepicker-4.14.0.tgz", - "integrity": "sha512-MLky2SF8hVTPgFRseauoOprjz6/rUMWq8MHadWYwExJvojUyCZOWDMWq9bRqoliQqqPhcViYjyxAxvFQpD9aDA==", + "version": "4.21.0", + "resolved": "https://registry.npmjs.org/react-datepicker/-/react-datepicker-4.21.0.tgz", + "integrity": "sha512-z0DtuRrKMz9i7dcTusW29VacbM9pn08g1yw0cG+Y5GpodJDxSWv7zUMxl3IwKN9Ap/AMphiepvmT5P+iNCgEiA==", "dependencies": { - "@popperjs/core": "^2.9.2", + "@popperjs/core": "^2.11.8", "classnames": "^2.2.6", - "date-fns": "^2.24.0", + "date-fns": "^2.30.0", "prop-types": "^15.7.2", - "react-onclickoutside": "^6.12.2", + "react-onclickoutside": "^6.13.0", "react-popper": "^2.3.0" }, "peerDependencies": { diff --git a/frontend/src/app/components/containers/complaints/details/complaint-details-create.tsx b/frontend/src/app/components/containers/complaints/details/complaint-details-create.tsx index e4f6ea1a9..23f1d9d58 100644 --- a/frontend/src/app/components/containers/complaints/details/complaint-details-create.tsx +++ b/frontend/src/app/components/containers/complaints/details/complaint-details-create.tsx @@ -33,7 +33,6 @@ import { selectOfficers } from "../../../../store/reducers/officer"; import { CreateComplaintHeader } from "./create-complaint-header"; import { Button } from "react-bootstrap"; import { CancelConfirm } from "../../../../types/modal/modal-types"; -import { useNavigate } from "react-router-dom"; import { createAllegationComplaint, createWildlifeComplaint, @@ -45,6 +44,7 @@ import { Complaint } from "../../../../types/complaints/complaint"; import { ToggleError } from "../../../../common/toast"; import { ToastContainer } from "react-toastify"; import "react-toastify/dist/ReactToastify.css"; +import { useNavigate } from "react-router-dom"; export const CreateComplaint: FC = () => { const dispatch = useAppDispatch(); @@ -852,23 +852,23 @@ export const CreateComplaint: FC = () => { const [longitude, setLongitude] = useState(""); function handleIncidentDateTimeChange(date: Date) { - setSelectedIncidentDateTime(date); - - if (complaintType === COMPLAINT_TYPES.HWCR) { - let hwcrComplaint: HwcrComplaint = cloneDeep( - createComplaint, - ) as HwcrComplaint; - hwcrComplaint.complaint_identifier.incident_utc_datetime = - date; - setCreateComplaint(hwcrComplaint); - } else if (complaintType === COMPLAINT_TYPES.ERS) { - let allegationComplaint: AllegationComplaint = cloneDeep( - createComplaint, - ) as AllegationComplaint; - allegationComplaint.complaint_identifier.incident_utc_datetime = - date; - setCreateComplaint(allegationComplaint); - } + setSelectedIncidentDateTime(date); + + if (complaintType === COMPLAINT_TYPES.HWCR) { + let hwcrComplaint: HwcrComplaint = cloneDeep( + createComplaint, + ) as HwcrComplaint; + hwcrComplaint.complaint_identifier.incident_utc_datetime = + date; + setCreateComplaint(hwcrComplaint); + } else if (complaintType === COMPLAINT_TYPES.ERS) { + let allegationComplaint: AllegationComplaint = cloneDeep( + createComplaint, + ) as AllegationComplaint; + allegationComplaint.complaint_identifier.incident_utc_datetime = + date; + setCreateComplaint(allegationComplaint); + } } const handleCoordinateChange = (input: string, type: Coordinates) => { @@ -1021,6 +1021,8 @@ export const CreateComplaint: FC = () => { } }; + const maxDate = new Date(); + return (
@@ -1191,15 +1193,16 @@ export const CreateComplaint: FC = () => { >
{complaintType === COMPLAINT_TYPES.HWCR && ( diff --git a/frontend/src/app/components/containers/complaints/details/complaint-details-edit.tsx b/frontend/src/app/components/containers/complaints/details/complaint-details-edit.tsx index cffa55ef4..8b3e558f2 100644 --- a/frontend/src/app/components/containers/complaints/details/complaint-details-edit.tsx +++ b/frontend/src/app/components/containers/complaints/details/complaint-details-edit.tsx @@ -997,6 +997,8 @@ export const ComplaintDetailsEdit: FC = () => { } } + const maxDate = new Date(); + return (
@@ -1198,6 +1200,7 @@ export const ComplaintDetailsEdit: FC = () => { dateFormat="yyyy-MM-dd HH:mm" timeFormat="HH:mm" wrapperClassName="comp-details-edit-calendar-input" + maxDate={maxDate} />
{complaintType === COMPLAINT_TYPES.HWCR && (