diff --git a/src/components/events/partials/ModalTabsAndPages/NewSourcePage.tsx b/src/components/events/partials/ModalTabsAndPages/NewSourcePage.tsx index 2bfedc4ae3..c588b522b3 100644 --- a/src/components/events/partials/ModalTabsAndPages/NewSourcePage.tsx +++ b/src/components/events/partials/ModalTabsAndPages/NewSourcePage.tsx @@ -12,7 +12,7 @@ import { Field } from "../../../shared/Field"; import RenderField from "../../../shared/wizard/RenderField"; import { getRecordings } from "../../../../selectors/recordingSelectors"; import { sourceMetadata } from "../../../../configs/sourceConfig"; -import { weekdays } from "../../../../configs/modalConfig"; +import { weekdays, NOTIFICATION_CONTEXT } from "../../../../configs/modalConfig"; import { getUserInformation } from "../../../../selectors/userInfoSelectors"; import { filterDevicesForAccess, @@ -37,7 +37,7 @@ import { } from "../../../../utils/dateUtils"; import { useAppDispatch, useAppSelector } from "../../../../store"; import { Recording, fetchRecordings } from "../../../../slices/recordingSlice"; -import { removeNotificationWizardForm } from "../../../../slices/notificationSlice"; +import { addNotification, removeNotificationWizardForm } from "../../../../slices/notificationSlice"; import { parseISO } from "date-fns"; import WizardNavigationButtons from "../../../shared/wizard/WizardNavigationButtons"; import { checkConflicts, UploadAssetsTrack } from "../../../../slices/eventSlice"; @@ -370,6 +370,23 @@ const Schedule = { const { t } = useTranslation(); const currentLanguage = getCurrentLanguageInformation(); + const dispatch = useAppDispatch(); + + // Parse start-Date strings + const startDateTime = new Date( + `${new Date(formik.values.scheduleStartDate).toISOString().split("T")[0]}T${formik.values.scheduleStartHour}:${formik.values.scheduleStartMinute}:00`, + ); + + // Parse end datetime + const endDateTime = new Date( + `${new Date(formik.values.scheduleEndDate).toISOString().split("T")[0]}T${formik.values.scheduleEndHour}:${formik.values.scheduleEndMinute}:00`, + ); + + const now = new Date(); + + // Event is in progress + const eventInProgress = now >= startDateTime && now <= endDateTime; + const getEndDateForSchedulingTime = () => { const { scheduleStartDate, @@ -631,6 +648,17 @@ const Schedule = { + if (eventInProgress && value < formik.values.scheduleEndHour) { + dispatch( + addNotification({ + type: "error", + key: "CONFLICT_END_TIME_TOO_EARLY", + duration: -1, + context: NOTIFICATION_CONTEXT, + }), + ); + return; // Block shortening + } if (formik.values.sourceMode === "SCHEDULE_MULTIPLE") { changeEndHourMultiple( value, @@ -646,6 +674,19 @@ const Schedule = { + + if (eventInProgress && value < formik.values.scheduleEndMinute) { + dispatch( + addNotification({ + type: "error", + key: "CONFLICT_END_TIME_TOO_EARLY", + duration: -1, + context: NOTIFICATION_CONTEXT, + }), + ); + return; // Block shortening + } + if (formik.values.sourceMode === "SCHEDULE_MULTIPLE") { changeEndMinuteMultiple( value, diff --git a/src/i18n/org/opencastproject/adminui/languages/lang-en_US.json b/src/i18n/org/opencastproject/adminui/languages/lang-en_US.json index 4b2843ff91..03f650c94b 100644 --- a/src/i18n/org/opencastproject/adminui/languages/lang-en_US.json +++ b/src/i18n/org/opencastproject/adminui/languages/lang-en_US.json @@ -211,6 +211,7 @@ "CONFLICT_ALREADY_ENDED": "Scheduling error: The event has already ended.", "CONFLICT_END_BEFORE_START": "Scheduling error: Schedule end has to be later than the start.", "CONFLICT_IN_THE_PAST": "The schedule could not be updated: You cannot schedule an event to be in the past.", + "CONFLICT_END_TIME_TOO_EARLY": "This event cannot be modified because it is currently in progress.", "CONFLICT_RANGE_DAYS":"At least one repeat day must be within the scheduled date range.", "INVALID_ACL_RULES": "Rules have to contain a valid role and read or/and write right(s).", "MISSING_ACL_RULES": "At least one role with Read and Write permissions is required!", diff --git a/src/slices/eventSlice.ts b/src/slices/eventSlice.ts index baa4a318bc..4196dffff3 100644 --- a/src/slices/eventSlice.ts +++ b/src/slices/eventSlice.ts @@ -904,7 +904,6 @@ export const checkConflicts = (values: { sourceMode: string, }) => async (dispatch: AppDispatch) => { let check = true; - // Only perform checks if source mode is SCHEDULE_SINGLE or SCHEDULE_MULTIPLE if ( values.sourceMode === "SCHEDULE_SINGLE" || @@ -936,7 +935,8 @@ export const checkConflicts = (values: { 0, 0, ); - + const today = new Date(); + today.setHours(0, 0, 0, 0); // If start date of event is smaller than today --> Event is in past if ((values.sourceMode === "SCHEDULE_SINGLE" && startDate < new Date()) || (values.sourceMode === "SCHEDULE_MULTIPLE" && startDate < new Date())) { dispatch(