Use a pinia store to manage account state
Refactor the existing scattered code dealing with the account state into a pinia store.
This commit is contained in:
parent
fae8b4e2e4
commit
e722876aae
12 changed files with 126 additions and 98 deletions
|
@ -394,12 +394,8 @@ function removeSlot(eventChanges: ChangeRecord<Shift>[], shift: Shift, shiftSlot
|
|||
return eventChanges;
|
||||
}
|
||||
|
||||
const sessionStore = useSessionStore();
|
||||
const accountStore = useAccountStore();
|
||||
const schedule = await useSchedule();
|
||||
const runtimeConfig = useRuntimeConfig();
|
||||
const timezone = computed(
|
||||
() => sessionStore.account?.timezone ?? runtimeConfig.public.defaultTimezone
|
||||
);
|
||||
|
||||
type ShiftSlotChange = { op: "set" | "del", data: ShiftSlot } ;
|
||||
|
||||
|
@ -436,12 +432,12 @@ const newShiftStart = ref("");
|
|||
const newShiftDuration = ref("01:00");
|
||||
const newShiftEnd = computed({
|
||||
get: () => (
|
||||
DateTime.fromISO(newShiftStart.value, { zone: timezone.value })
|
||||
DateTime.fromISO(newShiftStart.value, { zone: accountStore.activeTimezone })
|
||||
.plus(Duration.fromISOTime(newShiftDuration.value))
|
||||
.toFormat("HH:mm")
|
||||
),
|
||||
set: (value: string) => {
|
||||
const start = DateTime.fromISO(newShiftStart.value, { zone: timezone.value });
|
||||
const start = DateTime.fromISO(newShiftStart.value, { zone: accountStore.activeTimezone });
|
||||
const end = endFromTime(start, value);
|
||||
newShiftDuration.value = dropDay(end.diff(start)).toFormat("hh:mm");
|
||||
},
|
||||
|
@ -478,7 +474,7 @@ function editShiftSlot(
|
|||
}
|
||||
) {
|
||||
if (edits.start) {
|
||||
const start = DateTime.fromISO(edits.start, { zone: timezone.value });
|
||||
const start = DateTime.fromISO(edits.start, { zone: accountStore.activeTimezone });
|
||||
shiftSlot = {
|
||||
...shiftSlot,
|
||||
start,
|
||||
|
@ -558,7 +554,7 @@ function newShiftSlot(options: { start?: DateTime, end?: DateTime } = {}) {
|
|||
end = options.end;
|
||||
start = options.end.minus(duration);
|
||||
} else {
|
||||
start = DateTime.fromISO(newShiftStart.value, { zone: timezone.value });
|
||||
start = DateTime.fromISO(newShiftStart.value, { zone: accountStore.activeTimezone });
|
||||
end = endFromTime(start, newShiftEnd.value);
|
||||
}
|
||||
if (!start.isValid || !end.isValid) {
|
||||
|
@ -621,8 +617,8 @@ const shiftSlots = computed(() => {
|
|||
role: shift.role,
|
||||
assigned: slot.assigned ?? [],
|
||||
origRole: shift.role,
|
||||
start: DateTime.fromISO(slot.start, { zone: timezone.value }),
|
||||
end: DateTime.fromISO(slot.end, { zone: timezone.value }),
|
||||
start: DateTime.fromISO(slot.start, { zone: accountStore.activeTimezone }),
|
||||
end: DateTime.fromISO(slot.end, { zone: accountStore.activeTimezone }),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue