Booking page state improvements.
This commit is contained in:
@@ -9,6 +9,7 @@ export async function APISendCreateBooking(bookingData: NewBooking | null) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
const rs = await fetcherWithFilter<NewBookingResponse>(
|
const rs = await fetcherWithFilter<NewBookingResponse>(
|
||||||
"/api/booking/create",
|
"/api/booking/create",
|
||||||
bookingData,
|
bookingData,
|
||||||
@@ -18,4 +19,11 @@ export async function APISendCreateBooking(bookingData: NewBooking | null) {
|
|||||||
bookingResponse: rs,
|
bookingResponse: rs,
|
||||||
isError: false,
|
isError: false,
|
||||||
};
|
};
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
bookingResponse: null,
|
||||||
|
isError: true,
|
||||||
|
errorMessage: error,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,19 +19,22 @@ import { useForm } from "react-hook-form";
|
|||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { z } from "zod/v4";
|
import { z } from "zod/v4";
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
|
import { eBookingState } from "@/utils/AppStateManager";
|
||||||
|
|
||||||
enum PageState {
|
enum PageState {
|
||||||
noData,
|
|
||||||
showForm,
|
showForm,
|
||||||
sending,
|
sending,
|
||||||
created,
|
|
||||||
error,
|
error,
|
||||||
}
|
}
|
||||||
|
|
||||||
function BookPage() {
|
function BookPage() {
|
||||||
const [pageState, setPageState] = useState<PageState>(PageState.showForm);
|
const [pageState, setPageState] = useState<PageState>(PageState.showForm);
|
||||||
const bookingData = useAppStore((state) => state.currentBooking);
|
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 navigate = useNavigate();
|
||||||
|
|
||||||
const bookingForm = useForm<z.infer<typeof BookingFormSchema>>({
|
const bookingForm = useForm<z.infer<typeof BookingFormSchema>>({
|
||||||
@@ -67,16 +70,28 @@ function BookPage() {
|
|||||||
if (rs.isError) {
|
if (rs.isError) {
|
||||||
setPageState(PageState.error);
|
setPageState(PageState.error);
|
||||||
} else {
|
} else {
|
||||||
|
setAppBookingState(eBookingState.Booked);
|
||||||
navigate("/success", { state: rs.bookingResponse });
|
navigate("/success", { state: rs.bookingResponse });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!bookingData || !bookingData.customerDetails) {
|
//Redirect to home if no booking is active.
|
||||||
return (
|
if (
|
||||||
<Typography variant={"h2"}>You must select some rooms...</Typography>
|
!appBookingState ||
|
||||||
);
|
appBookingState.state != eBookingState.Booking ||
|
||||||
|
!bookingData
|
||||||
|
) {
|
||||||
|
navigate("/home");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const errorMsg = (
|
||||||
|
<div>
|
||||||
|
<Typography variant={"inlineCode"}>
|
||||||
|
Server error. Try again later!
|
||||||
|
</Typography>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Typography variant={"h1"}>Booking Details</Typography>
|
<Typography variant={"h1"}>Booking Details</Typography>
|
||||||
@@ -150,6 +165,7 @@ function BookPage() {
|
|||||||
</Button>
|
</Button>
|
||||||
</form>
|
</form>
|
||||||
</Form>
|
</Form>
|
||||||
|
{pageState == PageState.error ? errorMsg : null}
|
||||||
</div>
|
</div>
|
||||||
<Separator className="my-10 lg:hidden" />
|
<Separator className="my-10 lg:hidden" />
|
||||||
<BookingDetails mode="View"></BookingDetails>
|
<BookingDetails mode="View"></BookingDetails>
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ function SearchPage() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onBookingContinue = () => {
|
const onBookingContinue = () => {
|
||||||
|
setAppBookingState(eBookingState.Booking);
|
||||||
navigate("/book");
|
navigate("/book");
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -102,7 +103,9 @@ function SearchPage() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const getPageContent = () => {
|
const getPageContent = () => {
|
||||||
const isSearched = appBookingState.state == eBookingState.Searched;
|
const isSearched =
|
||||||
|
appBookingState.state == eBookingState.Searched ||
|
||||||
|
appBookingState.state == eBookingState.Booking;
|
||||||
if (!isSearched) {
|
if (!isSearched) {
|
||||||
return pageContentSearch;
|
return pageContentSearch;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user