import { useMemo, useState } from "react"; import { Form, Link, useNavigate, useNavigation, useSearchParams } from "react-router"; import { useTranslation } from "react-i18next"; import { FeatherArrowLeft, FeatherBuilding, FeatherMail, FeatherMailCheck, FeatherPencil, FeatherRotateCw } from "@subframe/core"; import { useRootData } from "~/utils/data/useRootData"; import { AuthShell } from "~/components/auth/AuthShell"; import { Alert } from "~/ui/components/Alert"; import { Button } from "~/ui/components/Button"; import { Card } from "~/ui/components/Card"; import { Checkbox } from "~/ui/components/Checkbox"; import { IconWithBackground } from "~/ui/components/IconWithBackground"; import { LinkButton } from "~/ui/components/LinkButton"; import { Logo } from "~/ui/components/Logo"; import { Progress } from "~/ui/components/Progress"; import { TextInput } from "~/ui/components/TextInput"; import Captcha from "~/components/captcha/Captcha"; import { getPasswordChecks, type PasswordPolicy } from "~/modules/users/components/RegisterForm"; // Signup-Screens nach Davids Subframe-"WF-P2"-Designs: // S01 "Signup" -> Form (Logo + Card "Konto erstellen": E-Mail, Passwort+Staerke, Vor-/Nachname, // Firmenname, Sicherheitspruefung/Captcha, 2 Consents, "Konto erstellen"). // S03 "E-Mail bestaetigen" -> verificationEmailSent-Status (Logo + Card: Mail-Check-Icon, Titel, gesendete // Adresse, Hinweis-Alert, "E-Mail erneut senden" / "E-Mail aendern" / "Zur Anmeldung"). // Voll an die bestehende Register-Action verdrahtet (Feld-Namen, Password-Policy, Captcha, Lead-Felder). // // Token-genaue Uebernahme + bewusste Abweichungen (vom Backend erzwungen, nicht erfunden): // - Davids S01 zeigt das Passwort IMMER. Bei aktiver E-Mail-Verifizierung sammelt das Backend das Passwort // aber erst beim Verify (Registration-Modell hat KEINE Passwort-Spalte) -> showPasswordInput bleibt // `!requireEmailVerification` (Default ist OFF -> Passwort sichtbar = Davids Optik). [Backend-Flag] // - Davids S01 hat KEIN Telefon-/USt-IdNr-Feld -> entfernt (wurden ohnehin nie persistiert). // - Davids S01 hat 2 Consents (AGB, Datenschutz); der separate AVV/DPA-Consent wurde gestrichen. [Flag] // - Davids PasswordStrengthIndicator existiert nicht in ~/ui -> bestehender Progress-Balken beibehalten. // - Davids statische Captcha-Box ("Ich bin kein Roboter") -> echtes mCaptcha-Widget in Davids Box-Optik, // nur sichtbar wenn Captcha aktiv ist. // - S03 "E-Mail erneut senden": echtes Resend braucht `recreateToken:true` (registerFromRequest nutzt // `false` -> versendet bei bestehender Registration NICHTS). Button postet `intent=resendVerification`; // das Backend muss diesen Intent noch auf createRegistrationForm({recreateToken:true}) mappen. [Backend-Flag] type RegisterData = { company?: string; firstName?: string; lastName?: string; email?: string; slug?: string }; export default function RegisterScreen({ requireCaptcha = false, error, verificationEmailSent, data = {}, leadConversion, passwordPolicy, }: { requireCaptcha?: boolean; error?: string; verificationEmailSent?: boolean; data?: RegisterData; leadConversion?: { leadId: string; token: string; planId?: string | null }; passwordPolicy?: PasswordPolicy; }) { const { t } = useTranslation(); const { appConfiguration, csrf } = useRootData(); const navigation = useNavigation(); const navigate = useNavigate(); const [searchParams] = useSearchParams(); const isSubmitting = navigation.state !== "idle"; const redirect = searchParams.get("redirect") ?? ""; // Controlled, damit Werte ueber den Wechsel Form <-> "E-Mail bestaetigt"-Status erhalten bleiben // (E-Mail-Anzeige in S03, Resend ohne erneutes Tippen). const [email, setEmail] = useState(data.email ?? ""); const [password, setPassword] = useState(""); const [company, setCompany] = useState(data.company ?? ""); const [firstName, setFirstName] = useState(data.firstName ?? ""); const [lastName, setLastName] = useState(data.lastName ?? ""); const [acceptTerms, setAcceptTerms] = useState(false); const [acceptPrivacy, setAcceptPrivacy] = useState(false); const allConsents = acceptTerms && acceptPrivacy; const requireEmailVerification = appConfiguration.auth.requireEmailVerification; const showPasswordInput = !requireEmailVerification; const captchaEnabled = requireCaptcha && appConfiguration.auth.captcha.enabled; const checks = useMemo(() => getPasswordChecks(password, passwordPolicy), [password, passwordPolicy]); const strength = checks.length === 0 ? 0 : Math.round((checks.filter((c) => c.valid).length / checks.length) * 100); // S03 "E-Mail bestaetigen" — Davids Status-Card. if (verificationEmailSent) { return (