@shoppexio/storefront-react 0.6.0 → 0.6.1

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.
@@ -126,6 +126,8 @@ export interface BillingHistoryInvoice {
126
126
  kind: 'first_order' | 'renewal' | 'plan_change';
127
127
  /** The plan change it paid for; null on a renewal or a first order. Days are null when the producer did not count them. */
128
128
  plan_change: { from_plan_name: string; to_plan_name: string; days_left: number | null; days_total: number | null } | null;
129
+ /** The coupon term payment it billed (`BillingHistoryCouponPayment`): the code, its 1-based payment, and the payments it discounts (null: every one). Null when it billed none. */
130
+ coupon_payment: { code: string; payment: number; payments_total: number | null } | null;
129
131
  }
130
132
 
131
133
  const BILLING_KINDS: ReadonlyArray<BillingHistoryInvoice['kind']> = ['first_order', 'renewal', 'plan_change'];
@@ -147,6 +149,17 @@ function readPlanChange(value: unknown): BillingHistoryInvoice['plan_change'] |
147
149
  return { from_plan_name: from, to_plan_name: to, days_left: daysLeft, days_total: daysTotal };
148
150
  }
149
151
 
152
+ // The route sends the field on every row (required, nullable): only null means no coupon payment; absent or malformed fails the read.
153
+ function readCouponPayment(value: unknown): BillingHistoryInvoice['coupon_payment'] | undefined {
154
+ if (value === null) return null;
155
+ if (!isRecord(value)) return undefined;
156
+ const code = readString(value, 'code');
157
+ const payment = readCount(value, 'payment');
158
+ const paymentsTotal = readCount(value, 'payments_total');
159
+ if (code === null || payment === undefined || payment === null || paymentsTotal === undefined) return undefined;
160
+ return { code, payment, payments_total: paymentsTotal };
161
+ }
162
+
150
163
  /** What a billing history row billed (Design Batch 9, C3), as a catalog key: "Renewal", "First order", "Plan change, Basic to Pro". */
