Skip to content

Commit 43871b6

Browse files
Merge pull request #1411 from EnsiyehE/fix/scheduling-event-in-progress-error
Fix that scheduling an event currently in progress gives you the wrong error message
2 parents 8dd3b79 + f06f49d commit 43871b6

3 files changed

Lines changed: 46 additions & 4 deletions

File tree

src/components/events/partials/ModalTabsAndPages/NewSourcePage.tsx

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { Field } from "../../../shared/Field";
1212
import RenderField from "../../../shared/wizard/RenderField";
1313
import { getRecordings } from "../../../../selectors/recordingSelectors";
1414
import { sourceMetadata } from "../../../../configs/sourceConfig";
15-
import { weekdays } from "../../../../configs/modalConfig";
15+
import { weekdays, NOTIFICATION_CONTEXT } from "../../../../configs/modalConfig";
1616
import { getUserInformation } from "../../../../selectors/userInfoSelectors";
1717
import {
1818
filterDevicesForAccess,
@@ -37,7 +37,7 @@ import {
3737
} from "../../../../utils/dateUtils";
3838
import { useAppDispatch, useAppSelector } from "../../../../store";
3939
import { Recording, fetchRecordings } from "../../../../slices/recordingSlice";
40-
import { removeNotificationWizardForm } from "../../../../slices/notificationSlice";
40+
import { addNotification, removeNotificationWizardForm } from "../../../../slices/notificationSlice";
4141
import { parseISO } from "date-fns";
4242
import WizardNavigationButtons from "../../../shared/wizard/WizardNavigationButtons";
4343
import { checkConflicts, UploadAssetsTrack } from "../../../../slices/eventSlice";
@@ -370,6 +370,23 @@ const Schedule = <T extends {
370370
}) => {
371371
const { t } = useTranslation();
372372
const currentLanguage = getCurrentLanguageInformation();
373+
const dispatch = useAppDispatch();
374+
375+
// Parse start-Date strings
376+
const startDateTime = new Date(
377+
`${new Date(formik.values.scheduleStartDate).toISOString().split("T")[0]}T${formik.values.scheduleStartHour}:${formik.values.scheduleStartMinute}:00`,
378+
);
379+
380+
// Parse end datetime
381+
const endDateTime = new Date(
382+
`${new Date(formik.values.scheduleEndDate).toISOString().split("T")[0]}T${formik.values.scheduleEndHour}:${formik.values.scheduleEndMinute}:00`,
383+
);
384+
385+
const now = new Date();
386+
387+
// Event is in progress
388+
const eventInProgress = now >= startDateTime && now <= endDateTime;
389+
373390
const getEndDateForSchedulingTime = () => {
374391
const {
375392
scheduleStartDate,
@@ -631,6 +648,17 @@ const Schedule = <T extends {
631648
hourPlaceholder={"EVENTS.EVENTS.DETAILS.SOURCE.PLACEHOLDER.HOUR"}
632649
minutePlaceholder={"EVENTS.EVENTS.DETAILS.SOURCE.PLACEHOLDER.MINUTE"}
633650
callbackHour={(value: string) => {
651+
if (eventInProgress && value < formik.values.scheduleEndHour) {
652+
dispatch(
653+
addNotification({
654+
type: "error",
655+
key: "CONFLICT_END_TIME_TOO_EARLY",
656+
duration: -1,
657+
context: NOTIFICATION_CONTEXT,
658+
}),
659+
);
660+
return; // Block shortening
661+
}
634662
if (formik.values.sourceMode === "SCHEDULE_MULTIPLE") {
635663
changeEndHourMultiple(
636664
value,
@@ -646,6 +674,19 @@ const Schedule = <T extends {
646674
}
647675
}}
648676
callbackMinute={(value: string) => {
677+
678+
if (eventInProgress && value < formik.values.scheduleEndMinute) {
679+
dispatch(
680+
addNotification({
681+
type: "error",
682+
key: "CONFLICT_END_TIME_TOO_EARLY",
683+
duration: -1,
684+
context: NOTIFICATION_CONTEXT,
685+
}),
686+
);
687+
return; // Block shortening
688+
}
689+
649690
if (formik.values.sourceMode === "SCHEDULE_MULTIPLE") {
650691
changeEndMinuteMultiple(
651692
value,

src/i18n/org/opencastproject/adminui/languages/lang-en_US.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@
211211
"CONFLICT_ALREADY_ENDED": "Scheduling error: The event has already ended.",
212212
"CONFLICT_END_BEFORE_START": "Scheduling error: Schedule end has to be later than the start.",
213213
"CONFLICT_IN_THE_PAST": "The schedule could not be updated: You cannot schedule an event to be in the past.",
214+
"CONFLICT_END_TIME_TOO_EARLY": "This event cannot be modified because it is currently in progress.",
214215
"CONFLICT_RANGE_DAYS":"At least one repeat day must be within the scheduled date range.",
215216
"INVALID_ACL_RULES": "Rules have to contain a valid role and read or/and write right(s).",
216217
"MISSING_ACL_RULES": "At least one role with Read and Write permissions is required!",

src/slices/eventSlice.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,6 @@ export const checkConflicts = (values: {
906906
sourceMode: string,
907907
}) => async (dispatch: AppDispatch) => {
908908
let check = true;
909-
910909
// Only perform checks if source mode is SCHEDULE_SINGLE or SCHEDULE_MULTIPLE
911910
if (
912911
values.sourceMode === "SCHEDULE_SINGLE" ||
@@ -938,7 +937,8 @@ export const checkConflicts = (values: {
938937
0,
939938
0,
940939
);
941-
940+
const today = new Date();
941+
today.setHours(0, 0, 0, 0);
942942
// If start date of event is smaller than today --> Event is in past
943943
if ((values.sourceMode === "SCHEDULE_SINGLE" && startDate < new Date()) || (values.sourceMode === "SCHEDULE_MULTIPLE" && startDate < new Date())) {
944944
dispatch(

0 commit comments

Comments
 (0)