Skip to content

Commit

Permalink
feat: Show schedule rules
Browse files Browse the repository at this point in the history
Show scheduling rules on child.
  • Loading branch information
LuukvH committed Sep 15, 2024
1 parent 06267fb commit 5a71738
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/web/src/features/schedules/ChildSchedule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,9 @@ import { AddChildScheduleDialog } from "./AddChildScheduleDialog";
import { useTranslation } from "react-i18next";
import dayjs from "dayjs";
import { useGetChildSchedules } from "@api/endpoints/schedules/schedules";
import { scheduleRulesFormatter } from "../../utils/scheduleRulesFormatter";

const columns: GridColDef[] = [
{
field: "name",
headerName: "Name",
flex: 1,
disableColumnMenu: true,
disableReorder: true,
},
{
field: "startDate",
headerName: "StartDate",
Expand All @@ -33,6 +27,14 @@ const columns: GridColDef[] = [
disableReorder: true,
valueFormatter: (value) => value && dayjs(value).format("DD/MM/YYYY"),
},
{
field: "scheduleRules",
headerName: "WeekSchedule",
flex: 1,
disableColumnMenu: true,
disableReorder: true,
valueFormatter: (value) => value && scheduleRulesFormatter(value),
},
];

type ChildScheduleProps = {
Expand Down
14 changes: 14 additions & 0 deletions src/web/src/utils/scheduleRulesFormatter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { type ChildScheduleListVMScheduleRule } from "@api/models/childScheduleListVMScheduleRule";
import dayjs from "dayjs";

export const scheduleRulesFormatter = (scheduleRules: ChildScheduleListVMScheduleRule[]): string => {

const monday = dayjs().startOf("week").add(1, "day"); // Ensure the week starts on Monday

return scheduleRules
.map((rule) => {
const dayName = monday.add(rule.day!, "day").format("dd"); // Get the localized day name
return `${dayName}: ${rule.timeSlotId}`;
})
.join("\n"); // Join all formatted rules into a single string with line breaks
};

0 comments on commit 5a71738

Please sign in to comment.