@semics-tech/emdash-events 1.0.0-rc.2 → 1.0.0-rc.20

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.
@@ -1,80 +1,137 @@
1
1
  ---
2
- // <BookingStatus>: a booking's state, order and cancel button (EU-FR-06). Rendered by the
3
- // `/booking` page from the `public/booking` answer; the cancel form is a plain POST back to it.
2
+ // <BookingStatus>: a booking's summary card (EU-FR-06). Rendered by the `/booking` page from the
3
+ // `public/booking` answer. It leads with the event and the booked session, in the event's zone, and the
4
+ // place (T157), then the state, the order and its total. With `cancelAction` it ends with the quiet cancel
5
+ // action (`<CancelBooking>`); the booking page instead puts that at its foot. A request awaiting approval with another
6
+ // time the organiser proposed (Events Pro, T174c) shows it with Accept and "That doesn't work": with `proposalAction`,
7
+ // two plain forms (`intent=accept-time` / `refuse-time`) that post there, so they work without JavaScript.
4
8
  import { around, pickLocale, translator } from "../i18n/index";
5
- import { type BookingView, formatMoney, statusLabel } from "./lib/widget";
9
+ import CancelBooking from "./CancelBooking.astro";
10
+ import { zonedAt } from "./lib/list";
11
+ import { type BookingView, endedNotes, formatMoney, statusLabel } from "./lib/widget";
6
12
 
7
13
  interface Props {
8
14
  booking: BookingView;
9
15
  /** Shown as cancelled (the page just cancelled it). */
10
16
  cancelled?: boolean;
11
- /** Where the cancel form posts. */
17
+ /** Where the Accept / "That doesn't work" forms of a proposed time post; without it they are not shown. */
18
+ proposalAction?: string;
19
+ /** Where the cancel form posts; without it the card has no cancel action. */
12
20
  cancelAction?: string;
13
21
  /** Ticket type names by id, when the page knows them. */
14
22
  ticketNames?: Record<string, string>;
23
+ /** A lapsed booking's way back: the event's page, when known. */
24
+ bookAgain?: string;
25
+ /** List the attendees' names (the page turns it off when Events Pro's signing list shows them). */
26
+ showAttendees?: boolean;
15
27
  locale?: string;
16
28
  }
17
29
 
18
- const { booking, cancelled = false, cancelAction, ticketNames = {} } = Astro.props;
30
+ const { booking, cancelled = false, cancelAction, proposalAction, ticketNames = {}, bookAgain, showAttendees = true } =
31
+ Astro.props;
19
32
  const locale = pickLocale(Astro.props.locale, Astro.currentLocale);
20
33
  const { t, plural, lang, dir } = translator(locale);
34
+ // Another time the organiser proposed (Pro, T174c): the buyer's answer is due by the deadline.
35
+ const proposed =
36
+ !cancelled && booking.status === "awaiting_approval" && booking.proposed && Number.isFinite(Date.parse(booking.proposed.startsAt))
37
+ ? booking.proposed
38
+ : undefined;
21
39
  // A request awaiting approval (T131) holds its places until the organiser's deadline.
22
40
  const [heldBefore, heldAfter] = around(
23
- t(booking.status === "awaiting_approval" ? "booking.decideBy" : "booking.heldUntil"),
41
+ t(proposed ? "booking.proposal.answerBy" : booking.status === "awaiting_approval" ? "booking.decideBy" : "booking.heldUntil"),
24
42
  "time",
25
43
  );
26
- const [cancelBefore, cancelAfter] = around(t("booking.cancelUntil"), "time");
27
44
  const tickets = booking.lines.reduce((n, line) => n + line.qty, 0);
28
45
  const status = cancelled ? "cancelled" : booking.status;
