mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-09 05:28:23 +00:00
feat(frontend): remove AccessApprovalPolicyList
This commit is contained in:
@@ -8,7 +8,6 @@ import { Divider } from "@app/components/v2/Divider";
|
|||||||
import { useWorkspace } from "@app/context";
|
import { useWorkspace } from "@app/context";
|
||||||
import { useGetAccessRequestsCount, useGetSecretApprovalRequestCount } from "@app/hooks/api";
|
import { useGetAccessRequestsCount, useGetSecretApprovalRequestCount } from "@app/hooks/api";
|
||||||
|
|
||||||
import { AccessApprovalPolicyList } from "./components/AccessApprovalPolicyList";
|
|
||||||
import { AccessApprovalRequest } from "./components/AccessApprovalRequest";
|
import { AccessApprovalRequest } from "./components/AccessApprovalRequest";
|
||||||
import { ApprovalPolicyList } from "./components/ApprovalPolicyList";
|
import { ApprovalPolicyList } from "./components/ApprovalPolicyList";
|
||||||
import { SecretApprovalPolicyList } from "./components/SecretApprovalPolicyList";
|
import { SecretApprovalPolicyList } from "./components/SecretApprovalPolicyList";
|
||||||
@@ -66,8 +65,6 @@ export const SecretApprovalPage = () => {
|
|||||||
Access Requests
|
Access Requests
|
||||||
{Boolean(accessApprovalRequestCount?.pendingCount) && <Badge className="ml-2">{accessApprovalRequestCount?.pendingCount}</Badge>}
|
{Boolean(accessApprovalRequestCount?.pendingCount) && <Badge className="ml-2">{accessApprovalRequestCount?.pendingCount}</Badge>}
|
||||||
</Tab>
|
</Tab>
|
||||||
<Tab value={TabSection.ResourcePolicies}>Access Request Policies</Tab>
|
|
||||||
<Divider />
|
|
||||||
<Tab value={TabSection.Policies}>Policies</Tab>
|
<Tab value={TabSection.Policies}>Policies</Tab>
|
||||||
</TabList>
|
</TabList>
|
||||||
<TabPanel value={TabSection.SecretPolicies}>
|
<TabPanel value={TabSection.SecretPolicies}>
|
||||||
@@ -79,9 +76,6 @@ export const SecretApprovalPage = () => {
|
|||||||
<TabPanel value={TabSection.ResourceApprovalRequests}>
|
<TabPanel value={TabSection.ResourceApprovalRequests}>
|
||||||
<AccessApprovalRequest projectId={projectId} projectSlug={projectSlug} />
|
<AccessApprovalRequest projectId={projectId} projectSlug={projectSlug} />
|
||||||
</TabPanel>
|
</TabPanel>
|
||||||
<TabPanel value={TabSection.ResourcePolicies}>
|
|
||||||
<AccessApprovalPolicyList workspaceId={projectId} />
|
|
||||||
</TabPanel>
|
|
||||||
<TabPanel value={TabSection.Policies}>
|
<TabPanel value={TabSection.Policies}>
|
||||||
<ApprovalPolicyList workspaceId={projectId} />
|
<ApprovalPolicyList workspaceId={projectId} />
|
||||||
</TabPanel>
|
</TabPanel>
|
||||||
|
|||||||
-174
@@ -1,174 +0,0 @@
|
|||||||
import { faFileShield, faPlus } from "@fortawesome/free-solid-svg-icons";
|
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
||||||
|
|
||||||
import { createNotification } from "@app/components/notifications";
|
|
||||||
import { ProjectPermissionCan } from "@app/components/permissions";
|
|
||||||
import {
|
|
||||||
Button,
|
|
||||||
DeleteActionModal,
|
|
||||||
EmptyState,
|
|
||||||
Table,
|
|
||||||
TableContainer,
|
|
||||||
TableSkeleton,
|
|
||||||
TBody,
|
|
||||||
Td,
|
|
||||||
Th,
|
|
||||||
THead,
|
|
||||||
Tr,
|
|
||||||
UpgradePlanModal
|
|
||||||
} from "@app/components/v2";
|
|
||||||
import {
|
|
||||||
ProjectPermissionActions,
|
|
||||||
ProjectPermissionSub,
|
|
||||||
useProjectPermission,
|
|
||||||
useSubscription,
|
|
||||||
useWorkspace
|
|
||||||
} from "@app/context";
|
|
||||||
import { usePopUp } from "@app/hooks";
|
|
||||||
import { useDeleteAccessApprovalPolicy, useGetWorkspaceUsers } from "@app/hooks/api";
|
|
||||||
import { useGetAccessApprovalPolicies } from "@app/hooks/api/accessApproval/queries";
|
|
||||||
import { TAccessApprovalPolicy } from "@app/hooks/api/types";
|
|
||||||
|
|
||||||
import { AccessApprovalPolicyRow } from "./components/AccessApprovalPolicyRow";
|
|
||||||
import { AccessPolicyForm } from "./components/AccessPolicyModal";
|
|
||||||
|
|
||||||
interface IProps {
|
|
||||||
workspaceId: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const AccessApprovalPolicyList = ({ workspaceId }: IProps) => {
|
|
||||||
const { handlePopUpToggle, handlePopUpOpen, handlePopUpClose, popUp } = usePopUp([
|
|
||||||
"secretPolicyForm",
|
|
||||||
"deletePolicy",
|
|
||||||
"upgradePlan"
|
|
||||||
] as const);
|
|
||||||
const { permission } = useProjectPermission();
|
|
||||||
const { subscription } = useSubscription();
|
|
||||||
const { currentWorkspace } = useWorkspace();
|
|
||||||
|
|
||||||
const { data: members } = useGetWorkspaceUsers(workspaceId);
|
|
||||||
const { data: policies, isLoading: isPoliciesLoading } = useGetAccessApprovalPolicies({
|
|
||||||
projectSlug: currentWorkspace?.slug as string,
|
|
||||||
options: {
|
|
||||||
enabled:
|
|
||||||
permission.can(ProjectPermissionActions.Read, ProjectPermissionSub.SecretApproval) &&
|
|
||||||
!!currentWorkspace?.slug
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const { mutateAsync: deleteSecretApprovalPolicy } = useDeleteAccessApprovalPolicy();
|
|
||||||
|
|
||||||
const handleDeletePolicy = async () => {
|
|
||||||
const { id } = popUp.deletePolicy.data as TAccessApprovalPolicy;
|
|
||||||
if (!currentWorkspace?.slug) return;
|
|
||||||
|
|
||||||
try {
|
|
||||||
await deleteSecretApprovalPolicy({
|
|
||||||
projectSlug: currentWorkspace?.slug,
|
|
||||||
id
|
|
||||||
});
|
|
||||||
createNotification({
|
|
||||||
type: "success",
|
|
||||||
text: "Successfully deleted policy"
|
|
||||||
});
|
|
||||||
handlePopUpClose("deletePolicy");
|
|
||||||
} catch (err) {
|
|
||||||
console.log(err);
|
|
||||||
createNotification({
|
|
||||||
type: "error",
|
|
||||||
text: "Failed to delete policy"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<div className="mb-6 flex items-end justify-between">
|
|
||||||
<div className="flex flex-col">
|
|
||||||
<span className="text-xl font-semibold text-mineshaft-100">Access Request Policies</span>
|
|
||||||
<div className="mt-2 text-sm text-bunker-300">
|
|
||||||
Implement secret request policies for specific secrets and environments.
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<ProjectPermissionCan
|
|
||||||
I={ProjectPermissionActions.Create}
|
|
||||||
a={ProjectPermissionSub.SecretApproval}
|
|
||||||
>
|
|
||||||
{(isAllowed) => (
|
|
||||||
<Button
|
|
||||||
onClick={() => {
|
|
||||||
if (subscription && !subscription?.secretApproval) {
|
|
||||||
handlePopUpOpen("upgradePlan");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
handlePopUpOpen("secretPolicyForm");
|
|
||||||
}}
|
|
||||||
leftIcon={<FontAwesomeIcon icon={faPlus} />}
|
|
||||||
isDisabled={!isAllowed}
|
|
||||||
>
|
|
||||||
Create policy
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</ProjectPermissionCan>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<TableContainer>
|
|
||||||
<Table>
|
|
||||||
<THead>
|
|
||||||
<Tr>
|
|
||||||
<Th>Name</Th>
|
|
||||||
<Th>Environment</Th>
|
|
||||||
<Th>Secret Path</Th>
|
|
||||||
<Th>Eligible Approvers</Th>
|
|
||||||
<Th>Approval Required</Th>
|
|
||||||
<Th />
|
|
||||||
</Tr>
|
|
||||||
</THead>
|
|
||||||
<TBody>
|
|
||||||
{isPoliciesLoading && (
|
|
||||||
<TableSkeleton columns={6} innerKey="secret-policies" className="bg-mineshaft-700" />
|
|
||||||
)}
|
|
||||||
{!isPoliciesLoading && !policies?.length && (
|
|
||||||
<Tr>
|
|
||||||
<Td colSpan={6}>
|
|
||||||
<EmptyState title="No policies found" icon={faFileShield} />
|
|
||||||
</Td>
|
|
||||||
</Tr>
|
|
||||||
)}
|
|
||||||
{!!currentWorkspace &&
|
|
||||||
policies?.map((policy) => (
|
|
||||||
<AccessApprovalPolicyRow
|
|
||||||
projectSlug={currentWorkspace.slug}
|
|
||||||
policy={policy}
|
|
||||||
key={policy.id}
|
|
||||||
members={members}
|
|
||||||
onEdit={() => handlePopUpOpen("secretPolicyForm", policy)}
|
|
||||||
onDelete={() => handlePopUpOpen("deletePolicy", policy)}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</TBody>
|
|
||||||
</Table>
|
|
||||||
</TableContainer>
|
|
||||||
<AccessPolicyForm
|
|
||||||
projectSlug={currentWorkspace?.slug!}
|
|
||||||
isOpen={popUp.secretPolicyForm.isOpen}
|
|
||||||
onToggle={(isOpen) => handlePopUpToggle("secretPolicyForm", isOpen)}
|
|
||||||
members={members}
|
|
||||||
editValues={popUp.secretPolicyForm.data as TAccessApprovalPolicy}
|
|
||||||
/>
|
|
||||||
<DeleteActionModal
|
|
||||||
isOpen={popUp.deletePolicy.isOpen}
|
|
||||||
deleteKey="remove"
|
|
||||||
title="Do you want to remove this policy?"
|
|
||||||
onChange={(isOpen) => handlePopUpToggle("deletePolicy", isOpen)}
|
|
||||||
onDeleteApproved={handleDeletePolicy}
|
|
||||||
/>
|
|
||||||
<UpgradePlanModal
|
|
||||||
isOpen={popUp.upgradePlan.isOpen}
|
|
||||||
onOpenChange={(isOpen) => handlePopUpToggle("upgradePlan", isOpen)}
|
|
||||||
text="You can add secret approval policy if you switch to Infisical's Enterprise plan."
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
-146
@@ -1,146 +0,0 @@
|
|||||||
import { useState } from "react";
|
|
||||||
import { faCheckCircle, faPencil, faTrash } from "@fortawesome/free-solid-svg-icons";
|
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
||||||
|
|
||||||
import { ProjectPermissionCan } from "@app/components/permissions";
|
|
||||||
import {
|
|
||||||
DropdownMenu,
|
|
||||||
DropdownMenuContent,
|
|
||||||
DropdownMenuItem,
|
|
||||||
DropdownMenuLabel,
|
|
||||||
DropdownMenuTrigger,
|
|
||||||
IconButton,
|
|
||||||
Input,
|
|
||||||
Td,
|
|
||||||
Tr
|
|
||||||
} from "@app/components/v2";
|
|
||||||
import { ProjectPermissionActions, ProjectPermissionSub, useProjectPermission } from "@app/context";
|
|
||||||
import { useUpdateAccessApprovalPolicy } from "@app/hooks/api";
|
|
||||||
import { TAccessApprovalPolicy } from "@app/hooks/api/types";
|
|
||||||
import { TWorkspaceUser } from "@app/hooks/api/users/types";
|
|
||||||
|
|
||||||
type Props = {
|
|
||||||
policy: TAccessApprovalPolicy;
|
|
||||||
members?: TWorkspaceUser[];
|
|
||||||
projectSlug: string;
|
|
||||||
onEdit: () => void;
|
|
||||||
onDelete: () => void;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const AccessApprovalPolicyRow = ({
|
|
||||||
policy,
|
|
||||||
members = [],
|
|
||||||
projectSlug,
|
|
||||||
onEdit,
|
|
||||||
onDelete
|
|
||||||
}: Props) => {
|
|
||||||
const [selectedApprovers, setSelectedApprovers] = useState<string[]>([]);
|
|
||||||
const { mutate: updateAccessApprovalPolicy, isLoading } = useUpdateAccessApprovalPolicy();
|
|
||||||
const { permission } = useProjectPermission();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Tr>
|
|
||||||
<Td>{policy.name}</Td>
|
|
||||||
<Td>{policy.environment.slug}</Td>
|
|
||||||
<Td>{policy.secretPath || "*"}</Td>
|
|
||||||
<Td>
|
|
||||||
<DropdownMenu
|
|
||||||
onOpenChange={(isOpen) => {
|
|
||||||
if (!isOpen) {
|
|
||||||
updateAccessApprovalPolicy(
|
|
||||||
{
|
|
||||||
projectSlug,
|
|
||||||
id: policy.id,
|
|
||||||
approvers: selectedApprovers
|
|
||||||
},
|
|
||||||
{
|
|
||||||
onSettled: () => {
|
|
||||||
setSelectedApprovers([]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
setSelectedApprovers(policy.approvers);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<DropdownMenuTrigger
|
|
||||||
asChild
|
|
||||||
disabled={
|
|
||||||
isLoading ||
|
|
||||||
permission.cannot(ProjectPermissionActions.Edit, ProjectPermissionSub.SecretApproval)
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<Input
|
|
||||||
isReadOnly
|
|
||||||
value={policy.approvers?.length ? `${policy.approvers.length} selected` : "None"}
|
|
||||||
className="text-left"
|
|
||||||
/>
|
|
||||||
</DropdownMenuTrigger>
|
|
||||||
<DropdownMenuContent
|
|
||||||
style={{ width: "var(--radix-dropdown-menu-trigger-width)" }}
|
|
||||||
align="start"
|
|
||||||
>
|
|
||||||
<DropdownMenuLabel>
|
|
||||||
Select members that are allowed to approve changes
|
|
||||||
</DropdownMenuLabel>
|
|
||||||
{members?.map(({ id, user }) => {
|
|
||||||
const isChecked = selectedApprovers.includes(id);
|
|
||||||
return (
|
|
||||||
<DropdownMenuItem
|
|
||||||
onClick={(evt) => {
|
|
||||||
evt.preventDefault();
|
|
||||||
setSelectedApprovers((state) =>
|
|
||||||
isChecked ? state.filter((el) => el !== id) : [...state, id]
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
key={`create-policy-members-${id}`}
|
|
||||||
iconPos="right"
|
|
||||||
icon={isChecked && <FontAwesomeIcon icon={faCheckCircle} />}
|
|
||||||
>
|
|
||||||
{user.username}
|
|
||||||
</DropdownMenuItem>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</DropdownMenuContent>
|
|
||||||
</DropdownMenu>
|
|
||||||
</Td>
|
|
||||||
<Td>{policy.approvals}</Td>
|
|
||||||
<Td>
|
|
||||||
<div className="flex items-center justify-end space-x-4">
|
|
||||||
<ProjectPermissionCan
|
|
||||||
I={ProjectPermissionActions.Edit}
|
|
||||||
a={ProjectPermissionSub.SecretApproval}
|
|
||||||
renderTooltip
|
|
||||||
allowedLabel="Edit"
|
|
||||||
>
|
|
||||||
{(isAllowed) => (
|
|
||||||
<IconButton variant="plain" ariaLabel="edit" onClick={onEdit} isDisabled={!isAllowed}>
|
|
||||||
<FontAwesomeIcon icon={faPencil} size="lg" />
|
|
||||||
</IconButton>
|
|
||||||
)}
|
|
||||||
</ProjectPermissionCan>
|
|
||||||
<ProjectPermissionCan
|
|
||||||
I={ProjectPermissionActions.Delete}
|
|
||||||
a={ProjectPermissionSub.SecretApproval}
|
|
||||||
renderTooltip
|
|
||||||
allowedLabel="Delete"
|
|
||||||
>
|
|
||||||
{(isAllowed) => (
|
|
||||||
<IconButton
|
|
||||||
variant="plain"
|
|
||||||
colorSchema="danger"
|
|
||||||
size="lg"
|
|
||||||
ariaLabel="edit"
|
|
||||||
onClick={onDelete}
|
|
||||||
isDisabled={!isAllowed}
|
|
||||||
>
|
|
||||||
<FontAwesomeIcon icon={faTrash} />
|
|
||||||
</IconButton>
|
|
||||||
)}
|
|
||||||
</ProjectPermissionCan>
|
|
||||||
</div>
|
|
||||||
</Td>
|
|
||||||
</Tr>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
-266
@@ -1,266 +0,0 @@
|
|||||||
import { useEffect } from "react";
|
|
||||||
import { Controller, useForm } from "react-hook-form";
|
|
||||||
import { faCheckCircle } from "@fortawesome/free-solid-svg-icons";
|
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
|
||||||
import { z } from "zod";
|
|
||||||
|
|
||||||
import { createNotification } from "@app/components/notifications";
|
|
||||||
import {
|
|
||||||
Button,
|
|
||||||
DropdownMenu,
|
|
||||||
DropdownMenuContent,
|
|
||||||
DropdownMenuItem,
|
|
||||||
DropdownMenuLabel,
|
|
||||||
DropdownMenuTrigger,
|
|
||||||
FormControl,
|
|
||||||
Input,
|
|
||||||
Modal,
|
|
||||||
ModalContent,
|
|
||||||
Select,
|
|
||||||
SelectItem
|
|
||||||
} from "@app/components/v2";
|
|
||||||
import { useWorkspace } from "@app/context";
|
|
||||||
import {
|
|
||||||
useCreateAccessApprovalPolicy,
|
|
||||||
useUpdateAccessApprovalPolicy
|
|
||||||
} from "@app/hooks/api/accessApproval";
|
|
||||||
import { TAccessApprovalPolicy } from "@app/hooks/api/accessApproval/types";
|
|
||||||
import { TWorkspaceUser } from "@app/hooks/api/users/types";
|
|
||||||
|
|
||||||
type Props = {
|
|
||||||
isOpen?: boolean;
|
|
||||||
onToggle: (isOpen: boolean) => void;
|
|
||||||
members?: TWorkspaceUser[];
|
|
||||||
projectSlug: string;
|
|
||||||
editValues?: TAccessApprovalPolicy;
|
|
||||||
};
|
|
||||||
|
|
||||||
const formSchema = z
|
|
||||||
.object({
|
|
||||||
environment: z.string(),
|
|
||||||
name: z.string().optional(),
|
|
||||||
secretPath: z.string().optional(),
|
|
||||||
approvals: z.number().min(1),
|
|
||||||
approvers: z.string().array().min(1)
|
|
||||||
})
|
|
||||||
.refine((data) => data.approvals <= data.approvers.length, {
|
|
||||||
path: ["approvals"],
|
|
||||||
message: "The number of approvals should be lower than the number of approvers."
|
|
||||||
});
|
|
||||||
|
|
||||||
type TFormSchema = z.infer<typeof formSchema>;
|
|
||||||
|
|
||||||
export const AccessPolicyForm = ({
|
|
||||||
isOpen,
|
|
||||||
onToggle,
|
|
||||||
members = [],
|
|
||||||
projectSlug,
|
|
||||||
editValues
|
|
||||||
}: Props) => {
|
|
||||||
const {
|
|
||||||
control,
|
|
||||||
handleSubmit,
|
|
||||||
reset,
|
|
||||||
formState: { isSubmitting }
|
|
||||||
} = useForm<TFormSchema>({
|
|
||||||
resolver: zodResolver(formSchema),
|
|
||||||
values: editValues ? { ...editValues, environment: editValues.environment.slug } : undefined
|
|
||||||
});
|
|
||||||
const { currentWorkspace } = useWorkspace();
|
|
||||||
|
|
||||||
const environments = currentWorkspace?.environments || [];
|
|
||||||
useEffect(() => {
|
|
||||||
if (!isOpen) reset({});
|
|
||||||
}, [isOpen]);
|
|
||||||
|
|
||||||
const isEditMode = Boolean(editValues);
|
|
||||||
|
|
||||||
const { mutateAsync: createAccessApprovalPolicy } = useCreateAccessApprovalPolicy();
|
|
||||||
const { mutateAsync: updateAccessApprovalPolicy } = useUpdateAccessApprovalPolicy();
|
|
||||||
|
|
||||||
const handleCreatePolicy = async (data: TFormSchema) => {
|
|
||||||
if (!projectSlug) return;
|
|
||||||
|
|
||||||
try {
|
|
||||||
await createAccessApprovalPolicy({
|
|
||||||
...data,
|
|
||||||
projectSlug
|
|
||||||
});
|
|
||||||
createNotification({
|
|
||||||
type: "success",
|
|
||||||
text: "Successfully created policy"
|
|
||||||
});
|
|
||||||
onToggle(false);
|
|
||||||
} catch (err) {
|
|
||||||
console.log(err);
|
|
||||||
createNotification({
|
|
||||||
type: "error",
|
|
||||||
text: "Failed to create policy"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleUpdatePolicy = async (data: TFormSchema) => {
|
|
||||||
if (!projectSlug) return;
|
|
||||||
if (!editValues?.id) return;
|
|
||||||
|
|
||||||
try {
|
|
||||||
await updateAccessApprovalPolicy({
|
|
||||||
id: editValues?.id,
|
|
||||||
...data,
|
|
||||||
projectSlug
|
|
||||||
});
|
|
||||||
createNotification({
|
|
||||||
type: "success",
|
|
||||||
text: "Successfully updated policy"
|
|
||||||
});
|
|
||||||
onToggle(false);
|
|
||||||
} catch (err) {
|
|
||||||
console.log(err);
|
|
||||||
createNotification({
|
|
||||||
type: "error",
|
|
||||||
text: "failed to update policy"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleFormSubmit = async (data: TFormSchema) => {
|
|
||||||
if (isEditMode) {
|
|
||||||
await handleUpdatePolicy(data);
|
|
||||||
} else {
|
|
||||||
await handleCreatePolicy(data);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Modal isOpen={isOpen} onOpenChange={onToggle}>
|
|
||||||
<ModalContent title={isEditMode ? "Edit Access Policy" : "Create Access Policy"}>
|
|
||||||
<form onSubmit={handleSubmit(handleFormSubmit)}>
|
|
||||||
<Controller
|
|
||||||
control={control}
|
|
||||||
name="name"
|
|
||||||
render={({ field, fieldState: { error } }) => (
|
|
||||||
<FormControl label="Policy Name" isError={Boolean(error)} errorText={error?.message}>
|
|
||||||
<Input {...field} value={field.value || ""} />
|
|
||||||
</FormControl>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<Controller
|
|
||||||
control={control}
|
|
||||||
name="environment"
|
|
||||||
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
|
||||||
<FormControl
|
|
||||||
label="Environment"
|
|
||||||
isRequired
|
|
||||||
className="mt-4"
|
|
||||||
isError={Boolean(error)}
|
|
||||||
errorText={error?.message}
|
|
||||||
>
|
|
||||||
<Select
|
|
||||||
isDisabled={isEditMode}
|
|
||||||
value={value}
|
|
||||||
onValueChange={(val) => onChange(val)}
|
|
||||||
className="w-full border border-mineshaft-500"
|
|
||||||
>
|
|
||||||
{environments.map((sourceEnvironment) => (
|
|
||||||
<SelectItem
|
|
||||||
value={sourceEnvironment.slug}
|
|
||||||
key={`azure-key-vault-environment-${sourceEnvironment.slug}`}
|
|
||||||
>
|
|
||||||
{sourceEnvironment.name}
|
|
||||||
</SelectItem>
|
|
||||||
))}
|
|
||||||
</Select>
|
|
||||||
</FormControl>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Controller
|
|
||||||
control={control}
|
|
||||||
name="secretPath"
|
|
||||||
render={({ field, fieldState: { error } }) => (
|
|
||||||
<FormControl label="Secret Path" isError={Boolean(error)} errorText={error?.message}>
|
|
||||||
<Input {...field} value={field.value || ""} />
|
|
||||||
</FormControl>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Controller
|
|
||||||
control={control}
|
|
||||||
name="approvers"
|
|
||||||
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
|
||||||
<FormControl
|
|
||||||
label="Approvers Required"
|
|
||||||
isError={Boolean(error)}
|
|
||||||
errorText={error?.message}
|
|
||||||
>
|
|
||||||
<DropdownMenu>
|
|
||||||
<DropdownMenuTrigger asChild>
|
|
||||||
<Input
|
|
||||||
isReadOnly
|
|
||||||
value={value?.length ? `${value.length} selected` : "None"}
|
|
||||||
className="text-left"
|
|
||||||
/>
|
|
||||||
</DropdownMenuTrigger>
|
|
||||||
<DropdownMenuContent
|
|
||||||
style={{ width: "var(--radix-dropdown-menu-trigger-width)" }}
|
|
||||||
align="start"
|
|
||||||
>
|
|
||||||
<DropdownMenuLabel>
|
|
||||||
Select members that are allowed to approve changes
|
|
||||||
</DropdownMenuLabel>
|
|
||||||
{members.map(({ id, user }) => {
|
|
||||||
const isChecked = value?.includes(id);
|
|
||||||
return (
|
|
||||||
<DropdownMenuItem
|
|
||||||
onClick={(evt) => {
|
|
||||||
evt.preventDefault();
|
|
||||||
onChange(
|
|
||||||
isChecked ? value?.filter((el) => el !== id) : [...(value || []), id]
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
key={`create-policy-members-${id}`}
|
|
||||||
iconPos="right"
|
|
||||||
icon={isChecked && <FontAwesomeIcon icon={faCheckCircle} />}
|
|
||||||
>
|
|
||||||
{user.username}
|
|
||||||
</DropdownMenuItem>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</DropdownMenuContent>
|
|
||||||
</DropdownMenu>
|
|
||||||
</FormControl>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<Controller
|
|
||||||
control={control}
|
|
||||||
name="approvals"
|
|
||||||
defaultValue={1}
|
|
||||||
render={({ field, fieldState: { error } }) => (
|
|
||||||
<FormControl
|
|
||||||
label="Approvals Required"
|
|
||||||
isError={Boolean(error)}
|
|
||||||
errorText={error?.message}
|
|
||||||
>
|
|
||||||
<Input
|
|
||||||
{...field}
|
|
||||||
type="number"
|
|
||||||
onChange={(el) => field.onChange(parseInt(el.target.value, 10))}
|
|
||||||
/>
|
|
||||||
</FormControl>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<div className="mt-8 flex items-center space-x-4">
|
|
||||||
<Button type="submit" isLoading={isSubmitting} isDisabled={isSubmitting}>
|
|
||||||
Save
|
|
||||||
</Button>
|
|
||||||
<Button onClick={() => onToggle(false)} variant="outline_bg">
|
|
||||||
Close
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</ModalContent>
|
|
||||||
</Modal>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
export { AccessApprovalPolicyList } from "./AccessApprovalPolicyList";
|
|
||||||
Reference in New Issue
Block a user