TorbatYar/frontend/modules/payment/hooks/usePaymentPermissions.ts
Mortezakoohjani 4451b32a33 feat(payment-frontend): ship Torbat Pay admin portal for MVP 14.0-14.5
Add payment module, BFF proxy, hub/dashboard/ops/PSP/merchant screens wired to real APIs, and mark payment-frontend complete in project status.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-27 18:35:07 +03:30

31 lines
1.0 KiB
TypeScript

"use client";
import { useMemo } from "react";
import { useQuery } from "@tanstack/react-query";
import { useTenantId } from "@/hooks/useTenantId";
import { paymentApi } from "@/modules/payment/services/payment-api";
type MembershipLike = { tenant_id?: string; permissions?: string[] };
export function usePaymentPermissions() {
const { tenantId, me } = useTenantId();
const catalog = useQuery({
queryKey: ["payment", tenantId, "permissions-catalog"],
queryFn: () => paymentApi.permissions.catalog(tenantId!),
enabled: !!tenantId,
staleTime: 60_000,
});
const membership = (me?.memberships as MembershipLike[] | undefined)?.find(
(m) => m.tenant_id === tenantId
);
const userPerms = useMemo(() => new Set(membership?.permissions ?? []), [membership]);
function can(permission: string) {
if (userPerms.size === 0) return true;
if (userPerms.has("payment.manage") || userPerms.has("*")) return true;
return userPerms.has(permission);
}
return { catalog, can, tenantId };
}