29
- const at = (iso: string) => {
30
- try {
31
- const time = new Intl.DateTimeFormat(locale, { dateStyle: "medium", timeStyle: "short", timeZone: "UTC" }).format(
32
- new Date(iso),
33
- );
34
- return t("time.utc", { time });
35
- } catch {
36
- return iso;
37
- }
38
- };
46
+ const zone = booking.event?.timezone;
47
+ const at = (iso: string) => zonedAt(iso, zone, locale);
48
+ const notes = endedNotes({ ...booking, status }, locale);
49
+ const event = booking.event;
50
+ const startsAt = event?.startsAt && Number.isFinite(Date.parse(event.startsAt)) ? event.startsAt : undefined;
51
+ // Who is coming, when the booking names different people (a plain booking puts every seat in the buyer's name).
52
+ const named = booking.attendees.map((a) => a.name).filter(Boolean);
53
+ const names = showAttendees && new Set(named).size > 1 ? named : [];
39
54
  ---
40
55
  <section class="semics-events semics-booking-status" data-testid="booking-details" data-status={status} lang={lang} dir={dir} aria-labelledby="semics-booking-status-title">
41
- <h2 id="semics-booking-status-title" class="semics-visually-hidden">{t("booking.status")}</h2>
42
- <p>
43
- {t("booking.reference")} <strong data-testid="booking-ref">{booking.bookingRef}</strong>
44
- </p>
45
- <p class="semics-status" data-testid="booking-status" data-status={status}>
46
- <span class="semics-status-badge">{statusLabel(status, locale)}</span>
47
- </p>
56
+ {event?.title ? (
57
+ <h2 id="semics-booking-status-title" class="semics-booking-event" data-testid="booking-event">{event.title}</h2>
58
+ ) : (
59
+ <h2 id="semics-booking-status-title" class="semics-visually-hidden">{t("booking.status")}</h2>
60
+ )}
61
+ {(startsAt || event?.venue || booking.requested) && (
62
+ <div class="semics-booking-session" data-testid="booking-session">
63
+ {startsAt && <p class="semics-booking-when"><time datetime={startsAt} data-testid="booking-when">{at(startsAt)}</time></p>}
64
+ {booking.requested && <p class="semics-booking-when" data-testid="booking-requested">{t("booking.requested", { when: booking.requested })}</p>}
65
+ {event?.venue && <p class="semics-booking-venue" data-testid="booking-venue">{event.venue}</p>}
66
+ </div>
67
+ )}
68
+ <div class="semics-booking-meta">
69
+ <p class="semics-status" data-testid="booking-status" data-status={status}>
70
+ <span class="semics-status-badge">{statusLabel(status, locale)}</span>
71
+ </p>
72
+ <p class="semics-booking-ref">
73
+ {t("booking.reference")} <strong data-testid="booking-ref">{booking.bookingRef}</strong>
74
+ </p>
75
+ </div>
76
+ {/* A booking request (T174a) waiting for the organiser to agree a time. */}
77
+ {status === "awaiting_approval" && booking.requested && !proposed && <p class="semics-booking-note" data-testid="booking-request">{t("booking.requestSent")}</p>}
78
+ {proposed && (
79
+ <section class="semics-booking-proposal" data-testid="booking-proposal" aria-labelledby="semics-booking-proposal-title">
80
+ <h3 id="semics-booking-proposal-title">{t("booking.proposal.title")}</h3>
81
+ <p>{t("booking.proposal.lead")}</p>
82
+ <p class="semics-booking-when"><time datetime={proposed.startsAt} data-testid="booking-proposed">{at(proposed.startsAt)}</time></p>
83
+ {proposalAction && (
84
+ <div class="semics-booking-proposal-actions">
85
+ <form method="post" action={proposalAction}>
86
+ <input type="hidden" name="intent" value="accept-time" />
87
+ <button type="submit" data-testid="booking-proposal-accept">{t("booking.proposal.accept")}</button>
88
+ </form>
89
+ <form method="post" action={proposalAction}>
90
+ <input type="hidden" name="intent" value="refuse-time" />
91
+ <button type="submit" class="semics-booking-refuse" data-testid="booking-proposal-refuse">{t("booking.proposal.refuse")}</button>
92
+ </form>
93
+ </div>
94
+ )}
95
+ {proposalAction && <p class="semics-booking-note">{t("booking.proposal.refuseNote")}</p>}
96
+ </section>
97
+ )}
48
98
  {
49
99
  !cancelled && booking.holdExpiresAt && (
50
- <p data-testid="booking-hold">
100
+ <p class="semics-booking-note" data-testid="booking-hold">
51
101
  {heldBefore}<time datetime={booking.holdExpiresAt}>{at(booking.holdExpiresAt)}</time>{heldAfter}
52
102
  </p>
53
103
  )
54
104
  }
