mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-27 00:52:50 +00:00
33 lines
994 B
TypeScript
33 lines
994 B
TypeScript
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: <T extends { value: string }>(options: T[]): T[] =>
|
|
options.filter((o) => directions.includes(o.value as TradeDirection)),
|
|
};
|
|
}
|