@schematichq/schematic-components 2.26.0 → 2.27.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.
- package/dist/schematic-components-elements.cjs.js +324 -10
- package/dist/schematic-components-elements.d.ts +169 -0
- package/dist/schematic-components-elements.esm.js +317 -2
- package/dist/schematic-components.browser.cjs.js +627 -3
- package/dist/schematic-components.browser.esm.js +627 -3
- package/dist/schematic-components.cjs.js +627 -3
- package/dist/schematic-components.d.ts +12 -0
- package/dist/schematic-components.esm.js +627 -3
- package/package.json +4 -4
|
@@ -20,18 +20,22 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/elements/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
-
BillingDataProvider: () =>
|
|
23
|
+
BillingDataProvider: () => import_schematic_react4.BillingDataProvider,
|
|
24
24
|
DEFAULT_STRINGS: () => DEFAULT_STRINGS,
|
|
25
25
|
Invoices: () => Invoices,
|
|
26
26
|
SCHEMATIC_TOKENS: () => SCHEMATIC_TOKENS,
|
|
27
|
-
SchematicI18nProvider: () =>
|
|
27
|
+
SchematicI18nProvider: () => import_schematic_react4.SchematicI18nProvider,
|
|
28
28
|
SchematicStyles: () => SchematicStyles,
|
|
29
|
+
UpcomingBill: () => UpcomingBill,
|
|
30
|
+
billingResources: () => billingResources,
|
|
29
31
|
deriveInvoiceList: () => deriveInvoiceList,
|
|
32
|
+
deriveUpcomingInvoice: () => deriveUpcomingInvoice,
|
|
30
33
|
featureName: () => featureName,
|
|
31
34
|
formatConsumptionRate: () => formatConsumptionRate,
|
|
32
35
|
formatCurrency: () => formatCurrency,
|
|
33
36
|
formatDate: () => formatDate,
|
|
34
37
|
formatNumber: () => formatNumber,
|
|
38
|
+
formatPercent: () => formatPercent,
|
|
35
39
|
formatShortDate: () => formatShortDate,
|
|
36
40
|
httpStatus: () => httpStatus,
|
|
37
41
|
interpolate: () => interpolate,
|
|
@@ -40,18 +44,19 @@ __export(index_exports, {
|
|
|
40
44
|
resolveLocale: () => resolveLocale,
|
|
41
45
|
schematicStylesCss: () => schematicStylesCss,
|
|
42
46
|
schematicTokensCss: () => schematicTokensCss,
|
|
43
|
-
useInvalidateBillingData: () =>
|
|
44
|
-
useInvoices: () =>
|
|
47
|
+
useInvalidateBillingData: () => import_schematic_react4.useInvalidateBillingData,
|
|
48
|
+
useInvoices: () => import_schematic_react4.useInvoices,
|
|
45
49
|
useResolvedLocale: () => useResolvedLocale,
|
|
46
|
-
useSchematicI18n: () =>
|
|
47
|
-
useSchematicLocale: () =>
|
|
48
|
-
useSchematicStrings: () =>
|
|
49
|
-
useSchematicTranslate: () =>
|
|
50
|
+
useSchematicI18n: () => import_schematic_react4.useSchematicI18n,
|
|
51
|
+
useSchematicLocale: () => import_schematic_react4.useSchematicLocale,
|
|
52
|
+
useSchematicStrings: () => import_schematic_react4.useSchematicStrings,
|
|
53
|
+
useSchematicTranslate: () => import_schematic_react4.useSchematicTranslate,
|
|
50
54
|
useTranslator: () => useTranslator,
|
|
55
|
+
useUpcomingInvoice: () => import_schematic_react4.useUpcomingInvoice,
|
|
51
56
|
viewerLocale: () => viewerLocale
|
|
52
57
|
});
|
|
53
58
|
module.exports = __toCommonJS(index_exports);
|
|
54
|
-
var
|
|
59
|
+
var import_schematic_react4 = require("@schematichq/schematic-react");
|
|
55
60
|
|
|
56
61
|
// src/elements/model/errors.ts
|
|
57
62
|
function httpStatus(error) {
|
|
@@ -511,6 +516,12 @@ function formatConsumptionRate(rate, locale) {
|
|
|
511
516
|
maximumFractionDigits: MAXIMUM_FRACTION_DIGITS
|
|
512
517
|
});
|
|
513
518
|
}
|
|
519
|
+
function formatPercent(fraction, locale) {
|
|
520
|
+
return new Intl.NumberFormat(usableLocale(locale), {
|
|
521
|
+
style: "percent",
|
|
522
|
+
maximumFractionDigits: 2
|
|
523
|
+
}).format(fraction);
|
|
524
|
+
}
|
|
514
525
|
function usableDate(date) {
|
|
515
526
|
if (date === null || date === void 0) {
|
|
516
527
|
return void 0;
|
|
@@ -600,6 +611,64 @@ function deriveInvoiceList(page, options) {
|
|
|
600
611
|
};
|
|
601
612
|
}
|
|
602
613
|
|
|
614
|
+
// src/elements/model/upcomingBill.ts
|
|
615
|
+
function deriveUpcomingInvoice(invoice, options) {
|
|
616
|
+
const { format, locale } = options;
|
|
617
|
+
const currency = invoice.currency.toUpperCase();
|
|
618
|
+
const money = (amountMinor) => format?.amount?.(amountMinor, currency, locale) ?? formatCurrency(amountMinor, currency, locale, {
|
|
619
|
+
preserveSubUnitPrecision: false
|
|
620
|
+
});
|
|
621
|
+
const line = (amountMinor) => ({
|
|
622
|
+
amountMinor,
|
|
623
|
+
amountText: money(amountMinor)
|
|
624
|
+
});
|
|
625
|
+
const applied = invoice.customerBalanceApplied;
|
|
626
|
+
const remaining = invoice.customerBalanceRemaining;
|
|
627
|
+
const dueDate = usableDate(invoice.dueDate) ?? null;
|
|
628
|
+
return {
|
|
629
|
+
amountDueMinor: invoice.amountDue,
|
|
630
|
+
amountDueText: money(invoice.amountDue),
|
|
631
|
+
subtotalMinor: invoice.subtotal,
|
|
632
|
+
subtotalText: money(invoice.subtotal),
|
|
633
|
+
currency,
|
|
634
|
+
dueAt: dueDate === null ? null : {
|
|
635
|
+
date: dueDate,
|
|
636
|
+
text: format?.date?.(dueDate, locale) ?? formatDate(dueDate, locale)
|
|
637
|
+
},
|
|
638
|
+
// A deduction: the sign is the locale's, so a host never assembles one.
|
|
639
|
+
balanceApplied: applied > 0 ? line(-applied) : null,
|
|
640
|
+
// Zero remaining is worth saying when a balance was spent; no balance at
|
|
641
|
+
// all is not.
|
|
642
|
+
balanceRemaining: applied > 0 || remaining > 0 ? line(remaining) : null,
|
|
643
|
+
discounts: invoice.discounts.flatMap(
|
|
644
|
+
(discount) => discountLine(discount, currency, locale, money)
|
|
645
|
+
)
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
function discountLine(discount, invoiceCurrency, locale, money) {
|
|
649
|
+
const percentOff = discount.percentOff ?? null;
|
|
650
|
+
const amountOff = discount.amountOff ?? null;
|
|
651
|
+
const isPercent = percentOff !== null && percentOff > 0;
|
|
652
|
+
if (!isPercent && (amountOff === null || amountOff <= 0)) {
|
|
653
|
+
return [];
|
|
654
|
+
}
|
|
655
|
+
const currency = discount.currency?.toUpperCase() ?? invoiceCurrency;
|
|
656
|
+
return [
|
|
657
|
+
{
|
|
658
|
+
couponName: discount.couponName,
|
|
659
|
+
code: discount.customerFacingCode ?? null,
|
|
660
|
+
kind: isPercent ? "percent" : "amount",
|
|
661
|
+
valueText: isPercent ? formatPercent(percentOff / 100, locale) : currency === invoiceCurrency ? money(amountOff ?? 0) : formatCurrency(amountOff ?? 0, currency, locale, {
|
|
662
|
+
preserveSubUnitPrecision: false
|
|
663
|
+
}),
|
|
664
|
+
percentOff: isPercent ? percentOff : null,
|
|
665
|
+
amountOffMinor: isPercent ? null : amountOff,
|
|
666
|
+
months: discount.duration === "repeating" ? discount.durationInMonths ?? null : null,
|
|
667
|
+
duration: discount.duration
|
|
668
|
+
}
|
|
669
|
+
];
|
|
670
|
+
}
|
|
671
|
+
|
|
603
672
|
// src/elements/strings.ts
|
|
604
673
|
var DEFAULT_STRINGS_LOCALE = "en";
|
|
605
674
|
var DEFAULT_STRINGS = {
|
|
@@ -614,7 +683,21 @@ var DEFAULT_STRINGS = {
|
|
|
614
683
|
invoicesLoadMore: "Load more",
|
|
615
684
|
invoicesChargeTooltip: "Charge \u2014 you were billed this amount",
|
|
616
685
|
invoicesCreditTooltip: "Credit \u2014 this amount was returned to your account, typically due to a plan change or proration",
|
|
617
|
-
invoicesUndated: "View invoice"
|
|
686
|
+
invoicesUndated: "View invoice",
|
|
687
|
+
upcomingBillLoading: "Loading your next bill",
|
|
688
|
+
upcomingBillHeader: "Next bill due {{date}}",
|
|
689
|
+
upcomingBillError: "There was a problem retrieving your upcoming invoice.",
|
|
690
|
+
upcomingBillUnavailable: "Your upcoming invoice is not available for this account.",
|
|
691
|
+
upcomingBillEmpty: "No upcoming invoice",
|
|
692
|
+
upcomingBillEstimate: "Estimated bill",
|
|
693
|
+
upcomingBillBalanceApplied: "Applied balance towards next invoice",
|
|
694
|
+
upcomingBillBalanceRemaining: "Remaining balance after next invoice",
|
|
695
|
+
upcomingBillDiscount: "Discount",
|
|
696
|
+
upcomingBillDiscountValue: "{{value}} off",
|
|
697
|
+
// Looked up by the bare key with `{ count }`; English has two forms.
|
|
698
|
+
upcomingBillDiscountRepeating: "{{value}} off for next {{count}} months",
|
|
699
|
+
upcomingBillDiscountRepeating_one: "{{value}} off for next month",
|
|
700
|
+
upcomingBillDiscountRepeating_other: "{{value}} off for next {{count}} months"
|
|
618
701
|
};
|
|
619
702
|
var MISSING_STRING = "\0schematic:missing";
|
|
620
703
|
function interpolate(template, vars) {
|
|
@@ -781,6 +864,83 @@ ${Object.entries(SCHEMATIC_TOKENS).map(([name, value]) => ` ${name}: ${value};`
|
|
|
781
864
|
}
|
|
782
865
|
`;
|
|
783
866
|
|
|
867
|
+
// src/elements/styles/upcoming-bill.ts
|
|
868
|
+
var upcomingBillCss = `
|
|
869
|
+
.schematic-upcoming-bill {
|
|
870
|
+
display: flex;
|
|
871
|
+
flex-direction: column;
|
|
872
|
+
gap: var(--schematic-space);
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
.schematic-upcoming-bill .schematic-header {
|
|
876
|
+
margin-bottom: 0;
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
.schematic-upcoming-bill .schematic-header__title {
|
|
880
|
+
margin-bottom: 0;
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
.schematic-upcoming-bill__amount {
|
|
884
|
+
align-items: flex-start;
|
|
885
|
+
display: flex;
|
|
886
|
+
gap: var(--schematic-space);
|
|
887
|
+
justify-content: space-between;
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
.schematic-upcoming-bill__total {
|
|
891
|
+
font-family: var(--schematic-font-heading);
|
|
892
|
+
font-size: 1.8125rem;
|
|
893
|
+
font-variant-numeric: tabular-nums;
|
|
894
|
+
font-weight: 800;
|
|
895
|
+
line-height: 1;
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
.schematic-upcoming-bill__estimate {
|
|
899
|
+
font-weight: 600;
|
|
900
|
+
max-width: 10rem;
|
|
901
|
+
text-align: end;
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
.schematic-upcoming-bill__rows {
|
|
905
|
+
display: flex;
|
|
906
|
+
flex-direction: column;
|
|
907
|
+
gap: var(--schematic-space);
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
.schematic-upcoming-bill .schematic-row__value {
|
|
911
|
+
font-variant-numeric: tabular-nums;
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
.schematic-upcoming-bill__discounts {
|
|
915
|
+
align-items: flex-end;
|
|
916
|
+
display: flex;
|
|
917
|
+
flex-direction: column;
|
|
918
|
+
gap: calc(var(--schematic-space) / 2);
|
|
919
|
+
list-style: none;
|
|
920
|
+
margin: 0;
|
|
921
|
+
padding: 0;
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
.schematic-upcoming-bill__discount {
|
|
925
|
+
align-items: center;
|
|
926
|
+
display: inline-flex;
|
|
927
|
+
gap: calc(var(--schematic-space) / 2);
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
.schematic-upcoming-bill__empty {
|
|
931
|
+
padding: calc(var(--schematic-space) / 2) 0;
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
.schematic-upcoming-bill .schematic-skeleton__cell[data-column="amount"] {
|
|
935
|
+
height: 1.8125rem;
|
|
936
|
+
width: 7rem;
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
.schematic-upcoming-bill .schematic-skeleton__cell[data-column="row"] {
|
|
940
|
+
width: 12rem;
|
|
941
|
+
}
|
|
942
|
+
`;
|
|
943
|
+
|
|
784
944
|
// src/elements/styles/index.tsx
|
|
785
945
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
786
946
|
var rulesCss = `
|
|
@@ -824,6 +984,12 @@ var rulesCss = `
|
|
|
824
984
|
gap: var(--schematic-space);
|
|
825
985
|
}
|
|
826
986
|
|
|
987
|
+
/* The message may run long; the action beside it stays one line. */
|
|
988
|
+
.schematic-status__retry {
|
|
989
|
+
flex-shrink: 0;
|
|
990
|
+
white-space: nowrap;
|
|
991
|
+
}
|
|
992
|
+
|
|
827
993
|
/* Visually hidden, still read by assistive technology. */
|
|
828
994
|
.schematic-hidden {
|
|
829
995
|
border: 0;
|
|
@@ -1090,6 +1256,22 @@ var rulesCss = `
|
|
|
1090
1256
|
margin: 0 0 calc(var(--schematic-space) / 2);
|
|
1091
1257
|
}
|
|
1092
1258
|
|
|
1259
|
+
/* A label on the left, its value on the right. */
|
|
1260
|
+
.schematic-row {
|
|
1261
|
+
align-items: flex-start;
|
|
1262
|
+
display: flex;
|
|
1263
|
+
gap: var(--schematic-space);
|
|
1264
|
+
justify-content: space-between;
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1267
|
+
.schematic-row__label {
|
|
1268
|
+
font-weight: 600;
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
.schematic-row__value {
|
|
1272
|
+
text-align: end;
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1093
1275
|
.schematic-feature-list {
|
|
1094
1276
|
display: flex;
|
|
1095
1277
|
flex-direction: column;
|
|
@@ -1276,6 +1458,7 @@ var rulesCss = `
|
|
|
1276
1458
|
}
|
|
1277
1459
|
|
|
1278
1460
|
${invoicesCss}
|
|
1461
|
+
${upcomingBillCss}
|
|
1279
1462
|
`;
|
|
1280
1463
|
var schematicStylesCss = withTokenDefaults(rulesCss);
|
|
1281
1464
|
var SchematicStyles = () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("style", { "data-schematic-styles": "", children: schematicStylesCss });
|
|
@@ -1289,6 +1472,17 @@ var import_schematic_react = require("@schematichq/schematic-react");
|
|
|
1289
1472
|
var import_react = require("react");
|
|
1290
1473
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
1291
1474
|
var cx = (...names) => names.filter((name) => typeof name === "string" && name !== "").join(" ");
|
|
1475
|
+
function billingResources(...elements) {
|
|
1476
|
+
const names = [];
|
|
1477
|
+
for (const element of elements) {
|
|
1478
|
+
for (const name of element.resources) {
|
|
1479
|
+
if (!names.includes(name)) {
|
|
1480
|
+
names.push(name);
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
return names;
|
|
1485
|
+
}
|
|
1292
1486
|
function useResolvedLocale(locale) {
|
|
1293
1487
|
const configured = (0, import_schematic_react.useSchematicLocale)();
|
|
1294
1488
|
const viewer = (0, import_react.useSyncExternalStore)(
|
|
@@ -1543,3 +1737,123 @@ function InvoiceDate({ row, t }) {
|
|
|
1543
1737
|
}
|
|
1544
1738
|
);
|
|
1545
1739
|
}
|
|
1740
|
+
Invoices.resources = ["invoices"];
|
|
1741
|
+
|
|
1742
|
+
// src/elements/UpcomingBill.tsx
|
|
1743
|
+
var import_schematic_react3 = require("@schematichq/schematic-react");
|
|
1744
|
+
var import_react3 = require("react");
|
|
1745
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1746
|
+
function UpcomingBill({
|
|
1747
|
+
className,
|
|
1748
|
+
headingLevel = 2,
|
|
1749
|
+
locale: localeProp,
|
|
1750
|
+
showAmount = true,
|
|
1751
|
+
showBalance = true,
|
|
1752
|
+
showDiscounts = true,
|
|
1753
|
+
showHeader = true,
|
|
1754
|
+
strings
|
|
1755
|
+
}) {
|
|
1756
|
+
const { data: invoice, error, isPending, refetch } = (0, import_schematic_react3.useUpcomingInvoice)();
|
|
1757
|
+
const locale = useResolvedLocale(localeProp);
|
|
1758
|
+
const t = useTranslator(strings, localeProp);
|
|
1759
|
+
const bill = (0, import_react3.useMemo)(
|
|
1760
|
+
() => invoice === void 0 || invoice === null ? null : deriveUpcomingInvoice(invoice, { locale }),
|
|
1761
|
+
[invoice, locale]
|
|
1762
|
+
);
|
|
1763
|
+
const Heading = `h${headingLevel}`;
|
|
1764
|
+
const balanceRows = showBalance && bill !== null && (bill.balanceApplied !== null || bill.balanceRemaining !== null);
|
|
1765
|
+
const discountRow = showDiscounts && bill !== null && bill.discounts.length > 0;
|
|
1766
|
+
const unavailable = invoice === void 0 && httpStatus(error) === 404;
|
|
1767
|
+
const errorMessage = error === void 0 ? void 0 : unavailable ? t("upcomingBillUnavailable") : t("upcomingBillError");
|
|
1768
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1769
|
+
StatusFrame,
|
|
1770
|
+
{
|
|
1771
|
+
className: cx("schematic-card", "schematic-upcoming-bill", className),
|
|
1772
|
+
error,
|
|
1773
|
+
errorMessage,
|
|
1774
|
+
hasData: invoice !== void 0,
|
|
1775
|
+
isPending,
|
|
1776
|
+
loadingLabel: t("upcomingBillLoading"),
|
|
1777
|
+
onRetry: refetch,
|
|
1778
|
+
retryText: t("retry"),
|
|
1779
|
+
skeleton: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(UpcomingBillSkeleton, { showHeader }),
|
|
1780
|
+
children: bill === null ? invoice !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: "schematic-muted schematic-upcoming-bill__empty", children: t("upcomingBillEmpty") }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
|
|
1781
|
+
showHeader && bill.dueAt !== null && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "schematic-header", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Heading, { className: "schematic-header__title", children: t("upcomingBillHeader", { date: bill.dueAt.text }) }) }),
|
|
1782
|
+
showAmount && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "schematic-upcoming-bill__amount", children: [
|
|
1783
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1784
|
+
"span",
|
|
1785
|
+
{
|
|
1786
|
+
className: "schematic-upcoming-bill__total",
|
|
1787
|
+
"data-testid": "schematic-upcoming-total",
|
|
1788
|
+
children: bill.amountDueText
|
|
1789
|
+
}
|
|
1790
|
+
),
|
|
1791
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "schematic-small schematic-upcoming-bill__estimate", children: t("upcomingBillEstimate") })
|
|
1792
|
+
] }),
|
|
1793
|
+
(balanceRows || discountRow) && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "schematic-upcoming-bill__rows", children: [
|
|
1794
|
+
balanceRows && bill.balanceApplied !== null && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
1795
|
+
"div",
|
|
1796
|
+
{
|
|
1797
|
+
className: "schematic-row schematic-upcoming-bill__balance-applied",
|
|
1798
|
+
"data-testid": "schematic-balance-applied",
|
|
1799
|
+
children: [
|
|
1800
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "schematic-row__label", children: t("upcomingBillBalanceApplied") }),
|
|
1801
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "schematic-row__value", children: bill.balanceApplied.amountText })
|
|
1802
|
+
]
|
|
1803
|
+
}
|
|
1804
|
+
),
|
|
1805
|
+
balanceRows && bill.balanceRemaining !== null && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
1806
|
+
"div",
|
|
1807
|
+
{
|
|
1808
|
+
className: "schematic-row schematic-upcoming-bill__balance-remaining",
|
|
1809
|
+
"data-testid": "schematic-balance-remaining",
|
|
1810
|
+
children: [
|
|
1811
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "schematic-row__label", children: t("upcomingBillBalanceRemaining") }),
|
|
1812
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "schematic-row__value", children: bill.balanceRemaining.amountText })
|
|
1813
|
+
]
|
|
1814
|
+
}
|
|
1815
|
+
),
|
|
1816
|
+
discountRow && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
1817
|
+
"div",
|
|
1818
|
+
{
|
|
1819
|
+
className: "schematic-row schematic-upcoming-bill__discount-row",
|
|
1820
|
+
"data-testid": "schematic-discounts",
|
|
1821
|
+
children: [
|
|
1822
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "schematic-row__label", children: t("upcomingBillDiscount") }),
|
|
1823
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("ul", { className: "schematic-row__value schematic-upcoming-bill__discounts", children: bill.discounts.map((discount, index) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
1824
|
+
"li",
|
|
1825
|
+
{
|
|
1826
|
+
className: "schematic-upcoming-bill__discount",
|
|
1827
|
+
"data-testid": "schematic-discount",
|
|
1828
|
+
children: [
|
|
1829
|
+
discount.code !== null && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "schematic-chip schematic-upcoming-bill__code", children: discount.code }),
|
|
1830
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "schematic-upcoming-bill__discount-value", children: discountText(discount, t) })
|
|
1831
|
+
]
|
|
1832
|
+
},
|
|
1833
|
+
`${discount.couponName}-${index}`
|
|
1834
|
+
)) })
|
|
1835
|
+
]
|
|
1836
|
+
}
|
|
1837
|
+
)
|
|
1838
|
+
] })
|
|
1839
|
+
] })
|
|
1840
|
+
}
|
|
1841
|
+
);
|
|
1842
|
+
}
|
|
1843
|
+
function UpcomingBillSkeleton({ showHeader }) {
|
|
1844
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "schematic-skeleton", children: [
|
|
1845
|
+
showHeader && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "schematic-skeleton__heading" }),
|
|
1846
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "amount" }) }),
|
|
1847
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "row" }) })
|
|
1848
|
+
] });
|
|
1849
|
+
}
|
|
1850
|
+
function discountText(discount, t) {
|
|
1851
|
+
if (discount.months === null) {
|
|
1852
|
+
return t("upcomingBillDiscountValue", { value: discount.valueText });
|
|
1853
|
+
}
|
|
1854
|
+
return t("upcomingBillDiscountRepeating", {
|
|
1855
|
+
count: discount.months,
|
|
1856
|
+
value: discount.valueText
|
|
1857
|
+
});
|
|
1858
|
+
}
|
|
1859
|
+
UpcomingBill.resources = ["upcomingInvoice"];
|
|
@@ -2,6 +2,8 @@ import { BillingData } from '@schematichq/schematic-react';
|
|
|
2
2
|
import { BillingDataProvider } from '@schematichq/schematic-react';
|
|
3
3
|
import { BillingDataProviderProps } from '@schematichq/schematic-react';
|
|
4
4
|
import { BillingDataStatus } from '@schematichq/schematic-react';
|
|
5
|
+
import { BillingResourceName } from '@schematichq/schematic-react';
|
|
6
|
+
import { Discount } from '@schematichq/schematic-react';
|
|
5
7
|
import { Invoice } from '@schematichq/schematic-react';
|
|
6
8
|
import { InvoicePage } from '@schematichq/schematic-react';
|
|
7
9
|
import { InvoiceQuery } from '@schematichq/schematic-react';
|
|
@@ -14,12 +16,14 @@ import { SchematicI18nConfig } from '@schematichq/schematic-react';
|
|
|
14
16
|
import { SchematicI18nProvider } from '@schematichq/schematic-react';
|
|
15
17
|
import { SchematicI18nProviderProps } from '@schematichq/schematic-react';
|
|
16
18
|
import type { Translate } from '@schematichq/schematic-react';
|
|
19
|
+
import { UpcomingInvoice } from '@schematichq/schematic-react';
|
|
17
20
|
import { useInvalidateBillingData } from '@schematichq/schematic-react';
|
|
18
21
|
import { useInvoices } from '@schematichq/schematic-react';
|
|
19
22
|
import { useSchematicI18n } from '@schematichq/schematic-react';
|
|
20
23
|
import { useSchematicLocale } from '@schematichq/schematic-react';
|
|
21
24
|
import { useSchematicStrings } from '@schematichq/schematic-react';
|
|
22
25
|
import { useSchematicTranslate } from '@schematichq/schematic-react';
|
|
26
|
+
import { useUpcomingInvoice } from '@schematichq/schematic-react';
|
|
23
27
|
|
|
24
28
|
export { BillingData }
|
|
25
29
|
|
|
@@ -29,6 +33,22 @@ export { BillingDataProviderProps }
|
|
|
29
33
|
|
|
30
34
|
export { BillingDataStatus }
|
|
31
35
|
|
|
36
|
+
/**
|
|
37
|
+
* The resource names to prefetch for the elements a page renders, each once:
|
|
38
|
+
*
|
|
39
|
+
* ```ts
|
|
40
|
+
* fetchBillingData(client, { names: billingResources(UpcomingBill, Invoices) });
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare function billingResources(...elements: ReadsBillingResources[]): BillingResourceName[];
|
|
44
|
+
|
|
45
|
+
/** An amount on the bill, with the text for it. */
|
|
46
|
+
export declare interface BillLine {
|
|
47
|
+
/** Minor units, signed as it affects the bill. */
|
|
48
|
+
amountMinor: number;
|
|
49
|
+
amountText: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
32
52
|
/**
|
|
33
53
|
* The English copy, and the fallback for anything a host does not answer.
|
|
34
54
|
* It is a plain resource bundle, so it can be registered as one:
|
|
@@ -52,6 +72,44 @@ export declare interface DeriveInvoiceListOptions {
|
|
|
52
72
|
format?: InvoiceFormatters;
|
|
53
73
|
}
|
|
54
74
|
|
|
75
|
+
export declare function deriveUpcomingInvoice(invoice: UpcomingInvoice, options: DeriveUpcomingInvoiceOptions): UpcomingBillSummary;
|
|
76
|
+
|
|
77
|
+
export declare interface DeriveUpcomingInvoiceOptions {
|
|
78
|
+
locale: string;
|
|
79
|
+
format?: UpcomingInvoiceFormatters;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export { Discount }
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* `deriveUpcomingInvoice`: the company's next bill as display parts — the
|
|
86
|
+
* estimated amount, the balance it consumes, and the discounts shaping it.
|
|
87
|
+
*
|
|
88
|
+
* The arithmetic is not here. The server sends what the balance applies and
|
|
89
|
+
* what survives, because those depend on provider conventions (a negative
|
|
90
|
+
* balance is held credit; a previewed invoice reports no ending balance)
|
|
91
|
+
* that no consumer should have to know.
|
|
92
|
+
*/
|
|
93
|
+
/** One discount on the subscription, as the bill shows it. */
|
|
94
|
+
export declare interface DiscountLine {
|
|
95
|
+
/** The coupon's name, for a host that wants to show it. */
|
|
96
|
+
couponName: string;
|
|
97
|
+
/** The promo code, for the chip beside the amount; `null` when none. */
|
|
98
|
+
code: string | null;
|
|
99
|
+
/** Whether the discount takes a percentage off or a fixed amount. */
|
|
100
|
+
kind: "percent" | "amount";
|
|
101
|
+
/** "20%" or "$5.00" — what comes off. */
|
|
102
|
+
valueText: string;
|
|
103
|
+
/** The percentage as written (20 for 20% off); `null` for an amount. */
|
|
104
|
+
percentOff: number | null;
|
|
105
|
+
/** Minor units off; `null` for a percentage. */
|
|
106
|
+
amountOffMinor: number | null;
|
|
107
|
+
/** Months the discount repeats for; `null` when it does not repeat. */
|
|
108
|
+
months: number | null;
|
|
109
|
+
/** Provider vocabulary: `once`, `repeating`, or `forever`. */
|
|
110
|
+
duration: string;
|
|
111
|
+
}
|
|
112
|
+
|
|
55
113
|
/** Props every element accepts on its root. */
|
|
56
114
|
export declare interface ElementProps {
|
|
57
115
|
className?: string;
|
|
@@ -82,6 +140,17 @@ export declare type ElementStrings = {
|
|
|
82
140
|
invoicesChargeTooltip: string;
|
|
83
141
|
invoicesCreditTooltip: string;
|
|
84
142
|
invoicesUndated: string;
|
|
143
|
+
upcomingBillLoading: string;
|
|
144
|
+
upcomingBillHeader: string;
|
|
145
|
+
upcomingBillError: string;
|
|
146
|
+
upcomingBillUnavailable: string;
|
|
147
|
+
upcomingBillEmpty: string;
|
|
148
|
+
upcomingBillEstimate: string;
|
|
149
|
+
upcomingBillBalanceApplied: string;
|
|
150
|
+
upcomingBillBalanceRemaining: string;
|
|
151
|
+
upcomingBillDiscount: string;
|
|
152
|
+
upcomingBillDiscountValue: string;
|
|
153
|
+
upcomingBillDiscountRepeating: string;
|
|
85
154
|
};
|
|
86
155
|
|
|
87
156
|
/**
|
|
@@ -122,6 +191,18 @@ export declare function formatDate(date: Date, locale: string, options?: Intl.Da
|
|
|
122
191
|
|
|
123
192
|
export declare function formatNumber(value: number, locale: string, options?: Intl.NumberFormatOptions): string;
|
|
124
193
|
|
|
194
|
+
/**
|
|
195
|
+
* A malformed timestamp decodes to an Invalid Date, and `Intl` throws a
|
|
196
|
+
* RangeError on formatting one. Thrown inside a render, that takes down the
|
|
197
|
+
* host's tree.
|
|
198
|
+
*/
|
|
199
|
+
/**
|
|
200
|
+
* "50%", or "12.5%" for a coupon written with a fraction. Two places is
|
|
201
|
+
* what a provider allows a percentage, and Intl drops trailing zeros, so
|
|
202
|
+
* a whole number stays whole.
|
|
203
|
+
*/
|
|
204
|
+
export declare function formatPercent(fraction: number, locale: string): string;
|
|
205
|
+
|
|
125
206
|
/** "8/21". Empty for an Invalid Date. */
|
|
126
207
|
export declare function formatShortDate(date: Date, locale: string): string;
|
|
127
208
|
|
|
@@ -191,6 +272,10 @@ export declare interface InvoiceRow {
|
|
|
191
272
|
*/
|
|
192
273
|
export declare function Invoices({ className, collapsible, headingLevel, limit, locale: localeProp, query, showAmount, showDate, showHeader, strings, }: InvoicesProps): JSX.Element;
|
|
193
274
|
|
|
275
|
+
export declare namespace Invoices {
|
|
276
|
+
var resources: readonly ["invoices"];
|
|
277
|
+
}
|
|
278
|
+
|
|
194
279
|
export declare interface InvoicesProps extends ElementProps {
|
|
195
280
|
/** Rows shown before "See more". Default 10. */
|
|
196
281
|
limit?: number;
|
|
@@ -231,6 +316,16 @@ export declare function plural(locale: string, count: number, forms: Partial<Rec
|
|
|
231
316
|
/** The i18next plural suffixes a key can carry. */
|
|
232
317
|
declare type PluralSuffix = "zero" | "one" | "two" | "few" | "many" | "other";
|
|
233
318
|
|
|
319
|
+
/**
|
|
320
|
+
* What an element reads from the billing store, declared on the element so
|
|
321
|
+
* a page can prefetch exactly that. `fetchBillingData` has no default set:
|
|
322
|
+
* each resource is a request on the server, and the set grows with every
|
|
323
|
+
* element, so the page names what it renders.
|
|
324
|
+
*/
|
|
325
|
+
export declare interface ReadsBillingResources {
|
|
326
|
+
readonly resources: readonly BillingResourceName[];
|
|
327
|
+
}
|
|
328
|
+
|
|
234
329
|
/**
|
|
235
330
|
* The given tag, or the default when it is absent or `Intl` rejects it.
|
|
236
331
|
* Deliberately ignores `navigator`; `viewerLocale` does that reading.
|
|
@@ -291,6 +386,78 @@ export { Translate }
|
|
|
291
386
|
|
|
292
387
|
export declare type Translator = (key: StringKey, vars?: StringVars) => string;
|
|
293
388
|
|
|
389
|
+
/**
|
|
390
|
+
* The company's next bill: what it will be charged and when, and the
|
|
391
|
+
* account balance and discounts that shaped the figure.
|
|
392
|
+
*
|
|
393
|
+
* A company with nothing to bill — no subscription — gets the empty state
|
|
394
|
+
* rather than a fabricated zero. That is a loaded answer from the server (a
|
|
395
|
+
* 204), not a missing one, so it renders as content rather than as a
|
|
396
|
+
* permanent skeleton. A 404 is something else: the account is not enabled
|
|
397
|
+
* for company reads, and the card says so rather than showing a customer
|
|
398
|
+
* with a subscription "no upcoming invoice".
|
|
399
|
+
*/
|
|
400
|
+
export declare function UpcomingBill({ className, headingLevel, locale: localeProp, showAmount, showBalance, showDiscounts, showHeader, strings, }: UpcomingBillProps): JSX.Element;
|
|
401
|
+
|
|
402
|
+
export declare namespace UpcomingBill {
|
|
403
|
+
var resources: readonly ["upcomingInvoice"];
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
export declare interface UpcomingBillProps extends ElementProps {
|
|
407
|
+
/** The "Next bill due …" heading. Default true. */
|
|
408
|
+
showHeader?: boolean;
|
|
409
|
+
/** Heading level, so the card fits the host's outline. Default 2. */
|
|
410
|
+
headingLevel?: HeadingLevel;
|
|
411
|
+
/** The estimated amount. Default true. */
|
|
412
|
+
showAmount?: boolean;
|
|
413
|
+
/** The applied and remaining account-balance rows. Default true. */
|
|
414
|
+
showBalance?: boolean;
|
|
415
|
+
/** The discount row. Default true. */
|
|
416
|
+
showDiscounts?: boolean;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
export declare interface UpcomingBillSummary {
|
|
420
|
+
/** What the company will be charged, after discounts and balance. */
|
|
421
|
+
amountDueMinor: number;
|
|
422
|
+
amountDueText: string;
|
|
423
|
+
/** Before discounts and tax. */
|
|
424
|
+
subtotalMinor: number;
|
|
425
|
+
subtotalText: string;
|
|
426
|
+
/** ISO 4217 code, upper-cased. */
|
|
427
|
+
currency: string;
|
|
428
|
+
/** When it will be charged; `null` when the provider names no date. */
|
|
429
|
+
dueAt: {
|
|
430
|
+
date: Date;
|
|
431
|
+
text: string;
|
|
432
|
+
} | null;
|
|
433
|
+
/**
|
|
434
|
+
* The stored balance this invoice consumes, as a deduction — the amount is
|
|
435
|
+
* negative and its text carries the locale's sign. `null` when none of the
|
|
436
|
+
* balance is applied.
|
|
437
|
+
*/
|
|
438
|
+
balanceApplied: BillLine | null;
|
|
439
|
+
/**
|
|
440
|
+
* What is left of the balance afterwards, as a positive amount. `null`
|
|
441
|
+
* when there was no balance to begin with — a company that has one, and
|
|
442
|
+
* spends all of it, still gets a zero here to say so.
|
|
443
|
+
*/
|
|
444
|
+
balanceRemaining: BillLine | null;
|
|
445
|
+
/** Active discounts, already filtered server-side to the ones that bite. */
|
|
446
|
+
discounts: DiscountLine[];
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
export { UpcomingInvoice }
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* Per-field formatting, for a host that wants the derivation's parts but not
|
|
453
|
+
* its wording. Each receives the raw value and the resolved locale; amounts
|
|
454
|
+
* arrive signed.
|
|
455
|
+
*/
|
|
456
|
+
export declare interface UpcomingInvoiceFormatters {
|
|
457
|
+
date?: (date: Date, locale: string) => string;
|
|
458
|
+
amount?: (amountMinor: number, currency: string, locale: string) => string;
|
|
459
|
+
}
|
|
460
|
+
|
|
294
461
|
export { useInvalidateBillingData }
|
|
295
462
|
|
|
296
463
|
export { useInvoices }
|
|
@@ -324,6 +491,8 @@ export { useSchematicTranslate }
|
|
|
324
491
|
*/
|
|
325
492
|
export declare function useTranslator(overrides?: StringOverrides, locale?: string): Translator;
|
|
326
493
|
|
|
494
|
+
export { useUpcomingInvoice }
|
|
495
|
+
|
|
327
496
|
/** Not for a server render or its hydration; `useResolvedLocale` reads it
|
|
328
497
|
* through `useSyncExternalStore`, which keeps it out of both. */
|
|
329
498
|
export declare function viewerLocale(): string | undefined;
|