import type { IconSvgElement } from "@hugeicons/react";
import {
ArrowLeft01Icon,
ArrowRight01Icon,
BotIcon,
CheckmarkCircle02Icon,
Copy01Icon,
Key01Icon,
Link01Icon,
SecurityLockIcon,
UserMultiple02Icon,
} from "@hugeicons/core-free-icons";
import type { ReactNode } from "react";
import { Icon } from "@/components/icon";
import { Alert, AlertDescription } from "@/components/ui/alert";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Textarea } from "@/components/ui/textarea";
import type { FieldValidationResult, SetupFormValues } from "@/lib/setup-types";
import { cn } from "@/lib/utils";
export const SETUP_STEP_IDS = [
"botToken",
"secretKey",
"oauth",
"redirectUri",
"owners",
"emeraldApi",
] as const;
export type SetupStepId = (typeof SETUP_STEP_IDS)[number];
export const SETUP_STEPS: {
id: SetupStepId;
title: string;
subtitle: string;
icon: IconSvgElement;
}[] = [
{
id: "botToken",
title: "Bot token",
subtitle: "Connect your Discord bot",
icon: BotIcon,
},
{
id: "secretKey",
title: "Session secret",
subtitle: "Secure dashboard logins",
icon: SecurityLockIcon,
},
{
id: "oauth",
title: "Discord OAuth",
subtitle: "Sign in with Discord",
icon: Key01Icon,
},
{
id: "redirectUri",
title: "Redirect URL",
subtitle: "OAuth callback address",
icon: Link01Icon,
},
{
id: "owners",
title: "Dashboard owners",
subtitle: "Who can access this panel",
icon: UserMultiple02Icon,
},
{
id: "emeraldApi",
title: "Emerald API",
subtitle: "One-click addons",
icon: Key01Icon,
},
];
function validationKeyForStep(id: SetupStepId): string {
if (id === "oauth") return "oauth";
if (id === "owners") return "owners";
return id;
}
export function SetupWizardShell({
brandingTitle,
faviconUrl,
faviconVersion,
hasFavicon,
children,
}: {
brandingTitle: string;
faviconUrl?: string | null;
faviconVersion?: number;
hasFavicon: boolean;
children: ReactNode;
}) {
return (
{hasFavicon && faviconUrl ? (
) : (
)}
First-time setup
{brandingTitle}
{children}
);
}
export function SetupProgress({
currentIndex,
validation,
}: {
currentIndex: number;
validation: Record;
}) {
const progress = ((currentIndex + 1) / SETUP_STEPS.length) * 100;
return (
Step {currentIndex + 1} of {SETUP_STEPS.length}
{Math.round(progress)}%
{SETUP_STEPS.map((step, index) => {
const key = validationKeyForStep(step.id);
const verified = validation[key]?.ok;
const isCurrent = index === currentIndex;
const isPast = index < currentIndex;
return (
{verified ? (
) : (
)}
{step.title}
{step.subtitle}
);
})}
Each step can be tested with Discord before you continue. You can move back
anytime to change a value.
);
}
export function SetupStepCard({
step,
children,
footer,
}: {
step: (typeof SETUP_STEPS)[number];
children: ReactNode;
footer?: ReactNode;
}) {
return (
{step.title}
{step.subtitle}
{step.title}
{step.subtitle}
{children}
{footer ? (
{footer}
) : null}
);
}
export function ValidationBanner({
result,
}: {
result?: FieldValidationResult;
}) {
if (!result) return null;
if (result.ok) {
return (
{result.bot ? (
Connected as @{result.bot.username}
{result.applicationId ? (
{" "}
· App ID {result.applicationId}
) : null}
) : null}
{result.users?.length ? (
{result.users.map((u) => (
{u.globalName || u.username}
{u.id}
))}
) : null}
{!result.bot && !result.users?.length ? (
{result.warning || "Verified successfully."}
) : null}
);
}
return (
{result.error}
);
}
export function BotTokenStep({
values,
setValues,
validation,
validating,
onValidate,
}: {
values: SetupFormValues;
setValues: (v: SetupFormValues) => void;
validation: Record;
validating: boolean;
onValidate: () => void;
}) {
return (
Open the{" "}
Discord Developer Portal
, select your application, go to Bot , and reset or copy
the token.
Bot token
setValues({ ...values, botToken: e.target.value })}
placeholder="MTI…"
className="h-11 font-mono text-sm"
/>
{validating ? "Checking with Discord…" : "Verify bot token"}
);
}
export function SecretKeyStep({
values,
setValues,
validation,
validating,
onValidate,
onGenerate,
}: {
values: SetupFormValues;
setValues: (v: SetupFormValues) => void;
validation: Record;
validating: boolean;
onValidate: () => void;
onGenerate: () => void;
}) {
return (
This random string signs your login cookies. Store it like a password — do
not commit it to public repos.
Session secret
setValues({ ...values, secretKey: e.target.value })}
className="h-11 font-mono text-sm"
/>
Generate secure secret
{validating ? "Checking…" : "Validate"}
);
}
export function OAuthStep({
values,
setValues,
validation,
validating,
onValidate,
}: {
values: SetupFormValues;
setValues: (v: SetupFormValues) => void;
validation: Record;
validating: boolean;
onValidate: () => void;
}) {
return (
Use the same application as your bot. Under OAuth2, copy
the Client ID and Client Secret.
{validating ? "Checking with Discord…" : "Verify OAuth credentials"}
);
}
export function RedirectStep({
values,
setValues,
validation,
}: {
values: SetupFormValues;
setValues: (v: SetupFormValues) => void;
validation: Record;
}) {
async function copyUri() {
if (!values.redirectUri) return;
try {
await navigator.clipboard.writeText(values.redirectUri);
} catch {
/* ignore */
}
}
return (
Add this exact URL under OAuth2 → Redirects in the
Developer Portal. It must match character-for-character.
{validation.redirectUri && !validation.redirectUri.ok ? (
) : (
We pre-filled this from your current dashboard URL. If you access the
panel from a different domain later, update this and add the new URL in
Discord too.
)}
);
}
export function OwnersStep({
values,
setValues,
validation,
validating,
onValidate,
}: {
values: SetupFormValues;
setValues: (v: SetupFormValues) => void;
validation: Record;
validating: boolean;
onValidate: () => void;
}) {
return (
Enable Developer Mode in Discord (Settings → Advanced),
then right-click your profile and Copy User ID . Add one ID
per line.
Owner user IDs
{validating ? "Checking with Discord…" : "Verify owner IDs"}
);
}
export function SetupCompleteScreen({ onContinue }: { onContinue: () => void }) {
return (
Setup complete
Your configuration has been saved. Restart the server for changes to take
effect — stop the running process, then start it again (for example{" "}
npm start
).
After restarting, sign in with Discord to open the dashboard.
Continue to sign in
);
}
export function SetupNav({
currentIndex,
validating,
saving,
onBack,
onNext,
onFinish,
}: {
currentIndex: number;
validating: boolean;
saving: boolean;
onBack: () => void;
onNext: () => void;
onFinish: () => void;
}) {
const isLast = currentIndex === SETUP_STEPS.length - 1;
return (
Back
{isLast ? (
{saving ? "Saving…" : "Finish setup"}
) : (
Continue
)}
);
}
export function EmeraldApiKeyStep({
values,
setValues,
validation,
validating,
onValidate,
}: {
values: SetupFormValues;
setValues: (v: SetupFormValues) => void;
validation: Record;
validating: boolean;
onValidate: () => void;
}) {
return (
An Emerald Services API key is optional, but required to use the one-click addon installer in the dashboard. You can get yours from the{" "}
Emerald Services Marketplace
.
Emerald API key (Optional)
setValues({ ...values, emeraldApiKey: e.target.value })}
placeholder="em_..."
className="h-11 font-mono text-sm"
/>
{validating ? "Checking…" : (values.emeraldApiKey ? "Verify key" : "Skip step")}
);
}