Replug organizations page without assume or user dropdown

Signed-off-by: Émile Ré <nemile.re@gmail.com>
This commit is contained in:
Émile Ré
2025-12-19 19:46:20 +01:00
committed by Bryan Frimin
parent e4df37b5c8
commit 4218200409
25 changed files with 1286 additions and 938 deletions

View File

@@ -1,31 +1,41 @@
import { useSuspenseQuery } from "@tanstack/react-query";
import { type PropsWithChildren } from "react";
import { useOrganizationId } from "/hooks/useOrganizationId";
import { PermissionsContext, type PermissionsResponse } from "./PermissionsContext";
import { PermissionsContext } from "./PermissionsContext";
import { Role } from "@probo/helpers";
export function PermissionsProvider(props: PropsWithChildren) {
const { children } = props;
const organizationId = useOrganizationId();
// const organizationId = useOrganizationId();
const { data } = useSuspenseQuery<PermissionsResponse>({
queryKey: ["permissions", organizationId],
queryFn: async () => {
const response = await fetch(`/authz/${organizationId}/permissions`, { credentials: "include" });
if (!response.ok) {
throw new Error("Failed to fetch permissions");
}
return response.json() as Promise<PermissionsResponse>;
},
});
// const { data } = useSuspenseQuery<PermissionsResponse>({
// queryKey: ["permissions", organizationId],
// queryFn: async () => {
// const response = await fetch(`/authz/${organizationId}/permissions`, { credentials: "include" });
// if (!response.ok) {
// throw new Error("Failed to fetch permissions");
// }
// return response.json() as Promise<PermissionsResponse>;
// },
// });
// @ts-expect-error wip refactor
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const isAuthorized = (entity: string, action: string) => {
return data.permissions[entity]?.[action] ?? false;
}
// return data.permissions[entity]?.[action] ?? false;
return true;
};
return (
<PermissionsContext value={{ ...data, isAuthorized }}>
<PermissionsContext
value={{ permissions: {}, role: Role.OWNER, isAuthorized }}
>
{children}
</PermissionsContext>
);
// return (
// <PermissionsContext value={{ ...data, isAuthorized }}>
// {children}
// </PermissionsContext>
// );
}