@semics-tech/emdash-events 1.0.0-rc.0 → 1.0.0-rc.10

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,74 +1,99 @@
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.
4
6
  import { around, pickLocale, translator } from "../i18n/index";
5
- import { type BookingView, formatMoney, statusLabel } from "./lib/widget";
7
+ import CancelBooking from "./CancelBooking.astro";
8
+ import { zonedAt } from "./lib/list";
9
+ import { type BookingView, endedNotes, formatMoney, statusLabel } from "./lib/widget";
6
10
 
7
11
  interface Props {
8
12
  booking: BookingView;
9
13
  /** Shown as cancelled (the page just cancelled it). */
10
14
  cancelled?: boolean;
11
- /** Where the cancel form posts. */
15
+ /** Where the cancel form posts; without it the card has no cancel action. */
12
16
  cancelAction?: string;
13
17
  /** Ticket type names by id, when the page knows them. */
14
18
  ticketNames?: Record<string, string>;
19
+ /** A lapsed booking's way back: the event's page, when known. */
20
+ bookAgain?: string;
21
+ /** List the attendees' names (the page turns it off when Events Pro's signing list shows them). */
22
+ showAttendees?: boolean;
15
23
  locale?: string;
16
24
  }
17
25
 
18
- const { booking, cancelled = false, cancelAction, ticketNames = {} } = Astro.props;
26
+ const { booking, cancelled = false, cancelAction, ticketNames = {}, bookAgain, showAttendees = true } = Astro.props;
19
27
  const locale = pickLocale(Astro.props.locale, Astro.currentLocale);
20
28
  const { t, plural, lang, dir } = translator(locale);
21
- const [heldBefore, heldAfter] = around(t("booking.heldUntil"), "time");
22
- const [cancelBefore, cancelAfter] = around(t("booking.cancelUntil"), "time");
29
+ // A request awaiting approval (T131) holds its places until the organiser's deadline.
30
+ const [heldBefore, heldAfter] = around(
31
+ t(booking.status === "awaiting_approval" ? "booking.decideBy" : "booking.heldUntil"),
32
+ "time",
33
+ );
23
34
  const tickets = booking.lines.reduce((n, line) => n + line.qty, 0);
24
35
  const status = cancelled ? "cancelled" : booking.status;
25
- const at = (iso: string) => {
26
- try {
27
- const time = new Intl.DateTimeFormat(locale, { dateStyle: "medium", timeStyle: "short", timeZone: "UTC" }).format(
28
- new Date(iso),
29
- );
30
- return t("time.utc", { time });
31
- } catch {
32
- return iso;
33
- }
34
- };
36
+ const zone = booking.event?.timezone;
37
+ const at = (iso: string) => zonedAt(iso, zone, locale);
38
+ const notes = endedNotes({ ...booking, status }, locale);
39
+ const event = booking.event;
40
+ const startsAt = event?.startsAt && Number.isFinite(Date.parse(event.startsAt)) ? event.startsAt : undefined;
41
+ // Who is coming, when the booking names different people (a plain booking puts every seat in the buyer's name).
42
+ const named = booking.attendees.map((a) => a.name).filter(Boolean);
43
+ const names = showAttendees && new Set(named).size > 1 ? named : [];
35
44
  ---
36
45
  <section class="semics-events semics-booking-status" data-testid="booking-details" data-status={status} lang={lang} dir={dir} aria-labelledby="semics-booking-status-title">
