From f1084fe560bb1aa67130219a87d3fa2de6abef2f Mon Sep 17 00:00:00 2001
From: Rudra Pratap Singh <130541940+rudrapratap63@users.noreply.github.com>
Date: Fri, 11 Oct 2024 01:44:26 +0530
Subject: [PATCH] Implementation For Request Booking At Event Space
---
.../explore-event-space/[spaceId]/page.tsx | 2 +-
.../request-booking/page.tsx | 132 ++++++++++++++++++
2 files changed, 133 insertions(+), 1 deletion(-)
create mode 100644 src/app/(event-space)/explore-event-space/request-booking/page.tsx
diff --git a/src/app/(event-space)/explore-event-space/[spaceId]/page.tsx b/src/app/(event-space)/explore-event-space/[spaceId]/page.tsx
index c3d06ab..65254d3 100644
--- a/src/app/(event-space)/explore-event-space/[spaceId]/page.tsx
+++ b/src/app/(event-space)/explore-event-space/[spaceId]/page.tsx
@@ -46,7 +46,7 @@ const EventPage = () => {
router.push("/unauthorized");
toast.error("Unauthorized access. Please register.");
} else {
- router.push(`/register-event/${spaceId}`);
+ router.push(`/explore-event-space/request-booking?spaceId=${spaceId}`);
toast.success("Redirecting to booking...");
}
});
diff --git a/src/app/(event-space)/explore-event-space/request-booking/page.tsx b/src/app/(event-space)/explore-event-space/request-booking/page.tsx
new file mode 100644
index 0000000..56cf510
--- /dev/null
+++ b/src/app/(event-space)/explore-event-space/request-booking/page.tsx
@@ -0,0 +1,132 @@
+"use client";
+
+import React, { useState, useEffect } from "react";
+import { useForm } from "react-hook-form";
+import { supabase } from "../../../../utils/supabase";
+import { userDetails } from "../../../../action/userDetails";
+import { useRouter } from "next/navigation";
+import { useKindeBrowserClient } from "@kinde-oss/kinde-auth-nextjs";
+import { useSearchParams } from "next/navigation";
+import Loading from "@/components/loading";
+import { toast } from "sonner";
+
+export default function RequestBooking() {
+ const router = useRouter();
+ const searchParams = useSearchParams();
+ const { isAuthenticated, isLoading } = useKindeBrowserClient();
+
+ const [user, setUser]: any = useState(null);
+ const { register, handleSubmit, formState: { errors }, setValue } = useForm();
+
+ useEffect(() => {
+ // Fetch user details
+ const fetchUserDetails = async () => {
+ try {
+ const fetchedUserDetails = await userDetails();
+ setUser(fetchedUserDetails);
+ } catch (error) {
+ console.error("Error fetching user details:", error);
+ toast.error("Failed to fetch user details");
+ setUser(null);
+ }
+ };
+
+ fetchUserDetails();
+ }, []);
+
+ useEffect(() => {
+ // Extract spaceId from the search parameters and set it in the form
+ const spaceId = searchParams.get("spaceId");
+ if (spaceId) {
+ setValue("space_id", spaceId);
+ }
+ }, [searchParams, setValue]);
+
+ const onSubmit = async (data: any) => {
+ const { space_id, request_date, status } = data;
+
+ const { error } = await supabase
+ .from("event_space_request")
+ .insert([{
+ organiser_id: user?.id,
+ space_id: space_id,
+ request_date: request_date,
+ status: status || 'pending',
+ }]);
+
+ if (error) {
+ console.error(error);
+ toast.error("Request submission failed. Please try again.");
+ return;
+ }
+
+ toast.success("Booking request submitted successfully!");
+ router.push("/");
+ };
+
+ if (isLoading) {
+ return