import { useState } from 'react' import { ArrowLeft, Briefcase, Mail, Phone, Plus, Star, UserCheck, UserMinus, UserPlus } from 'lucide-react' import { Link, useParams } from 'react-router-dom' import { ToolHeader } from '../../components/ToolHeader' import { Modal, Panel } from '../../components/ui' import { useAuth } from '../../lib/useAuth' import { recruitBrand } from './brand' import { useAddContact, useClaimClient, useClient, useReleaseClient, useUpdateClient, useUpdateContact, } from './clientQueries' const inputCls = 'w-full rounded-lg border border-line/70 bg-navy-900 px-3 py-2 text-sm text-ink outline-none focus:border-recruit' export function ClientDetail() { const { clientId } = useParams() const { principal } = useAuth() const q = useClient(clientId ?? null) const update = useUpdateClient() const claim = useClaimClient() const release = useReleaseClient() const addContact = useAddContact() const updateContact = useUpdateContact() const [editing, setEditing] = useState(false) const [industry, setIndustry] = useState('') const [notes, setNotes] = useState('') const [addOpen, setAddOpen] = useState(false) const [cName, setCName] = useState('') const [cTitle, setCTitle] = useState('') const [cEmail, setCEmail] = useState('') const [cHM, setCHM] = useState(false) if (q.isLoading) return Loading client… if (q.isError || !q.data) { return ( Could not load this client. {(q.error as Error)?.message} ) } const c = q.data const mine = !!c.owner_user_id && c.owner_user_id === principal?.user_id const unowned = !c.owner_user_id // The lock, stated plainly. Anyone may read; only the holder writes, and an unowned account is // claimable. An admin can still act, and the server is the authority on that, so this only shapes // what is offered rather than what is enforced. const canEdit = mine || unowned const saveEdits = () => { update.mutate( { id: c.id, patch: { expected_updated_at: c.updated_at, industry, notes } }, { onSuccess: () => setEditing(false) }, ) } const submitContact = () => { addContact.mutate( { clientId: c.id, patch: { full_name: cName, title: cTitle, email: cEmail, is_hiring_manager: cHM }, }, { onSuccess: () => { setCName('') setCTitle('') setCEmail('') setCHM(false) setAddOpen(false) }, }, ) } return (
All clients

{c.name}

{c.industry || 'No industry set'} · {c.status} {c.uei ? ` · UEI ${c.uei}` : ''}

{c.owner_user_id ? ( <> {mine ? 'You hold this account' : `Held by ${c.owner_name}`} {mine && ( )} ) : ( )}
{/* Someone else holds it. Say who, and say what to do about it, rather than only disabling the buttons and leaving the reason to be guessed. */} {!canEdit && (

{c.owner_name} is working this account. Talk to them before making changes, or ask an admin to reassign it.

)} {canEdit && !editing && ( )} {editing && (