@schematichq/schematic-components 1.4.2 → 1.4.3
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.cjs.js +246 -103
- package/dist/schematic-components.d.ts +69 -0
- package/dist/schematic-components.esm.js +246 -103
- package/package.json +14 -14
|
@@ -1918,7 +1918,7 @@ var HOURS_IN_MS = MINUTES_IN_MS * 60;
|
|
|
1918
1918
|
var DAYS_IN_MS = HOURS_IN_MS * 24;
|
|
1919
1919
|
|
|
1920
1920
|
// src/const/debounce.ts
|
|
1921
|
-
var
|
|
1921
|
+
var DEBOUNCE_SETTINGS = {
|
|
1922
1922
|
leading: true,
|
|
1923
1923
|
trailing: false
|
|
1924
1924
|
};
|
|
@@ -4273,6 +4273,7 @@ var initialContext = {
|
|
|
4273
4273
|
hydrateComponent: stub,
|
|
4274
4274
|
hydrateExternal: stub,
|
|
4275
4275
|
getUpcomingInvoice: stub,
|
|
4276
|
+
getCustomerBalance: stub,
|
|
4276
4277
|
listInvoices: stub,
|
|
4277
4278
|
createSetupIntent: stub,
|
|
4278
4279
|
updatePaymentMethod: stub,
|
|
@@ -4285,7 +4286,8 @@ var initialContext = {
|
|
|
4285
4286
|
setLayout: stub,
|
|
4286
4287
|
setCheckoutState: stub,
|
|
4287
4288
|
setData: stub,
|
|
4288
|
-
updateSettings: stub
|
|
4289
|
+
updateSettings: stub,
|
|
4290
|
+
debug: stub
|
|
4289
4291
|
};
|
|
4290
4292
|
var EmbedContext = (0, import_react3.createContext)(initialContext);
|
|
4291
4293
|
|
|
@@ -6779,8 +6781,10 @@ var en_default = {
|
|
|
6779
6781
|
"Choose add-on": "Choose add-on",
|
|
6780
6782
|
"Choose plan": "Choose plan",
|
|
6781
6783
|
"Choose your base plan": "Choose your base plan",
|
|
6782
|
-
"
|
|
6784
|
+
"Credit bundles": "Credit bundles",
|
|
6783
6785
|
Credits: "Credits",
|
|
6786
|
+
"Credits in plan": "Credits in plan",
|
|
6787
|
+
"Credits to be applied to future invoices": "Credits to be applied to future invoices",
|
|
6784
6788
|
"Current plan": "Current plan",
|
|
6785
6789
|
"Current usage exceeds the limit of this plan.": "Current usage exceeds the limit of this plan.",
|
|
6786
6790
|
"Currently using": "Currently using {{quantity}} {{unit}}",
|
|
@@ -6831,8 +6835,10 @@ var en_default = {
|
|
|
6831
6835
|
"Please provide an access token.": "Please provide an access token.",
|
|
6832
6836
|
"Powered by": "Powered by",
|
|
6833
6837
|
"Price by unit based on final tier reached.": "Price by unit based on final tier reached.",
|
|
6838
|
+
"Promotional credits": "Promotional credits",
|
|
6834
6839
|
Proration: "Proration",
|
|
6835
6840
|
"Quantity to pay for in advance": "Quantity to pay for in advance",
|
|
6841
|
+
"Remaining balance": "Remaining balance",
|
|
6836
6842
|
"Remove add-on": "Remove add-on",
|
|
6837
6843
|
Resets: "Resets {{date}}",
|
|
6838
6844
|
"Save payment method": "Save payment method",
|
|
@@ -10521,7 +10527,7 @@ var EmbedProvider = ({
|
|
|
10521
10527
|
});
|
|
10522
10528
|
const customHeaders = (0, import_react12.useMemo)(
|
|
10523
10529
|
() => ({
|
|
10524
|
-
"X-Schematic-Components-Version": "1.4.
|
|
10530
|
+
"X-Schematic-Components-Version": "1.4.3",
|
|
10525
10531
|
"X-Schematic-Session-ID": sessionIdRef.current
|
|
10526
10532
|
}),
|
|
10527
10533
|
[]
|
|
@@ -10554,7 +10560,7 @@ var EmbedProvider = ({
|
|
|
10554
10560
|
}
|
|
10555
10561
|
}, [api.public]);
|
|
10556
10562
|
const debouncedHydratePublic = (0, import_react12.useMemo)(
|
|
10557
|
-
() => (0, import_debounce.default)(hydratePublic, FETCH_DEBOUNCE_TIMEOUT,
|
|
10563
|
+
() => (0, import_debounce.default)(hydratePublic, FETCH_DEBOUNCE_TIMEOUT, DEBOUNCE_SETTINGS),
|
|
10558
10564
|
[hydratePublic]
|
|
10559
10565
|
);
|
|
10560
10566
|
const hydrate = (0, import_react12.useCallback)(async () => {
|
|
@@ -10576,7 +10582,7 @@ var EmbedProvider = ({
|
|
|
10576
10582
|
}
|
|
10577
10583
|
}, [api.checkout]);
|
|
10578
10584
|
const debouncedHydrate = (0, import_react12.useMemo)(
|
|
10579
|
-
() => (0, import_debounce.default)(hydrate, FETCH_DEBOUNCE_TIMEOUT,
|
|
10585
|
+
() => (0, import_debounce.default)(hydrate, FETCH_DEBOUNCE_TIMEOUT, DEBOUNCE_SETTINGS),
|
|
10580
10586
|
[hydrate]
|
|
10581
10587
|
);
|
|
10582
10588
|
const hydrateComponent = (0, import_react12.useCallback)(
|
|
@@ -10603,7 +10609,7 @@ var EmbedProvider = ({
|
|
|
10603
10609
|
[api.checkout]
|
|
10604
10610
|
);
|
|
10605
10611
|
const debouncedHydrateComponent = (0, import_react12.useMemo)(
|
|
10606
|
-
() => (0, import_debounce.default)(hydrateComponent, FETCH_DEBOUNCE_TIMEOUT,
|
|
10612
|
+
() => (0, import_debounce.default)(hydrateComponent, FETCH_DEBOUNCE_TIMEOUT, DEBOUNCE_SETTINGS),
|
|
10607
10613
|
[hydrateComponent]
|
|
10608
10614
|
);
|
|
10609
10615
|
const hydrateExternal = (0, import_react12.useCallback)(async function(fn) {
|
|
@@ -10623,14 +10629,14 @@ var EmbedProvider = ({
|
|
|
10623
10629
|
}
|
|
10624
10630
|
}, []);
|
|
10625
10631
|
const debouncedHydrateExternal = (0, import_react12.useMemo)(
|
|
10626
|
-
() => (0, import_debounce.default)(hydrateExternal, FETCH_DEBOUNCE_TIMEOUT,
|
|
10632
|
+
() => (0, import_debounce.default)(hydrateExternal, FETCH_DEBOUNCE_TIMEOUT, DEBOUNCE_SETTINGS),
|
|
10627
10633
|
[hydrateExternal]
|
|
10628
10634
|
);
|
|
10629
10635
|
const createSetupIntent = (0, import_react12.useCallback)(async () => {
|
|
10630
10636
|
return api.checkout?.createSetupIntent();
|
|
10631
10637
|
}, [api.checkout]);
|
|
10632
10638
|
const debouncedCreateSetupIntent = (0, import_react12.useMemo)(
|
|
10633
|
-
() => (0, import_debounce.default)(createSetupIntent, FETCH_DEBOUNCE_TIMEOUT,
|
|
10639
|
+
() => (0, import_debounce.default)(createSetupIntent, FETCH_DEBOUNCE_TIMEOUT, DEBOUNCE_SETTINGS),
|
|
10634
10640
|
[createSetupIntent]
|
|
10635
10641
|
);
|
|
10636
10642
|
const updatePaymentMethod = (0, import_react12.useCallback)(
|
|
@@ -10649,7 +10655,7 @@ var EmbedProvider = ({
|
|
|
10649
10655
|
[api.checkout]
|
|
10650
10656
|
);
|
|
10651
10657
|
const debouncedUpdatePaymentMethod = (0, import_react12.useMemo)(
|
|
10652
|
-
() => (0, import_debounce.default)(updatePaymentMethod, FETCH_DEBOUNCE_TIMEOUT,
|
|
10658
|
+
() => (0, import_debounce.default)(updatePaymentMethod, FETCH_DEBOUNCE_TIMEOUT, DEBOUNCE_SETTINGS),
|
|
10653
10659
|
[updatePaymentMethod]
|
|
10654
10660
|
);
|
|
10655
10661
|
const deletePaymentMethod = (0, import_react12.useCallback)(
|
|
@@ -10668,7 +10674,7 @@ var EmbedProvider = ({
|
|
|
10668
10674
|
[api.checkout]
|
|
10669
10675
|
);
|
|
10670
10676
|
const debouncedDeletePaymentMethod = (0, import_react12.useMemo)(
|
|
10671
|
-
() => (0, import_debounce.default)(deletePaymentMethod, FETCH_DEBOUNCE_TIMEOUT,
|
|
10677
|
+
() => (0, import_debounce.default)(deletePaymentMethod, FETCH_DEBOUNCE_TIMEOUT, DEBOUNCE_SETTINGS),
|
|
10672
10678
|
[deletePaymentMethod]
|
|
10673
10679
|
);
|
|
10674
10680
|
const checkout = (0, import_react12.useCallback)(
|
|
@@ -10687,7 +10693,7 @@ var EmbedProvider = ({
|
|
|
10687
10693
|
[api.checkout]
|
|
10688
10694
|
);
|
|
10689
10695
|
const debouncedCheckout = (0, import_react12.useMemo)(
|
|
10690
|
-
() => (0, import_debounce.default)(checkout, FETCH_DEBOUNCE_TIMEOUT,
|
|
10696
|
+
() => (0, import_debounce.default)(checkout, FETCH_DEBOUNCE_TIMEOUT, DEBOUNCE_SETTINGS),
|
|
10691
10697
|
[checkout]
|
|
10692
10698
|
);
|
|
10693
10699
|
const previewCheckout = (0, import_react12.useCallback)(
|
|
@@ -10697,7 +10703,12 @@ var EmbedProvider = ({
|
|
|
10697
10703
|
[api.checkout]
|
|
10698
10704
|
);
|
|
10699
10705
|
const debouncedPreviewCheckout = (0, import_react12.useMemo)(
|
|
10700
|
-
() => (0, import_debounce.default)(previewCheckout, FETCH_DEBOUNCE_TIMEOUT,
|
|
10706
|
+
() => (0, import_debounce.default)(previewCheckout, FETCH_DEBOUNCE_TIMEOUT, {
|
|
10707
|
+
// invoke immediately for minimal latency
|
|
10708
|
+
leading: true,
|
|
10709
|
+
// but also ensure latest data is fetched
|
|
10710
|
+
trailing: true
|
|
10711
|
+
}),
|
|
10701
10712
|
[previewCheckout]
|
|
10702
10713
|
);
|
|
10703
10714
|
const unsubscribe = (0, import_react12.useCallback)(async () => {
|
|
@@ -10711,7 +10722,7 @@ var EmbedProvider = ({
|
|
|
10711
10722
|
return response;
|
|
10712
10723
|
}, [api.checkout]);
|
|
10713
10724
|
const debouncedUnsubscribe = (0, import_react12.useMemo)(
|
|
10714
|
-
() => (0, import_debounce.default)(unsubscribe, FETCH_DEBOUNCE_TIMEOUT,
|
|
10725
|
+
() => (0, import_debounce.default)(unsubscribe, FETCH_DEBOUNCE_TIMEOUT, DEBOUNCE_SETTINGS),
|
|
10715
10726
|
[unsubscribe]
|
|
10716
10727
|
);
|
|
10717
10728
|
const getUpcomingInvoice = (0, import_react12.useCallback)(
|
|
@@ -10723,19 +10734,30 @@ var EmbedProvider = ({
|
|
|
10723
10734
|
[api.checkout]
|
|
10724
10735
|
);
|
|
10725
10736
|
const debouncedGetUpcomingInvoice = (0, import_react12.useMemo)(
|
|
10726
|
-
() => (0, import_debounce.default)(getUpcomingInvoice, FETCH_DEBOUNCE_TIMEOUT,
|
|
10737
|
+
() => (0, import_debounce.default)(getUpcomingInvoice, FETCH_DEBOUNCE_TIMEOUT, DEBOUNCE_SETTINGS),
|
|
10727
10738
|
[getUpcomingInvoice]
|
|
10728
10739
|
);
|
|
10740
|
+
const getCustomerBalance = (0, import_react12.useCallback)(async () => {
|
|
10741
|
+
return api.checkout?.fetchCustomerBalance();
|
|
10742
|
+
}, [api.checkout]);
|
|
10743
|
+
const debouncedGetCustomerBalance = (0, import_react12.useMemo)(
|
|
10744
|
+
() => (0, import_debounce.default)(getCustomerBalance, FETCH_DEBOUNCE_TIMEOUT, DEBOUNCE_SETTINGS),
|
|
10745
|
+
[getCustomerBalance]
|
|
10746
|
+
);
|
|
10729
10747
|
const listInvoices = (0, import_react12.useCallback)(async () => {
|
|
10730
10748
|
return api.checkout?.listInvoices();
|
|
10731
10749
|
}, [api.checkout]);
|
|
10732
10750
|
const debouncedListInvoices = (0, import_react12.useMemo)(
|
|
10733
|
-
() => (0, import_debounce.default)(listInvoices, FETCH_DEBOUNCE_TIMEOUT,
|
|
10751
|
+
() => (0, import_debounce.default)(listInvoices, FETCH_DEBOUNCE_TIMEOUT, DEBOUNCE_SETTINGS),
|
|
10734
10752
|
[listInvoices]
|
|
10735
10753
|
);
|
|
10736
|
-
const setError = (0, import_react12.useCallback)(
|
|
10737
|
-
|
|
10738
|
-
|
|
10754
|
+
const setError = (0, import_react12.useCallback)(
|
|
10755
|
+
(error) => {
|
|
10756
|
+
debug(error.message);
|
|
10757
|
+
dispatch({ type: "ERROR", error });
|
|
10758
|
+
},
|
|
10759
|
+
[debug]
|
|
10760
|
+
);
|
|
10739
10761
|
const setAccessToken = (0, import_react12.useCallback)((token2) => {
|
|
10740
10762
|
dispatch({ type: "SET_ACCESS_TOKEN", token: token2 });
|
|
10741
10763
|
}, []);
|
|
@@ -10760,13 +10782,13 @@ var EmbedProvider = ({
|
|
|
10760
10782
|
);
|
|
10761
10783
|
if (element) {
|
|
10762
10784
|
styleRef.current = element;
|
|
10763
|
-
|
|
10785
|
+
} else {
|
|
10786
|
+
const style = document.createElement("link");
|
|
10787
|
+
style.id = "schematic-fonts";
|
|
10788
|
+
style.rel = "stylesheet";
|
|
10789
|
+
document.head.appendChild(style);
|
|
10790
|
+
styleRef.current = style;
|
|
10764
10791
|
}
|
|
10765
|
-
const style = document.createElement("link");
|
|
10766
|
-
style.id = "schematic-fonts";
|
|
10767
|
-
style.rel = "stylesheet";
|
|
10768
|
-
document.head.appendChild(style);
|
|
10769
|
-
styleRef.current = style;
|
|
10770
10792
|
const darkModeQuery = matchMedia("(prefers-color-scheme: dark)");
|
|
10771
10793
|
const colorMode = darkModeQuery.matches ? "dark" : "light";
|
|
10772
10794
|
dispatch({
|
|
@@ -10777,13 +10799,17 @@ var EmbedProvider = ({
|
|
|
10777
10799
|
}
|
|
10778
10800
|
}
|
|
10779
10801
|
});
|
|
10780
|
-
|
|
10802
|
+
function darkModeQueryHandler(event) {
|
|
10781
10803
|
const newColorMode = event.matches ? "dark" : "light";
|
|
10782
10804
|
dispatch({
|
|
10783
10805
|
type: "UPDATE_SETTINGS",
|
|
10784
10806
|
settings: { theme: { colorMode: newColorMode } }
|
|
10785
10807
|
});
|
|
10786
|
-
}
|
|
10808
|
+
}
|
|
10809
|
+
darkModeQuery.addEventListener("change", darkModeQueryHandler);
|
|
10810
|
+
return () => {
|
|
10811
|
+
darkModeQuery.removeEventListener("change", darkModeQueryHandler);
|
|
10812
|
+
};
|
|
10787
10813
|
}, []);
|
|
10788
10814
|
(0, import_react12.useEffect)(() => {
|
|
10789
10815
|
const fontSet = /* @__PURE__ */ new Set([]);
|
|
@@ -10829,24 +10855,19 @@ var EmbedProvider = ({
|
|
|
10829
10855
|
}));
|
|
10830
10856
|
}
|
|
10831
10857
|
}, [state.accessToken, apiConfig, customHeaders]);
|
|
10832
|
-
(0, import_react12.useEffect)(() => {
|
|
10833
|
-
if (state.error) {
|
|
10834
|
-
debug(state.error.message);
|
|
10835
|
-
}
|
|
10836
|
-
}, [debug, state.error]);
|
|
10837
10858
|
(0, import_react12.useEffect)(() => {
|
|
10838
10859
|
const providedSettings = { ...options.settings || {} };
|
|
10839
10860
|
updateSettings(providedSettings, { update: false });
|
|
10840
10861
|
}, [options.settings, updateSettings]);
|
|
10841
10862
|
(0, import_react12.useEffect)(() => {
|
|
10842
|
-
|
|
10863
|
+
function planChangedHandler(event) {
|
|
10843
10864
|
if (event instanceof CustomEvent) {
|
|
10844
10865
|
debug("plan changed", event.detail);
|
|
10845
10866
|
}
|
|
10846
|
-
}
|
|
10847
|
-
window.addEventListener("plan-changed",
|
|
10867
|
+
}
|
|
10868
|
+
window.addEventListener("plan-changed", planChangedHandler);
|
|
10848
10869
|
return () => {
|
|
10849
|
-
window.removeEventListener("plan-changed",
|
|
10870
|
+
window.removeEventListener("plan-changed", planChangedHandler);
|
|
10850
10871
|
};
|
|
10851
10872
|
}, [debug]);
|
|
10852
10873
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
@@ -10871,13 +10892,15 @@ var EmbedProvider = ({
|
|
|
10871
10892
|
previewCheckout: debouncedPreviewCheckout,
|
|
10872
10893
|
unsubscribe: debouncedUnsubscribe,
|
|
10873
10894
|
getUpcomingInvoice: debouncedGetUpcomingInvoice,
|
|
10895
|
+
getCustomerBalance: debouncedGetCustomerBalance,
|
|
10874
10896
|
listInvoices: debouncedListInvoices,
|
|
10875
10897
|
setError,
|
|
10876
10898
|
setAccessToken,
|
|
10877
10899
|
setLayout,
|
|
10878
10900
|
setCheckoutState,
|
|
10879
10901
|
setData,
|
|
10880
|
-
updateSettings
|
|
10902
|
+
updateSettings,
|
|
10903
|
+
debug
|
|
10881
10904
|
},
|
|
10882
10905
|
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(ot, { theme: state.settings.theme, children: [
|
|
10883
10906
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(IconStyles, {}),
|
|
@@ -14712,11 +14735,12 @@ var CheckoutDialog = ({ top = 0 }) => {
|
|
|
14712
14735
|
const entitlements = plan.entitlements.reduce(
|
|
14713
14736
|
(acc, entitlement) => {
|
|
14714
14737
|
if (entitlement.priceBehavior && (period === "month" && entitlement.meteredMonthlyPrice || period === "year" && entitlement.meteredYearlyPrice)) {
|
|
14738
|
+
const allocation = entitlement.valueNumeric || 0;
|
|
14715
14739
|
acc.push({
|
|
14716
14740
|
...entitlement,
|
|
14717
|
-
allocation
|
|
14741
|
+
allocation,
|
|
14718
14742
|
usage: 0,
|
|
14719
|
-
quantity:
|
|
14743
|
+
quantity: allocation
|
|
14720
14744
|
});
|
|
14721
14745
|
}
|
|
14722
14746
|
return acc;
|
|
@@ -17802,11 +17826,29 @@ var PlanManager = (0, import_react48.forwardRef)(({ children, className, portal,
|
|
|
17802
17826
|
featureUsage: featureUsage2,
|
|
17803
17827
|
trialPaymentMethodRequired: trialPaymentMethodRequired2
|
|
17804
17828
|
} = data;
|
|
17829
|
+
const creditGroups2 = groupCreditGrants(creditGrants, {
|
|
17830
|
+
groupBy: "bundle"
|
|
17831
|
+
}).reduce(
|
|
17832
|
+
(acc, grant) => {
|
|
17833
|
+
switch (grant.grantReason) {
|
|
17834
|
+
case "plan" /* Plan */:
|
|
17835
|
+
acc.plan.push(grant);
|
|
17836
|
+
break;
|
|
17837
|
+
case "purchased" /* Purchased */:
|
|
17838
|
+
acc.bundles.push(grant);
|
|
17839
|
+
break;
|
|
17840
|
+
case "free" /* Free */:
|
|
17841
|
+
acc.promotional.push(grant);
|
|
17842
|
+
}
|
|
17843
|
+
return acc;
|
|
17844
|
+
},
|
|
17845
|
+
{ plan: [], bundles: [], promotional: [] }
|
|
17846
|
+
);
|
|
17805
17847
|
return {
|
|
17806
17848
|
currentPlan: company?.plan,
|
|
17807
17849
|
currentAddOns: company?.addOns || [],
|
|
17808
17850
|
creditBundles: creditBundles2,
|
|
17809
|
-
creditGroups:
|
|
17851
|
+
creditGroups: creditGroups2,
|
|
17810
17852
|
billingSubscription: company?.billingSubscription,
|
|
17811
17853
|
canCheckout: capabilities?.checkout ?? true,
|
|
17812
17854
|
defaultPlan: defaultPlan2,
|
|
@@ -17818,7 +17860,7 @@ var PlanManager = (0, import_react48.forwardRef)(({ children, className, portal,
|
|
|
17818
17860
|
currentPlan: void 0,
|
|
17819
17861
|
currentAddOns: [],
|
|
17820
17862
|
creditBundles: [],
|
|
17821
|
-
creditGroups: [],
|
|
17863
|
+
creditGroups: { plan: [], bundles: [], promotional: [] },
|
|
17822
17864
|
billingSubscription: void 0,
|
|
17823
17865
|
canCheckout: false,
|
|
17824
17866
|
defaultPlan: void 0,
|
|
@@ -17975,77 +18017,151 @@ var PlanManager = (0, import_react48.forwardRef)(({ children, className, portal,
|
|
|
17975
18017
|
);
|
|
17976
18018
|
}) })
|
|
17977
18019
|
] }),
|
|
17978
|
-
props.addOns.isVisible && creditGroups.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(Flex, { $flexDirection: "column", $gap: "0.5rem", children: [
|
|
18020
|
+
props.addOns.isVisible && creditGroups.plan.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(Flex, { $flexDirection: "column", $gap: "0.5rem", children: [
|
|
17979
18021
|
props.addOns.showLabel && /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
|
|
17980
18022
|
Text,
|
|
17981
18023
|
{
|
|
17982
18024
|
$color: isLightBackground ? darken(settings.theme.card.background, 0.46) : lighten(settings.theme.card.background, 0.46),
|
|
17983
18025
|
$leading: 1,
|
|
17984
|
-
children: t2("Credits")
|
|
18026
|
+
children: t2("Credits in plan")
|
|
17985
18027
|
}
|
|
17986
18028
|
),
|
|
17987
|
-
/* @__PURE__ */ (0, import_jsx_runtime43.jsx)(Flex, { $flexDirection: "column", $gap: "1rem", children: creditGroups.
|
|
17988
|
-
(
|
|
17989
|
-
|
|
17990
|
-
|
|
17991
|
-
|
|
17992
|
-
|
|
17993
|
-
|
|
17994
|
-
|
|
17995
|
-
|
|
17996
|
-
|
|
17997
|
-
|
|
17998
|
-
|
|
17999
|
-
|
|
18000
|
-
|
|
18001
|
-
|
|
18002
|
-
|
|
18029
|
+
/* @__PURE__ */ (0, import_jsx_runtime43.jsx)(Flex, { $flexDirection: "column", $gap: "1rem", children: creditGroups.plan.map((group, groupIndex) => {
|
|
18030
|
+
return /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
|
|
18031
|
+
Flex,
|
|
18032
|
+
{
|
|
18033
|
+
$justifyContent: "space-between",
|
|
18034
|
+
$alignItems: "center",
|
|
18035
|
+
$flexWrap: "wrap",
|
|
18036
|
+
$gap: "0.5rem",
|
|
18037
|
+
children: [
|
|
18038
|
+
/* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(Text, { display: props.addOns.fontStyle, children: [
|
|
18039
|
+
group.quantity,
|
|
18040
|
+
" ",
|
|
18041
|
+
getFeatureName(group, group.quantity),
|
|
18042
|
+
" ",
|
|
18043
|
+
subscriptionInterval && /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(import_jsx_runtime43.Fragment, { children: [
|
|
18044
|
+
t2("per"),
|
|
18045
|
+
" ",
|
|
18046
|
+
t2(subscriptionInterval)
|
|
18047
|
+
] })
|
|
18048
|
+
] }),
|
|
18049
|
+
group.total.used > 0 && /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
|
|
18050
|
+
Text,
|
|
18051
|
+
{
|
|
18052
|
+
style: { opacity: 0.54 },
|
|
18053
|
+
$size: 0.875 * settings.theme.typography.text.fontSize,
|
|
18054
|
+
$color: settings.theme.typography.text.color,
|
|
18055
|
+
children: [
|
|
18056
|
+
group.total.used,
|
|
18003
18057
|
" ",
|
|
18004
|
-
|
|
18005
|
-
|
|
18006
|
-
|
|
18007
|
-
|
|
18008
|
-
|
|
18009
|
-
|
|
18010
|
-
|
|
18011
|
-
|
|
18012
|
-
|
|
18013
|
-
|
|
18014
|
-
|
|
18015
|
-
|
|
18016
|
-
|
|
18017
|
-
|
|
18018
|
-
|
|
18058
|
+
t2("used")
|
|
18059
|
+
]
|
|
18060
|
+
}
|
|
18061
|
+
)
|
|
18062
|
+
]
|
|
18063
|
+
},
|
|
18064
|
+
groupIndex
|
|
18065
|
+
);
|
|
18066
|
+
}) })
|
|
18067
|
+
] }),
|
|
18068
|
+
props.addOns.isVisible && creditGroups.bundles.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(Flex, { $flexDirection: "column", $gap: "0.5rem", children: [
|
|
18069
|
+
props.addOns.showLabel && /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
|
|
18070
|
+
Text,
|
|
18071
|
+
{
|
|
18072
|
+
$color: isLightBackground ? darken(settings.theme.card.background, 0.46) : lighten(settings.theme.card.background, 0.46),
|
|
18073
|
+
$leading: 1,
|
|
18074
|
+
children: t2("Credit bundles")
|
|
18075
|
+
}
|
|
18076
|
+
),
|
|
18077
|
+
/* @__PURE__ */ (0, import_jsx_runtime43.jsx)(Flex, { $flexDirection: "column", $gap: "1rem", children: creditGroups.bundles.map((group, groupIndex) => {
|
|
18078
|
+
const bundle = group?.bundleId ? creditBundles.find((b2) => b2.id === group.bundleId) : void 0;
|
|
18079
|
+
return /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
|
|
18080
|
+
Flex,
|
|
18081
|
+
{
|
|
18082
|
+
$justifyContent: "space-between",
|
|
18083
|
+
$alignItems: "center",
|
|
18084
|
+
$flexWrap: "wrap",
|
|
18085
|
+
$gap: "0.5rem",
|
|
18086
|
+
children: [
|
|
18087
|
+
bundle ? /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(Text, { display: props.addOns.fontStyle, children: [
|
|
18088
|
+
group.grants.length > 1 && /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(Text, { style: { opacity: 0.5 }, children: [
|
|
18089
|
+
"(",
|
|
18090
|
+
group.grants.length,
|
|
18091
|
+
")",
|
|
18092
|
+
" "
|
|
18093
|
+
] }),
|
|
18094
|
+
bundle.name,
|
|
18095
|
+
" (",
|
|
18096
|
+
group.quantity,
|
|
18097
|
+
" ",
|
|
18098
|
+
getFeatureName(group, group.quantity),
|
|
18099
|
+
")"
|
|
18100
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(Text, { display: props.addOns.fontStyle, children: [
|
|
18101
|
+
group.quantity,
|
|
18102
|
+
" ",
|
|
18103
|
+
getFeatureName(group, group.quantity)
|
|
18104
|
+
] }),
|
|
18105
|
+
group.total.used > 0 && /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
|
|
18106
|
+
Text,
|
|
18107
|
+
{
|
|
18108
|
+
style: { opacity: 0.54 },
|
|
18109
|
+
$size: 0.875 * settings.theme.typography.text.fontSize,
|
|
18110
|
+
$color: settings.theme.typography.text.color,
|
|
18111
|
+
children: [
|
|
18112
|
+
group.total.used,
|
|
18019
18113
|
" ",
|
|
18020
|
-
|
|
18021
|
-
|
|
18022
|
-
|
|
18023
|
-
|
|
18114
|
+
t2("used")
|
|
18115
|
+
]
|
|
18116
|
+
}
|
|
18117
|
+
)
|
|
18118
|
+
]
|
|
18119
|
+
},
|
|
18120
|
+
groupIndex
|
|
18121
|
+
);
|
|
18122
|
+
}) })
|
|
18123
|
+
] }),
|
|
18124
|
+
props.addOns.isVisible && creditGroups.promotional.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(Flex, { $flexDirection: "column", $gap: "0.5rem", children: [
|
|
18125
|
+
props.addOns.showLabel && /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
|
|
18126
|
+
Text,
|
|
18127
|
+
{
|
|
18128
|
+
$color: isLightBackground ? darken(settings.theme.card.background, 0.46) : lighten(settings.theme.card.background, 0.46),
|
|
18129
|
+
$leading: 1,
|
|
18130
|
+
children: t2("Promotional credits")
|
|
18131
|
+
}
|
|
18132
|
+
),
|
|
18133
|
+
/* @__PURE__ */ (0, import_jsx_runtime43.jsx)(Flex, { $flexDirection: "column", $gap: "1rem", children: creditGroups.promotional.map((group, groupIndex) => {
|
|
18134
|
+
return /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
|
|
18135
|
+
Flex,
|
|
18136
|
+
{
|
|
18137
|
+
$justifyContent: "space-between",
|
|
18138
|
+
$alignItems: "center",
|
|
18139
|
+
$flexWrap: "wrap",
|
|
18140
|
+
$gap: "0.5rem",
|
|
18141
|
+
children: [
|
|
18142
|
+
/* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(Text, { display: props.addOns.fontStyle, children: [
|
|
18143
|
+
group.quantity,
|
|
18144
|
+
" ",
|
|
18145
|
+
getFeatureName(group, group.quantity)
|
|
18146
|
+
] }),
|
|
18147
|
+
group.total.used > 0 && /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
|
|
18148
|
+
Text,
|
|
18149
|
+
{
|
|
18150
|
+
style: { opacity: 0.54 },
|
|
18151
|
+
$size: 0.875 * settings.theme.typography.text.fontSize,
|
|
18152
|
+
$color: settings.theme.typography.text.color,
|
|
18153
|
+
children: [
|
|
18154
|
+
group.total.used,
|
|
18024
18155
|
" ",
|
|
18025
|
-
|
|
18026
|
-
]
|
|
18027
|
-
|
|
18028
|
-
|
|
18029
|
-
|
|
18030
|
-
|
|
18031
|
-
|
|
18032
|
-
|
|
18033
|
-
|
|
18034
|
-
group.total.used,
|
|
18035
|
-
" ",
|
|
18036
|
-
t2("used")
|
|
18037
|
-
]
|
|
18038
|
-
}
|
|
18039
|
-
)
|
|
18040
|
-
]
|
|
18041
|
-
},
|
|
18042
|
-
groupIndex
|
|
18043
|
-
)
|
|
18044
|
-
);
|
|
18045
|
-
return acc;
|
|
18046
|
-
},
|
|
18047
|
-
[]
|
|
18048
|
-
) })
|
|
18156
|
+
t2("used")
|
|
18157
|
+
]
|
|
18158
|
+
}
|
|
18159
|
+
)
|
|
18160
|
+
]
|
|
18161
|
+
},
|
|
18162
|
+
groupIndex
|
|
18163
|
+
);
|
|
18164
|
+
}) })
|
|
18049
18165
|
] }),
|
|
18050
18166
|
canCheckout && props.callToAction.isVisible && /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
|
|
18051
18167
|
Button,
|
|
@@ -19058,11 +19174,12 @@ function resolveDesignProps11(props) {
|
|
|
19058
19174
|
var UpcomingBill = (0, import_react54.forwardRef)(({ className, ...rest }, ref) => {
|
|
19059
19175
|
const props = resolveDesignProps11(rest);
|
|
19060
19176
|
const { t: t2 } = useTranslation();
|
|
19061
|
-
const { data, settings, getUpcomingInvoice } = useEmbed();
|
|
19177
|
+
const { data, settings, debug, getUpcomingInvoice, getCustomerBalance } = useEmbed();
|
|
19062
19178
|
const isLightBackground = useIsLightBackground();
|
|
19063
19179
|
const [isLoading, setIsLoading] = (0, import_react54.useState)(false);
|
|
19064
19180
|
const [error, setError] = (0, import_react54.useState)();
|
|
19065
19181
|
const [upcomingInvoice, setUpcomingInvoice] = (0, import_react54.useState)();
|
|
19182
|
+
const [balances, setBalances] = (0, import_react54.useState)([]);
|
|
19066
19183
|
const discounts = (0, import_react54.useMemo)(() => {
|
|
19067
19184
|
return (isCheckoutData(data) && data.subscription?.discounts || []).map(
|
|
19068
19185
|
(discount) => ({
|
|
@@ -19091,9 +19208,22 @@ var UpcomingBill = (0, import_react54.forwardRef)(({ className, ...rest }, ref)
|
|
|
19091
19208
|
}
|
|
19092
19209
|
}
|
|
19093
19210
|
}, [data, getUpcomingInvoice]);
|
|
19211
|
+
const getBalances = (0, import_react54.useCallback)(async () => {
|
|
19212
|
+
try {
|
|
19213
|
+
const response = await getCustomerBalance();
|
|
19214
|
+
if (response) {
|
|
19215
|
+
setBalances(response.data.balances);
|
|
19216
|
+
}
|
|
19217
|
+
} catch (err2) {
|
|
19218
|
+
debug("Failed to fetch customer balance.", err2);
|
|
19219
|
+
}
|
|
19220
|
+
}, [debug, getCustomerBalance]);
|
|
19094
19221
|
(0, import_react54.useEffect)(() => {
|
|
19095
19222
|
getInvoice();
|
|
19096
19223
|
}, [getInvoice]);
|
|
19224
|
+
(0, import_react54.useEffect)(() => {
|
|
19225
|
+
getBalances();
|
|
19226
|
+
}, [getBalances]);
|
|
19097
19227
|
if (!isCheckoutData(data) || !data.subscription || data.subscription.cancelAt) {
|
|
19098
19228
|
return null;
|
|
19099
19229
|
}
|
|
@@ -19143,6 +19273,19 @@ var UpcomingBill = (0, import_react54.forwardRef)(({ className, ...rest }, ref)
|
|
|
19143
19273
|
]
|
|
19144
19274
|
}
|
|
19145
19275
|
),
|
|
19276
|
+
balances.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime50.jsxs)(
|
|
19277
|
+
Flex,
|
|
19278
|
+
{
|
|
19279
|
+
as: TransitionBox,
|
|
19280
|
+
$justifyContent: "space-between",
|
|
19281
|
+
$alignItems: "start",
|
|
19282
|
+
$gap: "1rem",
|
|
19283
|
+
children: [
|
|
19284
|
+
/* @__PURE__ */ (0, import_jsx_runtime50.jsx)(Text, { $weight: 600, children: t2("Remaining balance") }),
|
|
19285
|
+
/* @__PURE__ */ (0, import_jsx_runtime50.jsx)(Flex, { $flexDirection: "column", $gap: "0.5rem", children: balances.map((item, idx) => /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(Text, { children: formatCurrency(item.balance, item.currency) }, idx)) })
|
|
19286
|
+
]
|
|
19287
|
+
}
|
|
19288
|
+
),
|
|
19146
19289
|
discounts.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime50.jsxs)(
|
|
19147
19290
|
Flex,
|
|
19148
19291
|
{
|