Skip to content

Commit

Permalink
Preventing future dates (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
cnesmithsalus authored Oct 27, 2023
1 parent b476098 commit 4ae2543
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 28 deletions.
18 changes: 9 additions & 9 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();
Expand Down Expand Up @@ -852,23 +852,23 @@ export const CreateComplaint: FC = () => {
const [longitude, setLongitude] = useState<string>("");

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) => {
Expand Down Expand Up @@ -1021,6 +1021,8 @@ export const CreateComplaint: FC = () => {
}
};

const maxDate = new Date();

return (
<div className="comp-complaint-details">
<ToastContainer />
Expand Down Expand Up @@ -1191,15 +1193,16 @@ export const CreateComplaint: FC = () => {
>
<label>Incident Time</label>
<DatePicker
showTimeInput
id="complaint-incident-time"
showIcon
timeInputLabel="Time:"
onChange={handleIncidentDateTimeChange}
selected={selectedIncidentDateTime}
showTimeInput
dateFormat="yyyy-MM-dd HH:mm"
timeFormat="HH:mm"
wrapperClassName="comp-details-edit-calendar-input"
maxDate={maxDate}
/>
</div>
{complaintType === COMPLAINT_TYPES.HWCR && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,8 @@ export const ComplaintDetailsEdit: FC = () => {
}
}

const maxDate = new Date();

return (
<div className="comp-complaint-details">
<ToastContainer />
Expand Down Expand Up @@ -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}
/>
</div>
{complaintType === COMPLAINT_TYPES.HWCR && (
Expand Down

0 comments on commit 4ae2543

Please sign in to comment.