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
improvement(frontend): migrate add machine identity to project dialog to v3 (#8047)
claude[bot]4d1157daf27a
diff --git a/frontend/src/pages/organization/IdentityDetailsByIDPage/components/IdentityProjectsSection/IdentityAddToProjectModal.tsx b/frontend/src/pages/organization/IdentityDetailsByIDPage/components/IdentityProjectsSection/IdentityAddToProjectModal.tsxindex c4bdfe2461..9e1faffdbf 100644--- a/frontend/src/pages/organization/IdentityDetailsByIDPage/components/IdentityProjectsSection/IdentityAddToProjectModal.tsx+++ b/frontend/src/pages/organization/IdentityDetailsByIDPage/components/IdentityProjectsSection/IdentityAddToProjectModal.tsx@@ -6,26 +6,31 @@ import { z } from "zod";import { createNotification } from "@app/components/notifications";import {Button,- FilterableSelect,- FormControl,- Modal,- ModalClose,- ModalContent-} from "@app/components/v2";+ Combobox,+ Dialog,+ DialogContent,+ DialogDescription,+ DialogFooter,+ DialogHeader,+ DialogTitle,+ Field,+ FieldError,+ FieldLabel+} from "@app/components/v3";import { useOrganization } from "@app/context";+import { useScopeVariant } from "@app/hooks";import {useCreateProjectIdentityMembership,useGetIdentityProjectMemberships,useGetProjectRoles,- useGetUserProjects,- useGetWorkspaceById+ useGetUserProjects} from "@app/hooks/api";import { UsePopUpState } from "@app/hooks/usePopUp";const schema = z.object({project: z.object({ name: z.string(), id: z.string(), type: z.string().optional() }),- role: z.object({ name: z.string(), slug: z.string() })+ role: z.object({ name: z.string(), slug: z.string(), description: z.string().nullish() })}).required();@@ -42,15 +47,17 @@ type Props = {// TODO: eventually refactor to support adding to multiple projects at once? would lose role granularity unique to project-const Content = ({ identityId, handlePopUpToggle }: Omit<Props, "popUp">) => {+export const IdentityAddToProjectModal = ({ identityId, popUp, handlePopUpToggle }: Props) => {const { currentOrg } = useOrganization();- const { data: workspaces = [] } = useGetUserProjects();+ const scopeVariant = useScopeVariant();+ const { data: workspaces = [], isPending: isWorkspacesLoading } = useGetUserProjects();const { mutateAsync: addIdentityToWorkspace } = useCreateProjectIdentityMembership();const {control,handleSubmit,reset,+ resetField,formState: { isSubmitting },watch} = useForm<FormData>({@@ -59,8 +66,7 @@ const Content = ({ identityId, handlePopUpToggle }: Omit<Props, "popUp">) => {const projectId = watch("project")?.id;const { data: projectMemberships } = useGetIdentityProjectMemberships(identityId);- const { data: project, isPending: isProjectLoading } = useGetWorkspaceById(projectId);- const { data: roles, isPending: isRolesLoading } = useGetProjectRoles(project?.id ?? "");+ const { data: roles = [], isPending: isRolesLoading } = useGetProjectRoles(projectId ?? "");const filteredWorkspaces = useMemo(() => {const wsWorkspaceIds = new Map();@@ -74,6 +80,11 @@ const Content = ({ identityId, handlePopUpToggle }: Omit<Props, "popUp">) => {);}, [workspaces, projectMemberships]);+ const handleOpenChange = (isOpen: boolean) => {+ handlePopUpToggle("addIdentityToProject", isOpen);+ if (!isOpen) reset();+ };+const onFormSubmit = async ({ project: selectedProject, role }: FormData) => {await addIdentityToWorkspace({projectId: selectedProject.id,@@ -87,90 +98,105 @@ const Content = ({ identityId, handlePopUpToggle }: Omit<Props, "popUp">) => {type: "success"});- reset();- handlePopUpToggle("addIdentityToProject", false);+ handleOpenChange(false);};const isProjectSelected = Boolean(projectId);return (- <form onSubmit={handleSubmit(onFormSubmit)}>- <Controller- control={control}- name="project"- render={({ field: { onChange, value }, fieldState: { error } }) => (- <FormControl- label="Project"- errorText={error?.message}- isError={Boolean(error)}- className="mt-4"- >- <FilterableSelect- value={value}- onChange={onChange}- options={filteredWorkspaces}- placeholder="Select project..."- getOptionValue={(option) => option.id}- getOptionLabel={(option) => option.name}- isLoading={isProjectSelected && isProjectLoading}- />- </FormControl>- )}- />- <Controller- control={control}- name="role"- render={({ field: { onChange, value }, fieldState: { error } }) => (- <FormControl- label="Role"- errorText={error?.message}- isError={Boolean(error)}- className="mt-4"- >- <FilterableSelect- isDisabled={!isProjectSelected}- value={value}- onChange={onChange}- options={roles}- isLoading={isProjectSelected && isRolesLoading}- placeholder="Select role..."- getOptionValue={(option) => option.slug}- getOptionLabel={(option) => option.name}- />- </FormControl>- )}- />- <div className="flex items-center">- <Button- className="mr-4"- size="sm"- type="submit"- isLoading={isSubmitting}- isDisabled={isSubmitting}- >- Add- </Button>- <ModalClose asChild>- <Button colorSchema="secondary" variant="plain">- Cancel- </Button>- </ModalClose>- </div>- </form>- );-};--export const IdentityAddToProjectModal = ({ identityId, popUp, handlePopUpToggle }: Props) => {- return (- <Modal- isOpen={popUp?.addIdentityToProject?.isOpen}- onOpenChange={(isOpen) => {- handlePopUpToggle("addIdentityToProject", isOpen);- }}- >- <ModalContent bodyClassName="overflow-visible" title="Add Machine Identity to Project">- <Content identityId={identityId} handlePopUpToggle={handlePopUpToggle} />- </ModalContent>- </Modal>+ <Dialog open={popUp?.addIdentityToProject?.isOpen} onOpenChange={handleOpenChange}>+ <DialogContent>+ <DialogHeader>+ <DialogTitle>Add Machine Identity to Project</DialogTitle>+ <DialogDescription>+ Select a project and the role this machine identity should have in it.+ </DialogDescription>+ </DialogHeader>+ <form onSubmit={handleSubmit(onFormSubmit)} className="flex flex-col gap-4">+ <Controller+ control={control}+ name="project"+ render={({ field: { onChange, value }, fieldState: { error } }) => (+ <Field>+ <FieldLabel htmlFor="add-identity-to-project-project">Project</FieldLabel>+ <Combobox+ id="add-identity-to-project-project"+ value={value ?? null}+ onValueChange={(project) => {+ onChange(project);+ resetField("role");+ }}+ options={filteredWorkspaces}+ getOptionValue={(option) => option.id}+ getOptionLabel={(option) => option.name}+ placeholder="Select project..."+ searchPlaceholder="Search projects..."+ searchAriaLabel="Search projects"+ emptyMessage={+ filteredWorkspaces.length === 0+ ? "This identity is already a member of every project you can access."+ : "No projects found."+ }+ isLoading={isWorkspacesLoading}+ isError={Boolean(error)}+ modal+ />+ <FieldError>{error?.message}</FieldError>+ </Field>+ )}+ />+ <Controller+ control={control}+ name="role"+ render={({ field: { onChange, value }, fieldState: { error } }) => (+ <Field>+ <FieldLabel htmlFor="add-identity-to-project-role">Role</FieldLabel>+ <Combobox+ id="add-identity-to-project-role"+ value={value ?? null}+ onValueChange={onChange}+ options={roles}+ getOptionValue={(option) => option.slug}+ getOptionLabel={(option) => option.name}+ getOptionKeywords={(option) => (option.description ? [option.description] : [])}+ placeholder="Select role..."+ searchPlaceholder="Search roles..."+ searchAriaLabel="Search project roles"+ emptyMessage="No project roles found."+ isDisabled={!isProjectSelected}+ isLoading={isProjectSelected && isRolesLoading}+ isError={Boolean(error)}+ modal+ renderOption={(option) => (+ <div className="min-w-0">+ <p className="truncate">{option.name}</p>+ {option.description && (+ <p className="text-xs leading-4 break-words whitespace-normal text-muted">+ {option.description}+ </p>+ )}+ </div>+ )}+ />+ <FieldError>{error?.message}</FieldError>+ </Field>+ )}+ />+ <DialogFooter>+ <Button type="button" variant="ghost" onClick={() => handleOpenChange(false)}>+ Cancel+ </Button>+ <Button+ type="submit"+ variant={scopeVariant}+ isPending={isSubmitting}+ isDisabled={isSubmitting}+ >+ Add to Project+ </Button>+ </DialogFooter>+ </form>+ </DialogContent>+ </Dialog>);};diff --git a/frontend/src/pages/organization/IdentityDetailsByIDPage/components/IdentityProjectsSection/IdentityProjectsSection.tsx b/frontend/src/pages/organization/IdentityDetailsByIDPage/components/IdentityProjectsSection/IdentityProjectsSection.tsxindex a6520d3915..ddf12d1eff 100644--- a/frontend/src/pages/organization/IdentityDetailsByIDPage/components/IdentityProjectsSection/IdentityProjectsSection.tsx+++ b/frontend/src/pages/organization/IdentityDetailsByIDPage/components/IdentityProjectsSection/IdentityProjectsSection.tsx@@ -1,8 +1,16 @@import { PlusIcon } from "lucide-react";import { createNotification } from "@app/components/notifications";-import { DeleteActionModal } from "@app/components/v2";import {+ AlertDialog,+ AlertDialogAction,+ AlertDialogCancel,+ AlertDialogConfirmationField,+ AlertDialogContent,+ AlertDialogDescription,+ AlertDialogFooter,+ AlertDialogHeader,+ AlertDialogTitle,Button,Card,CardAction,@@ -24,18 +32,32 @@ type Props = {identityId: string;};+type RemoveIdentityPopUpData = {+ identityId: string;+ identityName: string;+ projectId: string;+ projectName: string;+};+export const IdentityProjectsSection = ({ identityId }: Props) => {- const { mutateAsync: deleteMutateAsync } = useDeleteProjectIdentityMembership();+ const { mutateAsync: deleteMutateAsync, isPending: isRemoving } =+ useDeleteProjectIdentityMembership();const { popUp, handlePopUpOpen, handlePopUpClose, handlePopUpToggle } = usePopUp(["addIdentityToProject","removeIdentityFromProject"] as const);- const onRemoveIdentitySubmit = async (id: string, projectId: string) => {+ const removeIdentityData = popUp.removeIdentityFromProject.data as+ | RemoveIdentityPopUpData+ | undefined;++ const onRemoveIdentitySubmit = async () => {+ if (!removeIdentityData) return;+await deleteMutateAsync({- identityId: id,- projectId+ identityId: removeIdentityData.identityId,+ projectId: removeIdentityData.projectId});createNotification({@@ -73,24 +95,48 @@ export const IdentityProjectsSection = ({ identityId }: Props) => {<IdentityProjectsTable identityId={identityId} handlePopUpOpen={handlePopUpOpen} /></CardContent></Card>- <DeleteActionModal- isOpen={popUp.removeIdentityFromProject.isOpen}- title={`Are you sure you want to remove ${- (popUp?.removeIdentityFromProject?.data as { identityName: string })?.identityName || ""- } from ${- (popUp?.removeIdentityFromProject?.data as { projectName: string })?.projectName || ""- }?`}- onChange={(isOpen) => handlePopUpToggle("removeIdentityFromProject", isOpen)}- deleteKey="confirm"- onDeleteApproved={() => {- const popupData = popUp?.removeIdentityFromProject?.data as {- identityId: string;- projectId: string;- };-- return onRemoveIdentitySubmit(popupData.identityId, popupData.projectId);+ <AlertDialog+ open={popUp.removeIdentityFromProject.isOpen}+ confirmationValue="confirm"+ onOpenChange={(isOpen) => {+ if (!isOpen && isRemoving) return;+ handlePopUpToggle("removeIdentityFromProject", isOpen);}}- />+ >+ <AlertDialogContent>+ <AlertDialogHeader>+ <AlertDialogTitle>Remove Identity From Project</AlertDialogTitle>+ <AlertDialogDescription>+ Remove{" "}+ <span className="font-medium text-foreground">+ {removeIdentityData?.identityName ?? "this identity"}+ </span>{" "}+ from{" "}+ <span className="font-medium text-foreground">+ {removeIdentityData?.projectName ?? "this project"}+ </span>+ . The identity loses all access it has through this project membership.+ </AlertDialogDescription>+ </AlertDialogHeader>+ <AlertDialogConfirmationField+ inputProps={{ disabled: isRemoving }}+ onConfirm={() => onRemoveIdentitySubmit().catch(() => undefined)}+ />+ <AlertDialogFooter>+ <AlertDialogCancel isDisabled={isRemoving}>Cancel</AlertDialogCancel>+ <AlertDialogAction+ variant="danger"+ isPending={isRemoving}+ onClick={(event) => {+ event.preventDefault();+ onRemoveIdentitySubmit().catch(() => undefined);+ }}+ >+ Remove From Project+ </AlertDialogAction>+ </AlertDialogFooter>+ </AlertDialogContent>+ </AlertDialog><IdentityAddToProjectModalidentityId={identityId}popUp={popUp}diff --git a/frontend/src/pages/pam/PamAccessControlPage/components/IdentitiesTab.tsx b/frontend/src/pages/pam/PamAccessControlPage/components/IdentitiesTab.tsxindex 1ec6ac58d9..43943fe528 100644--- a/frontend/src/pages/pam/PamAccessControlPage/components/IdentitiesTab.tsx+++ b/frontend/src/pages/pam/PamAccessControlPage/components/IdentitiesTab.tsx@@ -6,9 +6,17 @@ import { MoreHorizontalIcon, PencilIcon, Plus, SearchIcon, Trash2Icon } from "luimport { createNotification } from "@app/components/notifications";import { ProjectPermissionCan } from "@app/components/permissions";-import { DeleteActionModal } from "@app/components/v2";import { HighlightText } from "@app/components/v2/HighlightText";import {+ AlertDialog,+ AlertDialogAction,+ AlertDialogCancel,+ AlertDialogConfirmationField,+ AlertDialogContent,+ AlertDialogDescription,+ AlertDialogFooter,+ AlertDialogHeader,+ AlertDialogTitle,Badge,Button,Card,@@ -70,6 +78,7 @@ export const IdentitiesTab = () => {const removeIdentity = useRemovePamProductIdentityMember();const deleteIdentity = useDeleteProjectIdentity();+ const isRemoving = removeIdentity.isPending || deleteIdentity.isPending;const filteredIdentities = useMemo(() => identities.filter((member) => member.name.toLowerCase().includes(search.toLowerCase())),@@ -80,6 +89,7 @@ export const IdentitiesTab = () => {// orphan them, so they are deleted outright. Org-level identities just lose their membership.const isPamManaged = (member: TPamIdentityMember) =>member.identityProjectId === currentProject.id;+ const isRemovingManagedIdentity = identityToRemove ? isPamManaged(identityToRemove) : false;const renderManagedByBadge = (member: TPamIdentityMember) => {if (isPamManaged(member)) {@@ -106,7 +116,7 @@ export const IdentitiesTab = () => {);};- // Rejections propagate to DeleteActionModal, which keeps itself open; the global mutation+ // Rejections keep the confirm dialog open (callers swallow them); the global mutation// error handler owns the toast.const handleDeleteIdentity = async () => {if (!identityToRemove?.identityId) return;@@ -301,31 +311,57 @@ export const IdentitiesTab = () => {}}/>- {identityToRemove && isPamManaged(identityToRemove) ? (- <DeleteActionModal- isOpen- onChange={(isOpen) => {- if (!isOpen) setIdentityToRemove(null);- }}- title={`Delete ${identityToRemove.name}?`}- subTitle="This identity is managed by PAM and will be permanently deleted."- deleteKey="delete"- buttonText="Delete"- onDeleteApproved={handleDeleteIdentity}- />- ) : (- <DeleteActionModal- isOpen={!!identityToRemove}- onChange={(isOpen) => {- if (!isOpen) setIdentityToRemove(null);- }}- title={`Remove ${identityToRemove?.name ?? "identity"} from PAM?`}- subTitle="The identity will lose its PAM access but remain available in your organization."- deleteKey="remove"- buttonText="Remove"- onDeleteApproved={handleDeleteIdentity}- />- )}+ <AlertDialog+ open={!!identityToRemove}+ confirmationValue={isRemovingManagedIdentity ? "delete" : "remove"}+ onOpenChange={(isOpen) => {+ if (!isOpen && isRemoving) return;+ if (!isOpen) setIdentityToRemove(null);+ }}+ >+ <AlertDialogContent>+ <AlertDialogHeader>+ <AlertDialogTitle>+ {isRemovingManagedIdentity ? "Delete Identity" : "Remove Identity From PAM"}+ </AlertDialogTitle>+ <AlertDialogDescription>+ {isRemovingManagedIdentity ? (+ <>+ Permanently delete{" "}+ <span className="font-medium text-foreground">{identityToRemove?.name}</span>.+ This identity is managed by PAM and cannot be recovered.+ </>+ ) : (+ <>+ Remove{" "}+ <span className="font-medium text-foreground">+ {identityToRemove?.name ?? "this identity"}+ </span>{" "}+ from PAM. The identity loses its PAM access but remains available in your+ organization.+ </>+ )}+ </AlertDialogDescription>+ </AlertDialogHeader>+ <AlertDialogConfirmationField+ inputProps={{ disabled: isRemoving }}+ onConfirm={() => handleDeleteIdentity().catch(() => undefined)}+ />+ <AlertDialogFooter>+ <AlertDialogCancel isDisabled={isRemoving}>Cancel</AlertDialogCancel>+ <AlertDialogAction+ variant="danger"+ isPending={isRemoving}+ onClick={(event) => {+ event.preventDefault();+ handleDeleteIdentity().catch(() => undefined);+ }}+ >+ {isRemovingManagedIdentity ? "Delete Identity" : "Remove From PAM"}+ </AlertDialogAction>+ </AlertDialogFooter>+ </AlertDialogContent>+ </AlertDialog></div>);};diff --git a/frontend/src/views/IdentityAuthMethods/IdentityAuthMethodsTable.tsx b/frontend/src/views/IdentityAuthMethods/IdentityAuthMethodsTable.tsxindex 762020bdc8..9e5ebf28da 100644--- a/frontend/src/views/IdentityAuthMethods/IdentityAuthMethodsTable.tsx+++ b/frontend/src/views/IdentityAuthMethods/IdentityAuthMethodsTable.tsx@@ -203,6 +203,7 @@ export const IdentityAuthMethodsTable = ({if (!open) setRevokeAuthMethod(null);}}identityId={identityId}+ identityName={identityName}authMethod={revokeAuthMethod}onSuccess={onMutated}/>diff --git a/frontend/src/views/IdentityAuthMethods/helpers/IdentityAuthRevokeDialog.tsx b/frontend/src/views/IdentityAuthMethods/helpers/IdentityAuthRevokeDialog.tsxindex 7d9fb4167b..9ffd85ce89 100644--- a/frontend/src/views/IdentityAuthMethods/helpers/IdentityAuthRevokeDialog.tsx+++ b/frontend/src/views/IdentityAuthMethods/helpers/IdentityAuthRevokeDialog.tsx@@ -1,22 +1,17 @@-import { useEffect, useState } from "react";+import { useState } from "react";import { useParams } from "@tanstack/react-router";-import { Trash2Icon } from "lucide-react";import { createNotification } from "@app/components/notifications";import {AlertDialog,AlertDialogAction,AlertDialogCancel,+ AlertDialogConfirmationField,AlertDialogContent,AlertDialogDescription,AlertDialogFooter,AlertDialogHeader,- AlertDialogMedia,- AlertDialogTitle,- Field,- FieldContent,- FieldLabel,- Input+ AlertDialogTitle} from "@app/components/v3";import { useOrganization } from "@app/context";import {@@ -44,6 +39,7 @@ type Props = {open: boolean;onOpenChange: (open: boolean) => void;identityId: string;+ identityName?: string;authMethod: IdentityAuthMethod | null;onSuccess: () => void;};@@ -52,6 +48,7 @@ export const IdentityAuthRevokeDialog = ({open,onOpenChange,identityId,+ identityName,authMethod,onSuccess}: Props) => {@@ -59,13 +56,7 @@ export const IdentityAuthRevokeDialog = ({const { currentOrg } = useOrganization();const orgId = currentOrg?.id || "";- const [removeConfirmInput, setRemoveConfirmInput] = useState("");-- useEffect(() => {- if (!open) setRemoveConfirmInput("");- }, [open]);-- const isRemoveConfirmed = removeConfirmInput === "confirm";+ const [isRemoving, setIsRemoving] = useState(false);const { mutateAsync: revokeUniversal } = useDeleteIdentityUniversalAuth();const { mutateAsync: revokeToken } = useDeleteIdentityTokenAuth();@@ -97,64 +88,64 @@ export const IdentityAuthRevokeDialog = ({[IdentityAuthMethod.LDAP_AUTH]: revokeLdap as RevokeFn};+ const authMethodName = authMethod ? identityAuthToNameMap[authMethod] : "this auth method";+const handleDelete = async () => {- if (!authMethod || !isRemoveConfirmed) return;+ if (!authMethod || isRemoving) return;- await revokeMap[authMethod]({- identityId,- ...(projectId ? { projectId } : { organizationId: orgId })- });+ setIsRemoving(true);+ try {+ await revokeMap[authMethod]({+ identityId,+ ...(projectId ? { projectId } : { organizationId: orgId })+ });- createNotification({- text: "Successfully removed auth method",- type: "success"- });- onOpenChange(false);- onSuccess();+ createNotification({+ text: "Successfully removed auth method",+ type: "success"+ });+ onOpenChange(false);+ onSuccess();+ } finally {+ setIsRemoving(false);+ }};return (- <AlertDialog open={open} onOpenChange={onOpenChange}>+ <AlertDialog+ open={open}+ confirmationValue="confirm"+ onOpenChange={(isOpen) => {+ if (!isOpen && isRemoving) return;+ onOpenChange(isOpen);+ }}+ ><AlertDialogContent><AlertDialogHeader>- <AlertDialogMedia>- <Trash2Icon />- </AlertDialogMedia>- <AlertDialogTitle>- Are you sure you want to remove{" "}- {authMethod ? identityAuthToNameMap[authMethod] : "this auth method"} on this identity?- </AlertDialogTitle>- <AlertDialogDescription>This action is irreversible.</AlertDialogDescription>+ <AlertDialogTitle>Remove Auth Method</AlertDialogTitle>+ <AlertDialogDescription>+ Remove <span className="font-medium text-foreground">{authMethodName}</span> from{" "}+ <span className="font-medium text-foreground">{identityName ?? "this identity"}</span>.+ Clients using this method can no longer authenticate as this identity, and its+ configuration and issued credentials are deleted. The method can be configured again+ later.+ </AlertDialogDescription></AlertDialogHeader>- <form- onSubmit={(e) => {- e.preventDefault();- handleDelete();- }}- >- <Field>- <FieldLabel htmlFor="remove-auth-confirm">- Type <span className="font-bold text-foreground">confirm</span> to perform this action- </FieldLabel>- <FieldContent>- <Input- id="remove-auth-confirm"- value={removeConfirmInput}- onChange={(e) => setRemoveConfirmInput(e.target.value)}- placeholder="Type confirm here"- autoComplete="off"- />- </FieldContent>- </Field>- </form>+ <AlertDialogConfirmationField+ inputProps={{ disabled: isRemoving }}+ onConfirm={() => handleDelete().catch(() => undefined)}+ /><AlertDialogFooter>- <AlertDialogCancel>Cancel</AlertDialogCancel>+ <AlertDialogCancel isDisabled={isRemoving}>Cancel</AlertDialogCancel><AlertDialogActionvariant="danger"- onClick={handleDelete}- isDisabled={!isRemoveConfirmed}+ isPending={isRemoving}+ onClick={(event) => {+ event.preventDefault();+ handleDelete().catch(() => undefined);+ }}>- Remove+ Remove Auth Method</AlertDialogAction></AlertDialogFooter></AlertDialogContent>