Skip to content

Commit

Permalink
updated PrintLink to only show up when the current day is enabled to …
Browse files Browse the repository at this point in the history
…prevent an error on navigation to PrintableList
  • Loading branch information
felix.ruf committed Feb 19, 2025
1 parent c3594ab commit f3b70ee
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/Resources/src/stores/dashboardStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ class DashboardStore extends Store<Dashboard> {
return undefined;
}

public getToday() {
const today = new Date();
return Object.values({ ...this.state.weeks })
.flatMap((week) => Object.values(week.days))
.find((day) => new Date(day.date.date).getUTCDay() === today.getUTCDay());
}

public updateEventParticipation(weekId: number, dayId: number, eventId: number, participations: number) {
const day = this.getDay(weekId, dayId);
if (day !== null && day !== undefined && day.event !== null && day.event.eventId === eventId) {
Expand Down
13 changes: 11 additions & 2 deletions src/Resources/src/views/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
:weeks="weeks"
/>
<PrintLink
v-if="userDataStore.roleAllowsRoute('PrintableList')"
v-if="showPrinkLink"
class="mr-[27px] text-right print:hidden"
/>
</template>
Expand All @@ -20,7 +20,7 @@ import DashboardWeekTabs from '@/components/dashboard/DashboardWeekTabs.vue';
import DashboardWeekAll from '@/components/dashboard/DashboardWeekAll.vue';
import PrintLink from '@/views/PrintLink.vue';
import { userDataStore } from '@/stores/userDataStore';
import { onMounted, ref } from 'vue';
import { computed, onMounted, ref } from 'vue';
import type { Dictionary } from '@/types/types';
import type { Week } from '@/api/getDashboardData';
import { useEvents } from '@/stores/eventsStore';
Expand All @@ -31,6 +31,15 @@ const weeks = ref<Dictionary<Week>>({});
const { fetchEvents } = useEvents();
const { receive } = useEventsBus();
const showPrinkLink = computed(() => {
return (
userDataStore.roleAllowsRoute('PrintableList') &&
Object.keys(weeks.value).length > 0 &&
Object.values(weeks.value)[0].isEnabled &&
dashboardStore.getToday()?.isEnabled
);
});
onMounted(async () => {
const progress = useProgress().start();
Expand Down

0 comments on commit f3b70ee

Please sign in to comment.