Archived
Supervisors can split an event's named attendees into allocation sets (rooms, small groups, buses) with capacity, gender and leader per group, using a drag-and-drop board or auto-allocate (keep bookings together or split them). Adds printable group and master lists (medical view audited), the group on tickets and in My Events, messaging by group, a "My groups" page for leaders, and an optional per-event gender question for named attendees. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
119 lines
6.2 KiB
TypeScript
119 lines
6.2 KiB
TypeScript
"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<string | null>(null);
|
|
const minor = youth && isMinorOn(f.dateOfBirth, event?.startDate);
|
|
const places = ticket.quantity || 1;
|
|
const set = (k: keyof typeof f) => (e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement>) => setF(prev => ({ ...prev, [k]: e.target.value }));
|
|
|
|
const submit = async (e: React.FormEvent) => {
|
|
e.preventDefault();
|
|
setBusy(true);
|
|
setError(null);
|
|
try {
|
|
const body: Record<string, string> = { 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 (
|
|
<div className="fixed inset-0 bg-black/40 flex items-center justify-center z-50" onClick={onClose}>
|
|
<form onSubmit={submit} className="bg-white rounded-xl shadow-lg max-w-md w-full mx-4 p-5 space-y-3 max-h-[90vh] overflow-y-auto" onClick={e => e.stopPropagation()}>
|
|
<div className="flex items-center gap-2">
|
|
<ArrowRightLeft className="w-5 h-5 text-brand-600" />
|
|
<h3 className="text-lg font-semibold">Transfer ticket</h3>
|
|
</div>
|
|
<p className="text-sm text-gray-600">
|
|
{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.
|
|
</p>
|
|
<div>
|
|
<label className="block text-xs text-gray-600 mb-1">New holder's name</label>
|
|
<input className={input} value={f.name} onChange={set("name")} required maxLength={100} />
|
|
</div>
|
|
<div className="grid grid-cols-1 sm:grid-cols-2 gap-2">
|
|
<div>
|
|
<label className="block text-xs text-gray-600 mb-1">Email</label>
|
|
<input type="email" className={input} value={f.email} onChange={set("email")} />
|
|
</div>
|
|
<div>
|
|
<label className="block text-xs text-gray-600 mb-1">Phone (WhatsApp)</label>
|
|
<input type="tel" className={input} value={f.phone} onChange={set("phone")} />
|
|
</div>
|
|
</div>
|
|
{event?.collectGender && (
|
|
<div>
|
|
<label className="block text-xs text-gray-600 mb-1">Gender</label>
|
|
<select className={input} value={f.gender} onChange={set("gender")} required>
|
|
<option value="">Choose…</option>
|
|
<option value="male">Male</option>
|
|
<option value="female">Female</option>
|
|
</select>
|
|
</div>
|
|
)}
|
|
<p className="text-xs text-gray-500">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.</p>
|
|
{youth && (
|
|
<div className="space-y-2 border-t pt-3">
|
|
<div>
|
|
<label className="block text-xs text-gray-600 mb-1">Date of birth</label>
|
|
<input type="date" className={input} value={f.dateOfBirth} onChange={set("dateOfBirth")} required />
|
|
</div>
|
|
{minor && (
|
|
<>
|
|
<p className="text-xs text-amber-800 bg-amber-50 rounded p-2">They're under 18, so a parent or guardian will be asked for consent before they can check in.</p>
|
|
<input className={input} placeholder="Parent or guardian's name" value={f.parentName} onChange={set("parentName")} required />
|
|
<div className="grid grid-cols-1 sm:grid-cols-2 gap-2">
|
|
<input type="email" className={input} placeholder="Parent's email" value={f.parentEmail} onChange={set("parentEmail")} required />
|
|
<input type="tel" className={input} placeholder="Parent's phone" value={f.parentPhone} onChange={set("parentPhone")} required />
|
|
</div>
|
|
</>
|
|
)}
|
|
</div>
|
|
)}
|
|
{error && <div className="p-2 rounded bg-red-50 text-red-800 text-sm">{error}</div>}
|
|
<div className="flex justify-end gap-2 pt-1">
|
|
<button type="button" onClick={onClose} className="px-3 py-1.5 text-sm rounded bg-gray-100 hover:bg-gray-200">Cancel</button>
|
|
<button type="submit" disabled={busy || !f.name.trim() || (!f.email.trim() && !f.phone.trim())} className="px-3 py-1.5 text-sm rounded bg-brand-600 text-white hover:bg-brand-700 disabled:opacity-50">
|
|
{busy ? "Transferring…" : "Transfer"}
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
);
|
|
}
|