55
- <ul class="semics-lines" aria-label={plural("booking.lines", tickets)}>
56
- {
57
- booking.lines.map((line) => (
58
- <li>
59
- {ticketNames[line.ticketTypeId]
60
- ? t("booking.line", { qty: new Intl.NumberFormat(locale).format(line.qty), name: ticketNames[line.ticketTypeId] })
61
- : plural("booking.lines", line.qty)}
62
- </li>
63
- ))
64
- }
65
- </ul>
66
- <p>{t("booking.total")} <strong>{formatMoney(booking.totals.totalMinor, booking.totals.currency, locale)}</strong></p>
105
+ {notes.map((note) => <p class="semics-booking-note" data-testid="booking-note">{note}</p>)}
106
+ {status === "expired" && bookAgain && <p><a href={bookAgain} data-testid="booking-book-again">{t("booking.bookAgain")}</a></p>}
107
+ <div class="semics-booking-order">
108
+ <ul class="semics-lines" aria-label={plural("booking.lines", tickets)}>
109
+ {
110
+ booking.lines.map((line) => (
111
+ <li>
112
+ {ticketNames[line.ticketTypeId]
113
+ ? t("booking.line", { qty: new Intl.NumberFormat(locale).format(line.qty), name: ticketNames[line.ticketTypeId] })
114
+ : plural("booking.lines", line.qty)}
115
+ </li>
116
+ ))
117
+ }
118
+ </ul>
119
+ {names.length > 0 && (
120
+ <div class="semics-booking-people" data-testid="booking-attendees">
121
+ <h3>{t("booking.attendeesHeading")}</h3>
122
+ <ul>{names.map((name) => <li>{name}</li>)}</ul>
123
+ </div>
124
+ )}
125
+ {(booking.totals.voucherMinor ?? 0) > 0 && (
126
+ <p class="semics-booking-voucher" data-testid="booking-voucher">
127
+ {t("booking.voucher")} <span>−{formatMoney(booking.totals.voucherMinor ?? 0, booking.totals.currency, locale)}</span>
128
+ </p>
129
+ )}
130
+ <p class="semics-booking-total">{t("booking.total")} <strong>{formatMoney(booking.totals.totalMinor, booking.totals.currency, locale)}</strong></p>
131
+ </div>
67
132
  {
68
133
  booking.canCancel && !cancelled && cancelAction && (
69
- <form method="post" action={cancelAction}>
70
- <input type="hidden" name="intent" value="cancel" />
71
- {booking.cancelBy && (
72
- <p>
73
- {cancelBefore}<time datetime={booking.cancelBy}>{at(booking.cancelBy)}</time>{cancelAfter}
74
- </p>
75
- )}
76
- <button type="submit">{t("booking.cancel")}</button>
77
- </form>
134
+ <CancelBooking action={cancelAction} cancelBy={booking.cancelBy} zone={zone} locale={locale} />
78
135
  )
79
136
  }
80
137
  </section>
