Compare commits
19 Commits
ezpz
...
17aa8956a7
| Author | SHA1 | Date | |
|---|---|---|---|
|
17aa8956a7
|
|||
|
5e5efcaf6f
|
|||
|
0c8e827cda
|
|||
|
42156209d8
|
|||
|
569ee4ec40
|
|||
|
29250f8694
|
|||
|
f214660ab2
|
|||
|
ba0804db30
|
|||
|
d25f4aa813
|
|||
|
8a6d3035cb
|
|||
|
0a849bd9c5
|
|||
|
17c6315dad
|
|||
|
e59a588a9d
|
|||
|
dfc8ace186
|
|||
|
439bbc5545
|
|||
|
89043c60a3
|
|||
|
7eabe88d30
|
|||
|
d180a33d6e
|
|||
|
cf47f25a4d
|
@@ -30,6 +30,7 @@
|
||||
"@tanstack/react-start": "^1.141.1",
|
||||
"@tanstack/router-plugin": "^1.141.1",
|
||||
"better-auth": "catalog:",
|
||||
"canvas-confetti": "^1.9.4",
|
||||
"class-variance-authority": "^0.7.1",
|
||||
"clsx": "^2.1.1",
|
||||
"dotenv": "catalog:",
|
||||
@@ -56,6 +57,7 @@
|
||||
"@tanstack/react-router-devtools": "^1.141.1",
|
||||
"@testing-library/dom": "^10.4.0",
|
||||
"@testing-library/react": "^16.2.0",
|
||||
"@types/canvas-confetti": "^1.9.0",
|
||||
"@types/qrcode": "^1.5.6",
|
||||
"@types/react": "19.2.7",
|
||||
"@types/react-dom": "19.2.3",
|
||||
|
||||
260
apps/web/src/components/homepage/CountdownBanner.tsx
Normal file
260
apps/web/src/components/homepage/CountdownBanner.tsx
Normal file
@@ -0,0 +1,260 @@
|
||||
import { useState } from "react";
|
||||
import { REGISTRATION_OPENS_AT } from "@/lib/opening";
|
||||
import { useRegistrationOpen } from "@/lib/useRegistrationOpen";
|
||||
import { client } from "@/utils/orpc";
|
||||
|
||||
function pad(n: number): string {
|
||||
return String(n).padStart(2, "0");
|
||||
}
|
||||
|
||||
interface UnitBoxProps {
|
||||
value: string;
|
||||
label: string;
|
||||
}
|
||||
|
||||
function UnitBox({ value, label }: UnitBoxProps) {
|
||||
return (
|
||||
<div className="flex flex-col items-center gap-1">
|
||||
<div className="flex w-14 items-center justify-center rounded-sm bg-white/10 px-2 py-2 font-['Intro',sans-serif] text-3xl text-white tabular-nums sm:w-auto sm:px-4 sm:py-3 sm:text-5xl md:text-6xl lg:text-7xl">
|
||||
{value}
|
||||
</div>
|
||||
<span className="font-['Intro',sans-serif] text-[9px] text-white/50 uppercase tracking-widest sm:text-xs">
|
||||
{label}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// Reminder opt-in form — sits at the very bottom of the banner
|
||||
function ReminderForm() {
|
||||
const [email, setEmail] = useState("");
|
||||
const [status, setStatus] = useState<
|
||||
"idle" | "loading" | "subscribed" | "already_subscribed" | "error"
|
||||
>("idle");
|
||||
const [errorMessage, setErrorMessage] = useState("");
|
||||
|
||||
async function handleSubmit(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
if (!email || status === "loading") return;
|
||||
|
||||
setStatus("loading");
|
||||
try {
|
||||
const result = await client.subscribeReminder({ email });
|
||||
if (!result.ok && result.reason === "already_open") {
|
||||
setStatus("idle");
|
||||
return;
|
||||
}
|
||||
setStatus("subscribed");
|
||||
} catch (err) {
|
||||
setErrorMessage(err instanceof Error ? err.message : "Er ging iets mis.");
|
||||
setStatus("error");
|
||||
}
|
||||
}
|
||||
|
||||
const reminderTime = REGISTRATION_OPENS_AT.toLocaleTimeString("nl-BE", {
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
});
|
||||
|
||||
return (
|
||||
<div
|
||||
className="w-full"
|
||||
style={{
|
||||
animation: "reminderFadeIn 0.6s ease both",
|
||||
animationDelay: "0.3s",
|
||||
}}
|
||||
>
|
||||
<style>{`
|
||||
@keyframes reminderFadeIn {
|
||||
from { opacity: 0; transform: translateY(8px); }
|
||||
to { opacity: 1; transform: translateY(0); }
|
||||
}
|
||||
@keyframes reminderCheck {
|
||||
from { opacity: 0; transform: scale(0.7); }
|
||||
to { opacity: 1; transform: scale(1); }
|
||||
}
|
||||
`}</style>
|
||||
|
||||
{/* Hairline divider */}
|
||||
<div
|
||||
className="mx-auto mb-6 h-px w-24"
|
||||
style={{
|
||||
background:
|
||||
"linear-gradient(to right, transparent, rgba(255,255,255,0.15), transparent)",
|
||||
}}
|
||||
/>
|
||||
|
||||
{status === "subscribed" || status === "already_subscribed" ? (
|
||||
<div
|
||||
className="flex flex-col items-center gap-2"
|
||||
style={{
|
||||
animation: "reminderCheck 0.4s cubic-bezier(0.34,1.56,0.64,1) both",
|
||||
}}
|
||||
>
|
||||
{/* Checkmark glyph */}
|
||||
<div
|
||||
className="flex h-8 w-8 items-center justify-center rounded-full"
|
||||
style={{
|
||||
background: "rgba(255,255,255,0.12)",
|
||||
border: "1px solid rgba(255,255,255,0.2)",
|
||||
}}
|
||||
>
|
||||
<svg
|
||||
width="14"
|
||||
height="14"
|
||||
viewBox="0 0 14 14"
|
||||
fill="none"
|
||||
aria-label="Vinkje"
|
||||
role="img"
|
||||
>
|
||||
<path
|
||||
d="M2.5 7L5.5 10L11.5 4"
|
||||
stroke="white"
|
||||
strokeWidth="1.5"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
/>
|
||||
</svg>
|
||||
</div>
|
||||
<p
|
||||
className="font-['Intro',sans-serif] text-sm tracking-wide"
|
||||
style={{ color: "rgba(255,255,255,0.65)" }}
|
||||
>
|
||||
Herinnering ingepland voor {reminderTime}
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex flex-col items-center gap-3">
|
||||
<p
|
||||
className="font-['Intro',sans-serif] text-xs uppercase tracking-widest"
|
||||
style={{ color: "rgba(255,255,255,0.35)", letterSpacing: "0.14em" }}
|
||||
>
|
||||
Herinnering ontvangen?
|
||||
</p>
|
||||
|
||||
{/* Fused pill input + button */}
|
||||
<form
|
||||
onSubmit={handleSubmit}
|
||||
className="flex w-full max-w-xs overflow-hidden"
|
||||
style={{
|
||||
borderRadius: "3px",
|
||||
border: "1px solid rgba(255,255,255,0.18)",
|
||||
background: "rgba(255,255,255,0.07)",
|
||||
backdropFilter: "blur(6px)",
|
||||
}}
|
||||
>
|
||||
<input
|
||||
type="email"
|
||||
required
|
||||
placeholder="jouw@email.be"
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
disabled={status === "loading"}
|
||||
className="min-w-0 flex-1 bg-transparent px-4 py-2.5 text-sm text-white outline-none disabled:opacity-50"
|
||||
style={{
|
||||
fontFamily: "'Intro', sans-serif",
|
||||
fontSize: "0.8rem",
|
||||
letterSpacing: "0.02em",
|
||||
}}
|
||||
/>
|
||||
{/* Vertical separator */}
|
||||
<div
|
||||
style={{
|
||||
width: "1px",
|
||||
background: "rgba(255,255,255,0.15)",
|
||||
flexShrink: 0,
|
||||
}}
|
||||
/>
|
||||
<button
|
||||
type="submit"
|
||||
disabled={status === "loading" || !email}
|
||||
className="shrink-0 px-4 py-2.5 font-semibold text-xs transition-all disabled:opacity-40"
|
||||
style={{
|
||||
fontFamily: "'Intro', sans-serif",
|
||||
letterSpacing: "0.06em",
|
||||
color:
|
||||
status === "loading"
|
||||
? "rgba(255,255,255,0.5)"
|
||||
: "rgba(255,255,255,0.9)",
|
||||
background: "transparent",
|
||||
cursor:
|
||||
status === "loading" || !email ? "not-allowed" : "pointer",
|
||||
whiteSpace: "nowrap",
|
||||
}}
|
||||
>
|
||||
{status === "loading" ? "…" : "Stuur mij"}
|
||||
</button>
|
||||
</form>
|
||||
|
||||
{status === "error" && (
|
||||
<p
|
||||
className="font-['Intro',sans-serif] text-xs"
|
||||
style={{ color: "rgba(255,140,140,0.8)" }}
|
||||
>
|
||||
{errorMessage}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shown in place of the registration form while registration is not yet open.
|
||||
*/
|
||||
export function CountdownBanner() {
|
||||
const { isOpen, days, hours, minutes, seconds } = useRegistrationOpen();
|
||||
|
||||
// Once open the parent component will unmount this — but render nothing just in case
|
||||
if (isOpen) return null;
|
||||
|
||||
const openDate = REGISTRATION_OPENS_AT.toLocaleDateString("nl-BE", {
|
||||
weekday: "long",
|
||||
day: "numeric",
|
||||
month: "long",
|
||||
year: "numeric",
|
||||
});
|
||||
const openTime = REGISTRATION_OPENS_AT.toLocaleTimeString("nl-BE", {
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="flex flex-col items-center gap-6 py-4 text-center sm:gap-8">
|
||||
<div>
|
||||
<p className="font-['Intro',sans-serif] text-base text-white/70 sm:text-lg md:text-xl">
|
||||
Inschrijvingen openen op
|
||||
</p>
|
||||
<p className="mt-1 font-['Intro',sans-serif] text-lg text-white capitalize sm:text-xl md:text-2xl">
|
||||
{openDate} om {openTime}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Countdown — single row forced via grid, scales down on small screens */}
|
||||
<div className="grid grid-cols-[auto_auto_auto_auto_auto_auto_auto] items-center gap-1.5 sm:flex sm:gap-4 md:gap-6">
|
||||
<UnitBox value={String(days)} label="dagen" />
|
||||
<span className="mb-6 font-['Intro',sans-serif] text-2xl text-white/40 sm:text-4xl">
|
||||
:
|
||||
</span>
|
||||
<UnitBox value={pad(hours)} label="uren" />
|
||||
<span className="mb-6 font-['Intro',sans-serif] text-2xl text-white/40 sm:text-4xl">
|
||||
:
|
||||
</span>
|
||||
<UnitBox value={pad(minutes)} label="minuten" />
|
||||
<span className="mb-6 font-['Intro',sans-serif] text-2xl text-white/40 sm:text-4xl">
|
||||
:
|
||||
</span>
|
||||
<UnitBox value={pad(seconds)} label="seconden" />
|
||||
</div>
|
||||
|
||||
<p className="max-w-md px-4 text-sm text-white/50">
|
||||
Kom snel terug! Zodra de inschrijvingen openen kun je je hier
|
||||
registreren als toeschouwer of als artiest.
|
||||
</p>
|
||||
|
||||
{/* Email reminder opt-in — always last */}
|
||||
<ReminderForm />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,46 +1,74 @@
|
||||
import { Link } from "@tanstack/react-router";
|
||||
import { useState } from "react";
|
||||
import confetti from "canvas-confetti";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { CountdownBanner } from "@/components/homepage/CountdownBanner";
|
||||
import { PerformerForm } from "@/components/registration/PerformerForm";
|
||||
import { SuccessScreen } from "@/components/registration/SuccessScreen";
|
||||
import { TypeSelector } from "@/components/registration/TypeSelector";
|
||||
import { WatcherForm } from "@/components/registration/WatcherForm";
|
||||
import { authClient } from "@/lib/auth-client";
|
||||
import { useRegistrationOpen } from "@/lib/useRegistrationOpen";
|
||||
|
||||
function fireConfetti() {
|
||||
const colors = ["#d82560", "#52979b", "#d09035", "#214e51", "#ffffff"];
|
||||
|
||||
confetti({
|
||||
particleCount: 120,
|
||||
spread: 80,
|
||||
origin: { x: 0.3, y: 0.6 },
|
||||
colors,
|
||||
});
|
||||
setTimeout(() => {
|
||||
confetti({
|
||||
particleCount: 120,
|
||||
spread: 80,
|
||||
origin: { x: 0.7, y: 0.6 },
|
||||
colors,
|
||||
});
|
||||
}, 200);
|
||||
setTimeout(() => {
|
||||
confetti({
|
||||
particleCount: 80,
|
||||
spread: 100,
|
||||
origin: { x: 0.5, y: 0.5 },
|
||||
colors,
|
||||
});
|
||||
}, 400);
|
||||
}
|
||||
|
||||
type RegistrationType = "performer" | "watcher";
|
||||
|
||||
interface SuccessState {
|
||||
token: string;
|
||||
email: string;
|
||||
name: string;
|
||||
function redirectToSignup(email: string) {
|
||||
const params = new URLSearchParams({
|
||||
signup: "1",
|
||||
email,
|
||||
next: "/account",
|
||||
});
|
||||
window.location.href = `/login?${params.toString()}`;
|
||||
}
|
||||
|
||||
export default function EventRegistrationForm() {
|
||||
const { data: session } = authClient.useSession();
|
||||
const { isOpen } = useRegistrationOpen();
|
||||
const confettiFired = useRef(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (isOpen && !confettiFired.current) {
|
||||
confettiFired.current = true;
|
||||
fireConfetti();
|
||||
}
|
||||
}, [isOpen]);
|
||||
|
||||
const [selectedType, setSelectedType] = useState<RegistrationType | null>(
|
||||
null,
|
||||
);
|
||||
const [successState, setSuccessState] = useState<SuccessState | null>(null);
|
||||
|
||||
const isLoggedIn = !!session?.user;
|
||||
const user = session?.user as { name?: string; email?: string } | undefined;
|
||||
|
||||
// Split "Jan De Smet" → firstName="Jan", lastName="De Smet"
|
||||
const nameParts = (user?.name ?? "").trim().split(/\s+/);
|
||||
const prefillFirstName = nameParts[0] ?? "";
|
||||
const prefillLastName = nameParts.slice(1).join(" ");
|
||||
const prefillEmail = user?.email ?? "";
|
||||
|
||||
if (successState) {
|
||||
if (!isOpen) {
|
||||
return (
|
||||
<SuccessScreen
|
||||
token={successState.token}
|
||||
email={successState.email}
|
||||
name={successState.name}
|
||||
onReset={() => {
|
||||
setSuccessState(null);
|
||||
setSelectedType(null);
|
||||
}}
|
||||
/>
|
||||
<section
|
||||
id="registration"
|
||||
className="relative z-30 w-full bg-[#214e51]/96 px-6 py-16 md:px-12"
|
||||
>
|
||||
<div className="mx-auto w-full max-w-6xl">
|
||||
<CountdownBanner />
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -59,54 +87,18 @@ export default function EventRegistrationForm() {
|
||||
<p className="mb-8 max-w-3xl text-lg text-white/80 md:text-xl">
|
||||
Doe je mee of kom je kijken? Kies je rol en vul het formulier in.
|
||||
</p>
|
||||
{/* Login nudge — shown only to guests */}
|
||||
{!isLoggedIn && (
|
||||
<div className="mb-10 flex flex-col gap-3 rounded-lg border border-[#52979b]/40 bg-[#52979b]/10 px-5 py-4 sm:flex-row sm:items-center sm:justify-between">
|
||||
<p className="text-sm text-white/80">
|
||||
<span className="mr-1 font-semibold text-teal-300">
|
||||
Al een account?
|
||||
</span>
|
||||
Log in om je gegevens automatisch in te vullen en je Drinkkaart
|
||||
direct te activeren na registratie.
|
||||
</p>
|
||||
<div className="flex shrink-0 items-center gap-3 text-sm">
|
||||
<Link
|
||||
to="/login"
|
||||
className="font-medium text-teal-300 underline-offset-2 transition-colors hover:underline"
|
||||
>
|
||||
Inloggen
|
||||
</Link>
|
||||
<span className="text-white/30">·</span>
|
||||
<Link
|
||||
to="/login"
|
||||
search={{ signup: "1" }}
|
||||
className="text-white/60 transition-colors hover:text-white"
|
||||
>
|
||||
Nog geen account? Aanmaken
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!selectedType && <TypeSelector onSelect={setSelectedType} />}
|
||||
{selectedType === "performer" && (
|
||||
<PerformerForm
|
||||
onBack={() => setSelectedType(null)}
|
||||
onSuccess={(token, email, name) =>
|
||||
setSuccessState({ token, email, name })
|
||||
}
|
||||
prefillFirstName={prefillFirstName}
|
||||
prefillLastName={prefillLastName}
|
||||
prefillEmail={prefillEmail}
|
||||
isLoggedIn={isLoggedIn}
|
||||
onSuccess={(_token, email, _name) => redirectToSignup(email)}
|
||||
/>
|
||||
)}
|
||||
{selectedType === "watcher" && (
|
||||
<WatcherForm
|
||||
onBack={() => setSelectedType(null)}
|
||||
prefillFirstName={prefillFirstName}
|
||||
prefillLastName={prefillLastName}
|
||||
prefillEmail={prefillEmail}
|
||||
isLoggedIn={isLoggedIn}
|
||||
onSuccess={(_token, email, _name) => redirectToSignup(email)}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
75
apps/web/src/components/homepage/HoeInschrijven.tsx
Normal file
75
apps/web/src/components/homepage/HoeInschrijven.tsx
Normal file
@@ -0,0 +1,75 @@
|
||||
export default function HoeInschrijven() {
|
||||
return (
|
||||
<section className="relative z-25 w-full bg-[#f8f8f8] px-6 py-16 md:px-12">
|
||||
<div className="mx-auto max-w-6xl">
|
||||
<h2 className="mb-4 font-['Intro',sans-serif] text-4xl text-[#214e51] md:text-5xl">
|
||||
Hoe schrijf ik mij in?
|
||||
</h2>
|
||||
<p className="mb-10 max-w-3xl text-[#214e51]/70 text-lg">
|
||||
Inschrijven doe je eenvoudig via deze website zodra de inschrijvingen
|
||||
openen.
|
||||
</p>
|
||||
|
||||
{/* Step cards */}
|
||||
<div className="grid gap-6 md:grid-cols-3">
|
||||
{/* Step 1 */}
|
||||
<div className="flex flex-col gap-3 rounded-2xl border border-[#214e51]/15 bg-white p-6 shadow-sm">
|
||||
<div className="flex h-10 w-10 items-center justify-center rounded-full bg-[#d82560] font-['Intro',sans-serif] font-bold text-lg text-white">
|
||||
1
|
||||
</div>
|
||||
<h3 className="font-['Intro',sans-serif] text-[#214e51] text-xl">
|
||||
Kies je rol
|
||||
</h3>
|
||||
<p className="text-[#214e51]/70 text-base leading-relaxed">
|
||||
Registreer je als{" "}
|
||||
<strong className="text-[#214e51]">artiest</strong> als je wil
|
||||
optreden, of als{" "}
|
||||
<strong className="text-[#214e51]">bezoeker</strong> als je wil
|
||||
komen kijken. Je kunt ook aangeven met hoeveel mensen je komt.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Step 2 */}
|
||||
<div className="flex flex-col gap-3 rounded-2xl border border-[#214e51]/15 bg-white p-6 shadow-sm">
|
||||
<div className="flex h-10 w-10 items-center justify-center rounded-full bg-[#d82560] font-['Intro',sans-serif] font-bold text-lg text-white">
|
||||
2
|
||||
</div>
|
||||
<h3 className="font-['Intro',sans-serif] text-[#214e51] text-xl">
|
||||
Bevestig je plaats
|
||||
</h3>
|
||||
<p className="text-[#214e51]/70 text-base leading-relaxed">
|
||||
We vragen een bijdrage van{" "}
|
||||
<strong className="text-[#214e51]">€5 per inschrijving</strong> en{" "}
|
||||
<strong className="text-[#214e51]">€2 per extra persoon</strong>{" "}
|
||||
die je meebrengt.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Step 3 */}
|
||||
<div className="flex flex-col gap-3 rounded-2xl border border-[#214e51]/15 bg-white p-6 shadow-sm">
|
||||
<div className="flex h-10 w-10 items-center justify-center rounded-full bg-[#d82560] font-['Intro',sans-serif] font-bold text-lg text-white">
|
||||
3
|
||||
</div>
|
||||
<h3 className="font-['Intro',sans-serif] text-[#214e51] text-xl">
|
||||
Geniet van de avond
|
||||
</h3>
|
||||
<p className="text-[#214e51]/70 text-base leading-relaxed">
|
||||
Je bijdrage gaat{" "}
|
||||
<strong className="text-[#214e51]">niet verloren</strong> — het
|
||||
wordt volledig op{" "}
|
||||
<strong className="text-[#214e51]">je drankkaart</strong> gezet.
|
||||
Zo kun je tijdens de avond iets drinken of een snack nemen.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Bottom note */}
|
||||
<p className="mt-8 max-w-3xl text-[#214e51]/60 text-base leading-relaxed">
|
||||
Zo zorgen we ervoor dat iedereen die zich inschrijft ook echt een
|
||||
plaats heeft — en dat we samen kunnen genieten van een gezellige,
|
||||
inspirerende avond vol muziek, poëzie en andere kunst.
|
||||
</p>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import { useState } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { authClient } from "@/lib/auth-client";
|
||||
import {
|
||||
inputCls,
|
||||
validateEmail,
|
||||
@@ -22,24 +23,16 @@ interface PerformerErrors {
|
||||
interface Props {
|
||||
onBack: () => void;
|
||||
onSuccess: (token: string, email: string, name: string) => void;
|
||||
prefillFirstName?: string;
|
||||
prefillLastName?: string;
|
||||
prefillEmail?: string;
|
||||
isLoggedIn?: boolean;
|
||||
}
|
||||
|
||||
export function PerformerForm({
|
||||
onBack,
|
||||
onSuccess,
|
||||
prefillFirstName = "",
|
||||
prefillLastName = "",
|
||||
prefillEmail = "",
|
||||
isLoggedIn = false,
|
||||
}: Props) {
|
||||
export function PerformerForm({ onBack, onSuccess }: Props) {
|
||||
const { data: session } = authClient.useSession();
|
||||
const sessionEmail = session?.user?.email ?? "";
|
||||
|
||||
const [data, setData] = useState({
|
||||
firstName: prefillFirstName,
|
||||
lastName: prefillLastName,
|
||||
email: prefillEmail,
|
||||
firstName: "",
|
||||
lastName: "",
|
||||
email: "",
|
||||
phone: "",
|
||||
artForm: "",
|
||||
experience: "",
|
||||
@@ -50,6 +43,12 @@ export function PerformerForm({
|
||||
const [errors, setErrors] = useState<PerformerErrors>({});
|
||||
const [touched, setTouched] = useState<Record<string, boolean>>({});
|
||||
|
||||
useEffect(() => {
|
||||
if (sessionEmail) {
|
||||
setData((prev) => ({ ...prev, email: sessionEmail }));
|
||||
}
|
||||
}, [sessionEmail]);
|
||||
|
||||
const submitMutation = useMutation({
|
||||
...orpc.submitRegistration.mutationOptions(),
|
||||
onSuccess: (result) => {
|
||||
@@ -265,15 +264,15 @@ export function PerformerForm({
|
||||
id="p-email"
|
||||
name="email"
|
||||
value={data.email}
|
||||
onChange={isLoggedIn ? undefined : handleChange}
|
||||
onBlur={isLoggedIn ? undefined : handleBlur}
|
||||
readOnly={isLoggedIn}
|
||||
onChange={sessionEmail ? undefined : handleChange}
|
||||
onBlur={sessionEmail ? undefined : handleBlur}
|
||||
readOnly={!!sessionEmail}
|
||||
placeholder="jouw@email.be"
|
||||
autoComplete="email"
|
||||
inputMode="email"
|
||||
aria-required="true"
|
||||
aria-invalid={touched.email && !!errors.email}
|
||||
className={`${inputCls(!!touched.email && !!errors.email)}${isLoggedIn ? "cursor-not-allowed opacity-60" : ""}`}
|
||||
className={`${inputCls(!!touched.email && !!errors.email)}${sessionEmail ? "cursor-not-allowed opacity-75" : ""}`}
|
||||
/>
|
||||
{touched.email && errors.email && (
|
||||
<span className="text-red-300 text-sm" role="alert">
|
||||
|
||||
@@ -1,150 +0,0 @@
|
||||
import { useState } from "react";
|
||||
|
||||
interface Props {
|
||||
token: string;
|
||||
email?: string;
|
||||
name?: string;
|
||||
onReset: () => void;
|
||||
}
|
||||
|
||||
export function SuccessScreen({ token, email, name, onReset }: Props) {
|
||||
const manageUrl =
|
||||
typeof window !== "undefined"
|
||||
? `${window.location.origin}/manage/${token}`
|
||||
: `/manage/${token}`;
|
||||
|
||||
const [drinkkaartPromptDismissed, setDrinkkaartPromptDismissed] = useState(
|
||||
() => {
|
||||
try {
|
||||
return (
|
||||
typeof localStorage !== "undefined" &&
|
||||
localStorage.getItem("drinkkaart_prompt_dismissed") === "1"
|
||||
);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
const handleDismissPrompt = () => {
|
||||
try {
|
||||
localStorage.setItem("drinkkaart_prompt_dismissed", "1");
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
setDrinkkaartPromptDismissed(true);
|
||||
};
|
||||
|
||||
// Build signup URL with pre-filled email query param so /login can pre-fill
|
||||
const signupUrl = email
|
||||
? `/login?signup=1&email=${encodeURIComponent(email)}`
|
||||
: "/login?signup=1";
|
||||
|
||||
return (
|
||||
<section
|
||||
id="registration"
|
||||
className="relative z-30 flex w-full items-center justify-center bg-[#214e51]/96 px-6 py-16 md:px-12"
|
||||
>
|
||||
<div className="mx-auto w-full max-w-3xl">
|
||||
<div className="rounded-lg border border-white/20 bg-white/5 p-8 md:p-12">
|
||||
<div className="mb-6 flex h-16 w-16 items-center justify-center rounded-full bg-green-500/20 text-green-400">
|
||||
<svg
|
||||
className="h-8 w-8"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
strokeWidth={2}
|
||||
aria-label="Succes"
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
d="M5 13l4 4L19 7"
|
||||
/>
|
||||
</svg>
|
||||
</div>
|
||||
<h2 className="mb-4 font-['Intro',sans-serif] text-3xl text-white md:text-4xl">
|
||||
Gelukt!
|
||||
</h2>
|
||||
<p className="mb-6 text-lg text-white/80">
|
||||
Je inschrijving is bevestigd. We sturen je zo dadelijk een
|
||||
bevestigingsmail.
|
||||
</p>
|
||||
<div className="mb-8 rounded-lg border border-white/10 bg-white/5 p-6">
|
||||
<p className="mb-2 text-sm text-white/60">
|
||||
Geen mail ontvangen? Gebruik deze link:
|
||||
</p>
|
||||
<a
|
||||
href={manageUrl}
|
||||
className="break-all text-sm text-white/80 underline underline-offset-2 hover:text-white"
|
||||
>
|
||||
{manageUrl}
|
||||
</a>
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center gap-4">
|
||||
<a
|
||||
href={manageUrl}
|
||||
className="inline-flex items-center bg-white px-6 py-3 font-['Intro',sans-serif] text-[#214e51] text-lg transition-all hover:scale-105 hover:bg-gray-100"
|
||||
>
|
||||
Bekijk mijn inschrijving
|
||||
</a>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onReset}
|
||||
className="text-white/60 underline underline-offset-2 transition-colors hover:text-white"
|
||||
>
|
||||
Nog een inschrijving
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Account creation prompt */}
|
||||
{!drinkkaartPromptDismissed && (
|
||||
<div className="mt-8 rounded-xl border border-teal-400/30 bg-teal-400/10 p-6">
|
||||
<h3 className="mb-1 font-['Intro',sans-serif] text-lg text-white">
|
||||
Maak een gratis account aan
|
||||
</h3>
|
||||
<p className="mb-4 text-sm text-white/70">
|
||||
Met een account zie je je inschrijving, activeer je je
|
||||
Drinkkaart en laad je saldo op vóór het evenement.
|
||||
</p>
|
||||
<ul className="mb-5 space-y-1.5 text-sm text-white/70">
|
||||
<li className="flex items-center gap-2">
|
||||
<span className="text-teal-300">✓</span>
|
||||
Beheer je inschrijving op één plek
|
||||
</li>
|
||||
<li className="flex items-center gap-2">
|
||||
<span className="text-teal-300">✓</span>
|
||||
Digitale Drinkkaart met QR-code
|
||||
</li>
|
||||
<li className="flex items-center gap-2">
|
||||
<span className="text-teal-300">✓</span>
|
||||
Saldo opladen vóór het evenement
|
||||
</li>
|
||||
</ul>
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
<a
|
||||
href={signupUrl}
|
||||
className="inline-flex items-center rounded-lg bg-white px-5 py-2.5 font-['Intro',sans-serif] text-[#214e51] text-sm transition-all hover:scale-105 hover:bg-gray-100"
|
||||
>
|
||||
Account aanmaken
|
||||
{name && (
|
||||
<span className="ml-1.5 font-normal text-xs opacity-60">
|
||||
als {name}
|
||||
</span>
|
||||
)}
|
||||
</a>
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleDismissPrompt}
|
||||
className="text-sm text-white/40 underline underline-offset-2 transition-colors hover:text-white/70"
|
||||
>
|
||||
Overslaan
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import { useState } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { authClient } from "@/lib/auth-client";
|
||||
import {
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
validatePhone,
|
||||
validateTextField,
|
||||
} from "@/lib/registration";
|
||||
import { client, orpc } from "@/utils/orpc";
|
||||
import { orpc } from "@/utils/orpc";
|
||||
import { GiftSelector } from "./GiftSelector";
|
||||
import { GuestList } from "./GuestList";
|
||||
|
||||
@@ -25,231 +25,19 @@ interface WatcherErrors {
|
||||
|
||||
interface Props {
|
||||
onBack: () => void;
|
||||
prefillFirstName?: string;
|
||||
prefillLastName?: string;
|
||||
prefillEmail?: string;
|
||||
isLoggedIn?: boolean;
|
||||
}
|
||||
|
||||
// ── Account creation modal shown after successful registration ─────────────
|
||||
|
||||
interface AccountModalProps {
|
||||
prefillName: string;
|
||||
prefillEmail: string;
|
||||
onDone: () => void;
|
||||
}
|
||||
|
||||
function AccountModal({
|
||||
prefillName,
|
||||
prefillEmail,
|
||||
onDone,
|
||||
}: AccountModalProps) {
|
||||
const [name, setName] = useState(prefillName);
|
||||
const [email] = useState(prefillEmail); // email is fixed (tied to registration)
|
||||
const [password, setPassword] = useState("");
|
||||
const [confirmPassword, setConfirmPassword] = useState("");
|
||||
const [passwordError, setPasswordError] = useState<string | undefined>();
|
||||
|
||||
const signupMutation = useMutation({
|
||||
mutationFn: async () => {
|
||||
if (password.length < 8)
|
||||
throw new Error("Wachtwoord moet minstens 8 tekens zijn");
|
||||
if (password !== confirmPassword)
|
||||
throw new Error("Wachtwoorden komen niet overeen");
|
||||
const result = await authClient.signUp.email({ email, password, name });
|
||||
if (result.error) throw new Error(result.error.message);
|
||||
return result.data;
|
||||
},
|
||||
onSuccess: () => {
|
||||
toast.success(
|
||||
"Account aangemaakt! Je wordt nu doorgestuurd naar betaling.",
|
||||
);
|
||||
onDone();
|
||||
},
|
||||
onError: (error) => {
|
||||
toast.error(`Account aanmaken mislukt: ${error.message}`);
|
||||
},
|
||||
});
|
||||
|
||||
const handlePasswordChange = (val: string) => {
|
||||
setPassword(val);
|
||||
if (passwordError) setPasswordError(undefined);
|
||||
};
|
||||
|
||||
const handleConfirmChange = (val: string) => {
|
||||
setConfirmPassword(val);
|
||||
if (passwordError) setPasswordError(undefined);
|
||||
};
|
||||
|
||||
const handleSignup = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (password.length < 8) {
|
||||
setPasswordError("Wachtwoord moet minstens 8 tekens zijn");
|
||||
return;
|
||||
}
|
||||
if (password !== confirmPassword) {
|
||||
setPasswordError("Wachtwoorden komen niet overeen");
|
||||
return;
|
||||
}
|
||||
signupMutation.mutate();
|
||||
};
|
||||
|
||||
// Receive the checkout URL from parent by exposing a setter via ref pattern
|
||||
// (simpler: the parent renders the modal and passes a prop)
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/60 px-4">
|
||||
<div className="w-full max-w-md rounded-2xl border border-white/10 bg-[#1a3d40] p-8 shadow-2xl">
|
||||
{/* Header */}
|
||||
<div className="mb-6 flex items-start gap-4">
|
||||
<div className="flex h-12 w-12 shrink-0 items-center justify-center rounded-full bg-teal-400/20 text-teal-300 text-xl">
|
||||
✓
|
||||
</div>
|
||||
<div>
|
||||
<h2 className="font-['Intro',sans-serif] text-2xl text-white">
|
||||
Inschrijving gelukt!
|
||||
</h2>
|
||||
<p className="mt-1 text-sm text-white/60">
|
||||
Maak een gratis account aan om je Drinkkaart bij te houden.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Value prop */}
|
||||
<div className="mb-6 rounded-lg border border-teal-400/20 bg-teal-400/10 p-4">
|
||||
<ul className="space-y-1.5 text-sm text-white/80">
|
||||
<li className="flex items-center gap-2">
|
||||
<span className="text-teal-300">✓</span>
|
||||
Zie je drinkkaart-saldo en QR-code
|
||||
</li>
|
||||
<li className="flex items-center gap-2">
|
||||
<span className="text-teal-300">✓</span>
|
||||
Laad je kaart op vóór het evenement
|
||||
</li>
|
||||
<li className="flex items-center gap-2">
|
||||
<span className="text-teal-300">✓</span>
|
||||
Beheer je inschrijving op één plek
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
{/* Signup form */}
|
||||
<form onSubmit={handleSignup} className="space-y-4">
|
||||
{/* Name */}
|
||||
<div>
|
||||
<label
|
||||
className="mb-1.5 block text-sm text-white/60"
|
||||
htmlFor="modal-name"
|
||||
>
|
||||
Naam
|
||||
</label>
|
||||
<input
|
||||
id="modal-name"
|
||||
type="text"
|
||||
value={name}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
required
|
||||
className="w-full rounded-lg border border-white/20 bg-white/10 px-3 py-2 text-white placeholder:text-white/30 focus:border-teal-400/60 focus:outline-none"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Email (read-only) */}
|
||||
<div>
|
||||
<label
|
||||
className="mb-1.5 block text-sm text-white/60"
|
||||
htmlFor="modal-email"
|
||||
>
|
||||
Email
|
||||
</label>
|
||||
<input
|
||||
id="modal-email"
|
||||
type="email"
|
||||
value={email}
|
||||
readOnly
|
||||
className="w-full cursor-not-allowed rounded-lg border border-white/10 bg-white/5 px-3 py-2 text-white/60"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Password */}
|
||||
<div>
|
||||
<label
|
||||
className="mb-1.5 block text-sm text-white/60"
|
||||
htmlFor="modal-password"
|
||||
>
|
||||
Wachtwoord
|
||||
</label>
|
||||
<input
|
||||
id="modal-password"
|
||||
type="password"
|
||||
placeholder="Minstens 8 tekens"
|
||||
value={password}
|
||||
onChange={(e) => handlePasswordChange(e.target.value)}
|
||||
required
|
||||
minLength={8}
|
||||
className="w-full rounded-lg border border-white/20 bg-white/10 px-3 py-2 text-white placeholder:text-white/30 focus:border-teal-400/60 focus:outline-none"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Confirm password */}
|
||||
<div>
|
||||
<label
|
||||
className="mb-1.5 block text-sm text-white/60"
|
||||
htmlFor="modal-confirm"
|
||||
>
|
||||
Bevestig wachtwoord
|
||||
</label>
|
||||
<input
|
||||
id="modal-confirm"
|
||||
type="password"
|
||||
placeholder="Herhaal je wachtwoord"
|
||||
value={confirmPassword}
|
||||
onChange={(e) => handleConfirmChange(e.target.value)}
|
||||
required
|
||||
className="w-full rounded-lg border border-white/20 bg-white/10 px-3 py-2 text-white placeholder:text-white/30 focus:border-teal-400/60 focus:outline-none"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{passwordError && (
|
||||
<p className="text-red-300 text-sm">{passwordError}</p>
|
||||
)}
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
disabled={signupMutation.isPending}
|
||||
className="w-full rounded-lg bg-white py-3 font-['Intro',sans-serif] text-[#214e51] transition-all hover:bg-gray-100 disabled:cursor-not-allowed disabled:opacity-50"
|
||||
>
|
||||
{signupMutation.isPending
|
||||
? "Bezig..."
|
||||
: "Account aanmaken & betalen"}
|
||||
</button>
|
||||
</form>
|
||||
|
||||
{/* Skip */}
|
||||
<button
|
||||
type="button"
|
||||
onClick={onDone}
|
||||
className="mt-4 w-full text-center text-sm text-white/40 transition-colors hover:text-white/70"
|
||||
>
|
||||
Overslaan, verder naar betaling →
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
onSuccess: (token: string, email: string, name: string) => void;
|
||||
}
|
||||
|
||||
// ── Main watcher form ──────────────────────────────────────────────────────
|
||||
|
||||
export function WatcherForm({
|
||||
onBack,
|
||||
prefillFirstName = "",
|
||||
prefillLastName = "",
|
||||
prefillEmail = "",
|
||||
isLoggedIn = false,
|
||||
}: Props) {
|
||||
export function WatcherForm({ onBack, onSuccess }: Props) {
|
||||
const { data: session } = authClient.useSession();
|
||||
const sessionEmail = session?.user?.email ?? "";
|
||||
|
||||
const [data, setData] = useState({
|
||||
firstName: prefillFirstName,
|
||||
lastName: prefillLastName,
|
||||
email: prefillEmail,
|
||||
firstName: "",
|
||||
lastName: "",
|
||||
email: "",
|
||||
phone: "",
|
||||
extraQuestions: "",
|
||||
});
|
||||
@@ -259,40 +47,21 @@ export function WatcherForm({
|
||||
const [guestErrors, setGuestErrors] = useState<GuestErrors[]>([]);
|
||||
const [giftAmount, setGiftAmount] = useState(0);
|
||||
|
||||
// Modal state: shown after successful registration while we fetch checkout URL
|
||||
const [modalState, setModalState] = useState<{
|
||||
prefillName: string;
|
||||
prefillEmail: string;
|
||||
checkoutUrl: string;
|
||||
} | null>(null);
|
||||
useEffect(() => {
|
||||
if (sessionEmail) {
|
||||
setData((prev) => ({ ...prev, email: sessionEmail }));
|
||||
}
|
||||
}, [sessionEmail]);
|
||||
|
||||
const submitMutation = useMutation({
|
||||
...orpc.submitRegistration.mutationOptions(),
|
||||
onSuccess: async (result) => {
|
||||
if (!result.managementToken) return;
|
||||
try {
|
||||
const redirectUrl = isLoggedIn
|
||||
? `${window.location.origin}/account?topup=success`
|
||||
: undefined;
|
||||
const checkout = await client.getCheckoutUrl({
|
||||
token: result.managementToken,
|
||||
redirectUrl,
|
||||
});
|
||||
if (isLoggedIn) {
|
||||
// Already logged in — skip the account-creation modal, go straight to checkout
|
||||
window.location.href = checkout.checkoutUrl;
|
||||
} else {
|
||||
// Show the account-creation modal before redirecting to checkout
|
||||
setModalState({
|
||||
prefillName:
|
||||
`${data.firstName.trim()} ${data.lastName.trim()}`.trim(),
|
||||
prefillEmail: data.email.trim(),
|
||||
checkoutUrl: checkout.checkoutUrl,
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Checkout error:", error);
|
||||
toast.error("Er is iets misgegaan bij het aanmaken van de betaling");
|
||||
onSuccess: (result) => {
|
||||
if (result.managementToken) {
|
||||
onSuccess(
|
||||
result.managementToken,
|
||||
data.email.trim(),
|
||||
`${data.firstName.trim()} ${data.lastName.trim()}`.trim(),
|
||||
);
|
||||
}
|
||||
},
|
||||
onError: (error) => {
|
||||
@@ -402,19 +171,6 @@ export function WatcherForm({
|
||||
|
||||
return (
|
||||
<div>
|
||||
{/* Account-creation interstitial modal */}
|
||||
{modalState && (
|
||||
<AccountModal
|
||||
prefillName={modalState.prefillName}
|
||||
prefillEmail={modalState.prefillEmail}
|
||||
onDone={() => {
|
||||
const url = modalState.checkoutUrl;
|
||||
setModalState(null);
|
||||
window.location.href = url;
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Back + type header */}
|
||||
<div className="mb-8 flex items-center gap-4">
|
||||
<button
|
||||
@@ -544,15 +300,15 @@ export function WatcherForm({
|
||||
id="w-email"
|
||||
name="email"
|
||||
value={data.email}
|
||||
onChange={isLoggedIn ? undefined : handleChange}
|
||||
onBlur={isLoggedIn ? undefined : handleBlur}
|
||||
readOnly={isLoggedIn}
|
||||
onChange={sessionEmail ? undefined : handleChange}
|
||||
onBlur={sessionEmail ? undefined : handleBlur}
|
||||
readOnly={!!sessionEmail}
|
||||
placeholder="jouw@email.be"
|
||||
autoComplete="email"
|
||||
inputMode="email"
|
||||
aria-required="true"
|
||||
aria-invalid={touched.email && !!errors.email}
|
||||
className={`${inputCls(!!touched.email && !!errors.email)}${isLoggedIn ? "cursor-not-allowed opacity-60" : ""}`}
|
||||
className={`${inputCls(!!touched.email && !!errors.email)}${sessionEmail ? "cursor-not-allowed opacity-75" : ""}`}
|
||||
/>
|
||||
{touched.email && errors.email && (
|
||||
<span className="text-red-300 text-sm" role="alert">
|
||||
@@ -653,7 +409,7 @@ export function WatcherForm({
|
||||
Bezig...
|
||||
</span>
|
||||
) : (
|
||||
"Bevestigen & betalen"
|
||||
"Bevestigen"
|
||||
)}
|
||||
</button>
|
||||
<a
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
import { createAuthClient } from "better-auth/react";
|
||||
|
||||
export const authClient = createAuthClient({});
|
||||
export const authClient = createAuthClient();
|
||||
|
||||
5
apps/web/src/lib/opening.ts
Normal file
5
apps/web/src/lib/opening.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* Single source-of-truth for when registration opens.
|
||||
* Change this date to reschedule — all gating logic imports from here.
|
||||
*/
|
||||
export const REGISTRATION_OPENS_AT = new Date("2026-03-16T19:00:00+01:00");
|
||||
45
apps/web/src/lib/useRegistrationOpen.ts
Normal file
45
apps/web/src/lib/useRegistrationOpen.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { REGISTRATION_OPENS_AT } from "./opening";
|
||||
|
||||
interface RegistrationOpenState {
|
||||
isOpen: boolean;
|
||||
days: number;
|
||||
hours: number;
|
||||
minutes: number;
|
||||
seconds: number;
|
||||
}
|
||||
|
||||
function compute(): RegistrationOpenState {
|
||||
const diff = REGISTRATION_OPENS_AT.getTime() - Date.now();
|
||||
if (diff <= 0) {
|
||||
return { isOpen: true, days: 0, hours: 0, minutes: 0, seconds: 0 };
|
||||
}
|
||||
const totalSeconds = Math.floor(diff / 1000);
|
||||
const days = Math.floor(totalSeconds / 86400);
|
||||
const hours = Math.floor((totalSeconds % 86400) / 3600);
|
||||
const minutes = Math.floor((totalSeconds % 3600) / 60);
|
||||
const seconds = totalSeconds % 60;
|
||||
return { isOpen: false, days, hours, minutes, seconds };
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns live countdown state to {@link REGISTRATION_OPENS_AT}.
|
||||
* Ticks every second; clears the interval once registration is open.
|
||||
*/
|
||||
export function useRegistrationOpen(): RegistrationOpenState {
|
||||
const [state, setState] = useState<RegistrationOpenState>(compute);
|
||||
|
||||
useEffect(() => {
|
||||
if (state.isOpen) return;
|
||||
|
||||
const id = setInterval(() => {
|
||||
const next = compute();
|
||||
setState(next);
|
||||
if (next.isOpen) clearInterval(id);
|
||||
}, 1000);
|
||||
|
||||
return () => clearInterval(id);
|
||||
}, [state.isOpen]);
|
||||
|
||||
return state;
|
||||
}
|
||||
@@ -10,8 +10,10 @@
|
||||
|
||||
import { Route as rootRouteImport } from './routes/__root'
|
||||
import { Route as TermsRouteImport } from './routes/terms'
|
||||
import { Route as ResetPasswordRouteImport } from './routes/reset-password'
|
||||
import { Route as PrivacyRouteImport } from './routes/privacy'
|
||||
import { Route as LoginRouteImport } from './routes/login'
|
||||
import { Route as ForgotPasswordRouteImport } from './routes/forgot-password'
|
||||
import { Route as DrinkkaartRouteImport } from './routes/drinkkaart'
|
||||
import { Route as ContactRouteImport } from './routes/contact'
|
||||
import { Route as AccountRouteImport } from './routes/account'
|
||||
@@ -21,6 +23,7 @@ import { Route as ManageTokenRouteImport } from './routes/manage.$token'
|
||||
import { Route as AdminDrinkkaartRouteImport } from './routes/admin/drinkkaart'
|
||||
import { Route as ApiWebhookMollieRouteImport } from './routes/api/webhook/mollie'
|
||||
import { Route as ApiRpcSplatRouteImport } from './routes/api/rpc/$'
|
||||
import { Route as ApiCronRemindersRouteImport } from './routes/api/cron/reminders'
|
||||
import { Route as ApiAuthSplatRouteImport } from './routes/api/auth/$'
|
||||
|
||||
const TermsRoute = TermsRouteImport.update({
|
||||
@@ -28,6 +31,11 @@ const TermsRoute = TermsRouteImport.update({
|
||||
path: '/terms',
|
||||
getParentRoute: () => rootRouteImport,
|
||||
} as any)
|
||||
const ResetPasswordRoute = ResetPasswordRouteImport.update({
|
||||
id: '/reset-password',
|
||||
path: '/reset-password',
|
||||
getParentRoute: () => rootRouteImport,
|
||||
} as any)
|
||||
const PrivacyRoute = PrivacyRouteImport.update({
|
||||
id: '/privacy',
|
||||
path: '/privacy',
|
||||
@@ -38,6 +46,11 @@ const LoginRoute = LoginRouteImport.update({
|
||||
path: '/login',
|
||||
getParentRoute: () => rootRouteImport,
|
||||
} as any)
|
||||
const ForgotPasswordRoute = ForgotPasswordRouteImport.update({
|
||||
id: '/forgot-password',
|
||||
path: '/forgot-password',
|
||||
getParentRoute: () => rootRouteImport,
|
||||
} as any)
|
||||
const DrinkkaartRoute = DrinkkaartRouteImport.update({
|
||||
id: '/drinkkaart',
|
||||
path: '/drinkkaart',
|
||||
@@ -83,6 +96,11 @@ const ApiRpcSplatRoute = ApiRpcSplatRouteImport.update({
|
||||
path: '/api/rpc/$',
|
||||
getParentRoute: () => rootRouteImport,
|
||||
} as any)
|
||||
const ApiCronRemindersRoute = ApiCronRemindersRouteImport.update({
|
||||
id: '/api/cron/reminders',
|
||||
path: '/api/cron/reminders',
|
||||
getParentRoute: () => rootRouteImport,
|
||||
} as any)
|
||||
const ApiAuthSplatRoute = ApiAuthSplatRouteImport.update({
|
||||
id: '/api/auth/$',
|
||||
path: '/api/auth/$',
|
||||
@@ -94,13 +112,16 @@ export interface FileRoutesByFullPath {
|
||||
'/account': typeof AccountRoute
|
||||
'/contact': typeof ContactRoute
|
||||
'/drinkkaart': typeof DrinkkaartRoute
|
||||
'/forgot-password': typeof ForgotPasswordRoute
|
||||
'/login': typeof LoginRoute
|
||||
'/privacy': typeof PrivacyRoute
|
||||
'/reset-password': typeof ResetPasswordRoute
|
||||
'/terms': typeof TermsRoute
|
||||
'/admin/drinkkaart': typeof AdminDrinkkaartRoute
|
||||
'/manage/$token': typeof ManageTokenRoute
|
||||
'/admin/': typeof AdminIndexRoute
|
||||
'/api/auth/$': typeof ApiAuthSplatRoute
|
||||
'/api/cron/reminders': typeof ApiCronRemindersRoute
|
||||
'/api/rpc/$': typeof ApiRpcSplatRoute
|
||||
'/api/webhook/mollie': typeof ApiWebhookMollieRoute
|
||||
}
|
||||
@@ -109,13 +130,16 @@ export interface FileRoutesByTo {
|
||||
'/account': typeof AccountRoute
|
||||
'/contact': typeof ContactRoute
|
||||
'/drinkkaart': typeof DrinkkaartRoute
|
||||
'/forgot-password': typeof ForgotPasswordRoute
|
||||
'/login': typeof LoginRoute
|
||||
'/privacy': typeof PrivacyRoute
|
||||
'/reset-password': typeof ResetPasswordRoute
|
||||
'/terms': typeof TermsRoute
|
||||
'/admin/drinkkaart': typeof AdminDrinkkaartRoute
|
||||
'/manage/$token': typeof ManageTokenRoute
|
||||
'/admin': typeof AdminIndexRoute
|
||||
'/api/auth/$': typeof ApiAuthSplatRoute
|
||||
'/api/cron/reminders': typeof ApiCronRemindersRoute
|
||||
'/api/rpc/$': typeof ApiRpcSplatRoute
|
||||
'/api/webhook/mollie': typeof ApiWebhookMollieRoute
|
||||
}
|
||||
@@ -125,13 +149,16 @@ export interface FileRoutesById {
|
||||
'/account': typeof AccountRoute
|
||||
'/contact': typeof ContactRoute
|
||||
'/drinkkaart': typeof DrinkkaartRoute
|
||||
'/forgot-password': typeof ForgotPasswordRoute
|
||||
'/login': typeof LoginRoute
|
||||
'/privacy': typeof PrivacyRoute
|
||||
'/reset-password': typeof ResetPasswordRoute
|
||||
'/terms': typeof TermsRoute
|
||||
'/admin/drinkkaart': typeof AdminDrinkkaartRoute
|
||||
'/manage/$token': typeof ManageTokenRoute
|
||||
'/admin/': typeof AdminIndexRoute
|
||||
'/api/auth/$': typeof ApiAuthSplatRoute
|
||||
'/api/cron/reminders': typeof ApiCronRemindersRoute
|
||||
'/api/rpc/$': typeof ApiRpcSplatRoute
|
||||
'/api/webhook/mollie': typeof ApiWebhookMollieRoute
|
||||
}
|
||||
@@ -142,13 +169,16 @@ export interface FileRouteTypes {
|
||||
| '/account'
|
||||
| '/contact'
|
||||
| '/drinkkaart'
|
||||
| '/forgot-password'
|
||||
| '/login'
|
||||
| '/privacy'
|
||||
| '/reset-password'
|
||||
| '/terms'
|
||||
| '/admin/drinkkaart'
|
||||
| '/manage/$token'
|
||||
| '/admin/'
|
||||
| '/api/auth/$'
|
||||
| '/api/cron/reminders'
|
||||
| '/api/rpc/$'
|
||||
| '/api/webhook/mollie'
|
||||
fileRoutesByTo: FileRoutesByTo
|
||||
@@ -157,13 +187,16 @@ export interface FileRouteTypes {
|
||||
| '/account'
|
||||
| '/contact'
|
||||
| '/drinkkaart'
|
||||
| '/forgot-password'
|
||||
| '/login'
|
||||
| '/privacy'
|
||||
| '/reset-password'
|
||||
| '/terms'
|
||||
| '/admin/drinkkaart'
|
||||
| '/manage/$token'
|
||||
| '/admin'
|
||||
| '/api/auth/$'
|
||||
| '/api/cron/reminders'
|
||||
| '/api/rpc/$'
|
||||
| '/api/webhook/mollie'
|
||||
id:
|
||||
@@ -172,13 +205,16 @@ export interface FileRouteTypes {
|
||||
| '/account'
|
||||
| '/contact'
|
||||
| '/drinkkaart'
|
||||
| '/forgot-password'
|
||||
| '/login'
|
||||
| '/privacy'
|
||||
| '/reset-password'
|
||||
| '/terms'
|
||||
| '/admin/drinkkaart'
|
||||
| '/manage/$token'
|
||||
| '/admin/'
|
||||
| '/api/auth/$'
|
||||
| '/api/cron/reminders'
|
||||
| '/api/rpc/$'
|
||||
| '/api/webhook/mollie'
|
||||
fileRoutesById: FileRoutesById
|
||||
@@ -188,13 +224,16 @@ export interface RootRouteChildren {
|
||||
AccountRoute: typeof AccountRoute
|
||||
ContactRoute: typeof ContactRoute
|
||||
DrinkkaartRoute: typeof DrinkkaartRoute
|
||||
ForgotPasswordRoute: typeof ForgotPasswordRoute
|
||||
LoginRoute: typeof LoginRoute
|
||||
PrivacyRoute: typeof PrivacyRoute
|
||||
ResetPasswordRoute: typeof ResetPasswordRoute
|
||||
TermsRoute: typeof TermsRoute
|
||||
AdminDrinkkaartRoute: typeof AdminDrinkkaartRoute
|
||||
ManageTokenRoute: typeof ManageTokenRoute
|
||||
AdminIndexRoute: typeof AdminIndexRoute
|
||||
ApiAuthSplatRoute: typeof ApiAuthSplatRoute
|
||||
ApiCronRemindersRoute: typeof ApiCronRemindersRoute
|
||||
ApiRpcSplatRoute: typeof ApiRpcSplatRoute
|
||||
ApiWebhookMollieRoute: typeof ApiWebhookMollieRoute
|
||||
}
|
||||
@@ -208,6 +247,13 @@ declare module '@tanstack/react-router' {
|
||||
preLoaderRoute: typeof TermsRouteImport
|
||||
parentRoute: typeof rootRouteImport
|
||||
}
|
||||
'/reset-password': {
|
||||
id: '/reset-password'
|
||||
path: '/reset-password'
|
||||
fullPath: '/reset-password'
|
||||
preLoaderRoute: typeof ResetPasswordRouteImport
|
||||
parentRoute: typeof rootRouteImport
|
||||
}
|
||||
'/privacy': {
|
||||
id: '/privacy'
|
||||
path: '/privacy'
|
||||
@@ -222,6 +268,13 @@ declare module '@tanstack/react-router' {
|
||||
preLoaderRoute: typeof LoginRouteImport
|
||||
parentRoute: typeof rootRouteImport
|
||||
}
|
||||
'/forgot-password': {
|
||||
id: '/forgot-password'
|
||||
path: '/forgot-password'
|
||||
fullPath: '/forgot-password'
|
||||
preLoaderRoute: typeof ForgotPasswordRouteImport
|
||||
parentRoute: typeof rootRouteImport
|
||||
}
|
||||
'/drinkkaart': {
|
||||
id: '/drinkkaart'
|
||||
path: '/drinkkaart'
|
||||
@@ -285,6 +338,13 @@ declare module '@tanstack/react-router' {
|
||||
preLoaderRoute: typeof ApiRpcSplatRouteImport
|
||||
parentRoute: typeof rootRouteImport
|
||||
}
|
||||
'/api/cron/reminders': {
|
||||
id: '/api/cron/reminders'
|
||||
path: '/api/cron/reminders'
|
||||
fullPath: '/api/cron/reminders'
|
||||
preLoaderRoute: typeof ApiCronRemindersRouteImport
|
||||
parentRoute: typeof rootRouteImport
|
||||
}
|
||||
'/api/auth/$': {
|
||||
id: '/api/auth/$'
|
||||
path: '/api/auth/$'
|
||||
@@ -300,13 +360,16 @@ const rootRouteChildren: RootRouteChildren = {
|
||||
AccountRoute: AccountRoute,
|
||||
ContactRoute: ContactRoute,
|
||||
DrinkkaartRoute: DrinkkaartRoute,
|
||||
ForgotPasswordRoute: ForgotPasswordRoute,
|
||||
LoginRoute: LoginRoute,
|
||||
PrivacyRoute: PrivacyRoute,
|
||||
ResetPasswordRoute: ResetPasswordRoute,
|
||||
TermsRoute: TermsRoute,
|
||||
AdminDrinkkaartRoute: AdminDrinkkaartRoute,
|
||||
ManageTokenRoute: ManageTokenRoute,
|
||||
AdminIndexRoute: AdminIndexRoute,
|
||||
ApiAuthSplatRoute: ApiAuthSplatRoute,
|
||||
ApiCronRemindersRoute: ApiCronRemindersRoute,
|
||||
ApiRpcSplatRoute: ApiRpcSplatRoute,
|
||||
ApiWebhookMollieRoute: ApiWebhookMollieRoute,
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ export const Route = createRootRouteWithContext<RouterAppContext>()({
|
||||
price: "0",
|
||||
priceCurrency: "EUR",
|
||||
availability: "https://schema.org/InStock",
|
||||
validFrom: "2026-03-01T00:00:00+02:00",
|
||||
validFrom: "2026-03-16T19:00:00+01:00",
|
||||
},
|
||||
}),
|
||||
},
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { createFileRoute, Link, useNavigate } from "@tanstack/react-router";
|
||||
import {
|
||||
Calendar,
|
||||
@@ -74,6 +74,22 @@ function AccountPage() {
|
||||
const [showQr, setShowQr] = useState(false);
|
||||
const [showTopUp, setShowTopUp] = useState(false);
|
||||
|
||||
const checkoutMutation = useMutation({
|
||||
mutationFn: async (token: string) => {
|
||||
const result = await client.getCheckoutUrl({
|
||||
token,
|
||||
redirectUrl: `${window.location.origin}/account?topup=success`,
|
||||
});
|
||||
return result;
|
||||
},
|
||||
onSuccess: (data) => {
|
||||
window.location.href = data.checkoutUrl;
|
||||
},
|
||||
onError: () => {
|
||||
toast.error("Er is iets misgegaan bij het aanmaken van de betaling");
|
||||
},
|
||||
});
|
||||
|
||||
const sessionQuery = useQuery({
|
||||
queryKey: ["session"],
|
||||
queryFn: () => authClient.getSession(),
|
||||
@@ -187,7 +203,13 @@ function AccountPage() {
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<PaymentBadge status={registration.paymentStatus} />
|
||||
{/* Only show a payment badge when there's actually something to pay:
|
||||
watchers always have a drinkcard fee; anyone with a gift amount does too.
|
||||
Performers with no gift have nothing to pay → hide the badge. */}
|
||||
{(registration.registrationType === "watcher" ||
|
||||
(registration.giftAmount ?? 0) > 0) && (
|
||||
<PaymentBadge status={registration.paymentStatus} />
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Name */}
|
||||
@@ -276,6 +298,60 @@ function AccountPage() {
|
||||
</Link>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Pay now CTA — shown for watchers with pending payment */}
|
||||
{registration.registrationType === "watcher" &&
|
||||
registration.paymentStatus === "pending" &&
|
||||
registration.managementToken && (
|
||||
<div className="mt-5 rounded-lg border border-teal-400/30 bg-teal-400/10 p-4">
|
||||
<p className="mb-3 text-sm text-white/80">
|
||||
Je inschrijving is bevestigd maar de betaling staat nog
|
||||
open. Betaal nu om je Drinkkaart te activeren.
|
||||
</p>
|
||||
<button
|
||||
type="button"
|
||||
disabled={checkoutMutation.isPending}
|
||||
onClick={() =>
|
||||
checkoutMutation.mutate(
|
||||
registration.managementToken ?? "",
|
||||
)
|
||||
}
|
||||
className="inline-flex items-center gap-2 rounded-lg bg-white px-4 py-2 font-semibold text-[#214e51] text-sm transition-colors hover:bg-white/90 disabled:cursor-not-allowed disabled:opacity-50"
|
||||
>
|
||||
{checkoutMutation.isPending ? (
|
||||
<>
|
||||
<svg
|
||||
className="h-4 w-4 animate-spin"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<circle
|
||||
className="opacity-25"
|
||||
cx="12"
|
||||
cy="12"
|
||||
r="10"
|
||||
stroke="currentColor"
|
||||
strokeWidth="4"
|
||||
/>
|
||||
<path
|
||||
className="opacity-75"
|
||||
fill="currentColor"
|
||||
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
|
||||
/>
|
||||
</svg>
|
||||
Laden...
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Wallet className="h-4 w-4" />
|
||||
Betaal nu
|
||||
</>
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<div className="rounded-2xl border border-white/10 bg-white/5 p-6">
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
40
apps/web/src/routes/api/cron/reminders.ts
Normal file
40
apps/web/src/routes/api/cron/reminders.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { runSendReminders } from "@kk/api/routers/index";
|
||||
import { env } from "@kk/env/server";
|
||||
import { createFileRoute } from "@tanstack/react-router";
|
||||
|
||||
async function handleCronReminders({ request }: { request: Request }) {
|
||||
const secret = env.CRON_SECRET;
|
||||
if (!secret) {
|
||||
return new Response("CRON_SECRET not configured", { status: 500 });
|
||||
}
|
||||
|
||||
// Accept the secret via Authorization header (Bearer) or JSON body
|
||||
const authHeader = request.headers.get("Authorization");
|
||||
let providedSecret: string | null = null;
|
||||
|
||||
if (authHeader?.startsWith("Bearer ")) {
|
||||
providedSecret = authHeader.slice(7);
|
||||
} else {
|
||||
try {
|
||||
const body = await request.json();
|
||||
providedSecret = (body as { secret?: string }).secret ?? null;
|
||||
} catch {
|
||||
// ignore parse errors
|
||||
}
|
||||
}
|
||||
|
||||
if (!providedSecret || providedSecret !== secret) {
|
||||
return new Response("Unauthorized", { status: 401 });
|
||||
}
|
||||
|
||||
const result = await runSendReminders();
|
||||
return Response.json(result);
|
||||
}
|
||||
|
||||
export const Route = createFileRoute("/api/cron/reminders")({
|
||||
server: {
|
||||
handlers: {
|
||||
POST: handleCronReminders,
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -1,4 +1,5 @@
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { sendPaymentConfirmationEmail } from "@kk/api/email";
|
||||
import { creditRegistrationToAccount } from "@kk/api/routers/index";
|
||||
import { db } from "@kk/db";
|
||||
import { drinkkaart, drinkkaartTopup, registration } from "@kk/db/schema";
|
||||
@@ -206,6 +207,20 @@ async function handleWebhook({ request }: { request: Request }) {
|
||||
`Payment successful for registration ${registrationToken}, payment ${payment.id}`,
|
||||
);
|
||||
|
||||
// Send payment confirmation email (fire-and-forget; don't block webhook)
|
||||
sendPaymentConfirmationEmail({
|
||||
to: regRow.email,
|
||||
firstName: regRow.firstName,
|
||||
managementToken: regRow.managementToken ?? registrationToken,
|
||||
drinkCardValue: regRow.drinkCardValue ?? undefined,
|
||||
giftAmount: regRow.giftAmount ?? undefined,
|
||||
}).catch((err) =>
|
||||
console.error(
|
||||
`Failed to send payment confirmation email for ${regRow.email}:`,
|
||||
err,
|
||||
),
|
||||
);
|
||||
|
||||
// If this is a watcher with a drink card value, try to credit their
|
||||
// drinkkaart immediately — but only if they already have an account.
|
||||
if (
|
||||
|
||||
118
apps/web/src/routes/forgot-password.tsx
Normal file
118
apps/web/src/routes/forgot-password.tsx
Normal file
@@ -0,0 +1,118 @@
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import { createFileRoute, Link } from "@tanstack/react-router";
|
||||
import { useState } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
CardDescription,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from "@/components/ui/card";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { authClient } from "@/lib/auth-client";
|
||||
|
||||
export const Route = createFileRoute("/forgot-password")({
|
||||
component: ForgotPasswordPage,
|
||||
});
|
||||
|
||||
function ForgotPasswordPage() {
|
||||
const [email, setEmail] = useState("");
|
||||
const [sent, setSent] = useState(false);
|
||||
|
||||
const mutation = useMutation({
|
||||
mutationFn: async (email: string) => {
|
||||
const result = await authClient.requestPasswordReset({
|
||||
email,
|
||||
redirectTo: "/reset-password",
|
||||
});
|
||||
if (result.error) {
|
||||
throw new Error(result.error.message);
|
||||
}
|
||||
return result.data;
|
||||
},
|
||||
onSuccess: () => {
|
||||
setSent(true);
|
||||
},
|
||||
});
|
||||
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
mutation.mutate(email);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex min-h-[calc(100dvh-2.75rem)] items-center justify-center overflow-y-auto px-4 py-8 sm:min-h-[calc(100dvh-3.5rem)]">
|
||||
<Card className="my-auto w-full max-w-md border-white/10 bg-white/5">
|
||||
<CardHeader className="text-center">
|
||||
<CardTitle className="font-['Intro',sans-serif] text-3xl text-white">
|
||||
Wachtwoord vergeten
|
||||
</CardTitle>
|
||||
<CardDescription className="text-white/60">
|
||||
{sent
|
||||
? "Controleer je inbox"
|
||||
: "Vul je e-mailadres in en we sturen je een link"}
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{sent ? (
|
||||
<div className="space-y-4">
|
||||
<div className="rounded-lg border border-white/10 bg-white/5 p-5 text-center">
|
||||
<p className="text-sm text-white/80 leading-relaxed">
|
||||
Als er een account bestaat voor{" "}
|
||||
<span className="font-medium text-white">{email}</span>, is er
|
||||
een e-mail verstuurd met een link om je wachtwoord opnieuw in
|
||||
te stellen. De link is 1 uur geldig.
|
||||
</p>
|
||||
</div>
|
||||
<Link
|
||||
to="/login"
|
||||
className="block text-center text-sm text-white/60 hover:text-white"
|
||||
>
|
||||
← Terug naar inloggen
|
||||
</Link>
|
||||
</div>
|
||||
) : (
|
||||
<form onSubmit={handleSubmit} className="space-y-4">
|
||||
<div>
|
||||
<label
|
||||
htmlFor="email"
|
||||
className="mb-2 block text-sm text-white/60"
|
||||
>
|
||||
E-mailadres
|
||||
</label>
|
||||
<Input
|
||||
id="email"
|
||||
type="email"
|
||||
placeholder="jouw@email.be"
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
required
|
||||
className="border-white/20 bg-white/10 text-white placeholder:text-white/40"
|
||||
/>
|
||||
</div>
|
||||
{mutation.isError && (
|
||||
<p className="text-red-400 text-sm">{mutation.error.message}</p>
|
||||
)}
|
||||
<Button
|
||||
type="submit"
|
||||
disabled={mutation.isPending}
|
||||
className="w-full bg-white text-[#214e51] hover:bg-white/90"
|
||||
>
|
||||
{mutation.isPending ? "Bezig..." : "Stuur reset-link"}
|
||||
</Button>
|
||||
<div className="text-center">
|
||||
<Link
|
||||
to="/login"
|
||||
className="text-sm text-white/60 hover:text-white"
|
||||
>
|
||||
← Terug naar inloggen
|
||||
</Link>
|
||||
</div>
|
||||
</form>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
import { createFileRoute } from "@tanstack/react-router";
|
||||
|
||||
import ArtForms from "@/components/homepage/ArtForms";
|
||||
import EventRegistrationForm from "@/components/homepage/EventRegistrationForm";
|
||||
import Footer from "@/components/homepage/Footer";
|
||||
import Hero from "@/components/homepage/Hero";
|
||||
import HoeInschrijven from "@/components/homepage/HoeInschrijven";
|
||||
import Info from "@/components/homepage/Info";
|
||||
|
||||
export const Route = createFileRoute("/")({
|
||||
@@ -16,7 +15,7 @@ function HomePage() {
|
||||
<main className="relative">
|
||||
<Hero />
|
||||
<Info />
|
||||
<ArtForms />
|
||||
<HoeInschrijven />
|
||||
<EventRegistrationForm />
|
||||
<Footer />
|
||||
</main>
|
||||
|
||||
@@ -12,6 +12,8 @@ import {
|
||||
} from "@/components/ui/card";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { authClient } from "@/lib/auth-client";
|
||||
import { REGISTRATION_OPENS_AT } from "@/lib/opening";
|
||||
import { useRegistrationOpen } from "@/lib/useRegistrationOpen";
|
||||
import { orpc } from "@/utils/orpc";
|
||||
|
||||
export const Route = createFileRoute("/login")({
|
||||
@@ -31,6 +33,7 @@ export const Route = createFileRoute("/login")({
|
||||
function LoginPage() {
|
||||
const navigate = useNavigate();
|
||||
const search = Route.useSearch();
|
||||
const { isOpen } = useRegistrationOpen();
|
||||
const [isSignup, setIsSignup] = useState(() => search.signup === "1");
|
||||
const [email, setEmail] = useState(() => search.email ?? "");
|
||||
const [password, setPassword] = useState("");
|
||||
@@ -204,6 +207,43 @@ function LoginPage() {
|
||||
← Terug naar website
|
||||
</Link>
|
||||
</div>
|
||||
) : isSignup && !isOpen ? (
|
||||
/* Signup is closed until registration opens */
|
||||
<div className="space-y-4">
|
||||
<div className="rounded-lg border border-white/10 bg-white/5 p-5 text-center">
|
||||
<p className="mb-1 font-['Intro',sans-serif] text-white">
|
||||
Registratie nog niet open
|
||||
</p>
|
||||
<p className="text-sm text-white/60">
|
||||
Accounts aanmaken kan vanaf{" "}
|
||||
<span className="text-teal-300">
|
||||
{REGISTRATION_OPENS_AT.toLocaleDateString("nl-BE", {
|
||||
weekday: "long",
|
||||
day: "numeric",
|
||||
month: "long",
|
||||
})}{" "}
|
||||
om{" "}
|
||||
{REGISTRATION_OPENS_AT.toLocaleTimeString("nl-BE", {
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
})}
|
||||
</span>
|
||||
.
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex flex-col gap-2 text-center">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setIsSignup(false)}
|
||||
className="text-sm text-white/60 hover:text-white"
|
||||
>
|
||||
Al een account? Log in
|
||||
</button>
|
||||
<Link to="/" className="text-sm text-white/60 hover:text-white">
|
||||
← Terug naar website
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<form onSubmit={handleSubmit} className="space-y-4">
|
||||
{isSignup && (
|
||||
@@ -259,6 +299,16 @@ function LoginPage() {
|
||||
className="border-white/20 bg-white/10 text-white placeholder:text-white/40"
|
||||
/>
|
||||
</div>
|
||||
{!isSignup && (
|
||||
<div className="text-right">
|
||||
<Link
|
||||
to="/forgot-password"
|
||||
className="text-sm text-white/50 hover:text-white"
|
||||
>
|
||||
Wachtwoord vergeten?
|
||||
</Link>
|
||||
</div>
|
||||
)}
|
||||
<Button
|
||||
type="submit"
|
||||
disabled={loginMutation.isPending || signupMutation.isPending}
|
||||
@@ -271,15 +321,34 @@ function LoginPage() {
|
||||
: "Inloggen"}
|
||||
</Button>
|
||||
<div className="flex flex-col gap-2 text-center">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setIsSignup(!isSignup)}
|
||||
className="text-sm text-white/60 hover:text-white"
|
||||
>
|
||||
{isSignup
|
||||
? "Al een account? Log in"
|
||||
: "Nog geen account? Registreer"}
|
||||
</button>
|
||||
{/* Only show signup toggle when registration is open */}
|
||||
{isOpen && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setIsSignup(!isSignup)}
|
||||
className="text-sm text-white/60 hover:text-white"
|
||||
>
|
||||
{isSignup
|
||||
? "Al een account? Log in"
|
||||
: "Nog geen account? Registreer"}
|
||||
</button>
|
||||
)}
|
||||
{!isOpen && isSignup === false && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setIsSignup(true)}
|
||||
className="cursor-not-allowed text-sm text-white/30"
|
||||
disabled
|
||||
title={`Registratie opent op ${REGISTRATION_OPENS_AT.toLocaleString("nl-BE", { day: "numeric", month: "long", hour: "2-digit", minute: "2-digit" })}`}
|
||||
>
|
||||
Nog geen account? (opent{" "}
|
||||
{REGISTRATION_OPENS_AT.toLocaleString("nl-BE", {
|
||||
day: "numeric",
|
||||
month: "long",
|
||||
})}
|
||||
)
|
||||
</button>
|
||||
)}
|
||||
<Link to="/" className="text-sm text-white/60 hover:text-white">
|
||||
← Terug naar website
|
||||
</Link>
|
||||
|
||||
@@ -585,8 +585,10 @@ function ManageRegistrationPage() {
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Payment status - shown for everyone with pending/extra payment or gift */}
|
||||
{(data.paymentStatus !== "paid" || (data.giftAmount ?? 0) > 0) && (
|
||||
{/* Payment status badge:
|
||||
- performers only see a badge if they have a gift to pay, or already paid one
|
||||
- watchers always have a payment (drink card), so always show a badge */}
|
||||
{(isPerformer ? (data.giftAmount ?? 0) > 0 : true) && (
|
||||
<div className="mb-6">
|
||||
{data.paymentStatus === "paid" ? (
|
||||
<PaidBadge />
|
||||
|
||||
154
apps/web/src/routes/reset-password.tsx
Normal file
154
apps/web/src/routes/reset-password.tsx
Normal file
@@ -0,0 +1,154 @@
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import { createFileRoute, Link, useNavigate } from "@tanstack/react-router";
|
||||
import { useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
CardDescription,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from "@/components/ui/card";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { authClient } from "@/lib/auth-client";
|
||||
|
||||
export const Route = createFileRoute("/reset-password")({
|
||||
validateSearch: (search: Record<string, unknown>) => {
|
||||
const token = typeof search.token === "string" ? search.token : undefined;
|
||||
return { ...(token !== undefined && { token }) } as { token?: string };
|
||||
},
|
||||
component: ResetPasswordPage,
|
||||
});
|
||||
|
||||
function ResetPasswordPage() {
|
||||
const navigate = useNavigate();
|
||||
const search = Route.useSearch();
|
||||
const token = search.token;
|
||||
|
||||
const [password, setPassword] = useState("");
|
||||
const [confirm, setConfirm] = useState("");
|
||||
|
||||
const mutation = useMutation({
|
||||
mutationFn: async ({
|
||||
token,
|
||||
newPassword,
|
||||
}: {
|
||||
token: string;
|
||||
newPassword: string;
|
||||
}) => {
|
||||
const result = await authClient.resetPassword({ token, newPassword });
|
||||
if (result.error) {
|
||||
throw new Error(result.error.message);
|
||||
}
|
||||
return result.data;
|
||||
},
|
||||
onSuccess: () => {
|
||||
toast.success("Wachtwoord succesvol gewijzigd!");
|
||||
navigate({ to: "/login" });
|
||||
},
|
||||
});
|
||||
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (password !== confirm) {
|
||||
toast.error("De wachtwoorden komen niet overeen.");
|
||||
return;
|
||||
}
|
||||
if (!token) {
|
||||
toast.error("Ongeldige reset-link. Vraag een nieuwe aan.");
|
||||
return;
|
||||
}
|
||||
mutation.mutate({ token, newPassword: password });
|
||||
};
|
||||
|
||||
if (!token) {
|
||||
return (
|
||||
<div className="flex min-h-[calc(100dvh-2.75rem)] items-center justify-center px-4 sm:min-h-[calc(100dvh-3.5rem)]">
|
||||
<Card className="w-full max-w-md border-white/10 bg-white/5">
|
||||
<CardHeader className="text-center">
|
||||
<CardTitle className="font-['Intro',sans-serif] text-3xl text-white">
|
||||
Ongeldige link
|
||||
</CardTitle>
|
||||
<CardDescription className="text-white/60">
|
||||
Deze reset-link is ongeldig of verlopen.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="text-center">
|
||||
<Link
|
||||
to="/forgot-password"
|
||||
className="text-sm text-white/60 hover:text-white"
|
||||
>
|
||||
Vraag een nieuwe reset-link aan
|
||||
</Link>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex min-h-[calc(100dvh-2.75rem)] items-center justify-center overflow-y-auto px-4 py-8 sm:min-h-[calc(100dvh-3.5rem)]">
|
||||
<Card className="my-auto w-full max-w-md border-white/10 bg-white/5">
|
||||
<CardHeader className="text-center">
|
||||
<CardTitle className="font-['Intro',sans-serif] text-3xl text-white">
|
||||
Nieuw wachtwoord
|
||||
</CardTitle>
|
||||
<CardDescription className="text-white/60">
|
||||
Kies een nieuw wachtwoord voor je account
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<form onSubmit={handleSubmit} className="space-y-4">
|
||||
<div>
|
||||
<label
|
||||
htmlFor="password"
|
||||
className="mb-2 block text-sm text-white/60"
|
||||
>
|
||||
Nieuw wachtwoord
|
||||
</label>
|
||||
<Input
|
||||
id="password"
|
||||
type="password"
|
||||
placeholder="••••••••"
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
required
|
||||
minLength={8}
|
||||
className="border-white/20 bg-white/10 text-white placeholder:text-white/40"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label
|
||||
htmlFor="confirm"
|
||||
className="mb-2 block text-sm text-white/60"
|
||||
>
|
||||
Bevestig wachtwoord
|
||||
</label>
|
||||
<Input
|
||||
id="confirm"
|
||||
type="password"
|
||||
placeholder="••••••••"
|
||||
value={confirm}
|
||||
onChange={(e) => setConfirm(e.target.value)}
|
||||
required
|
||||
minLength={8}
|
||||
className="border-white/20 bg-white/10 text-white placeholder:text-white/40"
|
||||
/>
|
||||
</div>
|
||||
{mutation.isError && (
|
||||
<p className="text-red-400 text-sm">{mutation.error.message}</p>
|
||||
)}
|
||||
<Button
|
||||
type="submit"
|
||||
disabled={mutation.isPending}
|
||||
className="w-full bg-white text-[#214e51] hover:bg-white/90"
|
||||
>
|
||||
{mutation.isPending ? "Bezig..." : "Stel wachtwoord in"}
|
||||
</Button>
|
||||
</form>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
18
apps/web/src/server.ts
Normal file
18
apps/web/src/server.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { runSendReminders } from "@kk/api/routers/index";
|
||||
import {
|
||||
createStartHandler,
|
||||
defaultStreamHandler,
|
||||
} from "@tanstack/react-start/server";
|
||||
|
||||
const fetch = createStartHandler(defaultStreamHandler);
|
||||
|
||||
export default {
|
||||
fetch,
|
||||
async scheduled(
|
||||
_event: { cron: string; scheduledTime: number },
|
||||
_env: Record<string, unknown>,
|
||||
ctx: { waitUntil: (promise: Promise<unknown>) => void },
|
||||
) {
|
||||
ctx.waitUntil(runSendReminders());
|
||||
},
|
||||
};
|
||||
10
bun.lock
10
bun.lock
@@ -42,6 +42,7 @@
|
||||
"@tanstack/react-start": "^1.141.1",
|
||||
"@tanstack/router-plugin": "^1.141.1",
|
||||
"better-auth": "catalog:",
|
||||
"canvas-confetti": "^1.9.4",
|
||||
"class-variance-authority": "^0.7.1",
|
||||
"clsx": "^2.1.1",
|
||||
"dotenv": "catalog:",
|
||||
@@ -68,6 +69,7 @@
|
||||
"@tanstack/react-router-devtools": "^1.141.1",
|
||||
"@testing-library/dom": "^10.4.0",
|
||||
"@testing-library/react": "^16.2.0",
|
||||
"@types/canvas-confetti": "^1.9.0",
|
||||
"@types/qrcode": "^1.5.6",
|
||||
"@types/react": "19.2.7",
|
||||
"@types/react-dom": "19.2.3",
|
||||
@@ -109,10 +111,12 @@
|
||||
"@kk/env": "workspace:*",
|
||||
"better-auth": "catalog:",
|
||||
"dotenv": "catalog:",
|
||||
"nodemailer": "^8.0.2",
|
||||
"zod": "catalog:",
|
||||
},
|
||||
"devDependencies": {
|
||||
"@kk/config": "workspace:*",
|
||||
"@types/nodemailer": "^7.0.11",
|
||||
"typescript": "catalog:",
|
||||
},
|
||||
},
|
||||
@@ -909,6 +913,8 @@
|
||||
|
||||
"@types/babel__traverse": ["@types/babel__traverse@7.28.0", "", { "dependencies": { "@babel/types": "^7.28.2" } }, "sha512-8PvcXf70gTDZBgt9ptxJ8elBeBjcLOAcOtoO/mPJjtji1+CdGbHgm77om1GrsPxsiE+uXIpNSK64UYaIwQXd4Q=="],
|
||||
|
||||
"@types/canvas-confetti": ["@types/canvas-confetti@1.9.0", "", {}, "sha512-aBGj/dULrimR1XDZLtG9JwxX1b4HPRF6CX9Yfwh3NvstZEm1ZL7RBnel4keCPSqs1ANRu1u2Aoz9R+VmtjYuTg=="],
|
||||
|
||||
"@types/draco3d": ["@types/draco3d@1.4.10", "", {}, "sha512-AX22jp8Y7wwaBgAixaSvkoG4M/+PlAcm3Qs4OW8yT9DM4xUpWKeFhLueTAyZF39pviAdcDdeJoACapiAceqNcw=="],
|
||||
|
||||
"@types/estree": ["@types/estree@1.0.8", "", {}, "sha512-dWHzHa2WqEXI/O1E9OjrocMTKJl2mSrEolh1Iomrv6U+JuNwaHXsXx9bLu5gG7BUWFIN0skIQJQ/L1rIex4X6w=="],
|
||||
@@ -1027,6 +1033,8 @@
|
||||
|
||||
"caniuse-lite": ["caniuse-lite@1.0.30001774", "", {}, "sha512-DDdwPGz99nmIEv216hKSgLD+D4ikHQHjBC/seF98N9CPqRX4M5mSxT9eTV6oyisnJcuzxtZy4n17yKKQYmYQOA=="],
|
||||
|
||||
"canvas-confetti": ["canvas-confetti@1.9.4", "", {}, "sha512-yxQbJkAVrFXWNbTUjPqjF7G+g6pDotOUHGbkZq2NELZUMDpiJ85rIEazVb8GTaAptNW2miJAXbs1BtioA251Pw=="],
|
||||
|
||||
"chalk": ["chalk@4.1.2", "", { "dependencies": { "ansi-styles": "^4.1.0", "supports-color": "^7.1.0" } }, "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA=="],
|
||||
|
||||
"cheerio": ["cheerio@1.2.0", "", { "dependencies": { "cheerio-select": "^2.1.0", "dom-serializer": "^2.0.0", "domhandler": "^5.0.3", "domutils": "^3.2.2", "encoding-sniffer": "^0.2.1", "htmlparser2": "^10.1.0", "parse5": "^7.3.0", "parse5-htmlparser2-tree-adapter": "^7.1.0", "parse5-parser-stream": "^7.1.2", "undici": "^7.19.0", "whatwg-mimetype": "^4.0.0" } }, "sha512-WDrybc/gKFpTYQutKIK6UvfcuxijIZfMfXaYm8NMsPQxSYvf+13fXUJ4rztGGbJcBQ/GF55gvrZ0Bc0bj/mqvg=="],
|
||||
@@ -1979,6 +1987,8 @@
|
||||
|
||||
"@jridgewell/remapping/@jridgewell/trace-mapping": ["@jridgewell/trace-mapping@0.3.31", "", { "dependencies": { "@jridgewell/resolve-uri": "^3.1.0", "@jridgewell/sourcemap-codec": "^1.4.14" } }, "sha512-zzNR+SdQSDJzc8joaeP8QQoCQr8NuYx2dIIytl1QeBEZHJ9uW6hebsrYgbz8hJwUQao3TWCMtmfV8Nu1twOLAw=="],
|
||||
|
||||
"@kk/auth/nodemailer": ["nodemailer@8.0.2", "", {}, "sha512-zbj002pZAIkWQFxyAaqoxvn+zoIwRnS40hgjqTXudKOOJkiFFgBeNqjgD3/YCR12sZnrghWYBY+yP1ZucdDRpw=="],
|
||||
|
||||
"@noble/curves/@noble/hashes": ["@noble/hashes@1.8.0", "", {}, "sha512-jCs9ldd7NwzpgXDIf6P3+NrHh9/sD6CQdxHyjQI+h/6rDNo88ypBxxz45UDuZHz9r3tNz7N/VInSVoVdtXEI4A=="],
|
||||
|
||||
"@octokit/plugin-paginate-rest/@octokit/types": ["@octokit/types@13.10.0", "", { "dependencies": { "@octokit/openapi-types": "^24.2.0" } }, "sha512-ifLaO34EbbPj0Xgro4G5lP5asESjwHracYJvVaPIyXMuiuXLlhic3S47cBdTb+jfODkTE5YtGCLt3Ay3+J97sA=="],
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import { env } from "@kk/env/server";
|
||||
import nodemailer from "nodemailer";
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Transport
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// Singleton transport — created once per module, reused across all email sends.
|
||||
// Re-creating it on every call causes EventEmitter listener accumulation in
|
||||
// long-lived Cloudflare Worker processes, triggering memory leak warnings.
|
||||
@@ -27,45 +31,153 @@ function getTransport(): nodemailer.Transporter | null {
|
||||
const from = env.SMTP_FROM ?? "Kunstenkamp <info@kunstenkamp.be>";
|
||||
const baseUrl = env.BETTER_AUTH_URL ?? "https://kunstenkamp.be";
|
||||
|
||||
function registrationConfirmationHtml(params: {
|
||||
firstName: string;
|
||||
manageUrl: string;
|
||||
wantsToPerform: boolean;
|
||||
artForm?: string | null;
|
||||
giftAmount?: number;
|
||||
drinkCardValue?: number;
|
||||
}) {
|
||||
const role = params.wantsToPerform
|
||||
? `Optreden${params.artForm ? ` — ${params.artForm}` : ""}`
|
||||
: "Toeschouwer";
|
||||
// ---------------------------------------------------------------------------
|
||||
// Structured logger
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const giftCents = params.giftAmount ?? 0;
|
||||
// drinkCardValue is stored in euros (e.g., 5), giftAmount in cents (e.g., 5000)
|
||||
const drinkCardCents = (params.drinkCardValue ?? 0) * 100;
|
||||
const hasPayment = drinkCardCents > 0 || giftCents > 0;
|
||||
/**
|
||||
* Emits a single-line JSON log that Cloudflare captures in its invocation
|
||||
* log output (visible in the CF dashboard and via `wrangler tail`).
|
||||
*
|
||||
* Plain `console.warn` / `console.error` calls are NOT surfaced in the CF
|
||||
* dashboard — only `console.log` with a JSON string payload is captured.
|
||||
*/
|
||||
export function emailLog(
|
||||
level: "info" | "warn" | "error",
|
||||
event: string,
|
||||
extra?: Record<string, unknown>,
|
||||
): void {
|
||||
console.log(JSON.stringify({ level, event, ...extra }));
|
||||
}
|
||||
|
||||
const formatEuro = (cents: number) =>
|
||||
`€${(cents / 100).toFixed(cents % 100 === 0 ? 0 : 2).replace(".", ",")}`;
|
||||
// ---------------------------------------------------------------------------
|
||||
// Primitives
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const paymentSummary = hasPayment
|
||||
? `<table width="100%" cellpadding="0" cellspacing="0" style="background:rgba(255,255,255,0.08);border-radius:4px;margin:16px 0;">
|
||||
<tr>
|
||||
<td style="padding:20px 24px;">
|
||||
<p style="margin:0 0 12px;font-size:12px;color:rgba(255,255,255,0.5);text-transform:uppercase;letter-spacing:0.06em;">Betaling</p>
|
||||
${drinkCardCents > 0 ? `<p style="margin:0 0 8px;font-size:16px;color:rgba(255,255,255,0.85);line-height:1.5;">Drinkkaart: <span style="color:#ffffff;font-weight:500;">${formatEuro(drinkCardCents)}</span></p>` : ""}
|
||||
${giftCents > 0 ? `<p style="margin:0 0 8px;font-size:16px;color:rgba(255,255,255,0.85);line-height:1.5;">Vrijwillige gift: <span style="color:#ffffff;font-weight:500;">${formatEuro(giftCents)}</span></p>` : ""}
|
||||
<p style="margin:16px 0 0;padding-top:12px;border-top:1px solid rgba(255,255,255,0.1);font-size:18px;color:#ffffff;font-weight:600;">Totaal: ${formatEuro(drinkCardCents + giftCents)}</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>`
|
||||
: "";
|
||||
/** Format a cent amount as a Euro string, e.g. 500 → "€5", 550 → "€5,50". */
|
||||
function formatEuro(cents: number): string {
|
||||
return `€${(cents / 100).toFixed(cents % 100 === 0 ? 0 : 2).replace(".", ",")}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* A shaded info box with a small uppercase label and a bold value.
|
||||
*
|
||||
* @example
|
||||
* infoBox("Jouw rol", "Optreden — Muziek")
|
||||
* infoBox("Inschrijvingen openen", "maandag 16 maart 2026 om 19:00")
|
||||
*/
|
||||
function infoBox(label: string, value: string): string {
|
||||
return `<table width="100%" cellpadding="0" cellspacing="0" style="background:rgba(255,255,255,0.08);border-radius:4px;margin:24px 0;">
|
||||
<tr>
|
||||
<td style="padding:20px 24px;">
|
||||
<p style="margin:0 0 8px;font-size:12px;color:rgba(255,255,255,0.5);text-transform:uppercase;letter-spacing:0.06em;">${label}</p>
|
||||
<p style="margin:0;font-size:18px;color:#ffffff;font-weight:600;">${value}</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>`;
|
||||
}
|
||||
|
||||
/**
|
||||
* A CTA button.
|
||||
*
|
||||
* - `"primary"` — white background, teal text (main action)
|
||||
* - `"secondary"` — translucent white background, white text (secondary action)
|
||||
*/
|
||||
function ctaButton(
|
||||
href: string,
|
||||
label: string,
|
||||
style: "primary" | "secondary" = "primary",
|
||||
): string {
|
||||
const bg = style === "primary" ? "#ffffff" : "rgba(255,255,255,0.15)";
|
||||
const color = style === "primary" ? "#214e51" : "#ffffff";
|
||||
return `<table cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
<td style="border-radius:2px;background:${bg};">
|
||||
<a href="${href}" style="display:inline-block;padding:14px 32px;font-size:16px;font-weight:600;color:${color};text-decoration:none;">
|
||||
${label}
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>`;
|
||||
}
|
||||
|
||||
/**
|
||||
* A small muted link line rendered below a CTA button, e.g. "Of kopieer deze link: …"
|
||||
*/
|
||||
function ctaSubtext(text: string): string {
|
||||
return `<p style="margin:16px 0 0;font-size:13px;color:rgba(255,255,255,0.4);">${text}</p>`;
|
||||
}
|
||||
|
||||
/**
|
||||
* A standard body paragraph (16 px, 85% white, 1.6 line-height).
|
||||
* Pass raw HTML as the content, e.g. include `<strong>` tags freely.
|
||||
*/
|
||||
function p(content: string): string {
|
||||
return `<p style="margin:0 0 16px;font-size:16px;color:rgba(255,255,255,0.85);line-height:1.6;">${content}</p>`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Payment summary box (drinkcard + gift + total).
|
||||
* Returns an empty string when both amounts are zero.
|
||||
*/
|
||||
function paymentSummaryBox(
|
||||
drinkCardCents: number,
|
||||
giftCents: number,
|
||||
heading = "Betaling",
|
||||
): string {
|
||||
if (drinkCardCents === 0 && giftCents === 0) return "";
|
||||
const total = drinkCardCents + giftCents;
|
||||
return `<table width="100%" cellpadding="0" cellspacing="0" style="background:rgba(255,255,255,0.08);border-radius:4px;margin:16px 0;">
|
||||
<tr>
|
||||
<td style="padding:20px 24px;">
|
||||
<p style="margin:0 0 12px;font-size:12px;color:rgba(255,255,255,0.5);text-transform:uppercase;letter-spacing:0.06em;">${heading}</p>
|
||||
${drinkCardCents > 0 ? `<p style="margin:0 0 8px;font-size:16px;color:rgba(255,255,255,0.85);line-height:1.5;">Drinkkaart: <span style="color:#ffffff;font-weight:500;">${formatEuro(drinkCardCents)}</span></p>` : ""}
|
||||
${giftCents > 0 ? `<p style="margin:0 0 8px;font-size:16px;color:rgba(255,255,255,0.85);line-height:1.5;">Vrijwillige gift: <span style="color:#ffffff;font-weight:500;">${formatEuro(giftCents)}</span></p>` : ""}
|
||||
<p style="margin:16px 0 0;padding-top:12px;border-top:1px solid rgba(255,255,255,0.1);font-size:18px;color:#ffffff;font-weight:600;">Totaal: ${formatEuro(total)}</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>`;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Layout shell
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Wraps content in the full Kunstenkamp email chrome:
|
||||
* outer grey background → teal card → header → body → footer.
|
||||
*
|
||||
* @param title HTML `<title>` value
|
||||
* @param heading Large white `<h1>` in the card header
|
||||
* @param bodyHtml Everything between the header and the footer
|
||||
* @param footerLines Optional extra lines rendered above the default contact
|
||||
* line in the footer (e.g. unsubscribe notice). Pass an
|
||||
* array of plain strings or HTML snippets.
|
||||
* @param headerLabel Small uppercase label above the heading (default: "Kunstenkamp")
|
||||
*/
|
||||
function emailLayout({
|
||||
title,
|
||||
heading,
|
||||
bodyHtml,
|
||||
footerLines = [],
|
||||
headerLabel = "Kunstenkamp",
|
||||
}: {
|
||||
title: string;
|
||||
heading: string;
|
||||
bodyHtml: string;
|
||||
footerLines?: string[];
|
||||
headerLabel?: string;
|
||||
}): string {
|
||||
const extraFooter = footerLines
|
||||
.map((line) => `${line}<br/>`)
|
||||
.join("\n ");
|
||||
|
||||
return `<!DOCTYPE html>
|
||||
<html lang="nl">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Bevestiging inschrijving</title>
|
||||
<title>${title}</title>
|
||||
</head>
|
||||
<body style="margin:0;padding:0;background:#f4f4f5;font-family:sans-serif;">
|
||||
<table width="100%" cellpadding="0" cellspacing="0" style="background:#f4f4f5;padding:40px 0;">
|
||||
@@ -75,51 +187,21 @@ function registrationConfirmationHtml(params: {
|
||||
<!-- Header -->
|
||||
<tr>
|
||||
<td style="padding:40px 48px 32px;">
|
||||
<p style="margin:0;font-size:13px;color:rgba(255,255,255,0.5);letter-spacing:0.08em;text-transform:uppercase;">Kunstenkamp</p>
|
||||
<h1 style="margin:12px 0 0;font-size:28px;color:#ffffff;font-weight:700;">Je inschrijving is bevestigd!</h1>
|
||||
<p style="margin:0;font-size:13px;color:rgba(255,255,255,0.5);letter-spacing:0.08em;text-transform:uppercase;">${headerLabel}</p>
|
||||
<h1 style="margin:12px 0 0;font-size:28px;color:#ffffff;font-weight:700;">${heading}</h1>
|
||||
</td>
|
||||
</tr>
|
||||
<!-- Body -->
|
||||
<tr>
|
||||
<td style="padding:0 48px 32px;">
|
||||
<p style="margin:0 0 16px;font-size:16px;color:rgba(255,255,255,0.85);line-height:1.6;">
|
||||
Hoi ${params.firstName},
|
||||
</p>
|
||||
<p style="margin:0 0 16px;font-size:16px;color:rgba(255,255,255,0.85);line-height:1.6;">
|
||||
We hebben je inschrijving voor <strong style="color:#ffffff;">Open Mic Night — vrijdag 18 april 2026</strong> in goede orde ontvangen.
|
||||
</p>
|
||||
<!-- Registration summary -->
|
||||
<table width="100%" cellpadding="0" cellspacing="0" style="background:rgba(255,255,255,0.08);border-radius:4px;margin:24px 0;">
|
||||
<tr>
|
||||
<td style="padding:20px 24px;">
|
||||
<p style="margin:0 0 8px;font-size:12px;color:rgba(255,255,255,0.5);text-transform:uppercase;letter-spacing:0.06em;">Jouw rol</p>
|
||||
<p style="margin:0;font-size:18px;color:#ffffff;font-weight:600;">${role}</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
${paymentSummary}
|
||||
<p style="margin:0 0 24px;font-size:16px;color:rgba(255,255,255,0.85);line-height:1.6;">
|
||||
Wil je je gegevens later nog aanpassen of je inschrijving annuleren? Gebruik dan de knop hieronder. De link is uniek voor jou — deel hem niet.
|
||||
</p>
|
||||
<!-- CTA button -->
|
||||
<table cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
<td style="border-radius:2px;background:#ffffff;">
|
||||
<a href="${params.manageUrl}" style="display:inline-block;padding:14px 32px;font-size:16px;font-weight:600;color:#214e51;text-decoration:none;">
|
||||
Beheer mijn inschrijving
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p style="margin:16px 0 0;font-size:13px;color:rgba(255,255,255,0.4);">
|
||||
Of kopieer deze link: <span style="color:rgba(255,255,255,0.6);">${params.manageUrl}</span>
|
||||
</p>
|
||||
${bodyHtml}
|
||||
</td>
|
||||
</tr>
|
||||
<!-- Footer -->
|
||||
<tr>
|
||||
<td style="padding:24px 48px;border-top:1px solid rgba(255,255,255,0.1);">
|
||||
<p style="margin:0;font-size:13px;color:rgba(255,255,255,0.4);line-height:1.6;">
|
||||
${extraFooter}
|
||||
Vragen? Mail ons op <a href="mailto:info@kunstenkamp.be" style="color:rgba(255,255,255,0.6);">info@kunstenkamp.be</a><br/>
|
||||
Kunstenkamp vzw — Een initiatief voor en door kunstenaars.
|
||||
</p>
|
||||
@@ -133,6 +215,73 @@ function registrationConfirmationHtml(params: {
|
||||
</html>`;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Shared role / payment helpers
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function roleLabel(wantsToPerform: boolean, artForm?: string | null): string {
|
||||
return wantsToPerform
|
||||
? `Optreden${artForm ? ` — ${artForm}` : ""}`
|
||||
: "Toeschouwer";
|
||||
}
|
||||
|
||||
function toCents(
|
||||
drinkCardValue: number | undefined,
|
||||
giftAmount: number | undefined,
|
||||
): { drinkCardCents: number; giftCents: number } {
|
||||
// drinkCardValue is stored in euros (e.g., 5); giftAmount in cents (e.g., 5000)
|
||||
return {
|
||||
drinkCardCents: (drinkCardValue ?? 0) * 100,
|
||||
giftCents: giftAmount ?? 0,
|
||||
};
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Email composers
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function registrationConfirmationHtml(params: {
|
||||
firstName: string;
|
||||
manageUrl: string;
|
||||
signupUrl: string;
|
||||
wantsToPerform: boolean;
|
||||
artForm?: string | null;
|
||||
giftAmount?: number;
|
||||
drinkCardValue?: number;
|
||||
}): string {
|
||||
const { drinkCardCents, giftCents } = toCents(
|
||||
params.drinkCardValue,
|
||||
params.giftAmount,
|
||||
);
|
||||
|
||||
const body = [
|
||||
p(`Hoi ${params.firstName},`),
|
||||
p(
|
||||
`We hebben je inschrijving voor <strong style="color:#ffffff;">Open Mic Night — vrijdag 18 april 2026</strong> in goede orde ontvangen.`,
|
||||
),
|
||||
infoBox("Jouw rol", roleLabel(params.wantsToPerform, params.artForm)),
|
||||
paymentSummaryBox(drinkCardCents, giftCents),
|
||||
p(
|
||||
"Maak een account aan om je inschrijving te beheren en (voor bezoekers) je Drinkkaart te activeren.",
|
||||
),
|
||||
ctaButton(params.signupUrl, "Account aanmaken"),
|
||||
`<div style="margin-top:16px;"></div>`,
|
||||
p(
|
||||
"Wil je je gegevens later nog aanpassen of je inschrijving annuleren? Gebruik dan de knop hieronder. De link is uniek voor jou — deel hem niet.",
|
||||
),
|
||||
ctaButton(params.manageUrl, "Beheer mijn inschrijving", "secondary"),
|
||||
ctaSubtext(
|
||||
`Of kopieer deze link: <span style="color:rgba(255,255,255,0.6);">${params.manageUrl}</span>`,
|
||||
),
|
||||
].join("\n");
|
||||
|
||||
return emailLayout({
|
||||
title: "Bevestiging inschrijving",
|
||||
heading: "Je inschrijving is bevestigd!",
|
||||
bodyHtml: body,
|
||||
});
|
||||
}
|
||||
|
||||
function updateConfirmationHtml(params: {
|
||||
firstName: string;
|
||||
manageUrl: string;
|
||||
@@ -140,138 +289,199 @@ function updateConfirmationHtml(params: {
|
||||
artForm?: string | null;
|
||||
giftAmount?: number;
|
||||
drinkCardValue?: number;
|
||||
}) {
|
||||
const role = params.wantsToPerform
|
||||
? `Optreden${params.artForm ? ` — ${params.artForm}` : ""}`
|
||||
: "Toeschouwer";
|
||||
}): string {
|
||||
const { drinkCardCents, giftCents } = toCents(
|
||||
params.drinkCardValue,
|
||||
params.giftAmount,
|
||||
);
|
||||
|
||||
const giftCents = params.giftAmount ?? 0;
|
||||
// drinkCardValue is stored in euros (e.g., 5), giftAmount in cents (e.g., 5000)
|
||||
const drinkCardCents = (params.drinkCardValue ?? 0) * 100;
|
||||
const hasPayment = drinkCardCents > 0 || giftCents > 0;
|
||||
const body = [
|
||||
p(`Hoi ${params.firstName},`),
|
||||
p(
|
||||
`Je inschrijving voor <strong style="color:#ffffff;">Open Mic Night — vrijdag 18 april 2026</strong> is succesvol bijgewerkt.`,
|
||||
),
|
||||
infoBox("Jouw rol", roleLabel(params.wantsToPerform, params.artForm)),
|
||||
paymentSummaryBox(drinkCardCents, giftCents),
|
||||
ctaButton(params.manageUrl, "Bekijk mijn inschrijving"),
|
||||
].join("\n");
|
||||
|
||||
const formatEuro = (cents: number) =>
|
||||
`€${(cents / 100).toFixed(cents % 100 === 0 ? 0 : 2).replace(".", ",")}`;
|
||||
|
||||
const paymentSummary = hasPayment
|
||||
? `<table width="100%" cellpadding="0" cellspacing="0" style="background:rgba(255,255,255,0.08);border-radius:4px;margin:16px 0;">
|
||||
<tr>
|
||||
<td style="padding:20px 24px;">
|
||||
<p style="margin:0 0 12px;font-size:12px;color:rgba(255,255,255,0.5);text-transform:uppercase;letter-spacing:0.06em;">Betaling</p>
|
||||
${drinkCardCents > 0 ? `<p style="margin:0 0 8px;font-size:16px;color:rgba(255,255,255,0.85);line-height:1.5;">Drinkkaart: <span style="color:#ffffff;font-weight:500;">${formatEuro(drinkCardCents)}</span></p>` : ""}
|
||||
${giftCents > 0 ? `<p style="margin:0 0 8px;font-size:16px;color:rgba(255,255,255,0.85);line-height:1.5;">Vrijwillige gift: <span style="color:#ffffff;font-weight:500;">${formatEuro(giftCents)}</span></p>` : ""}
|
||||
<p style="margin:16px 0 0;padding-top:12px;border-top:1px solid rgba(255,255,255,0.1);font-size:18px;color:#ffffff;font-weight:600;">Totaal: ${formatEuro(drinkCardCents + giftCents)}</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>`
|
||||
: "";
|
||||
|
||||
return `<!DOCTYPE html>
|
||||
<html lang="nl">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>Inschrijving bijgewerkt</title>
|
||||
</head>
|
||||
<body style="margin:0;padding:0;background:#f4f4f5;font-family:sans-serif;">
|
||||
<table width="100%" cellpadding="0" cellspacing="0" style="background:#f4f4f5;padding:40px 0;">
|
||||
<tr>
|
||||
<td align="center">
|
||||
<table width="600" cellpadding="0" cellspacing="0" style="background:#214e51;border-radius:4px;overflow:hidden;">
|
||||
<tr>
|
||||
<td style="padding:40px 48px 32px;">
|
||||
<p style="margin:0;font-size:13px;color:rgba(255,255,255,0.5);letter-spacing:0.08em;text-transform:uppercase;">Kunstenkamp</p>
|
||||
<h1 style="margin:12px 0 0;font-size:28px;color:#ffffff;font-weight:700;">Inschrijving bijgewerkt</h1>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding:0 48px 32px;">
|
||||
<p style="margin:0 0 16px;font-size:16px;color:rgba(255,255,255,0.85);line-height:1.6;">
|
||||
Hoi ${params.firstName},
|
||||
</p>
|
||||
<p style="margin:0 0 16px;font-size:16px;color:rgba(255,255,255,0.85);line-height:1.6;">
|
||||
Je inschrijving voor <strong style="color:#ffffff;">Open Mic Night — vrijdag 18 april 2026</strong> is succesvol bijgewerkt.
|
||||
</p>
|
||||
<table width="100%" cellpadding="0" cellspacing="0" style="background:rgba(255,255,255,0.08);border-radius:4px;margin:24px 0;">
|
||||
<tr>
|
||||
<td style="padding:20px 24px;">
|
||||
<p style="margin:0 0 8px;font-size:12px;color:rgba(255,255,255,0.5);text-transform:uppercase;letter-spacing:0.06em;">Jouw rol</p>
|
||||
<p style="margin:0;font-size:18px;color:#ffffff;font-weight:600;">${role}</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
${paymentSummary}
|
||||
<table cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
<td style="border-radius:2px;background:#ffffff;">
|
||||
<a href="${params.manageUrl}" style="display:inline-block;padding:14px 32px;font-size:16px;font-weight:600;color:#214e51;text-decoration:none;">
|
||||
Bekijk mijn inschrijving
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding:24px 48px;border-top:1px solid rgba(255,255,255,0.1);">
|
||||
<p style="margin:0;font-size:13px;color:rgba(255,255,255,0.4);">
|
||||
Vragen? Mail ons op <a href="mailto:info@kunstenkamp.be" style="color:rgba(255,255,255,0.6);">info@kunstenkamp.be</a>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>`;
|
||||
return emailLayout({
|
||||
title: "Inschrijving bijgewerkt",
|
||||
heading: "Inschrijving bijgewerkt",
|
||||
bodyHtml: body,
|
||||
});
|
||||
}
|
||||
|
||||
function cancellationHtml(params: { firstName: string }) {
|
||||
return `<!DOCTYPE html>
|
||||
<html lang="nl">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>Inschrijving geannuleerd</title>
|
||||
</head>
|
||||
<body style="margin:0;padding:0;background:#f4f4f5;font-family:sans-serif;">
|
||||
<table width="100%" cellpadding="0" cellspacing="0" style="background:#f4f4f5;padding:40px 0;">
|
||||
<tr>
|
||||
<td align="center">
|
||||
<table width="600" cellpadding="0" cellspacing="0" style="background:#214e51;border-radius:4px;overflow:hidden;">
|
||||
<tr>
|
||||
<td style="padding:40px 48px 32px;">
|
||||
<p style="margin:0;font-size:13px;color:rgba(255,255,255,0.5);letter-spacing:0.08em;text-transform:uppercase;">Kunstenkamp</p>
|
||||
<h1 style="margin:12px 0 0;font-size:28px;color:#ffffff;font-weight:700;">Inschrijving geannuleerd</h1>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding:0 48px 40px;">
|
||||
<p style="margin:0 0 16px;font-size:16px;color:rgba(255,255,255,0.85);line-height:1.6;">
|
||||
Hoi ${params.firstName},
|
||||
</p>
|
||||
<p style="margin:0 0 16px;font-size:16px;color:rgba(255,255,255,0.85);line-height:1.6;">
|
||||
Je inschrijving voor <strong style="color:#ffffff;">Open Mic Night — vrijdag 18 april 2026</strong> is geannuleerd.
|
||||
</p>
|
||||
<p style="margin:0;font-size:16px;color:rgba(255,255,255,0.85);line-height:1.6;">
|
||||
Van gedachten veranderd? Je kunt je altijd opnieuw inschrijven via <a href="${baseUrl}/#registration" style="color:#ffffff;">kunstenkamp.be</a>.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding:24px 48px;border-top:1px solid rgba(255,255,255,0.1);">
|
||||
<p style="margin:0;font-size:13px;color:rgba(255,255,255,0.4);">
|
||||
Vragen? Mail ons op <a href="mailto:info@kunstenkamp.be" style="color:rgba(255,255,255,0.6);">info@kunstenkamp.be</a>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>`;
|
||||
function cancellationHtml(params: { firstName: string }): string {
|
||||
const body = [
|
||||
p(`Hoi ${params.firstName},`),
|
||||
p(
|
||||
`Je inschrijving voor <strong style="color:#ffffff;">Open Mic Night — vrijdag 18 april 2026</strong> is geannuleerd.`,
|
||||
),
|
||||
p(
|
||||
`Van gedachten veranderd? Je kunt je altijd opnieuw inschrijven via <a href="${baseUrl}/#registration" style="color:#ffffff;">kunstenkamp.be</a>.`,
|
||||
),
|
||||
].join("\n");
|
||||
|
||||
return emailLayout({
|
||||
title: "Inschrijving geannuleerd",
|
||||
heading: "Inschrijving geannuleerd",
|
||||
bodyHtml: body,
|
||||
});
|
||||
}
|
||||
|
||||
function reminder24hHtml(params: { firstName?: string | null }): string {
|
||||
const greeting = params.firstName ? `Hoi ${params.firstName},` : "Hoi!";
|
||||
const openDateStr = "maandag 16 maart 2026 om 19:00";
|
||||
const registrationUrl = `${baseUrl}/#registration`;
|
||||
|
||||
const body = [
|
||||
p(greeting),
|
||||
p(
|
||||
`Morgen openen de inschrijvingen voor <strong style="color:#ffffff;">Open Mic Night — vrijdag 18 april 2026</strong>. Zet je wekker!`,
|
||||
),
|
||||
infoBox("Inschrijvingen openen", openDateStr),
|
||||
p("Wees er snel bij — de plaatsen zijn beperkt!"),
|
||||
ctaButton(registrationUrl, "Bekijk de pagina"),
|
||||
ctaSubtext(
|
||||
`Of ga naar: <span style="color:rgba(255,255,255,0.6);">${registrationUrl}</span>`,
|
||||
),
|
||||
].join("\n");
|
||||
|
||||
return emailLayout({
|
||||
title: "Nog 24 uur — inschrijvingen openen morgen!",
|
||||
heading: "Nog 24 uur!",
|
||||
bodyHtml: body,
|
||||
footerLines: [
|
||||
"Je ontvangt dit bericht omdat je een herinnering hebt aangevraagd.",
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
function reminderHtml(params: { firstName?: string | null }): string {
|
||||
const greeting = params.firstName ? `Hoi ${params.firstName},` : "Hoi!";
|
||||
const openDateStr = "maandag 16 maart 2026 om 19:00";
|
||||
const registrationUrl = `${baseUrl}/#registration`;
|
||||
|
||||
const body = [
|
||||
p(greeting),
|
||||
p(
|
||||
`Over ongeveer <strong style="color:#ffffff;">1 uur</strong> openen de inschrijvingen voor <strong style="color:#ffffff;">Open Mic Night — vrijdag 18 april 2026</strong>.`,
|
||||
),
|
||||
infoBox("Inschrijvingen openen", openDateStr),
|
||||
p("Wees er snel bij — de plaatsen zijn beperkt!"),
|
||||
ctaButton(registrationUrl, "Schrijf je in"),
|
||||
ctaSubtext(
|
||||
`Of ga naar: <span style="color:rgba(255,255,255,0.6);">${registrationUrl}</span>`,
|
||||
),
|
||||
].join("\n");
|
||||
|
||||
return emailLayout({
|
||||
title: "Nog 1 uur — inschrijvingen openen straks!",
|
||||
heading: "Nog 1 uur!",
|
||||
bodyHtml: body,
|
||||
footerLines: [
|
||||
"Je ontvangt dit bericht omdat je een herinnering hebt aangevraagd.",
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
function subscriptionConfirmationHtml(params: { email: string }): string {
|
||||
const openDateStr = "maandag 16 maart 2026 om 19:00";
|
||||
const registrationUrl = `${baseUrl}/#registration`;
|
||||
|
||||
const body = [
|
||||
p(
|
||||
`We sturen een herinnering naar <strong style="color:#ffffff;">${params.email}</strong> wanneer de inschrijvingen openen.`,
|
||||
),
|
||||
infoBox("Inschrijvingen openen", openDateStr),
|
||||
p(
|
||||
"Je ontvangt twee herinneringen: één 24 uur van tevoren en één 1 uur voor de opening.",
|
||||
),
|
||||
p("Wees er snel bij — de plaatsen zijn beperkt!"),
|
||||
ctaButton(registrationUrl, "Bekijk de pagina"),
|
||||
].join("\n");
|
||||
|
||||
return emailLayout({
|
||||
title: "Herinnering ingepland — Open Mic Night",
|
||||
heading: "Je herinnering is ingepland!",
|
||||
bodyHtml: body,
|
||||
footerLines: [
|
||||
"Je ontvangt dit bericht omdat je een herinnering hebt aangevraagd op kunstenkamp.be.",
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
function paymentReminderHtml(params: {
|
||||
firstName: string;
|
||||
accountUrl: string;
|
||||
manageUrl: string;
|
||||
drinkCardValue?: number;
|
||||
giftAmount?: number;
|
||||
}): string {
|
||||
const { drinkCardCents, giftCents } = toCents(
|
||||
params.drinkCardValue,
|
||||
params.giftAmount,
|
||||
);
|
||||
const totalCents = drinkCardCents + giftCents;
|
||||
|
||||
const amountLine =
|
||||
totalCents > 0
|
||||
? p(
|
||||
`Je betaling van <strong style="color:#ffffff;">${formatEuro(totalCents)}</strong> staat nog open. Log in op je account om te betalen.`,
|
||||
)
|
||||
: p("Je betaling staat nog open. Log in op je account om te betalen.");
|
||||
|
||||
const body = [
|
||||
p(`Hoi ${params.firstName},`),
|
||||
p(
|
||||
`Je hebt je ingeschreven voor <strong style="color:#ffffff;">Open Mic Night — vrijdag 18 april 2026</strong>, maar we hebben nog geen betaling ontvangen.`,
|
||||
),
|
||||
amountLine,
|
||||
ctaButton(params.accountUrl, "Betaal nu"),
|
||||
ctaSubtext(
|
||||
`Je inschrijving beheren? <a href="${params.manageUrl}" style="color:rgba(255,255,255,0.6);">Klik hier</a>`,
|
||||
),
|
||||
].join("\n");
|
||||
|
||||
return emailLayout({
|
||||
title: "Herinnering: betaling open",
|
||||
heading: "Betaling nog open",
|
||||
bodyHtml: body,
|
||||
});
|
||||
}
|
||||
|
||||
function paymentConfirmationHtml(params: {
|
||||
firstName: string;
|
||||
manageUrl: string;
|
||||
drinkCardValue?: number;
|
||||
giftAmount?: number;
|
||||
}): string {
|
||||
const { drinkCardCents, giftCents } = toCents(
|
||||
params.drinkCardValue,
|
||||
params.giftAmount,
|
||||
);
|
||||
|
||||
const body = [
|
||||
p(`Hoi ${params.firstName},`),
|
||||
p(
|
||||
`We hebben je betaling voor <strong style="color:#ffffff;">Open Mic Night — vrijdag 18 april 2026</strong> in goede orde ontvangen. Tot dan!`,
|
||||
),
|
||||
paymentSummaryBox(drinkCardCents, giftCents, "Betaling ontvangen"),
|
||||
ctaButton(params.manageUrl, "Beheer mijn inschrijving", "secondary"),
|
||||
].join("\n");
|
||||
|
||||
return emailLayout({
|
||||
title: "Betaling ontvangen",
|
||||
heading: "Betaling ontvangen!",
|
||||
bodyHtml: body,
|
||||
});
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Public send functions
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export async function sendConfirmationEmail(params: {
|
||||
to: string;
|
||||
firstName: string;
|
||||
@@ -280,26 +490,48 @@ export async function sendConfirmationEmail(params: {
|
||||
artForm?: string | null;
|
||||
giftAmount?: number;
|
||||
drinkCardValue?: number;
|
||||
/** Pre-filled signup URL, e.g. /login?signup=1&email=…&next=/account */
|
||||
signupUrl?: string;
|
||||
}) {
|
||||
const type = "registrationConfirmation";
|
||||
emailLog("info", "email.attempt", { type, to: params.to });
|
||||
const transport = getTransport();
|
||||
if (!transport) {
|
||||
console.warn("SMTP not configured — skipping confirmation email");
|
||||
emailLog("warn", "email.skipped", {
|
||||
type,
|
||||
to: params.to,
|
||||
reason: "smtp_not_configured",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const manageUrl = `${baseUrl}/manage/${params.managementToken}`;
|
||||
await transport.sendMail({
|
||||
from,
|
||||
to: params.to,
|
||||
subject: "Bevestiging inschrijving — Open Mic Night",
|
||||
html: registrationConfirmationHtml({
|
||||
firstName: params.firstName,
|
||||
manageUrl,
|
||||
wantsToPerform: params.wantsToPerform,
|
||||
artForm: params.artForm,
|
||||
giftAmount: params.giftAmount,
|
||||
drinkCardValue: params.drinkCardValue,
|
||||
}),
|
||||
});
|
||||
const signupUrl =
|
||||
params.signupUrl ??
|
||||
`${baseUrl}/login?signup=1&email=${encodeURIComponent(params.to)}&next=/account`;
|
||||
try {
|
||||
await transport.sendMail({
|
||||
from,
|
||||
to: params.to,
|
||||
subject: "Bevestiging inschrijving — Open Mic Night",
|
||||
html: registrationConfirmationHtml({
|
||||
firstName: params.firstName,
|
||||
manageUrl,
|
||||
signupUrl,
|
||||
wantsToPerform: params.wantsToPerform,
|
||||
artForm: params.artForm,
|
||||
giftAmount: params.giftAmount,
|
||||
drinkCardValue: params.drinkCardValue,
|
||||
}),
|
||||
});
|
||||
emailLog("info", "email.sent", { type, to: params.to });
|
||||
} catch (err) {
|
||||
emailLog("error", "email.error", {
|
||||
type,
|
||||
to: params.to,
|
||||
error: String(err),
|
||||
});
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
export async function sendUpdateEmail(params: {
|
||||
@@ -311,40 +543,256 @@ export async function sendUpdateEmail(params: {
|
||||
giftAmount?: number;
|
||||
drinkCardValue?: number;
|
||||
}) {
|
||||
const type = "updateConfirmation";
|
||||
emailLog("info", "email.attempt", { type, to: params.to });
|
||||
const transport = getTransport();
|
||||
if (!transport) {
|
||||
console.warn("SMTP not configured — skipping update email");
|
||||
emailLog("warn", "email.skipped", {
|
||||
type,
|
||||
to: params.to,
|
||||
reason: "smtp_not_configured",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const manageUrl = `${baseUrl}/manage/${params.managementToken}`;
|
||||
await transport.sendMail({
|
||||
from,
|
||||
to: params.to,
|
||||
subject: "Inschrijving bijgewerkt — Open Mic Night",
|
||||
html: updateConfirmationHtml({
|
||||
firstName: params.firstName,
|
||||
manageUrl,
|
||||
wantsToPerform: params.wantsToPerform,
|
||||
artForm: params.artForm,
|
||||
giftAmount: params.giftAmount,
|
||||
drinkCardValue: params.drinkCardValue,
|
||||
}),
|
||||
});
|
||||
try {
|
||||
await transport.sendMail({
|
||||
from,
|
||||
to: params.to,
|
||||
subject: "Inschrijving bijgewerkt — Open Mic Night",
|
||||
html: updateConfirmationHtml({
|
||||
firstName: params.firstName,
|
||||
manageUrl,
|
||||
wantsToPerform: params.wantsToPerform,
|
||||
artForm: params.artForm,
|
||||
giftAmount: params.giftAmount,
|
||||
drinkCardValue: params.drinkCardValue,
|
||||
}),
|
||||
});
|
||||
emailLog("info", "email.sent", { type, to: params.to });
|
||||
} catch (err) {
|
||||
emailLog("error", "email.error", {
|
||||
type,
|
||||
to: params.to,
|
||||
error: String(err),
|
||||
});
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
export async function sendCancellationEmail(params: {
|
||||
to: string;
|
||||
firstName: string;
|
||||
}) {
|
||||
const type = "cancellation";
|
||||
emailLog("info", "email.attempt", { type, to: params.to });
|
||||
const transport = getTransport();
|
||||
if (!transport) {
|
||||
console.warn("SMTP not configured — skipping cancellation email");
|
||||
emailLog("warn", "email.skipped", {
|
||||
type,
|
||||
to: params.to,
|
||||
reason: "smtp_not_configured",
|
||||
});
|
||||
return;
|
||||
}
|
||||
await transport.sendMail({
|
||||
from,
|
||||
to: params.to,
|
||||
subject: "Inschrijving geannuleerd — Open Mic Night",
|
||||
html: cancellationHtml({ firstName: params.firstName }),
|
||||
});
|
||||
try {
|
||||
await transport.sendMail({
|
||||
from,
|
||||
to: params.to,
|
||||
subject: "Inschrijving geannuleerd — Open Mic Night",
|
||||
html: cancellationHtml({ firstName: params.firstName }),
|
||||
});
|
||||
emailLog("info", "email.sent", { type, to: params.to });
|
||||
} catch (err) {
|
||||
emailLog("error", "email.error", {
|
||||
type,
|
||||
to: params.to,
|
||||
error: String(err),
|
||||
});
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
export async function sendSubscriptionConfirmationEmail(params: {
|
||||
to: string;
|
||||
}) {
|
||||
const type = "subscriptionConfirmation";
|
||||
emailLog("info", "email.attempt", { type, to: params.to });
|
||||
const transport = getTransport();
|
||||
if (!transport) {
|
||||
emailLog("warn", "email.skipped", {
|
||||
type,
|
||||
to: params.to,
|
||||
reason: "smtp_not_configured",
|
||||
});
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await transport.sendMail({
|
||||
from,
|
||||
to: params.to,
|
||||
subject: "Herinnering ingepland — Open Mic Night",
|
||||
html: subscriptionConfirmationHtml({ email: params.to }),
|
||||
});
|
||||
emailLog("info", "email.sent", { type, to: params.to });
|
||||
} catch (err) {
|
||||
emailLog("error", "email.error", {
|
||||
type,
|
||||
to: params.to,
|
||||
error: String(err),
|
||||
});
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
export async function sendReminder24hEmail(params: {
|
||||
to: string;
|
||||
firstName?: string | null;
|
||||
}) {
|
||||
const type = "reminder24h";
|
||||
emailLog("info", "email.attempt", { type, to: params.to });
|
||||
const transport = getTransport();
|
||||
if (!transport) {
|
||||
emailLog("warn", "email.skipped", {
|
||||
type,
|
||||
to: params.to,
|
||||
reason: "smtp_not_configured",
|
||||
});
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await transport.sendMail({
|
||||
from,
|
||||
to: params.to,
|
||||
subject: "Nog 24 uur — inschrijvingen openen morgen!",
|
||||
html: reminder24hHtml({ firstName: params.firstName }),
|
||||
});
|
||||
emailLog("info", "email.sent", { type, to: params.to });
|
||||
} catch (err) {
|
||||
emailLog("error", "email.error", {
|
||||
type,
|
||||
to: params.to,
|
||||
error: String(err),
|
||||
});
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
export async function sendReminderEmail(params: {
|
||||
to: string;
|
||||
firstName?: string | null;
|
||||
}) {
|
||||
const type = "reminder1h";
|
||||
emailLog("info", "email.attempt", { type, to: params.to });
|
||||
const transport = getTransport();
|
||||
if (!transport) {
|
||||
emailLog("warn", "email.skipped", {
|
||||
type,
|
||||
to: params.to,
|
||||
reason: "smtp_not_configured",
|
||||
});
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await transport.sendMail({
|
||||
from,
|
||||
to: params.to,
|
||||
subject: "Nog 1 uur — inschrijvingen openen straks!",
|
||||
html: reminderHtml({ firstName: params.firstName }),
|
||||
});
|
||||
emailLog("info", "email.sent", { type, to: params.to });
|
||||
} catch (err) {
|
||||
emailLog("error", "email.error", {
|
||||
type,
|
||||
to: params.to,
|
||||
error: String(err),
|
||||
});
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
export async function sendPaymentReminderEmail(params: {
|
||||
to: string;
|
||||
firstName: string;
|
||||
managementToken: string;
|
||||
drinkCardValue?: number;
|
||||
giftAmount?: number;
|
||||
}) {
|
||||
const type = "paymentReminder";
|
||||
emailLog("info", "email.attempt", { type, to: params.to });
|
||||
const transport = getTransport();
|
||||
if (!transport) {
|
||||
emailLog("warn", "email.skipped", {
|
||||
type,
|
||||
to: params.to,
|
||||
reason: "smtp_not_configured",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const accountUrl = `${baseUrl}/account`;
|
||||
const manageUrl = `${baseUrl}/manage/${params.managementToken}`;
|
||||
try {
|
||||
await transport.sendMail({
|
||||
from,
|
||||
to: params.to,
|
||||
subject: "Herinnering: betaling open — Open Mic Night",
|
||||
html: paymentReminderHtml({
|
||||
firstName: params.firstName,
|
||||
accountUrl,
|
||||
manageUrl,
|
||||
drinkCardValue: params.drinkCardValue,
|
||||
giftAmount: params.giftAmount,
|
||||
}),
|
||||
});
|
||||
emailLog("info", "email.sent", { type, to: params.to });
|
||||
} catch (err) {
|
||||
emailLog("error", "email.error", {
|
||||
type,
|
||||
to: params.to,
|
||||
error: String(err),
|
||||
});
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
export async function sendPaymentConfirmationEmail(params: {
|
||||
to: string;
|
||||
firstName: string;
|
||||
managementToken: string;
|
||||
drinkCardValue?: number;
|
||||
giftAmount?: number;
|
||||
}) {
|
||||
const type = "paymentConfirmation";
|
||||
emailLog("info", "email.attempt", { type, to: params.to });
|
||||
const transport = getTransport();
|
||||
if (!transport) {
|
||||
emailLog("warn", "email.skipped", {
|
||||
type,
|
||||
to: params.to,
|
||||
reason: "smtp_not_configured",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const manageUrl = `${baseUrl}/manage/${params.managementToken}`;
|
||||
try {
|
||||
await transport.sendMail({
|
||||
from,
|
||||
to: params.to,
|
||||
subject: "Betaling ontvangen — Open Mic Night",
|
||||
html: paymentConfirmationHtml({
|
||||
firstName: params.firstName,
|
||||
manageUrl,
|
||||
drinkCardValue: params.drinkCardValue,
|
||||
giftAmount: params.giftAmount,
|
||||
}),
|
||||
});
|
||||
emailLog("info", "email.sent", { type, to: params.to });
|
||||
} catch (err) {
|
||||
emailLog("error", "email.error", {
|
||||
type,
|
||||
to: params.to,
|
||||
error: String(err),
|
||||
});
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,49 @@
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { db } from "@kk/db";
|
||||
import { adminRequest, registration } from "@kk/db/schema";
|
||||
import { adminRequest, registration, reminder } from "@kk/db/schema";
|
||||
import { user } from "@kk/db/schema/auth";
|
||||
import { drinkkaart, drinkkaartTopup } from "@kk/db/schema/drinkkaart";
|
||||
import { env } from "@kk/env/server";
|
||||
import type { RouterClient } from "@orpc/server";
|
||||
import { and, count, desc, eq, gte, isNull, like, lte, sum } from "drizzle-orm";
|
||||
import {
|
||||
and,
|
||||
count,
|
||||
desc,
|
||||
eq,
|
||||
gte,
|
||||
isNull,
|
||||
like,
|
||||
lte,
|
||||
or,
|
||||
sum,
|
||||
} from "drizzle-orm";
|
||||
import { z } from "zod";
|
||||
import {
|
||||
emailLog,
|
||||
sendCancellationEmail,
|
||||
sendConfirmationEmail,
|
||||
sendPaymentReminderEmail,
|
||||
sendReminder24hEmail,
|
||||
sendReminderEmail,
|
||||
sendSubscriptionConfirmationEmail,
|
||||
sendUpdateEmail,
|
||||
} from "../email";
|
||||
import { adminProcedure, protectedProcedure, publicProcedure } from "../index";
|
||||
import { generateQrSecret } from "../lib/drinkkaart-utils";
|
||||
import { drinkkaartRouter } from "./drinkkaart";
|
||||
|
||||
// Registration opens at this date — reminders fire 24 hours and 1 hour before
|
||||
const REGISTRATION_OPENS_AT = new Date("2026-03-16T19:00:00+01:00");
|
||||
const REMINDER_1H_WINDOW_START = new Date(
|
||||
REGISTRATION_OPENS_AT.getTime() - 60 * 60 * 1000,
|
||||
);
|
||||
const REMINDER_24H_WINDOW_START = new Date(
|
||||
REGISTRATION_OPENS_AT.getTime() - 25 * 60 * 60 * 1000,
|
||||
);
|
||||
const REMINDER_24H_WINDOW_END = new Date(
|
||||
REGISTRATION_OPENS_AT.getTime() - 23 * 60 * 60 * 1000,
|
||||
);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Shared helpers
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -297,7 +325,10 @@ export const appRouter = {
|
||||
giftAmount: input.giftAmount,
|
||||
drinkCardValue: isPerformer ? 0 : drinkCardEuros(guests.length),
|
||||
}).catch((err) =>
|
||||
console.error("Failed to send confirmation email:", err),
|
||||
emailLog("error", "email.catch", {
|
||||
type: "confirmation",
|
||||
error: String(err),
|
||||
}),
|
||||
);
|
||||
|
||||
return { success: true, managementToken };
|
||||
@@ -385,7 +416,12 @@ export const appRouter = {
|
||||
artForm: input.artForm,
|
||||
giftAmount: input.giftAmount,
|
||||
drinkCardValue: isPerformer ? 0 : drinkCardEuros(guests.length),
|
||||
}).catch((err) => console.error("Failed to send update email:", err));
|
||||
}).catch((err) =>
|
||||
emailLog("error", "email.catch", {
|
||||
type: "update",
|
||||
error: String(err),
|
||||
}),
|
||||
);
|
||||
|
||||
return { success: true };
|
||||
}),
|
||||
@@ -404,7 +440,10 @@ export const appRouter = {
|
||||
to: row.email,
|
||||
firstName: row.firstName,
|
||||
}).catch((err) =>
|
||||
console.error("Failed to send cancellation email:", err),
|
||||
emailLog("error", "email.catch", {
|
||||
type: "cancellation",
|
||||
error: String(err),
|
||||
}),
|
||||
);
|
||||
|
||||
return { success: true };
|
||||
@@ -418,7 +457,7 @@ export const appRouter = {
|
||||
if (input.search) {
|
||||
const term = `%${input.search}%`;
|
||||
conditions.push(
|
||||
and(
|
||||
or(
|
||||
like(registration.firstName, term),
|
||||
like(registration.lastName, term),
|
||||
like(registration.email, term),
|
||||
@@ -466,27 +505,49 @@ export const appRouter = {
|
||||
const today = new Date();
|
||||
today.setHours(0, 0, 0, 0);
|
||||
|
||||
const [totalResult, todayResult, artFormResult, typeResult, giftResult] =
|
||||
await Promise.all([
|
||||
db.select({ count: count() }).from(registration),
|
||||
db
|
||||
.select({ count: count() })
|
||||
.from(registration)
|
||||
.where(gte(registration.createdAt, today)),
|
||||
db
|
||||
.select({ artForm: registration.artForm, count: count() })
|
||||
.from(registration)
|
||||
.where(eq(registration.registrationType, "performer"))
|
||||
.groupBy(registration.artForm),
|
||||
db
|
||||
.select({
|
||||
registrationType: registration.registrationType,
|
||||
count: count(),
|
||||
})
|
||||
.from(registration)
|
||||
.groupBy(registration.registrationType),
|
||||
db.select({ total: sum(registration.giftAmount) }).from(registration),
|
||||
]);
|
||||
const [
|
||||
totalResult,
|
||||
todayResult,
|
||||
artFormResult,
|
||||
typeResult,
|
||||
giftResult,
|
||||
watcherGuestRows,
|
||||
] = await Promise.all([
|
||||
db.select({ count: count() }).from(registration),
|
||||
db
|
||||
.select({ count: count() })
|
||||
.from(registration)
|
||||
.where(gte(registration.createdAt, today)),
|
||||
db
|
||||
.select({ artForm: registration.artForm, count: count() })
|
||||
.from(registration)
|
||||
.where(eq(registration.registrationType, "performer"))
|
||||
.groupBy(registration.artForm),
|
||||
db
|
||||
.select({
|
||||
registrationType: registration.registrationType,
|
||||
count: count(),
|
||||
})
|
||||
.from(registration)
|
||||
.groupBy(registration.registrationType),
|
||||
db.select({ total: sum(registration.giftAmount) }).from(registration),
|
||||
// Fetch guests column for all watcher registrations to count total guests
|
||||
db
|
||||
.select({ guests: registration.guests })
|
||||
.from(registration)
|
||||
.where(
|
||||
and(
|
||||
eq(registration.registrationType, "watcher"),
|
||||
isNull(registration.cancelledAt),
|
||||
),
|
||||
),
|
||||
]);
|
||||
|
||||
// Sum up all guest counts across all watcher registrations
|
||||
const totalGuestCount = watcherGuestRows.reduce((sum, r) => {
|
||||
const guests = parseGuestsJson(r.guests);
|
||||
return sum + guests.length;
|
||||
}, 0);
|
||||
|
||||
return {
|
||||
total: totalResult[0]?.count ?? 0,
|
||||
@@ -500,6 +561,7 @@ export const appRouter = {
|
||||
count: r.count,
|
||||
})),
|
||||
totalGiftRevenue: giftResult[0]?.total ?? 0,
|
||||
totalGuestCount,
|
||||
};
|
||||
}),
|
||||
|
||||
@@ -509,6 +571,9 @@ export const appRouter = {
|
||||
.from(registration)
|
||||
.orderBy(desc(registration.createdAt));
|
||||
|
||||
const escapeCell = (val: string) => `"${val.replace(/"/g, '""')}"`;
|
||||
|
||||
// Main registration headers
|
||||
const headers = [
|
||||
"ID",
|
||||
"First Name",
|
||||
@@ -519,49 +584,97 @@ export const appRouter = {
|
||||
"Art Form",
|
||||
"Experience",
|
||||
"Is Over 16",
|
||||
"Drink Card Value",
|
||||
"Gift Amount",
|
||||
"Drink Card Value (EUR)",
|
||||
"Gift Amount (cents)",
|
||||
"Guest Count",
|
||||
"Guests",
|
||||
"Guest 1 First Name",
|
||||
"Guest 1 Last Name",
|
||||
"Guest 1 Email",
|
||||
"Guest 1 Phone",
|
||||
"Guest 2 First Name",
|
||||
"Guest 2 Last Name",
|
||||
"Guest 2 Email",
|
||||
"Guest 2 Phone",
|
||||
"Guest 3 First Name",
|
||||
"Guest 3 Last Name",
|
||||
"Guest 3 Email",
|
||||
"Guest 3 Phone",
|
||||
"Guest 4 First Name",
|
||||
"Guest 4 Last Name",
|
||||
"Guest 4 Email",
|
||||
"Guest 4 Phone",
|
||||
"Guest 5 First Name",
|
||||
"Guest 5 Last Name",
|
||||
"Guest 5 Email",
|
||||
"Guest 5 Phone",
|
||||
"Guest 6 First Name",
|
||||
"Guest 6 Last Name",
|
||||
"Guest 6 Email",
|
||||
"Guest 6 Phone",
|
||||
"Guest 7 First Name",
|
||||
"Guest 7 Last Name",
|
||||
"Guest 7 Email",
|
||||
"Guest 7 Phone",
|
||||
"Guest 8 First Name",
|
||||
"Guest 8 Last Name",
|
||||
"Guest 8 Email",
|
||||
"Guest 8 Phone",
|
||||
"Guest 9 First Name",
|
||||
"Guest 9 Last Name",
|
||||
"Guest 9 Email",
|
||||
"Guest 9 Phone",
|
||||
"Payment Status",
|
||||
"Paid At",
|
||||
"Extra Questions",
|
||||
"Cancelled At",
|
||||
"Created At",
|
||||
];
|
||||
|
||||
const MAX_GUESTS = 9;
|
||||
|
||||
const rows = data.map((r) => {
|
||||
const guests = parseGuestsJson(r.guests);
|
||||
const guestSummary = guests
|
||||
.map(
|
||||
(g) =>
|
||||
`${g.firstName} ${g.lastName}${g.email ? ` <${g.email}>` : ""}${g.phone ? ` (${g.phone})` : ""}`,
|
||||
)
|
||||
.join(" | ");
|
||||
|
||||
// Build guest columns (up to 9 guests, 4 fields each)
|
||||
const guestCols: string[] = [];
|
||||
for (let i = 0; i < MAX_GUESTS; i++) {
|
||||
const g = guests[i];
|
||||
guestCols.push(g?.firstName ?? "");
|
||||
guestCols.push(g?.lastName ?? "");
|
||||
guestCols.push(g?.email ?? "");
|
||||
guestCols.push(g?.phone ?? "");
|
||||
}
|
||||
|
||||
return [
|
||||
r.id,
|
||||
r.firstName,
|
||||
r.lastName,
|
||||
r.email,
|
||||
r.phone || "",
|
||||
r.registrationType,
|
||||
r.registrationType ?? "",
|
||||
r.artForm || "",
|
||||
r.experience || "",
|
||||
r.isOver16 ? "Yes" : "No",
|
||||
String(r.drinkCardValue ?? 0),
|
||||
String(r.giftAmount ?? 0),
|
||||
String(guests.length),
|
||||
guestSummary,
|
||||
r.paymentStatus === "paid" ? "Paid" : "Pending",
|
||||
...guestCols,
|
||||
r.paymentStatus === "paid"
|
||||
? "Paid"
|
||||
: r.paymentStatus === "extra_payment_pending"
|
||||
? "Extra Payment Pending"
|
||||
: "Pending",
|
||||
r.paidAt ? r.paidAt.toISOString() : "",
|
||||
r.extraQuestions || "",
|
||||
r.cancelledAt ? r.cancelledAt.toISOString() : "",
|
||||
r.createdAt.toISOString(),
|
||||
];
|
||||
});
|
||||
|
||||
const csvContent = [
|
||||
headers.join(","),
|
||||
headers.map(escapeCell).join(","),
|
||||
...rows.map((row) =>
|
||||
row.map((cell) => `"${String(cell).replace(/"/g, '""')}"`).join(","),
|
||||
row.map((cell) => escapeCell(String(cell))).join(","),
|
||||
),
|
||||
].join("\n");
|
||||
|
||||
@@ -729,6 +842,155 @@ export const appRouter = {
|
||||
return { success: true, message: "Admin toegang geweigerd" };
|
||||
}),
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Reminder opt-in
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Subscribe an email address to receive reminders before registration opens:
|
||||
* one 24 hours before and one 1 hour before. Silently deduplicates — if the
|
||||
* email is already subscribed, returns ok:true without error. Returns
|
||||
* ok:false if registration is already open.
|
||||
*/
|
||||
subscribeReminder: publicProcedure
|
||||
.input(z.object({ email: z.string().email() }))
|
||||
.handler(async ({ input }) => {
|
||||
const now = Date.now();
|
||||
|
||||
// Registration is already open — no point subscribing
|
||||
if (now >= REGISTRATION_OPENS_AT.getTime()) {
|
||||
return { ok: false, reason: "already_open" as const };
|
||||
}
|
||||
|
||||
// Check for an existing subscription (silent dedup)
|
||||
const existing = await db
|
||||
.select({ id: reminder.id })
|
||||
.from(reminder)
|
||||
.where(eq(reminder.email, input.email))
|
||||
.limit(1)
|
||||
.then((rows) => rows[0]);
|
||||
|
||||
if (existing) {
|
||||
return { ok: true };
|
||||
}
|
||||
|
||||
await db.insert(reminder).values({
|
||||
id: randomUUID(),
|
||||
email: input.email,
|
||||
});
|
||||
|
||||
// Fire-and-forget — don't let a mail failure block the response
|
||||
sendSubscriptionConfirmationEmail({ to: input.email }).catch((err) =>
|
||||
emailLog("error", "email.catch", {
|
||||
type: "subscription_confirmation",
|
||||
to: input.email,
|
||||
error: String(err),
|
||||
}),
|
||||
);
|
||||
|
||||
return { ok: true };
|
||||
}),
|
||||
|
||||
/**
|
||||
* Send pending reminder emails to all opted-in addresses.
|
||||
* Protected by a shared secret (`CRON_SECRET`) passed as an Authorization
|
||||
* header. Should be called by a Cloudflare Cron Trigger at the top of
|
||||
* every hour, or directly via `POST /api/cron/reminders`.
|
||||
*
|
||||
* Fires two waves:
|
||||
* - 24 hours before: window [REGISTRATION_OPENS_AT - 25h, REGISTRATION_OPENS_AT - 23h)
|
||||
* - 1 hour before: window [REGISTRATION_OPENS_AT - 1h, REGISTRATION_OPENS_AT)
|
||||
*/
|
||||
sendReminders: publicProcedure
|
||||
.input(z.object({ secret: z.string() }))
|
||||
.handler(async ({ input }) => {
|
||||
// Validate the shared secret
|
||||
if (!env.CRON_SECRET || input.secret !== env.CRON_SECRET) {
|
||||
throw new Error("Unauthorized");
|
||||
}
|
||||
|
||||
const now = Date.now();
|
||||
const in24hWindow =
|
||||
now >= REMINDER_24H_WINDOW_START.getTime() &&
|
||||
now < REMINDER_24H_WINDOW_END.getTime();
|
||||
const in1hWindow =
|
||||
now >= REMINDER_1H_WINDOW_START.getTime() &&
|
||||
now < REGISTRATION_OPENS_AT.getTime();
|
||||
|
||||
const activeWindow = in24hWindow ? "24h" : in1hWindow ? "1h" : null;
|
||||
emailLog("info", "reminders.cron.tick", { activeWindow });
|
||||
|
||||
if (!in24hWindow && !in1hWindow) {
|
||||
return { sent: 0, skipped: true, reason: "outside_window" as const };
|
||||
}
|
||||
|
||||
let sent = 0;
|
||||
const errors: string[] = [];
|
||||
|
||||
if (in24hWindow) {
|
||||
// Fetch reminders where the 24h email has not been sent yet
|
||||
const pending = await db
|
||||
.select()
|
||||
.from(reminder)
|
||||
.where(isNull(reminder.sent24hAt));
|
||||
|
||||
emailLog("info", "reminders.24h.pending", { count: pending.length });
|
||||
|
||||
for (const row of pending) {
|
||||
try {
|
||||
await sendReminder24hEmail({ to: row.email });
|
||||
await db
|
||||
.update(reminder)
|
||||
.set({ sent24hAt: new Date() })
|
||||
.where(eq(reminder.id, row.id));
|
||||
sent++;
|
||||
} catch (err) {
|
||||
errors.push(`24h ${row.email}: ${String(err)}`);
|
||||
emailLog("error", "email.catch", {
|
||||
type: "reminder_24h",
|
||||
to: row.email,
|
||||
error: String(err),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (in1hWindow) {
|
||||
// Fetch reminders where the 1h email has not been sent yet
|
||||
const pending = await db
|
||||
.select()
|
||||
.from(reminder)
|
||||
.where(isNull(reminder.sentAt));
|
||||
|
||||
emailLog("info", "reminders.1h.pending", { count: pending.length });
|
||||
|
||||
for (const row of pending) {
|
||||
try {
|
||||
await sendReminderEmail({ to: row.email });
|
||||
await db
|
||||
.update(reminder)
|
||||
.set({ sentAt: new Date() })
|
||||
.where(eq(reminder.id, row.id));
|
||||
sent++;
|
||||
} catch (err) {
|
||||
errors.push(`1h ${row.email}: ${String(err)}`);
|
||||
emailLog("error", "email.catch", {
|
||||
type: "reminder_1h",
|
||||
to: row.email,
|
||||
error: String(err),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
emailLog("info", "reminders.cron.done", {
|
||||
sent,
|
||||
errorCount: errors.length,
|
||||
});
|
||||
|
||||
return { sent, skipped: false, errors };
|
||||
}),
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Checkout
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -835,3 +1097,134 @@ export const appRouter = {
|
||||
|
||||
export type AppRouter = typeof appRouter;
|
||||
export type AppRouterClient = RouterClient<typeof appRouter>;
|
||||
|
||||
/**
|
||||
* Standalone function that sends pending reminder emails.
|
||||
* Exported so that the Cloudflare Cron HTTP handler can call it directly
|
||||
* without needing drizzle-orm as a direct dependency of apps/web.
|
||||
*/
|
||||
export async function runSendReminders(): Promise<{
|
||||
sent: number;
|
||||
skipped: boolean;
|
||||
reason?: string;
|
||||
errors: string[];
|
||||
}> {
|
||||
const now = Date.now();
|
||||
const in24hWindow =
|
||||
now >= REMINDER_24H_WINDOW_START.getTime() &&
|
||||
now < REMINDER_24H_WINDOW_END.getTime();
|
||||
const in1hWindow =
|
||||
now >= REMINDER_1H_WINDOW_START.getTime() &&
|
||||
now < REGISTRATION_OPENS_AT.getTime();
|
||||
|
||||
const activeWindow = in24hWindow ? "24h" : in1hWindow ? "1h" : null;
|
||||
emailLog("info", "reminders.cron.tick", { activeWindow });
|
||||
|
||||
if (!in24hWindow && !in1hWindow) {
|
||||
return { sent: 0, skipped: true, reason: "outside_window", errors: [] };
|
||||
}
|
||||
|
||||
let sent = 0;
|
||||
const errors: string[] = [];
|
||||
|
||||
if (in24hWindow) {
|
||||
const pending = await db
|
||||
.select()
|
||||
.from(reminder)
|
||||
.where(isNull(reminder.sent24hAt));
|
||||
|
||||
emailLog("info", "reminders.24h.pending", { count: pending.length });
|
||||
|
||||
for (const row of pending) {
|
||||
try {
|
||||
await sendReminder24hEmail({ to: row.email });
|
||||
await db
|
||||
.update(reminder)
|
||||
.set({ sent24hAt: new Date() })
|
||||
.where(eq(reminder.id, row.id));
|
||||
sent++;
|
||||
} catch (err) {
|
||||
errors.push(`24h ${row.email}: ${String(err)}`);
|
||||
emailLog("error", "email.catch", {
|
||||
type: "reminder_24h",
|
||||
to: row.email,
|
||||
error: String(err),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (in1hWindow) {
|
||||
const pending = await db
|
||||
.select()
|
||||
.from(reminder)
|
||||
.where(isNull(reminder.sentAt));
|
||||
|
||||
emailLog("info", "reminders.1h.pending", { count: pending.length });
|
||||
|
||||
for (const row of pending) {
|
||||
try {
|
||||
await sendReminderEmail({ to: row.email });
|
||||
await db
|
||||
.update(reminder)
|
||||
.set({ sentAt: new Date() })
|
||||
.where(eq(reminder.id, row.id));
|
||||
sent++;
|
||||
} catch (err) {
|
||||
errors.push(`1h ${row.email}: ${String(err)}`);
|
||||
emailLog("error", "email.catch", {
|
||||
type: "reminder_1h",
|
||||
to: row.email,
|
||||
error: String(err),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Payment reminders: watchers with pending payment older than 3 days
|
||||
const threeDaysAgo = now - 3 * 24 * 60 * 60 * 1000;
|
||||
const unpaidWatchers = await db
|
||||
.select()
|
||||
.from(registration)
|
||||
.where(
|
||||
and(
|
||||
eq(registration.registrationType, "watcher"),
|
||||
eq(registration.paymentStatus, "pending"),
|
||||
isNull(registration.paymentReminderSentAt),
|
||||
lte(registration.createdAt, new Date(threeDaysAgo)),
|
||||
),
|
||||
);
|
||||
|
||||
emailLog("info", "reminders.payment.pending", {
|
||||
count: unpaidWatchers.length,
|
||||
});
|
||||
|
||||
for (const reg of unpaidWatchers) {
|
||||
if (!reg.managementToken) continue;
|
||||
try {
|
||||
await sendPaymentReminderEmail({
|
||||
to: reg.email,
|
||||
firstName: reg.firstName,
|
||||
managementToken: reg.managementToken,
|
||||
drinkCardValue: reg.drinkCardValue ?? undefined,
|
||||
giftAmount: reg.giftAmount ?? undefined,
|
||||
});
|
||||
await db
|
||||
.update(registration)
|
||||
.set({ paymentReminderSentAt: new Date() })
|
||||
.where(eq(registration.id, reg.id));
|
||||
sent++;
|
||||
} catch (err) {
|
||||
errors.push(`payment-reminder ${reg.email}: ${String(err)}`);
|
||||
emailLog("error", "email.catch", {
|
||||
type: "payment_reminder",
|
||||
to: reg.email,
|
||||
error: String(err),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
emailLog("info", "reminders.cron.done", { sent, errorCount: errors.length });
|
||||
|
||||
return { sent, skipped: false, errors };
|
||||
}
|
||||
|
||||
@@ -15,10 +15,12 @@
|
||||
"@kk/env": "workspace:*",
|
||||
"better-auth": "catalog:",
|
||||
"dotenv": "catalog:",
|
||||
"nodemailer": "^8.0.2",
|
||||
"zod": "catalog:"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@kk/config": "workspace:*",
|
||||
"@types/nodemailer": "^7.0.11",
|
||||
"typescript": "catalog:"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,96 @@ import { env } from "@kk/env/server";
|
||||
import { betterAuth } from "better-auth";
|
||||
import { drizzleAdapter } from "better-auth/adapters/drizzle";
|
||||
import { tanstackStartCookies } from "better-auth/tanstack-start";
|
||||
import nodemailer from "nodemailer";
|
||||
|
||||
const _smtpFrom = env.SMTP_FROM ?? "Kunstenkamp <info@kunstenkamp.be>";
|
||||
|
||||
let _transport: nodemailer.Transporter | null | undefined;
|
||||
function getTransport(): nodemailer.Transporter | null {
|
||||
if (_transport !== undefined) return _transport;
|
||||
if (!env.SMTP_HOST || !env.SMTP_USER || !env.SMTP_PASS) {
|
||||
_transport = null;
|
||||
return null;
|
||||
}
|
||||
_transport = nodemailer.createTransport({
|
||||
host: env.SMTP_HOST,
|
||||
port: env.SMTP_PORT,
|
||||
secure: env.SMTP_PORT === 465,
|
||||
auth: { user: env.SMTP_USER, pass: env.SMTP_PASS },
|
||||
});
|
||||
return _transport;
|
||||
}
|
||||
|
||||
async function sendPasswordResetEmail(to: string, resetUrl: string) {
|
||||
const transport = getTransport();
|
||||
if (!transport) {
|
||||
console.warn("SMTP not configured — skipping password reset email");
|
||||
return;
|
||||
}
|
||||
const html = `<!DOCTYPE html>
|
||||
<html lang="nl">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Wachtwoord opnieuw instellen</title>
|
||||
</head>
|
||||
<body style="margin:0;padding:0;background:#f4f4f5;font-family:sans-serif;">
|
||||
<table width="100%" cellpadding="0" cellspacing="0" style="background:#f4f4f5;padding:40px 0;">
|
||||
<tr>
|
||||
<td align="center">
|
||||
<table width="600" cellpadding="0" cellspacing="0" style="background:#214e51;border-radius:4px;overflow:hidden;">
|
||||
<tr>
|
||||
<td style="padding:40px 48px 32px;">
|
||||
<p style="margin:0;font-size:13px;color:rgba(255,255,255,0.5);letter-spacing:0.08em;text-transform:uppercase;">Kunstenkamp</p>
|
||||
<h1 style="margin:12px 0 0;font-size:28px;color:#ffffff;font-weight:700;">Wachtwoord opnieuw instellen</h1>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding:0 48px 32px;">
|
||||
<p style="margin:0 0 16px;font-size:16px;color:rgba(255,255,255,0.85);line-height:1.6;">
|
||||
We hebben een aanvraag ontvangen om het wachtwoord van je Kunstenkamp-account opnieuw in te stellen.
|
||||
</p>
|
||||
<p style="margin:0 0 24px;font-size:16px;color:rgba(255,255,255,0.85);line-height:1.6;">
|
||||
Klik op de knop hieronder om een nieuw wachtwoord in te stellen. Deze link is <strong style="color:#ffffff;">1 uur geldig</strong>.
|
||||
</p>
|
||||
<table cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
<td style="border-radius:2px;background:#ffffff;">
|
||||
<a href="${resetUrl}" style="display:inline-block;padding:14px 32px;font-size:16px;font-weight:600;color:#214e51;text-decoration:none;">
|
||||
Stel wachtwoord in
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p style="margin:16px 0 0;font-size:13px;color:rgba(255,255,255,0.4);">
|
||||
Of kopieer deze link: <span style="color:rgba(255,255,255,0.6);">${resetUrl}</span>
|
||||
</p>
|
||||
<p style="margin:24px 0 0;font-size:14px;color:rgba(255,255,255,0.5);line-height:1.6;">
|
||||
Heb je dit niet aangevraagd? Dan hoef je niets te doen — je wachtwoord blijft ongewijzigd.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding:24px 48px;border-top:1px solid rgba(255,255,255,0.1);">
|
||||
<p style="margin:0;font-size:13px;color:rgba(255,255,255,0.4);line-height:1.6;">
|
||||
Vragen? Mail ons op <a href="mailto:info@kunstenkamp.be" style="color:rgba(255,255,255,0.6);">info@kunstenkamp.be</a><br/>
|
||||
Kunstenkamp vzw — Een initiatief voor en door kunstenaars.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>`;
|
||||
await transport.sendMail({
|
||||
from: _smtpFrom,
|
||||
to,
|
||||
subject: "Wachtwoord opnieuw instellen — Kunstenkamp",
|
||||
html,
|
||||
});
|
||||
}
|
||||
|
||||
export const auth = betterAuth({
|
||||
database: drizzleAdapter(db, {
|
||||
@@ -35,6 +125,9 @@ export const auth = betterAuth({
|
||||
return keyBuffer.equals(hashBuffer);
|
||||
},
|
||||
},
|
||||
sendResetPassword: async ({ user, url }) => {
|
||||
await sendPasswordResetEmail(user.email, url);
|
||||
},
|
||||
},
|
||||
user: {
|
||||
additionalFields: {
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
9
packages/db/src/migrations/0007_reminder.sql
Normal file
9
packages/db/src/migrations/0007_reminder.sql
Normal file
@@ -0,0 +1,9 @@
|
||||
-- Add reminder table for email reminders 1 hour before registration opens
|
||||
CREATE TABLE `reminder` (
|
||||
`id` text PRIMARY KEY NOT NULL,
|
||||
`email` text NOT NULL,
|
||||
`sent_at` integer,
|
||||
`created_at` integer DEFAULT (cast(unixepoch('subsecond') * 1000 as integer)) NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE INDEX `reminder_email_idx` ON `reminder` (`email`);
|
||||
@@ -0,0 +1,2 @@
|
||||
-- Migration: add payment_reminder_sent_at column to registration table
|
||||
ALTER TABLE registration ADD COLUMN payment_reminder_sent_at INTEGER;
|
||||
2
packages/db/src/migrations/0009_reminder_24h.sql
Normal file
2
packages/db/src/migrations/0009_reminder_24h.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
-- Add sent_24h_at column to track whether the 24-hour-before reminder was sent
|
||||
ALTER TABLE `reminder` ADD `sent_24h_at` integer;
|
||||
@@ -29,6 +29,34 @@
|
||||
"when": 1772530000000,
|
||||
"tag": "0003_add_guests",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 4,
|
||||
"version": "6",
|
||||
"when": 1772536320000,
|
||||
"tag": "0004_drinkkaart",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 5,
|
||||
"version": "6",
|
||||
"when": 1772596240000,
|
||||
"tag": "0005_registration_drinkkaart_credit",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 6,
|
||||
"version": "6",
|
||||
"when": 1772672880000,
|
||||
"tag": "0006_mollie_migration",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 7,
|
||||
"version": "6",
|
||||
"when": 1772931300000,
|
||||
"tag": "0007_reminder",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -2,3 +2,4 @@ export * from "./admin-requests";
|
||||
export * from "./auth";
|
||||
export * from "./drinkkaart";
|
||||
export * from "./registrations";
|
||||
export * from "./reminders";
|
||||
|
||||
@@ -37,6 +37,9 @@ export const registration = sqliteTable(
|
||||
drinkkaartCreditedAt: integer("drinkkaart_credited_at", {
|
||||
mode: "timestamp_ms",
|
||||
}),
|
||||
paymentReminderSentAt: integer("payment_reminder_sent_at", {
|
||||
mode: "timestamp_ms",
|
||||
}),
|
||||
createdAt: integer("created_at", { mode: "timestamp_ms" })
|
||||
.default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
|
||||
.notNull(),
|
||||
|
||||
21
packages/db/src/schema/reminders.ts
Normal file
21
packages/db/src/schema/reminders.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { sql } from "drizzle-orm";
|
||||
import { index, integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
|
||||
|
||||
export const reminder = sqliteTable(
|
||||
"reminder",
|
||||
{
|
||||
id: text("id").primaryKey(), // UUID
|
||||
email: text("email").notNull(),
|
||||
/** Set when the 24-hours-before reminder has been sent. */
|
||||
sent24hAt: integer("sent_24h_at", { mode: "timestamp_ms" }),
|
||||
/** Set when the 1-hour-before reminder has been sent. */
|
||||
sentAt: integer("sent_at", { mode: "timestamp_ms" }),
|
||||
createdAt: integer("created_at", { mode: "timestamp_ms" })
|
||||
.default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
|
||||
.notNull(),
|
||||
},
|
||||
(t) => [index("reminder_email_idx").on(t.email)],
|
||||
);
|
||||
|
||||
export type Reminder = typeof reminder.$inferSelect;
|
||||
export type NewReminder = typeof reminder.$inferInsert;
|
||||
1
packages/env/src/server.ts
vendored
1
packages/env/src/server.ts
vendored
@@ -26,6 +26,7 @@ export const env = createEnv({
|
||||
.enum(["development", "production", "test"])
|
||||
.default("development"),
|
||||
MOLLIE_API_KEY: z.string().min(1).optional(),
|
||||
CRON_SECRET: z.string().min(1).optional(),
|
||||
},
|
||||
runtimeEnv: process.env,
|
||||
emptyStringAsUndefined: true,
|
||||
|
||||
@@ -32,7 +32,11 @@ export const web = await TanStackStart("web", {
|
||||
SMTP_FROM: getEnvVar("SMTP_FROM"),
|
||||
// Payments (Mollie)
|
||||
MOLLIE_API_KEY: getEnvVar("MOLLIE_API_KEY"),
|
||||
// Cron secret for protected scheduled endpoints
|
||||
CRON_SECRET: getEnvVar("CRON_SECRET"),
|
||||
},
|
||||
// Fire every hour so reminder checks can run at 19:00 on 2026-03-15 (24h) and 18:00 on 2026-03-16 (1h)
|
||||
crons: ["0 * * * *"],
|
||||
domains: ["kunstenkamp.be", "www.kunstenkamp.be"],
|
||||
});
|
||||
|
||||
|
||||
@@ -18,14 +18,17 @@
|
||||
"persistent": true
|
||||
},
|
||||
"db:push": {
|
||||
"cache": false
|
||||
"cache": false,
|
||||
"interactive": true
|
||||
},
|
||||
"db:generate": {
|
||||
"cache": false
|
||||
"cache": false,
|
||||
"interactive": true
|
||||
},
|
||||
"db:migrate": {
|
||||
"cache": false,
|
||||
"persistent": true
|
||||
"persistent": true,
|
||||
"interactive": true
|
||||
},
|
||||
"db:studio": {
|
||||
"cache": false,
|
||||
|
||||
Reference in New Issue
Block a user