@composable-os/pack-ticketing 0.1.0-beta.11 → 0.1.0-beta.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/automations.d.ts +2 -1
- package/dist/automations.js +52 -145
- package/dist/blocks/ticketing-checkout/ticket-picker.d.ts +9 -3
- package/dist/blocks/ticketing-checkout/ticket-picker.js +91 -17
- package/dist/blocks/ticketing-my-tickets/my-tickets.js +9 -3
- package/dist/blocks/ticketing-native-my-tickets/my-tickets-screen.d.ts +5 -2
- package/dist/blocks/ticketing-native-my-tickets/my-tickets-screen.js +5 -6
- package/dist/blocks/ticketing-native-scanner/door-scanner-screen.js +2 -2
- package/dist/blocks/ticketing-native-ticket/ticket-screen.js +4 -3
- package/dist/blocks/ticketing-order/order-confirmation.js +2 -1
- package/dist/client/index.d.ts +28 -2
- package/dist/client/index.js +31 -14
- package/dist/index.d.ts +218 -1
- package/dist/index.js +77 -5
- package/dist/routine-mail.d.ts +160 -0
- package/dist/routine-mail.js +137 -0
- package/dist/tools.d.ts +21 -0
- package/dist/tools.js +86 -45
- package/package.json +3 -3
package/dist/automations.d.ts
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
export declare const BALANCE_BATCH = 200;
|
|
3
3
|
/**
|
|
4
4
|
* When an event starts, as its holders read it: the day and time in the event's own zone, and
|
|
5
|
-
* the zone, so a camp in Bangkok sold from Sydney says Bangkok's time (ADR 0460).
|
|
5
|
+
* the zone, so a camp in Bangkok sold from Sydney says Bangkok's time (ADR 0460). The emails
|
|
6
|
+
* write it the same way (the host's `datetime` with the year).
|
|
6
7
|
*/
|
|
7
8
|
export declare function eventTimeText(iso: string | null, zone: string | null): string | null;
|
|
8
9
|
export declare const ticketsByEmail: import("@composable-os/sdk").AutomationSpec<{
|
package/dist/automations.js
CHANGED
|
@@ -1,82 +1,38 @@
|
|
|
1
|
-
// The Ticketing automations (stage 27, step 4).
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
// The Ticketing automations (stage 27, step 4). The buyer's and the holder's emails are routine
|
|
2
|
+
// mail (ADR 0590): fixed emails this pack declares (routine-mail.ts), which the host composes and
|
|
3
|
+
// sends to the order's own address or the ticket's holder without a person's approval, unless an
|
|
4
|
+
// admin turned the kind off or the host holds one for a person. They go out from the email-send
|
|
5
|
+
// connection an admin binds when the pack is installed. One automation moves an event to ended.
|
|
6
|
+
// They add no rule of their own: what is paid, what is owed and when is the host's. Each declares
|
|
7
|
+
// its steps, so the host renders the summary from them.
|
|
8
|
+
import { defineAutomation, formatMoment } from "@composable-os/sdk";
|
|
9
|
+
import { EVENT, isConflict, TICKET, TICKET_TYPE } from "./tools.js";
|
|
9
10
|
const DAY_MS = 86_400_000;
|
|
10
11
|
/** Most buyers reminded in one run of the daily balance reminders; the rest wait a day. */
|
|
11
12
|
export const BALANCE_BATCH = 200;
|
|
12
|
-
/** The email-send connection
|
|
13
|
+
/** The email-send connection the host sends from (the binding is a person's consent). */
|
|
13
14
|
const MAIL = {
|
|
14
15
|
id: "mail",
|
|
15
16
|
gatekeeper: "email-send",
|
|
16
17
|
purpose: "Send buyers their tickets and reminders",
|
|
17
18
|
};
|
|
18
19
|
const text = (value) => value === null || value === undefined || value === "" ? null : String(value);
|
|
19
|
-
/** The pack's settings an admin set (Settings → Extensions), by name. */
|
|
20
|
-
async function settings(ctx) {
|
|
21
|
-
const { items } = await ctx.ops.call("extensionSettings.list");
|
|
22
|
-
return items.find((item) => item.id === "ticketing")?.values ?? {};
|
|
23
|
-
}
|
|
24
|
-
/** A link with `?order=<id>`, or the page alone. */
|
|
25
|
-
function withOrder(base, orderId) {
|
|
26
|
-
const url = text(base);
|
|
27
|
-
if (!url)
|
|
28
|
-
return null;
|
|
29
|
-
return `${url}${url.includes("?") ? "&" : "?"}order=${encodeURIComponent(orderId)}`;
|
|
30
|
-
}
|
|
31
|
-
/** Sends one email to one buyer through the bound email-send connection. */
|
|
32
|
-
async function sendMail(ctx, message) {
|
|
33
|
-
const gatekeeper = ctx.gatekeeper("email-send");
|
|
34
|
-
const connections = await gatekeeper.connections();
|
|
35
|
-
const resource = connections.find((c) => c.id === MAIL.id)?.resources[0]?.bindingName ??
|
|
36
|
-
connections[0]?.resources[0]?.bindingName ??
|
|
37
|
-
"SENDER";
|
|
38
|
-
const result = await gatekeeper.call(MAIL.id, resource, "send", {
|
|
39
|
-
to: [message.to],
|
|
40
|
-
subject: message.subject,
|
|
41
|
-
text: message.text,
|
|
42
|
-
...(message.related?.length ? { relatedRecords: message.related.slice(0, 20) } : {}),
|
|
43
|
-
});
|
|
44
|
-
return result.value;
|
|
45
|
-
}
|
|
46
|
-
const money = (minor, currency) => `${(minor / 100).toFixed(2)} ${currency}`;
|
|
47
20
|
/**
|
|
48
21
|
* When an event starts, as its holders read it: the day and time in the event's own zone, and
|
|
49
|
-
* the zone, so a camp in Bangkok sold from Sydney says Bangkok's time (ADR 0460).
|
|
22
|
+
* the zone, so a camp in Bangkok sold from Sydney says Bangkok's time (ADR 0460). The emails
|
|
23
|
+
* write it the same way (the host's `datetime` with the year).
|
|
50
24
|
*/
|
|
51
25
|
export function eventTimeText(iso, zone) {
|
|
52
26
|
if (!iso)
|
|
53
27
|
return null;
|
|
54
|
-
|
|
55
|
-
if (Number.isNaN(at.getTime()))
|
|
56
|
-
return iso;
|
|
57
|
-
const timeZone = zone ?? "UTC";
|
|
58
|
-
try {
|
|
59
|
-
const local = new Intl.DateTimeFormat("en-GB", {
|
|
60
|
-
timeZone,
|
|
61
|
-
weekday: "long",
|
|
62
|
-
day: "numeric",
|
|
63
|
-
month: "long",
|
|
64
|
-
year: "numeric",
|
|
65
|
-
hour: "2-digit",
|
|
66
|
-
minute: "2-digit",
|
|
67
|
-
hourCycle: "h23",
|
|
68
|
-
}).format(at);
|
|
69
|
-
return `${local} (${timeZone.replace(/_/g, " ")} time)`;
|
|
70
|
-
}
|
|
71
|
-
catch {
|
|
72
|
-
return iso;
|
|
73
|
-
}
|
|
28
|
+
return formatMoment(iso, zone, "datetime", true) ?? iso;
|
|
74
29
|
}
|
|
75
30
|
// --- Tickets by email ---------------------------------------------------------------------------
|
|
76
31
|
export const ticketsByEmail = defineAutomation({
|
|
77
32
|
label: "Tickets by email",
|
|
78
33
|
description: "When an order is first paid (in full, or its deposit), emails the buyer their tickets: " +
|
|
79
|
-
"one line per ticket with its code, and the page where they can show them."
|
|
34
|
+
"one line per ticket with its code, and the page where they can show them. Routine email: " +
|
|
35
|
+
"Tickets by email.",
|
|
80
36
|
trigger: {
|
|
81
37
|
type: "fieldChanged",
|
|
82
38
|
object: "order",
|
|
@@ -89,8 +45,7 @@ export const ticketsByEmail = defineAutomation({
|
|
|
89
45
|
{
|
|
90
46
|
name: "findTickets",
|
|
91
47
|
label: "Find the order's tickets",
|
|
92
|
-
reads: [TICKET
|
|
93
|
-
calls: ["order.get", "extensionSettings.list"],
|
|
48
|
+
reads: [TICKET],
|
|
94
49
|
},
|
|
95
50
|
{ name: "sendTickets", label: "Email the buyer their tickets" },
|
|
96
51
|
],
|
|
@@ -99,53 +54,23 @@ export const ticketsByEmail = defineAutomation({
|
|
|
99
54
|
if (!orderId)
|
|
100
55
|
return { skipped: "no order" };
|
|
101
56
|
const found = await step.do("findTickets", async () => {
|
|
102
|
-
const order = await ctx.ops.call("order.get", {
|
|
103
|
-
id: orderId,
|
|
104
|
-
});
|
|
105
57
|
const tickets = await ctx.ops.call("record.list", {
|
|
106
58
|
object: TICKET,
|
|
107
59
|
filter: { field: "order", op: "eq", value: orderId },
|
|
108
60
|
limit: 100,
|
|
109
61
|
});
|
|
110
|
-
|
|
111
|
-
// The events the tickets are for, with when each starts in its own zone.
|
|
112
|
-
const eventIds = [...new Set(tickets.items.map((t) => text(t.values.event)))].filter((id) => Boolean(id));
|
|
113
|
-
const events = [];
|
|
114
|
-
for (const id of eventIds) {
|
|
115
|
-
const ev = await ctx.ops.call("record.get", { object: EVENT, id });
|
|
116
|
-
const when = eventTimeText(text(ev.values.startsAt), text(ev.values.timezone));
|
|
117
|
-
const venue = text(ev.values.venue);
|
|
118
|
-
events.push(`${text(ev.values.name) ?? "Your event"}${when ? `: ${when}` : ""}${venue ? `, ${venue}` : ""}`);
|
|
119
|
-
}
|
|
120
|
-
return {
|
|
121
|
-
email: order.email,
|
|
122
|
-
events,
|
|
123
|
-
page: withOrder(ticketsUrl, orderId),
|
|
124
|
-
tickets: tickets.items.map((t) => ({
|
|
125
|
-
id: t.id,
|
|
126
|
-
name: text(t.values.name) ?? "Ticket",
|
|
127
|
-
code: text(t.values.code) ?? "",
|
|
128
|
-
})),
|
|
129
|
-
};
|
|
62
|
+
return { tickets: tickets.items.length };
|
|
130
63
|
});
|
|
131
|
-
// An order of something else
|
|
132
|
-
if (!found.tickets
|
|
64
|
+
// An order of something else: nothing to send. The host sends to the order's own address.
|
|
65
|
+
if (!found.tickets)
|
|
133
66
|
return { sent: false, tickets: 0 };
|
|
134
67
|
return step.do("sendTickets", async () => {
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
text: [
|
|
140
|
-
"Thank you. Your tickets are below: show the code at the door.",
|
|
141
|
-
...(found.events.length ? ["", ...found.events] : []),
|
|
142
|
-
"",
|
|
143
|
-
...lines,
|
|
144
|
-
...(found.page ? ["", `See them any time: ${found.page}`] : []),
|
|
145
|
-
].join("\n"),
|
|
146
|
-
related: [orderId, ...found.tickets.map((t) => t.id)],
|
|
68
|
+
const result = await ctx.routineMail.send({
|
|
69
|
+
kind: "tickets",
|
|
70
|
+
record: orderId,
|
|
71
|
+
message: found.tickets === 1 ? "one" : "many",
|
|
147
72
|
});
|
|
148
|
-
return { sent:
|
|
73
|
+
return { sent: result.sent > 0, held: result.held > 0, tickets: found.tickets };
|
|
149
74
|
});
|
|
150
75
|
},
|
|
151
76
|
});
|
|
@@ -153,7 +78,8 @@ export const ticketsByEmail = defineAutomation({
|
|
|
153
78
|
export const eventReminder = defineAutomation({
|
|
154
79
|
label: "Event reminder",
|
|
155
80
|
description: "The day before an event on sale starts, counted in the event's own time zone, emails each " +
|
|
156
|
-
"holder of a valid ticket a reminder with the time (in that zone) and the venue."
|
|
81
|
+
"holder of a valid ticket a reminder with the time (in that zone) and the venue. Routine " +
|
|
82
|
+
"email: Event reminders.",
|
|
157
83
|
trigger: {
|
|
158
84
|
type: "dateRelative",
|
|
159
85
|
object: EVENT,
|
|
@@ -167,7 +93,7 @@ export const eventReminder = defineAutomation({
|
|
|
167
93
|
{
|
|
168
94
|
name: "findHolders",
|
|
169
95
|
label: "Find the holders of valid tickets",
|
|
170
|
-
reads: [TICKET
|
|
96
|
+
reads: [TICKET],
|
|
171
97
|
},
|
|
172
98
|
{ name: "sendReminders", label: "Email each holder" },
|
|
173
99
|
],
|
|
@@ -175,9 +101,9 @@ export const eventReminder = defineAutomation({
|
|
|
175
101
|
const eventId = event.record?.id;
|
|
176
102
|
if (!eventId)
|
|
177
103
|
return { skipped: "no event" };
|
|
178
|
-
const data = event.record?.data ?? {};
|
|
179
104
|
const holders = await step.do("findHolders", async () => {
|
|
180
|
-
|
|
105
|
+
// One email per holder however many tickets they hold: about their first ticket.
|
|
106
|
+
const byHolder = new Map();
|
|
181
107
|
let cursor = null;
|
|
182
108
|
do {
|
|
183
109
|
const page = await ctx.ops.call("record.list", {
|
|
@@ -195,38 +121,30 @@ export const eventReminder = defineAutomation({
|
|
|
195
121
|
const holder = text(ticket.values.holder);
|
|
196
122
|
if (!holder)
|
|
197
123
|
continue;
|
|
198
|
-
|
|
124
|
+
const held = byHolder.get(holder);
|
|
125
|
+
if (held)
|
|
126
|
+
held.count += 1;
|
|
127
|
+
else
|
|
128
|
+
byHolder.set(holder, { ticket: ticket.id, count: 1 });
|
|
199
129
|
}
|
|
200
130
|
cursor = page.nextCursor;
|
|
201
131
|
} while (cursor);
|
|
202
|
-
|
|
203
|
-
for (const [personId, tickets] of emails) {
|
|
204
|
-
const person = await ctx.ops.call("person.get", {
|
|
205
|
-
id: personId,
|
|
206
|
-
});
|
|
207
|
-
if (person?.primaryEmail)
|
|
208
|
-
out.push({ email: person.primaryEmail, tickets });
|
|
209
|
-
}
|
|
210
|
-
return out;
|
|
132
|
+
return [...byHolder.values()];
|
|
211
133
|
});
|
|
212
134
|
if (!holders.length)
|
|
213
135
|
return { sent: 0 };
|
|
214
136
|
return step.do("sendReminders", async () => {
|
|
215
|
-
|
|
216
|
-
const when = eventTimeText(text(data.startsAt), text(data.timezone));
|
|
217
|
-
const venue = text(data.venue);
|
|
137
|
+
let sent = 0;
|
|
218
138
|
for (const holder of holders) {
|
|
219
|
-
await
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
`You have ${holder.tickets.length === 1 ? "a ticket" : `${holder.tickets.length} tickets`}: bring the code.`,
|
|
225
|
-
].join("\n"),
|
|
226
|
-
related: [eventId, ...holder.tickets],
|
|
139
|
+
const result = await ctx.routineMail.send({
|
|
140
|
+
kind: "eventReminder",
|
|
141
|
+
record: holder.ticket,
|
|
142
|
+
message: holder.count === 1 ? "one" : "many",
|
|
143
|
+
values: { count: holder.count },
|
|
227
144
|
});
|
|
145
|
+
sent += result.sent;
|
|
228
146
|
}
|
|
229
|
-
return { sent
|
|
147
|
+
return { sent };
|
|
230
148
|
});
|
|
231
149
|
},
|
|
232
150
|
});
|
|
@@ -265,7 +183,7 @@ export const eventEnded = defineAutomation({
|
|
|
265
183
|
return { ended: true };
|
|
266
184
|
}
|
|
267
185
|
catch (error) {
|
|
268
|
-
if (error
|
|
186
|
+
if (isConflict(error))
|
|
269
187
|
return { ended: false };
|
|
270
188
|
throw error;
|
|
271
189
|
}
|
|
@@ -295,14 +213,14 @@ function periodMs(period) {
|
|
|
295
213
|
export const balanceReminders = defineAutomation({
|
|
296
214
|
label: "Balance reminders",
|
|
297
215
|
description: "Every morning, emails the buyer of a part-paid ticket order whose balance is due in a week " +
|
|
298
|
-
"or tomorrow: how much is owed, when, and the link to pay.",
|
|
216
|
+
"or tomorrow: how much is owed, when, and the link to pay. Routine email: Balance reminders.",
|
|
299
217
|
trigger: { type: "schedule", cron: "0 9 * * *" },
|
|
300
218
|
connections: [MAIL],
|
|
301
219
|
steps: [
|
|
302
220
|
{
|
|
303
221
|
name: "findDue",
|
|
304
222
|
label: "Find part-paid orders due in a week or tomorrow",
|
|
305
|
-
calls: ["query.sql"
|
|
223
|
+
calls: ["query.sql"],
|
|
306
224
|
},
|
|
307
225
|
{ name: "sendReminders", label: "Email each buyer the balance and the link to pay" },
|
|
308
226
|
],
|
|
@@ -314,28 +232,17 @@ export const balanceReminders = defineAutomation({
|
|
|
314
232
|
params: [isoDay(today + 7 * DAY_MS), isoDay(today + DAY_MS)],
|
|
315
233
|
maxRows: BALANCE_BATCH,
|
|
316
234
|
});
|
|
317
|
-
|
|
318
|
-
return rows.map((row) => ({ ...row, link: withOrder(payUrl, row.id) }));
|
|
235
|
+
return rows.map((row) => row.id);
|
|
319
236
|
});
|
|
320
237
|
if (!due.length)
|
|
321
238
|
return { sent: 0 };
|
|
322
239
|
return step.do("sendReminders", async () => {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
await
|
|
326
|
-
|
|
327
|
-
subject: `Balance due ${day}`,
|
|
328
|
-
text: [
|
|
329
|
-
`The balance on your tickets, ${money(order.balance, order.currency)}, is due on ${day}.`,
|
|
330
|
-
order.link
|
|
331
|
-
? `Pay it here (sign in with this email address): ${order.link}`
|
|
332
|
-
: "Reply to this email to pay it.",
|
|
333
|
-
"You can pay it in one go or in parts.",
|
|
334
|
-
].join("\n"),
|
|
335
|
-
related: [order.id],
|
|
336
|
-
});
|
|
240
|
+
let sent = 0;
|
|
241
|
+
for (const orderId of due) {
|
|
242
|
+
const result = await ctx.routineMail.send({ kind: "balance", record: orderId });
|
|
243
|
+
sent += result.sent;
|
|
337
244
|
}
|
|
338
|
-
return { sent
|
|
245
|
+
return { sent };
|
|
339
246
|
});
|
|
340
247
|
},
|
|
341
248
|
});
|
|
@@ -1,11 +1,17 @@
|
|
|
1
|
+
import { type AgreementsHooks } from "@composable-os/client";
|
|
1
2
|
import type { EventOnSale, StartedOrder, TicketingHooks } from "@composable-os/pack-ticketing/client";
|
|
3
|
+
/** The agreements hooks the inline step uses: a member's (due, accept) and a visitor's (words). */
|
|
4
|
+
export type TicketAgreements = Pick<AgreementsHooks, "useDue" | "useAccept" | "useGuestVersions">;
|
|
2
5
|
/**
|
|
3
6
|
* The picker and checkout. `signedIn`: the buyer is a signed-in customer (no email asked).
|
|
4
7
|
* `returnUrl`: the confirmation page, on one of the deployment's allowed sites; it gets the order
|
|
5
8
|
* (and a guest's token) from `onStarted`, which is called before the buyer leaves.
|
|
9
|
+
* `agreements`: for what must be agreed to first, shown inline; without it, the refusal is only
|
|
10
|
+
* named.
|
|
6
11
|
*/
|
|
7
|
-
export declare function TicketPicker({ ticketing, event, signedIn, returnUrl, onStarted, }: {
|
|
8
|
-
ticketing: Pick<TicketingHooks, "useCheckout" | "
|
|
12
|
+
export declare function TicketPicker({ ticketing, agreements, event, signedIn, returnUrl, onStarted, }: {
|
|
13
|
+
ticketing: Pick<TicketingHooks, "useCheckout" | "useStartOrder" | "useTicketPicker">;
|
|
14
|
+
agreements?: TicketAgreements;
|
|
9
15
|
event: EventOnSale;
|
|
10
16
|
signedIn: boolean;
|
|
11
17
|
returnUrl: string;
|
|
@@ -16,7 +22,7 @@ export declare function TicketPicker({ ticketing, event, signedIn, returnUrl, on
|
|
|
16
22
|
* what may be charged (a part at least its minimum, never more than the balance).
|
|
17
23
|
*/
|
|
18
24
|
export declare function BalancePayment({ ticketing, order, returnUrl, }: {
|
|
19
|
-
ticketing: Pick<TicketingHooks, "useCheckout" | "useOrder"
|
|
25
|
+
ticketing: Pick<TicketingHooks, "useCheckout" | "useOrder">;
|
|
20
26
|
order: {
|
|
21
27
|
id: string;
|
|
22
28
|
token?: string | null;
|
|
@@ -1,13 +1,29 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// Choosing tickets and paying, for a site (stage 27): quantities per ticket type, pay in full or
|
|
3
|
+
// by deposit when every chosen type offers one, then the payment provider's page. And paying what
|
|
4
|
+
// is still owed on a part-paid order. The host prices the order, holds the places, refuses what
|
|
5
|
+
// cannot be bought and decides what may be charged; this asks and shows what it answers.
|
|
6
|
+
//
|
|
7
|
+
// What must be agreed to first (stage 44: a waiver on the event) is the host's answer too: when
|
|
8
|
+
// "Pay" is refused with it, the documents are shown inline (the web-agree block's step) and "Pay"
|
|
9
|
+
// is tried again (issue #292). A visitor's agreements travel in the buying call, held in memory
|
|
10
|
+
// until then; a member's are recorded as they agree. A minor is told a parent or guardian buys it.
|
|
11
|
+
import { agreementRefusal, forgetAfter, purchaseErrorWords, withAgreements, } from "@composable-os/client";
|
|
2
12
|
import { availabilityLabel, eventCurrency, formatMoney, formatPrice, minorFromInput, } from "@composable-os/pack-ticketing/client";
|
|
3
13
|
import { useState } from "react";
|
|
4
14
|
import { Button } from "../ui-button/button.js";
|
|
5
15
|
import { Input } from "../ui-input/input.js";
|
|
6
16
|
import { Label } from "../ui-label/label.js";
|
|
17
|
+
import { useForgetOnLeave } from "../web-agree/agree.js";
|
|
18
|
+
import { GuestAgreementStep, MemberAgreementStep } from "../web-agree/agreement-step.js";
|
|
7
19
|
/** What the host said when it refused, in the buyer's words. */
|
|
8
20
|
function refusal(error) {
|
|
9
21
|
if (!error)
|
|
10
22
|
return null;
|
|
23
|
+
// Agreements and the connection (stage 44): what changed, a minor, offline.
|
|
24
|
+
const words = purchaseErrorWords(error) ?? agreementRefusal(error)?.message;
|
|
25
|
+
if (words)
|
|
26
|
+
return words;
|
|
11
27
|
const rule = error.details;
|
|
12
28
|
switch (rule?.details?.rule ?? rule?.rule) {
|
|
13
29
|
case "capacity":
|
|
@@ -24,8 +40,10 @@ function refusal(error) {
|
|
|
24
40
|
* The picker and checkout. `signedIn`: the buyer is a signed-in customer (no email asked).
|
|
25
41
|
* `returnUrl`: the confirmation page, on one of the deployment's allowed sites; it gets the order
|
|
26
42
|
* (and a guest's token) from `onStarted`, which is called before the buyer leaves.
|
|
43
|
+
* `agreements`: for what must be agreed to first, shown inline; without it, the refusal is only
|
|
44
|
+
* named.
|
|
27
45
|
*/
|
|
28
|
-
export function TicketPicker({ ticketing, event, signedIn, returnUrl, onStarted, }) {
|
|
46
|
+
export function TicketPicker({ ticketing, agreements, event, signedIn, returnUrl, onStarted, }) {
|
|
29
47
|
const picker = ticketing.useTicketPicker(event);
|
|
30
48
|
// The currency is the host's, given with the prices; the picker states none of its own.
|
|
31
49
|
const currency = eventCurrency(event);
|
|
@@ -33,23 +51,78 @@ export function TicketPicker({ ticketing, event, signedIn, returnUrl, onStarted,
|
|
|
33
51
|
const checkout = ticketing.useCheckout();
|
|
34
52
|
const [email, setEmail] = useState("");
|
|
35
53
|
const [pay, setPay] = useState("full");
|
|
54
|
+
const [problem, setProblem] = useState(null);
|
|
55
|
+
const [busy, setBusy] = useState(false);
|
|
56
|
+
// What the host said must be agreed to first.
|
|
57
|
+
const [due, setDue] = useState(null);
|
|
58
|
+
// A visitor's agreements: this component's state only, kept if the order does not start
|
|
59
|
+
// (nothing typed twice), forgotten once it starts and when they leave the page.
|
|
60
|
+
const [agreed, setAgreed] = useState(null);
|
|
61
|
+
// A member's "a copy is on its way".
|
|
62
|
+
const [said, setSaid] = useState(null);
|
|
63
|
+
useForgetOnLeave(() => setAgreed(null));
|
|
36
64
|
const byDeposit = picker.estimate.deposit !== null;
|
|
37
|
-
async function
|
|
65
|
+
async function buy(given = agreed) {
|
|
66
|
+
setProblem(null);
|
|
67
|
+
setBusy(true);
|
|
68
|
+
try {
|
|
69
|
+
const outcome = await withAgreements((previous) => forgetAfter(start, {
|
|
70
|
+
lines: picker.lines,
|
|
71
|
+
pay: byDeposit ? pay : "full",
|
|
72
|
+
...(signedIn ? {} : { email }),
|
|
73
|
+
...(!signedIn && given && previous?.kind !== "read_again" ? { agreements: given } : {}),
|
|
74
|
+
}));
|
|
75
|
+
if (outcome.kind !== "done")
|
|
76
|
+
setAgreed(null);
|
|
77
|
+
if (outcome.kind === "due") {
|
|
78
|
+
if (agreements)
|
|
79
|
+
setDue(outcome.documents);
|
|
80
|
+
else {
|
|
81
|
+
setProblem(`Something must be agreed to first: ${outcome.documents.map((d) => d.title).join(", ")}.`);
|
|
82
|
+
}
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (outcome.kind === "minor_payer") {
|
|
86
|
+
setProblem(outcome.message);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const order = outcome.value;
|
|
90
|
+
// Recorded with the order: nothing of it is kept here any more.
|
|
91
|
+
setAgreed(null);
|
|
92
|
+
onStarted(order);
|
|
93
|
+
const page = await checkout.mutateAsync({
|
|
94
|
+
id: order.id,
|
|
95
|
+
...(order.token ? { token: order.token } : {}),
|
|
96
|
+
returnUrl,
|
|
97
|
+
});
|
|
98
|
+
window.location.assign(page.url);
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
if (agreementRefusal(error))
|
|
102
|
+
setAgreed(null);
|
|
103
|
+
setProblem(refusal(error));
|
|
104
|
+
}
|
|
105
|
+
finally {
|
|
106
|
+
setBusy(false);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function submit(e) {
|
|
38
110
|
e.preventDefault();
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
111
|
+
void buy();
|
|
112
|
+
}
|
|
113
|
+
if (due && agreements) {
|
|
114
|
+
const back = () => setDue(null);
|
|
115
|
+
return signedIn ? (_jsx(MemberAgreementStep, { agreements: agreements, documents: due, continueLabel: "Agree and pay", onCancel: back, onAgreed: (copy) => {
|
|
116
|
+
setDue(null);
|
|
117
|
+
setSaid(copy);
|
|
118
|
+
void buy(null);
|
|
119
|
+
} })) : (_jsx(GuestAgreementStep, { agreements: agreements, documents: due, continueLabel: "Agree and pay", onCancel: back, onAgreed: (given) => {
|
|
120
|
+
setDue(null);
|
|
121
|
+
setAgreed(given);
|
|
122
|
+
void buy(given);
|
|
123
|
+
} }));
|
|
51
124
|
}
|
|
52
|
-
return (_jsxs("form", { onSubmit: submit, className: "grid gap-4", children: [event.ticketTypes.map((type) => (_jsxs("div", { className: "grid gap-1", children: [_jsxs(Label, { htmlFor: `qty-${type.id}`, children: [type.name, " \u00B7 ", formatPrice(type.price, currency), type.deposit !== null ? ` (deposit ${formatPrice(type.deposit, currency)})` : ""] }), _jsx(Input, { id: `qty-${type.id}`, type: "number", inputMode: "numeric", min: 0, max: picker.max(type), disabled: picker.max(type) === 0, value: picker.quantities[type.id] ?? 0, onChange: (e) => picker.set(type.id, Number(e.target.value)) }), availabilityLabel(type.availability) ? (_jsx("span", { className: "text-sm text-muted-foreground", children: availabilityLabel(type.availability) })) : null] }, type.id))), byDeposit ? (_jsxs("fieldset", { className: "grid gap-2", children: [_jsx("legend", { children: "How would you like to pay?" }), _jsxs("label", { children: [_jsx("input", { type: "radio", name: "pay", checked: pay === "full", onChange: () => setPay("full") }), " ", "In full: ", formatMoney(picker.estimate.full, currency)] }), _jsxs("label", { children: [_jsx("input", { type: "radio", name: "pay", checked: pay === "deposit", onChange: () => setPay("deposit") }), " ", "A deposit now: ", formatMoney(picker.estimate.deposit ?? 0, currency), ", the rest by the date on your ticket type"] })] })) : (_jsx("p", { children: picker.empty ? "Choose your tickets." : formatMoney(picker.estimate.full, currency) })), signedIn ? null : (_jsxs("div", { className: "grid gap-1", children: [_jsx(Label, { htmlFor: "buyer-email", children: "Email (your tickets are sent here)" }), _jsx(Input, { id: "buyer-email", type: "email", autoComplete: "email", required: true, value: email, onChange: (e) => setEmail(e.target.value) })] })),
|
|
125
|
+
return (_jsxs("form", { onSubmit: submit, className: "grid gap-4", children: [event.ticketTypes.map((type) => (_jsxs("div", { className: "grid gap-1", children: [_jsxs(Label, { htmlFor: `qty-${type.id}`, children: [type.name, " \u00B7 ", formatPrice(type.price, currency), type.deposit !== null ? ` (deposit ${formatPrice(type.deposit, currency)})` : ""] }), _jsx(Input, { id: `qty-${type.id}`, type: "number", inputMode: "numeric", min: 0, max: picker.max(type), disabled: picker.max(type) === 0, value: picker.quantities[type.id] ?? 0, onChange: (e) => picker.set(type.id, Number(e.target.value)) }), availabilityLabel(type.availability) ? (_jsx("span", { className: "text-sm text-muted-foreground", children: availabilityLabel(type.availability) })) : null] }, type.id))), byDeposit ? (_jsxs("fieldset", { className: "grid gap-2", children: [_jsx("legend", { children: "How would you like to pay?" }), _jsxs("label", { children: [_jsx("input", { type: "radio", name: "pay", checked: pay === "full", onChange: () => setPay("full") }), " ", "In full: ", formatMoney(picker.estimate.full, currency)] }), _jsxs("label", { children: [_jsx("input", { type: "radio", name: "pay", checked: pay === "deposit", onChange: () => setPay("deposit") }), " ", "A deposit now: ", formatMoney(picker.estimate.deposit ?? 0, currency), ", the rest by the date on your ticket type"] })] })) : (_jsx("p", { children: picker.empty ? "Choose your tickets." : formatMoney(picker.estimate.full, currency) })), signedIn ? null : (_jsxs("div", { className: "grid gap-1", children: [_jsx(Label, { htmlFor: "buyer-email", children: "Email (your tickets are sent here)" }), _jsx(Input, { id: "buyer-email", type: "email", autoComplete: "email", required: true, value: email, onChange: (e) => setEmail(e.target.value) })] })), said ? _jsx("p", { role: "status", children: said }) : null, agreed ? (_jsx("p", { className: "text-sm", children: "What you agreed to is kept for this order: press Pay to try again." })) : null, problem ? _jsx("p", { role: "alert", children: problem }) : null, _jsx(Button, { type: "submit", disabled: picker.empty || busy, children: busy ? "Opening the payment page…" : "Pay" })] }));
|
|
53
126
|
}
|
|
54
127
|
/**
|
|
55
128
|
* Paying what is still owed on a part-paid order, in one go or a part of it. The host decides
|
|
@@ -64,6 +137,7 @@ export function BalancePayment({ ticketing, order, returnUrl, }) {
|
|
|
64
137
|
return current.isPending ? _jsx("p", { "aria-busy": "true", children: "Loading your order\u2026" }) : null;
|
|
65
138
|
if (data.state !== "part_paid")
|
|
66
139
|
return null;
|
|
140
|
+
const partAmount = minorFromInput(part, data.currency);
|
|
67
141
|
async function open(amount) {
|
|
68
142
|
const page = await checkout.mutateAsync({
|
|
69
143
|
id: order.id,
|
|
@@ -73,5 +147,5 @@ export function BalancePayment({ ticketing, order, returnUrl, }) {
|
|
|
73
147
|
});
|
|
74
148
|
window.location.assign(page.url);
|
|
75
149
|
}
|
|
76
|
-
return (_jsxs("div", { className: "grid gap-3", children: [_jsxs("p", { children: ["Still to pay: ", formatMoney(data.balance, data.currency), data.balanceDueAt ? `, by ${new Date(data.balanceDueAt).toLocaleDateString()}` : "", "."] }), _jsx(Button, { onClick: () => open(data.balance), disabled: checkout.isPending, children: "Pay it all" }), _jsxs("div", { className: "grid gap-1", children: [_jsx(Label, { htmlFor: "part", children: "Or pay part of it" }), _jsx(Input, { id: "part", inputMode: "decimal", value: part, onChange: (e) => setPart(e.target.value) }), _jsx(Button, { onClick: () => open(
|
|
150
|
+
return (_jsxs("div", { className: "grid gap-3", children: [_jsxs("p", { children: ["Still to pay: ", formatMoney(data.balance, data.currency), data.balanceDueAt ? `, by ${new Date(data.balanceDueAt).toLocaleDateString()}` : "", "."] }), _jsx(Button, { onClick: () => open(data.balance), disabled: checkout.isPending, children: "Pay it all" }), _jsxs("div", { className: "grid gap-1", children: [_jsx(Label, { htmlFor: "part", children: "Or pay part of it" }), _jsx(Input, { id: "part", inputMode: "decimal", value: part, onChange: (e) => setPart(e.target.value) }), _jsx(Button, { onClick: () => open(partAmount), disabled: checkout.isPending || partAmount === null, children: "Pay this amount" })] }), checkout.error ? (_jsx("p", { role: "alert", children: "That amount cannot be paid. It must be at least the minimum, and no more than you owe." })) : null] }));
|
|
77
151
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { eventTime } from "@composable-os/pack-ticketing/client";
|
|
3
|
-
|
|
2
|
+
import { eventTime, ticketStateLabel } from "@composable-os/pack-ticketing/client";
|
|
3
|
+
import { Button } from "../ui-button/button.js";
|
|
4
4
|
export function MyTickets({ ticketing, onShow, }) {
|
|
5
5
|
const { data, isPending, error } = ticketing.useMyTickets();
|
|
6
6
|
if (isPending)
|
|
@@ -9,5 +9,11 @@ export function MyTickets({ ticketing, onShow, }) {
|
|
|
9
9
|
return _jsx("p", { role: "alert", children: "We could not load your tickets." });
|
|
10
10
|
if (!data?.items.length)
|
|
11
11
|
return _jsx("p", { children: "You have no tickets yet." });
|
|
12
|
-
return (_jsx("ul", { className: "grid gap-2", children: data.items.map((ticket) => (_jsxs("li", { className: "flex justify-between gap-
|
|
12
|
+
return (_jsx("ul", { className: "grid gap-2", "aria-label": "Your tickets", children: data.items.map((ticket) => (_jsxs("li", { className: "flex flex-wrap items-center justify-between gap-3 rounded-md border p-3", children: [_jsxs("div", { className: "grid gap-1", children: [_jsx("strong", { children: ticket.eventName ?? "Ticket" }), _jsx("span", { className: "text-muted-foreground text-sm", children: [
|
|
13
|
+
ticket.ticketTypeName,
|
|
14
|
+
ticket.startsAt ? eventTime(ticket) : null,
|
|
15
|
+
ticketStateLabel(ticket.state),
|
|
16
|
+
]
|
|
17
|
+
.filter(Boolean)
|
|
18
|
+
.join(" · ") })] }), onShow && ticket.state === "valid" ? (_jsx(Button, { type: "button", variant: "outline", onClick: () => onShow({ id: ticket.id, code: ticket.code }), children: "Show code" })) : null] }, ticket.id))) }));
|
|
13
19
|
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { TicketingHooks } from "@composable-os/pack-ticketing/client";
|
|
2
2
|
export declare function MyTicketsScreen({ ticketing, onOpen, }: {
|
|
3
3
|
ticketing: Pick<TicketingHooks, "useMyTickets">;
|
|
4
|
-
/**
|
|
5
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Pushes the ticket's screen (TicketScreen) on the app's native stack. Left out (as a section of
|
|
6
|
+
* My account, ADR 0710), a row is not pressable.
|
|
7
|
+
*/
|
|
8
|
+
onOpen?: (ticket: {
|
|
6
9
|
id: string;
|
|
7
10
|
code: string | null;
|
|
8
11
|
event: string | null;
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { eventTime } from "@composable-os/pack-ticketing/client";
|
|
3
|
-
import { Text } from "react-native";
|
|
2
|
+
import { eventTime, ticketStateLabel } from "@composable-os/pack-ticketing/client";
|
|
4
3
|
import { List } from "../native-base/list.js";
|
|
5
4
|
import { Row } from "../native-base/row.js";
|
|
6
5
|
import { Screen } from "../native-base/screen.js";
|
|
7
|
-
|
|
6
|
+
import { Text } from "../native-base/text.js";
|
|
8
7
|
export function MyTicketsScreen({ ticketing, onOpen, }) {
|
|
9
8
|
const { data, isPending, error } = ticketing.useMyTickets();
|
|
10
|
-
return (_jsxs(Screen, { title: "Tickets", children: [isPending ? _jsx(Text, { accessibilityRole: "progressbar", children: "Loading your tickets\u2026" }) : null, error ? _jsx(Text, { accessibilityRole: "alert", children: "We could not load your tickets." }) : null, data ? (_jsx(List, { empty: "You have no tickets yet.", children: data.items.map((ticket) => (_jsx(Row, { title: ticket.eventName ?? "Ticket", detail: [
|
|
9
|
+
return (_jsxs(Screen, { title: "Tickets", children: [isPending ? (_jsx(Text, { tone: "muted", accessibilityRole: "progressbar", children: "Loading your tickets\u2026" })) : null, error ? _jsx(Text, { accessibilityRole: "alert", children: "We could not load your tickets." }) : null, data ? (_jsx(List, { empty: "You have no tickets yet.", children: data.items.map((ticket) => (_jsx(Row, { title: ticket.eventName ?? "Ticket", detail: [
|
|
11
10
|
ticket.ticketTypeName,
|
|
12
11
|
ticket.startsAt ? eventTime(ticket) : null,
|
|
13
|
-
|
|
12
|
+
ticketStateLabel(ticket.state),
|
|
14
13
|
]
|
|
15
14
|
.filter(Boolean)
|
|
16
|
-
.join(" · "), onPress: ticket.state === "valid" ? () => onOpen(ticket) : undefined }, ticket.id))) })) : null] }));
|
|
15
|
+
.join(" · "), onPress: ticket.state === "valid" && onOpen ? () => onOpen(ticket) : undefined }, ticket.id))) })) : null] }));
|
|
17
16
|
}
|
|
@@ -35,8 +35,8 @@ export function DoorScannerScreen({ ticketing, Scanner, haptics, title = "Door",
|
|
|
35
35
|
const styles = StyleSheet.create({
|
|
36
36
|
count: { fontSize: theme.font.small, color: theme.color.muted, marginBottom: theme.space.sm },
|
|
37
37
|
result: { borderRadius: theme.radius, padding: theme.space.lg, marginTop: theme.space.md },
|
|
38
|
-
accepted: { backgroundColor:
|
|
39
|
-
refused: { backgroundColor:
|
|
38
|
+
accepted: { backgroundColor: theme.color.successSurface },
|
|
39
|
+
refused: { backgroundColor: theme.color.dangerSurface },
|
|
40
40
|
verdict: { fontSize: theme.font.title, fontWeight: "700", color: theme.color.text },
|
|
41
41
|
message: { fontSize: theme.font.body, color: theme.color.text, marginVertical: theme.space.sm },
|
|
42
42
|
});
|
|
@@ -26,14 +26,15 @@ export function TicketScreen({ ticket, title, detail, Qr, brightness, }) {
|
|
|
26
26
|
brightness.set(before).catch(() => undefined);
|
|
27
27
|
};
|
|
28
28
|
}, [brightness]);
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
// Only a valid ticket's code is drawn to be scanned.
|
|
30
|
+
const scannable = ticket.state === "valid" ? ticket.code : null;
|
|
31
|
+
return (_jsxs(Screen, { title: title, children: [detail ? _jsx(Text, { style: styles.detail, children: detail }) : null, _jsx(View, { style: styles.card, accessible: true, accessibilityLabel: "Ticket code", children: scannable ? (_jsx(Qr, { value: scannable, size: 240 })) : (_jsx(Text, { style: styles.detail, children: ticket.state === "used" ? "This ticket has been used." : "This ticket is not valid." })) }), ticket.code ? (_jsx(Text, { selectable: true, style: styles.code, children: ticket.code })) : null] }));
|
|
31
32
|
}
|
|
32
33
|
const styles = StyleSheet.create({
|
|
33
34
|
card: {
|
|
34
35
|
alignItems: "center",
|
|
35
36
|
justifyContent: "center",
|
|
36
|
-
backgroundColor:
|
|
37
|
+
backgroundColor: theme.color.codeBackground,
|
|
37
38
|
borderRadius: theme.radius,
|
|
38
39
|
padding: theme.space.lg,
|
|
39
40
|
marginVertical: theme.space.md,
|
|
@@ -7,5 +7,6 @@ export function OrderConfirmation({ ticketing, order, children, }) {
|
|
|
7
7
|
if (error || !data)
|
|
8
8
|
return _jsx("p", { role: "alert", children: "We could not find this order." });
|
|
9
9
|
const status = orderStatus(data);
|
|
10
|
-
|
|
10
|
+
const tax = data.taxAmount ?? 0;
|
|
11
|
+
return (_jsxs("section", { className: "grid gap-3", "aria-live": "polite", children: [_jsx("h2", { className: "text-xl font-semibold", children: status.title }), status.waiting ? (_jsx("p", { "aria-busy": "true", children: "This usually takes a few seconds. You can leave this page open." })) : null, _jsx("ul", { className: "grid gap-1", children: data.lines.map((line) => (_jsxs("li", { className: "flex justify-between gap-4", children: [_jsxs("span", { children: [line.quantity, " \u00D7 ", line.title] }), _jsx("span", { children: formatMoney(line.total, data.currency) })] }, line.id))) }), _jsxs("p", { children: ["Total ", formatMoney(data.total, data.currency), " \u00B7 paid", " ", formatMoney(data.paid, data.currency)] }), tax > 0 ? (_jsxs("p", { "data-testid": "order-tax", children: ["Including tax ", formatMoney(tax, data.currency)] })) : null, status.kind === "part_paid" ? children : null] }));
|
|
11
12
|
}
|