Sorted out a bunch of reactivity issues

This commit is contained in:
2024-05-29 10:00:48 -04:00
parent 6654132120
commit 387af2e6ce
10 changed files with 304 additions and 228 deletions

View File

@@ -50,7 +50,8 @@ export const useAuthStore = defineStore('auth', () => {
currentUser.value = await account.get();
}
function getUserNameById(id: string) {
function getUserNameById(id: string | undefined | null): string {
if (!id) return 'No User';
try {
if (!userNames.value[id]) {
userNames.value[id] = '';

View File

@@ -47,6 +47,19 @@ export const useReservationStore = defineStore('reservation', () => {
setDateLoaded(startDate, endDate, 'error');
}
};
const getReservationById = async (id: string) => {
try {
const response = await databases.getDocument(
AppwriteIds.databaseId,
AppwriteIds.collection.reservation,
id
);
return response as Reservation;
} catch (error) {
console.error('Failed to fetch reservation: ', error);
}
};
const createReservation = async (reservation: Reservation) => {
try {
const response = await databases.createDocument(
@@ -75,7 +88,6 @@ export const useReservationStore = defineStore('reservation', () => {
return false;
}
console.log(id);
try {
await databases.deleteDocument(
AppwriteIds.databaseId,
@@ -203,6 +215,7 @@ export const useReservationStore = defineStore('reservation', () => {
return {
getReservationsByDate,
getReservationById,
createReservation,
deleteReservation,
fetchReservationsForDateRange,

View File

@@ -10,6 +10,8 @@ export type Reservation = Partial<Models.Document> & {
status?: StatusTypes;
reason: string;
comment: string;
members?: string[];
guests?: string[];
};
// 24 hrs in advance only 2 weekday, and 1 weekend slot