This commit is contained in:
2023-10-20 15:14:02 +05:00
parent 45e5b95dd9
commit 6f908a0da1
11 changed files with 125 additions and 10 deletions
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable react-hooks/exhaustive-deps */
/* eslint-disable no-irregular-whitespace */
import { ru } from "date-fns/locale";
@@ -13,24 +14,29 @@ import Input from "../Input";
import {
addMonths,
addWeeks,
areIntervalsOverlapping,
differenceInDays,
eachMinuteOfInterval,
endOfDay,
format,
parse,
parseISO,
startOfDay,
subDays,
} from "date-fns";
import api from "../../utils/api";
interface CreateScheduleProps {
companyId: string;
buildId: string;
schedules?: any[];
handleCreate: () => void;
}
function CreateSchedule({
companyId,
buildId,
schedules,
handleCreate,
}: CreateScheduleProps) {
const setModal = useModalStore((state) => state.setModal);
@@ -50,9 +56,12 @@ function CreateSchedule({
setStartDate(startOfDay(date));
setEndDate(
endOfDay(
scheduleDuration !== 3
? addWeeks(date, scheduleDuration)
: addMonths(date, 1)
subDays(
scheduleDuration !== 3
? addWeeks(date, scheduleDuration)
: addMonths(date, 1),
1
)
)
);
}, [date, scheduleDuration]);
@@ -102,6 +111,25 @@ function CreateSchedule({
}
async function handleClickCreateSchedule() {
if (!startDate || !endDate) return;
if (
schedules?.some((schedule) =>
areIntervalsOverlapping(
{ start: startDate, end: endDate },
{
start: parseISO(schedule.startDate),
end: parseISO(schedule.endDate),
}
)
)
) {
alert(
"Данные даты пересекаются с другим расписанием! Выберите другие даты."
);
return;
}
await createSchedule();
handleCreate();
setModal(null);
+1
View File
@@ -512,6 +512,7 @@ function DashboardPage() {
<CreateSchedule
companyId={company?.id}
buildId={selectedBuild?.id}
schedules={schedules}
handleCreate={getSchedules}
/>
)