Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

♻️ Rebuild the danger zone on Setting primitives (#2842)

Luke Vella780bb5fe2c98
diff --git a/apps/web/src/app/[locale]/(space)/settings/profile/components/cancel-account-deletion-button.tsx b/apps/web/src/app/[locale]/(space)/settings/profile/components/cancel-account-deletion-button.tsx
index adb077ee6..cb73de4b2 100644
--- a/apps/web/src/app/[locale]/(space)/settings/profile/components/cancel-account-deletion-button.tsx
+++ b/apps/web/src/app/[locale]/(space)/settings/profile/components/cancel-account-deletion-button.tsx
@@ -5,7 +5,12 @@ import { Trans, useTranslation } from "@/i18n/client";
import { useSafeAction } from "@/lib/safe-action/client";
import { cancelAccountDeletionAction } from "../actions";
-export function CancelAccountDeletionButton() {
+export function CancelAccountDeletionButton({
+ ...rest
+}: {
+ "aria-labelledby"?: string;
+ "aria-describedby"?: string;
+}) {
const { t } = useTranslation();
const cancelAccountDeletion = useSafeAction(cancelAccountDeletionAction, {
onSuccess: () => {
@@ -21,6 +26,7 @@ export function CancelAccountDeletionButton() {
<Button
loading={cancelAccountDeletion.isExecuting}
onClick={() => cancelAccountDeletion.executeAsync()}
+ {...rest}
>
<Trans i18nKey="cancelAccountDeletion" defaults="Cancel deletion" />
</Button>
diff --git a/apps/web/src/app/[locale]/(space)/settings/profile/components/delete-account-button.tsx b/apps/web/src/app/[locale]/(space)/settings/profile/components/delete-account-button.tsx
index 61853a354..ebd1fd0c9 100644
--- a/apps/web/src/app/[locale]/(space)/settings/profile/components/delete-account-button.tsx
+++ b/apps/web/src/app/[locale]/(space)/settings/profile/components/delete-account-button.tsx
@@ -8,13 +8,16 @@ import { DeleteAccountDialog } from "./delete-account-dialog";
export function DeleteAccountButton({
summary,
+ ...rest
}: {
summary?: React.ReactNode;
+ "aria-labelledby"?: string;
+ "aria-describedby"?: string;
}) {
const dialog = useDialog();
return (
<>
- <Button className="text-destructive" {...dialog.triggerProps}>
+ <Button className="text-destructive" {...dialog.triggerProps} {...rest}>
<Trans i18nKey="deleteAccount" defaults="Delete Account" />
</Button>
<DeleteAccountDialog {...dialog.dialogProps} summary={summary} />
diff --git a/apps/web/src/app/[locale]/(space)/settings/profile/components/delete-account-setting.tsx b/apps/web/src/app/[locale]/(space)/settings/profile/components/delete-account-setting.tsx
new file mode 100644
index 000000000..3332aa0e6
--- /dev/null
+++ b/apps/web/src/app/[locale]/(space)/settings/profile/components/delete-account-setting.tsx
@@ -0,0 +1,74 @@
+import { TriangleAlertIcon } from "lucide-react";
+import {
+ Setting,
+ SettingControl,
+ SettingDescription,
+ SettingIcon,
+ SettingTitle,
+} from "@/components/setting";
+import { getScheduledDeletionDate } from "@/features/user/account-deletion/utils";
+import { Trans } from "@/i18n/client";
+import { getSession } from "@/lib/auth";
+import { formatDateTime } from "@/lib/datetime/format";
+import { CancelAccountDeletionButton } from "./cancel-account-deletion-button";
+
+export async function PendingDeletionSetting({
+ deletedAt,
+}: {
+ deletedAt: Date;
+}) {
+ const session = await getSession();
+ const deletionDate = formatDateTime(getScheduledDeletionDate(deletedAt), {
+ preset: "dateLong",
+ locale: session?.user.locale ?? "en",
+ timeZone: session?.user.timeZone,
+ });
+
+ return (
+ <Setting>
+ <SettingIcon>
+ <TriangleAlertIcon />
+ </SettingIcon>
+ <SettingTitle>
+ <Trans i18nKey="deleteAccount" defaults="Delete Account" />
+ </SettingTitle>
+ <SettingDescription>
+ <Trans
+ i18nKey="pendingDeletionNotice"
+ defaults="Your account and data will be permanently deleted on {deletionDate}."
+ values={{ deletionDate }}
+ />
+ </SettingDescription>
+ <SettingControl>
+ <CancelAccountDeletionButton />
+ </SettingControl>
+ </Setting>
+ );
+}
+
+export function DeleteAccountSetting({
+ children,
+}: {
+ children: React.ReactElement<{
+ "aria-labelledby"?: string;
+ "aria-describedby"?: string;
+ }>;
+}) {
+ return (
+ <Setting>
+ <SettingIcon>
+ <TriangleAlertIcon />
+ </SettingIcon>
+ <SettingTitle>
+ <Trans i18nKey="deleteAccount" defaults="Delete Account" />
+ </SettingTitle>
+ <SettingDescription>
+ <Trans
+ i18nKey="dangerZoneAccountDeletion"
+ defaults="Delete your account and all data associated with it"
+ />
+ </SettingDescription>
+ <SettingControl>{children}</SettingControl>
+ </Setting>
+ );
+}
diff --git a/apps/web/src/app/[locale]/(space)/settings/profile/components/pending-deletion-notice.tsx b/apps/web/src/app/[locale]/(space)/settings/profile/components/pending-deletion-notice.tsx
deleted file mode 100644
index 9255affe1..000000000
--- a/apps/web/src/app/[locale]/(space)/settings/profile/components/pending-deletion-notice.tsx
+++ /dev/null
@@ -1,31 +0,0 @@
-import { getScheduledDeletionDate } from "@/features/user/account-deletion/utils";
-import { Trans } from "@/i18n/client";
-import { getSession } from "@/lib/auth";
-import { formatDateTime } from "@/lib/datetime/format";
-import { CancelAccountDeletionButton } from "./cancel-account-deletion-button";
-
-export async function PendingDeletionNotice({
- deletedAt,
-}: {
- deletedAt: Date;
-}) {
- const session = await getSession();
- const deletionDate = formatDateTime(getScheduledDeletionDate(deletedAt), {
- preset: "dateLong",
- locale: session?.user.locale ?? "en",
- timeZone: session?.user.timeZone,
- });
-
- return (
- <div className="space-y-4">
- <p className="text-sm">
- <Trans
- i18nKey="pendingDeletionNotice"
- defaults="Your account and data will be permanently deleted on {deletionDate}."
- values={{ deletionDate }}
- />
- </p>
- <CancelAccountDeletionButton />
- </div>
- );
-}
diff --git a/apps/web/src/app/[locale]/(space)/settings/profile/page.tsx b/apps/web/src/app/[locale]/(space)/settings/profile/page.tsx
index 4a1e8391e..db3d70585 100644
--- a/apps/web/src/app/[locale]/(space)/settings/profile/page.tsx
+++ b/apps/web/src/app/[locale]/(space)/settings/profile/page.tsx
@@ -11,6 +11,7 @@ import {
PageSectionHeader,
PageSectionTitle,
} from "@/components/page-layout";
+import { SettingsGroup } from "@/components/setting";
import {
SettingsPage,
SettingsPageContent,
@@ -28,7 +29,10 @@ import {
AccountDeletionSummarySkeleton,
} from "./components/account-deletion-summary";
import { DeleteAccountButton } from "./components/delete-account-button";
-import { PendingDeletionNotice } from "./components/pending-deletion-notice";
+import {
+ DeleteAccountSetting,
+ PendingDeletionSetting,
+} from "./components/delete-account-setting";
import { ProfileEmailAddress } from "./components/profile-email-address";
import { ProfileSettings } from "./components/profile-settings";
@@ -89,25 +93,23 @@ export default async function Page() {
<PageSectionTitle>
<Trans i18nKey="dangerZone" defaults="Danger Zone" />
</PageSectionTitle>
- <PageSectionDescription>
- <Trans
- i18nKey="dangerZoneAccountDeletion"
- defaults="Delete your account and all data associated with it"
- />
- </PageSectionDescription>
</PageSectionHeader>
<PageSectionContent>
- {user.deletedAt ? (
- <PendingDeletionNotice deletedAt={user.deletedAt} />
- ) : (
- <DeleteAccountButton
- summary={
- <Suspense fallback={<AccountDeletionSummarySkeleton />}>
- <AccountDeletionSummary />
- </Suspense>
- }
- />
- )}
+ <SettingsGroup>
+ {user.deletedAt ? (
+ <PendingDeletionSetting deletedAt={user.deletedAt} />
+ ) : (
+ <DeleteAccountSetting>
+ <DeleteAccountButton
+ summary={
+ <Suspense fallback={<AccountDeletionSummarySkeleton />}>
+ <AccountDeletionSummary />
+ </Suspense>
+ }
+ />
+ </DeleteAccountSetting>
+ )}
+ </SettingsGroup>
</PageSectionContent>
</PageSection>
</PageSectionGroup>