Skip to content

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

fix(web): move delete organization dialog to design-system Dialog (#19654)

Tobias Wochingerdb598ac1277c
diff --git a/web/src/features/organizations/components/DeleteOrganizationDialog.stories.tsx b/web/src/features/organizations/components/DeleteOrganizationDialog.stories.tsx
index aa007ed4ab..06ddeb968e 100644
--- a/web/src/features/organizations/components/DeleteOrganizationDialog.stories.tsx
+++ b/web/src/features/organizations/components/DeleteOrganizationDialog.stories.tsx
@@ -1,31 +1,31 @@
-/* eslint-disable @typescript-eslint/no-deprecated -- Legacy UI usage retained during migration to design-system components. */
import { expect, fn, userEvent, within } from "storybook/test";
-import { type ComponentProps } from "react";
-import preview from "../../../../.storybook/preview";
-import { Dialog, DialogContent } from "@/src/components/ui/dialog";
+import preview from "@/.storybook/preview";
+import { DialogController } from "@/src/components/design-system/DialogController/DialogController";
-import { DeleteOrganizationDialogContent } from "./DeleteOrganizationDialogContent";
+import {
+ DeleteOrganizationDialog,
+ type DeleteOrganizationDialogProps,
+} from "./DeleteOrganizationDialog";
const defaultArgs = {
confirmMessage: "acme",
hasProjects: false,
isPending: false,
onConfirm: fn(),
-} satisfies ComponentProps<typeof DeleteOrganizationDialogContent>;
+} satisfies DeleteOrganizationDialogProps;
-const renderDialog = (
- args: ComponentProps<typeof DeleteOrganizationDialogContent>,
-) => (
- <Dialog open onOpenChange={fn()}>
- <DialogContent className="sm:max-w-[425px]">
- <DeleteOrganizationDialogContent {...args} />
- </DialogContent>
- </Dialog>
+const renderDialog = (args: DeleteOrganizationDialogProps) => (
+ <DialogController
+ initialState={() => true}
+ renderDialog={() => <DeleteOrganizationDialog {...args} />}
+ >
+ {() => null}
+ </DialogController>
);
const meta = preview.meta({
- component: DeleteOrganizationDialogContent,
+ component: DeleteOrganizationDialog,
});
export default meta;
diff --git a/web/src/features/organizations/components/DeleteOrganizationDialog.tsx b/web/src/features/organizations/components/DeleteOrganizationDialog.tsx
new file mode 100644
index 0000000000..b3e5d5a881
--- /dev/null
+++ b/web/src/features/organizations/components/DeleteOrganizationDialog.tsx
@@ -0,0 +1,92 @@
+import { zodResolver } from "@hookform/resolvers/zod";
+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,
+ FormField,
+ FormItem,
+ FormMessage,
+} from "@/src/components/ui/form";
+import { Input } from "@/src/components/ui/input";
+
+export type DeleteOrganizationDialogProps = {
+ confirmMessage: string;
+ hasProjects: boolean;
+ isPending: boolean;
+ onConfirm: () => void | Promise<void>;
+};
+
+export function DeleteOrganizationDialog({
+ confirmMessage,
+ hasProjects,
+ isPending,
+ onConfirm,
+}: DeleteOrganizationDialogProps) {
+ const formId = useId();
+ const formSchema = z.object({
+ name: z.string().includes(confirmMessage, {
+ message: `Please confirm with "${confirmMessage}"`,
+ }),
+ });
+ const form = useForm({
+ resolver: zodResolver(formSchema),
+ defaultValues: {
+ name: "",
+ },
+ });
+
+ const onSubmit = () => {
+ if (hasProjects) return;
+ return onConfirm();
+ };
+
+ return (
+ <Dialog
+ title="Delete Organization"
+ actions={[
+ {
+ label: "Delete Organization",
+ type: "submit",
+ form: formId,
+ variant: "destructive",
+ loading: isPending,
+ disabled: hasProjects,
+ },
+ ]}
+ >
+ {hasProjects ? (
+ <Dialog.Body>
+ <p>
+ You can only delete an organization if it has no projects associated
+ with it. Please delete or transfer all projects first. Deleting
+ projects may take a few minutes.
+ </p>
+ </Dialog.Body>
+ ) : (
+ <Form {...form}>
+ <form id={formId} onSubmit={form.handleSubmit(onSubmit)}>
+ <Dialog.Body>
+ <p>{`To confirm, type "${confirmMessage}" in the input box`}</p>
+ <FormField
+ control={form.control}
+ name="name"
+ render={({ field }) => (
+ <FormItem>
+ <FormControl>
+ <Input placeholder={confirmMessage} {...field} />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ </Dialog.Body>
+ </form>
+ </Form>
+ )}
+ </Dialog>
+ );
+}
diff --git a/web/src/features/organizations/components/DeleteOrganizationDialogContent.tsx b/web/src/features/organizations/components/DeleteOrganizationDialogContent.tsx
deleted file mode 100644
index 497dbe045e..0000000000
--- a/web/src/features/organizations/components/DeleteOrganizationDialogContent.tsx
+++ /dev/null
@@ -1,98 +0,0 @@
-/* eslint-disable @typescript-eslint/no-deprecated -- Legacy UI usage retained during migration to design-system components. */
-import { zodResolver } from "@hookform/resolvers/zod";
-import * as z from "zod";
-import { useForm } from "react-hook-form";
-
-import { Button } from "@/src/components/ui/button";
-import {
- DialogBody,
- DialogDescription,
- DialogFooter,
- DialogHeader,
- DialogTitle,
-} from "@/src/components/ui/dialog";
-import {
- Form,
- FormControl,
- FormField,
- FormItem,
- FormMessage,
-} from "@/src/components/ui/form";
-import { Input } from "@/src/components/ui/input";
-
-export interface DeleteOrganizationDialogContentProps {
- confirmMessage: string;
- hasProjects: boolean;
- isPending: boolean;
- onConfirm: () => void | Promise<void>;
-}
-
-export function DeleteOrganizationDialogContent({
- confirmMessage,
- hasProjects,
- isPending,
- onConfirm,
-}: DeleteOrganizationDialogContentProps) {
- const formSchema = z.object({
- name: z.string().includes(confirmMessage, {
- message: `Please confirm with "${confirmMessage}"`,
- }),
- });
- const form = useForm({
- resolver: zodResolver(formSchema),
- defaultValues: {
- name: "",
- },
- });
-
- const onSubmit = () => {
- if (hasProjects) return;
- return onConfirm();
- };
-
- return (
- <>
- <DialogHeader>
- <DialogTitle className="text-lg font-bold">
- Delete Organization
- </DialogTitle>
- <DialogDescription>
- {hasProjects
- ? "You can only delete an organization if it has no projects associated with it. Please delete or transfer all projects first. Deleting projects may take a few minutes."
- : `To confirm, type "${confirmMessage}" in the input box `}
- </DialogDescription>
- </DialogHeader>
- <Form {...form}>
- <form onSubmit={form.handleSubmit(onSubmit)}>
- {!hasProjects && (
- <DialogBody>
- <FormField
- control={form.control}
- name="name"
- render={({ field }) => (
- <FormItem>
- <FormControl>
- <Input placeholder={confirmMessage} {...field} />
- </FormControl>
- <FormMessage />
- </FormItem>
- )}
- />
- </DialogBody>
- )}
- <DialogFooter>
- <Button
- type="submit"
- variant="destructive"
- loading={isPending}
- disabled={hasProjects}
- className="w-full"
- >
- Delete Organization
- </Button>
- </DialogFooter>
- </form>
- </Form>
- </>
- );
-}
diff --git a/web/src/features/organizations/components/DeleteOrganizationDialogController.tsx b/web/src/features/organizations/components/DeleteOrganizationDialogController.tsx
index cc3adec149..d1e940400f 100644
--- a/web/src/features/organizations/components/DeleteOrganizationDialogController.tsx
+++ b/web/src/features/organizations/components/DeleteOrganizationDialogController.tsx
@@ -1,11 +1,10 @@
-/* eslint-disable @typescript-eslint/no-deprecated -- Legacy UI usage retained during migration to design-system components. */
import { showSuccessToast } from "@/src/features/notifications/showSuccessToast";
-import { type ReactNode, useState } from "react";
+import { type ReactNode } from "react";
import { useRouter } from "next/router";
import { useSession } from "next-auth/react";
-import { Dialog, DialogContent } from "@/src/components/ui/dialog";
-import { DeleteOrganizationDialogContent } from "@/src/features/organizations/components/DeleteOrganizationDialogContent";
+import { DialogController } from "@/src/components/design-system/DialogController/DialogController";
+import { DeleteOrganizationDialog } from "@/src/features/organizations/components/DeleteOrganizationDialog";
import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";
import { useQueryOrganization } from "@/src/features/organizations/hooks";
import { useHasOrganizationAccess } from "@/src/features/rbac/utils/checkOrganizationAccess";
@@ -21,7 +20,6 @@ type DeleteOrganizationDialogControllerProps = {
export function DeleteOrganizationDialogController({
children,
}: DeleteOrganizationDialogControllerProps) {
- const [open, setOpen] = useState(false);
const router = useRouter();
const session = useSession();
const capture = usePostHogClientCapture();
@@ -39,19 +37,14 @@ export function DeleteOrganizationDialogController({
? undefined
: { reason: "You don't have permission to delete this organization." };
- const openDialog = () => {
- if (!hasAccess) return;
- setOpen(true);
- };
-
- const onSubmit = async () => {
+ const onSubmit = async (closeDialog: () => void) => {
if (!organization || hasProjects) return;
try {
await deleteOrganization.mutateAsync({
orgId: organization.id,
});
capture("organization_settings:delete_organization");
- setOpen(false);
+ closeDialog();
showSuccessToast({
operation: "organization.delete",
title: "Organization Deleted",
@@ -68,18 +61,25 @@ export function DeleteOrganizationDialogController({
};
return (
- <>
- {children({ disabled, openDialog })}
- <Dialog open={hasAccess && open} onOpenChange={setOpen}>
- <DialogContent className="sm:max-w-[425px]">
- <DeleteOrganizationDialogContent
- confirmMessage={confirmMessage}
- hasProjects={hasProjects}
- isPending={deleteOrganization.isPending}
- onConfirm={onSubmit}
- />
- </DialogContent>
- </Dialog>
- </>
+ <DialogController
+ renderDialog={({ closeDialog }) => (
+ <DeleteOrganizationDialog
+ confirmMessage={confirmMessage}
+ hasProjects={hasProjects}
+ isPending={deleteOrganization.isPending}
+ onConfirm={() => onSubmit(closeDialog)}
+ />
+ )}
+ >
+ {({ openDialog }) =>
+ children({
+ disabled,
+ openDialog: () => {
+ if (!hasAccess) return;
+ openDialog();
+ },
+ })
+ }
+ </DialogController>
);
}