diff --git a/src/app/admin/BusinessTable.tsx b/src/app/admin/BusinessTable.tsx new file mode 100644 index 0000000..cfa1eb2 --- /dev/null +++ b/src/app/admin/BusinessTable.tsx @@ -0,0 +1,59 @@ +import Link from "next/link"; +import { Table, TableHeader, TableRow, TableCell, TableBody, TableHead } from "@/components/ui/table"; + +interface Business { + id: any; + location: any; + business_name: any; + business_type: any; + joined_date: any; + user_id: number; + username: string; + full_name: string; + email: string; +} + +interface BusinessTableProps { + businesses: Business[] | null; +} + +const BusinessTable = ({ businesses }: BusinessTableProps) => { + if (!businesses) return
No data available
; + + return ( +
+ + + + Business Name + Owner + Business Type + Location + Joined Date + + + + {businesses.map((business) => ( + + + +

{business.business_name}

+ +
+ + +

{business.username}

+ +
+ {business.business_type} + {business.location} + {new Date(business.joined_date).toLocaleDateString()} +
+ ))} +
+
+
+ ); +}; + +export default BusinessTable; diff --git a/src/app/admin/page.tsx b/src/app/admin/page.tsx index 65c4337..4d289ae 100644 --- a/src/app/admin/page.tsx +++ b/src/app/admin/page.tsx @@ -1,156 +1,21 @@ -import { getUserRole } from "@/lib/data/userQuery"; +import { getAllBusinesses } from "@/lib/data/businessQuery"; import { createSupabaseClient } from "@/lib/supabase/serverComponentClient"; -import { redirect } from "next/navigation"; -import { Table, TableBody, TableCaption, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; -import { Checkbox } from "@/components/ui/checkbox"; -import Link from "next/link"; -import { FolderOpenDot } from "lucide-react"; -import { getAllBusinessApplicationQuery } from "@/lib/data/applicationQuery"; -import { BusinessActionButtons } from "./BusinessActionButtons"; -import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; +import BusinessTable from "./BusinessTable"; import { Separator } from "@/components/ui/separator"; -interface ApplicationData { - id: any; - user_id: any; - username: any; - business_type_id: any; - business_type_value: any; - project_application_id: any; - business_name: any; - created_at: any; - is_in_us: any; - is_for_sale: any; - pitch_deck_url: any; - community_size: any; - is_generating_revenue: any; - money_raised_to_date: any; - location: any; - status: any; -} - -function ApplicationTable({ applications }: { applications: ApplicationData[] }) { - if (!applications || applications.length === 0) { - return ( - - - No business applications found - - - ); - } - - return applications.map((application: ApplicationData) => ( - - {application.business_name} - - - {application.username} - - - - {application.pitch_deck_url && ( - - {application.pitch_deck_url} - - )} - - - - - - - - - - - {application.community_size} - {application.money_raised_to_date} - {application.location} - - {application.project_application_id && ( - - - - )} - - - {application.status === "pending" && } - - - )); -} - export default async function AdminPage() { const client = createSupabaseClient(); - const { data: userData, error: userDataError } = await client.auth.getUser(); + const { data, error } = await getAllBusinesses(client); - if (userDataError) { - redirect("/"); + if (error) { + return
Error fetching businesses: {error.message}
; } - const uid = userData.user!.id; - const { data: roleData, error: roleDataError } = await getUserRole(client, uid); - - if (roleDataError || roleData!.role != "admin") { - redirect("/"); - } - - const { data: businessApplicationData, error: businessApplicationError } = - await getAllBusinessApplicationQuery(client); - - if (businessApplicationError) { - console.log(businessApplicationError); - } - - const pendingApplications = businessApplicationData?.filter((app) => app.status === "pending") || []; - const approvedApplications = businessApplicationData?.filter((app) => app.status === "approve") || []; - const rejectedApplications = businessApplicationData?.filter((app) => app.status === "rejecte") || []; return (
-
Admin Page
- - - - Pending ({pendingApplications.length}) - Approved ({approvedApplications.length}) - Rejected ({rejectedApplications.length}) - - - {["pending", "approved", "rejected"].map((status) => ( - - - {status.charAt(0).toUpperCase() + status.slice(1)} business applications - - - Business Name - User Account - Pitch Deck URL - Is In US? - Is For Sale? - Generate Revenue - Community Size - Money raised to date - Location - Project - Actions - - - - - -
-
- ))} -
+

Business List

+ +
); }