Skip to content

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

🐛 Close the license dialog when a key is activated (#2884)

Luke Vella1cbbe38a173e
diff --git a/apps/web/src/app/[locale]/control-panel/license/page.tsx b/apps/web/src/app/[locale]/control-panel/license/page.tsx
index 0a22a894d..bdcee5e4e 100644
--- a/apps/web/src/app/[locale]/control-panel/license/page.tsx
+++ b/apps/web/src/app/[locale]/control-panel/license/page.tsx
@@ -1,21 +1,8 @@
import { buttonVariants } from "@rallly/ui";
import { Badge } from "@rallly/ui/badge";
-import { Button } from "@rallly/ui/button";
import { Card, CardContent, CardHeader, CardTitle } from "@rallly/ui/card";
-import {
- Dialog,
- DialogContent,
- DialogHeader,
- DialogTitle,
- DialogTrigger,
-} from "@rallly/ui/dialog";
-import {
- KeySquareIcon,
- PaletteIcon,
- PlusIcon,
- ShoppingBagIcon,
-} from "lucide-react";
+import { KeySquareIcon, PaletteIcon, ShoppingBagIcon } from "lucide-react";
import type { Metadata } from "next";
import {
DescriptionList,
@@ -37,7 +24,7 @@ import {
SettingsPageHeader,
SettingsPageTitle,
} from "@/components/settings-layout";
-import { LicenseKeyForm } from "@/features/licensing/components/license-key-form";
+import { AddLicenseKeyButton } from "@/features/licensing/components/add-license-key-button";
import { RefreshLicenseButton } from "@/features/licensing/components/refresh-license-button";
import { RemoveLicenseButton } from "@/features/licensing/components/remove-license-button";
import { loadInstanceLicense } from "@/features/licensing/data";
@@ -193,23 +180,7 @@ export default async function LicensePage() {
<ShoppingBagIcon data-icon="inline-start" />
<Trans i18nKey="purchaseLicense" defaults="Purchase license" />
</a>
- <Dialog>
- <DialogTrigger render={<Button variant="primary" />}>
- <PlusIcon data-icon="inline-start" />
- <Trans i18nKey="addLicenseKey" defaults="Add license key" />
- </DialogTrigger>
- <DialogContent size="sm">
- <DialogHeader>
- <DialogTitle>
- <Trans
- i18nKey="addLicenseKey"
- defaults="Add license key"
- />
- </DialogTitle>
- </DialogHeader>
- <LicenseKeyForm />
- </DialogContent>
- </Dialog>
+ <AddLicenseKeyButton />
</EmptyStateFooter>
</EmptyState>
)}
diff --git a/apps/web/src/features/licensing/components/add-license-key-button.tsx b/apps/web/src/features/licensing/components/add-license-key-button.tsx
new file mode 100644
index 000000000..b7baacbca
--- /dev/null
+++ b/apps/web/src/features/licensing/components/add-license-key-button.tsx
@@ -0,0 +1,48 @@
+"use client";
+
+import { Button } from "@rallly/ui/button";
+import {
+ Dialog,
+ DialogContent,
+ DialogHeader,
+ DialogTitle,
+ useDialog,
+} from "@rallly/ui/dialog";
+import { PlusIcon } from "lucide-react";
+import { LicenseKeyForm } from "@/features/licensing/components/license-key-form";
+import { Trans } from "@/i18n/client";
+
+export function AddLicenseKeyButton() {
+ const dialog = useDialog();
+
+ // On success the page swaps to the installed-license view, which unmounts
+ // this trigger, so dismiss()'s focus restore targets a detached node and
+ // focus falls to <body>. Send it to the main content region instead, which
+ // survives the swap. Deferred so it lands after the dialog's own focus
+ // handling rather than being overwritten by it.
+ const handleSuccess = () => {
+ dialog.dismiss();
+ requestAnimationFrame(() => {
+ document.getElementById("main-content")?.focus();
+ });
+ };
+
+ return (
+ <>
+ <Button variant="primary" {...dialog.triggerProps}>
+ <PlusIcon data-icon="inline-start" />
+ <Trans i18nKey="addLicenseKey" defaults="Add license key" />
+ </Button>
+ <Dialog {...dialog.dialogProps}>
+ <DialogContent size="sm">
+ <DialogHeader>
+ <DialogTitle>
+ <Trans i18nKey="addLicenseKey" defaults="Add license key" />
+ </DialogTitle>
+ </DialogHeader>
+ <LicenseKeyForm onSuccess={handleSuccess} />
+ </DialogContent>
+ </Dialog>
+ </>
+ );
+}
diff --git a/apps/web/src/features/licensing/components/license-key-form.tsx b/apps/web/src/features/licensing/components/license-key-form.tsx
index 66c1362b5..1bdbb0844 100644
--- a/apps/web/src/features/licensing/components/license-key-form.tsx
+++ b/apps/web/src/features/licensing/components/license-key-form.tsx
@@ -25,7 +25,7 @@ const formSchema = z.object({
}),
});
-export function LicenseKeyForm() {
+export function LicenseKeyForm({ onSuccess }: { onSuccess?: () => void }) {
const { t } = useTranslation();
const router = useRouter();
const form = useForm({
@@ -53,6 +53,7 @@ export function LicenseKeyForm() {
defaultValue: "Invalid license key",
}),
});
+ return;
}
} catch (_error) {
form.setError("licenseKey", {
@@ -61,7 +62,13 @@ export function LicenseKeyForm() {
"An error occurred while validating the license key",
}),
});
+ return;
}
+
+ // Refreshing swaps the page to the installed-license branch, which
+ // unmounts this form. Notify the owner first so closing the dialog
+ // doesn't depend on that re-render winning a race.
+ onSuccess?.();
router.refresh();
})}
>