Booking page state improvements.

This commit is contained in:
2025-09-08 19:45:46 +02:00
parent 590d7f6fa1
commit 550beffba8
3 changed files with 43 additions and 16 deletions
+8
View File
@@ -9,6 +9,7 @@ export async function APISendCreateBooking(bookingData: NewBooking | null) {
};
}
try {
const rs = await fetcherWithFilter<NewBookingResponse>(
"/api/booking/create",
bookingData,
@@ -18,4 +19,11 @@ export async function APISendCreateBooking(bookingData: NewBooking | null) {
bookingResponse: rs,
isError: false,
};
} catch (error) {
return {
bookingResponse: null,
isError: true,
errorMessage: error,
};
}
}
+23 -7
View File
@@ -19,19 +19,22 @@ import { useForm } from "react-hook-form";
import { useNavigate } from "react-router-dom";
import { z } from "zod/v4";
import { zodResolver } from "@hookform/resolvers/zod";
import { eBookingState } from "@/utils/AppStateManager";
enum PageState {
noData,
showForm,
sending,
created,
error,
}
function BookPage() {
const [pageState, setPageState] = useState<PageState>(PageState.showForm);
const bookingData = useAppStore((state) => state.currentBooking);
const setCustomerData = useAppStore((state) => state.currentBookingSetCustomer);
const appBookingState = useAppStore((state) => state.bookingState);
const setAppBookingState = useAppStore((state) => state.setBookingState);
const setCustomerData = useAppStore(
(state) => state.currentBookingSetCustomer,
);
const navigate = useNavigate();
const bookingForm = useForm<z.infer<typeof BookingFormSchema>>({
@@ -67,16 +70,28 @@ function BookPage() {
if (rs.isError) {
setPageState(PageState.error);
} else {
setAppBookingState(eBookingState.Booked);
navigate("/success", { state: rs.bookingResponse });
}
};
if (!bookingData || !bookingData.customerDetails) {
return (
<Typography variant={"h2"}>You must select some rooms...</Typography>
);
//Redirect to home if no booking is active.
if (
!appBookingState ||
appBookingState.state != eBookingState.Booking ||
!bookingData
) {
navigate("/home");
}
const errorMsg = (
<div>
<Typography variant={"inlineCode"}>
Server error. Try again later!
</Typography>
</div>
);
return (
<>
<Typography variant={"h1"}>Booking Details</Typography>
@@ -150,6 +165,7 @@ function BookPage() {
</Button>
</form>
</Form>
{pageState == PageState.error ? errorMsg : null}
</div>
<Separator className="my-10 lg:hidden" />
<BookingDetails mode="View"></BookingDetails>
+4 -1
View File
@@ -55,6 +55,7 @@ function SearchPage() {
};
const onBookingContinue = () => {
setAppBookingState(eBookingState.Booking);
navigate("/book");
};
@@ -102,7 +103,9 @@ function SearchPage() {
);
const getPageContent = () => {
const isSearched = appBookingState.state == eBookingState.Searched;
const isSearched =
appBookingState.state == eBookingState.Searched ||
appBookingState.state == eBookingState.Booking;
if (!isSearched) {
return pageContentSearch;
}