Skip to content

Commit

Permalink
add response to booking submission
Browse files Browse the repository at this point in the history
  • Loading branch information
fmtabbara committed Nov 20, 2024
1 parent dc4bbf2 commit 6b2721a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
16 changes: 16 additions & 0 deletions suncityla/app/bookings/[bookingId]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export default async function BookingConfirmed({
params,
}: {
params: Promise<{ bookingId: string }>;
}) {
const { bookingId } = await params;
console.log(bookingId);

return (
<div>
<h1>Booking Confirmed</h1>
<p>Your booking has been confirmed.</p>
<p>Booking id: {bookingId}</p>
</div>
);
}
1 change: 0 additions & 1 deletion suncityla/app/bookings/actions/onSubmitAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const onSubmitAction = async (
): Promise<FormState> => {
const formData = Object.fromEntries(data);
const parsed = bookingFormSchema.safeParse(formData);
console.log({ parsed });

if (!parsed.success) {
const fields: Record<string, string> = {};
Expand Down
8 changes: 6 additions & 2 deletions suncityla/app/bookings/components/BookingForm/BookingForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ import { useActionState, useRef, startTransition } from "react";
import onSubmitAction from "../../actions/onSubmitAction";
import BookingFormField from "./BookingFormField";
import { DateTimePickerForm } from "../TimeDatePicker/TimeDatePicker";
import { useRouter } from "next/navigation";

export type BookingFormData = z.infer<typeof bookingFormSchema>;

export default function BookingForm() {
const [state, formAction] = useActionState(onSubmitAction, {
message: "",
bookingRef: undefined,
});

console.log(state);
const router = useRouter();

const form = useForm<z.infer<typeof bookingFormSchema>>({
resolver: zodResolver(bookingFormSchema),
Expand All @@ -39,7 +41,9 @@ export default function BookingForm() {
form.reset();
};

console.log(form.getValues());
if (state.bookingRef) {
router.push(`/bookings/${state.bookingRef}`);
}

return (
<div className="w-96 border p-4 bg-slate-100 rounded-md">
Expand Down

0 comments on commit 6b2721a

Please sign in to comment.