All files / src/features/babies/api invites.hooks.ts

83.33% Statements 5/6
0% Branches 0/4
83.33% Functions 5/6
83.33% Lines 5/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27              15x       15x   6x                 15x 4x      
import { useMutation, useQuery } from '@tanstack/react-query'
 
import { ApiError } from '@/lib/http-client'
 
import { fetchInvitePreview, redeemInvite } from './invites.api'
 
export function inviteQueryKey(code: string) {
  return ['invites', code] as const
}
 
export function useInvitePreview(code: string) {
  return useQuery({
    queryKey: inviteQueryKey(code),
    queryFn: () => fetchInvitePreview(code),
    enabled: !!code,
    // A 404 (unknown code) is a definitive answer, not a transient failure —
    // don't burn retries on it (mirrors the global default in query-client.ts).
    retry: (failureCount, error) => !(error instanceof ApiError && error.status === 404) && failureCount < 2,
  })
}
 
export function useRedeemInvite(code: string) {
  return useMutation({
    mutationFn: () => redeemInvite(code),
  })
}