37
- <h2 id="semics-booking-status-title" class="semics-visually-hidden">{t("booking.status")}</h2>
38
- <p>
39
- {t("booking.reference")} <strong data-testid="booking-ref">{booking.bookingRef}</strong>
40
- </p>
41
- <p class="semics-status" data-testid="booking-status" data-status={status}>
42
- <span class="semics-status-badge">{statusLabel(status, locale)}</span>
43
- </p>
46
+ {event?.title ? (
47
+ <h2 id="semics-booking-status-title" class="semics-booking-event" data-testid="booking-event">{event.title}</h2>
48
+ ) : (
49
+ <h2 id="semics-booking-status-title" class="semics-visually-hidden">{t("booking.status")}</h2>
50
+ )}
51
+ {(startsAt || event?.venue) && (
52
+ <div class="semics-booking-session" data-testid="booking-session">
53
+ {startsAt && <p class="semics-booking-when"><time datetime={startsAt} data-testid="booking-when">{at(startsAt)}</time></p>}
54
+ {event?.venue && <p class="semics-booking-venue" data-testid="booking-venue">{event.venue}</p>}
55
+ </div>
56
+ )}
57
+ <div class="semics-booking-meta">
58
+ <p class="semics-status" data-testid="booking-status" data-status={status}>
59
+ <span class="semics-status-badge">{statusLabel(status, locale)}</span>
60
+ </p>
61
+ <p class="semics-booking-ref">
62
+ {t("booking.reference")} <strong data-testid="booking-ref">{booking.bookingRef}</strong>
63
+ </p>
64
+ </div>
44
65
  {
45
66
  !cancelled && booking.holdExpiresAt && (
46
- <p data-testid="booking-hold">
67
+ <p class="semics-booking-note" data-testid="booking-hold">
47
68
  {heldBefore}<time datetime={booking.holdExpiresAt}>{at(booking.holdExpiresAt)}</time>{heldAfter}
48
69
  </p>
49
70
  )
50
71
  }
51
- <ul class="semics-lines" aria-label={plural("booking.lines", tickets)}>
52
- {
53
- booking.lines.map((line) => (
54
- <li>
55
- {t("booking.line", { qty: new Intl.NumberFormat(locale).format(line.qty), name: ticketNames[line.ticketTypeId] ?? line.ticketTypeId })}
56
- </li>
57
- ))
58
- }
59
- </ul>
60
- <p>{t("booking.total")} <strong>{formatMoney(booking.totals.totalMinor, booking.totals.currency, locale)}</strong></p>
72
+ {notes.map((note) => <p class="semics-booking-note" data-testid="booking-note">{note}</p>)}
73
+ {status === "expired" && bookAgain && <p><a href={bookAgain} data-testid="booking-book-again">{t("booking.bookAgain")}</a></p>}
74
+ <div class="semics-booking-order">
75
+ <ul class="semics-lines" aria-label={plural("booking.lines", tickets)}>
76
+ {
77
+ booking.lines.map((line) => (
78
+ <li>
79
+ {ticketNames[line.ticketTypeId]
80
+ ? t("booking.line", { qty: new Intl.NumberFormat(locale).format(line.qty), name: ticketNames[line.ticketTypeId] })
81
+ : plural("booking.lines", line.qty)}
82
+ </li>
83
+ ))
84
+ }
85
+ </ul>
86
+ {names.length > 0 && (
87
+ <div class="semics-booking-people" data-testid="booking-attendees">
88
+ <h3>{t("booking.attendeesHeading")}</h3>
89
+ <ul>{names.map((name) => <li>{name}</li>)}</ul>
90
+ </div>
91
+ )}
92
+ <p class="semics-booking-total">{t("booking.total")} <strong>{formatMoney(booking.totals.totalMinor, booking.totals.currency, locale)}</strong></p>
93
+ </div>
61
94
  {
62
95
  booking.canCancel && !cancelled && cancelAction && (
63
- <form method="post" action={cancelAction}>
64
- <input type="hidden" name="intent" value="cancel" />
65
- {booking.cancelBy && (
66
- <p>
67
- {cancelBefore}<time datetime={booking.cancelBy}>{at(booking.cancelBy)}</time>{cancelAfter}
68
- </p>
69
- )}
70
- <button type="submit">{t("booking.cancel")}</button>
71
- </form>
96
+ <CancelBooking action={cancelAction} cancelBy={booking.cancelBy} zone={zone} locale={locale} />
72
97
  )
73
98
  }
74
99
  </section>
