import { useQuery } from "@tanstack/react-query"; import { ALL_TRADE_DIRECTIONS, userTradeAccessService, type TradeDirection, } from "@/services/userTradeAccess.service"; /** * Current user's trade-direction scope. While loading (or on error) it * reports full access — the API enforces the real scope regardless; this * hook only trims filter dropdowns to the directions the user can see. */ export function useMyTradeAccess() { const { data } = useQuery({ queryKey: ["user-trade-access", "me"], queryFn: userTradeAccessService.me, staleTime: 5 * 60 * 1000, }); const directions: TradeDirection[] = data?.directions ?? [ ...ALL_TRADE_DIRECTIONS, ]; return { restricted: data?.restricted ?? false, directions, /** Trim `{ value }`-shaped dropdown options to the allowed directions. */ filterOptions: (options: T[]): T[] => options.filter((o) => directions.includes(o.value as TradeDirection)), }; }