mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 21:08:12 +00:00
per-user trade-direction access scope
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
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)),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user