Routes /app/animals, new, :animalId, edit under one workspace gate; list with species filter; form (D-R7, U3 birth, no default sex or role, optional first client); page with current and former relations, end, dates, void; client page links its animals, adds one pre-associated, links an existing one. Card now passes aria-labelledby, which it silently dropped.
51 lines
1.3 KiB
TypeScript
51 lines
1.3 KiB
TypeScript
import { useCallback } from 'react'
|
|
import {
|
|
searchAnimals,
|
|
searchClients,
|
|
type AnimalListItem,
|
|
type ClientListItem,
|
|
} from '@faunosteo/supabase'
|
|
import { getSupabaseClient } from '@/lib/supabase'
|
|
|
|
/** Matches shown at once: enough to pick from, the term narrows the rest. */
|
|
const CHOICES = 8
|
|
|
|
function backend() {
|
|
const client = getSupabaseClient()
|
|
if (!client) throw new TypeError('no backend')
|
|
return client
|
|
}
|
|
|
|
/** Active clients of the workspace for a term; only an active client can be linked (§7.1). */
|
|
export function useClientChoices(workspaceId: string) {
|
|
return useCallback(
|
|
async (term: string): Promise<ClientListItem[]> =>
|
|
(
|
|
await searchClients(backend(), {
|
|
workspaceId,
|
|
query: term,
|
|
archived: false,
|
|
pageSize: CHOICES,
|
|
})
|
|
).rows,
|
|
[workspaceId],
|
|
)
|
|
}
|
|
|
|
/** Active animals of the workspace for a term, every species. */
|
|
export function useAnimalChoices(workspaceId: string) {
|
|
return useCallback(
|
|
async (term: string): Promise<AnimalListItem[]> =>
|
|
(
|
|
await searchAnimals(backend(), {
|
|
workspaceId,
|
|
query: term,
|
|
speciesId: null,
|
|
archived: false,
|
|
pageSize: CHOICES,
|
|
})
|
|
).rows,
|
|
[workspaceId],
|
|
)
|
|
}
|