import { useState } from 'react'; import { Card, CardContent } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { Textarea } from '@/components/ui/textarea'; import { useCurrentUser } from '@/hooks/useCurrentUser'; import { useToast } from '@/hooks/useToast'; import { useSendCollectiveJoinRequest, useMyCollectiveJoinRequest, } from '@/hooks/useCollectiveJoinRequests'; import type { LabProfile } from '@/hooks/useLabProfiles'; import { Users, Hand, Loader2, Check, X } from 'lucide-react'; /** * "Request to join this collective" — shown on a Lab collective's profile to * logged-in skaters who aren't the owner and aren't already listed. Mirrors the * crew join-request: it notifies the owner (who adds the member through their * own editor). Owners never see it on their own profile. */ export function RequestToJoinCollective({ profile, accentText = 'text-teal-400', accentBorder = 'border-teal-500', }: { profile: LabProfile; accentText?: string; accentBorder?: string; }) { const { user } = useCurrentUser(); const { toast } = useToast(); const [open, setOpen] = useState(false); const [note, setNote] = useState(''); const coord = `${profile.event.kind}:${profile.pubkey}:${profile.identifier}`; const { mutateAsync: send, isPending: sending } = useSendCollectiveJoinRequest(); const { data: alreadyRequested, isLoading: checking } = useMyCollectiveJoinRequest(coord); // Gate: must be logged in, not the owner, not already a listed member. if (!user) return null; const meLc = user.pubkey.toLowerCase(); if (meLc === profile.pubkey.toLowerCase()) return null; if (profile.members.some((m) => m.toLowerCase() === meLc)) return null; const handleSend = async () => { try { await send({ profile, note }); setOpen(false); setNote(''); toast({ title: 'Request sent 🤝', description: `${profile.title} will see it in their notifications and can add you.`, }); } catch (err) { toast({ title: 'Could not send request', description: err instanceof Error ? err.message : 'Please try again.', variant: 'destructive', }); } }; return (

Join this collective

{alreadyRequested ? (
Request sent — waiting on {profile.title}.
) : !open ? ( <>

Ask the crew behind {profile.title} to add you to the roster. They’ll get a notification and can add you in one tap.

) : (