From 9f398e5509952b88f48302e6f9b73a8fca0238c4 Mon Sep 17 00:00:00 2001 From: Patrick Toal Date: Fri, 24 May 2024 20:45:04 -0400 Subject: [PATCH] Add List View --- src/pages/schedule/BoatReservationPage.vue | 17 +--- src/pages/schedule/ListBookingsPage.vue | 107 +++++++++++++++++++++ src/router/navlinks.ts | 7 ++ src/router/routes.ts | 5 + src/stores/reservation.ts | 23 +++++ src/utils/schedule.ts | 6 ++ 6 files changed, 152 insertions(+), 13 deletions(-) create mode 100644 src/pages/schedule/ListBookingsPage.vue diff --git a/src/pages/schedule/BoatReservationPage.vue b/src/pages/schedule/BoatReservationPage.vue index 099dda1..095cd25 100644 --- a/src/pages/schedule/BoatReservationPage.vue +++ b/src/pages/schedule/BoatReservationPage.vue @@ -44,12 +44,7 @@ label="Start" /> - {{ - date.formatDate( - new Date(bookingForm.startDate as string), - 'ddd MMM Do hh:mm A' - ) - }} + {{ formatDate(bookingForm.startDate) }} @@ -59,12 +54,7 @@ label="End" /> - {{ - date.formatDate( - new Date(bookingForm.endDate as string), - 'ddd MMM Do hh:mm A' - ) - }} + {{ formatDate(bookingForm.endDate) }} @@ -131,10 +121,11 @@ import { computed, ref, watch } from 'vue'; import { useAuthStore } from 'src/stores/auth'; import { Boat, useBoatStore } from 'src/stores/boat'; -import { date, useQuasar } from 'quasar'; +import { useQuasar } from 'quasar'; import { Interval, Reservation } from 'src/stores/schedule.types'; import BoatScheduleTableComponent from 'src/components/scheduling/boat/BoatScheduleTableComponent.vue'; import { getNewId } from 'src/utils/misc'; +import { formatDate } from 'src/utils/schedule'; import { useRouter } from 'vue-router'; import { useReservationStore } from 'src/stores/reservation'; diff --git a/src/pages/schedule/ListBookingsPage.vue b/src/pages/schedule/ListBookingsPage.vue new file mode 100644 index 0000000..9a09c40 --- /dev/null +++ b/src/pages/schedule/ListBookingsPage.vue @@ -0,0 +1,107 @@ + + diff --git a/src/router/navlinks.ts b/src/router/navlinks.ts index 6ce4d08..fbd7fee 100644 --- a/src/router/navlinks.ts +++ b/src/router/navlinks.ts @@ -29,6 +29,13 @@ export const links = [ front_links: true, enabled: true, sublinks: [ + { + name: 'List', + to: '/schedule/list', + icon: 'list', + front_links: false, + enabled: true, + }, { name: 'Book', to: '/schedule/book', diff --git a/src/router/routes.ts b/src/router/routes.ts index 670a1b9..ad0e90d 100644 --- a/src/router/routes.ts +++ b/src/router/routes.ts @@ -40,6 +40,11 @@ const routes: RouteRecordRaw[] = [ component: () => import('src/pages/schedule/BoatScheduleView.vue'), name: 'boat-schedule', }, + { + path: 'list', + component: () => import('src/pages/schedule/ListBookingsPage.vue'), + name: 'list-bookings', + }, { path: 'manage', component: () => import('src/pages/schedule/ManageCalendar.vue'), diff --git a/src/stores/reservation.ts b/src/stores/reservation.ts index f9ac79c..c095a19 100644 --- a/src/stores/reservation.ts +++ b/src/stores/reservation.ts @@ -6,10 +6,13 @@ import { ID, Query } from 'appwrite'; import { date } from 'quasar'; import { Timestamp, parseDate, today } from '@quasar/quasar-ui-qcalendar'; import { LoadingTypes } from 'src/utils/misc'; +import { useAuthStore } from './auth'; export const useReservationStore = defineStore('reservation', () => { const reservations = ref>(new Map()); const datesLoaded = ref>({}); + const userReservations = ref(); + const authStore = useAuthStore(); // Fetch reservations for a specific date range const fetchReservationsForDateRange = async ( @@ -136,6 +139,24 @@ export const useReservationStore = defineStore('reservation', () => { ); }; + const getUserReservations = () => { + return userReservations; + }; + + const fetchUserReservations = async () => { + if (!authStore.currentUser) return; + try { + const response = await databases.listDocuments( + AppwriteIds.databaseId, + AppwriteIds.collection.reservation, + [Query.equal('user', authStore.currentUser.$id)] + ); + userReservations.value = response.documents as Reservation[]; + } catch (error) { + console.error('Failed to fetch reservations for user: ', error); + } + }; + return { getReservationsByDate, createReservation, @@ -143,5 +164,7 @@ export const useReservationStore = defineStore('reservation', () => { isReservationOverlapped, isResourceTimeOverlapped, getConflictingReservations, + fetchUserReservations, + getUserReservations, }; }); diff --git a/src/utils/schedule.ts b/src/utils/schedule.ts index efbd733..a7780b6 100644 --- a/src/utils/schedule.ts +++ b/src/utils/schedule.ts @@ -1,3 +1,4 @@ +import { date } from 'quasar'; import { Boat } from 'src/stores/boat'; import { Interval, @@ -69,3 +70,8 @@ export function buildInterval( }; return result; } + +export function formatDate(inputDate: string | undefined): string { + if (!inputDate) return ''; + return date.formatDate(new Date(inputDate), 'ddd MMM Do hh:mm A'); +}