151
164
  export function billingEntryTitle(invoice: BillingHistoryInvoice): { key: string; params?: { from: string; to: string } } {
152
165
  if (invoice.plan_change) {
@@ -199,11 +212,12 @@ export function narrowBillingHistory(payload: unknown): BillingHistoryResult {
199
212
  // A kind this build does not know fails the read: a row that guesses what it billed could misname a charge.
200
213
  const kind = BILLING_KINDS.find((known) => known === entry.kind);
201
214
  const planChange = readPlanChange(entry.plan_change);
202
- if (uniqid === null || total === null || currency === null || status === null || createdAt === null || !kind || planChange === undefined) {
215
+ const couponPayment = readCouponPayment(entry.coupon_payment);
216
+ if (uniqid === null || total === null || currency === null || status === null || createdAt === null || !kind || planChange === undefined || couponPayment === undefined) {
203
217
  return { ok: false };
204
218
  }
205
219
 
206
- invoices.push({ uniqid, total, currency, status, created_at: createdAt, kind, plan_change: planChange });
220
+ invoices.push({ uniqid, total, currency, status, created_at: createdAt, kind, plan_change: planChange, coupon_payment: couponPayment });
207
221
  }
208
222
 
209
223
  return { ok: true, invoices };
@@ -365,7 +365,8 @@
365
365
  "historyFirstOrder": "الطلب الأول",
366
366
  "historyRenewal": "تجديد",
367
367
  "historyPlanChange": "تغيير الخطة، من {from} إلى {to}",
368
- "historyDays": "عن {days} من {total} يومًا"
368
+ "historyDays": "عن {days} من {total} يومًا",
369
+ "historyCouponPayment": "{code} · {payment} من {total}"
369
370
  },
370
371
  "favorites": {
371
372
  "loading": "جارٍ تحميل مفضلتك",
@@ -365,7 +365,8 @@
365
365
  "historyFirstOrder": "Erstbestellung",
366
366
  "historyRenewal": "Verlängerung",
367
367
  "historyPlanChange": "Tarifwechsel, {from} zu {to}",
368
- "historyDays": "für {days} von {total} Tagen"
368
+ "historyDays": "für {days} von {total} Tagen",
369
+ "historyCouponPayment": "{code} · {payment} von {total}"
369
370
  },
370
371
  "favorites": {
371
372
  "loading": "Deine Favoriten werden geladen",
@@ -365,7 +365,8 @@
365
365
  "historyFirstOrder": "First order",
366
366
  "historyRenewal": "Renewal",
367
367
  "historyPlanChange": "Plan change, {from} to {to}",
368
- "historyDays": "for {days} of {total} days"
368
+ "historyDays": "for {days} of {total} days",
369
+ "historyCouponPayment": "{code} · {payment} of {total}"
369
370
  },
370
371
  "favorites": {
371
372
  "loading": "Loading your favorites",
@@ -365,7 +365,8 @@
365
365
  "historyFirstOrder": "Primer pedido",
366
366
  "historyRenewal": "Renovación",
367
367
  "historyPlanChange": "Cambio de plan, de {from} a {to}",
368
- "historyDays": "por {days} de {total} días"
368
+ "historyDays": "por {days} de {total} días",
369
+ "historyCouponPayment": "{code} · {payment} de {total}"
369
370
  },
370
371
  "favorites": {
371
372
  "loading": "Cargando tus favoritos",
@@ -365,7 +365,8 @@
365
365
  "historyFirstOrder": "Ensimmäinen tilaus",
366
366
  "historyRenewal": "Uusinta",
367
367
  "historyPlanChange": "Sopimuksen vaihto, {from} → {to}",
368
- "historyDays": "{days}/{total} päivältä"
368
+ "historyDays": "{days}/{total} päivältä",
369
+ "historyCouponPayment": "{code} · {payment}/{total}"
369
370
  },
370
371
  "favorites": {
371
372
  "loading": "Ladataan suosikkejasi",
@@ -365,7 +365,8 @@
365
365
  "historyFirstOrder": "Première commande",
366
366
  "historyRenewal": "Renouvellement",
367
367
  "historyPlanChange": "Changement de formule, de {from} à {to}",
368
- "historyDays": "pour {days} jours sur {total}"
368
+ "historyDays": "pour {days} jours sur {total}",
369
+ "historyCouponPayment": "{code} · {payment} sur {total}"
369
370
  },
370
371
  "favorites": {
371
372
  "loading": "Chargement de vos favoris",
@@ -365,7 +365,8 @@
365
365
  "historyFirstOrder": "पहला ऑर्डर",
366
366
  "historyRenewal": "नवीनीकरण",
367
367
  "historyPlanChange": "योजना बदलाव, {from} से {to}",
368
- "historyDays": "{total} में से {days} दिनों के लिए"
368
+ "historyDays": "{total} में से {days} दिनों के लिए",
369
+ "historyCouponPayment": "{code} · {total} में से {payment}"
369
370
  },
370
371
  "favorites": {
371
372
  "loading": "आपके पसंदीदा लोड हो रहे हैं",
@@ -365,7 +365,8 @@
365
365
  "historyFirstOrder": "Primo ordine",
366
366
  "historyRenewal": "Rinnovo",
367
367
  "historyPlanChange": "Cambio piano, da {from} a {to}",
368
- "historyDays": "per {days} giorni su {total}"
368
+ "historyDays": "per {days} giorni su {total}",
369
+ "historyCouponPayment": "{code} · {payment} di {total}"
369
370
  },
370
371
  "favorites": {
371
372
  "loading": "Caricamento dei tuoi preferiti",
@@ -365,7 +365,8 @@
365
365
  "historyFirstOrder": "Pirmas užsakymas",
366
366
  "historyRenewal": "Atnaujinimas",
367
367
  "historyPlanChange": "Plano keitimas, {from} → {to}",
368
- "historyDays": "už {days} iš {total} d."
368
+ "historyDays": "už {days} iš {total} d.",
369
+ "historyCouponPayment": "{code} · {payment} iš {total}"
369
370
  },
370
371
  "favorites": {
371
372
  "loading": "Įkeliami jūsų mėgstami",
@@ -365,7 +365,8 @@
365
365
  "historyFirstOrder": "Eerste bestelling",
366
366
  "historyRenewal": "Verlenging",
367
367
  "historyPlanChange": "Pakketwijziging, van {from} naar {to}",
368
- "historyDays": "voor {days} van {total} dagen"
368
+ "historyDays": "voor {days} van {total} dagen",
369
+ "historyCouponPayment": "{code} · {payment} van {total}"
369
370
  },
370
371
  "favorites": {
371
372
  "loading": "Je favorieten worden geladen",
@@ -365,7 +365,8 @@
365
365
  "historyFirstOrder": "Pierwsze zamówienie",
366
366
  "historyRenewal": "Odnowienie",
367
367
  "historyPlanChange": "Zmiana planu, z {from} na {to}",
368
- "historyDays": "za {days} z {total} dni"
368
+ "historyDays": "za {days} z {total} dni",
369
+ "historyCouponPayment": "{code} · {payment} z {total}"
369
370
  },
370
371
  "favorites": {
371
372
  "loading": "Wczytujemy Twoje ulubione",
@@ -365,7 +365,8 @@
365
365
  "historyFirstOrder": "Primeiro pedido",
366
366
  "historyRenewal": "Renovação",
367
367
  "historyPlanChange": "Mudança de plano, de {from} para {to}",
368
- "historyDays": "por {days} de {total} dias"
368
+ "historyDays": "por {days} de {total} dias",
369
+ "historyCouponPayment": "{code} · {payment} de {total}"
369
370
  },
370
371
  "favorites": {
371
372
  "loading": "A carregar os teus favoritos",
@@ -365,7 +365,8 @@
365
365
  "historyFirstOrder": "Первый заказ",
366
366
  "historyRenewal": "Продление",
367
367
  "historyPlanChange": "Смена тарифа: {from} на {to}",
368
- "historyDays": "за {days} из {total} дн."
368
+ "historyDays": "за {days} из {total} дн.",
369
+ "historyCouponPayment": "{code} · {payment} из {total}"
369
370
  },
370
371
  "favorites": {
371
372
  "loading": "Загружаем ваше избранное",
@@ -365,7 +365,8 @@
365
365
  "historyFirstOrder": "İlk sipariş",
366
366
  "historyRenewal": "Yenileme",
367
367
  "historyPlanChange": "Plan değişikliği, {from} → {to}",
368
- "historyDays": "{total} günün {days} günü için"
368
+ "historyDays": "{total} günün {days} günü için",
369
+ "historyCouponPayment": "{code} · {payment}/{total}"
369
370
  },
370
371
  "favorites": {
371
372
  "loading": "Favorileriniz yükleniyor",
@@ -365,7 +365,8 @@
365
365
  "historyFirstOrder": "Перше замовлення",
366
366
  "historyRenewal": "Продовження",
367
367
  "historyPlanChange": "Зміна тарифу: {from} на {to}",
368
- "historyDays": "за {days} з {total} дн."
368
+ "historyDays": "за {days} з {total} дн.",
369
+ "historyCouponPayment": "{code} · {payment} з {total}"
369
370
  },
370
371
  "favorites": {
371
372
  "loading": "Завантажуємо ваше обране",
@@ -365,7 +365,8 @@
365
365
  "historyFirstOrder": "首次订单",
366
366
  "historyRenewal": "续订",
367
367
  "historyPlanChange": "套餐变更:{from} 改为 {to}",
368
- "historyDays": "{total} 天中的 {days} 天"
368
+ "historyDays": "{total} 天中的 {days} 天",
369
+ "historyCouponPayment": "{code} · 第 {payment}/{total} 次"
369
370
  },
370
371
  "favorites": {
371
372
  "loading": "正在加载你的收藏",
@@ -776,6 +776,7 @@ export function BillingHistoryList({ payload, reload }: { payload: unknown; relo
776
776
  {history.invoices.map((invoice) => {
777
777
  const title = billingEntryTitle(invoice);
778
778
  const days = billingEntryDays(invoice);
779
+ const coupon = invoice.coupon_payment;
779
780
  return (
780
781
  <li key={invoice.uniqid}>
781
782
  <Link
@@ -788,6 +789,14 @@ export function BillingHistoryList({ payload, reload }: { payload: unknown; relo
788
789
  {formatAccountDate(invoice.created_at)}
789
790
  {days ? ` · ${t(days.key, days.params)}` : null}
790
791
  </p>
792
+ {/* A discounted payment names its code and which term payment it was, as the dashboard does: "LAUNCH20 · 2 of 3", the code alone when every payment is discounted. Its own line, so it does not wrap after the date at 375 px. */}
793
+ {coupon ? (
794
+ <p className="sxa:mt-0.5 sxa:text-micro sxa:tabular-nums sxa:text-muted">
795
+ {coupon.payments_total === null
796
+ ? coupon.code
797
+ : t('subscriptions.historyCouponPayment', { code: coupon.code, payment: coupon.payment, total: coupon.payments_total })}
798
+ </p>
799
+ ) : null}
791
800
  </div>
792
801
  <div className="sxa:flex sxa:shrink-0 sxa:flex-col sxa:items-end sxa:gap-1.5 sxa:sm:flex-row sxa:sm:items-center sxa:sm:gap-3">
793
802
  <span className="sxa:text-small sxa:font-semibold sxa:tabular-nums">{formatAccountAmount(invoice.total, invoice.currency)}</span>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shoppexio/storefront-react",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "React hooks, models and a customer account for Shoppex code storefronts",
5
5
  "type": "module",
6
6
  "homepage": "https://docs.shoppex.io/storefront/code-storefront-development",