Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
import { useMemo } from "react";
import { useFormContext, useWatch } from "react-hook-form";
import {
ProjectPermissionMemberActions,
ProjectPermissionSub
} from "@app/context/ProjectPermissionContext/types";
import { ConditionsFields } from "./ConditionsFields";
import {
ACTION_ALLOWED_CONDITIONS,
getActionLabelsForSubject,
TFormSchema
} from "./ProjectRoleModifySection.utils";
type Props = {
position?: number;
isDisabled?: boolean;
};
export const MemberPermissionConditions = ({ position = 0, isDisabled }: Props) => {
const { control } = useFormContext<TFormSchema>();
const permissionRule = useWatch({
control,
name: `permissions.${ProjectPermissionSub.Member}.${position}` as const
});
const selectedActions = useMemo(() => {
if (!permissionRule) return [];
return Object.entries(permissionRule)
.filter(
([key, value]) =>
value === true &&
Object.values(ProjectPermissionMemberActions).includes(
key as ProjectPermissionMemberActions
)
)
.map(([key]) => key);
}, [permissionRule]);
const actionLabelsMap = useMemo(() => getActionLabelsForSubject(ProjectPermissionSub.Member), []);
return (
<ConditionsFields
isDisabled={isDisabled}
subject={ProjectPermissionSub.Member}
position={position}
selectOptions={[
{
value: "userEmail",
label: "User Email",
description: "The email address of the target user"
},
{
value: "assignableRole",
label: "Assignable Roles",
description:
"The roles that the actor is allowed to assign to the target users. (e.g., admin, member, viewer)"
},
{
value: "assignableSubject",
label: "Assignable Subjects",
description:
"The permission subjects that the actor is allowed to grant in additional privileges to the target users. (e.g., secrets, environments, members)"
},
{
value: "assignableAction",
label: "Assignable Actions",
description:
"The specific actions that the actor is allowed to grant in additional privileges to the target users. (e.g., secrets:describeSecret, environments:edit)"
}
]}
selectedActions={selectedActions}
actionConditionsMap={ACTION_ALLOWED_CONDITIONS[ProjectPermissionSub.Member]}
actionLabelsMap={actionLabelsMap}
/>
);
};