diff --git a/src/app/(user)/profile/[uid]/BusinessProfile.tsx b/src/app/(user)/profile/[uid]/BusinessProfile.tsx new file mode 100644 index 0000000..8f0a78e --- /dev/null +++ b/src/app/(user)/profile/[uid]/BusinessProfile.tsx @@ -0,0 +1,74 @@ +import { getBusinessByUserId } from "@/lib/data/businessQuery"; +import { createSupabaseClient } from "@/lib/supabase/serverComponentClient"; +import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/components/ui/card"; +import { Separator } from "@/components/ui/separator"; + +export const BusinessProfile = async ({ userId }: { userId: string }) => { + const supabase = createSupabaseClient(); + const { data, error } = await getBusinessByUserId(supabase, userId); + if (error) { + return ( + + + Error Loading Data + + +

Can't load business data

+
+
+ ); + } + + if (!data) { + return ( + + + No Business Found + + +

This business account doesn't have businesses

+
+
+ ); + } + + return ( +
+ + +
+
+ {data.business_name} + {data.business_type} +
+
+

+ Location: {data.location} +

+

+ Joined on: {new Date(data.joined_date).toLocaleDateString()} +

+
+
+
+ + +
+
+

Business ID:

+

{data.business_id}

+
+
+

Business Type:

+

{data.business_type}

+
+
+

User ID:

+

{data.user_id}

+
+
+
+
+
+ ); +}; diff --git a/src/app/(user)/profile/[uid]/ProjectProfile.tsx b/src/app/(user)/profile/[uid]/ProjectProfile.tsx new file mode 100644 index 0000000..3f6067d --- /dev/null +++ b/src/app/(user)/profile/[uid]/ProjectProfile.tsx @@ -0,0 +1,66 @@ +import { getProjectByUserId } from "@/lib/data/projectQuery"; +import { createSupabaseClient } from "@/lib/supabase/serverComponentClient"; +import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/components/ui/card"; +import { Separator } from "@/components/ui/separator"; +import { Button } from "@/components/ui/button"; +import Link from "next/link"; + +export const ProjectProfileSection = async ({ userId }: { userId: string }) => { + const supabase = createSupabaseClient(); + const { data, error } = await getProjectByUserId(supabase, userId); + + if (error) { + return ( + + + Error Loading Data + + +

Can't load business data

+
+
+ ); + } + + if (!data || data.length === 0) { + return ( + + + No Project Found + + +

This business doesn't have any projects

+
+
+ ); + } + + return ( +
+
+
+ {data.map((project) => ( + + +
+
+ {project.project_name} + + {project.project_short_description} + +
+
+
+ + + + +
+ ))} +
+
+
+ ); +}; diff --git a/src/app/(user)/profile/[uid]/page.tsx b/src/app/(user)/profile/[uid]/page.tsx index 3fb7f04..922db33 100644 --- a/src/app/(user)/profile/[uid]/page.tsx +++ b/src/app/(user)/profile/[uid]/page.tsx @@ -6,6 +6,8 @@ import { format } from "date-fns"; import ReactMarkdown from "react-markdown"; import Link from "next/link"; import { getUserRole } from "@/lib/data/userQuery"; +import { BusinessProfile } from "./BusinessProfile"; +import { ProjectProfileSection } from "./ProjectProfile"; export default async function ProfilePage({ params }: { params: { uid: string } }) { const supabase = createSupabaseClient(); @@ -85,12 +87,20 @@ export default async function ProfilePage({ params }: { params: { uid: string } )} + {userRoleData.role === "business" && ( +
+ + +
+ )} {/* Lower */}
-

Bio

-
- {profileData.bio || "No bio available."} + {/*

Bio

*/} +
+
+ {profileData.bio || "No bio available."} +
diff --git a/src/lib/data/businessQuery.ts b/src/lib/data/businessQuery.ts index 3bed1bf..db66d43 100644 --- a/src/lib/data/businessQuery.ts +++ b/src/lib/data/businessQuery.ts @@ -45,6 +45,28 @@ export const getBusinessByName = ( return query; }; +export const getBusinessByUserId = (client: SupabaseClient, userId: string) => { + const query = client + .from("business") + .select( + ` + business_id:id, + location, + business_name, + ...business_type ( + business_type_id: id, + business_type: value + ), + joined_date, + user_id + ` + ) + .eq("user_id", userId) + .single(); + + return query; +}; + export const getBusinessAndProject = ( client: SupabaseClient, params: { businessName?: String | null; businessId?: number | null; single?: boolean } = { single: false }