@schematichq/schematic-components 2.32.0 → 2.33.0
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 +838 -258
- package/dist/schematic-components-elements.d.ts +174 -10
- package/dist/schematic-components-elements.esm.js +805 -220
- package/dist/schematic-components.browser.cjs.js +247 -32
- package/dist/schematic-components.browser.esm.js +247 -32
- package/dist/schematic-components.cjs.js +247 -32
- package/dist/schematic-components.d.ts +127 -0
- package/dist/schematic-components.esm.js +247 -32
- package/package.json +6 -6
|
@@ -75,6 +75,9 @@ var init_tokens = __esm({
|
|
|
75
75
|
"--schematic-font-heading": '"Manrope", system-ui, sans-serif',
|
|
76
76
|
// Link buttons' face: Edit, Set default, Try again, and the rest.
|
|
77
77
|
"--schematic-font-link": '"Inter", system-ui, sans-serif',
|
|
78
|
+
// A lighter tint than the surface, for panels set into a card: a credit's
|
|
79
|
+
// grants, a plan's auto top-up.
|
|
80
|
+
"--schematic-inset": ld("hsla(0, 0%, 0%, 0.04)", "hsla(0, 0%, 100%, 0.06)"),
|
|
78
81
|
"--schematic-line-height": "1.375",
|
|
79
82
|
"--schematic-line-height-heading": "1.2",
|
|
80
83
|
"--schematic-meter-track": ld("#f2f4f7", "#26282d"),
|
|
@@ -159,10 +162,10 @@ function PaymentMethodForm({
|
|
|
159
162
|
onSelectExisting,
|
|
160
163
|
t
|
|
161
164
|
}) {
|
|
162
|
-
const { create } = (0,
|
|
163
|
-
const [state, setState] = (0,
|
|
164
|
-
const hostRef = (0,
|
|
165
|
-
(0,
|
|
165
|
+
const { create } = (0, import_schematic_react6.useSetupIntent)();
|
|
166
|
+
const [state, setState] = (0, import_react7.useState)({ status: "loading" });
|
|
167
|
+
const hostRef = (0, import_react7.useRef)(null);
|
|
168
|
+
(0, import_react7.useEffect)(() => {
|
|
166
169
|
let cancelled = false;
|
|
167
170
|
let setupFailed = false;
|
|
168
171
|
Promise.all([
|
|
@@ -208,7 +211,7 @@ function PaymentMethodForm({
|
|
|
208
211
|
};
|
|
209
212
|
}, [create, locale]);
|
|
210
213
|
if (state.status === "loading") {
|
|
211
|
-
return /* @__PURE__ */ (0,
|
|
214
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
|
|
212
215
|
"div",
|
|
213
216
|
{
|
|
214
217
|
"aria-busy": "true",
|
|
@@ -216,15 +219,15 @@ function PaymentMethodForm({
|
|
|
216
219
|
"data-state": "pending",
|
|
217
220
|
ref: hostRef,
|
|
218
221
|
children: [
|
|
219
|
-
/* @__PURE__ */ (0,
|
|
220
|
-
/* @__PURE__ */ (0,
|
|
222
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "schematic-hidden", children: t("paymentMethodsFormLoading") }),
|
|
223
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "schematic-skeleton", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "field" }) }) })
|
|
221
224
|
]
|
|
222
225
|
}
|
|
223
226
|
);
|
|
224
227
|
}
|
|
225
228
|
if (state.status === "failed") {
|
|
226
|
-
return /* @__PURE__ */ (0,
|
|
227
|
-
/* @__PURE__ */ (0,
|
|
229
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "schematic-payment-methods__form", "data-state": "error", children: [
|
|
230
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
228
231
|
"p",
|
|
229
232
|
{
|
|
230
233
|
className: "schematic-error schematic-small schematic-payment-methods__form-error",
|
|
@@ -232,11 +235,11 @@ function PaymentMethodForm({
|
|
|
232
235
|
children: t(state.errorKey)
|
|
233
236
|
}
|
|
234
237
|
),
|
|
235
|
-
onSelectExisting !== void 0 && /* @__PURE__ */ (0,
|
|
238
|
+
onSelectExisting !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(SelectExisting, { t, onSelectExisting })
|
|
236
239
|
] });
|
|
237
240
|
}
|
|
238
241
|
const { Elements } = state.ui;
|
|
239
|
-
return /* @__PURE__ */ (0,
|
|
242
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
240
243
|
Elements,
|
|
241
244
|
{
|
|
242
245
|
stripe: state.stripe,
|
|
@@ -244,7 +247,7 @@ function PaymentMethodForm({
|
|
|
244
247
|
appearance: state.appearance,
|
|
245
248
|
clientSecret: state.clientSecret
|
|
246
249
|
},
|
|
247
|
-
children: /* @__PURE__ */ (0,
|
|
250
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
248
251
|
Fields,
|
|
249
252
|
{
|
|
250
253
|
checkoutPrefill,
|
|
@@ -273,19 +276,19 @@ function Fields({
|
|
|
273
276
|
const showAddress = collectAddress || collectPhone;
|
|
274
277
|
const prefill = checkoutPrefill?.billingDetails;
|
|
275
278
|
const prefillName = orUndefined(prefill?.name);
|
|
276
|
-
const emailId = (0,
|
|
279
|
+
const emailId = (0, import_react7.useId)();
|
|
277
280
|
const stripe = useStripe();
|
|
278
281
|
const elements = useElements();
|
|
279
|
-
const [saving, setSaving] = (0,
|
|
280
|
-
const [message, setMessage] = (0,
|
|
281
|
-
const [complete, setComplete] = (0,
|
|
282
|
-
const [ready, setReady] = (0,
|
|
283
|
-
const [loadFailed, setLoadFailed] = (0,
|
|
284
|
-
const [addressComplete, setAddressComplete] = (0,
|
|
285
|
-
const [typedEmail, setTypedEmail] = (0,
|
|
282
|
+
const [saving, setSaving] = (0, import_react7.useState)(false);
|
|
283
|
+
const [message, setMessage] = (0, import_react7.useState)(null);
|
|
284
|
+
const [complete, setComplete] = (0, import_react7.useState)(false);
|
|
285
|
+
const [ready, setReady] = (0, import_react7.useState)(false);
|
|
286
|
+
const [loadFailed, setLoadFailed] = (0, import_react7.useState)(false);
|
|
287
|
+
const [addressComplete, setAddressComplete] = (0, import_react7.useState)(!collectAddress);
|
|
288
|
+
const [typedEmail, setTypedEmail] = (0, import_react7.useState)(null);
|
|
286
289
|
const email = typedEmail ?? orUndefined(prefill?.email) ?? "";
|
|
287
290
|
const emailValid = !collectEmail || VALID_EMAIL.test(email);
|
|
288
|
-
(0,
|
|
291
|
+
(0, import_react7.useEffect)(() => {
|
|
289
292
|
if (ready) {
|
|
290
293
|
return;
|
|
291
294
|
}
|
|
@@ -337,14 +340,14 @@ function Fields({
|
|
|
337
340
|
setSaving(false);
|
|
338
341
|
}
|
|
339
342
|
};
|
|
340
|
-
return /* @__PURE__ */ (0,
|
|
343
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
|
|
341
344
|
"form",
|
|
342
345
|
{
|
|
343
346
|
className: "schematic-payment-methods__form",
|
|
344
347
|
"data-state": "ready",
|
|
345
348
|
onSubmit: (event) => void submit(event),
|
|
346
349
|
children: [
|
|
347
|
-
/* @__PURE__ */ (0,
|
|
350
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "schematic-payment-methods__fields", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
348
351
|
PaymentElement,
|
|
349
352
|
{
|
|
350
353
|
onChange: (event) => setComplete(event.complete),
|
|
@@ -355,8 +358,8 @@ function Fields({
|
|
|
355
358
|
}
|
|
356
359
|
}
|
|
357
360
|
) }),
|
|
358
|
-
collectEmail && /* @__PURE__ */ (0,
|
|
359
|
-
/* @__PURE__ */ (0,
|
|
361
|
+
collectEmail && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "schematic-payment-methods__field", children: [
|
|
362
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
360
363
|
"label",
|
|
361
364
|
{
|
|
362
365
|
className: "schematic-payment-methods__field-label",
|
|
@@ -364,7 +367,7 @@ function Fields({
|
|
|
364
367
|
children: t("paymentMethodsEmail")
|
|
365
368
|
}
|
|
366
369
|
),
|
|
367
|
-
/* @__PURE__ */ (0,
|
|
370
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
368
371
|
"input",
|
|
369
372
|
{
|
|
370
373
|
autoComplete: "email",
|
|
@@ -378,7 +381,7 @@ function Fields({
|
|
|
378
381
|
}
|
|
379
382
|
)
|
|
380
383
|
] }),
|
|
381
|
-
showAddress && /* @__PURE__ */ (0,
|
|
384
|
+
showAddress && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "schematic-payment-methods__address", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
382
385
|
AddressElement,
|
|
383
386
|
{
|
|
384
387
|
options: {
|
|
@@ -392,7 +395,7 @@ function Fields({
|
|
|
392
395
|
},
|
|
393
396
|
prefillName ?? ""
|
|
394
397
|
) }),
|
|
395
|
-
loadFailed && /* @__PURE__ */ (0,
|
|
398
|
+
loadFailed && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
396
399
|
"p",
|
|
397
400
|
{
|
|
398
401
|
className: "schematic-error schematic-small schematic-payment-methods__form-error",
|
|
@@ -400,7 +403,7 @@ function Fields({
|
|
|
400
403
|
children: t("paymentMethodsFormError")
|
|
401
404
|
}
|
|
402
405
|
),
|
|
403
|
-
message !== null && /* @__PURE__ */ (0,
|
|
406
|
+
message !== null && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
404
407
|
"p",
|
|
405
408
|
{
|
|
406
409
|
className: "schematic-error schematic-small schematic-payment-methods__form-error",
|
|
@@ -408,7 +411,7 @@ function Fields({
|
|
|
408
411
|
children: message
|
|
409
412
|
}
|
|
410
413
|
),
|
|
411
|
-
/* @__PURE__ */ (0,
|
|
414
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
412
415
|
"button",
|
|
413
416
|
{
|
|
414
417
|
className: "schematic-cta schematic-payment-methods__save",
|
|
@@ -417,7 +420,7 @@ function Fields({
|
|
|
417
420
|
children: saving ? t("paymentMethodsSaving") : t("paymentMethodsSave")
|
|
418
421
|
}
|
|
419
422
|
),
|
|
420
|
-
onSelectExisting !== void 0 && /* @__PURE__ */ (0,
|
|
423
|
+
onSelectExisting !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
421
424
|
SelectExisting,
|
|
422
425
|
{
|
|
423
426
|
disabled: saving,
|
|
@@ -434,7 +437,7 @@ function SelectExisting({
|
|
|
434
437
|
onSelectExisting,
|
|
435
438
|
t
|
|
436
439
|
}) {
|
|
437
|
-
return /* @__PURE__ */ (0,
|
|
440
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
438
441
|
"button",
|
|
439
442
|
{
|
|
440
443
|
className: "schematic-link-button schematic-payment-methods__select-existing",
|
|
@@ -445,14 +448,14 @@ function SelectExisting({
|
|
|
445
448
|
}
|
|
446
449
|
);
|
|
447
450
|
}
|
|
448
|
-
var
|
|
451
|
+
var import_schematic_react6, import_react7, import_jsx_runtime8, NO_CLIENT_SECRET, STRIPE_NOT_LOADED, PROBE_CSS, READY_TIMEOUT_MS, VALID_EMAIL, PaymentMethodForm_default;
|
|
449
452
|
var init_PaymentMethodForm = __esm({
|
|
450
453
|
"src/elements/PaymentMethodForm.tsx"() {
|
|
451
454
|
"use strict";
|
|
452
|
-
|
|
453
|
-
|
|
455
|
+
import_schematic_react6 = require("@schematichq/schematic-react");
|
|
456
|
+
import_react7 = require("react");
|
|
454
457
|
init_tokens();
|
|
455
|
-
|
|
458
|
+
import_jsx_runtime8 = require("react/jsx-runtime");
|
|
456
459
|
NO_CLIENT_SECRET = "The setup intent carries no client secret.";
|
|
457
460
|
STRIPE_NOT_LOADED = "Stripe.js did not load.";
|
|
458
461
|
PROBE_CSS = withTokenDefaults(
|
|
@@ -476,20 +479,22 @@ var init_PaymentMethodForm = __esm({
|
|
|
476
479
|
// src/elements/index.ts
|
|
477
480
|
var index_exports = {};
|
|
478
481
|
__export(index_exports, {
|
|
479
|
-
BillingDataProvider: () =>
|
|
482
|
+
BillingDataProvider: () => import_schematic_react9.BillingDataProvider,
|
|
483
|
+
CreditUsage: () => CreditUsage,
|
|
480
484
|
DEFAULT_STRINGS: () => DEFAULT_STRINGS,
|
|
481
|
-
FEATURE_USER_USAGE_LIMIT: () =>
|
|
485
|
+
FEATURE_USER_USAGE_LIMIT: () => import_schematic_react9.FEATURE_USER_USAGE_LIMIT,
|
|
482
486
|
IncludedFeatures: () => IncludedFeatures,
|
|
483
487
|
Invoices: () => Invoices,
|
|
484
488
|
MeteredFeatures: () => MeteredFeatures,
|
|
485
489
|
PaymentMethods: () => PaymentMethods,
|
|
486
490
|
SCHEMATIC_TOKENS: () => SCHEMATIC_TOKENS,
|
|
487
|
-
SchematicI18nProvider: () =>
|
|
491
|
+
SchematicI18nProvider: () => import_schematic_react9.SchematicI18nProvider,
|
|
488
492
|
SchematicStyles: () => SchematicStyles,
|
|
489
493
|
Tooltip: () => Tooltip,
|
|
490
494
|
UpcomingBill: () => UpcomingBill,
|
|
491
495
|
billingResources: () => billingResources,
|
|
492
496
|
currentTier: () => currentTier,
|
|
497
|
+
deriveCreditUsage: () => deriveCreditUsage,
|
|
493
498
|
deriveIncludedFeatures: () => deriveIncludedFeatures,
|
|
494
499
|
deriveInvoiceList: () => deriveInvoiceList,
|
|
495
500
|
deriveMeteredFeatures: () => deriveMeteredFeatures,
|
|
@@ -516,23 +521,25 @@ __export(index_exports, {
|
|
|
516
521
|
tierRanges: () => tierRanges,
|
|
517
522
|
unitPrice: () => unitPrice,
|
|
518
523
|
usageLimit: () => usageLimit,
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
+
useCreditBalances: () => import_schematic_react9.useCreditBalances,
|
|
525
|
+
useCreditUserUsage: () => import_schematic_react9.useCreditUserUsage,
|
|
526
|
+
useFeatureUsage: () => import_schematic_react9.useFeatureUsage,
|
|
527
|
+
useFeatureUserUsage: () => import_schematic_react9.useFeatureUserUsage,
|
|
528
|
+
useInvalidateBillingData: () => import_schematic_react9.useInvalidateBillingData,
|
|
529
|
+
useInvoices: () => import_schematic_react9.useInvoices,
|
|
530
|
+
usePaymentMethods: () => import_schematic_react9.usePaymentMethods,
|
|
524
531
|
useResolvedLocale: () => useResolvedLocale,
|
|
525
|
-
useSchematicI18n: () =>
|
|
526
|
-
useSchematicLocale: () =>
|
|
527
|
-
useSchematicStrings: () =>
|
|
528
|
-
useSchematicTranslate: () =>
|
|
529
|
-
useSetupIntent: () =>
|
|
532
|
+
useSchematicI18n: () => import_schematic_react9.useSchematicI18n,
|
|
533
|
+
useSchematicLocale: () => import_schematic_react9.useSchematicLocale,
|
|
534
|
+
useSchematicStrings: () => import_schematic_react9.useSchematicStrings,
|
|
535
|
+
useSchematicTranslate: () => import_schematic_react9.useSchematicTranslate,
|
|
536
|
+
useSetupIntent: () => import_schematic_react9.useSetupIntent,
|
|
530
537
|
useTranslator: () => useTranslator,
|
|
531
|
-
useUpcomingInvoice: () =>
|
|
538
|
+
useUpcomingInvoice: () => import_schematic_react9.useUpcomingInvoice,
|
|
532
539
|
viewerLocale: () => viewerLocale
|
|
533
540
|
});
|
|
534
541
|
module.exports = __toCommonJS(index_exports);
|
|
535
|
-
var
|
|
542
|
+
var import_schematic_react9 = require("@schematichq/schematic-react");
|
|
536
543
|
|
|
537
544
|
// src/elements/model/errors.ts
|
|
538
545
|
function httpStatus(error) {
|
|
@@ -987,6 +994,9 @@ function formatCurrency(amountMinor, currency, locale, options = {}) {
|
|
|
987
994
|
function formatNumber(value, locale, options) {
|
|
988
995
|
return new Intl.NumberFormat(usableLocale(locale), options).format(value);
|
|
989
996
|
}
|
|
997
|
+
function formatCredits(value, locale) {
|
|
998
|
+
return formatNumber(value, locale, { maximumFractionDigits: 10 });
|
|
999
|
+
}
|
|
990
1000
|
function formatConsumptionRate(rate, locale) {
|
|
991
1001
|
return formatNumber(rate, locale, {
|
|
992
1002
|
maximumFractionDigits: MAXIMUM_FRACTION_DIGITS
|
|
@@ -1383,7 +1393,10 @@ function includedFeatureRow(row, options) {
|
|
|
1383
1393
|
description: nonEmpty(row.featureDescription),
|
|
1384
1394
|
icon: nonEmpty(row.featureIcon),
|
|
1385
1395
|
perLicenseCredits: row.perLicenseCreditGrants.filter((grant) => grant.scaling === "per_license").map((grant) => ({
|
|
1386
|
-
|
|
1396
|
+
// Credits come in fractions as small as 1e-10.
|
|
1397
|
+
amount: formatNumber(grant.creditAmount, locale, {
|
|
1398
|
+
maximumFractionDigits: 10
|
|
1399
|
+
}),
|
|
1387
1400
|
creditName: featureName(
|
|
1388
1401
|
{
|
|
1389
1402
|
name: grant.creditName,
|
|
@@ -1403,7 +1416,7 @@ function includedFeatureRow(row, options) {
|
|
|
1403
1416
|
usage: usageSegments(row, locale, tiered, period),
|
|
1404
1417
|
usageSummary: usageSummary(row, options),
|
|
1405
1418
|
hardLimit: row.priceBehavior !== void 0 && row.priceBehavior !== null && row.priceBehavior !== "credit_burndown" && row.valueType === "numeric" && typeof row.allocation === "number" ? {
|
|
1406
|
-
amount: row.allocation,
|
|
1419
|
+
amount: formatNumber(row.allocation, locale),
|
|
1407
1420
|
units: featureName(feature, row.allocation, locale)
|
|
1408
1421
|
} : null,
|
|
1409
1422
|
tiers: (row.priceBehavior === "tier" || tiered) && row.price !== void 0 ? {
|
|
@@ -1448,7 +1461,7 @@ function entitlementText(row, options) {
|
|
|
1448
1461
|
return size > 1 ? {
|
|
1449
1462
|
kind: "perPackage",
|
|
1450
1463
|
cost,
|
|
1451
|
-
size,
|
|
1464
|
+
size: formatNumber(size, locale),
|
|
1452
1465
|
units: featureName(feature, size, locale)
|
|
1453
1466
|
} : { kind: "perUnit", cost, unit: featureName(feature, 1, locale) };
|
|
1454
1467
|
}
|
|
@@ -1509,14 +1522,14 @@ function usageSegments(row, locale, tiered, period) {
|
|
|
1509
1522
|
segments.push({
|
|
1510
1523
|
kind: "unitPricePerPeriod",
|
|
1511
1524
|
cost: formatCurrency(unitPrice(row.price), row.price.currency, locale),
|
|
1512
|
-
size,
|
|
1525
|
+
size: size > 1 ? formatNumber(size, locale) : null,
|
|
1513
1526
|
units: featureName(feature, size, locale),
|
|
1514
1527
|
period
|
|
1515
1528
|
});
|
|
1516
1529
|
} else if ((row.priceBehavior === "pay_as_you_go" || row.priceBehavior === "overage" || row.priceBehavior === "tier" || row.priceBehavior === "credit_burndown" || tiered) && typeof row.usage === "number") {
|
|
1517
1530
|
segments.push({
|
|
1518
1531
|
kind: "used",
|
|
1519
|
-
amount:
|
|
1532
|
+
amount: formatNumber(row.usage, locale),
|
|
1520
1533
|
units: featureName(feature, row.usage, locale)
|
|
1521
1534
|
});
|
|
1522
1535
|
}
|
|
@@ -1591,7 +1604,7 @@ function meteredFeatureRow(row, options) {
|
|
|
1591
1604
|
limit: limitLine(row, limit, unit, options),
|
|
1592
1605
|
resetsAt: resetsAt === void 0 ? null : formatDate(resetsAt, locale, { month: "short", year: void 0 }),
|
|
1593
1606
|
hardLimit: row.priceBehavior !== void 0 && row.priceBehavior !== null && row.priceBehavior !== "credit_burndown" && row.valueType === "numeric" && typeof row.allocation === "number" ? {
|
|
1594
|
-
amount: row.allocation,
|
|
1607
|
+
amount: formatNumber(row.allocation, locale),
|
|
1595
1608
|
units: featureName(unit, row.allocation, locale)
|
|
1596
1609
|
} : null,
|
|
1597
1610
|
meter: meter(row, options),
|
|
@@ -1713,7 +1726,7 @@ function priceDetails(row, unit, locale) {
|
|
|
1713
1726
|
return {
|
|
1714
1727
|
kind: "overage",
|
|
1715
1728
|
unitPrice: money(tier.perUnitPrice),
|
|
1716
|
-
packageSize: size,
|
|
1729
|
+
packageSize: size > 1 ? formatNumber(size, locale) : null,
|
|
1717
1730
|
units: featureName(unit, size, locale),
|
|
1718
1731
|
period,
|
|
1719
1732
|
overage: {
|
|
@@ -1729,8 +1742,8 @@ function priceDetails(row, unit, locale) {
|
|
|
1729
1742
|
}
|
|
1730
1743
|
return {
|
|
1731
1744
|
kind: "tier",
|
|
1732
|
-
from: tier.from === 0 ? 1 : tier.from,
|
|
1733
|
-
to: tier.to,
|
|
1745
|
+
from: formatNumber(tier.from === 0 ? 1 : tier.from, locale),
|
|
1746
|
+
to: tier.to === null ? null : formatNumber(tier.to, locale),
|
|
1734
1747
|
cost: typeof row.currentCost === "number" ? money(row.currentCost) : null,
|
|
1735
1748
|
period,
|
|
1736
1749
|
tiers: {
|
|
@@ -1743,6 +1756,98 @@ function priceDetails(row, unit, locale) {
|
|
|
1743
1756
|
return null;
|
|
1744
1757
|
}
|
|
1745
1758
|
|
|
1759
|
+
// src/elements/model/creditUsage.ts
|
|
1760
|
+
function deriveCreditUsage(balances, options) {
|
|
1761
|
+
const ordered = options.visibleCredits === void 0 ? balances : options.visibleCredits.flatMap((id) => {
|
|
1762
|
+
const balance = balances.find((b) => b.creditId === id);
|
|
1763
|
+
return balance === void 0 ? [] : [balance];
|
|
1764
|
+
});
|
|
1765
|
+
return ordered.map((balance) => creditUsageRow(balance, options.locale));
|
|
1766
|
+
}
|
|
1767
|
+
function creditUsageRow(balance, locale) {
|
|
1768
|
+
const unit = {
|
|
1769
|
+
name: balance.creditName,
|
|
1770
|
+
singularName: balance.creditSingularName ?? void 0,
|
|
1771
|
+
pluralName: balance.creditPluralName ?? void 0
|
|
1772
|
+
};
|
|
1773
|
+
const composition = balance.composition;
|
|
1774
|
+
return {
|
|
1775
|
+
creditId: balance.creditId,
|
|
1776
|
+
name: balance.creditName,
|
|
1777
|
+
description: balance.creditDescription === "" ? null : balance.creditDescription,
|
|
1778
|
+
icon: balance.creditIcon === void 0 || balance.creditIcon === null || balance.creditIcon === "" ? null : balance.creditIcon,
|
|
1779
|
+
remaining: {
|
|
1780
|
+
amount: formatCredits(balance.remaining, locale),
|
|
1781
|
+
units: featureName(unit, balance.remaining, locale)
|
|
1782
|
+
},
|
|
1783
|
+
purchasable: balance.purchasable,
|
|
1784
|
+
ledger: balance.grants.map((grant) => ledgerRow(grant, unit, locale)),
|
|
1785
|
+
composition: composition === void 0 || composition === null ? null : {
|
|
1786
|
+
total: formatCredits(composition.total, locale),
|
|
1787
|
+
creditName: featureName(unit, composition.total, locale),
|
|
1788
|
+
period: composition.period,
|
|
1789
|
+
perLicense: {
|
|
1790
|
+
quantity: formatNumber(composition.licenseQuantity, locale),
|
|
1791
|
+
licenseName: featureName(
|
|
1792
|
+
{
|
|
1793
|
+
name: composition.licenseName,
|
|
1794
|
+
singularName: composition.licenseSingularName,
|
|
1795
|
+
pluralName: composition.licensePluralName
|
|
1796
|
+
},
|
|
1797
|
+
composition.licenseQuantity,
|
|
1798
|
+
locale
|
|
1799
|
+
),
|
|
1800
|
+
perUnit: formatCredits(composition.perLicenseAmount, locale)
|
|
1801
|
+
},
|
|
1802
|
+
companyGrant: composition.fixedQuantity > 0 ? formatCredits(composition.fixedQuantity, locale) : null,
|
|
1803
|
+
renewsOn: renewsOn(composition.renewsAt, locale)
|
|
1804
|
+
},
|
|
1805
|
+
unit,
|
|
1806
|
+
source: balance
|
|
1807
|
+
};
|
|
1808
|
+
}
|
|
1809
|
+
function ledgerRow(grant, unit, locale) {
|
|
1810
|
+
const kind = grant.grantReason === "plan" ? "plan" : grant.grantReason === "purchased" ? "bundle" : grant.grantReason === "billing_credit_auto_topup" ? "autoTopup" : "promotional";
|
|
1811
|
+
const short = (date) => formatDate(date, locale, { month: "short" });
|
|
1812
|
+
const resetsAt = usableDate(grant.resetsAt);
|
|
1813
|
+
const expiresAt = usableDate(grant.expiresAt);
|
|
1814
|
+
return {
|
|
1815
|
+
id: grant.id,
|
|
1816
|
+
kind,
|
|
1817
|
+
amount: formatCredits(grant.quantity, locale),
|
|
1818
|
+
item: featureName(unit, kind === "bundle" ? 1 : grant.quantity, locale),
|
|
1819
|
+
createdAt: short(grant.createdAt),
|
|
1820
|
+
date: resetsAt !== void 0 ? { kind: "resets", text: short(resetsAt) } : expiresAt !== void 0 ? { kind: "expires", text: short(expiresAt) } : null,
|
|
1821
|
+
source: grant
|
|
1822
|
+
};
|
|
1823
|
+
}
|
|
1824
|
+
function renewsOn(date, locale) {
|
|
1825
|
+
const due = usableDate(date);
|
|
1826
|
+
if (due === void 0) {
|
|
1827
|
+
return null;
|
|
1828
|
+
}
|
|
1829
|
+
const day = due.getDate();
|
|
1830
|
+
if (!isEnglish2(locale)) {
|
|
1831
|
+
return formatNumber(day, locale);
|
|
1832
|
+
}
|
|
1833
|
+
const suffix = {
|
|
1834
|
+
few: "rd",
|
|
1835
|
+
many: "th",
|
|
1836
|
+
one: "st",
|
|
1837
|
+
other: "th",
|
|
1838
|
+
two: "nd",
|
|
1839
|
+
zero: "th"
|
|
1840
|
+
};
|
|
1841
|
+
return `${day}${suffix[new Intl.PluralRules("en", { type: "ordinal" }).select(day)]}`;
|
|
1842
|
+
}
|
|
1843
|
+
function isEnglish2(locale) {
|
|
1844
|
+
try {
|
|
1845
|
+
return new Intl.Locale(locale).language === "en";
|
|
1846
|
+
} catch {
|
|
1847
|
+
return false;
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
|
|
1746
1851
|
// src/elements/strings.ts
|
|
1747
1852
|
var DEFAULT_STRINGS_LOCALE = "en";
|
|
1748
1853
|
var DEFAULT_STRINGS = {
|
|
@@ -1830,6 +1935,27 @@ var DEFAULT_STRINGS = {
|
|
|
1830
1935
|
meteredFeaturesAddMore: "Add More",
|
|
1831
1936
|
meteredFeaturesAdditional: "Additional",
|
|
1832
1937
|
meteredFeaturesTier: "Tier",
|
|
1938
|
+
creditUsageLoading: "Loading credits",
|
|
1939
|
+
creditUsageHeader: "Credits",
|
|
1940
|
+
creditUsageError: "There was a problem retrieving your credits.",
|
|
1941
|
+
creditUsageUnavailable: "Credits are not available for this account.",
|
|
1942
|
+
creditUsageRemaining: "{{amount}} {{units}} remaining",
|
|
1943
|
+
creditUsageBuyMore: "Buy More",
|
|
1944
|
+
creditUsageSeeDetails: "See balance details",
|
|
1945
|
+
creditUsageHideDetails: "Hide balance details",
|
|
1946
|
+
creditUsageSeeAll: "See all ({{total}})",
|
|
1947
|
+
creditUsageHideAll: "Hide all",
|
|
1948
|
+
creditUsageGrantPlan: "{{amount}} {{item}} included in plan",
|
|
1949
|
+
creditUsageGrantBundle: "{{amount}} {{item}} bundle purchased {{createdAt}}",
|
|
1950
|
+
creditUsageGrantAutoTopup: "{{amount}} {{item}} auto-topup purchased {{createdAt}}",
|
|
1951
|
+
creditUsageGrantPromotional: "{{amount}} promotional {{item}} granted {{createdAt}}",
|
|
1952
|
+
creditUsageResets: "Resets {{date}}",
|
|
1953
|
+
creditUsageExpires: "Expires {{date}}",
|
|
1954
|
+
creditUsageComposition: "Your plan includes {{total}} {{creditName}}/{{period}} \u2014 {{perLicense}}.",
|
|
1955
|
+
creditUsageCompositionWithGrant: "Your plan includes {{total}} {{creditName}}/{{period}} \u2014 {{perLicense}} + {{companyGrant}}.",
|
|
1956
|
+
creditUsagePerLicense: "{{quantity}} {{licenseName}} \xD7 {{perUnit}}",
|
|
1957
|
+
creditUsageCompanyGrant: "{{amount}} company grant",
|
|
1958
|
+
creditUsageRenewsOn: "Renews on the {{day}}.",
|
|
1833
1959
|
usageByUserHeader: "Usage by user",
|
|
1834
1960
|
usageByUserTotal: "{{amount}} used by your team this period",
|
|
1835
1961
|
usageByUserError: "There was a problem retrieving usage by user.",
|
|
@@ -1896,6 +2022,160 @@ function defaultString(key, vars) {
|
|
|
1896
2022
|
return lookup(DEFAULT_STRINGS, key, vars) ?? DEFAULT_STRINGS[key] ?? key;
|
|
1897
2023
|
}
|
|
1898
2024
|
|
|
2025
|
+
// src/elements/styles/credit-usage.ts
|
|
2026
|
+
var creditUsageCss = `
|
|
2027
|
+
.schematic-credit-usage__credits {
|
|
2028
|
+
display: flex;
|
|
2029
|
+
flex-direction: column;
|
|
2030
|
+
gap: var(--schematic-space);
|
|
2031
|
+
}
|
|
2032
|
+
|
|
2033
|
+
/* Each credit draws its own card, so the root draws one only while pending
|
|
2034
|
+
or failed. */
|
|
2035
|
+
.schematic-credit-usage[data-state="pending"],
|
|
2036
|
+
.schematic-credit-usage[data-state="error"] {
|
|
2037
|
+
background: var(--schematic-background);
|
|
2038
|
+
border-radius: var(--schematic-radius);
|
|
2039
|
+
box-shadow: var(--schematic-shadow);
|
|
2040
|
+
padding: calc(var(--schematic-card-padding) * 0.75)
|
|
2041
|
+
var(--schematic-card-padding);
|
|
2042
|
+
}
|
|
2043
|
+
|
|
2044
|
+
.schematic-credit-usage__credit {
|
|
2045
|
+
display: flex;
|
|
2046
|
+
flex-direction: column;
|
|
2047
|
+
gap: var(--schematic-space);
|
|
2048
|
+
}
|
|
2049
|
+
|
|
2050
|
+
.schematic-credit-usage__main {
|
|
2051
|
+
display: flex;
|
|
2052
|
+
gap: calc(var(--schematic-space) * 1.5);
|
|
2053
|
+
}
|
|
2054
|
+
|
|
2055
|
+
/* Held even without a glyph, as the embed does, so names line up. */
|
|
2056
|
+
.schematic-credit-usage__icon {
|
|
2057
|
+
align-items: center;
|
|
2058
|
+
background: var(--schematic-surface);
|
|
2059
|
+
border-radius: 9999px;
|
|
2060
|
+
display: inline-flex;
|
|
2061
|
+
flex-shrink: 0;
|
|
2062
|
+
font-size: 1.5rem;
|
|
2063
|
+
height: 2.75rem;
|
|
2064
|
+
justify-content: center;
|
|
2065
|
+
width: 2.75rem;
|
|
2066
|
+
}
|
|
2067
|
+
|
|
2068
|
+
.schematic-credit-usage__icon .schematic-icon {
|
|
2069
|
+
color: var(--schematic-accent);
|
|
2070
|
+
}
|
|
2071
|
+
|
|
2072
|
+
/* The embed's spacing: the balance well clear of the name, the composition
|
|
2073
|
+
tucked close under the balance. */
|
|
2074
|
+
.schematic-credit-usage__body {
|
|
2075
|
+
display: flex;
|
|
2076
|
+
flex-direction: column;
|
|
2077
|
+
flex-grow: 1;
|
|
2078
|
+
gap: calc(var(--schematic-space) * 2);
|
|
2079
|
+
min-width: 0;
|
|
2080
|
+
}
|
|
2081
|
+
|
|
2082
|
+
.schematic-credit-usage__composition {
|
|
2083
|
+
margin-top: calc(var(--schematic-space) * -1.5);
|
|
2084
|
+
}
|
|
2085
|
+
|
|
2086
|
+
.schematic-credit-usage__title {
|
|
2087
|
+
display: flex;
|
|
2088
|
+
flex-direction: column;
|
|
2089
|
+
gap: 0.5rem;
|
|
2090
|
+
}
|
|
2091
|
+
|
|
2092
|
+
.schematic-credit-usage__name {
|
|
2093
|
+
font-family: var(--schematic-font-heading);
|
|
2094
|
+
font-size: 1.8125rem;
|
|
2095
|
+
font-weight: 800;
|
|
2096
|
+
line-height: var(--schematic-line-height-heading);
|
|
2097
|
+
margin: 0;
|
|
2098
|
+
}
|
|
2099
|
+
|
|
2100
|
+
.schematic-credit-usage__balance {
|
|
2101
|
+
align-items: center;
|
|
2102
|
+
display: flex;
|
|
2103
|
+
gap: var(--schematic-space);
|
|
2104
|
+
justify-content: space-between;
|
|
2105
|
+
}
|
|
2106
|
+
|
|
2107
|
+
.schematic-credit-usage__remaining {
|
|
2108
|
+
font-size: 1.0625rem;
|
|
2109
|
+
font-variant-numeric: tabular-nums;
|
|
2110
|
+
font-weight: 500;
|
|
2111
|
+
}
|
|
2112
|
+
|
|
2113
|
+
.schematic-credit-usage__buy-more {
|
|
2114
|
+
white-space: nowrap;
|
|
2115
|
+
}
|
|
2116
|
+
|
|
2117
|
+
.schematic-credit-usage__details,
|
|
2118
|
+
.schematic-credit-usage__see-all {
|
|
2119
|
+
align-items: center;
|
|
2120
|
+
display: inline-flex;
|
|
2121
|
+
gap: 0.25rem;
|
|
2122
|
+
}
|
|
2123
|
+
|
|
2124
|
+
.schematic-credit-usage__details .schematic-chevron,
|
|
2125
|
+
.schematic-credit-usage__see-all .schematic-chevron {
|
|
2126
|
+
margin-inline-start: -0.333rem;
|
|
2127
|
+
}
|
|
2128
|
+
|
|
2129
|
+
/* Opens above its toggle, as in the embed. */
|
|
2130
|
+
.schematic-credit-usage__grants {
|
|
2131
|
+
background: var(--schematic-inset);
|
|
2132
|
+
border-radius: calc(var(--schematic-radius) * 0.8);
|
|
2133
|
+
display: flex;
|
|
2134
|
+
flex-direction: column;
|
|
2135
|
+
gap: 0.5rem;
|
|
2136
|
+
margin-bottom: 0.5rem;
|
|
2137
|
+
padding: calc(var(--schematic-space) * 1.5);
|
|
2138
|
+
}
|
|
2139
|
+
|
|
2140
|
+
.schematic-credit-usage__grant-list {
|
|
2141
|
+
display: flex;
|
|
2142
|
+
flex-direction: column;
|
|
2143
|
+
gap: 0.75rem;
|
|
2144
|
+
list-style: none;
|
|
2145
|
+
margin: 0;
|
|
2146
|
+
padding: 0;
|
|
2147
|
+
}
|
|
2148
|
+
|
|
2149
|
+
/* Where the grant and its date do not fit on one line, the date wraps
|
|
2150
|
+
rather than overflowing the panel. */
|
|
2151
|
+
.schematic-credit-usage__grant {
|
|
2152
|
+
display: flex;
|
|
2153
|
+
flex-wrap: wrap;
|
|
2154
|
+
gap: 0.25rem var(--schematic-space);
|
|
2155
|
+
justify-content: space-between;
|
|
2156
|
+
}
|
|
2157
|
+
|
|
2158
|
+
.schematic-credit-usage__grant-text {
|
|
2159
|
+
flex: 1 1 12rem;
|
|
2160
|
+
min-width: 0;
|
|
2161
|
+
overflow-wrap: anywhere;
|
|
2162
|
+
}
|
|
2163
|
+
|
|
2164
|
+
.schematic-credit-usage__grant-date {
|
|
2165
|
+
margin-inline-start: auto;
|
|
2166
|
+
text-align: end;
|
|
2167
|
+
white-space: nowrap;
|
|
2168
|
+
}
|
|
2169
|
+
|
|
2170
|
+
.schematic-credit-usage .schematic-skeleton__cell[data-column="name"] {
|
|
2171
|
+
width: 10rem;
|
|
2172
|
+
}
|
|
2173
|
+
|
|
2174
|
+
.schematic-credit-usage .schematic-skeleton__cell[data-column="remaining"] {
|
|
2175
|
+
width: 6rem;
|
|
2176
|
+
}
|
|
2177
|
+
`;
|
|
2178
|
+
|
|
1899
2179
|
// src/elements/styles/dialog.ts
|
|
1900
2180
|
var dialogCss = `
|
|
1901
2181
|
/* Up to 768px wide, with a tighter radius than a card. */
|
|
@@ -3782,11 +4062,12 @@ ${paymentMethodsCss}
|
|
|
3782
4062
|
${tooltipCss}
|
|
3783
4063
|
${includedFeaturesCss}
|
|
3784
4064
|
${meteredFeaturesCss}
|
|
4065
|
+
${creditUsageCss}
|
|
3785
4066
|
`;
|
|
3786
4067
|
var schematicStylesCss = withTokenDefaults(rulesCss) + iconsCss;
|
|
3787
4068
|
var SchematicStyles = () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("style", { "data-schematic-styles": "", children: schematicStylesCss });
|
|
3788
4069
|
|
|
3789
|
-
// src/elements/
|
|
4070
|
+
// src/elements/CreditUsage.tsx
|
|
3790
4071
|
var import_schematic_react2 = require("@schematichq/schematic-react");
|
|
3791
4072
|
var import_react3 = require("react");
|
|
3792
4073
|
|
|
@@ -3823,6 +4104,9 @@ function useTranslator(overrides, locale) {
|
|
|
3823
4104
|
const { onMissingString, strings, translate } = (0, import_schematic_react.useSchematicI18n)();
|
|
3824
4105
|
return (0, import_react.useCallback)(
|
|
3825
4106
|
(key, vars) => {
|
|
4107
|
+
if (isDevelopment) {
|
|
4108
|
+
warnRawNumbers(key, vars);
|
|
4109
|
+
}
|
|
3826
4110
|
const override = lookup(overrides, key, vars, resolved2) ?? lookup(strings, key, vars, resolved2);
|
|
3827
4111
|
if (override !== void 0) {
|
|
3828
4112
|
return override;
|
|
@@ -3844,6 +4128,18 @@ function useTranslator(overrides, locale) {
|
|
|
3844
4128
|
[onMissingString, overrides, resolved2, strings, translate]
|
|
3845
4129
|
);
|
|
3846
4130
|
}
|
|
4131
|
+
var rawNumberWarnings = /* @__PURE__ */ new Set();
|
|
4132
|
+
function warnRawNumbers(key, vars) {
|
|
4133
|
+
for (const [name, value] of Object.entries(vars ?? {})) {
|
|
4134
|
+
const id = `${key}.${name}`;
|
|
4135
|
+
if (name !== "count" && typeof value === "number" && !rawNumberWarnings.has(id)) {
|
|
4136
|
+
rawNumberWarnings.add(id);
|
|
4137
|
+
console.warn(
|
|
4138
|
+
`Schematic: "${key}" got a raw number for "${name}"; format it before it reaches the translator.`
|
|
4139
|
+
);
|
|
4140
|
+
}
|
|
4141
|
+
}
|
|
4142
|
+
}
|
|
3847
4143
|
var isDevelopment = (() => {
|
|
3848
4144
|
try {
|
|
3849
4145
|
return process.env.NODE_ENV !== "production";
|
|
@@ -4027,8 +4323,8 @@ function PriceTiers({
|
|
|
4027
4323
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { className: "schematic-tiers", children: [
|
|
4028
4324
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("dl", { className: "schematic-tiers__list", children: ranges.map((tier) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "schematic-tiers__tier", children: [
|
|
4029
4325
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("dt", { className: "schematic-tiers__range", children: [
|
|
4030
|
-
tier.from,
|
|
4031
|
-
tier.to === null ? "+" : tier.to !== tier.from ? `\u2013${tier.to}` : ""
|
|
4326
|
+
formatNumber(tier.from, locale),
|
|
4327
|
+
tier.to === null ? "+" : tier.to !== tier.from ? `\u2013${formatNumber(tier.to, locale)}` : ""
|
|
4032
4328
|
] }),
|
|
4033
4329
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("dd", { className: "schematic-tiers__price", children: tierPrice(tier.flatPrice ?? 0, tier.perUnitPrice ?? 0) })
|
|
4034
4330
|
] }, tier.from)) }),
|
|
@@ -4038,6 +4334,7 @@ function PriceTiers({
|
|
|
4038
4334
|
function UserBreakdown({
|
|
4039
4335
|
breakdown,
|
|
4040
4336
|
error,
|
|
4337
|
+
formatAmount,
|
|
4041
4338
|
locale,
|
|
4042
4339
|
onRetry,
|
|
4043
4340
|
t,
|
|
@@ -4048,7 +4345,7 @@ function UserBreakdown({
|
|
|
4048
4345
|
() => [...breakdown?.users ?? []].sort((a, b) => b.amount - a.amount),
|
|
4049
4346
|
[breakdown?.users]
|
|
4050
4347
|
);
|
|
4051
|
-
const amount = (value) => `${formatNumber(value, locale)} ${featureName(unit, value, locale)}`;
|
|
4348
|
+
const amount = (value) => `${formatAmount?.(value) ?? formatNumber(value, locale)} ${featureName(unit, value, locale)}`;
|
|
4052
4349
|
if (breakdown === void 0 && error !== void 0) {
|
|
4053
4350
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "schematic-usage-by-user", role: "alert", children: [
|
|
4054
4351
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "schematic-usage-by-user__title", children: t("usageByUserHeader") }),
|
|
@@ -4136,8 +4433,286 @@ function UserBreakdown({
|
|
|
4136
4433
|
] });
|
|
4137
4434
|
}
|
|
4138
4435
|
|
|
4139
|
-
// src/elements/
|
|
4436
|
+
// src/elements/CreditUsage.tsx
|
|
4140
4437
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
4438
|
+
var VISIBLE_GRANT_COUNT = 3;
|
|
4439
|
+
var GRANT_KEY = {
|
|
4440
|
+
autoTopup: "creditUsageGrantAutoTopup",
|
|
4441
|
+
bundle: "creditUsageGrantBundle",
|
|
4442
|
+
plan: "creditUsageGrantPlan",
|
|
4443
|
+
promotional: "creditUsageGrantPromotional"
|
|
4444
|
+
};
|
|
4445
|
+
function CreditUsage({
|
|
4446
|
+
buyMoreTarget,
|
|
4447
|
+
buyMoreUrl,
|
|
4448
|
+
className,
|
|
4449
|
+
headingLevel = 2,
|
|
4450
|
+
locale: localeProp,
|
|
4451
|
+
onBuyMore,
|
|
4452
|
+
showDescription = true,
|
|
4453
|
+
showExpiration = true,
|
|
4454
|
+
showHeader = false,
|
|
4455
|
+
showIcon = true,
|
|
4456
|
+
showUsage = true,
|
|
4457
|
+
showUsageByUser = true,
|
|
4458
|
+
strings,
|
|
4459
|
+
visibleCredits
|
|
4460
|
+
}) {
|
|
4461
|
+
const { data: balances, error, isPending, refetch } = (0, import_schematic_react2.useCreditBalances)();
|
|
4462
|
+
const locale = useResolvedLocale(localeProp);
|
|
4463
|
+
const t = useTranslator(strings, localeProp);
|
|
4464
|
+
const credits = (0, import_react3.useMemo)(
|
|
4465
|
+
() => balances === void 0 ? [] : deriveCreditUsage(balances, { locale, visibleCredits }),
|
|
4466
|
+
[balances, locale, visibleCredits]
|
|
4467
|
+
);
|
|
4468
|
+
const unavailable = balances === void 0 && httpStatus(error) === 404;
|
|
4469
|
+
const errorMessage = error === void 0 ? void 0 : unavailable ? t("creditUsageUnavailable") : t("creditUsageError");
|
|
4470
|
+
if (balances !== void 0 && error === void 0 && credits.length === 0) {
|
|
4471
|
+
return null;
|
|
4472
|
+
}
|
|
4473
|
+
const Heading = `h${headingLevel}`;
|
|
4474
|
+
const CreditHeading = showHeader ? `h${Math.min(6, headingLevel + 1)}` : Heading;
|
|
4475
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
4476
|
+
StatusFrame,
|
|
4477
|
+
{
|
|
4478
|
+
className: cx("schematic-credit-usage", className),
|
|
4479
|
+
error,
|
|
4480
|
+
errorMessage,
|
|
4481
|
+
hasData: balances !== void 0,
|
|
4482
|
+
isPending,
|
|
4483
|
+
loadingLabel: t("creditUsageLoading"),
|
|
4484
|
+
onRetry: refetch,
|
|
4485
|
+
retryText: t("retry"),
|
|
4486
|
+
skeleton: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CreditUsageSkeleton, { showHeader }),
|
|
4487
|
+
children: [
|
|
4488
|
+
showHeader && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "schematic-header", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Heading, { className: "schematic-header__title", children: t("creditUsageHeader") }) }),
|
|
4489
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "schematic-credit-usage__credits", children: credits.map((credit) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
4490
|
+
"section",
|
|
4491
|
+
{
|
|
4492
|
+
"aria-label": credit.name,
|
|
4493
|
+
className: "schematic-card schematic-credit-usage__credit",
|
|
4494
|
+
"data-testid": "schematic-credit",
|
|
4495
|
+
children: [
|
|
4496
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "schematic-credit-usage__main", children: [
|
|
4497
|
+
showIcon && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "schematic-credit-usage__icon", children: credit.icon !== null && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
4498
|
+
"i",
|
|
4499
|
+
{
|
|
4500
|
+
"aria-hidden": "true",
|
|
4501
|
+
className: `schematic-icon schematic-icon--${credit.icon}`
|
|
4502
|
+
}
|
|
4503
|
+
) }),
|
|
4504
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "schematic-credit-usage__body", children: [
|
|
4505
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "schematic-credit-usage__title", children: [
|
|
4506
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CreditHeading, { className: "schematic-credit-usage__name", children: credit.name }),
|
|
4507
|
+
showDescription && credit.description !== null && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: "schematic-muted", children: credit.description })
|
|
4508
|
+
] }),
|
|
4509
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "schematic-credit-usage__balance", children: [
|
|
4510
|
+
showUsage && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
4511
|
+
"span",
|
|
4512
|
+
{
|
|
4513
|
+
className: "schematic-credit-usage__remaining",
|
|
4514
|
+
"data-testid": "schematic-credit-remaining",
|
|
4515
|
+
children: t("creditUsageRemaining", credit.remaining)
|
|
4516
|
+
}
|
|
4517
|
+
),
|
|
4518
|
+
credit.purchasable && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
4519
|
+
BuyMore,
|
|
4520
|
+
{
|
|
4521
|
+
credit,
|
|
4522
|
+
label: t("creditUsageBuyMore"),
|
|
4523
|
+
onBuyMore,
|
|
4524
|
+
target: buyMoreTarget,
|
|
4525
|
+
url: buyMoreUrl
|
|
4526
|
+
}
|
|
4527
|
+
)
|
|
4528
|
+
] }),
|
|
4529
|
+
credit.composition !== null && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: "schematic-muted schematic-small schematic-credit-usage__composition", children: compositionText(credit, t) })
|
|
4530
|
+
] })
|
|
4531
|
+
] }),
|
|
4532
|
+
credit.ledger.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
4533
|
+
Ledger,
|
|
4534
|
+
{
|
|
4535
|
+
credit,
|
|
4536
|
+
locale,
|
|
4537
|
+
showExpiration,
|
|
4538
|
+
t
|
|
4539
|
+
}
|
|
4540
|
+
),
|
|
4541
|
+
showUsageByUser && credit.ledger.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CreditUserBreakdown, { credit, locale, t })
|
|
4542
|
+
]
|
|
4543
|
+
},
|
|
4544
|
+
credit.creditId
|
|
4545
|
+
)) })
|
|
4546
|
+
]
|
|
4547
|
+
}
|
|
4548
|
+
);
|
|
4549
|
+
}
|
|
4550
|
+
function compositionText(credit, t) {
|
|
4551
|
+
const composition = credit.composition;
|
|
4552
|
+
if (composition === null) {
|
|
4553
|
+
return "";
|
|
4554
|
+
}
|
|
4555
|
+
const vars = {
|
|
4556
|
+
creditName: composition.creditName,
|
|
4557
|
+
perLicense: t("creditUsagePerLicense", composition.perLicense),
|
|
4558
|
+
period: shortPeriod(composition.period, t) ?? composition.period,
|
|
4559
|
+
total: composition.total
|
|
4560
|
+
};
|
|
4561
|
+
const sentence = composition.companyGrant === null ? t("creditUsageComposition", vars) : t("creditUsageCompositionWithGrant", {
|
|
4562
|
+
...vars,
|
|
4563
|
+
companyGrant: t("creditUsageCompanyGrant", {
|
|
4564
|
+
amount: composition.companyGrant
|
|
4565
|
+
})
|
|
4566
|
+
});
|
|
4567
|
+
return composition.renewsOn === null ? sentence : `${sentence} ${t("creditUsageRenewsOn", { day: composition.renewsOn })}`;
|
|
4568
|
+
}
|
|
4569
|
+
function Ledger({
|
|
4570
|
+
credit,
|
|
4571
|
+
locale,
|
|
4572
|
+
showExpiration,
|
|
4573
|
+
t
|
|
4574
|
+
}) {
|
|
4575
|
+
const [open, setOpen] = (0, import_react3.useState)(false);
|
|
4576
|
+
const [all, setAll] = (0, import_react3.useState)(false);
|
|
4577
|
+
const rows = all ? credit.ledger : credit.ledger.slice(0, VISIBLE_GRANT_COUNT);
|
|
4578
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "schematic-credit-usage__ledger", children: [
|
|
4579
|
+
open && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "schematic-credit-usage__grants", children: [
|
|
4580
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("ul", { className: "schematic-credit-usage__grant-list", children: rows.map((row) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
4581
|
+
"li",
|
|
4582
|
+
{
|
|
4583
|
+
className: "schematic-credit-usage__grant",
|
|
4584
|
+
"data-testid": "schematic-credit-grant",
|
|
4585
|
+
children: [
|
|
4586
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "schematic-credit-usage__grant-text", children: t(GRANT_KEY[row.kind], {
|
|
4587
|
+
amount: row.amount,
|
|
4588
|
+
createdAt: row.createdAt,
|
|
4589
|
+
item: row.item
|
|
4590
|
+
}) }),
|
|
4591
|
+
showExpiration && row.date !== null && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "schematic-credit-usage__grant-date", children: row.date.kind === "resets" ? t("creditUsageResets", { date: row.date.text }) : t("creditUsageExpires", { date: row.date.text }) })
|
|
4592
|
+
]
|
|
4593
|
+
},
|
|
4594
|
+
row.id
|
|
4595
|
+
)) }),
|
|
4596
|
+
credit.ledger.length > VISIBLE_GRANT_COUNT && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
4597
|
+
"button",
|
|
4598
|
+
{
|
|
4599
|
+
"aria-expanded": all,
|
|
4600
|
+
className: "schematic-link-button schematic-credit-usage__see-all",
|
|
4601
|
+
type: "button",
|
|
4602
|
+
onClick: () => setAll((value) => !value),
|
|
4603
|
+
children: [
|
|
4604
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
4605
|
+
"i",
|
|
4606
|
+
{
|
|
4607
|
+
"aria-hidden": "true",
|
|
4608
|
+
className: `schematic-icon schematic-icon--${all ? "chevron-up" : "chevron-down"} schematic-chevron`
|
|
4609
|
+
}
|
|
4610
|
+
),
|
|
4611
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "schematic-link-button__label", children: all ? t("creditUsageHideAll") : t("creditUsageSeeAll", {
|
|
4612
|
+
total: formatNumber(credit.ledger.length, locale)
|
|
4613
|
+
}) })
|
|
4614
|
+
]
|
|
4615
|
+
}
|
|
4616
|
+
)
|
|
4617
|
+
] }),
|
|
4618
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
4619
|
+
"button",
|
|
4620
|
+
{
|
|
4621
|
+
"aria-expanded": open,
|
|
4622
|
+
className: "schematic-link-button schematic-credit-usage__details",
|
|
4623
|
+
type: "button",
|
|
4624
|
+
onClick: () => {
|
|
4625
|
+
setOpen((value) => !value);
|
|
4626
|
+
setAll(false);
|
|
4627
|
+
},
|
|
4628
|
+
children: [
|
|
4629
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
4630
|
+
"i",
|
|
4631
|
+
{
|
|
4632
|
+
"aria-hidden": "true",
|
|
4633
|
+
className: `schematic-icon schematic-icon--${open ? "chevron-up" : "chevron-down"} schematic-chevron`
|
|
4634
|
+
}
|
|
4635
|
+
),
|
|
4636
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "schematic-link-button__label", children: open ? t("creditUsageHideDetails") : t("creditUsageSeeDetails") })
|
|
4637
|
+
]
|
|
4638
|
+
}
|
|
4639
|
+
)
|
|
4640
|
+
] });
|
|
4641
|
+
}
|
|
4642
|
+
function BuyMore({
|
|
4643
|
+
credit,
|
|
4644
|
+
label,
|
|
4645
|
+
onBuyMore,
|
|
4646
|
+
target,
|
|
4647
|
+
url
|
|
4648
|
+
}) {
|
|
4649
|
+
if (onBuyMore !== void 0) {
|
|
4650
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
4651
|
+
"button",
|
|
4652
|
+
{
|
|
4653
|
+
className: "schematic-cta schematic-cta--small schematic-credit-usage__buy-more",
|
|
4654
|
+
type: "button",
|
|
4655
|
+
onClick: () => onBuyMore(credit.source),
|
|
4656
|
+
children: label
|
|
4657
|
+
}
|
|
4658
|
+
);
|
|
4659
|
+
}
|
|
4660
|
+
if (url !== void 0) {
|
|
4661
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
4662
|
+
"a",
|
|
4663
|
+
{
|
|
4664
|
+
className: "schematic-cta schematic-cta--small schematic-credit-usage__buy-more",
|
|
4665
|
+
href: url,
|
|
4666
|
+
target,
|
|
4667
|
+
children: label
|
|
4668
|
+
}
|
|
4669
|
+
);
|
|
4670
|
+
}
|
|
4671
|
+
return null;
|
|
4672
|
+
}
|
|
4673
|
+
function CreditUserBreakdown({
|
|
4674
|
+
credit,
|
|
4675
|
+
locale,
|
|
4676
|
+
t
|
|
4677
|
+
}) {
|
|
4678
|
+
const { data, error, refetch } = (0, import_schematic_react2.useCreditUserUsage)(credit.creditId);
|
|
4679
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
4680
|
+
UserBreakdown,
|
|
4681
|
+
{
|
|
4682
|
+
breakdown: data === void 0 ? void 0 : {
|
|
4683
|
+
count: data.count,
|
|
4684
|
+
total: data.total,
|
|
4685
|
+
unattributed: data.unattributed ?? null,
|
|
4686
|
+
users: data.users.map((user) => ({
|
|
4687
|
+
amount: user.used,
|
|
4688
|
+
id: user.userId,
|
|
4689
|
+
label: user.name ?? user.userId
|
|
4690
|
+
}))
|
|
4691
|
+
},
|
|
4692
|
+
error,
|
|
4693
|
+
formatAmount: (value) => formatCredits(value, locale),
|
|
4694
|
+
locale,
|
|
4695
|
+
onRetry: refetch,
|
|
4696
|
+
t,
|
|
4697
|
+
unit: credit.unit
|
|
4698
|
+
}
|
|
4699
|
+
);
|
|
4700
|
+
}
|
|
4701
|
+
function CreditUsageSkeleton({ showHeader }) {
|
|
4702
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "schematic-skeleton", children: [
|
|
4703
|
+
showHeader && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "schematic-skeleton__heading" }),
|
|
4704
|
+
[0, 1].map((index) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "schematic-skeleton__row", children: [
|
|
4705
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "name" }),
|
|
4706
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "remaining" })
|
|
4707
|
+
] }, index))
|
|
4708
|
+
] });
|
|
4709
|
+
}
|
|
4710
|
+
CreditUsage.resources = ["creditBalances"];
|
|
4711
|
+
|
|
4712
|
+
// src/elements/IncludedFeatures.tsx
|
|
4713
|
+
var import_schematic_react3 = require("@schematichq/schematic-react");
|
|
4714
|
+
var import_react4 = require("react");
|
|
4715
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
4141
4716
|
var VISIBLE_FEATURE_COUNT = 4;
|
|
4142
4717
|
function IncludedFeatures({
|
|
4143
4718
|
className,
|
|
@@ -4155,11 +4730,11 @@ function IncludedFeatures({
|
|
|
4155
4730
|
strings,
|
|
4156
4731
|
visibleFeatures
|
|
4157
4732
|
}) {
|
|
4158
|
-
const { data: features, error, isPending, refetch } = (0,
|
|
4733
|
+
const { data: features, error, isPending, refetch } = (0, import_schematic_react3.useFeatureUsage)();
|
|
4159
4734
|
const locale = useResolvedLocale(localeProp);
|
|
4160
4735
|
const t = useTranslator(strings, localeProp);
|
|
4161
|
-
const [expanded, setExpanded] = (0,
|
|
4162
|
-
const rows = (0,
|
|
4736
|
+
const [expanded, setExpanded] = (0, import_react4.useState)(false);
|
|
4737
|
+
const rows = (0, import_react4.useMemo)(
|
|
4163
4738
|
() => features === void 0 ? [] : deriveIncludedFeatures(features, {
|
|
4164
4739
|
locale,
|
|
4165
4740
|
showCredits,
|
|
@@ -4179,7 +4754,7 @@ function IncludedFeatures({
|
|
|
4179
4754
|
const shown = canExpand && !expanded ? rows.slice(0, VISIBLE_FEATURE_COUNT) : rows;
|
|
4180
4755
|
const unavailable = features === void 0 && httpStatus(error) === 404;
|
|
4181
4756
|
const errorMessage = error === void 0 ? void 0 : unavailable ? t("includedFeaturesUnavailable") : t("includedFeaturesError");
|
|
4182
|
-
return /* @__PURE__ */ (0,
|
|
4757
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
4183
4758
|
StatusFrame,
|
|
4184
4759
|
{
|
|
4185
4760
|
className: cx("schematic-card", "schematic-included-features", className),
|
|
@@ -4190,26 +4765,26 @@ function IncludedFeatures({
|
|
|
4190
4765
|
loadingLabel: t("includedFeaturesLoading"),
|
|
4191
4766
|
onRetry: refetch,
|
|
4192
4767
|
retryText: t("retry"),
|
|
4193
|
-
skeleton: /* @__PURE__ */ (0,
|
|
4768
|
+
skeleton: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(IncludedFeaturesSkeleton, { showHeader }),
|
|
4194
4769
|
children: [
|
|
4195
|
-
showHeader && /* @__PURE__ */ (0,
|
|
4196
|
-
/* @__PURE__ */ (0,
|
|
4770
|
+
showHeader && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "schematic-header", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Heading, { className: "schematic-header__title", children: t("includedFeaturesHeader") }) }),
|
|
4771
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("ul", { className: "schematic-included-features__list", children: shown.map((row) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
4197
4772
|
"li",
|
|
4198
4773
|
{
|
|
4199
4774
|
className: "schematic-included-features__row",
|
|
4200
4775
|
"data-testid": "schematic-included-feature",
|
|
4201
4776
|
children: [
|
|
4202
|
-
showIcon && row.icon !== null && /* @__PURE__ */ (0,
|
|
4777
|
+
showIcon && row.icon !== null && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
4203
4778
|
"i",
|
|
4204
4779
|
{
|
|
4205
4780
|
"aria-hidden": "true",
|
|
4206
4781
|
className: `schematic-icon schematic-icon--${row.icon} schematic-included-features__icon`
|
|
4207
4782
|
}
|
|
4208
4783
|
),
|
|
4209
|
-
/* @__PURE__ */ (0,
|
|
4210
|
-
/* @__PURE__ */ (0,
|
|
4211
|
-
showDescription && row.description !== null && /* @__PURE__ */ (0,
|
|
4212
|
-
row.perLicenseCredits.map((credits, index) => /* @__PURE__ */ (0,
|
|
4784
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "schematic-included-features__details", children: [
|
|
4785
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "schematic-included-features__name", children: row.name }),
|
|
4786
|
+
showDescription && row.description !== null && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "schematic-muted schematic-small", children: row.description }),
|
|
4787
|
+
row.perLicenseCredits.map((credits, index) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
4213
4788
|
"span",
|
|
4214
4789
|
{
|
|
4215
4790
|
className: "schematic-muted schematic-small",
|
|
@@ -4221,9 +4796,9 @@ function IncludedFeatures({
|
|
|
4221
4796
|
},
|
|
4222
4797
|
`${credits.creditName}-${index}`
|
|
4223
4798
|
)),
|
|
4224
|
-
showExpiration && row.expiresAt !== null && /* @__PURE__ */ (0,
|
|
4799
|
+
showExpiration && row.expiresAt !== null && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("em", { className: "schematic-muted schematic-small", children: t("includedFeaturesExpires", { date: row.expiresAt.text }) })
|
|
4225
4800
|
] }),
|
|
4226
|
-
/* @__PURE__ */ (0,
|
|
4801
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
4227
4802
|
UsageDetails,
|
|
4228
4803
|
{
|
|
4229
4804
|
row,
|
|
@@ -4238,7 +4813,7 @@ function IncludedFeatures({
|
|
|
4238
4813
|
},
|
|
4239
4814
|
row.featureId
|
|
4240
4815
|
)) }),
|
|
4241
|
-
canExpand && /* @__PURE__ */ (0,
|
|
4816
|
+
canExpand && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
4242
4817
|
"button",
|
|
4243
4818
|
{
|
|
4244
4819
|
"aria-expanded": expanded,
|
|
@@ -4246,14 +4821,14 @@ function IncludedFeatures({
|
|
|
4246
4821
|
type: "button",
|
|
4247
4822
|
onClick: () => setExpanded((value) => !value),
|
|
4248
4823
|
children: [
|
|
4249
|
-
/* @__PURE__ */ (0,
|
|
4824
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
4250
4825
|
"i",
|
|
4251
4826
|
{
|
|
4252
4827
|
"aria-hidden": "true",
|
|
4253
4828
|
className: `schematic-icon schematic-icon--${expanded ? "chevron-up" : "chevron-down"} schematic-chevron`
|
|
4254
4829
|
}
|
|
4255
4830
|
),
|
|
4256
|
-
/* @__PURE__ */ (0,
|
|
4831
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "schematic-link-button__label", children: expanded ? t("includedFeaturesHideAll") : t("includedFeaturesSeeAll") })
|
|
4257
4832
|
]
|
|
4258
4833
|
}
|
|
4259
4834
|
)
|
|
@@ -4273,17 +4848,17 @@ function UsageDetails({
|
|
|
4273
4848
|
if (row.entitlement === null && usage === null) {
|
|
4274
4849
|
return null;
|
|
4275
4850
|
}
|
|
4276
|
-
return /* @__PURE__ */ (0,
|
|
4277
|
-
showEntitlement && row.entitlement !== null && /* @__PURE__ */ (0,
|
|
4851
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "schematic-included-features__usage", children: [
|
|
4852
|
+
showEntitlement && row.entitlement !== null && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "schematic-included-features__entitlement", children: [
|
|
4278
4853
|
entitlementText2(row.entitlement, t),
|
|
4279
|
-
showHardLimit && row.hardLimit !== null && /* @__PURE__ */ (0,
|
|
4854
|
+
showHardLimit && row.hardLimit !== null && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Tooltip, { label: t("usageHardLimitLabel"), children: t("usageHardLimit", {
|
|
4280
4855
|
amount: row.hardLimit.amount,
|
|
4281
4856
|
units: row.hardLimit.units
|
|
4282
4857
|
}) })
|
|
4283
4858
|
] }),
|
|
4284
|
-
showUsage && usage !== null && /* @__PURE__ */ (0,
|
|
4859
|
+
showUsage && usage !== null && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "schematic-muted schematic-small schematic-included-features__used", children: [
|
|
4285
4860
|
usage,
|
|
4286
|
-
row.tiers !== null && row.tiers.ranges.length > 0 && /* @__PURE__ */ (0,
|
|
4861
|
+
row.tiers !== null && row.tiers.ranges.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Tooltip, { label: t("usageTieredPricingLabel"), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
4287
4862
|
PriceTiers,
|
|
4288
4863
|
{
|
|
4289
4864
|
currency: row.tiers.currency,
|
|
@@ -4336,7 +4911,7 @@ function segmentText(segment, t) {
|
|
|
4336
4911
|
switch (segment.kind) {
|
|
4337
4912
|
case "unitPricePerPeriod": {
|
|
4338
4913
|
const period = shortPeriod(segment.period, t) ?? segment.period;
|
|
4339
|
-
return segment.size
|
|
4914
|
+
return segment.size !== null ? t("usagePackagePricePerPeriod", {
|
|
4340
4915
|
cost: segment.cost,
|
|
4341
4916
|
size: segment.size,
|
|
4342
4917
|
units: segment.units,
|
|
@@ -4358,20 +4933,20 @@ function segmentText(segment, t) {
|
|
|
4358
4933
|
}
|
|
4359
4934
|
}
|
|
4360
4935
|
function IncludedFeaturesSkeleton({ showHeader }) {
|
|
4361
|
-
return /* @__PURE__ */ (0,
|
|
4362
|
-
showHeader && /* @__PURE__ */ (0,
|
|
4363
|
-
[0, 1, 2].map((index) => /* @__PURE__ */ (0,
|
|
4364
|
-
/* @__PURE__ */ (0,
|
|
4365
|
-
/* @__PURE__ */ (0,
|
|
4936
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "schematic-skeleton", children: [
|
|
4937
|
+
showHeader && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "schematic-skeleton__heading" }),
|
|
4938
|
+
[0, 1, 2].map((index) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "schematic-skeleton__row", children: [
|
|
4939
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "name" }),
|
|
4940
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "usage" })
|
|
4366
4941
|
] }, index))
|
|
4367
4942
|
] });
|
|
4368
4943
|
}
|
|
4369
4944
|
IncludedFeatures.resources = ["featureUsage"];
|
|
4370
4945
|
|
|
4371
4946
|
// src/elements/Invoices.tsx
|
|
4372
|
-
var
|
|
4373
|
-
var
|
|
4374
|
-
var
|
|
4947
|
+
var import_schematic_react4 = require("@schematichq/schematic-react");
|
|
4948
|
+
var import_react5 = require("react");
|
|
4949
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
4375
4950
|
var SKELETON_ROWS = 4;
|
|
4376
4951
|
function Invoices({
|
|
4377
4952
|
className,
|
|
@@ -4391,15 +4966,15 @@ function Invoices({
|
|
|
4391
4966
|
isPending,
|
|
4392
4967
|
loadMore,
|
|
4393
4968
|
refetch
|
|
4394
|
-
} = (0,
|
|
4969
|
+
} = (0, import_schematic_react4.useInvoices)(query);
|
|
4395
4970
|
const locale = useResolvedLocale(localeProp);
|
|
4396
4971
|
const t = useTranslator(strings, localeProp);
|
|
4397
|
-
const [expanded, setExpanded] = (0,
|
|
4398
|
-
const list = (0,
|
|
4972
|
+
const [expanded, setExpanded] = (0, import_react5.useState)(false);
|
|
4973
|
+
const list = (0, import_react5.useMemo)(
|
|
4399
4974
|
() => page === void 0 ? void 0 : deriveInvoiceList(page, { locale }),
|
|
4400
4975
|
[locale, page]
|
|
4401
4976
|
);
|
|
4402
|
-
const headingId = (0,
|
|
4977
|
+
const headingId = (0, import_react5.useId)();
|
|
4403
4978
|
const rows = list?.rows ?? [];
|
|
4404
4979
|
const canCollapse = collapsible && rows.length > limit;
|
|
4405
4980
|
const showingAll = !canCollapse || expanded;
|
|
@@ -4411,7 +4986,7 @@ function Invoices({
|
|
|
4411
4986
|
);
|
|
4412
4987
|
const unavailable = list === void 0 && httpStatus(error) === 404;
|
|
4413
4988
|
const errorMessage = error === void 0 ? void 0 : unavailable ? t("invoicesUnavailable") : t("invoicesError");
|
|
4414
|
-
return /* @__PURE__ */ (0,
|
|
4989
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
4415
4990
|
StatusFrame,
|
|
4416
4991
|
{
|
|
4417
4992
|
className: cx("schematic-card", "schematic-invoices", className),
|
|
@@ -4422,7 +4997,7 @@ function Invoices({
|
|
|
4422
4997
|
loadingLabel: t("invoicesLoading"),
|
|
4423
4998
|
onRetry: refetch,
|
|
4424
4999
|
retryText: t("retry"),
|
|
4425
|
-
skeleton: /* @__PURE__ */ (0,
|
|
5000
|
+
skeleton: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
4426
5001
|
InvoicesSkeleton,
|
|
4427
5002
|
{
|
|
4428
5003
|
columns,
|
|
@@ -4430,22 +5005,22 @@ function Invoices({
|
|
|
4430
5005
|
showHeader
|
|
4431
5006
|
}
|
|
4432
5007
|
),
|
|
4433
|
-
children: list !== void 0 && /* @__PURE__ */ (0,
|
|
4434
|
-
showHeader && /* @__PURE__ */ (0,
|
|
4435
|
-
rows.length === 0 ? /* @__PURE__ */ (0,
|
|
5008
|
+
children: list !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
|
|
5009
|
+
showHeader && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "schematic-header", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Heading, { className: "schematic-header__title", id: headingId, children: t("invoicesHeader") }) }),
|
|
5010
|
+
rows.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { className: "schematic-muted schematic-invoices__empty", children: t("invoicesEmpty") }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
4436
5011
|
"ul",
|
|
4437
5012
|
{
|
|
4438
5013
|
className: "schematic-invoices__list",
|
|
4439
5014
|
"aria-label": showHeader ? void 0 : t("invoicesHeader"),
|
|
4440
5015
|
"aria-labelledby": showHeader ? headingId : void 0,
|
|
4441
|
-
children: visible.map((row) => /* @__PURE__ */ (0,
|
|
5016
|
+
children: visible.map((row) => /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
|
|
4442
5017
|
"li",
|
|
4443
5018
|
{
|
|
4444
5019
|
className: "schematic-invoices__row",
|
|
4445
5020
|
"data-testid": "schematic-invoice",
|
|
4446
5021
|
children: [
|
|
4447
|
-
showDate && /* @__PURE__ */ (0,
|
|
4448
|
-
showAmount && /* @__PURE__ */ (0,
|
|
5022
|
+
showDate && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "schematic-invoices__date", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(InvoiceDate, { row, t }) }),
|
|
5023
|
+
showAmount && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
4449
5024
|
"span",
|
|
4450
5025
|
{
|
|
4451
5026
|
className: cx(
|
|
@@ -4462,8 +5037,8 @@ function Invoices({
|
|
|
4462
5037
|
))
|
|
4463
5038
|
}
|
|
4464
5039
|
),
|
|
4465
|
-
(canCollapse || showingAll && list.hasMore) && /* @__PURE__ */ (0,
|
|
4466
|
-
canCollapse && /* @__PURE__ */ (0,
|
|
5040
|
+
(canCollapse || showingAll && list.hasMore) && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "schematic-invoices__actions", children: [
|
|
5041
|
+
canCollapse && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
|
|
4467
5042
|
"button",
|
|
4468
5043
|
{
|
|
4469
5044
|
"aria-expanded": expanded,
|
|
@@ -4471,7 +5046,7 @@ function Invoices({
|
|
|
4471
5046
|
type: "button",
|
|
4472
5047
|
onClick: () => setExpanded((value) => !value),
|
|
4473
5048
|
children: [
|
|
4474
|
-
/* @__PURE__ */ (0,
|
|
5049
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
4475
5050
|
"i",
|
|
4476
5051
|
{
|
|
4477
5052
|
"aria-hidden": "true",
|
|
@@ -4483,11 +5058,11 @@ function Invoices({
|
|
|
4483
5058
|
)
|
|
4484
5059
|
}
|
|
4485
5060
|
),
|
|
4486
|
-
/* @__PURE__ */ (0,
|
|
5061
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "schematic-link-button__label", children: expanded ? t("invoicesSeeLess") : t("invoicesSeeMore") })
|
|
4487
5062
|
]
|
|
4488
5063
|
}
|
|
4489
5064
|
),
|
|
4490
|
-
showingAll && list.hasMore && /* @__PURE__ */ (0,
|
|
5065
|
+
showingAll && list.hasMore && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
4491
5066
|
"button",
|
|
4492
5067
|
{
|
|
4493
5068
|
className: "schematic-link-button schematic-invoices__load-more",
|
|
@@ -4510,9 +5085,9 @@ function InvoicesSkeleton({
|
|
|
4510
5085
|
rows,
|
|
4511
5086
|
showHeader
|
|
4512
5087
|
}) {
|
|
4513
|
-
return /* @__PURE__ */ (0,
|
|
4514
|
-
showHeader && /* @__PURE__ */ (0,
|
|
4515
|
-
Array.from({ length: rows }, (_, row) => /* @__PURE__ */ (0,
|
|
5088
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "schematic-skeleton", children: [
|
|
5089
|
+
showHeader && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "schematic-skeleton__heading" }),
|
|
5090
|
+
Array.from({ length: rows }, (_, row) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "schematic-skeleton__row", children: columns.map((column) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
4516
5091
|
"div",
|
|
4517
5092
|
{
|
|
4518
5093
|
className: "schematic-skeleton__cell",
|
|
@@ -4524,10 +5099,10 @@ function InvoicesSkeleton({
|
|
|
4524
5099
|
}
|
|
4525
5100
|
function InvoiceDate({ row, t }) {
|
|
4526
5101
|
if (row.url === null) {
|
|
4527
|
-
return /* @__PURE__ */ (0,
|
|
5102
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "schematic-invoices__date-text", children: row.dateText });
|
|
4528
5103
|
}
|
|
4529
5104
|
const label = row.dateText === "" ? t("invoicesUndated") : row.dateText;
|
|
4530
|
-
return /* @__PURE__ */ (0,
|
|
5105
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
4531
5106
|
"a",
|
|
4532
5107
|
{
|
|
4533
5108
|
className: "schematic-invoices__link",
|
|
@@ -4541,9 +5116,9 @@ function InvoiceDate({ row, t }) {
|
|
|
4541
5116
|
Invoices.resources = ["invoices"];
|
|
4542
5117
|
|
|
4543
5118
|
// src/elements/MeteredFeatures.tsx
|
|
4544
|
-
var
|
|
4545
|
-
var
|
|
4546
|
-
var
|
|
5119
|
+
var import_schematic_react5 = require("@schematichq/schematic-react");
|
|
5120
|
+
var import_react6 = require("react");
|
|
5121
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
4547
5122
|
function MeteredFeatures({
|
|
4548
5123
|
addMoreTarget,
|
|
4549
5124
|
addMoreUrl,
|
|
@@ -4564,10 +5139,10 @@ function MeteredFeatures({
|
|
|
4564
5139
|
strings,
|
|
4565
5140
|
visibleFeatures
|
|
4566
5141
|
}) {
|
|
4567
|
-
const { data: features, error, isPending, refetch } = (0,
|
|
5142
|
+
const { data: features, error, isPending, refetch } = (0, import_schematic_react5.useFeatureUsage)();
|
|
4568
5143
|
const locale = useResolvedLocale(localeProp);
|
|
4569
5144
|
const t = useTranslator(strings, localeProp);
|
|
4570
|
-
const rows = (0,
|
|
5145
|
+
const rows = (0, import_react6.useMemo)(
|
|
4571
5146
|
() => features === void 0 ? [] : deriveMeteredFeatures(features, {
|
|
4572
5147
|
locale,
|
|
4573
5148
|
showCredits,
|
|
@@ -4589,7 +5164,7 @@ function MeteredFeatures({
|
|
|
4589
5164
|
}
|
|
4590
5165
|
const Heading = `h${headingLevel}`;
|
|
4591
5166
|
const NameHeading = showHeader ? `h${Math.min(6, headingLevel + 1)}` : Heading;
|
|
4592
|
-
return /* @__PURE__ */ (0,
|
|
5167
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
|
|
4593
5168
|
StatusFrame,
|
|
4594
5169
|
{
|
|
4595
5170
|
className: cx("schematic-metered-features", className),
|
|
@@ -4600,32 +5175,32 @@ function MeteredFeatures({
|
|
|
4600
5175
|
loadingLabel: t("meteredFeaturesLoading"),
|
|
4601
5176
|
onRetry: refetch,
|
|
4602
5177
|
retryText: t("retry"),
|
|
4603
|
-
skeleton: /* @__PURE__ */ (0,
|
|
5178
|
+
skeleton: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(MeteredFeaturesSkeleton, { showHeader }),
|
|
4604
5179
|
children: [
|
|
4605
|
-
showHeader && /* @__PURE__ */ (0,
|
|
4606
|
-
/* @__PURE__ */ (0,
|
|
5180
|
+
showHeader && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "schematic-header", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Heading, { className: "schematic-header__title", children: t("meteredFeaturesHeader") }) }),
|
|
5181
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("ul", { className: "schematic-metered-features__list", children: rows.map((row) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
|
|
4607
5182
|
"li",
|
|
4608
5183
|
{
|
|
4609
5184
|
className: "schematic-card schematic-metered-features__feature",
|
|
4610
5185
|
"data-testid": "schematic-metered-feature",
|
|
4611
5186
|
children: [
|
|
4612
|
-
/* @__PURE__ */ (0,
|
|
4613
|
-
showIcon && /* @__PURE__ */ (0,
|
|
5187
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "schematic-metered-features__main", children: [
|
|
5188
|
+
showIcon && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "schematic-metered-features__icon", children: row.icon !== null && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
4614
5189
|
"i",
|
|
4615
5190
|
{
|
|
4616
5191
|
"aria-hidden": "true",
|
|
4617
5192
|
className: `schematic-icon schematic-icon--${row.icon}`
|
|
4618
5193
|
}
|
|
4619
5194
|
) }),
|
|
4620
|
-
/* @__PURE__ */ (0,
|
|
4621
|
-
/* @__PURE__ */ (0,
|
|
4622
|
-
/* @__PURE__ */ (0,
|
|
4623
|
-
/* @__PURE__ */ (0,
|
|
4624
|
-
showDescription && row.description !== null && /* @__PURE__ */ (0,
|
|
5195
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "schematic-metered-features__body", children: [
|
|
5196
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "schematic-metered-features__top", children: [
|
|
5197
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "schematic-metered-features__title", children: [
|
|
5198
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(NameHeading, { className: "schematic-metered-features__name", children: row.name }),
|
|
5199
|
+
showDescription && row.description !== null && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "schematic-muted", children: row.description })
|
|
4625
5200
|
] }),
|
|
4626
|
-
/* @__PURE__ */ (0,
|
|
4627
|
-
showUsage && row.headline !== null && /* @__PURE__ */ (0,
|
|
4628
|
-
showAllocation && /* @__PURE__ */ (0,
|
|
5201
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "schematic-metered-features__figures", children: [
|
|
5202
|
+
showUsage && row.headline !== null && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "schematic-metered-features__headline", children: headlineText(row.headline, t) }),
|
|
5203
|
+
showAllocation && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
4629
5204
|
LimitLine,
|
|
4630
5205
|
{
|
|
4631
5206
|
row,
|
|
@@ -4635,8 +5210,8 @@ function MeteredFeatures({
|
|
|
4635
5210
|
)
|
|
4636
5211
|
] })
|
|
4637
5212
|
] }),
|
|
4638
|
-
showMeter && row.meter !== null && /* @__PURE__ */ (0,
|
|
4639
|
-
row.canAddMore && /* @__PURE__ */ (0,
|
|
5213
|
+
showMeter && row.meter !== null && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Meter, { meter: row.meter }),
|
|
5214
|
+
row.canAddMore && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
4640
5215
|
AddMore,
|
|
4641
5216
|
{
|
|
4642
5217
|
label: t("meteredFeaturesAddMore"),
|
|
@@ -4647,8 +5222,8 @@ function MeteredFeatures({
|
|
|
4647
5222
|
)
|
|
4648
5223
|
] })
|
|
4649
5224
|
] }),
|
|
4650
|
-
showUsageByUser && row.hasUsageByUser && /* @__PURE__ */ (0,
|
|
4651
|
-
row.priceDetails !== null && /* @__PURE__ */ (0,
|
|
5225
|
+
showUsageByUser && row.hasUsageByUser && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(UsageByUser, { locale, row, t }),
|
|
5226
|
+
row.priceDetails !== null && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
4652
5227
|
PriceDetails,
|
|
4653
5228
|
{
|
|
4654
5229
|
details: row.priceDetails,
|
|
@@ -4712,9 +5287,9 @@ function LimitLine({
|
|
|
4712
5287
|
if (parts.length === 0) {
|
|
4713
5288
|
return null;
|
|
4714
5289
|
}
|
|
4715
|
-
return /* @__PURE__ */ (0,
|
|
5290
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { className: "schematic-muted schematic-metered-features__limit", children: [
|
|
4716
5291
|
parts.join(" \u2022 "),
|
|
4717
|
-
showHardLimit && row.hardLimit !== null && /* @__PURE__ */ (0,
|
|
5292
|
+
showHardLimit && row.hardLimit !== null && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Tooltip, { label: t("usageHardLimitLabel"), children: t("usageHardLimit", {
|
|
4718
5293
|
amount: row.hardLimit.amount,
|
|
4719
5294
|
units: row.hardLimit.units
|
|
4720
5295
|
}) })
|
|
@@ -4728,8 +5303,8 @@ var METER_TONE_CLASS = {
|
|
|
4728
5303
|
overage: "schematic-meter--overage"
|
|
4729
5304
|
};
|
|
4730
5305
|
function Meter({ meter: meter2 }) {
|
|
4731
|
-
return /* @__PURE__ */ (0,
|
|
4732
|
-
/* @__PURE__ */ (0,
|
|
5306
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "schematic-metered-features__meter", children: [
|
|
5307
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
4733
5308
|
"div",
|
|
4734
5309
|
{
|
|
4735
5310
|
"aria-valuemax": meter2.total,
|
|
@@ -4738,7 +5313,7 @@ function Meter({ meter: meter2 }) {
|
|
|
4738
5313
|
className: cx("schematic-meter", METER_TONE_CLASS[meter2.tone]),
|
|
4739
5314
|
"data-tone": meter2.tone,
|
|
4740
5315
|
role: "meter",
|
|
4741
|
-
children: /* @__PURE__ */ (0,
|
|
5316
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
4742
5317
|
"div",
|
|
4743
5318
|
{
|
|
4744
5319
|
className: "schematic-meter__fill",
|
|
@@ -4747,7 +5322,7 @@ function Meter({ meter: meter2 }) {
|
|
|
4747
5322
|
)
|
|
4748
5323
|
}
|
|
4749
5324
|
),
|
|
4750
|
-
meter2.total > 0 && /* @__PURE__ */ (0,
|
|
5325
|
+
meter2.total > 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { className: "schematic-metered-features__meter-label", children: [
|
|
4751
5326
|
meter2.valueText,
|
|
4752
5327
|
"/",
|
|
4753
5328
|
meter2.totalText
|
|
@@ -4761,7 +5336,7 @@ function AddMore({
|
|
|
4761
5336
|
url
|
|
4762
5337
|
}) {
|
|
4763
5338
|
if (onAddMore !== void 0) {
|
|
4764
|
-
return /* @__PURE__ */ (0,
|
|
5339
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
4765
5340
|
"button",
|
|
4766
5341
|
{
|
|
4767
5342
|
className: "schematic-cta schematic-metered-features__add-more",
|
|
@@ -4772,7 +5347,7 @@ function AddMore({
|
|
|
4772
5347
|
);
|
|
4773
5348
|
}
|
|
4774
5349
|
if (url !== void 0) {
|
|
4775
|
-
return /* @__PURE__ */ (0,
|
|
5350
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
4776
5351
|
"a",
|
|
4777
5352
|
{
|
|
4778
5353
|
className: "schematic-cta schematic-metered-features__add-more",
|
|
@@ -4792,38 +5367,38 @@ function PriceDetails({
|
|
|
4792
5367
|
}) {
|
|
4793
5368
|
const period = details.period === null ? void 0 : shortPeriod(details.period, t);
|
|
4794
5369
|
if (details.kind === "overage") {
|
|
4795
|
-
return /* @__PURE__ */ (0,
|
|
4796
|
-
/* @__PURE__ */ (0,
|
|
5370
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "schematic-metered-features__price-details", children: [
|
|
5371
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { children: [
|
|
4797
5372
|
t("meteredFeaturesAdditional"),
|
|
4798
5373
|
": ",
|
|
4799
5374
|
details.unitPrice,
|
|
4800
|
-
/* @__PURE__ */ (0,
|
|
5375
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("sub", { children: [
|
|
4801
5376
|
"/",
|
|
4802
|
-
details.packageSize
|
|
5377
|
+
details.packageSize !== null && `${details.packageSize} `,
|
|
4803
5378
|
details.units,
|
|
4804
5379
|
period !== void 0 && `/${period}`
|
|
4805
5380
|
] })
|
|
4806
5381
|
] }),
|
|
4807
|
-
/* @__PURE__ */ (0,
|
|
5382
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { children: [
|
|
4808
5383
|
details.overage.amount,
|
|
4809
5384
|
" ",
|
|
4810
5385
|
details.overage.units,
|
|
4811
5386
|
" \xB7 ",
|
|
4812
5387
|
details.overage.cost,
|
|
4813
|
-
period !== void 0 && /* @__PURE__ */ (0,
|
|
5388
|
+
period !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("sub", { children: [
|
|
4814
5389
|
"/",
|
|
4815
5390
|
period
|
|
4816
5391
|
] })
|
|
4817
5392
|
] })
|
|
4818
5393
|
] });
|
|
4819
5394
|
}
|
|
4820
|
-
return /* @__PURE__ */ (0,
|
|
4821
|
-
/* @__PURE__ */ (0,
|
|
5395
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "schematic-metered-features__price-details", children: [
|
|
5396
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { children: [
|
|
4822
5397
|
t("meteredFeaturesTier"),
|
|
4823
5398
|
": ",
|
|
4824
5399
|
details.from,
|
|
4825
5400
|
details.to === null ? "+" : details.to !== details.from ? `\u2013${details.to}` : "",
|
|
4826
|
-
/* @__PURE__ */ (0,
|
|
5401
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Tooltip, { label: t("usageTieredPricingLabel"), children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
4827
5402
|
PriceTiers,
|
|
4828
5403
|
{
|
|
4829
5404
|
currency: details.tiers.currency,
|
|
@@ -4836,9 +5411,9 @@ function PriceDetails({
|
|
|
4836
5411
|
}
|
|
4837
5412
|
) })
|
|
4838
5413
|
] }),
|
|
4839
|
-
details.cost !== null && /* @__PURE__ */ (0,
|
|
5414
|
+
details.cost !== null && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { children: [
|
|
4840
5415
|
details.cost,
|
|
4841
|
-
period !== void 0 && /* @__PURE__ */ (0,
|
|
5416
|
+
period !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("sub", { children: [
|
|
4842
5417
|
"/",
|
|
4843
5418
|
period
|
|
4844
5419
|
] })
|
|
@@ -4850,8 +5425,8 @@ function UsageByUser({
|
|
|
4850
5425
|
row,
|
|
4851
5426
|
t
|
|
4852
5427
|
}) {
|
|
4853
|
-
const { data, error, refetch } = (0,
|
|
4854
|
-
return /* @__PURE__ */ (0,
|
|
5428
|
+
const { data, error, refetch } = (0, import_schematic_react5.useFeatureUserUsage)(row.featureId);
|
|
5429
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
4855
5430
|
UserBreakdown,
|
|
4856
5431
|
{
|
|
4857
5432
|
breakdown: data === void 0 ? void 0 : {
|
|
@@ -4873,21 +5448,21 @@ function UsageByUser({
|
|
|
4873
5448
|
);
|
|
4874
5449
|
}
|
|
4875
5450
|
function MeteredFeaturesSkeleton({ showHeader }) {
|
|
4876
|
-
return /* @__PURE__ */ (0,
|
|
4877
|
-
showHeader && /* @__PURE__ */ (0,
|
|
4878
|
-
[0, 1].map((index) => /* @__PURE__ */ (0,
|
|
4879
|
-
/* @__PURE__ */ (0,
|
|
4880
|
-
/* @__PURE__ */ (0,
|
|
5451
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "schematic-skeleton", children: [
|
|
5452
|
+
showHeader && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "schematic-skeleton__heading" }),
|
|
5453
|
+
[0, 1].map((index) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "schematic-skeleton__row", children: [
|
|
5454
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "name" }),
|
|
5455
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "usage" })
|
|
4881
5456
|
] }, index))
|
|
4882
5457
|
] });
|
|
4883
5458
|
}
|
|
4884
5459
|
MeteredFeatures.resources = ["featureUsage"];
|
|
4885
5460
|
|
|
4886
5461
|
// src/elements/PaymentMethods.tsx
|
|
4887
|
-
var
|
|
4888
|
-
var
|
|
4889
|
-
var
|
|
4890
|
-
var PaymentMethodForm2 = (0,
|
|
5462
|
+
var import_schematic_react7 = require("@schematichq/schematic-react");
|
|
5463
|
+
var import_react8 = require("react");
|
|
5464
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
5465
|
+
var PaymentMethodForm2 = (0, import_react8.lazy)(() => Promise.resolve().then(() => (init_PaymentMethodForm(), PaymentMethodForm_exports)));
|
|
4891
5466
|
function PaymentMethods({
|
|
4892
5467
|
allowEdit = true,
|
|
4893
5468
|
checkoutPrefill,
|
|
@@ -4908,24 +5483,24 @@ function PaymentMethods({
|
|
|
4908
5483
|
refetch,
|
|
4909
5484
|
remove,
|
|
4910
5485
|
setDefault
|
|
4911
|
-
} = (0,
|
|
5486
|
+
} = (0, import_schematic_react7.usePaymentMethods)();
|
|
4912
5487
|
const locale = useResolvedLocale(localeProp);
|
|
4913
5488
|
const t = useTranslator(strings, localeProp);
|
|
4914
|
-
const [dialog, setDialog] = (0,
|
|
4915
|
-
const [choosing, setChoosing] = (0,
|
|
4916
|
-
const [lastWrite, setLastWrite] = (0,
|
|
4917
|
-
const derived = (0,
|
|
5489
|
+
const [dialog, setDialog] = (0, import_react8.useState)(null);
|
|
5490
|
+
const [choosing, setChoosing] = (0, import_react8.useState)(false);
|
|
5491
|
+
const [lastWrite, setLastWrite] = (0, import_react8.useState)(null);
|
|
5492
|
+
const derived = (0, import_react8.useMemo)(
|
|
4918
5493
|
() => methods === void 0 ? void 0 : derivePaymentMethods(methods, { locale }),
|
|
4919
5494
|
[locale, methods]
|
|
4920
5495
|
);
|
|
4921
|
-
const write = (0,
|
|
5496
|
+
const write = (0, import_react8.useCallback)(async (next) => {
|
|
4922
5497
|
setLastWrite(next);
|
|
4923
5498
|
try {
|
|
4924
5499
|
await next.action();
|
|
4925
5500
|
} catch {
|
|
4926
5501
|
}
|
|
4927
5502
|
}, []);
|
|
4928
|
-
const saved = (0,
|
|
5503
|
+
const saved = (0, import_react8.useCallback)(
|
|
4929
5504
|
async (paymentMethodId) => {
|
|
4930
5505
|
await write({
|
|
4931
5506
|
action: () => setDefault(paymentMethodId),
|
|
@@ -4936,16 +5511,16 @@ function PaymentMethods({
|
|
|
4936
5511
|
},
|
|
4937
5512
|
[setDefault, write]
|
|
4938
5513
|
);
|
|
4939
|
-
const open = (0,
|
|
5514
|
+
const open = (0, import_react8.useCallback)(() => {
|
|
4940
5515
|
setLastWrite(null);
|
|
4941
5516
|
setChoosing(false);
|
|
4942
5517
|
setDialog("current");
|
|
4943
5518
|
}, []);
|
|
4944
|
-
const close = (0,
|
|
5519
|
+
const close = (0, import_react8.useCallback)(() => setDialog(null), []);
|
|
4945
5520
|
const Heading = `h${headingLevel}`;
|
|
4946
5521
|
const unavailable = derived === void 0 && httpStatus(error) === 404;
|
|
4947
5522
|
const errorMessage = error === void 0 ? void 0 : unavailable ? t("paymentMethodsUnavailable") : t("paymentMethodsError");
|
|
4948
|
-
return /* @__PURE__ */ (0,
|
|
5523
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
4949
5524
|
StatusFrame,
|
|
4950
5525
|
{
|
|
4951
5526
|
className: cx("schematic-card", "schematic-payment-methods", className),
|
|
@@ -4956,18 +5531,19 @@ function PaymentMethods({
|
|
|
4956
5531
|
loadingLabel: t("paymentMethodsLoading"),
|
|
4957
5532
|
onRetry: refetch,
|
|
4958
5533
|
retryText: t("retry"),
|
|
4959
|
-
skeleton: /* @__PURE__ */ (0,
|
|
4960
|
-
children: derived !== void 0 && /* @__PURE__ */ (0,
|
|
4961
|
-
showHeader && /* @__PURE__ */ (0,
|
|
5534
|
+
skeleton: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(PaymentMethodsSkeleton, { showHeader }),
|
|
5535
|
+
children: derived !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
|
|
5536
|
+
showHeader && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
4962
5537
|
PaymentMethodsHeader,
|
|
4963
5538
|
{
|
|
4964
5539
|
derived,
|
|
4965
5540
|
heading: Heading,
|
|
5541
|
+
locale,
|
|
4966
5542
|
showExpiration,
|
|
4967
5543
|
t
|
|
4968
5544
|
}
|
|
4969
5545
|
),
|
|
4970
|
-
/* @__PURE__ */ (0,
|
|
5546
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(MethodPill, { row: derived.current, t, children: allowEdit && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
4971
5547
|
"button",
|
|
4972
5548
|
{
|
|
4973
5549
|
className: "schematic-link-button schematic-payment-methods__edit",
|
|
@@ -4976,7 +5552,7 @@ function PaymentMethods({
|
|
|
4976
5552
|
children: derived.current === null ? t("paymentMethodsAdd") : t("paymentMethodsEdit")
|
|
4977
5553
|
}
|
|
4978
5554
|
) }),
|
|
4979
|
-
dialog !== null && /* @__PURE__ */ (0,
|
|
5555
|
+
dialog !== null && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
4980
5556
|
PaymentMethodsDialog,
|
|
4981
5557
|
{
|
|
4982
5558
|
checkoutPrefill,
|
|
@@ -5028,7 +5604,7 @@ function PaymentMethodsDialog({
|
|
|
5028
5604
|
const { current, others, rows } = derived;
|
|
5029
5605
|
const hasMethods = rows.length > 0;
|
|
5030
5606
|
const showForm = view === "add" || !hasMethods;
|
|
5031
|
-
return /* @__PURE__ */ (0,
|
|
5607
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
5032
5608
|
Dialog,
|
|
5033
5609
|
{
|
|
5034
5610
|
className: "schematic-payment-methods__dialog",
|
|
@@ -5037,11 +5613,11 @@ function PaymentMethodsDialog({
|
|
|
5037
5613
|
title: t("paymentMethodsDialogTitle"),
|
|
5038
5614
|
onClose,
|
|
5039
5615
|
children: [
|
|
5040
|
-
showForm ? /* @__PURE__ */ (0,
|
|
5041
|
-
|
|
5616
|
+
showForm ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
5617
|
+
import_react8.Suspense,
|
|
5042
5618
|
{
|
|
5043
|
-
fallback: /* @__PURE__ */ (0,
|
|
5044
|
-
children: /* @__PURE__ */ (0,
|
|
5619
|
+
fallback: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(FormSkeleton, { label: t("paymentMethodsFormLoading") }),
|
|
5620
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
5045
5621
|
PaymentMethodForm2,
|
|
5046
5622
|
{
|
|
5047
5623
|
checkoutPrefill,
|
|
@@ -5053,17 +5629,18 @@ function PaymentMethodsDialog({
|
|
|
5053
5629
|
}
|
|
5054
5630
|
)
|
|
5055
5631
|
}
|
|
5056
|
-
) : /* @__PURE__ */ (0,
|
|
5057
|
-
/* @__PURE__ */ (0,
|
|
5632
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
|
|
5633
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
5058
5634
|
PaymentMethodsHeader,
|
|
5059
5635
|
{
|
|
5060
5636
|
derived,
|
|
5061
5637
|
heading: "h3",
|
|
5638
|
+
locale,
|
|
5062
5639
|
showExpiration: true,
|
|
5063
5640
|
t
|
|
5064
5641
|
}
|
|
5065
5642
|
),
|
|
5066
|
-
/* @__PURE__ */ (0,
|
|
5643
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(MethodPill, { row: current, t, children: current?.canRemove === true && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
5067
5644
|
"button",
|
|
5068
5645
|
{
|
|
5069
5646
|
className: "schematic-link-button schematic-payment-methods__remove-current",
|
|
@@ -5073,7 +5650,7 @@ function PaymentMethodsDialog({
|
|
|
5073
5650
|
children: t("paymentMethodsRemove")
|
|
5074
5651
|
}
|
|
5075
5652
|
) }),
|
|
5076
|
-
/* @__PURE__ */ (0,
|
|
5653
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
5077
5654
|
"button",
|
|
5078
5655
|
{
|
|
5079
5656
|
"aria-expanded": choosing,
|
|
@@ -5081,8 +5658,8 @@ function PaymentMethodsDialog({
|
|
|
5081
5658
|
type: "button",
|
|
5082
5659
|
onClick: onChoose,
|
|
5083
5660
|
children: [
|
|
5084
|
-
/* @__PURE__ */ (0,
|
|
5085
|
-
/* @__PURE__ */ (0,
|
|
5661
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "schematic-payment-methods__choose-label", children: t("paymentMethodsChooseDifferent") }),
|
|
5662
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
5086
5663
|
"i",
|
|
5087
5664
|
{
|
|
5088
5665
|
"aria-hidden": "true",
|
|
@@ -5097,13 +5674,13 @@ function PaymentMethodsDialog({
|
|
|
5097
5674
|
]
|
|
5098
5675
|
}
|
|
5099
5676
|
),
|
|
5100
|
-
choosing && /* @__PURE__ */ (0,
|
|
5101
|
-
others.length > 0 && /* @__PURE__ */ (0,
|
|
5677
|
+
choosing && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
|
|
5678
|
+
others.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
5102
5679
|
"ul",
|
|
5103
5680
|
{
|
|
5104
5681
|
"aria-label": t("paymentMethodsChooseDifferent"),
|
|
5105
5682
|
className: "schematic-payment-methods__list",
|
|
5106
|
-
children: others.map((row) => /* @__PURE__ */ (0,
|
|
5683
|
+
children: others.map((row) => /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
5107
5684
|
"li",
|
|
5108
5685
|
{
|
|
5109
5686
|
className: "schematic-payment-methods__row",
|
|
@@ -5111,11 +5688,11 @@ function PaymentMethodsDialog({
|
|
|
5111
5688
|
"data-kind": row.kind,
|
|
5112
5689
|
"data-testid": "schematic-payment-method",
|
|
5113
5690
|
children: [
|
|
5114
|
-
/* @__PURE__ */ (0,
|
|
5115
|
-
row.expiresShort !== null && /* @__PURE__ */ (0,
|
|
5691
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Method, { row, t }),
|
|
5692
|
+
row.expiresShort !== null && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "schematic-payment-methods__expires", children: t("paymentMethodsExpires", {
|
|
5116
5693
|
date: row.expiresShort
|
|
5117
5694
|
}) }),
|
|
5118
|
-
/* @__PURE__ */ (0,
|
|
5695
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
5119
5696
|
"button",
|
|
5120
5697
|
{
|
|
5121
5698
|
className: "schematic-link-button schematic-payment-methods__set-default",
|
|
@@ -5125,7 +5702,7 @@ function PaymentMethodsDialog({
|
|
|
5125
5702
|
children: t("paymentMethodsSetDefault")
|
|
5126
5703
|
}
|
|
5127
5704
|
),
|
|
5128
|
-
row.canRemove && /* @__PURE__ */ (0,
|
|
5705
|
+
row.canRemove && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
5129
5706
|
"button",
|
|
5130
5707
|
{
|
|
5131
5708
|
"aria-label": t("paymentMethodsRemove"),
|
|
@@ -5133,7 +5710,7 @@ function PaymentMethodsDialog({
|
|
|
5133
5710
|
disabled: isMutating,
|
|
5134
5711
|
type: "button",
|
|
5135
5712
|
onClick: () => onRemove(row),
|
|
5136
|
-
children: /* @__PURE__ */ (0,
|
|
5713
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
5137
5714
|
"i",
|
|
5138
5715
|
{
|
|
5139
5716
|
"aria-hidden": "true",
|
|
@@ -5148,7 +5725,7 @@ function PaymentMethodsDialog({
|
|
|
5148
5725
|
))
|
|
5149
5726
|
}
|
|
5150
5727
|
),
|
|
5151
|
-
/* @__PURE__ */ (0,
|
|
5728
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
5152
5729
|
"button",
|
|
5153
5730
|
{
|
|
5154
5731
|
className: "schematic-cta schematic-payment-methods__add-new",
|
|
@@ -5160,14 +5737,14 @@ function PaymentMethodsDialog({
|
|
|
5160
5737
|
)
|
|
5161
5738
|
] })
|
|
5162
5739
|
] }),
|
|
5163
|
-
mutationError !== void 0 && /* @__PURE__ */ (0,
|
|
5740
|
+
mutationError !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
5164
5741
|
"p",
|
|
5165
5742
|
{
|
|
5166
5743
|
className: "schematic-status-note schematic-error schematic-payment-methods__error",
|
|
5167
5744
|
role: "alert",
|
|
5168
5745
|
children: [
|
|
5169
|
-
/* @__PURE__ */ (0,
|
|
5170
|
-
onRetry !== void 0 && /* @__PURE__ */ (0,
|
|
5746
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "schematic-payment-methods__error-message", children: mutationError }),
|
|
5747
|
+
onRetry !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
5171
5748
|
"button",
|
|
5172
5749
|
{
|
|
5173
5750
|
className: "schematic-cta schematic-cta--small schematic-cta--ghost schematic-payment-methods__error-retry",
|
|
@@ -5187,17 +5764,18 @@ function PaymentMethodsDialog({
|
|
|
5187
5764
|
function PaymentMethodsHeader({
|
|
5188
5765
|
derived,
|
|
5189
5766
|
heading: Heading,
|
|
5767
|
+
locale,
|
|
5190
5768
|
showExpiration,
|
|
5191
5769
|
t
|
|
5192
5770
|
}) {
|
|
5193
|
-
return /* @__PURE__ */ (0,
|
|
5194
|
-
/* @__PURE__ */ (0,
|
|
5195
|
-
showExpiration && derived.expiryWarning !== "none" && /* @__PURE__ */ (0,
|
|
5771
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "schematic-header", children: [
|
|
5772
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Heading, { className: "schematic-header__title", children: t("paymentMethodsHeader") }),
|
|
5773
|
+
showExpiration && derived.expiryWarning !== "none" && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
5196
5774
|
"span",
|
|
5197
5775
|
{
|
|
5198
5776
|
className: "schematic-small schematic-payment-methods__expiry-warning",
|
|
5199
5777
|
"data-expiry": derived.expiryWarning,
|
|
5200
|
-
children: expiryWarningText(derived, t)
|
|
5778
|
+
children: expiryWarningText(derived, locale, t)
|
|
5201
5779
|
}
|
|
5202
5780
|
)
|
|
5203
5781
|
] });
|
|
@@ -5207,37 +5785,37 @@ function MethodPill({
|
|
|
5207
5785
|
row,
|
|
5208
5786
|
t
|
|
5209
5787
|
}) {
|
|
5210
|
-
return /* @__PURE__ */ (0,
|
|
5788
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
5211
5789
|
"div",
|
|
5212
5790
|
{
|
|
5213
5791
|
className: "schematic-payment-methods__current",
|
|
5214
5792
|
"data-testid": "schematic-payment-method-current",
|
|
5215
5793
|
children: [
|
|
5216
|
-
row === null ? /* @__PURE__ */ (0,
|
|
5794
|
+
row === null ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "schematic-payment-methods__empty", children: t("paymentMethodsEmpty") }) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Method, { row, t }),
|
|
5217
5795
|
children
|
|
5218
5796
|
]
|
|
5219
5797
|
}
|
|
5220
5798
|
);
|
|
5221
5799
|
}
|
|
5222
5800
|
function Method({ row, t }) {
|
|
5223
|
-
return /* @__PURE__ */ (0,
|
|
5801
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
5224
5802
|
"span",
|
|
5225
5803
|
{
|
|
5226
5804
|
className: "schematic-payment-methods__method",
|
|
5227
5805
|
"data-brand": row.brand,
|
|
5228
5806
|
"data-kind": row.kind,
|
|
5229
5807
|
children: [
|
|
5230
|
-
/* @__PURE__ */ (0,
|
|
5808
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
5231
5809
|
"i",
|
|
5232
5810
|
{
|
|
5233
5811
|
"aria-hidden": "true",
|
|
5234
5812
|
className: `schematic-icon schematic-icon--${row.icon} schematic-payment-methods__icon`
|
|
5235
5813
|
}
|
|
5236
5814
|
),
|
|
5237
|
-
/* @__PURE__ */ (0,
|
|
5238
|
-
row.last4 !== null && /* @__PURE__ */ (0,
|
|
5815
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "schematic-payment-methods__label", children: labelText(row.label, t) }),
|
|
5816
|
+
row.last4 !== null && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
|
|
5239
5817
|
" ",
|
|
5240
|
-
/* @__PURE__ */ (0,
|
|
5818
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "schematic-payment-methods__last4", children: row.last4 })
|
|
5241
5819
|
] })
|
|
5242
5820
|
]
|
|
5243
5821
|
}
|
|
@@ -5246,29 +5824,31 @@ function Method({ row, t }) {
|
|
|
5246
5824
|
function labelText(label, t) {
|
|
5247
5825
|
return label.key === void 0 ? label.text : t(label.key);
|
|
5248
5826
|
}
|
|
5249
|
-
function expiryWarningText(derived, t) {
|
|
5827
|
+
function expiryWarningText(derived, locale, t) {
|
|
5250
5828
|
const months = derived.monthsToExpiration ?? 0;
|
|
5251
|
-
return derived.expiryWarning === "expired" ? t("paymentMethodsExpired") : t("paymentMethodsExpiresInMonths", {
|
|
5829
|
+
return derived.expiryWarning === "expired" ? t("paymentMethodsExpired") : t("paymentMethodsExpiresInMonths", {
|
|
5830
|
+
months: formatNumber(months, locale)
|
|
5831
|
+
});
|
|
5252
5832
|
}
|
|
5253
5833
|
function PaymentMethodsSkeleton({ showHeader }) {
|
|
5254
|
-
return /* @__PURE__ */ (0,
|
|
5255
|
-
showHeader && /* @__PURE__ */ (0,
|
|
5256
|
-
/* @__PURE__ */ (0,
|
|
5257
|
-
/* @__PURE__ */ (0,
|
|
5258
|
-
/* @__PURE__ */ (0,
|
|
5834
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "schematic-skeleton", children: [
|
|
5835
|
+
showHeader && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "schematic-skeleton__heading" }),
|
|
5836
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "schematic-skeleton__row", children: [
|
|
5837
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "method" }),
|
|
5838
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "action" })
|
|
5259
5839
|
] })
|
|
5260
5840
|
] });
|
|
5261
5841
|
}
|
|
5262
5842
|
function FormSkeleton({ label }) {
|
|
5263
|
-
return /* @__PURE__ */ (0,
|
|
5843
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
5264
5844
|
"div",
|
|
5265
5845
|
{
|
|
5266
5846
|
"aria-busy": "true",
|
|
5267
5847
|
className: "schematic-payment-methods__form",
|
|
5268
5848
|
"data-state": "pending",
|
|
5269
5849
|
children: [
|
|
5270
|
-
/* @__PURE__ */ (0,
|
|
5271
|
-
/* @__PURE__ */ (0,
|
|
5850
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "schematic-hidden", children: label }),
|
|
5851
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "schematic-skeleton", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "field" }) }) })
|
|
5272
5852
|
]
|
|
5273
5853
|
}
|
|
5274
5854
|
);
|
|
@@ -5276,9 +5856,9 @@ function FormSkeleton({ label }) {
|
|
|
5276
5856
|
PaymentMethods.resources = ["paymentMethods"];
|
|
5277
5857
|
|
|
5278
5858
|
// src/elements/UpcomingBill.tsx
|
|
5279
|
-
var
|
|
5280
|
-
var
|
|
5281
|
-
var
|
|
5859
|
+
var import_schematic_react8 = require("@schematichq/schematic-react");
|
|
5860
|
+
var import_react9 = require("react");
|
|
5861
|
+
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
5282
5862
|
function UpcomingBill({
|
|
5283
5863
|
className,
|
|
5284
5864
|
headingLevel = 2,
|
|
@@ -5289,10 +5869,10 @@ function UpcomingBill({
|
|
|
5289
5869
|
showHeader = true,
|
|
5290
5870
|
strings
|
|
5291
5871
|
}) {
|
|
5292
|
-
const { data: invoice, error, isPending, refetch } = (0,
|
|
5872
|
+
const { data: invoice, error, isPending, refetch } = (0, import_schematic_react8.useUpcomingInvoice)();
|
|
5293
5873
|
const locale = useResolvedLocale(localeProp);
|
|
5294
5874
|
const t = useTranslator(strings, localeProp);
|
|
5295
|
-
const bill = (0,
|
|
5875
|
+
const bill = (0, import_react9.useMemo)(
|
|
5296
5876
|
() => invoice === void 0 || invoice === null ? null : deriveUpcomingInvoice(invoice, { locale }),
|
|
5297
5877
|
[invoice, locale]
|
|
5298
5878
|
);
|
|
@@ -5301,7 +5881,7 @@ function UpcomingBill({
|
|
|
5301
5881
|
const discountRow = showDiscounts && bill !== null && bill.discounts.length > 0;
|
|
5302
5882
|
const unavailable = invoice === void 0 && httpStatus(error) === 404;
|
|
5303
5883
|
const errorMessage = error === void 0 ? void 0 : unavailable ? t("upcomingBillUnavailable") : t("upcomingBillError");
|
|
5304
|
-
return /* @__PURE__ */ (0,
|
|
5884
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
5305
5885
|
StatusFrame,
|
|
5306
5886
|
{
|
|
5307
5887
|
className: cx("schematic-card", "schematic-upcoming-bill", className),
|
|
@@ -5312,11 +5892,11 @@ function UpcomingBill({
|
|
|
5312
5892
|
loadingLabel: t("upcomingBillLoading"),
|
|
5313
5893
|
onRetry: refetch,
|
|
5314
5894
|
retryText: t("retry"),
|
|
5315
|
-
skeleton: /* @__PURE__ */ (0,
|
|
5316
|
-
children: bill === null ? invoice !== void 0 && /* @__PURE__ */ (0,
|
|
5317
|
-
showHeader && bill.dueAt !== null && /* @__PURE__ */ (0,
|
|
5318
|
-
showAmount && /* @__PURE__ */ (0,
|
|
5319
|
-
/* @__PURE__ */ (0,
|
|
5895
|
+
skeleton: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(UpcomingBillSkeleton, { showHeader }),
|
|
5896
|
+
children: bill === null ? invoice !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("p", { className: "schematic-muted schematic-upcoming-bill__empty", children: t("upcomingBillEmpty") }) : /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_jsx_runtime10.Fragment, { children: [
|
|
5897
|
+
showHeader && bill.dueAt !== null && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "schematic-header", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Heading, { className: "schematic-header__title", children: t("upcomingBillHeader", { date: bill.dueAt.text }) }) }),
|
|
5898
|
+
showAmount && /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "schematic-upcoming-bill__amount", children: [
|
|
5899
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
5320
5900
|
"span",
|
|
5321
5901
|
{
|
|
5322
5902
|
className: "schematic-upcoming-bill__total",
|
|
@@ -5324,46 +5904,46 @@ function UpcomingBill({
|
|
|
5324
5904
|
children: bill.amountDueText
|
|
5325
5905
|
}
|
|
5326
5906
|
),
|
|
5327
|
-
/* @__PURE__ */ (0,
|
|
5907
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: "schematic-small schematic-upcoming-bill__estimate", children: t("upcomingBillEstimate") })
|
|
5328
5908
|
] }),
|
|
5329
|
-
(balanceRows || discountRow) && /* @__PURE__ */ (0,
|
|
5330
|
-
balanceRows && bill.balanceApplied !== null && /* @__PURE__ */ (0,
|
|
5909
|
+
(balanceRows || discountRow) && /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "schematic-upcoming-bill__rows", children: [
|
|
5910
|
+
balanceRows && bill.balanceApplied !== null && /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
|
|
5331
5911
|
"div",
|
|
5332
5912
|
{
|
|
5333
5913
|
className: "schematic-row schematic-upcoming-bill__balance-applied",
|
|
5334
5914
|
"data-testid": "schematic-balance-applied",
|
|
5335
5915
|
children: [
|
|
5336
|
-
/* @__PURE__ */ (0,
|
|
5337
|
-
/* @__PURE__ */ (0,
|
|
5916
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: "schematic-row__label", children: t("upcomingBillBalanceApplied") }),
|
|
5917
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: "schematic-row__value", children: bill.balanceApplied.amountText })
|
|
5338
5918
|
]
|
|
5339
5919
|
}
|
|
5340
5920
|
),
|
|
5341
|
-
balanceRows && bill.balanceRemaining !== null && /* @__PURE__ */ (0,
|
|
5921
|
+
balanceRows && bill.balanceRemaining !== null && /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
|
|
5342
5922
|
"div",
|
|
5343
5923
|
{
|
|
5344
5924
|
className: "schematic-row schematic-upcoming-bill__balance-remaining",
|
|
5345
5925
|
"data-testid": "schematic-balance-remaining",
|
|
5346
5926
|
children: [
|
|
5347
|
-
/* @__PURE__ */ (0,
|
|
5348
|
-
/* @__PURE__ */ (0,
|
|
5927
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: "schematic-row__label", children: t("upcomingBillBalanceRemaining") }),
|
|
5928
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: "schematic-row__value", children: bill.balanceRemaining.amountText })
|
|
5349
5929
|
]
|
|
5350
5930
|
}
|
|
5351
5931
|
),
|
|
5352
|
-
discountRow && /* @__PURE__ */ (0,
|
|
5932
|
+
discountRow && /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
|
|
5353
5933
|
"div",
|
|
5354
5934
|
{
|
|
5355
5935
|
className: "schematic-row schematic-upcoming-bill__discount-row",
|
|
5356
5936
|
"data-testid": "schematic-discounts",
|
|
5357
5937
|
children: [
|
|
5358
|
-
/* @__PURE__ */ (0,
|
|
5359
|
-
/* @__PURE__ */ (0,
|
|
5938
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: "schematic-row__label", children: t("upcomingBillDiscount") }),
|
|
5939
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("ul", { className: "schematic-row__value schematic-upcoming-bill__discounts", children: bill.discounts.map((discount, index) => /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
|
|
5360
5940
|
"li",
|
|
5361
5941
|
{
|
|
5362
5942
|
className: "schematic-upcoming-bill__discount",
|
|
5363
5943
|
"data-testid": "schematic-discount",
|
|
5364
5944
|
children: [
|
|
5365
|
-
discount.code !== null && /* @__PURE__ */ (0,
|
|
5366
|
-
/* @__PURE__ */ (0,
|
|
5945
|
+
discount.code !== null && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: "schematic-chip schematic-upcoming-bill__code", children: discount.code }),
|
|
5946
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: "schematic-upcoming-bill__discount-value", children: discountText(discount, t) })
|
|
5367
5947
|
]
|
|
5368
5948
|
},
|
|
5369
5949
|
`${discount.couponName}-${index}`
|
|
@@ -5377,10 +5957,10 @@ function UpcomingBill({
|
|
|
5377
5957
|
);
|
|
5378
5958
|
}
|
|
5379
5959
|
function UpcomingBillSkeleton({ showHeader }) {
|
|
5380
|
-
return /* @__PURE__ */ (0,
|
|
5381
|
-
showHeader && /* @__PURE__ */ (0,
|
|
5382
|
-
/* @__PURE__ */ (0,
|
|
5383
|
-
/* @__PURE__ */ (0,
|
|
5960
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "schematic-skeleton", children: [
|
|
5961
|
+
showHeader && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "schematic-skeleton__heading" }),
|
|
5962
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "amount" }) }),
|
|
5963
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "row" }) })
|
|
5384
5964
|
] });
|
|
5385
5965
|
}
|
|
5386
5966
|
function discountText(discount, t) {
|