188 lines
9.4 KiB
TypeScript
188 lines
9.4 KiB
TypeScript
import { ActionFunction, LoaderFunctionArgs, MetaFunction } from "react-router";
|
|
import { Form, Link, useActionData, useLoaderData, useNavigation } from "react-router";
|
|
import { useTranslation } from "react-i18next";
|
|
import { FeatherArrowLeft, FeatherCheckCircle, FeatherInfo, FeatherRefreshCw } from "@subframe/core";
|
|
import { getTranslations } from "~/locale/i18next.server";
|
|
import type { Registration } from "@hivegrid/db/prisma-browser";
|
|
import { getRegistrationByToken } from "~/utils/db/registration.db.server";
|
|
import AuthService from "~/modules/users/services/AuthService";
|
|
import { useRootData } from "~/utils/data/useRootData";
|
|
import { AuthShell } from "~/components/auth/AuthShell";
|
|
import { Button } from "~/ui/components/Button";
|
|
import { Card } from "~/ui/components/Card";
|
|
import { IconWithBackground } from "~/ui/components/IconWithBackground";
|
|
import { LinkButton } from "~/ui/components/LinkButton";
|
|
import { Loader } from "~/ui/components/Loader";
|
|
import { Logo } from "~/ui/components/Logo";
|
|
import { TextInput } from "~/ui/components/TextInput";
|
|
|
|
// E-Mail-Bestaetigung -> nach Davids Subframe-"S02 Signup erfolgreich / Workspace wird vorbereitet".
|
|
//
|
|
// Davids S02 ist input-los und auto-provisioniert. Die bestehende Backend-Kette verlangt aber, dass der
|
|
// Nutzer hier ein Passwort setzt (das Registration-Modell hat KEINE Passwort-Spalte, das Passwort wird also
|
|
// erst beim Verify gesammelt) und provisioniert SYNCHRON in der Action (kein Job/Polling). Deshalb:
|
|
// - vor dem Absenden: kompakte Abschluss-Card (Passwort -> "Workspace einrichten"); restliche Stammdaten
|
|
// kommen aus der Registration als hidden-Felder (kein erneutes Tippen).
|
|
// - waehrend des Absendens: Davids S02 "Workspace wird vorbereitet" (Checkliste + Loader) als der
|
|
// Provisionierungs-Moment; bei Erfolg leitet die Action auf das Dashboard weiter.
|
|
// [Backend-Flags] Davids reines Auto-S02 braucht: Passwort-Spalte auf Registration (Erfassung schon in S01),
|
|
// asynchrone Provisionierung + Polling/Live-Checkliste. Davids "Erneut versuchen"/"Support kontaktieren"
|
|
// sind hier weggelassen (synchroner Flow, keine echten Ziele).
|
|
|
|
export const meta: MetaFunction<typeof loader> = ({ data }) => [{ title: data?.title }];
|
|
|
|
type LoaderData = {
|
|
title: string;
|
|
registration: Registration | null;
|
|
};
|
|
export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
|
const { t } = await getTranslations(request);
|
|
const registration = await getRegistrationByToken(params.id ?? "");
|
|
const data: LoaderData = {
|
|
title: `${t("account.verify.title")} | ${process.env.APP_NAME}`,
|
|
registration,
|
|
};
|
|
return data;
|
|
};
|
|
|
|
type ActionData = {
|
|
error?: string;
|
|
fieldErrors?: {
|
|
email: string | undefined;
|
|
password: string | undefined;
|
|
};
|
|
fields?: {
|
|
email: string;
|
|
password: string;
|
|
company: string | undefined;
|
|
firstName: string | undefined;
|
|
lastName: string | undefined;
|
|
slug: string | undefined;
|
|
};
|
|
};
|
|
|
|
export const action: ActionFunction = async ({ request, params }) => {
|
|
return await AuthService.verifyFromRequest({ request, params });
|
|
};
|
|
|
|
export default function RegisterRoute() {
|
|
const data = useLoaderData<LoaderData>();
|
|
const actionData = useActionData<ActionData>();
|
|
const { t } = useTranslation();
|
|
const { csrf } = useRootData();
|
|
const navigation = useNavigation();
|
|
const isSubmitting = navigation.state !== "idle";
|
|
const registration = data.registration;
|
|
const canComplete = Boolean(registration && !registration.createdTenantId);
|
|
|
|
// S02 "Workspace wird vorbereitet" — Provisionierungs-Moment waehrend des Absendens.
|
|
if (canComplete && isSubmitting) {
|
|
return (
|
|
<div
|
|
className="flex min-h-screen w-full flex-col items-center justify-center gap-8 bg-surface-neutral-primary px-4 py-12 mobile:gap-6 mobile:py-6"
|
|
data-ui-id="ui.auth.verify.preparing"
|
|
>
|
|
<Logo size="64" />
|
|
<Card size="medium" variant="default" className="max-w-[448px]">
|
|
<div className="flex w-full flex-col items-center gap-6">
|
|
<IconWithBackground size="large" round={true} icon={<FeatherRefreshCw />} />
|
|
<div className="flex w-full flex-col items-center gap-2">
|
|
<span className="text-heading- font-heading- text-text-neutral-primary text-center">{t("account.verify.preparingTitle")}</span>
|
|
<span className="w-full text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary text-center">{t("account.verify.preparingBody")}</span>
|
|
</div>
|
|
</div>
|
|
<div className="flex w-full flex-col items-start gap-3 rounded-md border border-solid border-border-default bg-surface-neutral-primary px-4 py-4">
|
|
<div className="flex w-full items-center gap-3">
|
|
<FeatherCheckCircle className="text-body-default-regular-150 font-body-default-regular-150 text-text-feedback-positive" />
|
|
<span className="grow shrink-0 basis-0 text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-secondary">{t("account.verify.stepAccountCreated")}</span>
|
|
</div>
|
|
<div className="flex w-full items-center gap-3">
|
|
<FeatherCheckCircle className="text-body-default-regular-150 font-body-default-regular-150 text-text-feedback-positive" />
|
|
<span className="grow shrink-0 basis-0 text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-secondary">{t("account.verify.stepEmailConfirmed")}</span>
|
|
</div>
|
|
<div className="flex w-full items-center gap-3">
|
|
<Loader className="text-text-neutral-tertiary" size="small" />
|
|
<span className="grow shrink-0 basis-0 text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-primary">{t("account.verify.stepWorkspaceConfiguring")}</span>
|
|
</div>
|
|
</div>
|
|
<div className="flex w-full items-center justify-center gap-2">
|
|
<FeatherInfo className="text-body-small-regular-150 font-body-small-regular-150 text-icon-neutral-tertiary" />
|
|
<span className="text-body-extra-small-regular-150 font-body-extra-small-regular-150 text-text-neutral-tertiary text-center">{t("account.verify.autoRedirectNote")}</span>
|
|
</div>
|
|
</Card>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
// Abschluss-Card: Passwort setzen -> Workspace einrichten (Backend sammelt das Passwort erst hier).
|
|
if (canComplete) {
|
|
return (
|
|
<AuthShell
|
|
title={t("account.verify.title")}
|
|
subtitle={t("account.verify.completeSubtitle")}
|
|
cardSize="medium"
|
|
cardClassName="max-w-[448px]"
|
|
logoIconOnly={false}
|
|
dataUiId="ui.auth.verify.page"
|
|
>
|
|
<Form method="post" noValidate className="flex w-full flex-col gap-4" data-ui-id="ui.auth.verify.form">
|
|
<input type="hidden" name="csrf" value={csrf} readOnly />
|
|
<input type="hidden" name="email" value={registration?.email ?? ""} readOnly />
|
|
<input type="hidden" name="company" value={registration?.company ?? ""} readOnly />
|
|
<input type="hidden" name="first-name" value={registration?.firstName ?? ""} readOnly />
|
|
<input type="hidden" name="last-name" value={registration?.lastName ?? ""} readOnly />
|
|
|
|
<div className="flex w-full flex-col items-center gap-2 rounded-md border border-solid border-border-default bg-surface-neutral-primary px-4 py-3">
|
|
<span className="text-body-extra-small-medium-150 font-body-extra-small-medium-150 text-text-neutral-tertiary">{t("account.verify.linkSentTo")}</span>
|
|
<span className="w-full text-body-default-semibold-0 font-body-default-semibold-0 text-text-neutral-primary text-center">{registration?.email}</span>
|
|
</div>
|
|
|
|
<TextInput
|
|
className="h-auto w-full flex-none"
|
|
fillContainer
|
|
showLabel
|
|
label={t("account.shared.password")}
|
|
helpText={actionData?.fieldErrors?.password ?? ""}
|
|
error={Boolean(actionData?.fieldErrors?.password)}
|
|
type="password"
|
|
>
|
|
<TextInput.Input
|
|
name="password"
|
|
type="password"
|
|
required
|
|
autoComplete="new-password"
|
|
autoFocus
|
|
placeholder={t("account.register.passwordChoosePlaceholder")}
|
|
disabled={isSubmitting}
|
|
data-ui-id="ui.auth.verify.password"
|
|
/>
|
|
</TextInput>
|
|
|
|
<Button type="submit" className="h-9 w-full flex-none" loading={isSubmitting} disabled={isSubmitting} data-ui-id="ui.auth.verify.submit">
|
|
{t("account.verify.setupWorkspace")}
|
|
</Button>
|
|
|
|
{actionData?.error && navigation.state === "idle" ? (
|
|
<p className="text-center text-body-small-regular-0 font-body-small-regular-0 text-text-feedback-negative" role="alert">
|
|
{actionData.error}
|
|
</p>
|
|
) : null}
|
|
</Form>
|
|
</AuthShell>
|
|
);
|
|
}
|
|
|
|
// Ungueltiger / bereits eingeloester Link.
|
|
return (
|
|
<AuthShell title={t("account.verify.title")} subtitle={t("account.verify.invalidLink")} cardSize="medium" cardClassName="max-w-[448px]" logoIconOnly={false} dataUiId="ui.auth.verify.invalid">
|
|
<div className="flex w-full items-center justify-center gap-1" data-ui-id="ui.auth.verify.toLogin">
|
|
<Link to="/login" className="no-underline">
|
|
<LinkButton size="small" icon={<FeatherArrowLeft />}>
|
|
{t("account.verify.toLogin")}
|
|
</LinkButton>
|
|
</Link>
|
|
</div>
|
|
</AuthShell>
|
|
);
|
|
}
|