Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/missionmatch / frontend/src/tools/recruitmatch/clientQueries.ts |
| Date | Not specified in source |
| Repository | Janady13/missionmatch |
| Revision | 720d47fae476b0d38477ae4401697d372b1ea2bc |
| Branch | feature/opportunity-to-outcome |
| Path or archive member | frontend/src/tools/recruitmatch/clientQueries.ts |
| Original SHA-256 | a7fbe3e3e5dcfe085ec9e1f41467894d03a6e3de8f5adb4ae4015e0f0f97ab98 |
| Git blob SHA | a1650e085ea82a122218059676e49d6f8451be4e |
| Reading-copy SHA-256 | a7fbe3e3e5dcfe085ec9e1f41467894d03a6e3de8f5adb4ae4015e0f0f97ab98 |
Every recorded occurrence
These 2 records contain identical original source bytes. Their paths and revisions remain part of the archive.
| Original record | Branch or archive | Revision / identifier | Original location |
|---|---|---|---|
| Janady13/missionmatch / frontend/src/tools/recruitmatch/clientQueries.ts | feature/opportunity-to-outcome | 720d47fae476b0d38477ae4401697d372b1ea2bc | Open original |
| Janady13/missionmatch / frontend/src/tools/recruitmatch/clientQueries.ts | feature/aioe-upgrade | 2178e7298d0e5d9af83afa12402fd587f0ba6ed8 | Open original |
Recovered source transcript
Download complete source text ↓72 lines · 2.3 KB
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import { clientsApi } from './clientsApi'
type ListParams = { status?: string; q?: string; owner?: string }
export function useClients(p: ListParams) {
return useQuery({
queryKey: ['recruitmatch', 'clients', p.status ?? '', p.q ?? '', p.owner ?? ''],
queryFn: () => clientsApi.list(p),
})
}
export function useClient(id: string | null) {
return useQuery({
queryKey: ['recruitmatch', 'client', id],
queryFn: () => clientsApi.get(id as string),
enabled: !!id,
})
}
// Every mutation invalidates BOTH the list and the detail. An ownership change alters the row shown in
// the list as well as the one on screen, and leaving the list stale would show a client as unassigned
// seconds after someone claimed it.
function useInvalidate() {
const qc = useQueryClient()
return (id?: string) => {
void qc.invalidateQueries({ queryKey: ['recruitmatch', 'clients'] })
if (id) void qc.invalidateQueries({ queryKey: ['recruitmatch', 'client', id] })
}
}
export function useCreateClient() {
const inv = useInvalidate()
return useMutation({ mutationFn: clientsApi.create, onSuccess: () => inv() })
}
export function useUpdateClient() {
const inv = useInvalidate()
return useMutation({
mutationFn: (v: { id: string; patch: Record<string, unknown> }) => clientsApi.update(v.id, v.patch),
onSuccess: (_d, v) => inv(v.id),
})
}
export function useClaimClient() {
const inv = useInvalidate()
return useMutation({ mutationFn: (id: string) => clientsApi.claim(id), onSuccess: (_d, id) => inv(id) })
}
export function useReleaseClient() {
const inv = useInvalidate()
return useMutation({ mutationFn: (id: string) => clientsApi.release(id), onSuccess: (_d, id) => inv(id) })
}
export function useAddContact() {
const inv = useInvalidate()
return useMutation({
mutationFn: (v: { clientId: string; patch: Record<string, unknown> }) => clientsApi.addContact(v.clientId, v.patch),
onSuccess: (_d, v) => inv(v.clientId),
})
}
export function useUpdateContact() {
const inv = useInvalidate()
return useMutation({
mutationFn: (v: { id: string; clientId: string; patch: Record<string, unknown> }) =>
clientsApi.updateContact(v.id, v.patch),
onSuccess: (_d, v) => inv(v.clientId),
})
}