Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

improvement(ui): build ConfirmationAlertDialog on AlertDialog confirmation state and migrate hand-rolled typed confirms (#8829)

Andrew Huang03e90bf549c0
diff --git a/frontend/src/components/V3_MIGRATION.md b/frontend/src/components/V3_MIGRATION.md
index fb377d3e52..83a050b958 100644
--- a/frontend/src/components/V3_MIGRATION.md
+++ b/frontend/src/components/V3_MIGRATION.md
@@ -301,7 +301,7 @@ After:
- **Chained confirmations.** If `onConfirm` opens a second dialog instead of closing, as `IntegrationsDetailsByIDPage` does, keep that control flow and check the second dialog's focus return.
- **Pending state outside the form.** If the mutation runs in the parent, pass the mutation's `isPending` to `DialogContent` or `ConfirmationAlertDialog`. Do not add `onOpenChange` guards.
- **Reset and discard.** Keep the consumer's `reset()` or state clearing on close. Radix unmounts closed content, so state inside the content subtree resets by itself. Add `useDiscardChangesGuard` only when the product asks for a dirty-form guard; V2 never had one.
-- **Existing AlertDialog compositions** with `confirmationValue` do not lock while pending. New typed confirmations use `ConfirmationAlertDialog`.
+- **Existing AlertDialog compositions** with `confirmationValue` lock while pending when the mutation's `isPending` is passed to `AlertDialog`: Escape, Cancel, the confirmation input, and Enter are disabled, and `AlertDialogAction` shows the pending state. New typed confirmations use `ConfirmationAlertDialog`, which is built on the same confirmation state.
- **Proof.** For each sweep, open each migrated overlay once in the preview: Escape with a nested popup open, Escape and an outside click while a mutation is pending, and focus after close.
## Completion acceptance
diff --git a/frontend/src/components/v3/generic/AlertDialog/AlertDialog.tsx b/frontend/src/components/v3/generic/AlertDialog/AlertDialog.tsx
index 0aa194c732..cd4ff31ce9 100644
--- a/frontend/src/components/v3/generic/AlertDialog/AlertDialog.tsx
+++ b/frontend/src/components/v3/generic/AlertDialog/AlertDialog.tsx
@@ -14,6 +14,7 @@ type AlertDialogConfirmationContextValue = {
confirmationValue?: string;
inputValue: string;
isConfirmed: boolean;
+ isPending: boolean;
setInputValue: React.Dispatch<React.SetStateAction<string>>;
};
@@ -21,11 +22,13 @@ const AlertDialogConfirmationContext = React.createContext<AlertDialogConfirmati
actionRef: { current: null },
inputValue: "",
isConfirmed: true,
+ isPending: false,
setInputValue: () => undefined
});
type AlertDialogProps = React.ComponentProps<typeof AlertDialogPrimitive.Root> & {
confirmationValue?: string;
+ isPending?: boolean;
};
function AlertDialog(alertDialogProps: AlertDialogProps) {
@@ -33,21 +36,26 @@ function AlertDialog(alertDialogProps: AlertDialogProps) {
alertDialogProps,
"confirmationValue"
);
- const { confirmationValue, onOpenChange, ...props } = alertDialogProps;
+ const { confirmationValue, isPending = false, onOpenChange, ...props } = alertDialogProps;
const [inputValue, setInputValue] = React.useState("");
const actionRef = React.useRef<HTMLButtonElement>(null);
const isConfirmed =
- !hasConfirmation || (confirmationValue !== undefined && inputValue === confirmationValue);
+ !hasConfirmation || (Boolean(confirmationValue) && inputValue === confirmationValue);
const confirmationContextValue = React.useMemo(
- () => ({ actionRef, confirmationValue, inputValue, isConfirmed, setInputValue }),
- [confirmationValue, inputValue, isConfirmed]
+ () => ({ actionRef, confirmationValue, inputValue, isConfirmed, isPending, setInputValue }),
+ [confirmationValue, inputValue, isConfirmed, isPending]
);
React.useEffect(() => {
if (props.open === false) setInputValue("");
}, [props.open]);
+ React.useEffect(() => {
+ setInputValue("");
+ }, [confirmationValue]);
+
const handleOpenChange = (open: boolean) => {
+ if (!open && isPending) return;
if (!open) setInputValue("");
onOpenChange?.(open);
};
@@ -102,6 +110,7 @@ function AlertDialogContent({
}) {
const { contextValue, guardDismiss, captureFocusReturn, restoreFocusReturn } =
useOverlayLayer(false);
+ const { isPending } = React.useContext(AlertDialogConfirmationContext);
return (
<AlertDialogPortal>
@@ -130,7 +139,13 @@ function AlertDialogContent({
if (focusedInput) event.preventDefault();
}}
onCloseAutoFocus={(event) => restoreFocusReturn(event, onCloseAutoFocus)}
- onEscapeKeyDown={(event) => guardDismiss(event, onEscapeKeyDown)}
+ onEscapeKeyDown={(event) => {
+ if (isPending) {
+ event.preventDefault();
+ return;
+ }
+ guardDismiss(event, onEscapeKeyDown);
+ }}
{...props}
>
<OverlayLayerContext.Provider value={contextValue}>{children}</OverlayLayerContext.Provider>
@@ -311,9 +326,8 @@ function AlertDialogConfirmationField({
onConfirm?: () => void;
}) {
const inputId = React.useId();
- const { actionRef, confirmationValue, inputValue, isConfirmed, setInputValue } = React.useContext(
- AlertDialogConfirmationContext
- );
+ const { actionRef, confirmationValue, inputValue, isConfirmed, isPending, setInputValue } =
+ React.useContext(AlertDialogConfirmationContext);
return (
<div data-slot="alert-dialog-confirmation-field" className={cn("mt-4", className)} {...props}>
@@ -328,13 +342,15 @@ function AlertDialogConfirmationField({
<Input
autoComplete="off"
placeholder={confirmationValue}
+ spellCheck={false}
{...inputProps}
+ disabled={inputProps?.disabled || isPending}
id={inputProps?.id ?? inputId}
value={inputValue}
onChange={(event) => setInputValue(event.target.value)}
onKeyDown={(event) => {
inputProps?.onKeyDown?.(event);
- if (!event.defaultPrevented && event.key === "Enter" && isConfirmed) {
+ if (!event.defaultPrevented && event.key === "Enter" && isConfirmed && !isPending) {
event.preventDefault();
if (onConfirm) {
onConfirm();
@@ -364,7 +380,11 @@ function AlertDialogAction({
React.ComponentProps<typeof Button>,
"variant" | "size" | "isFullWidth" | "isDisabled" | "isPending"
>) {
- const { actionRef, isConfirmed } = React.useContext(AlertDialogConfirmationContext);
+ const {
+ actionRef,
+ isConfirmed,
+ isPending: isDialogPending
+ } = React.useContext(AlertDialogConfirmationContext);
const setActionRef = React.useCallback(
(node: HTMLButtonElement | null) => {
@@ -390,9 +410,9 @@ function AlertDialogAction({
data-slot="alert-dialog-action"
variant={variant}
size={size}
- isPending={isPending}
+ isPending={isPending || isDialogPending}
isFullWidth={isFullWidth}
- isDisabled={isDisabled || !isConfirmed}
+ isDisabled={isDisabled || !isConfirmed || isDialogPending}
className={cn(className)}
{...props}
/>
@@ -409,8 +429,16 @@ function AlertDialogCancel({
...props
}: React.ComponentProps<typeof AlertDialogPrimitive.Cancel> &
Pick<React.ComponentProps<typeof Button>, "variant" | "size" | "isFullWidth" | "isDisabled">) {
+ const { isPending } = React.useContext(AlertDialogConfirmationContext);
+
return (
- <Button variant={variant} size={size} isFullWidth={isFullWidth} isDisabled={isDisabled} asChild>
+ <Button
+ variant={variant}
+ size={size}
+ isFullWidth={isFullWidth}
+ isDisabled={isDisabled || isPending}
+ asChild
+ >
<AlertDialogPrimitive.Cancel
data-slot="alert-dialog-cancel"
className={cn(className)}
diff --git a/frontend/src/components/v3/platform/ConfirmationAlertDialog/ConfirmationAlertDialog.tsx b/frontend/src/components/v3/platform/ConfirmationAlertDialog/ConfirmationAlertDialog.tsx
index 8da435a081..3e4104f28f 100644
--- a/frontend/src/components/v3/platform/ConfirmationAlertDialog/ConfirmationAlertDialog.tsx
+++ b/frontend/src/components/v3/platform/ConfirmationAlertDialog/ConfirmationAlertDialog.tsx
@@ -1,19 +1,17 @@
-import { FormEvent, ReactNode, useEffect, useId, useRef, useState } from "react";
+import { ReactNode, useRef, useState } from "react";
import {
AlertDialog,
+ AlertDialogAction,
AlertDialogCancel,
AlertDialogConfirmationField,
- AlertDialogConfirmationLabel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle
} from "../../generic/AlertDialog";
-import { Button, type ButtonProps } from "../../generic/Button";
-import { Field } from "../../generic/Field";
-import { Input } from "../../generic/Input";
+import { type ButtonProps } from "../../generic/Button";
type Props = {
isOpen: boolean;
@@ -45,20 +43,11 @@ export const ConfirmationAlertDialog = ({
confirmVariant = "danger",
children
} = isOpen ? contentProps : lastOpenContent.current;
- const [typedValue, setTypedValue] = useState("");
const [isConfirming, setIsConfirming] = useState(false);
- const confirmationInputId = useId();
const isActionPending = Boolean(isPending || isConfirming);
- useEffect(() => {
- setTypedValue("");
- }, [confirmKey, isOpen]);
-
- const canConfirm = Boolean(confirmKey) && typedValue === confirmKey && !isActionPending;
-
- const handleSubmit = (event: FormEvent<HTMLFormElement>) => {
- event.preventDefault();
- if (!canConfirm) return;
+ const handleConfirm = () => {
+ if (isActionPending) return;
setIsConfirming(true);
Promise.resolve()
@@ -70,52 +59,33 @@ export const ConfirmationAlertDialog = ({
return (
<AlertDialog
open={isOpen}
- onOpenChange={(open) => {
- if (!open && isActionPending) return;
- onOpenChange(open);
- }}
+ onOpenChange={onOpenChange}
+ confirmationValue={confirmKey}
+ isPending={isActionPending}
>
<AlertDialogContent>
- <form className="contents" onSubmit={handleSubmit}>
- <AlertDialogHeader>
- <AlertDialogTitle>{title}</AlertDialogTitle>
- {description ? (
- <AlertDialogDescription asChild>
- <div className="w-full">{description}</div>
- </AlertDialogDescription>
- ) : null}
- </AlertDialogHeader>
- <AlertDialogConfirmationField>
- <Field>
- <AlertDialogConfirmationLabel
- htmlFor={confirmationInputId}
- confirmationValue={confirmKey}
- />
- <Input
- id={confirmationInputId}
- autoComplete="off"
- disabled={isActionPending}
- placeholder={confirmKey}
- spellCheck={false}
- value={typedValue}
- onChange={(event) => setTypedValue(event.target.value)}
- />
- </Field>
- </AlertDialogConfirmationField>
- {children}
- <AlertDialogFooter>
- <AlertDialogCancel isDisabled={isActionPending}>Cancel</AlertDialogCancel>
- <Button
- type="submit"
- variant={confirmVariant}
- size="sm"
- isDisabled={!canConfirm}
- isPending={isActionPending}
- >
- {confirmLabel}
- </Button>
- </AlertDialogFooter>
- </form>
+ <AlertDialogHeader>
+ <AlertDialogTitle>{title}</AlertDialogTitle>
+ {description ? (
+ <AlertDialogDescription asChild>
+ <div className="w-full">{description}</div>
+ </AlertDialogDescription>
+ ) : null}
+ </AlertDialogHeader>
+ <AlertDialogConfirmationField onConfirm={handleConfirm} />
+ {children}
+ <AlertDialogFooter>
+ <AlertDialogCancel>Cancel</AlertDialogCancel>
+ <AlertDialogAction
+ variant={confirmVariant}
+ onClick={(event) => {
+ event.preventDefault();
+ handleConfirm();
+ }}
+ >
+ {confirmLabel}
+ </AlertDialogAction>
+ </AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
);
diff --git a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentitySection.tsx b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentitySection.tsx
index f79b5b06be..3931c2390b 100644
--- a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentitySection.tsx
+++ b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentitySection.tsx
@@ -1,4 +1,4 @@
-import { useEffect, useState } from "react";
+import { useState } from "react";
import { PlusIcon } from "lucide-react";
import {
@@ -8,14 +8,6 @@ import {
import { createNotification } from "@app/components/notifications";
import { OrgPermissionCan } from "@app/components/permissions";
import {
- AlertDialog,
- AlertDialogAction,
- AlertDialogCancel,
- AlertDialogContent,
- AlertDialogDescription,
- AlertDialogFooter,
- AlertDialogHeader,
- AlertDialogTitle,
Button,
Card,
CardAction,
@@ -23,10 +15,8 @@ import {
CardDescription,
CardHeader,
CardTitle,
- DocumentationLinkBadge,
- Field,
- FieldLabel,
- Input
+ ConfirmationAlertDialog,
+ DocumentationLinkBadge
} from "@app/components/v3";
import {
OrgPermissionIdentityActions,
@@ -65,56 +55,17 @@ const ConfirmDeleteDialog = ({
isPending,
onOpenChange,
onConfirm
-}: ConfirmDeleteDialogProps) => {
- const [confirmation, setConfirmation] = useState("");
-
- useEffect(() => {
- if (!isOpen) setConfirmation("");
- }, [isOpen]);
-
- return (
- <AlertDialog
- open={isOpen}
- onOpenChange={(open) => {
- onOpenChange(open);
- }}
- >
- <AlertDialogContent>
- <AlertDialogHeader>
- <AlertDialogTitle>Delete {name}?</AlertDialogTitle>
- <AlertDialogDescription>
- This action cannot be undone. Type &quot;confirm&quot; to continue.
- </AlertDialogDescription>
- </AlertDialogHeader>
- <Field>
- <FieldLabel htmlFor="delete-identity-resource-confirmation">
- Type &quot;confirm&quot; to confirm
- </FieldLabel>
- <Input
- id="delete-identity-resource-confirmation"
- value={confirmation}
- onChange={(event) => setConfirmation(event.target.value)}
- autoComplete="off"
- />
- </Field>
- <AlertDialogFooter>
- <AlertDialogCancel isDisabled={isPending}>Cancel</AlertDialogCancel>
- <AlertDialogAction
- variant="danger"
- isDisabled={confirmation !== "confirm"}
- isPending={isPending}
- onClick={(event) => {
- event.preventDefault();
- onConfirm();
- }}
- >
- Delete
- </AlertDialogAction>
- </AlertDialogFooter>
- </AlertDialogContent>
- </AlertDialog>
- );
-};
+}: ConfirmDeleteDialogProps) => (
+ <ConfirmationAlertDialog
+ isOpen={isOpen}
+ onOpenChange={onOpenChange}
+ title={`Delete ${name}?`}
+ description="This action cannot be undone."
+ confirmKey="confirm"
+ isPending={isPending}
+ onConfirm={onConfirm}
+ />
+);
const IdentitySectionContent = ({ view = "identities" }: Props) => {
const { subscription } = useSubscription();
diff --git a/frontend/src/pages/organization/SettingsPage/components/OrgWorkflowIntegrationTab/OrgWorkflowIntegrationTab.tsx b/frontend/src/pages/organization/SettingsPage/components/OrgWorkflowIntegrationTab/OrgWorkflowIntegrationTab.tsx
index 033072845f..4aa20f2d9f 100644
--- a/frontend/src/pages/organization/SettingsPage/components/OrgWorkflowIntegrationTab/OrgWorkflowIntegrationTab.tsx
+++ b/frontend/src/pages/organization/SettingsPage/components/OrgWorkflowIntegrationTab/OrgWorkflowIntegrationTab.tsx
@@ -1,4 +1,3 @@
-import { useState } from "react";
import { BsMicrosoftTeams, BsSlack } from "react-icons/bs";
import axios from "axios";
import { Info, MoreHorizontal, Plus, RotateCcw, ShieldCheck, Trash2 } from "lucide-react";
@@ -6,14 +5,6 @@ import { Info, MoreHorizontal, Plus, RotateCcw, ShieldCheck, Trash2 } from "luci
import { createNotification } from "@app/components/notifications";
import { OrgPermissionCan } from "@app/components/permissions";
import {
- AlertDialog,
- AlertDialogCancel,
- AlertDialogContent,
- AlertDialogDescription,
- AlertDialogFooter,
- AlertDialogHeader,
- AlertDialogMedia,
- AlertDialogTitle,
Badge,
Button,
Card,
@@ -22,6 +13,7 @@ import {
CardDescription,
CardHeader,
CardTitle,
+ ConfirmationAlertDialog,
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
@@ -31,7 +23,6 @@ import {
EmptyHeader,
EmptyTitle,
IconButton,
- Input,
Skeleton,
Table,
TableBody,
@@ -81,7 +72,6 @@ export const OrgWorkflowIntegrationTab = withPermission(
"integrationDetails",
"removeIntegration"
] as const);
- const [deleteConfirmation, setDeleteConfirmation] = useState("");
const { currentOrg } = useOrganization();
const { data: workflowIntegrations, isPending: isWorkflowIntegrationsLoading } =
@@ -123,7 +113,6 @@ export const OrgWorkflowIntegrationTab = withPermission(
}
handlePopUpClose("removeIntegration");
- setDeleteConfirmation("");
createNotification({
text: `Deleted integration "${slug}"`,
type: "success"
@@ -348,55 +337,15 @@ export const OrgWorkflowIntegrationTab = withPermission(
id={popUp.integrationDetails?.data?.id}
onOpenChange={(state) => handlePopUpToggle("integrationDetails", state)}
/>
- <AlertDialog
- open={popUp.removeIntegration.isOpen}
- onOpenChange={(isOpen) => {
- handlePopUpToggle("removeIntegration", isOpen);
- if (!isOpen) setDeleteConfirmation("");
- }}
- >
- <AlertDialogContent>
- <AlertDialogHeader>
- <AlertDialogMedia>
- <Trash2 />
- </AlertDialogMedia>
- <AlertDialogTitle>
- Delete integration &quot;{removeIntegrationData?.slug}&quot;?
- </AlertDialogTitle>
- <AlertDialogDescription>
- Projects using this integration will stop sending notifications to it. This cannot
- be undone.
- </AlertDialogDescription>
- </AlertDialogHeader>
- <div className="w-full">
- <p className="mb-2 text-sm text-muted">
- Type {removeIntegrationData?.slug ?? ""} to confirm.
- </p>
- <Input
- value={deleteConfirmation}
- onChange={(e) => setDeleteConfirmation(e.target.value)}
- placeholder={removeIntegrationData?.slug ?? ""}
- aria-label="Confirm integration alias"
- />
- </div>
- <AlertDialogFooter>
- <AlertDialogCancel>Cancel</AlertDialogCancel>
- <Button
- variant="danger"
- size="sm"
- onClick={handleRemoveIntegration}
- isPending={isDeletingIntegration}
- isDisabled={
- isDeletingIntegration ||
- !removeIntegrationData?.slug ||
- deleteConfirmation !== removeIntegrationData.slug
- }
- >
- Delete
- </Button>
- </AlertDialogFooter>
- </AlertDialogContent>
- </AlertDialog>
+ <ConfirmationAlertDialog
+ isOpen={popUp.removeIntegration.isOpen}
+ onOpenChange={(isOpen) => handlePopUpToggle("removeIntegration", isOpen)}
+ title={`Delete integration "${removeIntegrationData?.slug ?? ""}"?`}
+ description="Projects using this integration will stop sending notifications to it. This cannot be undone."
+ confirmKey={removeIntegrationData?.slug ?? ""}
+ isPending={isDeletingIntegration}
+ onConfirm={handleRemoveIntegration}
+ />
</Card>
);
},
diff --git a/frontend/src/pages/project/MemberDetailsByIDPage/components/MemberRoleDetailsSection/MemberRoleDetailsSection.tsx b/frontend/src/pages/project/MemberDetailsByIDPage/components/MemberRoleDetailsSection/MemberRoleDetailsSection.tsx
index b054bb794f..f491876be5 100644
--- a/frontend/src/pages/project/MemberDetailsByIDPage/components/MemberRoleDetailsSection/MemberRoleDetailsSection.tsx
+++ b/frontend/src/pages/project/MemberDetailsByIDPage/components/MemberRoleDetailsSection/MemberRoleDetailsSection.tsx
@@ -1,4 +1,4 @@
-import { useMemo, useState } from "react";
+import { useMemo } from "react";
import { useNavigate } from "@tanstack/react-router";
import { format, formatDistance } from "date-fns";
import { ClockAlertIcon, ClockIcon, EllipsisIcon, PencilIcon } from "lucide-react";
@@ -6,17 +6,10 @@ import picomatch from "picomatch";
import { createNotification } from "@app/components/notifications";
import { ProjectPermissionCan } from "@app/components/permissions";
-import { PageLoader } from "@app/components/v3";
+import { ConfirmationAlertDialog, PageLoader } from "@app/components/v3";
import {
Alert,
AlertDescription,
- AlertDialog,
- AlertDialogAction,
- AlertDialogCancel,
- AlertDialogContent,
- AlertDialogFooter,
- AlertDialogHeader,
- AlertDialogTitle,
Badge,
Button,
Card,
@@ -39,10 +32,7 @@ import {
EmptyDescription,
EmptyHeader,
EmptyTitle,
- Field,
- FieldLabel,
IconButton,
- Input,
Sheet,
SheetContent,
SheetDescription,
@@ -94,7 +84,6 @@ export const MemberRoleDetailsSection = ({
const { projectId, currentProject } = useProject();
const { permission } = useProjectPermission();
const navigate = useNavigate();
- const [deleteRoleConfirmation, setDeleteRoleConfirmation] = useState("");
const assignRoleConditions = useMemo(
() => getMemberAssignRoleConditions(permission),
@@ -156,7 +145,6 @@ export const MemberRoleDetailsSection = ({
membershipId: isCertManager ? membershipDetails.user.id : membershipDetails.id
});
createNotification({ type: "success", text: "Successfully removed role" });
- setDeleteRoleConfirmation("");
handlePopUpClose("deleteRole");
};
@@ -401,55 +389,20 @@ export const MemberRoleDetailsSection = ({
</CardContent>
</Card>
- <AlertDialog
- open={popUp.deleteRole.isOpen}
- onOpenChange={(isOpen) => {
- if (updateUserWorkspaceRole.isPending) return;
- if (!isOpen) setDeleteRoleConfirmation("");
- handlePopUpToggle("deleteRole", isOpen);
- }}
- >
- <AlertDialogContent>
- <AlertDialogHeader>
- <AlertDialogTitle>
- Remove role &quot;{(popUp?.deleteRole?.data as TProjectRole)?.slug}&quot;?
- </AlertDialogTitle>
- <Alert variant="danger" appearance="borderless">
- <AlertDescription>
- This role will no longer grant access to this user.
- </AlertDescription>
- </Alert>
- </AlertDialogHeader>
- <Field>
- <FieldLabel htmlFor="remove-member-role-confirmation">
- Type &quot;remove&quot; to confirm
- </FieldLabel>
- <Input
- id="remove-member-role-confirmation"
- value={deleteRoleConfirmation}
- onChange={(event) => setDeleteRoleConfirmation(event.target.value)}
- autoComplete="off"
- disabled={updateUserWorkspaceRole.isPending}
- />
- </Field>
- <AlertDialogFooter>
- <AlertDialogCancel isDisabled={updateUserWorkspaceRole.isPending}>
- Cancel
- </AlertDialogCancel>
- <AlertDialogAction
- variant="danger"
- isPending={updateUserWorkspaceRole.isPending}
- isDisabled={deleteRoleConfirmation !== "remove"}
- onClick={(event) => {
- event.preventDefault();
- handleRoleDelete().catch(() => undefined);
- }}
- >
- Remove Role
- </AlertDialogAction>
- </AlertDialogFooter>
- </AlertDialogContent>
- </AlertDialog>
+ <ConfirmationAlertDialog
+ isOpen={popUp.deleteRole.isOpen}
+ onOpenChange={(isOpen) => handlePopUpToggle("deleteRole", isOpen)}
+ title={`Remove role "${(popUp?.deleteRole?.data as TProjectRole)?.slug}"?`}
+ description={
+ <Alert variant="danger" appearance="borderless">
+ <AlertDescription>This role will no longer grant access to this user.</AlertDescription>
+ </Alert>
+ }
+ confirmKey="remove"
+ confirmLabel="Remove Role"
+ isPending={updateUserWorkspaceRole.isPending}
+ onConfirm={handleRoleDelete}
+ />
<Sheet
open={popUp.modifyManyRoles.isOpen}
onOpenChange={(isOpen) => handlePopUpToggle("modifyManyRoles", isOpen)}
diff --git a/frontend/src/pages/project/RoleDetailsBySlugPage/components/DeleteProjectRoleDialog.tsx b/frontend/src/pages/project/RoleDetailsBySlugPage/components/DeleteProjectRoleDialog.tsx
index d168819fd3..b7fab487dc 100644
--- a/frontend/src/pages/project/RoleDetailsBySlugPage/components/DeleteProjectRoleDialog.tsx
+++ b/frontend/src/pages/project/RoleDetailsBySlugPage/components/DeleteProjectRoleDialog.tsx
@@ -1,18 +1,4 @@
-import { useState } from "react";
-
-import {
- AlertDialog,
- AlertDialogAction,
- AlertDialogCancel,
- AlertDialogContent,
- AlertDialogDescription,
- AlertDialogFooter,
- AlertDialogHeader,
- AlertDialogTitle,
- Field,
- FieldLabel,
- Input
-} from "@app/components/v3";
+import { ConfirmationAlertDialog } from "@app/components/v3";
import { useProject } from "@app/context";
import { ProjectType } from "@app/hooks/api/projects/types";
@@ -34,55 +20,17 @@ export const DeleteProjectRoleDialog = ({
onConfirm
}: Props) => {
const { currentProject } = useProject();
- const [confirmation, setConfirmation] = useState("");
- const isConfirmed = confirmation === confirmationKey;
-
- const handleOpenChange = (open: boolean) => {
- if (!open) setConfirmation("");
- onOpenChange(open);
- };
return (
- <AlertDialog open={isOpen} onOpenChange={handleOpenChange}>
- <AlertDialogContent>
- <AlertDialogHeader>
- <AlertDialogTitle>Delete &quot;{roleName}&quot;?</AlertDialogTitle>
- <AlertDialogDescription>
- This {currentProject.type === ProjectType.CertificateManager ? "role" : "project role"}{" "}
- and its policies will be deleted. This action cannot be undone.
- </AlertDialogDescription>
- </AlertDialogHeader>
- <Field>
- <FieldLabel htmlFor="delete-project-role-confirmation">
- Type &quot;{confirmationKey}&quot; to confirm
- </FieldLabel>
- <Input
- id="delete-project-role-confirmation"
- value={confirmation}
- onChange={(event) => setConfirmation(event.target.value)}
- autoComplete="off"
- disabled={isPending}
- />
- </Field>
- <AlertDialogFooter>
- <AlertDialogCancel isDisabled={isPending}>Cancel</AlertDialogCancel>
- <AlertDialogAction
- variant="danger"
- isDisabled={!isConfirmed}
- isPending={isPending}
- onClick={async (event) => {
- event.preventDefault();
- try {
- await onConfirm();
- } catch {
- // Mutation errors are surfaced globally and the dialog stays open for retry.
- }
- }}
- >
- Delete Role
- </AlertDialogAction>
- </AlertDialogFooter>
- </AlertDialogContent>
- </AlertDialog>
+ <ConfirmationAlertDialog
+ isOpen={isOpen}
+ onOpenChange={onOpenChange}
+ title={`Delete "${roleName}"?`}
+ description={`This ${currentProject.type === ProjectType.CertificateManager ? "role" : "project role"} and its policies will be deleted. This action cannot be undone.`}
+ confirmKey={confirmationKey}
+ confirmLabel="Delete Role"
+ isPending={isPending}
+ onConfirm={onConfirm}
+ />
);
};