feat(onboarding): add board tour on dashboard pages

Scope the board tour to content pages, target header actions, remove the
loading overlay, and persist completion with optimistic cache updates.
This commit is contained in:
Thomas Camlong committed 2026-05-20 09:43:00 +02:00
1 parent 1279168538
commit 60bf867203
5 files changed
+78 -64

No files matched your search

@@ -1,7 +1,7 @@
"use client"; "use client";
import { useCallback, useRef } from "react"; import { useCallback, useRef } from "react";
import { Box, LoadingOverlay, Stack } from "@mantine/core"; import { Box, Stack } from "@mantine/core";
import type { RouterOutputs } from "@homarr/api"; import type { RouterOutputs } from "@homarr/api";
import { clientApi } from "@homarr/api/client"; import { clientApi } from "@homarr/api/client";
@@ -10,8 +10,6 @@ import { useCurrentLayout, useRequiredBoard } from "@homarr/boards/context";
import { BoardCategorySection } from "~/components/board/sections/category-section"; import { BoardCategorySection } from "~/components/board/sections/category-section";
import { BoardEmptySection } from "~/components/board/sections/empty-section"; import { BoardEmptySection } from "~/components/board/sections/empty-section";
import { BoardBackgroundVideo } from "~/components/layout/background"; import { BoardBackgroundVideo } from "~/components/layout/background";
import { fullHeightWithoutHeaderAndFooter } from "~/constants";
import { useIsBoardReady } from "./_ready-context";
let boardName: string | null = null; let boardName: string | null = null;
@@ -44,7 +42,6 @@ export const useUpdateBoard = () => {
export const ClientBoard = () => { export const ClientBoard = () => {
const board = useRequiredBoard(); const board = useRequiredBoard();
const currentLayoutId = useCurrentLayout(); const currentLayoutId = useCurrentLayout();
const isReady = useIsBoardReady();
const fullWidthSortedSections = board.sections const fullWidthSortedSections = board.sections
.filter((section) => section.kind === "empty" || section.kind === "category") .filter((section) => section.kind === "empty" || section.kind === "category")
@@ -55,13 +52,7 @@ export const ClientBoard = () => {
return ( return (
<Box h="100%" pos="relative"> <Box h="100%" pos="relative">
<BoardBackgroundVideo /> <BoardBackgroundVideo />
<LoadingOverlay <Stack ref={ref} h="100%">
visible={!isReady}
transitionProps={{ duration: 500 }}
loaderProps={{ size: "lg" }}
h={fullHeightWithoutHeaderAndFooter}
/>
<Stack ref={ref} h="100%" style={{ visibility: isReady ? "visible" : "hidden" }}>
{fullWidthSortedSections.map((section) => {fullWidthSortedSections.map((section) =>
section.kind === "empty" ? ( section.kind === "empty" ? (
// Unique keys per layout to always reinitialize the gridstack // Unique keys per layout to always reinitialize the gridstack
@@ -38,6 +38,7 @@ export const createBoardContentPage = <TParams extends Record<string, unknown>>(
layout: createBoardLayout({ layout: createBoardLayout({
headerActions: <BoardContentHeaderActions />, headerActions: <BoardContentHeaderActions />,
getInitialBoardAsync: getInitialBoard, getInitialBoardAsync: getInitialBoard,
withTour: true,
}), }),
// eslint-disable-next-line no-restricted-syntax // eslint-disable-next-line no-restricted-syntax
page: async ({ params }: { params: Promise<TParams> }) => { page: async ({ params }: { params: Promise<TParams> }) => {
@@ -2,7 +2,8 @@
import { useCallback, useEffect } from "react"; import { useCallback, useEffect } from "react";
import { useRouter } from "next/navigation"; import { useRouter } from "next/navigation";
import { Group, Menu, ScrollArea } from "@mantine/core"; import { OnboardingTour } from "@gfazioli/mantine-onboarding-tour";
import { Box, Group, Menu, ScrollArea } from "@mantine/core";
import { useHotkeys } from "@mantine/hooks"; import { useHotkeys } from "@mantine/hooks";
import { import {
IconBox, IconBox,
@@ -53,9 +54,11 @@ export const BoardContentHeaderActions = () => {
<EditModeMenu /> <EditModeMenu />
<HeaderButton href={`/boards/${board.name}/settings`} data-onboarding-tour-id="board-settings"> <OnboardingTour.Target id="board-settings">
<IconSettings stroke={1.5} /> <HeaderButton href={`/boards/${board.name}/settings`}>
</HeaderButton> <IconSettings stroke={1.5} />
</HeaderButton>
</OnboardingTour.Target>
<SelectBoardsMenu /> <SelectBoardsMenu />
</> </>
@@ -173,9 +176,11 @@ const EditModeMenu = () => {
usePreventLeaveWithDirty(isEditMode); usePreventLeaveWithDirty(isEditMode);
return ( return (
<HeaderButton onClick={toggle} loading={isPending} data-onboarding-tour-id="board-edit-mode"> <OnboardingTour.Target id="board-edit-mode">
{isEditMode ? <IconPencilOff stroke={1.5} /> : <IconPencil stroke={1.5} />} <HeaderButton onClick={toggle} loading={isPending}>
</HeaderButton> {isEditMode ? <IconPencilOff stroke={1.5} /> : <IconPencil stroke={1.5} />}
</HeaderButton>
</OnboardingTour.Target>
); );
}; };
@@ -183,27 +188,31 @@ const SelectBoardsMenu = () => {
const { data: boards = [] } = clientApi.board.getAllBoards.useQuery(); const { data: boards = [] } = clientApi.board.getAllBoards.useQuery();
return ( return (
<Menu position="bottom-end" withArrow> <OnboardingTour.Target id="board-switcher">
<Menu.Target> <Box>
<HeaderButton w="auto" px={4} data-onboarding-tour-id="board-switcher"> <Menu position="bottom-end" withArrow>
<IconReplace stroke={1.5} /> <Menu.Target>
</HeaderButton> <HeaderButton w="auto" px={4}>
</Menu.Target> <IconReplace stroke={1.5} />
<Menu.Dropdown style={{ transform: "translate(-7px, 0)" }}> </HeaderButton>
<ScrollArea.Autosize mah={300}> </Menu.Target>
{boards.map((board) => ( <Menu.Dropdown style={{ transform: "translate(-7px, 0)" }}>
<Menu.Item <ScrollArea.Autosize mah={300}>
key={board.id} {boards.map((board) => (
component={Link} <Menu.Item
href={`/boards/${board.name}`} key={board.id}
leftSection={<IconLayoutBoard size={20} />} component={Link}
> href={`/boards/${board.name}`}
{board.name} leftSection={<IconLayoutBoard size={20} />}
</Menu.Item> >
))} {board.name}
</ScrollArea.Autosize> </Menu.Item>
</Menu.Dropdown> ))}
</Menu> </ScrollArea.Autosize>
</Menu.Dropdown>
</Menu>
</Box>
</OnboardingTour.Target>
); );
}; };
@@ -29,11 +29,13 @@ const BoardTourWrapper = ({ hasSession, children }: PropsWithChildren<{ hasSessi
interface CreateBoardLayoutProps<TParams extends Params> { interface CreateBoardLayoutProps<TParams extends Params> {
headerActions: JSX.Element; headerActions: JSX.Element;
getInitialBoardAsync: (params: TParams) => Promise<Board>; getInitialBoardAsync: (params: TParams) => Promise<Board>;
withTour?: boolean;
} }
export const createBoardLayout = <TParams extends Params>({ export const createBoardLayout = <TParams extends Params>({
headerActions, headerActions,
getInitialBoardAsync: getInitialBoard, getInitialBoardAsync: getInitialBoard,
withTour = false,
}: CreateBoardLayoutProps<TParams>) => { }: CreateBoardLayoutProps<TParams>) => {
const Layout = async ({ const Layout = async ({
params, params,
@@ -67,7 +69,7 @@ export const createBoardLayout = <TParams extends Params>({
<EditModeProvider> <EditModeProvider>
<BoardMantineProvider defaultColorScheme={colorScheme}> <BoardMantineProvider defaultColorScheme={colorScheme}>
<CustomCss /> <CustomCss />
<BoardTourWrapper hasSession={!!session}> <BoardTourWrapper hasSession={withTour && !!session}>
<ClientShell hasNavigation={false}> <ClientShell hasNavigation={false}>
<MainHeader <MainHeader
logo={<BoardLogoWithTitle size="md" hideTitleOnMobile />} logo={<BoardLogoWithTitle size="md" hideTitleOnMobile />}
@@ -3,26 +3,35 @@
import type { PropsWithChildren } from "react"; import type { PropsWithChildren } from "react";
import { useMemo } from "react"; import { useMemo } from "react";
import type { OnboardingTourStep } from "@gfazioli/mantine-onboarding-tour"; import type { OnboardingTourStep } from "@gfazioli/mantine-onboarding-tour";
import { OnboardingTour } from "@gfazioli/mantine-onboarding-tour";
import { clientApi } from "@homarr/api/client"; import { clientApi } from "@homarr/api/client";
import { useRequiredBoard } from "@homarr/boards/context"; import { useRequiredBoard } from "@homarr/boards/context";
import { createDocumentationLink } from "@homarr/definitions";
import { useScopedI18n } from "@homarr/translation/client"; import { useScopedI18n } from "@homarr/translation/client";
import { useBoardPermissions } from "~/components/board/permissions/client"; import { useBoardPermissions } from "~/components/board/permissions/client";
import { SkipHoldButton } from "./skip-hold-button"; import { TourShell } from "./tour-shell";
import { TourStepContent } from "./tour-step-content"; import { TourStepContent } from "./tour-step-content";
export const BoardTourProvider = ({ children }: PropsWithChildren) => { export const BoardTourProvider = ({ children }: PropsWithChildren) => {
const t = useScopedI18n("onboardingTour.board"); const t = useScopedI18n("onboardingTour.board");
const board = useRequiredBoard(); const board = useRequiredBoard();
const { hasChangeAccess } = useBoardPermissions(board); const { hasChangeAccess } = useBoardPermissions(board);
const utils = clientApi.useUtils();
const { data: tourStatus } = clientApi.user.getTourStatus.useQuery(); const { data: tourStatus } = clientApi.user.getTourStatus.useQuery();
const { mutate: completeTour } = clientApi.user.completeTour.useMutation(); const { mutate: completeTour } = clientApi.user.completeTour.useMutation({
onSuccess() {
void utils.user.getTourStatus.invalidate();
},
});
const started = tourStatus !== undefined && !tourStatus.completedBoardTour; const started = tourStatus !== undefined && !tourStatus.completedBoardTour;
const handleEnd = () => { const handleEnd = () => {
utils.user.getTourStatus.setData(undefined, {
completedManageTour: tourStatus?.completedManageTour ?? false,
completedBoardTour: true,
});
completeTour({ tour: "board" }); completeTour({ tour: "board" });
}; };
@@ -34,13 +43,12 @@ export const BoardTourProvider = ({ children }: PropsWithChildren) => {
content: ( content: (
<TourStepContent <TourStepContent
description={t("welcome.description")} description={t("welcome.description")}
docPath="/docs/getting-started/after-the-installation" documentationHref={createDocumentationLink(
docHash="#creating-your-first-board" "/docs/getting-started/after-the-installation",
"#creating-your-first-board",
)}
/> />
), ),
footer: (controller: { skipTour: () => void }) => (
<SkipHoldButton onSkip={() => controller.skipTour()} />
),
}, },
{ {
id: "board-edit-mode", id: "board-edit-mode",
@@ -49,8 +57,10 @@ export const BoardTourProvider = ({ children }: PropsWithChildren) => {
content: ( content: (
<TourStepContent <TourStepContent
description={t("editMode.description")} description={t("editMode.description")}
docPath="/docs/getting-started/after-the-installation" documentationHref={createDocumentationLink(
docHash="#arrange-and-organize-your-board" "/docs/getting-started/after-the-installation",
"#arrange-and-organize-your-board",
)}
/> />
), ),
}, },
@@ -59,39 +69,40 @@ export const BoardTourProvider = ({ children }: PropsWithChildren) => {
title: t("settings.title"), title: t("settings.title"),
requiresChangeAccess: true, requiresChangeAccess: true,
content: ( content: (
<TourStepContent description={t("settings.description")} docPath="/docs/management/boards" /> <TourStepContent
description={t("settings.description")}
documentationHref={createDocumentationLink("/docs/management/boards")}
/>
), ),
}, },
{ {
id: "board-switcher", id: "board-switcher",
title: t("switcher.title"), title: t("switcher.title"),
content: ( content: (
<TourStepContent description={t("switcher.description")} docPath="/docs/management/boards" /> <TourStepContent
description={t("switcher.description")}
documentationHref={createDocumentationLink("/docs/management/boards")}
/>
), ),
}, },
{ {
id: "board-user-menu", id: "board-user-menu",
title: t("userMenu.title"), title: t("userMenu.title"),
content: ( content: (
<TourStepContent description={t("userMenu.description")} docPath="/docs/management/users" /> <TourStepContent
description={t("userMenu.description")}
documentationHref={createDocumentationLink("/docs/management/users")}
/>
), ),
}, },
]; ];
return allSteps.filter( return allSteps.filter((step) => !step.requiresChangeAccess || hasChangeAccess) as OnboardingTourStep[];
(step) => !step.requiresChangeAccess || hasChangeAccess,
) as OnboardingTourStep[];
}, [hasChangeAccess, t]); }, [hasChangeAccess, t]);
return ( return (
<OnboardingTour <TourShell steps={steps} started={started} onEnd={handleEnd} position={{ base: "bottom", sm: "left" }}>
tour={steps}
started={started}
onOnboardingTourComplete={handleEnd}
onOnboardingTourSkip={handleEnd}
maw={420}
>
{children} {children}
</OnboardingTour> </TourShell>
); );
}; };