@@ -82,24 +139,118 @@ const at = (iso: string) => {
82
139
  <style>
83
140
  .semics-booking-status {
84
141
  box-sizing: border-box;
85
- max-inline-size: 36rem;
86
142
  color: var(--events-fg, #1a1a1a);
87
143
  overflow-wrap: anywhere;
88
144
  }
145
+ .semics-booking-status p {
146
+ margin: 0 0 0.5rem;
147
+ }
148
+ .semics-booking-status .semics-booking-event {
149
+ margin: 0 0 0.5rem;
150
+ font-size: clamp(1.375rem, 1.2rem + 0.8vw, 1.75rem);
151
+ line-height: 1.2;
152
+ }
153
+ .semics-booking-session {
154
+ margin-block-end: 1.25rem;
155
+ }
156
+ .semics-booking-status .semics-booking-when {
157
+ margin: 0;
158
+ font-size: 1.125rem;
159
+ font-weight: 600;
160
+ }
161
+ .semics-booking-status .semics-booking-venue {
162
+ margin: 0;
163
+ color: var(--events-muted, #4a4a4a);
164
+ }
165
+ .semics-booking-meta {
166
+ display: flex;
167
+ flex-wrap: wrap;
168
+ align-items: center;
169
+ gap: 0.5rem 1rem;
170
+ margin-block-end: 0.75rem;
171
+ }
172
+ .semics-booking-meta p {
173
+ margin: 0;
174
+ }
175
+ .semics-booking-ref {
176
+ color: var(--events-muted, #4a4a4a);
177
+ }
178
+ .semics-booking-ref strong {
179
+ color: var(--events-fg, #1a1a1a);
180
+ letter-spacing: 0.04em;
181
+ }
89
182
  .semics-status-badge {
90
183
  display: inline-block;
91
- padding: 0.125rem 0.5rem;
184
+ padding: 0.125rem 0.625rem;
92
185
  border: 1px solid currentColor;
93
- border-radius: var(--events-radius, 6px);
186
+ border-radius: 999px;
187
+ font-size: 0.875rem;
94
188
  font-weight: 600;
95
189
  }
96
190
  .semics-booking-status[data-status="confirmed"] .semics-status-badge {
97
191
  color: var(--events-success, #146c2e);
98
192
  }
99
- .semics-booking-status button {
100
- font: inherit;
101
- min-block-size: 2.75rem;
102
- padding: 0.5rem 1rem;
193
+ .semics-booking-note {
194
+ color: var(--events-muted, #4a4a4a);
195
+ }
196
+ .semics-booking-proposal {
197
+ margin-block: 1rem;
198
+ padding: 0.75rem 1rem;
199
+ border: 1px solid color-mix(in srgb, var(--events-border, #6b6b6b) 40%, transparent);
200
+ border-radius: 0.5rem;
201
+ }
202
+ .semics-booking-proposal h3 {
203
+ margin: 0 0 0.5rem;
204
+ font-size: 1rem;
205
+ }
206
+ .semics-booking-proposal-actions {
207
+ display: flex;
208
+ flex-wrap: wrap;
209
+ gap: 0.5rem;
210
+ margin-block: 0.75rem 0.5rem;
211
+ }
212
+ .semics-booking-proposal-actions form {
213
+ margin: 0;
214
+ }
215
+ .semics-booking-proposal-actions .semics-booking-refuse {
216
+ background: transparent;
217
+ color: var(--events-accent, #0b57d0);
218
+ }
219
+ .semics-booking-order {
220
+ margin-block-start: 1.25rem;
221
+ padding-block-start: 1rem;
222
+ border-block-start: 1px solid color-mix(in srgb, var(--events-border, #6b6b6b) 30%, transparent);
223
+ }
224
+ .semics-lines {
225
+ margin: 0 0 0.75rem;
226
+ padding: 0;
227
+ list-style: none;
228
+ }
229
+ .semics-lines li + li {
230
+ margin-block-start: 0.25rem;
231
+ }
232
+ .semics-booking-people h3 {
233
+ margin: 0 0 0.25rem;
234
+ font-size: 0.8125rem;
235
+ letter-spacing: 0.06em;
236
+ text-transform: uppercase;
237
+ color: var(--events-muted, #4a4a4a);
238
+ }
239
+ .semics-booking-people ul {
240
+ margin: 0 0 0.75rem;
241
+ padding-inline-start: 1.25rem;
242
+ }
243
+ .semics-booking-status .semics-booking-total {
244
+ display: flex;
245
+ justify-content: space-between;
246
+ gap: 1rem;
247
+ margin: 0;
248
+ padding-block-start: 0.75rem;
249
+ border-block-start: 1px solid color-mix(in srgb, var(--events-border, #6b6b6b) 30%, transparent);
250
+ font-weight: 600;
251
+ }
252
+ .semics-booking-total strong {
253
+ font-size: 1.125rem;
103
254
  }
104
255
  .semics-visually-hidden {
105
256
  position: absolute;