mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 12:27:28 +00:00
feat(infisical-pg): new org role routes completed
This commit is contained in:
@@ -19,7 +19,8 @@
|
|||||||
"migration:latest": "knex --knexfile ./src/db/knexfile.ts --client pg migrate:latest",
|
"migration:latest": "knex --knexfile ./src/db/knexfile.ts --client pg migrate:latest",
|
||||||
"migration:rollback": "knex --knexfile ./src/db/knexfile.ts migrate:rollback",
|
"migration:rollback": "knex --knexfile ./src/db/knexfile.ts migrate:rollback",
|
||||||
"seed:new": "tsx ./scripts/create-seed-file.ts",
|
"seed:new": "tsx ./scripts/create-seed-file.ts",
|
||||||
"seed:run": "knex --knexfile ./src/db/knexfile.ts --client pg seed:run"
|
"seed:run": "knex --knexfile ./src/db/knexfile.ts --client pg seed:run",
|
||||||
|
"db:reset": "npm run migration:rollback -- --all && npm run migration:latest && npm run seed:run"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "",
|
"author": "",
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export async function up(knex: Knex): Promise<void> {
|
|||||||
t.string("name").notNullable();
|
t.string("name").notNullable();
|
||||||
t.string("description");
|
t.string("description");
|
||||||
t.string("slug").notNullable();
|
t.string("slug").notNullable();
|
||||||
t.json("permissions").notNullable();
|
t.jsonb("permissions").notNullable();
|
||||||
// does not need update trigger we will do it manually
|
// does not need update trigger we will do it manually
|
||||||
t.timestamps(true, true, true);
|
t.timestamps(true, true, true);
|
||||||
t.uuid("orgId").notNullable();
|
t.uuid("orgId").notNullable();
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ export const registerOrgRoleRouter = async (server: FastifyZodProvider) => {
|
|||||||
name: z.string().trim(),
|
name: z.string().trim(),
|
||||||
description: z.string().trim().optional(),
|
description: z.string().trim().optional(),
|
||||||
workspaceId: z.string().trim().optional(),
|
workspaceId: z.string().trim().optional(),
|
||||||
orgId: z.string().trim(),
|
|
||||||
permissions: z.any().array()
|
permissions: z.any().array()
|
||||||
}),
|
}),
|
||||||
response: {
|
response: {
|
||||||
@@ -31,7 +30,7 @@ export const registerOrgRoleRouter = async (server: FastifyZodProvider) => {
|
|||||||
const role = await server.services.orgRole.createRole(
|
const role = await server.services.orgRole.createRole(
|
||||||
req.auth.userId,
|
req.auth.userId,
|
||||||
req.params.organizationId,
|
req.params.organizationId,
|
||||||
{ ...req.body, permissions: JSON.stringify(req.body.permissions) }
|
req.body
|
||||||
);
|
);
|
||||||
return { role };
|
return { role };
|
||||||
}
|
}
|
||||||
@@ -49,8 +48,6 @@ export const registerOrgRoleRouter = async (server: FastifyZodProvider) => {
|
|||||||
slug: z.string().trim().optional(),
|
slug: z.string().trim().optional(),
|
||||||
name: z.string().trim().optional(),
|
name: z.string().trim().optional(),
|
||||||
description: z.string().trim().optional(),
|
description: z.string().trim().optional(),
|
||||||
workspaceId: z.string().trim().optional(),
|
|
||||||
orgId: z.string().trim(),
|
|
||||||
permissions: z.any().array()
|
permissions: z.any().array()
|
||||||
}),
|
}),
|
||||||
response: {
|
response: {
|
||||||
@@ -108,10 +105,12 @@ export const registerOrgRoleRouter = async (server: FastifyZodProvider) => {
|
|||||||
}),
|
}),
|
||||||
response: {
|
response: {
|
||||||
200: z.object({
|
200: z.object({
|
||||||
|
data: z.object({
|
||||||
roles: OrgRolesSchema.omit({ permissions: true })
|
roles: OrgRolesSchema.omit({ permissions: true })
|
||||||
.merge(z.object({ permissions: z.unknown() }))
|
.merge(z.object({ permissions: z.unknown() }))
|
||||||
.array()
|
.array()
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onRequest: verifyAuth([AuthMode.JWT]),
|
onRequest: verifyAuth([AuthMode.JWT]),
|
||||||
@@ -120,7 +119,7 @@ export const registerOrgRoleRouter = async (server: FastifyZodProvider) => {
|
|||||||
req.auth.userId,
|
req.auth.userId,
|
||||||
req.params.organizationId
|
req.params.organizationId
|
||||||
);
|
);
|
||||||
return { roles };
|
return { data: { roles } };
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -36,8 +36,11 @@ export const orgRoleServiceFactory = ({
|
|||||||
);
|
);
|
||||||
const existingRole = await orgRoleDal.findOne({ slug: data.slug, orgId });
|
const existingRole = await orgRoleDal.findOne({ slug: data.slug, orgId });
|
||||||
if (existingRole) throw new BadRequestError({ name: "Create Role", message: "Duplicate role" });
|
if (existingRole) throw new BadRequestError({ name: "Create Role", message: "Duplicate role" });
|
||||||
|
const role = await orgRoleDal.create({
|
||||||
const role = await orgRoleDal.create({ ...data, orgId });
|
...data,
|
||||||
|
orgId,
|
||||||
|
permissions: JSON.stringify(data.permissions)
|
||||||
|
});
|
||||||
return role;
|
return role;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -83,8 +86,8 @@ export const orgRoleServiceFactory = ({
|
|||||||
const customRoles = await orgRoleDal.find({ orgId });
|
const customRoles = await orgRoleDal.find({ orgId });
|
||||||
const roles = [
|
const roles = [
|
||||||
{
|
{
|
||||||
id: "admin",
|
id: "b11b49a9-09a9-4443-916a-4246f9ff2c69", // dummy userid
|
||||||
orgId: "",
|
orgId,
|
||||||
name: "Admin",
|
name: "Admin",
|
||||||
slug: "admin",
|
slug: "admin",
|
||||||
description: "Complete administration access over the organization",
|
description: "Complete administration access over the organization",
|
||||||
@@ -93,8 +96,8 @@ export const orgRoleServiceFactory = ({
|
|||||||
updatedAt: new Date()
|
updatedAt: new Date()
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "member",
|
id: "b11b49a9-09a9-4443-916a-4246f9ff2c70", // dummy user for zod validation in response
|
||||||
orgId: "",
|
orgId,
|
||||||
name: "Member",
|
name: "Member",
|
||||||
slug: "member",
|
slug: "member",
|
||||||
description: "Non-administrative role in an organization",
|
description: "Non-administrative role in an organization",
|
||||||
|
|||||||
@@ -1,2 +1,14 @@
|
|||||||
export { useCreateRole, useDeleteRole, useUpdateRole } from "./mutation";
|
export {
|
||||||
export { useGetRoles, useGetUserOrgPermissions,useGetUserProjectPermissions } from "./queries";
|
useCreateOrgRole,
|
||||||
|
useCreateRole,
|
||||||
|
useDeleteOrgRole,
|
||||||
|
useDeleteRole,
|
||||||
|
useUpdateOrgRole,
|
||||||
|
useUpdateRole
|
||||||
|
} from "./mutation";
|
||||||
|
export {
|
||||||
|
useGetOrgRoles,
|
||||||
|
useGetRoles,
|
||||||
|
useGetUserOrgPermissions,
|
||||||
|
useGetUserProjectPermissions
|
||||||
|
} from "./queries";
|
||||||
|
|||||||
@@ -1,9 +1,17 @@
|
|||||||
|
import { packRules } from "@casl/ability/extra";
|
||||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
|
|
||||||
import { apiRequest } from "@app/config/request";
|
import { apiRequest } from "@app/config/request";
|
||||||
|
|
||||||
import { roleQueryKeys } from "./queries";
|
import { roleQueryKeys } from "./queries";
|
||||||
import { TCreateRoleDTO, TDeleteRoleDTO, TUpdateRoleDTO } from "./types";
|
import {
|
||||||
|
TCreateOrgRoleDTO,
|
||||||
|
TCreateRoleDTO,
|
||||||
|
TDeleteOrgRoleDTO,
|
||||||
|
TDeleteRoleDTO,
|
||||||
|
TUpdateOrgRoleDTO,
|
||||||
|
TUpdateRoleDTO
|
||||||
|
} from "./types";
|
||||||
|
|
||||||
export const useCreateRole = <T extends string | undefined>() => {
|
export const useCreateRole = <T extends string | undefined>() => {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
@@ -40,3 +48,47 @@ export const useDeleteRole = () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const useCreateOrgRole = () => {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: ({ orgId, permissions, ...dto }: TCreateOrgRoleDTO) =>
|
||||||
|
apiRequest.post(`/api/ee/v1/organization/${orgId}/roles`, {
|
||||||
|
...dto,
|
||||||
|
permissions: permissions.length ? packRules(permissions) : []
|
||||||
|
}),
|
||||||
|
onSuccess: (_, { orgId }) => {
|
||||||
|
queryClient.invalidateQueries(roleQueryKeys.getOrgRoles(orgId));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useUpdateOrgRole = () => {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: ({ id, orgId, permissions, ...dto }: TUpdateOrgRoleDTO) =>
|
||||||
|
apiRequest.patch(`/api/ee/v1/organization/${orgId}/roles/${id}`, {
|
||||||
|
...dto,
|
||||||
|
permissions: permissions?.length ? packRules(permissions) : undefined
|
||||||
|
}),
|
||||||
|
onSuccess: (_, { orgId }) => {
|
||||||
|
queryClient.invalidateQueries(roleQueryKeys.getOrgRoles(orgId));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useDeleteOrgRole = () => {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: ({ orgId, id }: TDeleteOrgRoleDTO) =>
|
||||||
|
apiRequest.delete(`/api/ee/v1/organization/${orgId}/roles/${id}`, {
|
||||||
|
data: { orgId }
|
||||||
|
}),
|
||||||
|
onSuccess: (_, { orgId }) => {
|
||||||
|
queryClient.invalidateQueries(roleQueryKeys.getOrgRoles(orgId));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ import {
|
|||||||
TGetRolesDTO,
|
TGetRolesDTO,
|
||||||
TGetUserOrgPermissionsDTO,
|
TGetUserOrgPermissionsDTO,
|
||||||
TGetUserProjectPermissionDTO,
|
TGetUserProjectPermissionDTO,
|
||||||
|
TOrgRole,
|
||||||
|
TPermission,
|
||||||
TRole
|
TRole
|
||||||
} from "./types";
|
} from "./types";
|
||||||
|
|
||||||
@@ -36,6 +38,7 @@ const conditionsMatcher = buildMongoQueryMatcher({ $glob }, { glob });
|
|||||||
|
|
||||||
export const roleQueryKeys = {
|
export const roleQueryKeys = {
|
||||||
getRoles: ({ orgId, workspaceId }: TGetRolesDTO) => ["roles", { orgId, workspaceId }] as const,
|
getRoles: ({ orgId, workspaceId }: TGetRolesDTO) => ["roles", { orgId, workspaceId }] as const,
|
||||||
|
getOrgRoles: (orgId: string) => ["org-roles", { orgId }] as const,
|
||||||
getUserOrgPermissions: ({ orgId }: TGetUserOrgPermissionsDTO) =>
|
getUserOrgPermissions: ({ orgId }: TGetUserOrgPermissionsDTO) =>
|
||||||
["user-permissions", { orgId }] as const,
|
["user-permissions", { orgId }] as const,
|
||||||
getUserProjectPermissions: ({ workspaceId }: TGetUserProjectPermissionDTO) =>
|
getUserProjectPermissions: ({ workspaceId }: TGetUserProjectPermissionDTO) =>
|
||||||
@@ -63,6 +66,23 @@ export const useGetRoles = ({ orgId, workspaceId }: TGetRolesDTO) =>
|
|||||||
enabled: Boolean(orgId)
|
enabled: Boolean(orgId)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const getOrgRoles = async (orgId: string) => {
|
||||||
|
const { data } = await apiRequest.get<{
|
||||||
|
data: { roles: Array<Omit<TOrgRole, "permissions"> & { permissions: unknown }> };
|
||||||
|
}>(`/api/ee/v1/organization/${orgId}/roles`);
|
||||||
|
return data.data.roles.map(({ permissions, ...el }) => ({
|
||||||
|
...el,
|
||||||
|
permissions: unpackRules(permissions as PackRule<TPermission>[])
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useGetOrgRoles = (orgId: string, enable = true) =>
|
||||||
|
useQuery({
|
||||||
|
queryKey: roleQueryKeys.getOrgRoles(orgId),
|
||||||
|
queryFn: () => getOrgRoles(orgId),
|
||||||
|
enabled: Boolean(orgId) && enable
|
||||||
|
});
|
||||||
|
|
||||||
const getUserOrgPermissions = async ({ orgId }: TGetUserOrgPermissionsDTO) => {
|
const getUserOrgPermissions = async ({ orgId }: TGetUserOrgPermissionsDTO) => {
|
||||||
if (orgId === "") return { permissions: [], membership: null };
|
if (orgId === "") return { permissions: [], membership: null };
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ export type TGetRolesDTO = {
|
|||||||
workspaceId?: string;
|
workspaceId?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// @depreciated
|
||||||
export type TRole<T extends string | undefined> = {
|
export type TRole<T extends string | undefined> = {
|
||||||
id: string;
|
id: string;
|
||||||
organization: string;
|
organization: string;
|
||||||
@@ -15,6 +16,17 @@ export type TRole<T extends string | undefined> = {
|
|||||||
updatedAt: string;
|
updatedAt: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type TOrgRole = {
|
||||||
|
slug: string;
|
||||||
|
name: string;
|
||||||
|
orgId: string;
|
||||||
|
id: string;
|
||||||
|
createdAt: string;
|
||||||
|
updatedAt: string;
|
||||||
|
description?: string;
|
||||||
|
permissions: TPermission[];
|
||||||
|
};
|
||||||
|
|
||||||
export type TPermission = {
|
export type TPermission = {
|
||||||
conditions?: Record<string, any>;
|
conditions?: Record<string, any>;
|
||||||
action: string;
|
action: string;
|
||||||
@@ -55,3 +67,21 @@ export type TGetUserOrgPermissionsDTO = {
|
|||||||
export type TGetUserProjectPermissionDTO = {
|
export type TGetUserProjectPermissionDTO = {
|
||||||
workspaceId: string;
|
workspaceId: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type TCreateOrgRoleDTO = {
|
||||||
|
orgId: string;
|
||||||
|
name: string;
|
||||||
|
description?: string;
|
||||||
|
slug: string;
|
||||||
|
permissions: TPermission[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export type TUpdateOrgRoleDTO = {
|
||||||
|
orgId: string;
|
||||||
|
id: string;
|
||||||
|
} & Partial<Omit<TCreateOrgRoleDTO, "orgId">>;
|
||||||
|
|
||||||
|
export type TDeleteOrgRoleDTO = {
|
||||||
|
orgId: string;
|
||||||
|
id: string;
|
||||||
|
};
|
||||||
|
|||||||
+2
-3
@@ -30,6 +30,7 @@ import {
|
|||||||
import {
|
import {
|
||||||
useAddUserToOrg,
|
useAddUserToOrg,
|
||||||
useFetchServerStatus,
|
useFetchServerStatus,
|
||||||
|
useGetOrgRoles,
|
||||||
useGetOrgUsers,
|
useGetOrgUsers,
|
||||||
useGetRoles,
|
useGetRoles,
|
||||||
useUpdateOrgUserRole
|
useUpdateOrgUserRole
|
||||||
@@ -56,9 +57,7 @@ export const OrgMembersTable = ({ handlePopUpOpen, setCompleteInviteLink }: Prop
|
|||||||
const userId = user?.id || "";
|
const userId = user?.id || "";
|
||||||
const orgId = currentOrg?.id || "";
|
const orgId = currentOrg?.id || "";
|
||||||
|
|
||||||
const { data: roles, isLoading: isRolesLoading } = useGetRoles({
|
const { data: roles, isLoading: isRolesLoading } = useGetOrgRoles(orgId);
|
||||||
orgId
|
|
||||||
});
|
|
||||||
|
|
||||||
const [searchMemberFilter, setSearchMemberFilter] = useState("");
|
const [searchMemberFilter, setSearchMemberFilter] = useState("");
|
||||||
|
|
||||||
|
|||||||
+7
-6
@@ -8,15 +8,16 @@ import {
|
|||||||
faServer,
|
faServer,
|
||||||
faSignIn,
|
faSignIn,
|
||||||
faUserCog,
|
faUserCog,
|
||||||
faUsers} from "@fortawesome/free-solid-svg-icons";
|
faUsers
|
||||||
|
} from "@fortawesome/free-solid-svg-icons";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
|
|
||||||
import { useNotificationContext } from "@app/components/context/Notifications/NotificationProvider";
|
import { useNotificationContext } from "@app/components/context/Notifications/NotificationProvider";
|
||||||
import { Button, FormControl, Input } from "@app/components/v2";
|
import { Button, FormControl, Input } from "@app/components/v2";
|
||||||
import { useOrganization } from "@app/context";
|
import { useOrganization } from "@app/context";
|
||||||
import { useCreateRole, useUpdateRole } from "@app/hooks/api";
|
import { useCreateOrgRole, useUpdateOrgRole } from "@app/hooks/api";
|
||||||
import { TRole } from "@app/hooks/api/roles/types";
|
import { TOrgRole } from "@app/hooks/api/roles/types";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
formRolePermission2API,
|
formRolePermission2API,
|
||||||
@@ -28,7 +29,7 @@ import { SimpleLevelPermissionOption } from "./SimpleLevelPermissionOptions";
|
|||||||
import { WorkspacePermission } from "./WorkspacePermission";
|
import { WorkspacePermission } from "./WorkspacePermission";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
role?: TRole<undefined>;
|
role?: TOrgRole;
|
||||||
onGoBack: VoidFunction;
|
onGoBack: VoidFunction;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -101,8 +102,8 @@ export const OrgRoleModifySection = ({ role, onGoBack }: Props) => {
|
|||||||
resolver: zodResolver(formSchema)
|
resolver: zodResolver(formSchema)
|
||||||
});
|
});
|
||||||
|
|
||||||
const { mutateAsync: createRole } = useCreateRole();
|
const { mutateAsync: createRole } = useCreateOrgRole();
|
||||||
const { mutateAsync: updateRole } = useUpdateRole();
|
const { mutateAsync: updateRole } = useUpdateOrgRole();
|
||||||
|
|
||||||
const handleRoleUpdate = async (el: TFormSchema) => {
|
const handleRoleUpdate = async (el: TFormSchema) => {
|
||||||
if (!role?.id) return;
|
if (!role?.id) return;
|
||||||
|
|||||||
+1
-1
@@ -32,7 +32,7 @@ export const formSchema = z.object({
|
|||||||
"secret-scanning": generalPermissionSchema,
|
"secret-scanning": generalPermissionSchema,
|
||||||
sso: generalPermissionSchema,
|
sso: generalPermissionSchema,
|
||||||
billing: generalPermissionSchema,
|
billing: generalPermissionSchema,
|
||||||
"identity": generalPermissionSchema
|
identity: generalPermissionSchema
|
||||||
})
|
})
|
||||||
.optional()
|
.optional()
|
||||||
});
|
});
|
||||||
|
|||||||
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
import { motion } from "framer-motion";
|
import { motion } from "framer-motion";
|
||||||
|
|
||||||
import { usePopUp } from "@app/hooks";
|
import { usePopUp } from "@app/hooks";
|
||||||
import { TRole } from "@app/hooks/api/roles/types";
|
import { TOrgRole } from "@app/hooks/api/roles/types";
|
||||||
|
|
||||||
import { OrgRoleModifySection } from "./OrgRoleModifySection";
|
import { OrgRoleModifySection } from "./OrgRoleModifySection";
|
||||||
import { OrgRoleTable } from "./OrgRoleTable";
|
import { OrgRoleTable } from "./OrgRoleTable";
|
||||||
@@ -17,7 +17,7 @@ export const OrgRoleTabSection = () => {
|
|||||||
exit={{ opacity: 0, translateX: 30 }}
|
exit={{ opacity: 0, translateX: 30 }}
|
||||||
>
|
>
|
||||||
<OrgRoleModifySection
|
<OrgRoleModifySection
|
||||||
role={popUp.editRole.data as TRole<undefined>}
|
role={popUp.editRole.data as TOrgRole}
|
||||||
onGoBack={() => handlePopUpClose("editRole")}
|
onGoBack={() => handlePopUpClose("editRole")}
|
||||||
/>
|
/>
|
||||||
</motion.div>
|
</motion.div>
|
||||||
|
|||||||
@@ -20,11 +20,11 @@ import {
|
|||||||
} from "@app/components/v2";
|
} from "@app/components/v2";
|
||||||
import { OrgPermissionActions, OrgPermissionSubjects, useOrganization } from "@app/context";
|
import { OrgPermissionActions, OrgPermissionSubjects, useOrganization } from "@app/context";
|
||||||
import { usePopUp } from "@app/hooks";
|
import { usePopUp } from "@app/hooks";
|
||||||
import { useDeleteRole, useGetRoles } from "@app/hooks/api";
|
import { useDeleteOrgRole, useGetOrgRoles } from "@app/hooks/api";
|
||||||
import { TRole } from "@app/hooks/api/roles/types";
|
import { TOrgRole } from "@app/hooks/api/roles/types";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
onSelectRole: (role?: TRole<undefined>) => void;
|
onSelectRole: (role?: TOrgRole) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const OrgRoleTable = ({ onSelectRole }: Props) => {
|
export const OrgRoleTable = ({ onSelectRole }: Props) => {
|
||||||
@@ -34,14 +34,12 @@ export const OrgRoleTable = ({ onSelectRole }: Props) => {
|
|||||||
const { createNotification } = useNotificationContext();
|
const { createNotification } = useNotificationContext();
|
||||||
const { popUp, handlePopUpOpen, handlePopUpClose } = usePopUp(["deleteRole"] as const);
|
const { popUp, handlePopUpOpen, handlePopUpClose } = usePopUp(["deleteRole"] as const);
|
||||||
|
|
||||||
const { data: roles, isLoading: isRolesLoading } = useGetRoles({
|
const { data: roles, isLoading: isRolesLoading } = useGetOrgRoles(orgId);
|
||||||
orgId
|
|
||||||
});
|
|
||||||
|
|
||||||
const { mutateAsync: deleteRole } = useDeleteRole();
|
const { mutateAsync: deleteRole } = useDeleteOrgRole();
|
||||||
|
|
||||||
const handleRoleDelete = async () => {
|
const handleRoleDelete = async () => {
|
||||||
const { id } = popUp?.deleteRole?.data as TRole<undefined>;
|
const { id } = popUp?.deleteRole?.data as TOrgRole;
|
||||||
try {
|
try {
|
||||||
await deleteRole({
|
await deleteRole({
|
||||||
orgId,
|
orgId,
|
||||||
@@ -90,7 +88,7 @@ export const OrgRoleTable = ({ onSelectRole }: Props) => {
|
|||||||
</THead>
|
</THead>
|
||||||
<TBody>
|
<TBody>
|
||||||
{isRolesLoading && <TableSkeleton columns={4} innerKey="org-roles" />}
|
{isRolesLoading && <TableSkeleton columns={4} innerKey="org-roles" />}
|
||||||
{(roles as TRole<undefined>[])?.map((role) => {
|
{roles?.map((role) => {
|
||||||
const { id, name, slug } = role;
|
const { id, name, slug } = role;
|
||||||
const isNonMutatable = ["owner", "admin", "member", "no-access"].includes(slug);
|
const isNonMutatable = ["owner", "admin", "member", "no-access"].includes(slug);
|
||||||
|
|
||||||
@@ -148,9 +146,9 @@ export const OrgRoleTable = ({ onSelectRole }: Props) => {
|
|||||||
<DeleteActionModal
|
<DeleteActionModal
|
||||||
isOpen={popUp.deleteRole.isOpen}
|
isOpen={popUp.deleteRole.isOpen}
|
||||||
title={`Are you sure want to delete ${
|
title={`Are you sure want to delete ${
|
||||||
(popUp?.deleteRole?.data as TRole<undefined>)?.name || " "
|
(popUp?.deleteRole?.data as TOrgRole)?.name || " "
|
||||||
} role?`}
|
} role?`}
|
||||||
deleteKey={(popUp?.deleteRole?.data as TRole<undefined>)?.slug || ""}
|
deleteKey={(popUp?.deleteRole?.data as TOrgRole)?.slug || ""}
|
||||||
onClose={() => handlePopUpClose("deleteRole")}
|
onClose={() => handlePopUpClose("deleteRole")}
|
||||||
onDeleteApproved={handleRoleDelete}
|
onDeleteApproved={handleRoleDelete}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user