'use client'; import React, { useState } from 'react'; import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'; import { Plus, Loader2, AlertCircle, Users, Trash2 } from 'lucide-react'; import { FaYoutube } from 'react-icons/fa'; import { SiTwitch, SiInstagram, SiTiktok, SiX, SiBluesky, SiDiscord } from 'react-icons/si'; import { fetchCollaborators, deleteCollaborator, type Collaborator } from '@/lib/api'; import CollaboratorModal, { PLATFORMS, type PlatformKey } from '@/components/shared/CollaboratorModal'; import styles from './page.module.css'; // ─── Platforms cell ─────────────────────────────────────────────────────────── const PLATFORM_ICON: Record = { youtubeLink: , twitchLink: , instagramLink: , tiktokLink: , twitterLink: , blueskyLink: , discordHandle: , }; function PlatformsCell({ c }: { c: Collaborator }) { const links = PLATFORMS.filter((p) => !!c[p.key]); if (links.length === 0) return ; return (
{links.map((p) => { const val = c[p.key]; if (p.urlField && val) { return ( {PLATFORM_ICON[p.key]} ); } return ( {PLATFORM_ICON[p.key]} ); })}
); } // ─── Page ───────────────────────────────────────────────────────────────────── export default function CollaboratorsPage() { const qc = useQueryClient(); const [modal, setModal] = useState<'create' | Collaborator | null>(null); const [confirmDelete, setConfirmDelete] = useState(null); const [deleteError, setDeleteError] = useState(null); const deleteMut = useMutation({ mutationFn: deleteCollaborator, onSuccess: () => { qc.invalidateQueries({ queryKey: ['collaborators'] }); setConfirmDelete(null); setDeleteError(null); }, onError: (e: unknown) => setDeleteError((e as { response?: { data?: { message?: string } } })?.response?.data?.message ?? 'Delete failed'), }); const { data: collaborators = [], isLoading, isError } = useQuery({ queryKey: ['collaborators'], queryFn: fetchCollaborators, }); return (
People & Partners

Collaborators {collaborators.length > 0 && {collaborators.length}}

{isLoading &&
Loading collaborators…
} {isError &&
Failed to load collaborators — is the backend running?
} {!isLoading && !isError && collaborators.length === 0 && (

No collaborators yet.

Add guest creators and partners to use them in your description blocks.

)} {!isLoading && !isError && collaborators.length > 0 && (
{collaborators.map((c) => ( ))}
Name Platforms Aliases Status
{c.name.charAt(0).toUpperCase()}
{c.name} {c.notes && {c.notes}}
{c.aliases.slice(0, 2).map((a) => {a})} {c.aliases.length > 2 && +{c.aliases.length - 2}}
{c.active ? Active : Inactive} {confirmDelete === c.id ? (
{deleteError ? {deleteError} : Delete?}
) : (
)}
)} {modal !== null && ( setModal(null)} /> )}
); }