Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

refactor(web): Create design-system Dialog and DialogController (#17477)

Ben Bachem71103ff53ad0
diff --git a/web/src/components/design-system/Dialog/Dialog.module.css b/web/src/components/design-system/Dialog/Dialog.module.css
new file mode 100644
index 0000000000..9d83948f4c
--- /dev/null
+++ b/web/src/components/design-system/Dialog/Dialog.module.css
@@ -0,0 +1,71 @@
+.content {
+ transform-origin: center center;
+}
+
+.content[data-state="open"] {
+ animation: dialogContentIn 800ms cubic-bezier(0.16, 1, 0.3, 1) both;
+}
+
+.content[data-state="closed"] {
+ animation: dialogContentOut 180ms cubic-bezier(0.4, 0, 1, 1) both;
+}
+
+.content[data-state="closed"] * {
+ pointer-events: none;
+}
+
+.overlay[data-state="open"] {
+ animation: dialogOverlayIn 200ms ease-out both;
+}
+
+.overlay[data-state="closed"] {
+ animation: dialogOverlayOut 180ms ease-in both;
+}
+
+@keyframes dialogContentIn {
+ 0% {
+ opacity: 0;
+ scale: 0.95;
+ }
+
+ 50% {
+ opacity: 1;
+ }
+
+ 100% {
+ opacity: 1;
+ scale: 1;
+ }
+}
+
+@keyframes dialogContentOut {
+ from {
+ opacity: 1;
+ scale: 1;
+ }
+
+ to {
+ opacity: 0;
+ scale: 0.95;
+ }
+}
+
+@keyframes dialogOverlayIn {
+ from {
+ opacity: 0;
+ }
+
+ to {
+ opacity: 1;
+ }
+}
+
+@keyframes dialogOverlayOut {
+ from {
+ opacity: 1;
+ }
+
+ to {
+ opacity: 0;
+ }
+}
diff --git a/web/src/components/design-system/Dialog/Dialog.stories.tsx b/web/src/components/design-system/Dialog/Dialog.stories.tsx
new file mode 100644
index 0000000000..f4a10330b4
--- /dev/null
+++ b/web/src/components/design-system/Dialog/Dialog.stories.tsx
@@ -0,0 +1,166 @@
+import * as React from "react";
+import { expect, fn, userEvent, waitFor, within } from "storybook/test";
+
+import preview from "../../../../.storybook/preview";
+import { DialogController } from "@/src/components/design-system/DialogController/DialogController";
+
+import { Dialog } from "./Dialog";
+
+type Size = NonNullable<React.ComponentProps<typeof Dialog>["size"]>;
+
+const allSizes = Object.keys({
+ sm: true,
+ default: true,
+ lg: true,
+ xxl: true,
+} satisfies Record<Size, true>) as Size[];
+
+const meta = preview.meta({
+ component: Dialog,
+ parameters: {
+ layout: "fullscreen",
+ },
+});
+
+export default meta;
+
+export const VariantMatrix = meta.story({
+ parameters: {
+ controls: {
+ disable: true,
+ },
+ },
+ render: () => (
+ <div className="grid max-w-sm gap-3 p-6">
+ {allSizes.map((size) => (
+ <DialogController
+ key={size}
+ renderDialog={() => (
+ <Dialog
+ size={size}
+ title={`${size} dialog`}
+ text="Dialog body content remains readable at every supported size."
+ actions={[{ label: "Continue", onClick: fn() }]}
+ />
+ )}
+ >
+ {({ openDialog }) => (
+ <button
+ className="rounded-md border px-3 py-2 text-left text-sm"
+ type="button"
+ onClick={() => openDialog()}
+ >
+ Open {size}
+ </button>
+ )}
+ </DialogController>
+ ))}
+ </div>
+ ),
+});
+
+export const Autofocus = meta.story({
+ name: "(Test) Autofocus",
+ render: () => (
+ <DialogController
+ renderDialog={() => (
+ <Dialog
+ title="Text-only dialog"
+ text="The primary action receives focus when this dialog opens."
+ actions={[
+ { label: "Go back", onClick: fn() },
+ { label: "Continue", onClick: fn() },
+ ]}
+ />
+ )}
+ >
+ {({ openDialog }) => (
+ <button type="button" onClick={() => openDialog()}>
+ Open dialog
+ </button>
+ )}
+ </DialogController>
+ ),
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const body = within(canvasElement.ownerDocument.body);
+
+ await userEvent.click(canvas.getByRole("button", { name: "Open dialog" }));
+ await waitFor(() =>
+ expect(body.getByRole("button", { name: "Continue" })).toHaveFocus(),
+ );
+ },
+});
+
+export const DestructiveAutofocus = meta.story({
+ name: "(Test) Destructive autofocus",
+ render: () => (
+ <DialogController
+ renderDialog={() => (
+ <Dialog
+ title="Delete item"
+ text="This action cannot be undone."
+ actions={[
+ { label: "Keep item", onClick: fn() },
+ {
+ label: "Delete",
+ onClick: fn(),
+ variant: "destructive",
+ },
+ ]}
+ />
+ )}
+ >
+ {({ openDialog }) => (
+ <button type="button" onClick={() => openDialog()}>
+ Open dialog
+ </button>
+ )}
+ </DialogController>
+ ),
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const body = within(canvasElement.ownerDocument.body);
+
+ await userEvent.click(canvas.getByRole("button", { name: "Open dialog" }));
+ await waitFor(() =>
+ expect(body.getByRole("button", { name: "Keep item" })).toHaveFocus(),
+ );
+ },
+});
+
+export const DestructiveOnlyAutofocus = meta.story({
+ name: "(Test) Destructive-only autofocus",
+ render: () => (
+ <DialogController
+ renderDialog={() => (
+ <Dialog
+ title="Delete item"
+ text="This action cannot be undone."
+ actions={[
+ {
+ label: "Delete",
+ onClick: fn(),
+ variant: "destructive",
+ },
+ ]}
+ />
+ )}
+ >
+ {({ openDialog }) => (
+ <button type="button" onClick={() => openDialog()}>
+ Open dialog
+ </button>
+ )}
+ </DialogController>
+ ),
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const body = within(canvasElement.ownerDocument.body);
+
+ await userEvent.click(canvas.getByRole("button", { name: "Open dialog" }));
+ await waitFor(() =>
+ expect(body.getByRole("button", { name: "Cancel" })).toHaveFocus(),
+ );
+ },
+});
diff --git a/web/src/components/design-system/Dialog/Dialog.tsx b/web/src/components/design-system/Dialog/Dialog.tsx
new file mode 100644
index 0000000000..9c3a854d48
--- /dev/null
+++ b/web/src/components/design-system/Dialog/Dialog.tsx
@@ -0,0 +1,181 @@
+/* eslint-disable boundaries/dependencies */
+"use client";
+
+import * as DialogPrimitive from "@radix-ui/react-dialog";
+import { cva, type VariantProps } from "class-variance-authority";
+import { X, type LucideIcon } from "lucide-react";
+import * as React from "react";
+
+import { Button } from "@/src/components/ui/button";
+import { useLayerContainer } from "@/src/context/LayerContext/LayerContext";
+import { cn } from "@/src/utils/tailwind";
+
+import motionStyles from "./Dialog.module.css";
+
+const dialogContentVariants = cva(
+ "fixed left-[50%] top-[50%] flex max-h-[85vh] w-full translate-x-[-50%] translate-y-[-50%] flex-col overflow-hidden bg-modal shadow-lg sm:rounded-lg",
+ {
+ variants: {
+ size: {
+ sm: "max-w-md",
+ default: "max-w-lg",
+ lg: "max-w-4xl",
+ xxl: "h-[90vh] max-w-[95vw]",
+ },
+ },
+ defaultVariants: {
+ size: "default",
+ },
+ },
+);
+
+type DialogAction = {
+ disabled?: boolean;
+ form?: string;
+ icon?: LucideIcon;
+ label: string;
+ loading?: boolean;
+ onClick?: React.MouseEventHandler<HTMLButtonElement>;
+ type?: "button" | "submit";
+ variant?: "default" | "destructive";
+};
+
+type DialogProps = {
+ actions?: ReadonlyArray<DialogAction>;
+ closeOnInteractionOutside?: boolean;
+ size?: VariantProps<typeof dialogContentVariants>["size"];
+ title: string;
+} & (
+ | { children?: React.ReactNode; text?: never }
+ | { children?: never; text: string }
+);
+
+function DialogRoot({
+ actions,
+ children,
+ closeOnInteractionOutside = false,
+ size,
+ text,
+ title,
+}: DialogProps) {
+ const container = useLayerContainer("modal");
+ const cancelButtonRef = React.useRef<HTMLButtonElement>(null);
+ const actionButtonRefs = React.useRef<Array<HTMLButtonElement | null>>([]);
+
+ return (
+ <DialogPrimitive.Portal container={container}>
+ <DialogPrimitive.Overlay
+ className={cn(
+ motionStyles.overlay,
+ "fixed inset-0 bg-black/25 dark:bg-black/45",
+ )}
+ onClick={(event) => event.stopPropagation()}
+ />
+ <DialogPrimitive.Content
+ aria-describedby={undefined}
+ className={cn(motionStyles.content, dialogContentVariants({ size }))}
+ onOpenAutoFocus={(event) => {
+ // Radix otherwise focuses Cancel because it is the first tabbable.
+ // Prefer the rightmost safe action, falling back to Cancel rather
+ // than immediately triggering a destructive action.
+ if (text === undefined) return;
+
+ let safeActionButton: HTMLButtonElement | null = null;
+ for (let index = (actions?.length ?? 0) - 1; index >= 0; index--) {
+ const action = actions?.[index];
+ const button = actionButtonRefs.current[index];
+ if (
+ action?.variant !== "destructive" &&
+ button &&
+ !button.disabled
+ ) {
+ safeActionButton = button;
+ break;
+ }
+ }
+
+ event.preventDefault();
+ if (safeActionButton) {
+ safeActionButton.focus();
+ return;
+ }
+
+ cancelButtonRef.current?.focus();
+ }}
+ onClick={(event) => event.stopPropagation()}
+ onKeyDown={(event) => {
+ if (event.key === "Enter" || event.key === " ") {
+ event.stopPropagation();
+ }
+ }}
+ onPointerDownOutside={(event) => {
+ if (!closeOnInteractionOutside) event.preventDefault();
+ }}
+ onInteractOutside={(event) => {
+ if (!closeOnInteractionOutside) event.preventDefault();
+ }}
+ >
+ <header className="bg-modal sticky top-0 z-30 flex shrink-0 flex-col gap-1 rounded-t-lg p-4">
+ <div className="flex w-full items-center justify-between gap-4 text-center sm:text-left">
+ <DialogPrimitive.Title className="min-w-0 flex-1 text-lg leading-none font-bold tracking-tight">
+ {title}
+ </DialogPrimitive.Title>
+ <DialogPrimitive.Close
+ className="ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground hover:bg-accent z-20 -mt-2 -mr-2 inline-flex size-8 shrink-0 items-center justify-center rounded-md opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none"
+ tabIndex={-1}
+ >
+ <X className="size-4" />
+ <span className="sr-only">Close</span>
+ </DialogPrimitive.Close>
+ </div>
+ </header>
+ {text !== undefined ? <DialogBody>{text}</DialogBody> : children}
+ {actions?.length ? (
+ <DialogFooter>
+ <DialogPrimitive.Close asChild>
+ <Button ref={cancelButtonRef} variant="outline">
+ Cancel
+ </Button>
+ </DialogPrimitive.Close>
+ {actions.map(({ icon: Icon, label, ...buttonProps }, index) => (
+ <Button
+ key={label}
+ ref={(button) => {
+ actionButtonRefs.current[index] = button;
+ }}
+ {...buttonProps}
+ >
+ <span className="flex items-center gap-1.5">
+ {label}
+ {Icon ? (
+ <Icon className="size-3.5 shrink-0" aria-hidden="true" />
+ ) : null}
+ </span>
+ </Button>
+ ))}
+ </DialogFooter>
+ ) : null}
+ </DialogPrimitive.Content>
+ </DialogPrimitive.Portal>
+ );
+}
+
+function DialogBody({ children }: { children: React.ReactNode }) {
+ return (
+ <div className="flex flex-1 flex-col gap-4 overflow-y-auto p-4 text-sm leading-relaxed">
+ {children}
+ </div>
+ );
+}
+
+function DialogFooter({ children }: { children: React.ReactNode }) {
+ return (
+ <div className="bg-modal sticky bottom-0 z-10 flex shrink-0 flex-col-reverse rounded-b-lg p-4 sm:flex-row sm:justify-end sm:space-x-2 [&>button]:w-full sm:[&>button]:w-auto">
+ {children}
+ </div>
+ );
+}
+
+const Dialog = Object.assign(DialogRoot, { Body: DialogBody });
+
+export { Dialog };
diff --git a/web/src/components/design-system/DialogController/DialogController.stories.tsx b/web/src/components/design-system/DialogController/DialogController.stories.tsx
new file mode 100644
index 0000000000..ae959699be
--- /dev/null
+++ b/web/src/components/design-system/DialogController/DialogController.stories.tsx
@@ -0,0 +1,123 @@
+import { expect, fn, userEvent, waitFor, within } from "storybook/test";
+
+import preview from "../../../../.storybook/preview";
+import { Dialog } from "@/src/components/design-system/Dialog/Dialog";
+
+import { DialogController } from "./DialogController";
+
+const meta = preview.meta({
+ component: DialogController,
+ parameters: {
+ layout: "fullscreen",
+ },
+});
+
+export const StateValues = meta.story({
+ name: "(Test) State values",
+ render: () => (
+ <DialogController<string | null | undefined>
+ renderDialog={({ state, closeDialog }) => (
+ <Dialog title="Stateful dialog">
+ <Dialog.Body>
+ <output data-testid="dialog-state">{String(state)}</output>
+ <button type="button" onClick={closeDialog}>
+ Close from content
+ </button>
+ </Dialog.Body>
+ </Dialog>
+ )}
+ >
+ {({ isOpen, openDialog }) => (
+ <>
+ <output data-testid="open-state">{isOpen ? "open" : "closed"}</output>
+ <button type="button" onClick={() => openDialog(null)}>
+ Open with null
+ </button>
+ <button type="button" onClick={() => openDialog(undefined)}>
+ Open with undefined
+ </button>
+ </>
+ )}
+ </DialogController>
+ ),
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const body = within(canvasElement.ownerDocument.body);
+
+ await userEvent.click(
+ canvas.getByRole("button", { name: "Open with null" }),
+ );
+ await waitFor(() => {
+ expect(body.getByTestId("dialog-state")).toHaveTextContent("null");
+ expect(canvas.getByTestId("open-state")).toHaveTextContent("open");
+ });
+
+ await userEvent.click(
+ body.getByRole("button", { name: "Close from content" }),
+ );
+ await waitFor(() => {
+ expect(canvas.getByTestId("open-state")).toHaveTextContent("closed");
+ expect(body.queryByText("Stateful dialog")).not.toBeInTheDocument();
+ });
+
+ await userEvent.click(
+ canvas.getByRole("button", { name: "Open with undefined" }),
+ );
+ await waitFor(() =>
+ expect(body.getByTestId("dialog-state")).toHaveTextContent("undefined"),
+ );
+ },
+});
+
+const onBeforeClose = fn(() => false);
+const onDismiss = fn();
+
+export const CloseVeto = meta.story({
+ name: "(Test) Close veto",
+ render: () => (
+ <DialogController
+ onBeforeClose={onBeforeClose}
+ onDismiss={onDismiss}
+ renderDialog={() => <Dialog title="Vetoed dialog" text="Content" />}
+ >
+ {({ openDialog }) => (
+ <button type="button" onClick={() => openDialog()}>
+ Open
+ </button>
+ )}
+ </DialogController>
+ ),
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const body = within(canvasElement.ownerDocument.body);
+
+ onBeforeClose.mockClear();
+ onDismiss.mockClear();
+ await userEvent.click(canvas.getByRole("button", { name: "Open" }));
+ await waitFor(() => expect(body.getByText("Vetoed dialog")).toBeVisible());
+ await userEvent.keyboard("{Escape}");
+
+ await waitFor(() => {
+ expect(onBeforeClose).toHaveBeenCalledOnce();
+ expect(onDismiss).not.toHaveBeenCalled();
+ expect(body.getByText("Vetoed dialog")).toBeVisible();
+ });
+ },
+});
+
+export const InitialState = meta.story({
+ name: "(Test) Initial state",
+ render: () => (
+ <DialogController<string>
+ initialState={() => "Initial state"}
+ renderDialog={({ state }) => <Dialog title={state} text="Content" />}
+ >
+ {() => null}
+ </DialogController>
+ ),
+ play: async ({ canvasElement }) => {
+ const body = within(canvasElement.ownerDocument.body);
+
+ await waitFor(() => expect(body.getByText("Initial state")).toBeVisible());
+ },
+});
diff --git a/web/src/components/design-system/DialogController/DialogController.tsx b/web/src/components/design-system/DialogController/DialogController.tsx
new file mode 100644
index 0000000000..ef7a320176
--- /dev/null
+++ b/web/src/components/design-system/DialogController/DialogController.tsx
@@ -0,0 +1,73 @@
+"use client";
+
+import * as DialogPrimitive from "@radix-ui/react-dialog";
+import * as React from "react";
+
+type DialogControllerProps<State = void> = {
+ initialState?: () => State | undefined;
+ children: (control: {
+ isOpen: boolean;
+ openDialog: (...args: [State] extends [void] ? [] : [state: State]) => void;
+ }) => React.ReactNode;
+ onBeforeClose?: () => boolean;
+ onDismiss?: () => void;
+ renderDialog: (control: {
+ state: State;
+ closeDialog: () => void;
+ }) => React.ReactNode;
+};
+
+function DialogController<State = void>({
+ initialState,
+ children,
+ onBeforeClose,
+ onDismiss,
+ renderDialog,
+}: DialogControllerProps<State>) {
+ const [controllerState, setControllerState] = React.useState<
+ | { status: "uninitialized" }
+ | { status: "initialized"; isOpen: boolean; state: State }
+ >(() => {
+ const state = initialState?.();
+ return state === undefined
+ ? { status: "uninitialized" }
+ : { status: "initialized", isOpen: true, state };
+ });
+
+ const closeDialog = () => {
+ if (onBeforeClose?.() === false) return false;
+
+ setControllerState((currentState) =>
+ currentState.status === "initialized"
+ ? { ...currentState, isOpen: false }
+ : currentState,
+ );
+ return true;
+ };
+
+ return (
+ <DialogPrimitive.Root
+ open={controllerState.status === "initialized" && controllerState.isOpen}
+ onOpenChange={(open) => {
+ if (open) return;
+ if (closeDialog()) onDismiss?.();
+ }}
+ >
+ {children({
+ isOpen:
+ controllerState.status === "initialized" && controllerState.isOpen,
+ openDialog: (...args) =>
+ setControllerState({
+ status: "initialized",
+ isOpen: true,
+ state: args[0] as State,
+ }),
+ })}
+ {controllerState.status === "initialized"
+ ? renderDialog({ state: controllerState.state, closeDialog })
+ : null}
+ </DialogPrimitive.Root>
+ );
+}
+
+export { DialogController };
diff --git a/web/src/components/ui/dialog.tsx b/web/src/components/ui/dialog.tsx
index bb8448b856..9b93521e0f 100644
--- a/web/src/components/ui/dialog.tsx
+++ b/web/src/components/ui/dialog.tsx
@@ -8,6 +8,7 @@ import { cva, type VariantProps } from "class-variance-authority";
import { cn } from "@/src/utils/tailwind";
import { useLayerContainer } from "@/src/context/LayerContext/LayerContext";
+import { DialogController as DesignSystemDialogController } from "@/src/components/design-system/DialogController/DialogController";
import motionStyles from "./dialog-motion.module.css";
const Dialog = DialogPrimitive.Root;
@@ -199,47 +200,23 @@ const DialogController = <State = void,>({
onDismiss,
renderContent,
size,
-}: DialogControllerProps<State>) => {
- const [controllerState, setControllerState] = React.useState<
- { active: false } | { active: boolean; state: State }
- >(() => {
- const state = initialState?.();
- return state === undefined ? { active: false } : { active: true, state };
- });
- const closeDialog = () => {
- if (onBeforeClose?.() === false) return false;
- setControllerState((currentState) =>
- "state" in currentState
- ? { ...currentState, active: false }
- : currentState,
- );
- return true;
- };
-
- return (
- <Dialog
- open={controllerState.active}
- onOpenChange={(open) => {
- if (open) return;
- if (closeDialog()) onDismiss?.();
- }}
- >
- {children({
- isOpen: controllerState.active,
- openDialog: (...args) =>
- setControllerState({ active: true, state: args[0] as State }),
- })}
- {"state" in controllerState ? (
- <DialogContent
- size={size}
- closeOnInteractionOutside={closeOnInteractionOutside}
- >
- {renderContent({ state: controllerState.state, closeDialog })}
- </DialogContent>
- ) : null}
- </Dialog>
- );
-};
+}: DialogControllerProps<State>) => (
+ <DesignSystemDialogController
+ initialState={initialState}
+ onBeforeClose={onBeforeClose}
+ onDismiss={onDismiss}
+ renderDialog={({ state, closeDialog }) => (
+ <DialogContent
+ size={size}
+ closeOnInteractionOutside={closeOnInteractionOutside}
+ >
+ {renderContent({ state, closeDialog })}
+ </DialogContent>
+ )}
+ >
+ {children}
+ </DesignSystemDialogController>
+);
const dialogHeaderVariants = cva(
"bg-modal sticky top-0 z-30 flex shrink-0 flex-col space-y-1.5 rounded-t-lg p-4",
diff --git a/web/src/features/automations/components/DeleteAutomationDialog.stories.tsx b/web/src/features/automations/components/DeleteAutomationDialog.stories.tsx
index 649a6f0617..00fc315d31 100644
--- a/web/src/features/automations/components/DeleteAutomationDialog.stories.tsx
+++ b/web/src/features/automations/components/DeleteAutomationDialog.stories.tsx
@@ -1,18 +1,27 @@
import { expect, fn, userEvent, within } from "storybook/test";
import preview from "../../../../.storybook/preview";
+import { DialogController } from "@/src/components/design-system/DialogController/DialogController";
import { DeleteAutomationDialog } from "./DeleteAutomationDialog";
const meta = preview.meta({
component: DeleteAutomationDialog,
+ decorators: [
+ (Story) => (
+ <DialogController
+ initialState={() => true}
+ renderDialog={() => <Story />}
+ >
+ {() => null}
+ </DialogController>
+ ),
+ ],
});
export default meta;
export const Default = meta.story({
args: {
- open: true,
- onOpenChange: fn(),
isPending: false,
onConfirm: fn(),
},
@@ -20,8 +29,6 @@ export const Default = meta.story({
export const Loading = meta.story({
args: {
- open: true,
- onOpenChange: fn(),
isPending: true,
onConfirm: fn(),
},
@@ -30,17 +37,16 @@ export const Loading = meta.story({
export const ConfirmsDeletion = meta.story({
name: "(Test) Confirms deletion",
args: {
- open: true,
- onOpenChange: fn(),
isPending: false,
onConfirm: fn(),
},
play: async ({ args, canvasElement }) => {
const body = within(canvasElement.ownerDocument.body);
+ const deleteButton = body.getByRole("button", {
+ name: "Delete Automation",
+ });
- await userEvent.click(
- body.getByRole("button", { name: "Delete Automation" }),
- );
+ await userEvent.click(deleteButton);
await expect(args.onConfirm).toHaveBeenCalledOnce();
},
diff --git a/web/src/features/automations/components/DeleteAutomationDialog.tsx b/web/src/features/automations/components/DeleteAutomationDialog.tsx
index a4169136aa..0b5f5be13e 100644
--- a/web/src/features/automations/components/DeleteAutomationDialog.tsx
+++ b/web/src/features/automations/components/DeleteAutomationDialog.tsx
@@ -1,27 +1,27 @@
-import { ConfirmDialog } from "@/src/components/ui/confirm-dialog";
+import { Dialog } from "@/src/components/design-system/Dialog/Dialog";
export interface DeleteAutomationDialogProps {
- open: boolean;
- onOpenChange: (open: boolean) => void;
isPending: boolean;
onConfirm: () => void;
}
export function DeleteAutomationDialog({
- open,
- onOpenChange,
isPending,
onConfirm,
}: DeleteAutomationDialogProps) {
return (
- <ConfirmDialog
- open={open}
- onOpenChange={onOpenChange}
+ <Dialog
+ size="sm"
title="Please confirm"
- description="This action permanently deletes this automation and execution history. This cannot be undone."
- confirmLabel="Delete Automation"
- loading={isPending}
- onConfirm={onConfirm}
+ text="This action permanently deletes this automation and execution history. This cannot be undone."
+ actions={[
+ {
+ label: "Delete Automation",
+ variant: "destructive",
+ loading: isPending,
+ onClick: onConfirm,
+ },
+ ]}
/>
);
}
diff --git a/web/src/features/automations/components/DeleteAutomationDialogController.tsx b/web/src/features/automations/components/DeleteAutomationDialogController.tsx
index b4a38cbb26..e9e7fbf963 100644
--- a/web/src/features/automations/components/DeleteAutomationDialogController.tsx
+++ b/web/src/features/automations/components/DeleteAutomationDialogController.tsx
@@ -1,7 +1,7 @@
import { showSuccessToast } from "@/src/features/notifications";
import type * as React from "react";
-import { useState } from "react";
+import { DialogController } from "@/src/components/design-system/DialogController/DialogController";
import { api } from "@/src/utils/api";
import { useHasProjectAccess } from "@/src/features/rbac";
import { DeleteAutomationDialog } from "./DeleteAutomationDialog";
@@ -22,7 +22,6 @@ export const DeleteAutomationDialogController = ({
onSuccess,
children,
}: DeleteAutomationDialogControllerProps) => {
- const [open, setOpen] = useState(false);
const utils = api.useUtils();
const hasAccess = useHasProjectAccess({
projectId,
@@ -48,33 +47,36 @@ export const DeleteAutomationDialogController = ({
? undefined
: { reason: "You don't have permission to delete this automation." };
- const openDialog = () => {
- if (!hasAccess) return;
-
- setOpen(true);
- };
-
- const handleDelete = async () => {
+ const handleDelete = async (closeDialog: () => void) => {
try {
await deleteAutomationMutation.mutateAsync({
projectId,
automationId,
});
- setOpen(false);
+ closeDialog();
} catch {
// The tRPC error handler owns mutation failures; keep the dialog open.
}
};
return (
- <>
- {children({ disabled, openDialog })}
- <DeleteAutomationDialog
- open={hasAccess && open}
- onOpenChange={setOpen}
- isPending={deleteAutomationMutation.isPending}
- onConfirm={handleDelete}
- />
- </>
+ <DialogController
+ renderDialog={({ closeDialog }) => (
+ <DeleteAutomationDialog
+ isPending={deleteAutomationMutation.isPending}
+ onConfirm={() => handleDelete(closeDialog)}
+ />
+ )}
+ >
+ {({ openDialog }) =>
+ children({
+ disabled,
+ openDialog: () => {
+ if (!hasAccess) return;
+ openDialog();
+ },
+ })
+ }
+ </DialogController>
);
};
diff --git a/web/src/features/projects/components/DeleteProjectDialog.stories.tsx b/web/src/features/projects/components/DeleteProjectDialog.stories.tsx
index adf585cb87..0df21d664a 100644
--- a/web/src/features/projects/components/DeleteProjectDialog.stories.tsx
+++ b/web/src/features/projects/components/DeleteProjectDialog.stories.tsx
@@ -1,7 +1,7 @@
import { expect, fn, userEvent, within } from "storybook/test";
import preview from "@/.storybook/preview";
-import { Dialog, DialogContent } from "@/src/components/ui/dialog";
+import { DialogController } from "@/src/components/design-system/DialogController/DialogController";
import {
DeleteProjectDialog,
type DeleteProjectDialogProps,
@@ -14,11 +14,12 @@ const meta = preview.meta({
export default meta;
const renderDialog = (args: DeleteProjectDialogProps) => (
- <Dialog open onOpenChange={fn()}>
- <DialogContent className="sm:max-w-[425px]">
- <DeleteProjectDialog {...args} />
- </DialogContent>
- </Dialog>
+ <DialogController
+ initialState={() => true}
+ renderDialog={() => <DeleteProjectDialog {...args} />}
+ >
+ {() => null}
+ </DialogController>
);
export const Default = meta.story({
@@ -30,24 +31,6 @@ export const Default = meta.story({
render: renderDialog,
});
-export const Loading = meta.story({
- args: {
- confirmMessage: "acme/my-project",
- isPending: true,
- onSubmit: fn(),
- },
- render: renderDialog,
-});
-
-export const GatewayIngestionProject = meta.story({
- name: "Gateway ingestion project",
- args: {
- blocked: true,
- onOpenGatewaySettings: fn(),
- },
- render: renderDialog,
-});
-
export const ConfirmsDeletion = meta.story({
name: "(Test) Confirms deletion",
args: {
@@ -65,7 +48,6 @@ export const ConfirmsDeletion = meta.story({
);
await userEvent.click(body.getByRole("button", { name: "Delete project" }));
- if (!("onSubmit" in args)) throw new Error("Expected deletion dialog");
await expect(args.onSubmit).toHaveBeenCalledOnce();
},
});
diff --git a/web/src/features/projects/components/DeleteProjectDialog.tsx b/web/src/features/projects/components/DeleteProjectDialog.tsx
index df21068120..345ff723bd 100644
--- a/web/src/features/projects/components/DeleteProjectDialog.tsx
+++ b/web/src/features/projects/components/DeleteProjectDialog.tsx
@@ -1,16 +1,9 @@
import { zodResolver } from "@hookform/resolvers/zod";
-import { ExternalLink } from "lucide-react";
+import { useId } from "react";
import { useForm } from "react-hook-form";
import * as z from "zod";
-import { Button } from "@/src/components/ui/button";
-import {
- DialogBody,
- DialogDescription,
- DialogFooter,
- DialogHeader,
- DialogTitle,
-} from "@/src/components/ui/dialog";
+import { Dialog } from "@/src/components/design-system/Dialog/Dialog";
import {
Form,
FormControl,
@@ -24,59 +17,14 @@ type DeleteProjectForm = {
name: string;
};
-export type DeleteProjectDialogProps =
- | {
- blocked: true;
- onOpenGatewaySettings: () => void;
- }
- | {
- blocked?: false;
- confirmMessage: string;
- isPending: boolean;
- onSubmit: () => void;
- };
-
-export function DeleteProjectDialog(props: DeleteProjectDialogProps) {
- return props.blocked ? (
- <BlockedDeleteProjectDialog
- onOpenGatewaySettings={props.onOpenGatewaySettings}
- />
- ) : (
- <DeleteProjectConfirmationDialog {...props} />
- );
-}
-
-function BlockedDeleteProjectDialog({
- onOpenGatewaySettings,
-}: {
- onOpenGatewaySettings: () => void;
-}) {
- return (
- <>
- <DialogHeader>
- <DialogTitle className="text-lg font-bold">
- Project cannot be deleted
- </DialogTitle>
- <DialogDescription>
- This project is used as the AI Gateway ingestion project. Select
- another ingestion project before deleting it.
- </DialogDescription>
- </DialogHeader>
- <DialogFooter>
- <Button className="w-full" onClick={onOpenGatewaySettings}>
- Open AI Gateway settings
- <ExternalLink className="relative -top-px ml-1.5 size-3.5 shrink-0" />
- </Button>
- </DialogFooter>
- </>
- );
-}
-
-function DeleteProjectConfirmationDialog(props: {
+export type DeleteProjectDialogProps = {
confirmMessage: string;
isPending: boolean;
onSubmit: () => void;
-}) {
+};
+
+export function DeleteProjectDialog(props: DeleteProjectDialogProps) {
+ const formId = useId();
const formSchema = z.object({
name: z.string().includes(props.confirmMessage, {
message: `Please confirm with "${props.confirmMessage}"`,
@@ -91,16 +39,22 @@ function DeleteProjectConfirmationDialog(props: {
});
return (
- <>
- <DialogHeader>
- <DialogTitle className="text-lg font-bold">Delete Project</DialogTitle>
- <DialogDescription>
- {`To confirm, type "${props.confirmMessage}" in the input box`}
- </DialogDescription>
- </DialogHeader>
+ <Dialog
+ title="Delete Project"
+ actions={[
+ {
+ label: "Delete project",
+ type: "submit",
+ form: formId,
+ variant: "destructive",
+ loading: props.isPending,
+ },
+ ]}
+ >
<Form {...form}>
- <form onSubmit={form.handleSubmit(props.onSubmit)}>
- <DialogBody>
+ <form id={formId} onSubmit={form.handleSubmit(props.onSubmit)}>
+ <Dialog.Body>
+ <p>{`To confirm, type "${props.confirmMessage}" in the input box`}</p>
<FormField
control={form.control}
name="name"
@@ -113,19 +67,9 @@ function DeleteProjectConfirmationDialog(props: {
</FormItem>
)}
/>
- </DialogBody>
- <DialogFooter>
- <Button
- type="submit"
- variant="destructive"
- loading={props.isPending}
- className="w-full"
- >
- Delete project
- </Button>
- </DialogFooter>
+ </Dialog.Body>
</form>
</Form>
- </>
+ </Dialog>
);
}
diff --git a/web/src/features/projects/components/DeleteProjectDialogController.tsx b/web/src/features/projects/components/DeleteProjectDialogController.tsx
index 9f0f6ab640..6a0be8a533 100644
--- a/web/src/features/projects/components/DeleteProjectDialogController.tsx
+++ b/web/src/features/projects/components/DeleteProjectDialogController.tsx
@@ -1,7 +1,9 @@
+import { ExternalLink } from "lucide-react";
import { type ReactNode } from "react";
import { useRouter } from "next/router";
-import { DialogController } from "@/src/components/ui/dialog";
+import { Dialog } from "@/src/components/design-system/Dialog/Dialog";
+import { DialogController } from "@/src/components/design-system/DialogController/DialogController";
import { env } from "@/src/env.mjs";
import { usePostHogClientCapture } from "@/src/features/posthog-analytics";
import { useQueryProject } from "@/src/features/projects/hooks";
@@ -51,26 +53,37 @@ export function DeleteProjectDialogController({
return (
<DialogController
- closeOnInteractionOutside={false}
- size="default"
- renderContent={() =>
- deletionProtection.data?.isGatewayIngestionProject && organization ? (
- <DeleteProjectDialog
- blocked
- onOpenGatewaySettings={() =>
- router.push(
- `/organization/${organization.id}/settings/ai-gateway`,
- )
- }
- />
- ) : (
+ renderDialog={() => {
+ if (
+ deletionProtection.data?.isGatewayIngestionProject &&
+ organization
+ ) {
+ return (
+ <Dialog
+ title="Project cannot be deleted"
+ text="This project is used as the AI Gateway ingestion project. Select another ingestion project before deleting it."
+ actions={[
+ {
+ label: "Open AI Gateway settings",
+ icon: ExternalLink,
+ onClick: () =>
+ router.push(
+ `/organization/${organization.id}/settings/ai-gateway`,
+ ),
+ },
+ ]}
+ />
+ );
+ }
+
+ return (
<DeleteProjectDialog
confirmMessage={confirmMessage}
isPending={deleteProject.isPending}
onSubmit={handleDelete}
/>
- )
- }
+ );
+ }}
>
{({ openDialog }) =>
children({
diff --git a/web/src/features/projects/components/TransferProjectDialogContent.stories.tsx b/web/src/features/projects/components/TransferProjectDialog.stories.tsx
similarity index 75%
rename from web/src/features/projects/components/TransferProjectDialogContent.stories.tsx
rename to web/src/features/projects/components/TransferProjectDialog.stories.tsx
index 0db603b75a..ad01282ee0 100644
--- a/web/src/features/projects/components/TransferProjectDialogContent.stories.tsx
+++ b/web/src/features/projects/components/TransferProjectDialog.stories.tsx
@@ -2,9 +2,9 @@ import { type ComponentProps } from "react";
import { expect, fn, userEvent, within } from "storybook/test";
import preview from "../../../../.storybook/preview";
-import { Dialog } from "@/src/components/ui/dialog";
+import { DialogController } from "@/src/components/design-system/DialogController/DialogController";
-import { TransferProjectDialogContent } from "./TransferProjectDialogContent";
+import { TransferProjectDialog } from "./TransferProjectDialog";
const defaultArgs = {
projectName: "Support assistant",
@@ -12,18 +12,21 @@ const defaultArgs = {
organizations: [{ id: "organization-2", name: "Example" }],
isPending: false,
onConfirm: fn(),
-} satisfies ComponentProps<typeof TransferProjectDialogContent>;
+} satisfies ComponentProps<typeof TransferProjectDialog>;
const meta = preview.meta({
- component: TransferProjectDialogContent,
+ component: TransferProjectDialog,
parameters: {
layout: "fullscreen",
},
decorators: [
(Story) => (
- <Dialog open onOpenChange={fn()}>
- <Story />
- </Dialog>
+ <DialogController
+ initialState={() => true}
+ renderDialog={() => <Story />}
+ >
+ {() => null}
+ </DialogController>
),
],
});
diff --git a/web/src/features/projects/components/TransferProjectDialogContent.tsx b/web/src/features/projects/components/TransferProjectDialog.tsx
similarity index 82%
rename from web/src/features/projects/components/TransferProjectDialogContent.tsx
rename to web/src/features/projects/components/TransferProjectDialog.tsx
index 71aad53122..04df75a7f2 100644
--- a/web/src/features/projects/components/TransferProjectDialogContent.tsx
+++ b/web/src/features/projects/components/TransferProjectDialog.tsx
@@ -1,14 +1,7 @@
import { zodResolver } from "@hookform/resolvers/zod";
import { Alert } from "@/src/components/design-system/Alert/Alert";
+import { Dialog } from "@/src/components/design-system/Dialog/Dialog";
import { SelectInput } from "@/src/components/design-system/SelectInput/SelectInput";
-import { Button } from "@/src/components/ui/button";
-import {
- DialogBody,
- DialogContent,
- DialogFooter,
- DialogHeader,
- DialogTitle,
-} from "@/src/components/ui/dialog";
import {
Form,
FormControl,
@@ -20,6 +13,7 @@ import {
} from "@/src/components/ui/form";
import { Input } from "@/src/components/ui/input";
import { TriangleAlert } from "lucide-react";
+import { useId } from "react";
import { useForm } from "react-hook-form";
import * as z from "zod";
@@ -28,7 +22,7 @@ type TransferProjectDialogOrganization = {
name: string;
};
-export interface TransferProjectDialogContentProps {
+export interface TransferProjectDialogProps {
projectName: string;
organizationName: string;
organizations: TransferProjectDialogOrganization[];
@@ -36,13 +30,14 @@ export interface TransferProjectDialogContentProps {
onConfirm: (organizationId: string) => void;
}
-export function TransferProjectDialogContent({
+export function TransferProjectDialog({
projectName,
organizationName,
organizations,
isPending,
onConfirm,
-}: TransferProjectDialogContentProps) {
+}: TransferProjectDialogProps) {
+ const formId = useId();
const confirmMessage = `${organizationName}/${projectName}`
.replaceAll(" ", "-")
.toLowerCase();
@@ -61,18 +56,26 @@ export function TransferProjectDialogContent({
});
return (
- <DialogContent className="sm:max-w-[425px]">
- <DialogHeader>
- <DialogTitle>Transfer Project</DialogTitle>
- </DialogHeader>
+ <Dialog
+ title="Transfer Project"
+ actions={[
+ {
+ label: "Transfer project",
+ type: "submit",
+ form: formId,
+ variant: "destructive",
+ loading: isPending,
+ },
+ ]}
+ >
<Form {...form}>
<form
+ id={formId}
onSubmit={form.handleSubmit(({ organizationId }) =>
onConfirm(organizationId),
)}
- className="flex flex-col gap-8"
>
- <DialogBody>
+ <Dialog.Body>
<Alert variant="warning" icon={TriangleAlert}>
<Alert.Title>Warning</Alert.Title>
<Alert.Description>
@@ -134,19 +137,9 @@ export function TransferProjectDialogContent({
</FormItem>
)}
/>
- </DialogBody>
- <DialogFooter>
- <Button
- type="submit"
- variant="destructive"
- loading={isPending}
- className="w-full"
- >
- Transfer project
- </Button>
- </DialogFooter>
+ </Dialog.Body>
</form>
</Form>
- </DialogContent>
+ </Dialog>
);
}
diff --git a/web/src/features/projects/components/TransferProjectDialogController.tsx b/web/src/features/projects/components/TransferProjectDialogController.tsx
index ddd519923e..3a2b11dfb1 100644
--- a/web/src/features/projects/components/TransferProjectDialogController.tsx
+++ b/web/src/features/projects/components/TransferProjectDialogController.tsx
@@ -1,8 +1,8 @@
import { showSuccessToast } from "@/src/features/notifications";
-import { type ReactNode, useState } from "react";
+import { type ReactNode } from "react";
-import { Dialog } from "@/src/components/ui/dialog";
-import { TransferProjectDialogContent } from "@/src/features/projects/components/TransferProjectDialogContent";
+import { DialogController } from "@/src/components/design-system/DialogController/DialogController";
+import { TransferProjectDialog } from "@/src/features/projects/components/TransferProjectDialog";
import { usePostHogClientCapture } from "@/src/features/posthog-analytics";
import {
hasOrganizationAccess,
@@ -31,7 +31,6 @@ export function TransferProjectDialogController({
organization,
children,
}: TransferProjectDialogControllerProps) {
- const [open, setOpen] = useState(false);
const capture = usePostHogClientCapture();
const session = useSession();
const hasAccess = useHasOrganizationAccess({
@@ -67,12 +66,6 @@ export function TransferProjectDialogController({
? undefined
: { reason: "You don't have permission to transfer this project." };
- const openDialog = () => {
- if (!hasAccess) return;
-
- setOpen(true);
- };
-
const onConfirm = (organizationId: string) => {
capture("project_settings:project_delete");
transferProject.mutate({
@@ -82,17 +75,26 @@ export function TransferProjectDialogController({
};
return (
- <>
- {children({ disabled, openDialog })}
- <Dialog open={hasAccess && open} onOpenChange={setOpen}>
- <TransferProjectDialogContent
+ <DialogController
+ renderDialog={() => (
+ <TransferProjectDialog
projectName={project.name}
organizationName={organization.name}
organizations={organizationsToTransferTo}
isPending={transferProject.isPending}
onConfirm={onConfirm}
/>
- </Dialog>
- </>
+ )}
+ >
+ {({ openDialog }) =>
+ children({
+ disabled,
+ openDialog: () => {
+ if (!hasAccess) return;
+ openDialog();
+ },
+ })
+ }
+ </DialogController>
);
}
diff --git a/web/src/features/rbac/components/CreateProjectMemberDialogContent.stories.tsx b/web/src/features/rbac/components/CreateProjectMemberDialog.stories.tsx
similarity index 70%
rename from web/src/features/rbac/components/CreateProjectMemberDialogContent.stories.tsx
rename to web/src/features/rbac/components/CreateProjectMemberDialog.stories.tsx
index 585cc28726..b853093068 100644
--- a/web/src/features/rbac/components/CreateProjectMemberDialogContent.stories.tsx
+++ b/web/src/features/rbac/components/CreateProjectMemberDialog.stories.tsx
@@ -2,39 +2,32 @@ import { type ComponentProps } from "react";
import { expect, fn, userEvent, within } from "storybook/test";
import preview from "../../../../.storybook/preview";
-import {
- Dialog,
- DialogContent,
- DialogHeader,
- DialogTitle,
-} from "@/src/components/ui/dialog";
+import { DialogController } from "@/src/components/design-system/DialogController/DialogController";
-import { CreateProjectMemberDialogContent } from "./CreateProjectMemberDialogContent";
+import { CreateProjectMemberDialog } from "./CreateProjectMemberDialog";
const defaultArgs = {
project: undefined,
hasOnlySingleProjectAccess: false,
hasProjectRoleEntitlement: false,
- isSubmitting: false,
+ isPending: false,
createProjectMember: fn().mockResolvedValue(undefined),
onSuccess: fn(),
-} satisfies ComponentProps<typeof CreateProjectMemberDialogContent>;
+} satisfies ComponentProps<typeof CreateProjectMemberDialog>;
const meta = preview.meta({
- component: CreateProjectMemberDialogContent,
+ component: CreateProjectMemberDialog,
parameters: {
layout: "fullscreen",
},
decorators: [
(Story) => (
- <Dialog open onOpenChange={fn()}>
- <DialogContent>
- <DialogHeader>
- <DialogTitle>Add member</DialogTitle>
- </DialogHeader>
- <Story />
- </DialogContent>
- </Dialog>
+ <DialogController
+ initialState={() => true}
+ renderDialog={() => <Story />}
+ >
+ {() => null}
+ </DialogController>
),
],
});
@@ -60,13 +53,6 @@ export const SingleProjectAccess = meta.story({
},
});
-export const Submitting = meta.story({
- args: {
- ...defaultArgs,
- isSubmitting: true,
- },
-});
-
export const SubmitsInvitation = meta.story({
name: "(Test) Submits invitation",
args: defaultArgs,
diff --git a/web/src/features/rbac/components/CreateProjectMemberDialog.tsx b/web/src/features/rbac/components/CreateProjectMemberDialog.tsx
new file mode 100644
index 0000000000..a936fee5b8
--- /dev/null
+++ b/web/src/features/rbac/components/CreateProjectMemberDialog.tsx
@@ -0,0 +1,204 @@
+import { zodResolver } from "@hookform/resolvers/zod";
+import { type Role } from "@langfuse/shared";
+import { useId } from "react";
+import { useForm } from "react-hook-form";
+import * as z from "zod";
+
+import { Dialog } from "@/src/components/design-system/Dialog/Dialog";
+import {
+ Form,
+ FormControl,
+ FormDescription,
+ FormField,
+ FormItem,
+ FormLabel,
+ FormMessage,
+} from "@/src/components/ui/form";
+import { Input } from "@/src/components/ui/input";
+import {
+ Select,
+ SelectContent,
+ SelectTrigger,
+ SelectValue,
+} from "@/src/components/ui/select";
+import { RoleSelectItem } from "@/src/features/rbac/components/RoleSelectItem";
+import { reportTrpcErrorWithoutToast } from "@/src/utils/api";
+
+const roleValues = {
+ OWNER: "OWNER",
+ ADMIN: "ADMIN",
+ MEMBER: "MEMBER",
+ VIEWER: "VIEWER",
+ NONE: "NONE",
+} as const satisfies Record<Role, Role>;
+
+const formSchema = z.object({
+ email: z.string().trim().pipe(z.email()),
+ orgRole: z.enum(roleValues),
+ projectRole: z.enum(roleValues),
+});
+
+type FormValues = z.infer<typeof formSchema>;
+
+type CreateProjectMemberDialogProps = {
+ project: { id: string; name: string } | undefined;
+ hasOnlySingleProjectAccess: boolean;
+ hasProjectRoleEntitlement: boolean;
+ isPending: boolean;
+ createProjectMember: (values: FormValues) => Promise<void>;
+ onSuccess: () => void;
+};
+
+export function CreateProjectMemberDialog({
+ project,
+ hasOnlySingleProjectAccess,
+ hasProjectRoleEntitlement,
+ isPending,
+ createProjectMember,
+ onSuccess,
+}: CreateProjectMemberDialogProps) {
+ const formId = useId();
+ const form = useForm<FormValues>({
+ resolver: zodResolver(formSchema),
+ defaultValues: {
+ email: "",
+ orgRole: hasOnlySingleProjectAccess ? roleValues.NONE : roleValues.MEMBER,
+ projectRole: hasOnlySingleProjectAccess
+ ? roleValues.MEMBER
+ : roleValues.NONE,
+ },
+ });
+
+ async function onSubmit(values: FormValues) {
+ try {
+ await createProjectMember(values);
+ form.reset();
+ onSuccess();
+ } catch (error) {
+ form.setError("email", {
+ type: "manual",
+ message:
+ error instanceof Error ? error.message : "Failed to add member",
+ });
+ reportTrpcErrorWithoutToast(error, "members");
+ }
+ }
+
+ return (
+ <Dialog
+ actions={[
+ {
+ label: "Grant access",
+ type: "submit",
+ form: formId,
+ loading: isPending,
+ },
+ ]}
+ title={`Add new member to the ${
+ hasOnlySingleProjectAccess ? "project" : "organization"
+ }`}
+ >
+ <Form {...form}>
+ <form
+ id={formId}
+ className="space-y-6"
+ onSubmit={form.handleSubmit(onSubmit)}
+ >
+ <Dialog.Body>
+ <FormField
+ control={form.control}
+ name="email"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Email</FormLabel>
+ <FormControl>
+ <Input placeholder="[email protected]" {...field} />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ {!hasOnlySingleProjectAccess && (
+ <FormField
+ control={form.control}
+ name="orgRole"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Organization Role</FormLabel>
+ <Select
+ defaultValue={field.value}
+ onValueChange={(value) =>
+ field.onChange(
+ value as (typeof roleValues)[keyof typeof roleValues],
+ )
+ }
+ >
+ <FormControl>
+ <SelectTrigger>
+ <SelectValue placeholder="Select an organization role" />
+ </SelectTrigger>
+ </FormControl>
+ <SelectContent>
+ {Object.values(roleValues).map((role) => (
+ <RoleSelectItem role={role} key={role} />
+ ))}
+ </SelectContent>
+ </Select>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ )}
+ {project !== undefined && hasProjectRoleEntitlement && (
+ <FormField
+ control={form.control}
+ name="projectRole"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Project Role</FormLabel>
+ <Select
+ defaultValue={field.value}
+ onValueChange={(value) =>
+ field.onChange(
+ value as (typeof roleValues)[keyof typeof roleValues],
+ )
+ }
+ >
+ <FormControl>
+ <SelectTrigger>
+ <SelectValue placeholder="Select a project role" />
+ </SelectTrigger>
+ </FormControl>
+ <SelectContent>
+ {Object.values(roleValues)
+ .filter(
+ (role) =>
+ !hasOnlySingleProjectAccess ||
+ role !== roleValues.NONE,
+ )
+ .map((role) => (
+ <RoleSelectItem
+ role={role}
+ key={role}
+ isProjectRole
+ />
+ ))}
+ </SelectContent>
+ </Select>
+ {!hasOnlySingleProjectAccess && (
+ <FormDescription>
+ This project role will override the default role for
+ this current project ({project.name}).
+ </FormDescription>
+ )}
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ )}
+ </Dialog.Body>
+ </form>
+ </Form>
+ </Dialog>
+ );
+}
diff --git a/web/src/features/rbac/components/CreateProjectMemberDialogContent.tsx b/web/src/features/rbac/components/CreateProjectMemberDialogContent.tsx
deleted file mode 100644
index a565b9993a..0000000000
--- a/web/src/features/rbac/components/CreateProjectMemberDialogContent.tsx
+++ /dev/null
@@ -1,191 +0,0 @@
-import { zodResolver } from "@hookform/resolvers/zod";
-import { type Role } from "@langfuse/shared";
-import { useForm } from "react-hook-form";
-import * as z from "zod";
-
-import { Button } from "@/src/components/ui/button";
-import { DialogBody, DialogFooter } from "@/src/components/ui/dialog";
-import {
- Form,
- FormControl,
- FormDescription,
- FormField,
- FormItem,
- FormLabel,
- FormMessage,
-} from "@/src/components/ui/form";
-import { Input } from "@/src/components/ui/input";
-import {
- Select,
- SelectContent,
- SelectTrigger,
- SelectValue,
-} from "@/src/components/ui/select";
-import { RoleSelectItem } from "@/src/features/rbac/components/RoleSelectItem";
-import { reportTrpcErrorWithoutToast } from "@/src/utils/api";
-
-const roleValues = {
- OWNER: "OWNER",
- ADMIN: "ADMIN",
- MEMBER: "MEMBER",
- VIEWER: "VIEWER",
- NONE: "NONE",
-} as const satisfies Record<Role, Role>;
-
-const formSchema = z.object({
- email: z.string().trim().pipe(z.email()),
- orgRole: z.enum(roleValues),
- projectRole: z.enum(roleValues),
-});
-
-type FormValues = z.infer<typeof formSchema>;
-
-type CreateProjectMemberDialogContentProps = {
- project: { id: string; name: string } | undefined;
- hasOnlySingleProjectAccess: boolean;
- hasProjectRoleEntitlement: boolean;
- isSubmitting: boolean;
- createProjectMember: (values: FormValues) => Promise<void>;
- onSuccess: () => void;
-};
-
-export function CreateProjectMemberDialogContent({
- project,
- hasOnlySingleProjectAccess,
- hasProjectRoleEntitlement,
- isSubmitting,
- createProjectMember,
- onSuccess,
-}: CreateProjectMemberDialogContentProps) {
- const form = useForm<FormValues>({
- resolver: zodResolver(formSchema),
- defaultValues: {
- email: "",
- orgRole: hasOnlySingleProjectAccess ? roleValues.NONE : roleValues.MEMBER,
- projectRole: hasOnlySingleProjectAccess
- ? roleValues.MEMBER
- : roleValues.NONE,
- },
- });
-
- async function onSubmit(values: FormValues) {
- try {
- await createProjectMember(values);
- form.reset();
- onSuccess();
- } catch (error) {
- form.setError("email", {
- type: "manual",
- message:
- error instanceof Error ? error.message : "Failed to add member",
- });
- reportTrpcErrorWithoutToast(error, "members");
- }
- }
-
- return (
- <Form {...form}>
- <form className="space-y-6" onSubmit={form.handleSubmit(onSubmit)}>
- <DialogBody>
- <FormField
- control={form.control}
- name="email"
- render={({ field }) => (
- <FormItem>
- <FormLabel>Email</FormLabel>
- <FormControl>
- <Input placeholder="[email protected]" {...field} />
- </FormControl>
- <FormMessage />
- </FormItem>
- )}
- />
- {!hasOnlySingleProjectAccess && (
- <FormField
- control={form.control}
- name="orgRole"
- render={({ field }) => (
- <FormItem>
- <FormLabel>Organization Role</FormLabel>
- <Select
- defaultValue={field.value}
- onValueChange={(value) =>
- field.onChange(
- value as (typeof roleValues)[keyof typeof roleValues],
- )
- }
- >
- <FormControl>
- <SelectTrigger>
- <SelectValue placeholder="Select an organization role" />
- </SelectTrigger>
- </FormControl>
- <SelectContent>
- {Object.values(roleValues).map((role) => (
- <RoleSelectItem role={role} key={role} />
- ))}
- </SelectContent>
- </Select>
- <FormMessage />
- </FormItem>
- )}
- />
- )}
- {project !== undefined && hasProjectRoleEntitlement && (
- <FormField
- control={form.control}
- name="projectRole"
- render={({ field }) => (
- <FormItem>
- <FormLabel>Project Role</FormLabel>
- <Select
- defaultValue={field.value}
- onValueChange={(value) =>
- field.onChange(
- value as (typeof roleValues)[keyof typeof roleValues],
- )
- }
- >
- <FormControl>
- <SelectTrigger>
- <SelectValue placeholder="Select a project role" />
- </SelectTrigger>
- </FormControl>
- <SelectContent>
- {Object.values(roleValues)
- .filter(
- (role) =>
- !hasOnlySingleProjectAccess ||
- role !== roleValues.NONE,
- )
- .map((role) => (
- <RoleSelectItem
- role={role}
- key={role}
- isProjectRole
- />
- ))}
- </SelectContent>
- </Select>
- {!hasOnlySingleProjectAccess && (
- <FormDescription>
- This project role will override the default role for this
- current project ({project.name}).
- </FormDescription>
- )}
- <FormMessage />
- </FormItem>
- )}
- />
- )}
- </DialogBody>
- <DialogFooter>
- <Button type="submit" className="w-full" loading={isSubmitting}>
- Grant access
- </Button>
- <FormMessage />
- </DialogFooter>
- </form>
- </Form>
- );
-}
diff --git a/web/src/features/rbac/components/CreateProjectMemberDialogController.tsx b/web/src/features/rbac/components/CreateProjectMemberDialogController.tsx
index aa377f3d58..962d8ce64f 100644
--- a/web/src/features/rbac/components/CreateProjectMemberDialogController.tsx
+++ b/web/src/features/rbac/components/CreateProjectMemberDialogController.tsx
@@ -1,11 +1,7 @@
import { type ReactNode } from "react";
-import {
- DialogController,
- DialogHeader,
- DialogTitle,
-} from "@/src/components/ui/dialog";
-import { CreateProjectMemberDialogContent } from "@/src/features/rbac/components/CreateProjectMemberDialogContent";
+import { DialogController } from "@/src/components/design-system/DialogController/DialogController";
+import { CreateProjectMemberDialog } from "@/src/features/rbac/components/CreateProjectMemberDialog";
import {
useEntitlementLimit,
useHasEntitlement,
@@ -89,48 +85,38 @@ export function CreateProjectMemberDialogController({
return (
<DialogController
- closeOnInteractionOutside={false}
- size="default"
- renderContent={({ closeDialog }) => (
- <>
- <DialogHeader>
- <DialogTitle>
- Add new member to the{" "}
- {hasOnlySingleProjectAccess ? "project" : "organization"}
- </DialogTitle>
- </DialogHeader>
- <CreateProjectMemberDialogContent
- project={project}
- hasOnlySingleProjectAccess={hasOnlySingleProjectAccess}
- hasProjectRoleEntitlement={hasProjectRoleEntitlement}
- isSubmitting={createProjectMemberMutation.isPending}
- createProjectMember={(values) => {
- capture(
- project
- ? "project_settings:send_membership_invitation"
- : "organization_settings:send_membership_invitation",
- {
- orgRole: values.orgRole,
- projectRole: values.projectRole,
- },
- );
+ renderDialog={({ closeDialog }) => (
+ <CreateProjectMemberDialog
+ project={project}
+ hasOnlySingleProjectAccess={hasOnlySingleProjectAccess}
+ hasProjectRoleEntitlement={hasProjectRoleEntitlement}
+ isPending={createProjectMemberMutation.isPending}
+ createProjectMember={(values) => {
+ capture(
+ project
+ ? "project_settings:send_membership_invitation"
+ : "organization_settings:send_membership_invitation",
+ {
+ orgRole: values.orgRole,
+ projectRole: values.projectRole,
+ },
+ );
- return createProjectMemberMutation
- .mutateAsync({
- orgId,
- email: values.email,
- orgRole: values.orgRole,
- projectId: project?.id,
- projectRole:
- values.projectRole === "NONE"
- ? undefined
- : values.projectRole,
- })
- .then(() => undefined);
- }}
- onSuccess={closeDialog}
- />
- </>
+ return createProjectMemberMutation
+ .mutateAsync({
+ orgId,
+ email: values.email,
+ orgRole: values.orgRole,
+ projectId: project?.id,
+ projectRole:
+ values.projectRole === "NONE"
+ ? undefined
+ : values.projectRole,
+ })
+ .then(() => undefined);
+ }}
+ onSuccess={closeDialog}
+ />
)}
>
{({ openDialog }) =>