Skip to content

Commit a41b10b

Browse files
authored
Merge pull request #372 from openscript-ch/324-problems-with-adjusting-caregiver-settings-at-the-end-of-the-day-2
324 problems with adjusting caregiver settings at the end of the day 2
2 parents e200f7f + 326632f commit a41b10b

File tree

7 files changed

+32
-12
lines changed

7 files changed

+32
-12
lines changed

.changeset/fuzzy-hounds-create.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@quassel/frontend": patch
3+
"@quassel/backend": patch
4+
"@quassel/utils": patch
5+
"@quassel/ui": patch
6+
---
7+
8+
Improve calendering

apps/backend/project.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@
1313
}
1414
]
1515
}
16-
}
16+
},
17+
"implicitDependencies": ["@quassel/utils"]
1718
}

apps/backend/src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ async function bootstrap() {
1313
app.enableCors({
1414
credentials: true,
1515
origin: configService.get("cors.origin"),
16-
methods: ["GET", "POST", "PUT", "DELETE"],
16+
methods: ["GET", "POST", "PUT", "PATCH", "DELETE"],
1717
exposedHeaders: ["Content-Disposition"],
1818
});
1919
app.enableShutdownHooks();

apps/frontend/src/components/questionnaire/calendar/EntryCalendar.tsx

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import interactionPlugin from "@fullcalendar/interaction";
33
import timeGridPlugin from "@fullcalendar/timegrid";
44
import { DateSelectArg, EventChangeArg, EventInput } from "@fullcalendar/core";
55
import { Button, Modal, useDisclosure, useMantineTheme } from "@quassel/ui";
6-
import { GapsPerDay, getDateFromTimeAndWeekday, getTime, groupByWeekday, isSame } from "@quassel/utils";
6+
import { GapsPerDay, getDateFromTimeAndWeekday, getNext, getTime, groupByWeekday, isSame } from "@quassel/utils";
77
import { QuestionnaireEntry } from "./QuestionnaireEntry";
88
import { components } from "../../../api.gen";
99
import { EntityForm, EntryFormValues } from "./EntryForm";
@@ -22,10 +22,13 @@ const calendarBaseConfig: FullCalendar["props"] = {
2222
slotMaxTime: C.calendar.maxTime,
2323
slotDuration: { hour: 1 },
2424
firstDay: 1,
25-
locale: "de",
25+
locale: "en-GB",
2626
expandRows: true,
2727
editable: true,
28-
selectAllow: ({ start, end }) => isSame("day", start, end),
28+
selectAllow: ({ start, end }) => {
29+
end.setTime(end.getTime() - 1000);
30+
return isSame("day", start, end);
31+
},
2932
selectable: true,
3033
selectLongPressDelay: 200,
3134
eventLongPressDelay: 400,
@@ -116,7 +119,7 @@ export function EntryCalendar({
116119
},
117120
{
118121
start: getDateFromTimeAndWeekday(maxEnd, index),
119-
end: getDateFromTimeAndWeekday("23:00:00", index),
122+
end: getDateFromTimeAndWeekday("23:59:59", index),
120123
backgroundColor: theme.colors.uzhBlue[9],
121124
className: styles.eventSleepIndicator,
122125
display: "background",
@@ -143,15 +146,21 @@ export function EntryCalendar({
143146
};
144147

145148
const setupEntryCreate = ({ start, end }: DateSelectArg | EventImpl) => {
146-
setEntryDraft({ startedAt: getTime(start!), endedAt: getTime(end!), weekday: start!.getDay() });
149+
if (!start || !end) return;
150+
if (end.getHours() === 0 && end.getMinutes() === 0) end.setTime(end.getTime() - 1000);
151+
152+
setEntryDraft({ startedAt: getTime(start), endedAt: getTime(end), weekday: start!.getDay() });
147153
setEntryUpdadingId(undefined);
148154
open();
149155
};
150156

151-
const handleEventChange = ({ event }: EventChangeArg) => {
152-
const { id, start, end } = event;
157+
const handleEventChange = ({ event: { id, start, end } }: EventChangeArg) => {
153158
if (!start || !end) return;
154159

160+
if (end.getMinutes() === 59 && end.getHours() < 23) {
161+
end = getNext("hour", end);
162+
}
163+
155164
const startTime = getTime(start) < C.calendar.minTime ? C.calendar.minTime : getTime(start);
156165
const endTime = isSame("day", start, end) ? getTime(end) : C.calendar.maxTime;
157166

apps/frontend/src/configuration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ export const C = {
1414
},
1515
calendar: {
1616
minTime: "05:00",
17-
maxTime: "23:00",
17+
maxTime: "23:59",
1818
},
1919
};

libs/utils/src/date.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import dayjs from "dayjs";
22
import utc from "dayjs/plugin/utc";
33
import customParseFormat from "dayjs/plugin/customParseFormat";
4+
import isoWeek from "dayjs/plugin/isoWeek";
45

56
dayjs.extend(utc);
67
dayjs.extend(customParseFormat);
8+
dayjs.extend(isoWeek);
79

810
export function formatDate(date: Date, dayjsFormatTemplate: string) {
911
return dayjs(date).format(dayjsFormatTemplate);
@@ -20,7 +22,6 @@ export const isSameOrAfter = (left: Date, right: Date, unit: dayjs.ManipulateTyp
2022

2123
export function getDateFromTimeAndWeekday(time: string, weekday: number) {
2224
return dayjs(time, "HH:mm:ss")
23-
.set("day", weekday)
24-
.add(weekday === 0 ? 1 : 0, "week")
25+
.isoWeekday(weekday === 0 ? 7 : weekday)
2526
.toDate();
2627
}

libs/utils/vite.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export default defineConfig({
1515
dayjs: "dayjs",
1616
"dayjs/plugin/utc.js": "dayjsPluginUtc",
1717
"dayjs/plugin/customParseFormat.js": "dayjsPluginCustomParseFormat",
18+
"dayjs/plugin/isoWeek.js": "dayjsPluginIsoWeek",
1819
},
1920
},
2021
},

0 commit comments

Comments
 (0)