"use client"; import React, { useState } from "react"; import { ArrowRightLeft } from "lucide-react"; import { apiFetch } from "@/lib/api"; import { isMinorOn } from "@/components/shared/AttendeeNamesEditor"; /** Whether to offer "Transfer" on a ticket (the server checks the rules again). */ export function canOfferTransfer(ticket: any, event: any, isSupervisor = false): boolean { if (!ticket || !event) return false; if ((ticket.usages || []).length > 0 || ticket.isUsed) return false; if (event.startDate && new Date(event.startDate) <= new Date()) return false; return isSupervisor || event.allowTicketTransfer !== false; } /** * Hand a ticket to someone else: their name and email/phone (plus date of birth and a * parent's details on youth events). They get a new QR code; the old one stops working. */ export function TransferTicketModal({ ticket, event, token, onClose, onDone }: { ticket: any; event: any; token: string; onClose: () => void; onDone: (message: string) => void; }) { const youth = !!event?.requiresParentalConsent; const [f, setF] = useState({ name: "", email: "", phone: "", gender: "", dateOfBirth: "", parentName: "", parentEmail: "", parentPhone: "" }); const [busy, setBusy] = useState(false); const [error, setError] = useState(null); const minor = youth && isMinorOn(f.dateOfBirth, event?.startDate); const places = ticket.quantity || 1; const set = (k: keyof typeof f) => (e: React.ChangeEvent) => setF(prev => ({ ...prev, [k]: e.target.value })); const submit = async (e: React.FormEvent) => { e.preventDefault(); setBusy(true); setError(null); try { const body: Record = { name: f.name, email: f.email, phone: f.phone, ...(f.gender ? { gender: f.gender } : {}) }; if (youth) Object.assign(body, { dateOfBirth: f.dateOfBirth, parentName: f.parentName, parentEmail: f.parentEmail, parentPhone: f.parentPhone }); const res = await apiFetch<{ message: string }>(`/api/tickets/${ticket.id}/transfer`, { method: "POST", authToken: token, body }); onDone(res.message); } catch (err: any) { setError(err?.message || "Couldn't transfer the ticket"); } finally { setBusy(false); } }; const input = "w-full border rounded-lg px-3 py-2 text-sm"; return (
e.stopPropagation()}>

Transfer ticket

{places > 1 ? `This ticket is for ${places} people. One place moves to the new holder on their own ticket; the other ${places - 1} stay on this one.` : "The new holder gets their own ticket with a new QR code. The current QR code (including any screenshots of it) will stop working."} {" "}The booking and payment stay with the person who booked.

{event?.collectGender && (
)}

An email or phone number is needed to send them the ticket. If they don't have an account yet, one is created and they get a link to activate it.

{youth && (
{minor && ( <>

They're under 18, so a parent or guardian will be asked for consent before they can check in.

)}
)} {error &&
{error}
}
); }