Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 43 additions & 2 deletions src/components/events/partials/ModalTabsAndPages/NewSourcePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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";
Expand Down Expand Up @@ -370,6 +370,23 @@ const Schedule = <T extends {
}) => {
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,
Expand Down Expand Up @@ -631,6 +648,17 @@ const Schedule = <T extends {
hourPlaceholder={"EVENTS.EVENTS.DETAILS.SOURCE.PLACEHOLDER.HOUR"}
minutePlaceholder={"EVENTS.EVENTS.DETAILS.SOURCE.PLACEHOLDER.MINUTE"}
callbackHour={(value: string) => {
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,
Expand All @@ -646,6 +674,19 @@ const Schedule = <T extends {
}
}}
callbackMinute={(value: string) => {

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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!",
Expand Down
4 changes: 2 additions & 2 deletions src/slices/eventSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" ||
Expand Down Expand Up @@ -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(
Expand Down