93 lines
2.9 KiB
TypeScript
93 lines
2.9 KiB
TypeScript
import Link from "next/link";
|
|
import { redirect } from "next/navigation";
|
|
import { headers } from "next/headers";
|
|
|
|
import { env } from "@/config/env";
|
|
import { registerEditorial } from "@/modules/auth/auth";
|
|
import {
|
|
CURRENT_TERMS_VERSION,
|
|
RegistrationValidationError,
|
|
} from "@/modules/auth/registration";
|
|
import {
|
|
RegistrationForm,
|
|
type RegistrationFormState,
|
|
} from "@/modules/auth/public-forms";
|
|
import { RateLimitExceededError } from "@/modules/security/rate-limit-guard";
|
|
|
|
export default function RegistrationPage() {
|
|
return (
|
|
<main className="public-account-page">
|
|
<header className="masthead">
|
|
<Link className="wordmark" href="/">
|
|
Leon Tonhäuser
|
|
</Link>
|
|
<span className="section-label">Redaktionsportal</span>
|
|
</header>
|
|
<section className="account-panel account-panel-wide" aria-labelledby="registration-title">
|
|
<p className="eyebrow">B2B-Zugang</p>
|
|
<h1 id="registration-title">Redaktion registrieren</h1>
|
|
<p className="lede">
|
|
Das Redaktionsportal steht ausschließlich Unternehmen und Redaktionen zur Verfügung.
|
|
</p>
|
|
<RegistrationForm
|
|
action={registerAction}
|
|
legalUrls={{
|
|
imprint: env.LEGAL_IMPRINT_URL,
|
|
privacy: env.LEGAL_PRIVACY_URL,
|
|
terms: env.LEGAL_TERMS_URL,
|
|
}}
|
|
/>
|
|
</section>
|
|
</main>
|
|
);
|
|
}
|
|
|
|
async function registerAction(
|
|
_state: RegistrationFormState,
|
|
formData: FormData,
|
|
): Promise<RegistrationFormState> {
|
|
"use server";
|
|
|
|
try {
|
|
await registerEditorial({
|
|
companyName: text(formData, "companyName"),
|
|
contactName: text(formData, "contactName"),
|
|
email: text(formData, "email"),
|
|
password: text(formData, "password"),
|
|
billingAddress: {
|
|
addressLine1: text(formData, "addressLine1"),
|
|
addressLine2: text(formData, "addressLine2") || undefined,
|
|
postalCode: text(formData, "postalCode"),
|
|
city: text(formData, "city"),
|
|
countryCode: text(formData, "countryCode"),
|
|
},
|
|
actsForBusiness: formData.has("actsForBusiness"),
|
|
termsVersion: formData.has("termsAccepted") ? CURRENT_TERMS_VERSION : "",
|
|
privacyAcknowledged: formData.has("privacyAcknowledged"),
|
|
}, await headers());
|
|
} catch (error) {
|
|
if (error instanceof RateLimitExceededError) {
|
|
return {
|
|
errors: {
|
|
form: "Es wurden zu viele Registrierungsversuche gesendet. Bitte versuchen Sie es später erneut.",
|
|
},
|
|
};
|
|
}
|
|
if (error instanceof RegistrationValidationError) {
|
|
return { errors: { [error.field]: error.message } };
|
|
}
|
|
return {
|
|
errors: {
|
|
form: "Die Registrierung konnte nicht abgeschlossen werden. Bitte versuchen Sie es später erneut.",
|
|
},
|
|
};
|
|
}
|
|
|
|
redirect("/registrieren/bestaetigt");
|
|
}
|
|
|
|
function text(formData: FormData, name: string): string {
|
|
const value = formData.get(name);
|
|
return typeof value === "string" ? value : "";
|
|
}
|