From 2c1a47d3c0a4f250fd98b63e357573bd5b5e1884 Mon Sep 17 00:00:00 2001 From: Anant Mittal Date: Tue, 28 Mar 2023 14:24:49 -0700 Subject: [PATCH] Activity Scheduling: Show error message if schedule time is before current time --- .../components/Forms/AddEditActivityForm.tsx | 18 +++++++++++++++++- web_patient/src/services/strings.ts | 2 ++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/web_patient/src/components/Forms/AddEditActivityForm.tsx b/web_patient/src/components/Forms/AddEditActivityForm.tsx index a5460a5c..59ec10d2 100644 --- a/web_patient/src/components/Forms/AddEditActivityForm.tsx +++ b/web_patient/src/components/Forms/AddEditActivityForm.tsx @@ -22,7 +22,7 @@ import { TextField, Typography, } from '@mui/material'; -import { isEqual } from 'date-fns'; +import { isEqual, isSameDay } from 'date-fns'; import { action, runInAction } from 'mobx'; import { observer, useLocalObservable } from 'mobx-react'; import React, { Fragment, FunctionComponent } from 'react'; @@ -755,6 +755,21 @@ export const AddEditActivityForm: FunctionComponent = }; } + // Check if activityScheduleViewState.displayedDate is today + const currentTime = new Date(); + if (isSameDay(activityScheduleViewState.displayedDate as Date, currentTime)) { + // If so, check if the time is in the past + const timeOfDayDate = new Date(2023, 0, 1, date.getHours(), date.getMinutes(), 0); + const currentTimeDate = new Date(2023, 0, 1, currentTime.getHours(), currentTime.getMinutes(), 0); + if (timeOfDayDate < currentTimeDate) { + return { + valid: false, + error: true, + errorMessage: getString('form_add_edit_activity_schedule_time_of_day_validation_in_past'), + }; + } + } + return { valid: true, error: false, @@ -1038,6 +1053,7 @@ export const AddEditActivityForm: FunctionComponent = activityScheduleViewState.hasRepetition, activityScheduleViewState.repeatDayFlags, ); + const activitySchedulePage = (