changes after second dev test

fixed full name issue, refresh issue on reservation and user/admin login issue
This commit is contained in:
belviskhoremk
2026-05-27 23:04:32 +00:00
parent 209ac114b0
commit 53365b9dbf
7 changed files with 60 additions and 27 deletions

View File

@@ -44,7 +44,7 @@ interface AdminContextType {
deleteProduct: (id: string) => Promise<void>;
reservations: Reservation[];
reservationsLoading: boolean;
refreshReservations: () => Promise<void>;
refreshReservations: (silent?: boolean) => Promise<void>;
updateReservationStatus: (id: string, status: "confirmed" | "cancelled") => Promise<void>;
deleteReservation: (id: string) => Promise<void>;
}
@@ -69,14 +69,14 @@ export const AdminProvider = ({ children }: { children: ReactNode }) => {
}
};
const refreshReservations = async () => {
const refreshReservations = async (silent = false) => {
if (!isAdmin) return;
setReservationsLoading(true);
if (!silent) setReservationsLoading(true);
try {
const res = await bookingsApi.adminListBookings();
setReservations(res.data.map(toReservation));
} finally {
setReservationsLoading(false);
if (!silent) setReservationsLoading(false);
}
};
@@ -108,12 +108,11 @@ export const AdminProvider = ({ children }: { children: ReactNode }) => {
const updateReservationStatus = async (id: string, status: "confirmed" | "cancelled") => {
await bookingsApi.adminUpdateBookingStatus(id, status);
// Optimistic update for immediate feedback
setReservations((prev) =>
prev.map((r) => (r.id === id ? { ...r, status } : r))
);
// Refresh from server to ensure consistency
refreshReservations();
// Sync with server silently — no loading flash
refreshReservations(true);
};
const deleteReservation = async (id: string) => {