fix: address onboarding review feedback
This commit is contained in:
1 parent
dc71084323
commit
2566be2838
72 files changed
+7783
-280
No files matched your search
@@ -10,6 +10,7 @@ import { signIn } from "@homarr/auth/client";
|
||||
import { revalidatePathActionAsync } from "@homarr/common/client";
|
||||
import { useZodForm } from "@homarr/form";
|
||||
import { UserCreatePasswordFields } from "@homarr/forms-collection";
|
||||
import { showErrorNotification } from "@homarr/notifications";
|
||||
import { useScopedI18n } from "@homarr/translation/client";
|
||||
import { Link } from "@homarr/ui";
|
||||
import { groupCreateSchema } from "@homarr/validation/group";
|
||||
@@ -60,17 +61,24 @@ export const AccountSetup = ({ environment }: OnboardingStudioProps) => {
|
||||
const CredentialsSetup = () => {
|
||||
const t = useScopedI18n("init.studio.account");
|
||||
const [requiresSignIn, setRequiresSignIn] = useState(false);
|
||||
const [submitError, setSubmitError] = useState<string | null>(null);
|
||||
const recoveryActionRef = useRef<HTMLAnchorElement>(null);
|
||||
const mutation = clientApi.user.initUser.useMutation();
|
||||
const mutation = clientApi.user.initUser.useMutation({
|
||||
onError() {
|
||||
const message = t("unknownError");
|
||||
setSubmitError(message);
|
||||
showErrorNotification({ title: t("errorTitle"), message });
|
||||
},
|
||||
});
|
||||
const form = useZodForm(userInitSchema, {
|
||||
initialValues: { username: "", password: "", confirmPassword: "" },
|
||||
});
|
||||
|
||||
const submitAsync = async (values: z.infer<typeof userInitSchema>) => {
|
||||
setSubmitError(null);
|
||||
try {
|
||||
await mutation.mutateAsync(values);
|
||||
} catch (error) {
|
||||
form.setErrors({ username: error instanceof Error ? error.message : t("unknownError") });
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -119,9 +127,9 @@ const CredentialsSetup = () => {
|
||||
passwordInputProps={{ ...form.getInputProps("password"), autoComplete: "new-password" }}
|
||||
confirmPasswordInputProps={{ ...form.getInputProps("confirmPassword"), autoComplete: "new-password" }}
|
||||
/>
|
||||
{mutation.error ? (
|
||||
{submitError ? (
|
||||
<Alert color="red" title={t("errorTitle")}>
|
||||
{mutation.error.message}
|
||||
{submitError}
|
||||
</Alert>
|
||||
) : null}
|
||||
<Button type="submit" size="md" loading={mutation.isPending} rightSection={<IconArrowRight size={18} />}>
|
||||
@@ -135,16 +143,27 @@ const CredentialsSetup = () => {
|
||||
|
||||
const ExternalGroupSetup = () => {
|
||||
const t = useScopedI18n("init.studio.externalGroup");
|
||||
const [submitError, setSubmitError] = useState<string | null>(null);
|
||||
const mutation = clientApi.group.createInitialExternalGroup.useMutation({
|
||||
async onSuccess() {
|
||||
await revalidatePathActionAsync("/init");
|
||||
},
|
||||
onError() {
|
||||
const message = t("unknownError");
|
||||
setSubmitError(message);
|
||||
showErrorNotification({ title: t("errorTitle"), message });
|
||||
},
|
||||
});
|
||||
const form = useZodForm(groupCreateSchema, { initialValues: { name: "" } });
|
||||
|
||||
return (
|
||||
<AccountShell title={t("title")} description={t("description")}>
|
||||
<form onSubmit={form.onSubmit((values) => mutation.mutate(values))}>
|
||||
<form
|
||||
onSubmit={form.onSubmit((values) => {
|
||||
setSubmitError(null);
|
||||
mutation.mutate(values);
|
||||
})}
|
||||
>
|
||||
<Stack gap="md">
|
||||
<TextInput
|
||||
label={t("name")}
|
||||
@@ -153,9 +172,9 @@ const ExternalGroupSetup = () => {
|
||||
withAsterisk
|
||||
{...form.getInputProps("name")}
|
||||
/>
|
||||
{mutation.error ? (
|
||||
{submitError ? (
|
||||
<Alert color="red" title={t("errorTitle")}>
|
||||
{mutation.error.message}
|
||||
{submitError}
|
||||
</Alert>
|
||||
) : null}
|
||||
<Button type="submit" size="md" loading={mutation.isPending} rightSection={<IconArrowRight size={18} />}>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { isHttpUrl, resolveDiscoveredAppUrl, takeNewSourceIds } from "./discovery-selection";
|
||||
import { isHttpUrl, normalizeServiceUrl, resolveDiscoveredAppUrl, takeNewSourceIds } from "./discovery-selection";
|
||||
|
||||
describe("takeNewSourceIds", () => {
|
||||
it("keeps same-kind service instances independent and does not reselect them after refresh", () => {
|
||||
@@ -22,10 +22,12 @@ describe("takeNewSourceIds", () => {
|
||||
expect(resolveDiscoveredAppUrl(undefined, null, null)).toBe("");
|
||||
});
|
||||
|
||||
it("accepts only HTTP and HTTPS service addresses", () => {
|
||||
it("normalizes HTTP, HTTPS, and bare self-hosted service addresses", () => {
|
||||
expect(isHttpUrl("http://home.lan:8989")).toBe(true);
|
||||
expect(isHttpUrl("https://home.example/sonarr")).toBe(true);
|
||||
expect(isHttpUrl("home.lan:8989")).toBe(false);
|
||||
expect(normalizeServiceUrl("home.lan:8989")).toBe("http://home.lan:8989");
|
||||
expect(normalizeServiceUrl("0.0.0.0:8989")).toBe("http://0.0.0.0:8989");
|
||||
expect(isHttpUrl("javascript:alert(1)")).toBe(false);
|
||||
expect(isHttpUrl("file:///etc/passwd")).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -11,11 +11,15 @@ export const resolveDiscoveredAppUrl = (
|
||||
generatedUrl: string | null,
|
||||
) => override ?? suggestedUrl ?? generatedUrl ?? "";
|
||||
|
||||
export const isHttpUrl = (value: string) => {
|
||||
export const normalizeServiceUrl = (value: string) => {
|
||||
try {
|
||||
const protocol = new URL(value).protocol;
|
||||
return protocol === "http:" || protocol === "https:";
|
||||
const trimmed = value.trim();
|
||||
if (!trimmed) return null;
|
||||
const url = new URL(/^[a-z][a-z0-9+.-]*:\/\//iu.test(trimmed) ? trimmed : `http://${trimmed}`);
|
||||
return url.protocol === "http:" || url.protocol === "https:" ? url.toString().replace(/\/$/u, "") : null;
|
||||
} catch {
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
export const isHttpUrl = (value: string) => normalizeServiceUrl(value) !== null;
|
||||
@@ -450,7 +450,7 @@
|
||||
width: 1px;
|
||||
height: 1px;
|
||||
overflow: hidden;
|
||||
clip: rect(0 0 0 0);
|
||||
clip-path: inset(50%);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,13 +35,21 @@ export const OnboardingStudio = (props: OnboardingStudioProps) => {
|
||||
setClaimState("ready");
|
||||
return;
|
||||
}
|
||||
const body = (await response.json().catch(() => null)) as { error?: string } | null;
|
||||
setClaimError(body?.error ?? t("errorDescription"));
|
||||
setClaimState(response.status === 423 ? "locked" : response.status === 403 ? "signIn" : "error");
|
||||
const body = (await response.json().catch(() => null)) as { code?: unknown } | null;
|
||||
if (body?.code === "locked") {
|
||||
setClaimState("locked");
|
||||
return;
|
||||
}
|
||||
if (body?.code === "administrator_required") {
|
||||
setClaimState("signIn");
|
||||
return;
|
||||
}
|
||||
setClaimError(t("errorDescription"));
|
||||
setClaimState("error");
|
||||
})
|
||||
.catch((error: unknown) => {
|
||||
.catch(() => {
|
||||
if (controller.signal.aborted) return;
|
||||
setClaimError(error instanceof Error ? error.message : t("errorDescription"));
|
||||
setClaimError(t("errorDescription"));
|
||||
setClaimState("error");
|
||||
});
|
||||
return () => controller.abort();
|
||||
|
||||
@@ -96,7 +96,7 @@ import { IntegrationAvatar, Link } from "@homarr/ui";
|
||||
import { IntegrationMultiSelectGrid } from "@homarr/ui/integration-select-grid";
|
||||
|
||||
import type { OnboardingStudioProps } from "./types";
|
||||
import { isHttpUrl, resolveDiscoveredAppUrl, takeNewSourceIds } from "./discovery-selection";
|
||||
import { isHttpUrl, normalizeServiceUrl, resolveDiscoveredAppUrl, takeNewSourceIds } from "./discovery-selection";
|
||||
import classes from "./onboarding-studio.module.css";
|
||||
|
||||
type StudioSection = "essentials" | "discover" | "connect" | "board" | "extend" | "review";
|
||||
@@ -150,8 +150,10 @@ export const SetupStudio = ({ environment }: OnboardingStudioProps) => {
|
||||
const [selectedAppIds, setSelectedAppIds] = useState<string[]>([]);
|
||||
const [appUrlOverrides, setAppUrlOverrides] = useState<Record<string, string>>({});
|
||||
const [appErrorSourceId, setAppErrorSourceId] = useState<string | null>(null);
|
||||
const [selectedBoardId, setSelectedBoardId] = useState<string | null>(environment.initialBoard?.id ?? null);
|
||||
const [boardName, setBoardName] = useState(environment.initialBoard?.name ?? "dashboard");
|
||||
const initialBoard =
|
||||
environment.initialBoard ?? (environment.availableBoards.length === 1 ? environment.availableBoards[0] : null);
|
||||
const [selectedBoardId, setSelectedBoardId] = useState<string | null>(initialBoard?.id ?? null);
|
||||
const [boardName, setBoardName] = useState(initialBoard?.name ?? "dashboard");
|
||||
const [primaryColor, setPrimaryColor] = useState("#fa5252");
|
||||
const [secondaryColor, setSecondaryColor] = useState("#fd7e14");
|
||||
const [itemRadius, setItemRadius] = useState<MantineSize>("lg");
|
||||
@@ -163,6 +165,7 @@ export const SetupStudio = ({ environment }: OnboardingStudioProps) => {
|
||||
const [applyError, setApplyError] = useState<string | null>(null);
|
||||
const [appError, setAppError] = useState<string | null>(null);
|
||||
const sectionHeadingRef = useRef<HTMLHeadingElement>(null);
|
||||
const sectionButtonRefs = useRef<(HTMLButtonElement | null)[]>([]);
|
||||
const initialSection = useRef(true);
|
||||
const focusSectionHeading = useRef(true);
|
||||
const seenIntegrationSourceIds = useRef(new Set<string>());
|
||||
@@ -177,7 +180,11 @@ export const SetupStudio = ({ environment }: OnboardingStudioProps) => {
|
||||
retry: false,
|
||||
refetchOnWindowFocus: false,
|
||||
});
|
||||
const complete = clientApi.onboard.completeSetup.useMutation();
|
||||
const complete = clientApi.onboard.completeSetup.useMutation({
|
||||
onError(error) {
|
||||
showErrorNotification({ title: t("review.errorTitle"), message: error.message });
|
||||
},
|
||||
});
|
||||
const isApplying = complete.isPending;
|
||||
|
||||
const dockerData = docker.data;
|
||||
@@ -313,8 +320,7 @@ export const SetupStudio = ({ environment }: OnboardingStudioProps) => {
|
||||
if (!nextSection) return;
|
||||
focusSectionHeading.current = false;
|
||||
selectSection(nextSection.id);
|
||||
const nextButton = event.currentTarget.parentElement?.querySelectorAll("button").item(nextIndex);
|
||||
if (nextButton instanceof HTMLButtonElement) nextButton.focus();
|
||||
sectionButtonRefs.current[nextIndex]?.focus();
|
||||
};
|
||||
|
||||
const updateDraft = (id: string, patch: Partial<IntegrationDraft>) => {
|
||||
@@ -394,7 +400,7 @@ export const SetupStudio = ({ environment }: OnboardingStudioProps) => {
|
||||
return {
|
||||
sourceId: draft.sourceId ?? draft.id,
|
||||
name: draft.name,
|
||||
url: draft.url,
|
||||
url: normalizeServiceUrl(draft.url) ?? draft.url,
|
||||
kind: draft.kind,
|
||||
secrets: draft.secrets,
|
||||
iconUrl: discovered?.iconUrl ?? null,
|
||||
@@ -403,7 +409,7 @@ export const SetupStudio = ({ environment }: OnboardingStudioProps) => {
|
||||
};
|
||||
}),
|
||||
apps: appsToCreate.flatMap((app) => {
|
||||
const href = discoveredAppUrls[app.sourceId];
|
||||
const href = normalizeServiceUrl(discoveredAppUrls[app.sourceId] ?? "");
|
||||
return href
|
||||
? [
|
||||
{
|
||||
@@ -448,7 +454,7 @@ export const SetupStudio = ({ environment }: OnboardingStudioProps) => {
|
||||
if (dockerWarningCount > 0) {
|
||||
showWarningNotification({
|
||||
title: t("review.dockerWarningTitle"),
|
||||
message: t("review.dockerWarningDescription", { count: String(dockerWarningCount) }),
|
||||
message: t("review.dockerWarningDescription", { count: dockerWarningCount }),
|
||||
});
|
||||
}
|
||||
setApplyMessage(t("review.progress.done"));
|
||||
@@ -552,6 +558,9 @@ export const SetupStudio = ({ environment }: OnboardingStudioProps) => {
|
||||
return (
|
||||
<UnstyledButton
|
||||
key={section.id}
|
||||
ref={(node) => {
|
||||
sectionButtonRefs.current[index] = node;
|
||||
}}
|
||||
className={classes.railButton}
|
||||
data-active={active}
|
||||
onClick={() => selectSection(section.id)}
|
||||
@@ -1093,8 +1102,7 @@ const Connections = (props: StudioSectionProps) => {
|
||||
value={props.discoveredAppUrls[app.sourceId] ?? ""}
|
||||
onChange={(event) => props.setDiscoveredAppUrl(app.sourceId, event.currentTarget.value)}
|
||||
error={props.appErrorSourceId === app.sourceId ? props.appError : undefined}
|
||||
placeholder="https://service.example"
|
||||
type="url"
|
||||
placeholder="service.local:8080"
|
||||
required
|
||||
/>
|
||||
) : null}
|
||||
@@ -1253,7 +1261,7 @@ const BoardBuilder = (props: StudioSectionProps) => {
|
||||
allowDeselect={false}
|
||||
searchable
|
||||
withAsterisk
|
||||
error={props.selectedBoardId ? undefined : t("targetRequired")}
|
||||
error={!props.selectedBoardId && props.applyProgress > 0 ? t("targetRequired") : undefined}
|
||||
/>
|
||||
) : null}
|
||||
<TextInput
|
||||
@@ -1509,6 +1517,7 @@ const Extensions = (props: StudioSectionProps) => {
|
||||
|
||||
const AssistantSetup = ({ environment }: { environment: StudioSectionProps["environment"] }) => {
|
||||
const t = useScopedI18n("init.studio.extend.assistantSetup");
|
||||
const assistantSettingsT = useScopedI18n("management.page.settings.section.assistant");
|
||||
const reduceMotion = useReducedMotion();
|
||||
const [provider, setProvider] = useState<AssistantProvider>("homarr");
|
||||
const [baseUrl, setBaseUrl] = useState<string>(assistantProviderPresets.homarr.baseUrl);
|
||||
@@ -1532,6 +1541,9 @@ const AssistantSetup = ({ environment }: { environment: StudioSectionProps["envi
|
||||
await configuration.refetch();
|
||||
await models.refetch();
|
||||
},
|
||||
onError(error) {
|
||||
showErrorNotification({ title: t("errorTitle"), message: error.message });
|
||||
},
|
||||
});
|
||||
const updateConfiguration = clientApi.assistant.updateConfiguration.useMutation({
|
||||
onSuccess() {
|
||||
@@ -1616,7 +1628,10 @@ const AssistantSetup = ({ environment }: { environment: StudioSectionProps["envi
|
||||
label={t("provider")}
|
||||
value={provider}
|
||||
onChange={selectProvider}
|
||||
data={assistantProviderIds.map((value) => ({ value, label: value.replaceAll("-", " ") }))}
|
||||
data={assistantProviderIds.map((value) => ({
|
||||
value,
|
||||
label: assistantSettingsT(`provider.options.${value}.label`),
|
||||
}))}
|
||||
allowDeselect={false}
|
||||
/>
|
||||
<TextInput
|
||||
@@ -1768,6 +1783,9 @@ const McpSetup = ({ environment }: { environment: StudioSectionProps["environmen
|
||||
onSuccess(data) {
|
||||
setApiKey(data.apiKey);
|
||||
},
|
||||
onError(error) {
|
||||
showErrorNotification({ title: t("errorTitle"), message: error.message });
|
||||
},
|
||||
});
|
||||
const config = JSON.stringify(
|
||||
{
|
||||
@@ -1957,6 +1975,6 @@ const createDraft = ({
|
||||
url,
|
||||
source,
|
||||
secretOption: 0,
|
||||
secrets: getAllSecretKindOptions(kind)[0].map((secretKind) => ({ kind: secretKind, value: "" })),
|
||||
secrets: (getAllSecretKindOptions(kind)[0] ?? []).map((secretKind) => ({ kind: secretKind, value: "" })),
|
||||
error: null,
|
||||
});
|
||||
@@ -7,6 +7,7 @@ import { motion, useReducedMotion } from "motion/react";
|
||||
|
||||
import { clientApi } from "@homarr/api/client";
|
||||
import { revalidatePathActionAsync } from "@homarr/common/client";
|
||||
import { showErrorNotification } from "@homarr/notifications";
|
||||
import { useScopedI18n } from "@homarr/translation/client";
|
||||
|
||||
import type { OnboardingStudioProps } from "./types";
|
||||
@@ -14,6 +15,7 @@ import classes from "./onboarding-studio.module.css";
|
||||
|
||||
export const Welcome = ({ environment, sqliteRestore }: OnboardingStudioProps) => {
|
||||
const t = useScopedI18n("init.studio.welcome");
|
||||
const claimT = useScopedI18n("init.studio.claim");
|
||||
const reduceMotion = useReducedMotion();
|
||||
const [showRestore, setShowRestore] = useState(false);
|
||||
const [claimPending, setClaimPending] = useState(false);
|
||||
@@ -22,16 +24,34 @@ export const Welcome = ({ environment, sqliteRestore }: OnboardingStudioProps) =
|
||||
async onSuccess() {
|
||||
await revalidatePathActionAsync("/init");
|
||||
},
|
||||
onError() {
|
||||
showErrorNotification({ title: t("errorTitle"), message: t("errorDescription") });
|
||||
},
|
||||
});
|
||||
|
||||
const getClaimError = (code: unknown) => {
|
||||
switch (code) {
|
||||
case "finished":
|
||||
case "unavailable":
|
||||
case "cross_site":
|
||||
return claimT("errorDescription");
|
||||
case "administrator_required":
|
||||
return claimT("signInDescription");
|
||||
case "locked":
|
||||
return claimT("lockedDescription");
|
||||
default:
|
||||
return t("errorDescription");
|
||||
}
|
||||
};
|
||||
|
||||
const claimOnboardingAsync = async () => {
|
||||
setClaimPending(true);
|
||||
setClaimError(null);
|
||||
try {
|
||||
const response = await fetch("/api/onboarding/claim", { method: "POST" });
|
||||
if (!response.ok) {
|
||||
const body = (await response.json().catch(() => null)) as { error?: string } | null;
|
||||
throw new Error(body?.error ?? t("errorTitle"));
|
||||
const body = (await response.json().catch(() => null)) as { code?: unknown } | null;
|
||||
throw new Error(getClaimError(body?.code));
|
||||
}
|
||||
return true;
|
||||
} catch (error) {
|
||||
@@ -128,7 +148,7 @@ export const Welcome = ({ environment, sqliteRestore }: OnboardingStudioProps) =
|
||||
|
||||
{claimError || start.error ? (
|
||||
<Alert color="red" title={t("errorTitle")} maw="38rem">
|
||||
{claimError ?? start.error?.message}
|
||||
{claimError ?? t("errorDescription")}
|
||||
</Alert>
|
||||
) : null}
|
||||
</Stack>
|
||||
|
||||
Reference in new issue
Block a user