Skip to content

The complete open source platform to run your entire marketplace. Storefront, vendor panel, admin console, and integrations in one enterprise-grade platform you own.

553 B
Raw Blame
import { useMemo } from "react"
import type { PermissionKey } from "@mercurjs/dashboard-sdk"
import { usePermissions } from "./use-permissions"

/**
 * @example
 * ```tsx
 * const { canEdit } = useResourcePermissions("products")
 * ```
 */
export const useResourcePermissions = (key: PermissionKey) => {
  const { can, isLoading } = usePermissions()

  return useMemo(
    () => ({
      canView: can(key, "view"),
      canEdit: can(key, "edit"),
      canManage: can(key, "manage"),
      key,
      isLoading,
    }),
    [can, key, isLoading]
  )
}