From bc7fee8d166e999c7c8f824a8e92b3ac95db8930 Mon Sep 17 00:00:00 2001 From: Jan Berg Date: Wed, 24 Jul 2024 16:03:38 +0300 Subject: [PATCH 1/2] Removed some unnecessary setBookings as well as some unnecessary wait time --- .../src/components/BookingView/BookingView.tsx | 14 ++++---------- .../components/CurrentBooking/CurrentBooking.tsx | 5 ++--- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/frontend/src/components/BookingView/BookingView.tsx b/frontend/src/components/BookingView/BookingView.tsx index 6949725..a58c208 100644 --- a/frontend/src/components/BookingView/BookingView.tsx +++ b/frontend/src/components/BookingView/BookingView.tsx @@ -166,6 +166,7 @@ function BookingView(props: BookingViewProps) { const buildingPreference = preferences.building?.id; getRooms(buildingPreference, GET_RESERVED) .then((allRooms) => { + console.log('Setting rooms at update'); setRooms(allRooms); }) .catch((error) => console.log(error)); @@ -202,18 +203,12 @@ function BookingView(props: BookingViewProps) { setBookingLoading(room.id); makeBooking(bookingDetails, SKIP_CONFIRMATION) - .then((madeBooking) => { - setBookings([...bookings, madeBooking]); + .then((response) => { + console.log(response); updateData(); - // update data after 2.5s, waits Google Calendar to - // accept the booking. - setTimeout(() => { - updateData(); - }, 2500); createSuccessNotification('Booking was successful'); setBookingLoading('false'); document.getElementById('main-view-content')?.scrollTo(0, 0); - triggerGoogleAnalyticsEvent(new BookingEvent(room, duration)); triggerClarityEvent(AnalyticsEventEnum.BOOKING); }) @@ -403,8 +398,7 @@ function BookingView(props: BookingViewProps) { rooms, customFilter, onlyFavourites, - preferences?.fav_rooms, - filterRooms + preferences?.fav_rooms ]); useEffect(() => { diff --git a/frontend/src/components/CurrentBooking/CurrentBooking.tsx b/frontend/src/components/CurrentBooking/CurrentBooking.tsx index 2fd2fb5..242dafe 100644 --- a/frontend/src/components/CurrentBooking/CurrentBooking.tsx +++ b/frontend/src/components/CurrentBooking/CurrentBooking.tsx @@ -110,8 +110,7 @@ const CurrentBooking = (props: CurrentBookingProps) => { toggleDrawer(false); updateBooking(addTimeDetails, booking.id, NO_CONFIRMATION) - .then((updatedBooking) => { - setBookings([updatedBooking]); + .then(() => { setBookingProcessing('false'); // replace updated booking updateBookings(); @@ -140,7 +139,7 @@ const CurrentBooking = (props: CurrentBookingProps) => { toggleDrawer(false); endBooking(booking.id) - .then((endBooking) => { + .then(() => { setBookingProcessing('false'); // replace updated booking updateBookings(); From 469fb684ce808fd3879a7b23562886aafd07d372 Mon Sep 17 00:00:00 2001 From: Jan Berg Date: Thu, 25 Jul 2024 10:08:37 +0300 Subject: [PATCH 2/2] Removed an unnecessary console log --- frontend/src/components/BookingView/BookingView.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/frontend/src/components/BookingView/BookingView.tsx b/frontend/src/components/BookingView/BookingView.tsx index a58c208..18d1a25 100644 --- a/frontend/src/components/BookingView/BookingView.tsx +++ b/frontend/src/components/BookingView/BookingView.tsx @@ -204,7 +204,6 @@ function BookingView(props: BookingViewProps) { makeBooking(bookingDetails, SKIP_CONFIRMATION) .then((response) => { - console.log(response); updateData(); createSuccessNotification('Booking was successful'); setBookingLoading('false');