232 lines
10 KiB
TypeScript
232 lines
10 KiB
TypeScript
import { useTranslation } from "react-i18next";
|
|
import {
|
|
FeatherArrowRight,
|
|
FeatherBriefcase,
|
|
FeatherBuilding2,
|
|
FeatherCheckCircle,
|
|
FeatherContact,
|
|
FeatherCreditCard,
|
|
FeatherUser,
|
|
FeatherUsers,
|
|
} from "@subframe/core";
|
|
import type { FirstStepsChecklistItemVM, WelcomeSetupVM } from "@hivegrid/view-models";
|
|
|
|
import Logo from "~/components/brand/Logo";
|
|
import { Alert } from "~/ui/components/Alert";
|
|
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
|
|
import { Button } from "~/ui/components/Button";
|
|
import { Card } from "~/ui/components/Card";
|
|
import { EmptyState } from "~/ui/components/EmptyState";
|
|
import { IconWithBackground } from "~/ui/components/IconWithBackground";
|
|
import { Progress } from "~/ui/components/Progress";
|
|
import { StepperHorizontal } from "~/ui/components/StepperHorizontal";
|
|
|
|
export type WelcomeSetupPageProps = {
|
|
readonly vm: WelcomeSetupVM;
|
|
readonly homeHref: string;
|
|
readonly actions: {
|
|
readonly onOpen: (href: string) => void;
|
|
readonly onDashboard: (href: string) => void;
|
|
readonly onRetry?: () => void;
|
|
};
|
|
};
|
|
|
|
const taskContent: Record<string, { descriptionKey: string; actionKey: string; icon: React.ReactNode }> = {
|
|
profile: {
|
|
descriptionKey: "onboarding.welcome.tasks.profile.description",
|
|
actionKey: "onboarding.welcome.tasks.profile.action",
|
|
icon: <FeatherUser />,
|
|
},
|
|
team: {
|
|
descriptionKey: "onboarding.welcome.tasks.team.description",
|
|
actionKey: "onboarding.welcome.tasks.team.action",
|
|
icon: <FeatherUsers />,
|
|
},
|
|
contacts: {
|
|
descriptionKey: "onboarding.welcome.tasks.contacts.description",
|
|
actionKey: "onboarding.welcome.tasks.contacts.action",
|
|
icon: <FeatherContact />,
|
|
},
|
|
projects: {
|
|
descriptionKey: "onboarding.welcome.tasks.projects.description",
|
|
actionKey: "onboarding.welcome.tasks.projects.action",
|
|
icon: <FeatherBriefcase />,
|
|
},
|
|
billing: {
|
|
descriptionKey: "onboarding.welcome.tasks.billing.description",
|
|
actionKey: "onboarding.welcome.tasks.billing.action",
|
|
icon: <FeatherCreditCard />,
|
|
},
|
|
};
|
|
|
|
function contentFor(item: FirstStepsChecklistItemVM) {
|
|
return taskContent[item.block] ?? {
|
|
descriptionKey: "onboarding.welcome.tasks.default.description",
|
|
actionKey: "onboarding.welcome.tasks.default.action",
|
|
icon: <FeatherCheckCircle />,
|
|
};
|
|
}
|
|
|
|
export function WelcomeSetupPage({ vm, homeHref, actions }: WelcomeSetupPageProps) {
|
|
const { t } = useTranslation();
|
|
|
|
if (vm.status === "loading" || vm.status === "idle") {
|
|
return (
|
|
<main className="flex min-h-screen items-center justify-center bg-surface-neutral-secondary p-6" data-ui-id="ui.onboarding.welcome.loading">
|
|
<Alert variant="neutral" title={t("onboarding.welcome.loading.title")} description={t("onboarding.welcome.loading.body")} />
|
|
</main>
|
|
);
|
|
}
|
|
|
|
if (vm.status === "error") {
|
|
return (
|
|
<main className="flex min-h-screen items-center justify-center bg-surface-neutral-secondary p-6" data-ui-id="ui.onboarding.welcome.error">
|
|
<EmptyState
|
|
outlined
|
|
variant="error"
|
|
title={
|
|
<span role="heading" aria-level={1}>
|
|
{t("onboarding.welcome.error.title")}
|
|
</span>
|
|
}
|
|
body={t(vm.error.messageKey)}
|
|
action={
|
|
actions.onRetry ? (
|
|
<Button variant="tertiary" onClick={actions.onRetry}>
|
|
{t("shared.retry")}
|
|
</Button>
|
|
) : undefined
|
|
}
|
|
/>
|
|
</main>
|
|
);
|
|
}
|
|
|
|
if (vm.status === "empty" || !vm.data) {
|
|
return (
|
|
<main className="flex min-h-screen items-center justify-center bg-surface-neutral-secondary p-6" data-ui-id="ui.onboarding.welcome.empty">
|
|
<EmptyState
|
|
outlined
|
|
title={
|
|
<span role="heading" aria-level={1}>
|
|
{t("onboarding.welcome.empty.title")}
|
|
</span>
|
|
}
|
|
body={t("onboarding.welcome.empty.body")}
|
|
action={<Button onClick={() => actions.onDashboard(homeHref)}>{t("onboarding.welcome.dashboardAction")}</Button>}
|
|
/>
|
|
</main>
|
|
);
|
|
}
|
|
|
|
const { checklist } = vm.data;
|
|
const greeting = vm.data.firstName ? t("onboarding.welcome.titleNamed", { firstName: vm.data.firstName }) : t("onboarding.welcome.title");
|
|
|
|
return (
|
|
<main className="min-h-screen bg-surface-neutral-secondary px-4 py-8 sm:px-6 sm:py-10" data-ui-id="ui.onboarding.welcome.page">
|
|
<div className="mx-auto flex w-full max-w-6xl flex-col gap-8">
|
|
<div className="flex justify-center">
|
|
<Logo size="h-12" />
|
|
</div>
|
|
|
|
<StepperHorizontal aria-label={t("onboarding.welcome.stepper.label")}>
|
|
<StepperHorizontal.Step variant="completed" firstStep stepNumber="1" label={t("onboarding.welcome.stepper.account")} />
|
|
<StepperHorizontal.Step variant="completed" stepNumber="2" label={t("onboarding.welcome.stepper.payment")} />
|
|
<StepperHorizontal.Step variant="active" lastStep stepNumber="3" label={t("onboarding.welcome.stepper.workspace")} />
|
|
</StepperHorizontal>
|
|
|
|
<div className="flex flex-col items-center gap-3 text-center">
|
|
<BadgeFeedback farbe="subtle-positive">{t("onboarding.welcome.activeBadge")}</BadgeFeedback>
|
|
<h1 className="text-heading-1 font-heading-1 text-text-neutral-primary">{greeting}</h1>
|
|
<p className="max-w-2xl text-body-large-0 font-body-large-0 text-text-neutral-secondary">
|
|
{t("onboarding.welcome.description", { workspaceName: vm.data.workspaceName })}
|
|
</p>
|
|
</div>
|
|
|
|
<div className="grid items-start gap-6 lg:grid-cols-[minmax(0,1fr)_320px]">
|
|
<Card size="large" className="gap-6" data-ui-id="ui.onboarding.welcome.checklist">
|
|
<div className="flex w-full flex-wrap items-start justify-between gap-4">
|
|
<div className="flex items-start gap-3">
|
|
<IconWithBackground variant={checklist.isComplete ? "success" : "information"} size="large" icon={<FeatherCheckCircle />} />
|
|
<div className="flex flex-col gap-1">
|
|
<h2 className="text-heading-3 font-heading-3 text-text-neutral-primary">{t("onboarding.welcome.setupTitle")}</h2>
|
|
<p className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
|
{t("onboarding.welcome.setupDescription")}
|
|
</p>
|
|
</div>
|
|
</div>
|
|
<BadgeFeedback farbe={checklist.isComplete ? "subtle-positive" : "subtle-information"}>
|
|
{t("onboarding.firstSteps.progressBadge", { completed: checklist.completedCount, total: checklist.totalCount })}
|
|
</BadgeFeedback>
|
|
</div>
|
|
|
|
<Progress
|
|
className="w-full"
|
|
value={checklist.percentComplete}
|
|
state={checklist.isComplete ? "success" : "uploading"}
|
|
hideLabel
|
|
aria-label={t("onboarding.firstSteps.progressAria", { percent: checklist.percentComplete })}
|
|
/>
|
|
|
|
<div className="flex w-full flex-col gap-3">
|
|
{checklist.items.map((item) => {
|
|
const content = contentFor(item);
|
|
const isNext = vm.data?.nextItem?.id === item.id;
|
|
return (
|
|
<div
|
|
key={item.id}
|
|
className="flex w-full flex-wrap items-center justify-between gap-4 rounded-md border border-solid border-border-default bg-surface-neutral-primary px-4 py-4"
|
|
data-row-id={item.id}
|
|
>
|
|
<div className="flex min-w-0 items-start gap-3">
|
|
<IconWithBackground variant={item.completed ? "success" : isNext ? "information" : "neutral"} icon={item.completed ? <FeatherCheckCircle /> : content.icon} />
|
|
<div className="flex min-w-0 flex-col gap-1">
|
|
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{t(item.titleKey)}</span>
|
|
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-secondary">
|
|
{t(content.descriptionKey)}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
{item.completed ? (
|
|
<BadgeFeedback farbe="subtle-positive" size="small">
|
|
{t("onboarding.firstSteps.completed")}
|
|
</BadgeFeedback>
|
|
) : (
|
|
<Button
|
|
className="mobile:w-full"
|
|
variant={isNext ? "primary" : "tertiary"}
|
|
size="small"
|
|
iconRight={<FeatherArrowRight />}
|
|
onClick={() => actions.onOpen(item.href)}
|
|
data-ui-id={`ui.onboarding.welcome.open.${item.block}`}
|
|
>
|
|
{t(content.actionKey)}
|
|
</Button>
|
|
)}
|
|
</div>
|
|
);
|
|
})}
|
|
</div>
|
|
</Card>
|
|
|
|
<div className="flex flex-col gap-4">
|
|
<Card variant="positive" size="large" data-ui-id="ui.onboarding.welcome.workspaceActive">
|
|
<IconWithBackground variant="success" size="large" icon={<FeatherBuilding2 />} />
|
|
<div className="flex flex-col gap-2">
|
|
<h2 className="text-heading-3 font-heading-3 text-text-neutral-primary">{t("onboarding.welcome.workspaceActive.title")}</h2>
|
|
<p className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
|
{t("onboarding.welcome.workspaceActive.body", { workspaceName: vm.data.workspaceName })}
|
|
</p>
|
|
</div>
|
|
<Button className="w-full" variant="secondary" iconRight={<FeatherArrowRight />} onClick={() => actions.onDashboard(vm.data!.dashboardHref)}>
|
|
{t("onboarding.welcome.dashboardAction")}
|
|
</Button>
|
|
</Card>
|
|
<Alert notDismissible variant="information" title={t("onboarding.welcome.resume.title")} description={t("onboarding.welcome.resume.body")} />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
);
|
|
}
|