@@ -76,24 +101,95 @@ const at = (iso: string) => {
76
101
  <style>
77
102
  .semics-booking-status {
78
103
  box-sizing: border-box;
79
- max-inline-size: 36rem;
80
104
  color: var(--events-fg, #1a1a1a);
81
105
  overflow-wrap: anywhere;
82
106
  }
107
+ .semics-booking-status p {
108
+ margin: 0 0 0.5rem;
109
+ }
110
+ .semics-booking-status .semics-booking-event {
111
+ margin: 0 0 0.5rem;
112
+ font-size: clamp(1.375rem, 1.2rem + 0.8vw, 1.75rem);
113
+ line-height: 1.2;
114
+ }
115
+ .semics-booking-session {
116
+ margin-block-end: 1.25rem;
117
+ }
118
+ .semics-booking-status .semics-booking-when {
119
+ margin: 0;
120
+ font-size: 1.125rem;
121
+ font-weight: 600;
122
+ }
123
+ .semics-booking-status .semics-booking-venue {
124
+ margin: 0;
125
+ color: var(--events-muted, #4a4a4a);
126
+ }
127
+ .semics-booking-meta {
128
+ display: flex;
129
+ flex-wrap: wrap;
130
+ align-items: center;
131
+ gap: 0.5rem 1rem;
132
+ margin-block-end: 0.75rem;
133
+ }
134
+ .semics-booking-meta p {
135
+ margin: 0;
136
+ }
137
+ .semics-booking-ref {
138
+ color: var(--events-muted, #4a4a4a);
139
+ }
140
+ .semics-booking-ref strong {
141
+ color: var(--events-fg, #1a1a1a);
142
+ letter-spacing: 0.04em;
143
+ }
83
144
  .semics-status-badge {
84
145
  display: inline-block;
85
- padding: 0.125rem 0.5rem;
146
+ padding: 0.125rem 0.625rem;
86
147
  border: 1px solid currentColor;
87
- border-radius: var(--events-radius, 6px);
148
+ border-radius: 999px;
149
+ font-size: 0.875rem;
88
150
  font-weight: 600;
89
151
  }
90
152
  .semics-booking-status[data-status="confirmed"] .semics-status-badge {
91
153
  color: var(--events-success, #146c2e);
92
154
  }
93
- .semics-booking-status button {
94
- font: inherit;
95
- min-block-size: 2.75rem;
96
- padding: 0.5rem 1rem;
155
+ .semics-booking-note {
156
+ color: var(--events-muted, #4a4a4a);
157
+ }
158
+ .semics-booking-order {
159
+ margin-block-start: 1.25rem;
160
+ padding-block-start: 1rem;
161
+ border-block-start: 1px solid color-mix(in srgb, var(--events-border, #6b6b6b) 30%, transparent);
162
+ }
163
+ .semics-lines {
164
+ margin: 0 0 0.75rem;
165
+ padding: 0;
166
+ list-style: none;
167
+ }
168
+ .semics-lines li + li {
169
+ margin-block-start: 0.25rem;
170
+ }
171
+ .semics-booking-people h3 {
172
+ margin: 0 0 0.25rem;
173
+ font-size: 0.8125rem;
174
+ letter-spacing: 0.06em;
175
+ text-transform: uppercase;
176
+ color: var(--events-muted, #4a4a4a);
177
+ }
178
+ .semics-booking-people ul {
179
+ margin: 0 0 0.75rem;
180
+ padding-inline-start: 1.25rem;
181
+ }
182
+ .semics-booking-status .semics-booking-total {
183
+ display: flex;
184
+ justify-content: space-between;
185
+ gap: 1rem;
186
+ margin: 0;
187
+ padding-block-start: 0.75rem;
188
+ border-block-start: 1px solid color-mix(in srgb, var(--events-border, #6b6b6b) 30%, transparent);
189
+ font-weight: 600;
190
+ }
191
+ .semics-booking-total strong {
192
+ font-size: 1.125rem;
97
193
  }
98
194
  .semics-visually-hidden {
99
195
  position: absolute;