|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import { useEffect, useState } from "react"; |
| 4 | +import { useParams } from "next/navigation"; |
| 5 | +import { Company, UserProfile } from "@/types"; |
| 6 | +import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; |
| 7 | +import { AlumniCard } from "@/components/directory/AlumniCard"; |
| 8 | + |
| 9 | +export default function CompanyDetailPage() { |
| 10 | + const { id } = useParams<{ id: string }>(); |
| 11 | + const [company, setCompany] = useState<Company | null>(null); |
| 12 | + const [members, setMembers] = useState<UserProfile[]>([]); |
| 13 | + const [companies, setCompanies] = useState<Company[]>([]); |
| 14 | + |
| 15 | + useEffect(() => { |
| 16 | + Promise.all([ |
| 17 | + fetch(`/api/companies/${id}`).then((r) => r.json()), |
| 18 | + fetch(`/api/users?companyId=${id}`).then((r) => r.json()), |
| 19 | + fetch("/api/companies").then((r) => r.json()), |
| 20 | + ]).then(([comp, users, allCompanies]: [Company, UserProfile[], Company[]]) => { |
| 21 | + setCompany(comp); |
| 22 | + setMembers(users); |
| 23 | + setCompanies(allCompanies); |
| 24 | + }).catch(console.error); |
| 25 | + }, [id]); |
| 26 | + |
| 27 | + if (!company) return null; |
| 28 | + |
| 29 | + const initials = company.name.slice(0, 2).toUpperCase(); |
| 30 | + |
| 31 | + return ( |
| 32 | + <div className="space-y-6"> |
| 33 | + <div className="flex items-center gap-4"> |
| 34 | + <Avatar className="h-14 w-14 rounded-md"> |
| 35 | + <AvatarImage src={company.logoUrl} alt={company.name} /> |
| 36 | + <AvatarFallback className="rounded-md">{initials}</AvatarFallback> |
| 37 | + </Avatar> |
| 38 | + <div> |
| 39 | + <h1 className="text-2xl font-semibold">{company.name}</h1> |
| 40 | + <p className="text-sm text-muted-foreground">{members.length} {members.length === 1 ? "member" : "members"}</p> |
| 41 | + </div> |
| 42 | + </div> |
| 43 | + <div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-3"> |
| 44 | + {members.map((u) => ( |
| 45 | + <AlumniCard key={u.uid} profile={u} companies={companies} /> |
| 46 | + ))} |
| 47 | + </div> |
| 48 | + {members.length === 0 && ( |
| 49 | + <p className="text-center text-muted-foreground py-12">No members yet.</p> |
| 50 | + )} |
| 51 | + </div> |
| 52 | + ); |
| 53 | +} |
0 commit comments