diff --git a/components/EventCard.vue b/components/EventCard.vue
index d3eaaef..6f0b33f 100644
--- a/components/EventCard.vue
+++ b/components/EventCard.vue
@@ -5,13 +5,13 @@
{{ event.interested }} interested
-
+
@@ -20,13 +20,13 @@
{{ formatTime(slot.start) }} - {{ formatTime(slot.end) }}
({{ slot.interested }} interested)
@@ -48,33 +48,16 @@ defineProps<{
event: ScheduleEvent
}>()
-const runtimeConfig = useRuntimeConfig();
-const sessionStore = useSessionStore();
-const interestedIds = computed(() => new Set(sessionStore.account?.interestedIds ?? []));
-const timezone = computed(() => sessionStore.account?.timezone ?? runtimeConfig.public.defaultTimezone);
+const accountStore = useAccountStore();
const { data: accounts } = await useAccounts();
const idToAccount = computed(() => new Map(accounts.value?.map(a => [a.id, a])));
function formatTime(time: string) {
- return DateTime.fromISO(time, { zone: timezone.value }).toFormat("yyyy-LL-dd HH:mm");
+ return DateTime.fromISO(time, { zone: accountStore.activeTimezone }).toFormat("yyyy-LL-dd HH:mm");
}
async function toggle(id: string, slotIds?: string[]) {
- let newIds = [...sessionStore.account!.interestedIds ?? []];
- if (interestedIds.value.has(id)) {
- newIds = newIds.filter(newId => newId !== id);
- } else {
- newIds.push(id);
- if (slotIds) {
- const filterIds = new Set(slotIds);
- newIds = newIds.filter(newId => !filterIds.has(newId));
- }
- }
- await $fetch("/api/account", {
- method: "PATCH",
- body: { interestedIds: newIds },
- })
- await sessionStore.fetch();
+ await accountStore.toggleInterestedId(id, slotIds);
}
diff --git a/components/EventsTable.vue b/components/EventsTable.vue
index 111f225..ec66827 100644
--- a/components/EventsTable.vue
+++ b/components/EventsTable.vue
@@ -38,7 +38,7 @@
|
@@ -135,11 +135,10 @@ defineProps<{
}>();
const schedule = await useSchedule();
-const sessionStore = useSessionStore();
-const canEditPublic = computed(() => sessionStore.account?.type === "admin");
+const accountStore = useAccountStore();
function canEdit(event: ScheduleEvent) {
- return event.crew || canEditPublic.value;
+ return event.crew || accountStore.canEditPublic;
}
const changes = ref[]>([]);
diff --git a/components/Header.vue b/components/Header.vue
index aaf6ae2..0833aec 100644
--- a/components/Header.vue
+++ b/components/Header.vue
@@ -8,18 +8,18 @@
Schedule
-
+
Edit
-
- {{ sessionStore.account.name }}
- (s:{{ sessionStore.id }} a:{{ sessionStore.account.id }}{{ sessionStore.push ? " push" : null }})
- {{ sessionStore.account.type }}
+
+ {{ accountStore.name }}
+ (s:{{ sessionStore.id }} a:{{ accountStore.id }}{{ sessionStore.push ? " push" : null }})
+ {{ accountStore.type }}
Settings
-
+
Log In
@@ -29,6 +29,7 @@
diff --git a/components/ScheduleTable.vue b/components/ScheduleTable.vue
index 284377a..a0f6600 100644
--- a/components/ScheduleTable.vue
+++ b/components/ScheduleTable.vue
@@ -424,12 +424,8 @@ function removeSlot(eventChanges: ChangeRecord[], event: Schedule
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 EventSlotChange = { op: "set" | "del", data: EventSlot } ;
@@ -466,12 +462,12 @@ const newEventStart = ref("");
const newEventDuration = ref("01:00");
const newEventEnd = computed({
get: () => (
- DateTime.fromISO(newEventStart.value, { zone: timezone.value })
+ DateTime.fromISO(newEventStart.value, { zone: accountStore.activeTimezone })
.plus(Duration.fromISOTime(newEventDuration.value))
.toFormat("HH:mm")
),
set: (value: string) => {
- const start = DateTime.fromISO(newEventStart.value, { zone: timezone.value });
+ const start = DateTime.fromISO(newEventStart.value, { zone: accountStore.activeTimezone });
const end = endFromTime(start, value);
newEventDuration.value = dropDay(end.diff(start)).toFormat("hh:mm");
},
@@ -508,7 +504,7 @@ function editEventSlot(
}
) {
if (edits.start) {
- const start = DateTime.fromISO(edits.start, { zone: timezone.value });
+ const start = DateTime.fromISO(edits.start, { zone: accountStore.activeTimezone });
eventSlot = {
...eventSlot,
start,
@@ -577,7 +573,7 @@ function newEventSlot(options: { start?: DateTime, end?: DateTime } = {}) {
end = options.end;
start = options.end.minus(duration);
} else {
- start = DateTime.fromISO(newEventStart.value, { zone: timezone.value });
+ start = DateTime.fromISO(newEventStart.value, { zone: accountStore.activeTimezone });
end = endFromTime(start, newEventEnd.value);
}
if (!start.isValid || !end.isValid) {
@@ -641,8 +637,8 @@ const eventSlots = computed(() => {
location,
assigned: slot.assigned ?? [],
origLocation: location,
- 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 }),
});
}
}
diff --git a/components/ShiftScheduleTable.vue b/components/ShiftScheduleTable.vue
index 27e0919..085efc9 100644
--- a/components/ShiftScheduleTable.vue
+++ b/components/ShiftScheduleTable.vue
@@ -394,12 +394,8 @@ function removeSlot(eventChanges: ChangeRecord[], 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 }),
});
}
}
diff --git a/components/Timetable.vue b/components/Timetable.vue
index e0853b8..193b509 100644
--- a/components/Timetable.vue
+++ b/components/Timetable.vue
@@ -503,16 +503,14 @@ const stretches = computed(() => [
)
])
-const runtimeConfig = useRuntimeConfig();
-const sessionStore = useSessionStore();
-const debugTimezone = ref();
+const accountStore = useAccountStore();
const timezone = computed({
- get: () => debugTimezone.value ?? sessionStore.account?.timezone ?? runtimeConfig.public.defaultTimezone,
- set: (value: string) => { debugTimezone.value = value },
+ get: () => accountStore.activeTimezone,
+ set: (value: string) => { accountStore.timezone = value },
});
const elements = computed(() => tableElementsFromStretches(
- stretches.value, schedule.value.events, schedule.value.locations, schedule.value.rota, schedule.value.roles, timezone.value
+ stretches.value, schedule.value.events, schedule.value.locations, schedule.value.rota, schedule.value.roles, accountStore.activeTimezone
));
const totalColumns = computed(() => elements.value.totalColumns);
const columnGroups = computed(() => elements.value.columnGroups);
diff --git a/middleware/authenticated.ts b/middleware/authenticated.ts
index 95ddb0a..7acad5d 100644
--- a/middleware/authenticated.ts
+++ b/middleware/authenticated.ts
@@ -1,14 +1,14 @@
export default defineNuxtRouteMiddleware(async (to, from) => {
- const sessionStore = useSessionStore();
+ const accountStore = useAccountStore();
- if (!sessionStore.account) {
+ if (!accountStore.valid) {
console.log("Not logged in, redirecting to /login");
return navigateTo("/login");
}
if (
to.meta.allowedAccountTypes
- && !to.meta.allowedAccountTypes.includes(sessionStore.account.type)
+ && !to.meta.allowedAccountTypes.includes(accountStore.type!)
) {
throw createError({
status: 403,
diff --git a/pages/account/settings.vue b/pages/account/settings.vue
index 8274b59..1a560e2 100644
--- a/pages/account/settings.vue
+++ b/pages/account/settings.vue
@@ -1,14 +1,14 @@
Account Settings
-
- Name: {{ sessionStore.account?.name }}
+
+ Name: {{ accountStore.name }}
- Access: {{ sessionStore.account?.type }}
+ Access: {{ accountStore.type }}
diff --git a/pages/schedule.vue b/pages/schedule.vue
index 17bbfc9..9ae73fc 100644
--- a/pages/schedule.vue
+++ b/pages/schedule.vue
@@ -4,7 +4,7 @@
Study carefully, we only hold these events once a year.
-
+
Login or Create an account
to get notified about updates to the schedule.
@@ -12,7 +12,7 @@
Check out your Account Setting to set up notifications for changes to schedule.
Schedule
-