mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 20:27:43 +00:00
Make progress on org role detail modal
This commit is contained in:
@@ -27,7 +27,8 @@ import {
|
|||||||
} from "@app/hooks/api";
|
} from "@app/hooks/api";
|
||||||
import { usePopUp } from "@app/hooks/usePopUp";
|
import { usePopUp } from "@app/hooks/usePopUp";
|
||||||
|
|
||||||
import { RoleDetailsSection } from "./components";
|
import { RolePermissionsTable } from "./components/RolePermissionsSection/RolePermissionsTable";
|
||||||
|
import { RoleDetailsSection, RolePermissionsSection } from "./components";
|
||||||
|
|
||||||
// import { IdentityAuthMethodModal } from "../MembersPage/components/OrgIdentityTab/components/IdentitySection/IdentityAuthMethodModal";
|
// import { IdentityAuthMethodModal } from "../MembersPage/components/OrgIdentityTab/components/IdentitySection/IdentityAuthMethodModal";
|
||||||
// import { IdentityModal } from "../MembersPage/components/OrgIdentityTab/components/IdentitySection/IdentityModal";
|
// import { IdentityModal } from "../MembersPage/components/OrgIdentityTab/components/IdentitySection/IdentityModal";
|
||||||
@@ -201,8 +202,7 @@ export const RolePage = withPermission(
|
|||||||
<div className="mr-4 w-96">
|
<div className="mr-4 w-96">
|
||||||
<RoleDetailsSection roleId={roleId} handlePopUpOpen={handlePopUpOpen} />
|
<RoleDetailsSection roleId={roleId} handlePopUpOpen={handlePopUpOpen} />
|
||||||
</div>
|
</div>
|
||||||
Permissions Section
|
<RolePermissionsSection />
|
||||||
{/* <IdentityProjectsSection identityId={identityId} /> */}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -0,0 +1,218 @@
|
|||||||
|
// import { useEffect } from "react";
|
||||||
|
import { Controller, useForm } from "react-hook-form";
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
// import { useRouter } from "next/router";
|
||||||
|
import { createNotification } from "@app/components/notifications";
|
||||||
|
import { Button, FormControl, Input, Modal, ModalContent } from "@app/components/v2";
|
||||||
|
import { useOrganization } from "@app/context";
|
||||||
|
import {
|
||||||
|
useGetOrgRole
|
||||||
|
// useCreateOrgRole,
|
||||||
|
// useUpdateOrgRole
|
||||||
|
} from "@app/hooks/api";
|
||||||
|
import { UsePopUpState } from "@app/hooks/usePopUp";
|
||||||
|
|
||||||
|
const schema = z
|
||||||
|
.object({
|
||||||
|
name: z.string(),
|
||||||
|
description: z.string(),
|
||||||
|
slug: z.string()
|
||||||
|
})
|
||||||
|
.required();
|
||||||
|
|
||||||
|
export type FormData = z.infer<typeof schema>;
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
popUp: UsePopUpState<["role"]>;
|
||||||
|
// handlePopUpOpen: (
|
||||||
|
// popUpName: keyof UsePopUpState<["identityAuthMethod"]>,
|
||||||
|
// data: {
|
||||||
|
// identityId: string;
|
||||||
|
// name: string;
|
||||||
|
// authMethod?: IdentityAuthMethod;
|
||||||
|
// }
|
||||||
|
// ) => void;
|
||||||
|
handlePopUpToggle: (popUpName: keyof UsePopUpState<["role"]>, state?: boolean) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const RoleDetailsModal = ({ popUp, handlePopUpToggle }: Props) => {
|
||||||
|
// const router = useRouter();
|
||||||
|
const { currentOrg } = useOrganization();
|
||||||
|
const orgId = currentOrg?.id || "";
|
||||||
|
|
||||||
|
const role = popUp?.role?.data as {
|
||||||
|
roleId: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const { data } = useGetOrgRole(orgId, role.roleId ?? "");
|
||||||
|
console.log("RoleDetailsModal: useGetOrgRole data: ", data);
|
||||||
|
|
||||||
|
// TODO: fetch by role id here
|
||||||
|
|
||||||
|
// const { mutateAsync: createMutateAsync } = useCreateIdentity();
|
||||||
|
// const { mutateAsync: updateMutateAsync } = useUpdateIdentity();
|
||||||
|
// const { mutateAsync: addMutateAsync } = useAddIdentityUniversalAuth();
|
||||||
|
|
||||||
|
// const { mutateAsync: createOrgRole } = useCreateOrgRole();
|
||||||
|
// const { mutateAsync: updateOrgRole } = useUpdateOrgRole();
|
||||||
|
|
||||||
|
const {
|
||||||
|
control,
|
||||||
|
handleSubmit,
|
||||||
|
reset,
|
||||||
|
formState: { isSubmitting }
|
||||||
|
} = useForm<FormData>({
|
||||||
|
resolver: zodResolver(schema),
|
||||||
|
defaultValues: {
|
||||||
|
name: "",
|
||||||
|
description: ""
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// useEffect(() => {
|
||||||
|
// if (role) {
|
||||||
|
// reset({
|
||||||
|
// name: role.name,
|
||||||
|
// description: role.description,
|
||||||
|
// slug: role.slug
|
||||||
|
// });
|
||||||
|
// } else {
|
||||||
|
// reset({
|
||||||
|
// name: "",
|
||||||
|
// description: "",
|
||||||
|
// slug: ""
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
// }, [role]);
|
||||||
|
|
||||||
|
const onFormSubmit = async ({ name, description, slug }: FormData) => {
|
||||||
|
try {
|
||||||
|
console.log("onFormSubmit args: ", {
|
||||||
|
name,
|
||||||
|
description,
|
||||||
|
slug
|
||||||
|
});
|
||||||
|
|
||||||
|
if (role) {
|
||||||
|
// update
|
||||||
|
|
||||||
|
// const up = await updateOrgRole({});
|
||||||
|
|
||||||
|
// console.log("onFormSubmit up: ", up);
|
||||||
|
|
||||||
|
// await updateMutateAsync({
|
||||||
|
// identityId: identity.identityId,
|
||||||
|
// name,
|
||||||
|
// role: role || undefined,
|
||||||
|
// organizationId: orgId
|
||||||
|
// });
|
||||||
|
|
||||||
|
handlePopUpToggle("role", false);
|
||||||
|
} else {
|
||||||
|
// create
|
||||||
|
|
||||||
|
// const { id: createdId } = await createMutateAsync({
|
||||||
|
// name,
|
||||||
|
// role: role || undefined,
|
||||||
|
// organizationId: orgId
|
||||||
|
// });
|
||||||
|
|
||||||
|
// await addMutateAsync({
|
||||||
|
// organizationId: orgId,
|
||||||
|
// identityId: createdId,
|
||||||
|
// clientSecretTrustedIps: [{ ipAddress: "0.0.0.0/0" }, { ipAddress: "::/0" }],
|
||||||
|
// accessTokenTrustedIps: [{ ipAddress: "0.0.0.0/0" }, { ipAddress: "::/0" }],
|
||||||
|
// accessTokenTTL: 2592000,
|
||||||
|
// accessTokenMaxTTL: 2592000,
|
||||||
|
// accessTokenNumUsesLimit: 0
|
||||||
|
// });
|
||||||
|
|
||||||
|
handlePopUpToggle("role", false);
|
||||||
|
// router.push(`/org/${orgId}/identities/${createdId}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
createNotification({
|
||||||
|
text: `Successfully ${popUp?.role?.data ? "updated" : "created"} role`,
|
||||||
|
type: "success"
|
||||||
|
});
|
||||||
|
|
||||||
|
reset();
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
const error = err as any;
|
||||||
|
const text =
|
||||||
|
error?.response?.data?.message ??
|
||||||
|
`Failed to ${popUp?.role?.data ? "update" : "create"} role`;
|
||||||
|
|
||||||
|
createNotification({
|
||||||
|
text,
|
||||||
|
type: "error"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Modal
|
||||||
|
isOpen={popUp?.role?.isOpen}
|
||||||
|
onOpenChange={(isOpen) => {
|
||||||
|
handlePopUpToggle("role", isOpen);
|
||||||
|
reset();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<ModalContent title={`${popUp?.role?.data ? "Update" : "Create"} Role`}>
|
||||||
|
<form onSubmit={handleSubmit(onFormSubmit)}>
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
defaultValue=""
|
||||||
|
name="name"
|
||||||
|
render={({ field, fieldState: { error } }) => (
|
||||||
|
<FormControl label="Name" isError={Boolean(error)} errorText={error?.message}>
|
||||||
|
<Input {...field} placeholder="Billing Team" />
|
||||||
|
</FormControl>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
defaultValue=""
|
||||||
|
name="slug"
|
||||||
|
render={({ field, fieldState: { error } }) => (
|
||||||
|
<FormControl label="Slug" isError={Boolean(error)} errorText={error?.message}>
|
||||||
|
<Input {...field} placeholder="billing" />
|
||||||
|
</FormControl>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
defaultValue=""
|
||||||
|
name="description"
|
||||||
|
render={({ field, fieldState: { error } }) => (
|
||||||
|
<FormControl label="Description" isError={Boolean(error)} errorText={error?.message}>
|
||||||
|
<Input {...field} placeholder="To manage billing" />
|
||||||
|
</FormControl>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<div className="flex items-center">
|
||||||
|
<Button
|
||||||
|
className="mr-4"
|
||||||
|
size="sm"
|
||||||
|
type="submit"
|
||||||
|
isLoading={isSubmitting}
|
||||||
|
isDisabled={isSubmitting}
|
||||||
|
>
|
||||||
|
{popUp?.role?.data ? "Update" : "Create"}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
colorSchema="secondary"
|
||||||
|
variant="plain"
|
||||||
|
onClick={() => handlePopUpToggle("role", false)}
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</ModalContent>
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
};
|
||||||
+4
-2
@@ -6,13 +6,15 @@ import {
|
|||||||
// DeleteActionModal,
|
// DeleteActionModal,
|
||||||
IconButton
|
IconButton
|
||||||
} from "@app/components/v2";
|
} from "@app/components/v2";
|
||||||
|
|
||||||
|
import { RolePermissionsTable } from "./RolePermissionsTable";
|
||||||
// import { useDeleteIdentityFromWorkspace } from "@app/hooks/api";
|
// import { useDeleteIdentityFromWorkspace } from "@app/hooks/api";
|
||||||
// import { usePopUp } from "@app/hooks/usePopUp";
|
// import { usePopUp } from "@app/hooks/usePopUp";
|
||||||
|
|
||||||
// import { IdentityAddToProjectModal } from "./IdentityAddToProjectModal";
|
// import { IdentityAddToProjectModal } from "./IdentityAddToProjectModal";
|
||||||
// import { IdentityProjectsTable } from "./IdentityProjectsTable";
|
// import { IdentityProjectsTable } from "./IdentityProjectsTable";
|
||||||
|
|
||||||
export const RolePermissionsSesction = () => {
|
export const RolePermissionsSection = () => {
|
||||||
// const { mutateAsync: deleteMutateAsync } = useDeleteIdentityFromWorkspace();
|
// const { mutateAsync: deleteMutateAsync } = useDeleteIdentityFromWorkspace();
|
||||||
|
|
||||||
// const { popUp, handlePopUpOpen, handlePopUpClose, handlePopUpToggle } = usePopUp([
|
// const { popUp, handlePopUpOpen, handlePopUpClose, handlePopUpToggle } = usePopUp([
|
||||||
@@ -62,7 +64,7 @@ export const RolePermissionsSesction = () => {
|
|||||||
</IconButton>
|
</IconButton>
|
||||||
</div>
|
</div>
|
||||||
<div className="py-4">
|
<div className="py-4">
|
||||||
Permissions Table
|
<RolePermissionsTable />
|
||||||
{/* <IdentityProjectsTable identityId={identityId} handlePopUpOpen={handlePopUpOpen} /> */}
|
{/* <IdentityProjectsTable identityId={identityId} handlePopUpOpen={handlePopUpOpen} /> */}
|
||||||
</div>
|
</div>
|
||||||
{/* <DeleteActionModal
|
{/* <DeleteActionModal
|
||||||
|
|||||||
+93
-31
@@ -1,62 +1,124 @@
|
|||||||
import { faKey } from "@fortawesome/free-solid-svg-icons";
|
import { faEllipsis } from "@fortawesome/free-solid-svg-icons";
|
||||||
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
|
import { twMerge } from "tailwind-merge";
|
||||||
|
|
||||||
|
import { OrgPermissionCan } from "@app/components/permissions";
|
||||||
import {
|
import {
|
||||||
EmptyState,
|
DropdownMenu,
|
||||||
|
DropdownMenuContent,
|
||||||
|
DropdownMenuItem,
|
||||||
|
DropdownMenuTrigger,
|
||||||
|
// Tooltip,
|
||||||
|
// IconButton,
|
||||||
|
// EmptyState,
|
||||||
Table,
|
Table,
|
||||||
TableContainer,
|
TableContainer,
|
||||||
TableSkeleton,
|
// TableSkeleton,
|
||||||
TBody,
|
TBody,
|
||||||
|
Td,
|
||||||
Th,
|
Th,
|
||||||
THead,
|
THead,
|
||||||
Tr
|
Tr} from "@app/components/v2";
|
||||||
} from "@app/components/v2";
|
import { OrgPermissionActions, OrgPermissionSubjects } from "@app/context";
|
||||||
import { useGetIdentityProjectMemberships } from "@app/hooks/api";
|
|
||||||
// import { UsePopUpState } from "@app/hooks/usePopUp";
|
// import { UsePopUpState } from "@app/hooks/usePopUp";
|
||||||
|
|
||||||
// import { IdentityProjectRow } from "./IdentityProjectRow";
|
// import { IdentityProjectRow } from "./IdentityProjectRow";
|
||||||
|
|
||||||
type Props = {
|
// type Props = {
|
||||||
identityId: string;
|
// identityId: string;
|
||||||
// handlePopUpOpen: (
|
// handlePopUpOpen: (
|
||||||
// popUpName: keyof UsePopUpState<["removeIdentityFromProject"]>,
|
// popUpName: keyof UsePopUpState<["removeIdentityFromProject"]>,
|
||||||
// data?: {}
|
// data?: {}
|
||||||
// ) => void;
|
// ) => void;
|
||||||
};
|
// };
|
||||||
|
|
||||||
export const IdentityProjectsTable = ({
|
export const RolePermissionsTable = () => {
|
||||||
identityId
|
// const { data: projectMemberships, isLoading } = useGetIdentityProjectMemberships(identityId);
|
||||||
}: // handlePopUpOpen
|
|
||||||
Props) => {
|
|
||||||
const { data: projectMemberships, isLoading } = useGetIdentityProjectMemberships(identityId);
|
|
||||||
return (
|
return (
|
||||||
<TableContainer>
|
<TableContainer>
|
||||||
<Table>
|
<Table>
|
||||||
<THead>
|
<THead>
|
||||||
<Tr>
|
<Tr>
|
||||||
<Th>Name</Th>
|
<Th>Resource</Th>
|
||||||
<Th>Role</Th>
|
<Th>Allowed Actions</Th>
|
||||||
<Th>Added On</Th>
|
|
||||||
<Th className="w-5" />
|
<Th className="w-5" />
|
||||||
</Tr>
|
</Tr>
|
||||||
</THead>
|
</THead>
|
||||||
<TBody>
|
<TBody>
|
||||||
{isLoading && <TableSkeleton columns={2} innerKey="identity-project-memberships" />}
|
<Tr>
|
||||||
{!isLoading &&
|
<Td>Identity</Td>
|
||||||
|
<Td>Create/Read</Td>
|
||||||
|
<Td>
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild className="rounded-lg">
|
||||||
|
<div className="hover:text-primary-400 data-[state=open]:text-primary-400">
|
||||||
|
<FontAwesomeIcon size="sm" icon={faEllipsis} />
|
||||||
|
</div>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent align="start" className="p-1">
|
||||||
|
<OrgPermissionCan I={OrgPermissionActions.Edit} a={OrgPermissionSubjects.Role}>
|
||||||
|
{(isAllowed) => (
|
||||||
|
<DropdownMenuItem
|
||||||
|
className={twMerge(
|
||||||
|
!isAllowed && "pointer-events-none cursor-not-allowed opacity-50"
|
||||||
|
)}
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
// TODO
|
||||||
|
}}
|
||||||
|
disabled={!isAllowed}
|
||||||
|
>
|
||||||
|
Edit Permission
|
||||||
|
</DropdownMenuItem>
|
||||||
|
)}
|
||||||
|
</OrgPermissionCan>
|
||||||
|
<OrgPermissionCan
|
||||||
|
I={OrgPermissionActions.Edit}
|
||||||
|
a={OrgPermissionSubjects.Identity}
|
||||||
|
>
|
||||||
|
{(isAllowed) => (
|
||||||
|
<DropdownMenuItem
|
||||||
|
className={twMerge(
|
||||||
|
isAllowed
|
||||||
|
? "hover:!bg-red-500 hover:!text-white"
|
||||||
|
: "pointer-events-none cursor-not-allowed opacity-50"
|
||||||
|
)}
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
// handlePopUpOpen("deleteIdentity", {
|
||||||
|
// identityId: id,
|
||||||
|
// name
|
||||||
|
// });
|
||||||
|
}}
|
||||||
|
disabled={!isAllowed}
|
||||||
|
>
|
||||||
|
Delete Permission
|
||||||
|
</DropdownMenuItem>
|
||||||
|
)}
|
||||||
|
</OrgPermissionCan>
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
</Td>
|
||||||
|
</Tr>
|
||||||
|
{/* <TableSkeleton columns={3} innerKey="role-permissions" /> */}
|
||||||
|
{/* {isLoading && <TableSkeleton columns={2} innerKey="identity-project-memberships" />} */}
|
||||||
|
{/* {!isLoading &&
|
||||||
projectMemberships?.map((membership) => {
|
projectMemberships?.map((membership) => {
|
||||||
return (
|
return (
|
||||||
<div key={`membership-${membership.id}`}>Row</div>
|
<div key={`membership-${membership.id}`}>Row</div>
|
||||||
// <IdentityProjectRow
|
<IdentityProjectRow
|
||||||
// key={`identity-project-membership-${membership.id}`}
|
key={`identity-project-membership-${membership.id}`}
|
||||||
// membership={membership}
|
membership={membership}
|
||||||
// handlePopUpOpen={handlePopUpOpen}
|
handlePopUpOpen={handlePopUpOpen}
|
||||||
// />
|
/>
|
||||||
);
|
);
|
||||||
})}
|
})} */}
|
||||||
</TBody>
|
</TBody>
|
||||||
</Table>
|
</Table>
|
||||||
{!isLoading && !projectMemberships?.length && (
|
{/* <EmptyState title="This role does not have any permissions on it" icon={faShield} /> */}
|
||||||
|
{/* {!isLoading && !projectMemberships?.length && (
|
||||||
<EmptyState title="This identity has not been assigned to any projects" icon={faKey} />
|
<EmptyState title="This identity has not been assigned to any projects" icon={faKey} />
|
||||||
)}
|
)} */}
|
||||||
</TableContainer>
|
</TableContainer>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
export { RolePermissionsSesction } from "./RolePermissionsSection";
|
export { RolePermissionsSection } from "./RolePermissionsSection";
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
export { RoleDetailsSection } from "./RoleDetailsSection";
|
export { RoleDetailsSection } from "./RoleDetailsSection";
|
||||||
|
export { RolePermissionsSection } from "./RolePermissionsSection";
|
||||||
|
|||||||
Reference in New Issue
Block a user