'use client'; import { useQuery } from '@tanstack/react-query'; import { getReservationQuota } from '@/lib/api/bookings'; import { useAuth } from '@/lib/context/auth-context'; /** * Reservation (paid shipment) quota for the current plan. * * The free (Bronze) plan is limited to a number of PAID reservations per year * (`maxShipmentsPerYear`, e.g. 5); higher plans are unlimited. The value comes * from the backend, which uses the organization's real plan (not the ADMIN * PLATINIUM override) and counts only paid shipments — so the UI can prompt an * upgrade once the limit is reached instead of failing at the end of the flow. */ export function useReservationQuota() { const { isAuthenticated } = useAuth(); const { data, isLoading } = useQuery({ queryKey: ['reservation-quota'], queryFn: getReservationQuota, enabled: isAuthenticated, staleTime: 30_000, }); const max = data?.max ?? -1; const used = data?.used ?? 0; const unlimited = data?.unlimited ?? true; const limitReached = data?.limitReached ?? false; return { loading: isLoading, max, used, remaining: unlimited ? Infinity : Math.max(0, max - used), unlimited, limitReached, blocked: limitReached, }; }