-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathsomeday.draft.util.ts
More file actions
39 lines (35 loc) · 1.35 KB
/
someday.draft.util.ts
File metadata and controls
39 lines (35 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { Dayjs } from "dayjs";
import { Dispatch } from "redux";
import { YEAR_MONTH_DAY_FORMAT } from "@core/constants/date.constants";
import { Categories_Event } from "@core/types/event.types";
import { draftSlice } from "@web/ducks/events/slices/draft.slice";
import { Activity_DraftEvent } from "@web/ducks/events/slices/draft.slice.types";
import { assembleDefaultEvent } from "../event.util";
export const createSomedayDraft = async (
category: Categories_Event.SOMEDAY_WEEK | Categories_Event.SOMEDAY_MONTH,
startOfView: Dayjs,
endOfView: Dayjs,
activity: Activity_DraftEvent,
dispatch: Dispatch,
) => {
let startDate: string;
let endDate: string;
if (category === Categories_Event.SOMEDAY_WEEK) {
startDate = startOfView.format(YEAR_MONTH_DAY_FORMAT);
endDate = endOfView.format(YEAR_MONTH_DAY_FORMAT);
} else {
// Someday month
startDate = startOfView.startOf("month").format(YEAR_MONTH_DAY_FORMAT);
// `endDate` is the last day of the month, hence why we need to use `startOfView`, because
// `endOfView` could be in the next month relative to `startOfView`
endDate = startOfView.endOf("month").format(YEAR_MONTH_DAY_FORMAT);
}
const event = await assembleDefaultEvent(category, startDate, endDate);
dispatch(
draftSlice.actions.start({
activity,
eventType: category,
event,
}),
);
};