@schematichq/schematic-components 0.1.0 → 0.2.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.
@@ -6782,143 +6782,6 @@ var inflate_1 = inflate;
6782
6782
  // src/context/embed.tsx
6783
6783
  var import_lodash = __toESM(require_lodash());
6784
6784
 
6785
- // node_modules/@stripe/stripe-js/dist/index.mjs
6786
- var V3_URL = "https://js.stripe.com/v3";
6787
- var V3_URL_REGEX = /^https:\/\/js\.stripe\.com\/v3\/?(\?.*)?$/;
6788
- var EXISTING_SCRIPT_MESSAGE = "loadStripe.setLoadParameters was called but an existing Stripe.js script already exists in the document; existing script parameters will be used";
6789
- var findScript = function findScript2() {
6790
- var scripts = document.querySelectorAll('script[src^="'.concat(V3_URL, '"]'));
6791
- for (var i2 = 0; i2 < scripts.length; i2++) {
6792
- var script = scripts[i2];
6793
- if (!V3_URL_REGEX.test(script.src)) {
6794
- continue;
6795
- }
6796
- return script;
6797
- }
6798
- return null;
6799
- };
6800
- var injectScript = function injectScript2(params) {
6801
- var queryString = params && !params.advancedFraudSignals ? "?advancedFraudSignals=false" : "";
6802
- var script = document.createElement("script");
6803
- script.src = "".concat(V3_URL).concat(queryString);
6804
- var headOrBody = document.head || document.body;
6805
- if (!headOrBody) {
6806
- throw new Error("Expected document.body not to be null. Stripe.js requires a <body> element.");
6807
- }
6808
- headOrBody.appendChild(script);
6809
- return script;
6810
- };
6811
- var registerWrapper = function registerWrapper2(stripe, startTime) {
6812
- if (!stripe || !stripe._registerWrapper) {
6813
- return;
6814
- }
6815
- stripe._registerWrapper({
6816
- name: "stripe-js",
6817
- version: "4.4.0",
6818
- startTime
6819
- });
6820
- };
6821
- var stripePromise = null;
6822
- var onErrorListener = null;
6823
- var onLoadListener = null;
6824
- var onError = function onError2(reject) {
6825
- return function() {
6826
- reject(new Error("Failed to load Stripe.js"));
6827
- };
6828
- };
6829
- var onLoad = function onLoad2(resolve, reject) {
6830
- return function() {
6831
- if (window.Stripe) {
6832
- resolve(window.Stripe);
6833
- } else {
6834
- reject(new Error("Stripe.js not available"));
6835
- }
6836
- };
6837
- };
6838
- var loadScript = function loadScript2(params) {
6839
- if (stripePromise !== null) {
6840
- return stripePromise;
6841
- }
6842
- stripePromise = new Promise(function(resolve, reject) {
6843
- if (typeof window === "undefined" || typeof document === "undefined") {
6844
- resolve(null);
6845
- return;
6846
- }
6847
- if (window.Stripe && params) {
6848
- console.warn(EXISTING_SCRIPT_MESSAGE);
6849
- }
6850
- if (window.Stripe) {
6851
- resolve(window.Stripe);
6852
- return;
6853
- }
6854
- try {
6855
- var script = findScript();
6856
- if (script && params) {
6857
- console.warn(EXISTING_SCRIPT_MESSAGE);
6858
- } else if (!script) {
6859
- script = injectScript(params);
6860
- } else if (script && onLoadListener !== null && onErrorListener !== null) {
6861
- var _script$parentNode;
6862
- script.removeEventListener("load", onLoadListener);
6863
- script.removeEventListener("error", onErrorListener);
6864
- (_script$parentNode = script.parentNode) === null || _script$parentNode === void 0 ? void 0 : _script$parentNode.removeChild(script);
6865
- script = injectScript(params);
6866
- }
6867
- onLoadListener = onLoad(resolve, reject);
6868
- onErrorListener = onError(reject);
6869
- script.addEventListener("load", onLoadListener);
6870
- script.addEventListener("error", onErrorListener);
6871
- } catch (error) {
6872
- reject(error);
6873
- return;
6874
- }
6875
- });
6876
- return stripePromise["catch"](function(error) {
6877
- stripePromise = null;
6878
- return Promise.reject(error);
6879
- });
6880
- };
6881
- var initStripe = function initStripe2(maybeStripe, args, startTime) {
6882
- if (maybeStripe === null) {
6883
- return null;
6884
- }
6885
- var stripe = maybeStripe.apply(void 0, args);
6886
- registerWrapper(stripe, startTime);
6887
- return stripe;
6888
- };
6889
- var stripePromise$1;
6890
- var loadCalled = false;
6891
- var getStripePromise = function getStripePromise2() {
6892
- if (stripePromise$1) {
6893
- return stripePromise$1;
6894
- }
6895
- stripePromise$1 = loadScript(null)["catch"](function(error) {
6896
- stripePromise$1 = null;
6897
- return Promise.reject(error);
6898
- });
6899
- return stripePromise$1;
6900
- };
6901
- Promise.resolve().then(function() {
6902
- return getStripePromise();
6903
- })["catch"](function(error) {
6904
- if (!loadCalled) {
6905
- console.warn(error);
6906
- }
6907
- });
6908
- var loadStripe = function loadStripe2() {
6909
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
6910
- args[_key] = arguments[_key];
6911
- }
6912
- loadCalled = true;
6913
- var startTime = Date.now();
6914
- return getStripePromise().then(function(maybeStripe) {
6915
- return initStripe(maybeStripe, args, startTime);
6916
- });
6917
- };
6918
-
6919
- // src/context/embed.tsx
6920
- var import_react_stripe_js = require("@stripe/react-stripe-js");
6921
-
6922
6785
  // src/api/runtime.ts
6923
6786
  var BASE_PATH = "https://api.schematichq.com".replace(/\/+$/, "");
6924
6787
  var Configuration = class {
@@ -7250,10 +7113,10 @@ function BillingProductForSubscriptionResponseDataFromJSONTyped(json, ignoreDisc
7250
7113
  environmentId: json["environment_id"],
7251
7114
  externalId: json["external_id"],
7252
7115
  id: json["id"],
7253
- interval: json["interval"] == null ? void 0 : json["interval"],
7116
+ interval: json["interval"],
7254
7117
  name: json["name"],
7255
7118
  price: json["price"],
7256
- priceExternalId: json["price_external_id"] == null ? void 0 : json["price_external_id"],
7119
+ priceExternalId: json["price_external_id"],
7257
7120
  quantity: json["quantity"],
7258
7121
  subscriptionId: json["subscription_id"],
7259
7122
  updatedAt: new Date(json["updated_at"])
@@ -7765,6 +7628,7 @@ function CompanySubscriptionResponseDataFromJSONTyped(json, ignoreDiscriminator)
7765
7628
  products: json["products"].map(
7766
7629
  BillingProductForSubscriptionResponseDataFromJSON
7767
7630
  ),
7631
+ status: json["status"],
7768
7632
  subscriptionExternalId: json["subscription_external_id"],
7769
7633
  totalPrice: json["total_price"]
7770
7634
  };
@@ -8521,7 +8385,6 @@ var EmbedContext = (0, import_react2.createContext)({
8521
8385
  },
8522
8386
  nodes: [],
8523
8387
  settings: { ...defaultSettings },
8524
- stripe: null,
8525
8388
  layout: "portal",
8526
8389
  error: void 0,
8527
8390
  isPending: false,
@@ -8531,8 +8394,6 @@ var EmbedContext = (0, import_react2.createContext)({
8531
8394
  },
8532
8395
  updateSettings: () => {
8533
8396
  },
8534
- setStripe: () => {
8535
- },
8536
8397
  setLayout: () => {
8537
8398
  }
8538
8399
  });
@@ -8551,7 +8412,6 @@ var EmbedProvider = ({
8551
8412
  },
8552
8413
  nodes: [],
8553
8414
  settings: { ...defaultSettings },
8554
- stripe: null,
8555
8415
  layout: "portal",
8556
8416
  isPending: false,
8557
8417
  error: void 0,
@@ -8561,8 +8421,6 @@ var EmbedProvider = ({
8561
8421
  },
8562
8422
  updateSettings: () => {
8563
8423
  },
8564
- setStripe: () => {
8565
- },
8566
8424
  setLayout: () => {
8567
8425
  }
8568
8426
  };
@@ -8588,16 +8446,11 @@ var EmbedProvider = ({
8588
8446
  nodes.push(...parseEditorState(ast));
8589
8447
  }
8590
8448
  }
8591
- let stripe = null;
8592
- if (data.stripeEmbed?.publishableKey) {
8593
- stripe = loadStripe(data.stripeEmbed.publishableKey);
8594
- }
8595
8449
  setState((prev2) => ({
8596
8450
  ...prev2,
8597
8451
  data,
8598
8452
  nodes,
8599
8453
  settings,
8600
- stripe,
8601
8454
  isPending: false
8602
8455
  }));
8603
8456
  } catch (error) {
@@ -8632,15 +8485,6 @@ var EmbedProvider = ({
8632
8485
  },
8633
8486
  [setState]
8634
8487
  );
8635
- const setStripe = (0, import_react2.useCallback)(
8636
- (stripe) => {
8637
- setState((prev2) => ({
8638
- ...prev2,
8639
- stripe
8640
- }));
8641
- },
8642
- [setState]
8643
- );
8644
8488
  const setLayout = (0, import_react2.useCallback)(
8645
8489
  (layout) => {
8646
8490
  setState((prev2) => ({
@@ -8662,12 +8506,11 @@ var EmbedProvider = ({
8662
8506
  styleRef.current = style;
8663
8507
  }, []);
8664
8508
  (0, import_react2.useEffect)(() => {
8665
- if (!accessToken) {
8666
- return;
8509
+ if (accessToken) {
8510
+ const config = new Configuration({ ...apiConfig, apiKey: accessToken });
8511
+ const api = new CheckoutApi(config);
8512
+ setState((prev2) => ({ ...prev2, api }));
8667
8513
  }
8668
- const config = new Configuration({ ...apiConfig, apiKey: accessToken });
8669
- const api = new CheckoutApi(config);
8670
- setState((prev2) => ({ ...prev2, api }));
8671
8514
  }, [accessToken, apiConfig]);
8672
8515
  (0, import_react2.useEffect)(() => {
8673
8516
  hydrate();
@@ -8684,47 +8527,6 @@ var EmbedProvider = ({
8684
8527
  }
8685
8528
  }
8686
8529
  }, [state.settings.theme.typography]);
8687
- const renderChildren = () => {
8688
- if (state.stripe) {
8689
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
8690
- import_react_stripe_js.Elements,
8691
- {
8692
- stripe: state.stripe,
8693
- options: {
8694
- appearance: {
8695
- theme: "stripe",
8696
- variables: {
8697
- // Base
8698
- fontFamily: '"Public Sans", system-ui, sans-serif',
8699
- spacingUnit: "0.25rem",
8700
- borderRadius: "0.5rem",
8701
- colorText: "#30313D",
8702
- colorBackground: "#FFFFFF",
8703
- colorPrimary: "#0570DE",
8704
- colorDanger: "#DF1B41",
8705
- // Layout
8706
- gridRowSpacing: "1.5rem",
8707
- gridColumnSpacing: "1.5rem"
8708
- },
8709
- rules: {
8710
- ".Label": {
8711
- fontSize: "1rem",
8712
- fontWeight: "400",
8713
- marginBottom: "0.75rem",
8714
- color: state.settings.theme.typography.text.color
8715
- }
8716
- }
8717
- },
8718
- ...state.data.stripeEmbed?.setupIntentClientSecret ? {
8719
- clientSecret: state.data.stripeEmbed?.setupIntentClientSecret
8720
- } : { mode: "payment", currency: "usd", amount: 999999 }
8721
- },
8722
- children
8723
- }
8724
- );
8725
- }
8726
- return children;
8727
- };
8728
8530
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
8729
8531
  EmbedContext.Provider,
8730
8532
  {
@@ -8733,19 +8535,17 @@ var EmbedProvider = ({
8733
8535
  data: state.data,
8734
8536
  nodes: state.nodes,
8735
8537
  settings: state.settings,
8736
- stripe: state.stripe,
8737
8538
  layout: state.layout,
8738
8539
  error: state.error,
8739
8540
  isPending: state.isPending,
8740
8541
  hydrate,
8741
8542
  setData,
8742
8543
  updateSettings,
8743
- setStripe,
8744
8544
  setLayout
8745
8545
  },
8746
8546
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(ot, { theme: state.settings.theme, children: [
8747
8547
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(GlobalStyle, {}),
8748
- renderChildren()
8548
+ children
8749
8549
  ] })
8750
8550
  }
8751
8551
  );
@@ -8938,22 +8738,57 @@ var Box = dt.div((props) => {
8938
8738
  }, initialStyles);
8939
8739
  });
8940
8740
 
8941
- // src/components/ui/text/styles.ts
8942
- var Text = dt.span`
8943
- font-family: ${({ $font = "Inter" }) => `${$font}, sans-serif`};
8944
- font-size: ${({ $size = 16 }) => typeof $size === "number" ? `${$size / TEXT_BASE_SIZE}rem` : $size};
8945
- ${({ $weight = 400 }) => lt`
8946
- font-weight: ${$weight};
8947
- font-variation-settings: "wght" ${$weight};
8948
- `};
8949
- line-height: ${({ $lineHeight = 1.25 }) => $lineHeight};
8950
- ${({ $align }) => attr("text-align", $align)};
8951
- color: ${({ $color, theme }) => $color || theme.typography.text.color};
8741
+ // src/components/ui/loader/styles.ts
8742
+ var spin = mt`
8743
+ 0% {
8744
+ transform: rotate(0deg);
8745
+ }
8952
8746
 
8953
- &:focus-visible {
8954
- outline: 2px solid ${({ theme }) => theme.primary};
8955
- outline-offset: 2px;
8747
+ 100% {
8748
+ transform: rotate(360deg);
8749
+ }
8750
+ `;
8751
+ var Loader = dt.div`
8752
+ display: inline-block;
8753
+ border-style: solid;
8754
+ border-color: hsla(0, 0%, 50%, 0.125);
8755
+ border-top-color: ${({ theme, $color }) => $color || theme.primary};
8756
+ border-radius: 50%;
8757
+ transition: all 0.1s;
8758
+ animation: ${spin} 1.5s linear infinite;
8759
+
8760
+ ${({ $size = "md", $isLoading = true }) => {
8761
+ let px;
8762
+ switch ($size) {
8763
+ case "xs":
8764
+ px = 16;
8765
+ break;
8766
+ case "sm":
8767
+ px = 24;
8768
+ break;
8769
+ default:
8770
+ case "md":
8771
+ px = 32;
8772
+ break;
8773
+ case "lg":
8774
+ px = 40;
8775
+ break;
8776
+ case "xl":
8777
+ px = 48;
8778
+ break;
8779
+ case "2xl":
8780
+ px = 56;
8781
+ break;
8782
+ case "3xl":
8783
+ px = 64;
8784
+ break;
8956
8785
  }
8786
+ return lt`
8787
+ width: ${($isLoading ? px : 0) / TEXT_BASE_SIZE}rem;
8788
+ height: ${($isLoading ? px : 0) / TEXT_BASE_SIZE}rem;
8789
+ border-width: ${($isLoading ? px : 0) / 16 / TEXT_BASE_SIZE}rem;
8790
+ `;
8791
+ }}
8957
8792
  `;
8958
8793
 
8959
8794
  // src/components/ui/button/styles.ts
@@ -8962,8 +8797,11 @@ var Button = dt.button`
8962
8797
  font-family: Manrope, Arial, Helvetica, sans-serif;
8963
8798
  font-weight: 800;
8964
8799
  line-height: 1;
8800
+ display: flex;
8801
+ justify-content: center;
8802
+ align-items: center;
8803
+ gap: 0.5rem;
8965
8804
  border: 1px solid transparent;
8966
- transition-property: all;
8967
8805
 
8968
8806
  &:hover {
8969
8807
  cursor: pointer;
@@ -9047,10 +8885,11 @@ var Button2 = ({
9047
8885
  size = "md",
9048
8886
  variant = "solid",
9049
8887
  disabled = false,
8888
+ isLoading = false,
9050
8889
  children,
9051
8890
  ...props
9052
8891
  }) => {
9053
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
8892
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
9054
8893
  Button,
9055
8894
  {
9056
8895
  $color: color,
@@ -9058,7 +8897,10 @@ var Button2 = ({
9058
8897
  $variant: variant,
9059
8898
  disabled,
9060
8899
  ...props,
9061
- children
8900
+ children: [
8901
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Loader, { $size: "sm", $isLoading: isLoading }),
8902
+ children
8903
+ ]
9062
8904
  }
9063
8905
  );
9064
8906
  };
@@ -9152,25 +8994,6 @@ var IconRound = ({
9152
8994
  return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Container, { $size: size, $variant: variant, $colors: colors, ...props, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon2, { name }) });
9153
8995
  };
9154
8996
 
9155
- // src/components/ui/loader/styles.ts
9156
- var spin = mt`
9157
- 0% {
9158
- transform: rotate(0deg);
9159
- }
9160
- 100% {
9161
- transform: rotate(360deg);
9162
- }
9163
- `;
9164
- var Loader = dt.div`
9165
- border: ${4 / TEXT_BASE_SIZE}rem solid hsla(0, 0%, 50%, 0.125);
9166
- border-top: ${4 / TEXT_BASE_SIZE}rem solid ${({ theme }) => theme.secondary};
9167
- border-radius: 50%;
9168
- width: ${56 / TEXT_BASE_SIZE}rem;
9169
- height: ${56 / TEXT_BASE_SIZE}rem;
9170
- animation: ${spin} 1.5s linear infinite;
9171
- display: inline-block;
9172
- `;
9173
-
9174
8997
  // src/components/ui/modal/Modal.tsx
9175
8998
  var import_react4 = require("react");
9176
8999
  var import_jsx_runtime5 = require("react/jsx-runtime");
@@ -9224,8 +9047,8 @@ var Modal = ({ children, size = "auto", onClose }) => {
9224
9047
  ...size === "auto" ? { $width: "min-content", $height: "min-content" } : {
9225
9048
  $width: "100%",
9226
9049
  $height: "100%",
9227
- $maxWidth: "1366px",
9228
- $maxHeight: "768px"
9050
+ $maxWidth: "1356px",
9051
+ $maxHeight: "860px"
9229
9052
  },
9230
9053
  $backgroundColor: theme.card.background,
9231
9054
  $borderRadius: "0.5rem",
@@ -9357,21 +9180,178 @@ var ProgressBar = ({
9357
9180
  );
9358
9181
  };
9359
9182
 
9183
+ // src/components/ui/text/styles.ts
9184
+ var Text = dt.span`
9185
+ font-family: ${({ $font = "Inter" }) => `${$font}, sans-serif`};
9186
+ font-size: ${({ $size = 16 }) => typeof $size === "number" ? `${$size / TEXT_BASE_SIZE}rem` : $size};
9187
+ ${({ $weight = 400 }) => lt`
9188
+ font-weight: ${$weight};
9189
+ font-variation-settings: "wght" ${$weight};
9190
+ `};
9191
+ line-height: ${({ $lineHeight = 1.25 }) => $lineHeight};
9192
+ ${({ $align }) => attr("text-align", $align)};
9193
+ color: ${({ $color, theme }) => $color || theme.typography.text.color};
9194
+
9195
+ &:focus-visible {
9196
+ outline: 2px solid ${({ theme }) => theme.primary};
9197
+ outline-offset: 2px;
9198
+ }
9199
+ `;
9200
+
9360
9201
  // src/components/elements/plan-manager/CheckoutDialog.tsx
9361
9202
  var import_react8 = require("react");
9362
9203
  var import_pluralize = __toESM(require_pluralize());
9363
9204
 
9364
- // src/components/elements/payment-method/PaymentMethod.tsx
9365
- var import_react6 = require("react");
9366
- var import_react_dom = require("react-dom");
9367
-
9368
- // src/components/elements/plan-manager/styles.ts
9369
- var StyledButton = dt(Button2)`
9370
- font-family: "Public Sans", sans-serif;
9371
- font-weight: 500;
9372
- text-align: center;
9373
- width: 100%;
9374
- ${({ disabled, $color = "primary", theme }) => {
9205
+ // node_modules/@stripe/stripe-js/dist/index.mjs
9206
+ var V3_URL = "https://js.stripe.com/v3";
9207
+ var V3_URL_REGEX = /^https:\/\/js\.stripe\.com\/v3\/?(\?.*)?$/;
9208
+ var EXISTING_SCRIPT_MESSAGE = "loadStripe.setLoadParameters was called but an existing Stripe.js script already exists in the document; existing script parameters will be used";
9209
+ var findScript = function findScript2() {
9210
+ var scripts = document.querySelectorAll('script[src^="'.concat(V3_URL, '"]'));
9211
+ for (var i2 = 0; i2 < scripts.length; i2++) {
9212
+ var script = scripts[i2];
9213
+ if (!V3_URL_REGEX.test(script.src)) {
9214
+ continue;
9215
+ }
9216
+ return script;
9217
+ }
9218
+ return null;
9219
+ };
9220
+ var injectScript = function injectScript2(params) {
9221
+ var queryString = params && !params.advancedFraudSignals ? "?advancedFraudSignals=false" : "";
9222
+ var script = document.createElement("script");
9223
+ script.src = "".concat(V3_URL).concat(queryString);
9224
+ var headOrBody = document.head || document.body;
9225
+ if (!headOrBody) {
9226
+ throw new Error("Expected document.body not to be null. Stripe.js requires a <body> element.");
9227
+ }
9228
+ headOrBody.appendChild(script);
9229
+ return script;
9230
+ };
9231
+ var registerWrapper = function registerWrapper2(stripe, startTime) {
9232
+ if (!stripe || !stripe._registerWrapper) {
9233
+ return;
9234
+ }
9235
+ stripe._registerWrapper({
9236
+ name: "stripe-js",
9237
+ version: "4.4.0",
9238
+ startTime
9239
+ });
9240
+ };
9241
+ var stripePromise = null;
9242
+ var onErrorListener = null;
9243
+ var onLoadListener = null;
9244
+ var onError = function onError2(reject) {
9245
+ return function() {
9246
+ reject(new Error("Failed to load Stripe.js"));
9247
+ };
9248
+ };
9249
+ var onLoad = function onLoad2(resolve, reject) {
9250
+ return function() {
9251
+ if (window.Stripe) {
9252
+ resolve(window.Stripe);
9253
+ } else {
9254
+ reject(new Error("Stripe.js not available"));
9255
+ }
9256
+ };
9257
+ };
9258
+ var loadScript = function loadScript2(params) {
9259
+ if (stripePromise !== null) {
9260
+ return stripePromise;
9261
+ }
9262
+ stripePromise = new Promise(function(resolve, reject) {
9263
+ if (typeof window === "undefined" || typeof document === "undefined") {
9264
+ resolve(null);
9265
+ return;
9266
+ }
9267
+ if (window.Stripe && params) {
9268
+ console.warn(EXISTING_SCRIPT_MESSAGE);
9269
+ }
9270
+ if (window.Stripe) {
9271
+ resolve(window.Stripe);
9272
+ return;
9273
+ }
9274
+ try {
9275
+ var script = findScript();
9276
+ if (script && params) {
9277
+ console.warn(EXISTING_SCRIPT_MESSAGE);
9278
+ } else if (!script) {
9279
+ script = injectScript(params);
9280
+ } else if (script && onLoadListener !== null && onErrorListener !== null) {
9281
+ var _script$parentNode;
9282
+ script.removeEventListener("load", onLoadListener);
9283
+ script.removeEventListener("error", onErrorListener);
9284
+ (_script$parentNode = script.parentNode) === null || _script$parentNode === void 0 ? void 0 : _script$parentNode.removeChild(script);
9285
+ script = injectScript(params);
9286
+ }
9287
+ onLoadListener = onLoad(resolve, reject);
9288
+ onErrorListener = onError(reject);
9289
+ script.addEventListener("load", onLoadListener);
9290
+ script.addEventListener("error", onErrorListener);
9291
+ } catch (error) {
9292
+ reject(error);
9293
+ return;
9294
+ }
9295
+ });
9296
+ return stripePromise["catch"](function(error) {
9297
+ stripePromise = null;
9298
+ return Promise.reject(error);
9299
+ });
9300
+ };
9301
+ var initStripe = function initStripe2(maybeStripe, args, startTime) {
9302
+ if (maybeStripe === null) {
9303
+ return null;
9304
+ }
9305
+ var stripe = maybeStripe.apply(void 0, args);
9306
+ registerWrapper(stripe, startTime);
9307
+ return stripe;
9308
+ };
9309
+ var stripePromise$1;
9310
+ var loadCalled = false;
9311
+ var getStripePromise = function getStripePromise2() {
9312
+ if (stripePromise$1) {
9313
+ return stripePromise$1;
9314
+ }
9315
+ stripePromise$1 = loadScript(null)["catch"](function(error) {
9316
+ stripePromise$1 = null;
9317
+ return Promise.reject(error);
9318
+ });
9319
+ return stripePromise$1;
9320
+ };
9321
+ Promise.resolve().then(function() {
9322
+ return getStripePromise();
9323
+ })["catch"](function(error) {
9324
+ if (!loadCalled) {
9325
+ console.warn(error);
9326
+ }
9327
+ });
9328
+ var loadStripe = function loadStripe2() {
9329
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
9330
+ args[_key] = arguments[_key];
9331
+ }
9332
+ loadCalled = true;
9333
+ var startTime = Date.now();
9334
+ return getStripePromise().then(function(maybeStripe) {
9335
+ return initStripe(maybeStripe, args, startTime);
9336
+ });
9337
+ };
9338
+
9339
+ // src/components/elements/plan-manager/CheckoutDialog.tsx
9340
+ var import_react_stripe_js3 = require("@stripe/react-stripe-js");
9341
+
9342
+ // src/components/elements/payment-method/PaymentMethod.tsx
9343
+ var import_react6 = require("react");
9344
+ var import_react_dom = require("react-dom");
9345
+
9346
+ // src/components/elements/plan-manager/styles.ts
9347
+ var StyledButton = dt(Button2)`
9348
+ font-family: "Public Sans", sans-serif;
9349
+ font-weight: 500;
9350
+ text-align: center;
9351
+ width: 100%;
9352
+ padding: 0;
9353
+
9354
+ ${({ disabled, $color = "primary", theme }) => {
9375
9355
  const { l: l2 } = hexToHSL(theme[$color]);
9376
9356
  let textColor;
9377
9357
  let colorFn;
@@ -9446,19 +9426,19 @@ var StyledButton = dt(Button2)`
9446
9426
  case "sm":
9447
9427
  return lt`
9448
9428
  font-size: ${15 / TEXT_BASE_SIZE}rem;
9449
- padding: ${12 / TEXT_BASE_SIZE}rem 0;
9429
+ height: ${40 / TEXT_BASE_SIZE}rem;
9450
9430
  border-radius: ${6 / TEXT_BASE_SIZE}rem;
9451
9431
  `;
9452
9432
  case "md":
9453
9433
  return lt`
9454
9434
  font-size: ${17 / TEXT_BASE_SIZE}rem;
9455
- padding: ${16 / TEXT_BASE_SIZE}rem 0;
9435
+ height: ${52 / TEXT_BASE_SIZE}rem;
9456
9436
  border-radius: ${8 / TEXT_BASE_SIZE}rem;
9457
9437
  `;
9458
9438
  case "lg":
9459
9439
  return lt`
9460
9440
  font-size: ${19 / TEXT_BASE_SIZE}rem;
9461
- padding: ${20 / TEXT_BASE_SIZE}rem 0;
9441
+ height: ${64 / TEXT_BASE_SIZE}rem;
9462
9442
  border-radius: ${10 / TEXT_BASE_SIZE}rem;
9463
9443
  `;
9464
9444
  }
@@ -9764,13 +9744,13 @@ var PaymentMethod = (0, import_react6.forwardRef)(({ children, className, portal
9764
9744
 
9765
9745
  // src/components/elements/plan-manager/PaymentForm.tsx
9766
9746
  var import_react7 = require("react");
9747
+ var import_react_stripe_js = require("@stripe/react-stripe-js");
9767
9748
  var import_react_stripe_js2 = require("@stripe/react-stripe-js");
9768
- var import_react_stripe_js3 = require("@stripe/react-stripe-js");
9769
9749
  var import_jsx_runtime9 = require("react/jsx-runtime");
9770
9750
  var PaymentForm = ({ plan, period, onConfirm }) => {
9771
- const stripe = (0, import_react_stripe_js3.useStripe)();
9772
- const elements = (0, import_react_stripe_js3.useElements)();
9773
- const { api, data } = useEmbed();
9751
+ const stripe = (0, import_react_stripe_js2.useStripe)();
9752
+ const elements = (0, import_react_stripe_js2.useElements)();
9753
+ const { api } = useEmbed();
9774
9754
  const [message, setMessage] = (0, import_react7.useState)(null);
9775
9755
  const [isLoading, setIsLoading] = (0, import_react7.useState)(false);
9776
9756
  const [isConfirmed, setIsConfirmed] = (0, import_react7.useState)(false);
@@ -9826,20 +9806,20 @@ var PaymentForm = ({ plan, period, onConfirm }) => {
9826
9806
  $width: "100%",
9827
9807
  $marginBottom: "1.5rem",
9828
9808
  children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
9829
- import_react_stripe_js2.LinkAuthenticationElement,
9809
+ import_react_stripe_js.LinkAuthenticationElement,
9830
9810
  {
9831
9811
  id: "link-authentication-element"
9832
9812
  }
9833
9813
  )
9834
9814
  }
9835
9815
  ),
9836
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Box, { $marginBottom: "1.5rem", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_react_stripe_js2.PaymentElement, { id: "payment-element" }) }),
9816
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Box, { $marginBottom: "1.5rem", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_react_stripe_js.PaymentElement, { id: "payment-element" }) }),
9837
9817
  /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
9838
9818
  StyledButton,
9839
9819
  {
9840
9820
  id: "submit",
9841
- disabled: isLoading || !stripe || !elements || !data.stripeEmbed?.publishableKey || !data.stripeEmbed?.setupIntentClientSecret || isConfirmed,
9842
- $size: "md",
9821
+ disabled: isLoading || !stripe || !elements || isConfirmed,
9822
+ isLoading,
9843
9823
  $color: "primary",
9844
9824
  children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Text, { id: "button-text", children: isLoading ? "Loading" : "Save payment method" })
9845
9825
  }
@@ -9910,6 +9890,8 @@ var CheckoutDialog = () => {
9910
9890
  const [showPaymentForm, setShowPaymentForm] = (0, import_react8.useState)(
9911
9891
  () => typeof data.subscription?.paymentMethod === "undefined"
9912
9892
  );
9893
+ const [stripe, setStripe] = (0, import_react8.useState)(null);
9894
+ const [setupIntent, setSetupIntent] = (0, import_react8.useState)();
9913
9895
  const { paymentMethod, currentPlan, availablePlans, planPeriodOptions } = (0, import_react8.useMemo)(() => {
9914
9896
  const showMonthlyPriceOption = data.activePlans.some(
9915
9897
  (plan) => typeof plan.yearlyPrice !== "undefined"
@@ -9987,7 +9969,41 @@ var CheckoutDialog = () => {
9987
9969
  },
9988
9970
  [selectedPlan, selectPlan]
9989
9971
  );
9990
- const allowCheckout = api && selectedPlan && selectedPlan?.id !== currentPlan?.id && (paymentMethod && !showPaymentForm || paymentMethodId) && !isLoading;
9972
+ const checkout = (0, import_react8.useCallback)(async () => {
9973
+ const priceId = (planPeriod === "month" ? selectedPlan?.monthlyPrice : selectedPlan?.yearlyPrice)?.id;
9974
+ if (!api || !selectedPlan || !priceId) {
9975
+ return;
9976
+ }
9977
+ try {
9978
+ setIsLoading(true);
9979
+ await api.checkout({
9980
+ changeSubscriptionRequestBody: {
9981
+ newPlanId: selectedPlan.id,
9982
+ newPriceId: priceId,
9983
+ ...paymentMethodId && { paymentMethodId }
9984
+ }
9985
+ });
9986
+ setLayout("success");
9987
+ } catch {
9988
+ setError(
9989
+ "Error processing payment. Please try a different payment method."
9990
+ );
9991
+ } finally {
9992
+ setIsLoading(false);
9993
+ }
9994
+ }, [api, paymentMethodId, planPeriod, selectedPlan, setLayout]);
9995
+ (0, import_react8.useEffect)(() => {
9996
+ if (!stripe && setupIntent?.publishableKey) {
9997
+ setStripe(loadStripe(setupIntent.publishableKey));
9998
+ }
9999
+ }, [stripe, setupIntent?.publishableKey]);
10000
+ (0, import_react8.useLayoutEffect)(() => {
10001
+ document.body.style.overflow = "hidden";
10002
+ return () => {
10003
+ document.body.style.overflow = "";
10004
+ };
10005
+ }, []);
10006
+ const allowCheckout = api && selectedPlan && (paymentMethod && !showPaymentForm || paymentMethodId) && !isLoading;
9991
10007
  return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(Modal, { size: "lg", children: [
9992
10008
  /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(ModalHeader, { bordered: true, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(Flex, { $gap: "1rem", children: [
9993
10009
  /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(Flex, { $gap: "0.5rem", $alignItems: "center", children: [
@@ -10122,11 +10138,11 @@ var CheckoutDialog = () => {
10122
10138
  )
10123
10139
  ] }),
10124
10140
  /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Flex, { $flexWrap: "wrap", $gap: "1rem", $flexGrow: "1", children: availablePlans.sort((a2, b2) => {
10125
- if (planPeriod === "year" && a2.yearlyPrice && b2.yearlyPrice) {
10126
- return a2.yearlyPrice?.price - b2.yearlyPrice?.price;
10141
+ if (planPeriod === "year") {
10142
+ return (a2.yearlyPrice?.price ?? 0) - (b2.yearlyPrice?.price ?? 0);
10127
10143
  }
10128
- if (planPeriod === "month" && a2.monthlyPrice && b2.monthlyPrice) {
10129
- return a2.monthlyPrice.price - b2.monthlyPrice.price;
10144
+ if (planPeriod === "month") {
10145
+ return (a2.monthlyPrice?.price ?? 0) - (b2.monthlyPrice?.price ?? 0);
10130
10146
  }
10131
10147
  return 0;
10132
10148
  }).map((plan) => {
@@ -10266,10 +10282,10 @@ var CheckoutDialog = () => {
10266
10282
  ]
10267
10283
  }
10268
10284
  ),
10269
- !(plan.current || plan.id === currentPlan?.id) && plan.id !== selectedPlan?.id && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
10285
+ plan.id !== selectedPlan?.id && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
10270
10286
  StyledButton,
10271
10287
  {
10272
- disabled: plan.valid === false,
10288
+ disabled: isLoading || plan.valid === false,
10273
10289
  ...plan.valid === true && {
10274
10290
  onClick: () => selectPlan(plan)
10275
10291
  },
@@ -10288,36 +10304,69 @@ var CheckoutDialog = () => {
10288
10304
  );
10289
10305
  }) })
10290
10306
  ] }),
10291
- selectedPlan && checkoutStage === "checkout" && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_jsx_runtime10.Fragment, { children: showPaymentForm ? /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_jsx_runtime10.Fragment, { children: [
10292
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
10293
- PaymentForm,
10294
- {
10295
- plan: selectedPlan,
10296
- period: planPeriod,
10297
- onConfirm: (value) => {
10298
- setPaymentMethodId(value);
10299
- }
10300
- }
10301
- ),
10302
- typeof data.subscription?.paymentMethod !== "undefined" && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
10303
- Box,
10304
- {
10305
- tabIndex: 0,
10306
- onClick: () => setShowPaymentForm(false),
10307
- $cursor: "pointer",
10308
- children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
10309
- Text,
10307
+ selectedPlan && checkoutStage === "checkout" && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_jsx_runtime10.Fragment, { children: showPaymentForm && setupIntent?.setupIntentClientSecret ? /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
10308
+ import_react_stripe_js3.Elements,
10309
+ {
10310
+ stripe,
10311
+ options: {
10312
+ appearance: {
10313
+ theme: "stripe",
10314
+ variables: {
10315
+ // Base
10316
+ fontFamily: '"Public Sans", system-ui, sans-serif',
10317
+ spacingUnit: "0.25rem",
10318
+ borderRadius: "0.5rem",
10319
+ colorText: "#30313D",
10320
+ colorBackground: "#FFFFFF",
10321
+ colorPrimary: "#0570DE",
10322
+ colorDanger: "#DF1B41",
10323
+ // Layout
10324
+ gridRowSpacing: "1.5rem",
10325
+ gridColumnSpacing: "1.5rem"
10326
+ },
10327
+ rules: {
10328
+ ".Label": {
10329
+ fontSize: "1rem",
10330
+ fontWeight: "400",
10331
+ marginBottom: "0.75rem",
10332
+ color: theme.typography.text.color
10333
+ }
10334
+ }
10335
+ },
10336
+ clientSecret: setupIntent.setupIntentClientSecret
10337
+ },
10338
+ children: [
10339
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
10340
+ PaymentForm,
10310
10341
  {
10311
- $font: theme.typography.link.fontFamily,
10312
- $size: theme.typography.link.fontSize,
10313
- $weight: theme.typography.link.fontWeight,
10314
- $color: theme.typography.link.color,
10315
- children: "Use existing payment method"
10342
+ plan: selectedPlan,
10343
+ period: planPeriod,
10344
+ onConfirm: (value) => {
10345
+ setPaymentMethodId(value);
10346
+ }
10347
+ }
10348
+ ),
10349
+ data.subscription?.paymentMethod && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
10350
+ Box,
10351
+ {
10352
+ tabIndex: 0,
10353
+ onClick: () => setShowPaymentForm(false),
10354
+ $cursor: "pointer",
10355
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
10356
+ Text,
10357
+ {
10358
+ $font: theme.typography.link.fontFamily,
10359
+ $size: theme.typography.link.fontSize,
10360
+ $weight: theme.typography.link.fontWeight,
10361
+ $color: theme.typography.link.color,
10362
+ children: "Use existing payment method"
10363
+ }
10364
+ )
10316
10365
  }
10317
10366
  )
10318
- }
10319
- )
10320
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_jsx_runtime10.Fragment, { children: [
10367
+ ]
10368
+ }
10369
+ ) : /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_jsx_runtime10.Fragment, { children: [
10321
10370
  /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(PaymentMethod, {}),
10322
10371
  /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
10323
10372
  Box,
@@ -10345,16 +10394,17 @@ var CheckoutDialog = () => {
10345
10394
  Flex,
10346
10395
  {
10347
10396
  $flexDirection: "column",
10397
+ $width: "21.5rem",
10398
+ $overflow: "auto",
10348
10399
  $backgroundColor: theme.card.background,
10349
10400
  $borderRadius: "0 0 0.5rem",
10350
- $width: "21.5rem",
10351
10401
  $boxShadow: "0px 1px 20px 0px #1018280F, 0px 1px 3px 0px #1018281A;",
10352
10402
  children: [
10353
10403
  /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
10354
10404
  Flex,
10355
10405
  {
10356
- $flexDirection: "column",
10357
10406
  $position: "relative",
10407
+ $flexDirection: "column",
10358
10408
  $gap: "1rem",
10359
10409
  $width: "100%",
10360
10410
  $height: "auto",
@@ -10472,41 +10522,49 @@ var CheckoutDialog = () => {
10472
10522
  }
10473
10523
  ) }),
10474
10524
  /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(Flex, { $flexDirection: "column", $gap: "0.5rem", children: [
10475
- currentPlan && /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(Flex, { $justifyContent: "space-between", $alignItems: "center", children: [
10476
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
10477
- Flex,
10478
- {
10479
- ...selectedPlan && {
10480
- $opacity: "0.625",
10481
- $textDecoration: "line-through"
10482
- },
10483
- children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
10525
+ currentPlan && /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
10526
+ Flex,
10527
+ {
10528
+ $justifyContent: "space-between",
10529
+ $alignItems: "center",
10530
+ $gap: "1rem",
10531
+ children: [
10532
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
10533
+ Flex,
10534
+ {
10535
+ ...selectedPlan && {
10536
+ $opacity: "0.625",
10537
+ $textDecoration: "line-through"
10538
+ },
10539
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
10540
+ Text,
10541
+ {
10542
+ $font: theme.typography.heading4.fontFamily,
10543
+ $size: theme.typography.heading4.fontSize,
10544
+ $weight: theme.typography.heading4.fontWeight,
10545
+ $color: theme.typography.heading4.color,
10546
+ children: currentPlan.name
10547
+ }
10548
+ )
10549
+ }
10550
+ ),
10551
+ typeof currentPlan.planPrice === "number" && currentPlan.planPeriod && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Flex, { children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
10484
10552
  Text,
10485
10553
  {
10486
- $font: theme.typography.heading4.fontFamily,
10487
- $size: theme.typography.heading4.fontSize,
10488
- $weight: theme.typography.heading4.fontWeight,
10489
- $color: theme.typography.heading4.color,
10490
- children: currentPlan.name
10554
+ $font: theme.typography.text.fontFamily,
10555
+ $size: theme.typography.text.fontSize,
10556
+ $weight: theme.typography.text.fontWeight,
10557
+ $color: theme.typography.text.color,
10558
+ children: [
10559
+ formatCurrency(currentPlan.planPrice),
10560
+ "/",
10561
+ currentPlan.planPeriod
10562
+ ]
10491
10563
  }
10492
- )
10493
- }
10494
- ),
10495
- typeof currentPlan.planPrice === "number" && currentPlan.planPeriod && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Flex, { children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
10496
- Text,
10497
- {
10498
- $font: theme.typography.text.fontFamily,
10499
- $size: theme.typography.text.fontSize,
10500
- $weight: theme.typography.text.fontWeight,
10501
- $color: theme.typography.text.color,
10502
- children: [
10503
- formatCurrency(currentPlan.planPrice),
10504
- "/",
10505
- currentPlan.planPeriod
10506
- ]
10507
- }
10508
- ) })
10509
- ] }),
10564
+ ) })
10565
+ ]
10566
+ }
10567
+ ),
10510
10568
  selectedPlan && /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(Box, { $marginBottom: "1rem", children: [
10511
10569
  /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
10512
10570
  Box,
@@ -10527,34 +10585,42 @@ var CheckoutDialog = () => {
10527
10585
  )
10528
10586
  }
10529
10587
  ),
10530
- /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(Flex, { $justifyContent: "space-between", $alignItems: "center", children: [
10531
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Flex, { children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
10532
- Text,
10533
- {
10534
- $font: theme.typography.heading4.fontFamily,
10535
- $size: theme.typography.heading4.fontSize,
10536
- $weight: theme.typography.heading4.fontWeight,
10537
- $color: theme.typography.heading4.color,
10538
- children: selectedPlan.name
10539
- }
10540
- ) }),
10541
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Flex, { children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
10542
- Text,
10543
- {
10544
- $font: theme.typography.text.fontFamily,
10545
- $size: theme.typography.text.fontSize,
10546
- $weight: theme.typography.text.fontWeight,
10547
- $color: theme.typography.text.color,
10548
- children: [
10549
- formatCurrency(
10550
- (planPeriod === "month" ? selectedPlan.monthlyPrice : selectedPlan.yearlyPrice)?.price ?? 0
10551
- ),
10552
- "/",
10553
- planPeriod
10554
- ]
10555
- }
10556
- ) })
10557
- ] })
10588
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
10589
+ Flex,
10590
+ {
10591
+ $justifyContent: "space-between",
10592
+ $alignItems: "center",
10593
+ $gap: "1rem",
10594
+ children: [
10595
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Flex, { children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
10596
+ Text,
10597
+ {
10598
+ $font: theme.typography.heading4.fontFamily,
10599
+ $size: theme.typography.heading4.fontSize,
10600
+ $weight: theme.typography.heading4.fontWeight,
10601
+ $color: theme.typography.heading4.color,
10602
+ children: selectedPlan.name
10603
+ }
10604
+ ) }),
10605
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Flex, { children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
10606
+ Text,
10607
+ {
10608
+ $font: theme.typography.text.fontFamily,
10609
+ $size: theme.typography.text.fontSize,
10610
+ $weight: theme.typography.text.fontWeight,
10611
+ $color: theme.typography.text.color,
10612
+ children: [
10613
+ formatCurrency(
10614
+ (planPeriod === "month" ? selectedPlan.monthlyPrice : selectedPlan.yearlyPrice)?.price ?? 0
10615
+ ),
10616
+ "/",
10617
+ planPeriod
10618
+ ]
10619
+ }
10620
+ ) })
10621
+ ]
10622
+ }
10623
+ )
10558
10624
  ] })
10559
10625
  ] }),
10560
10626
  charges?.proration && /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_jsx_runtime10.Fragment, { children: [
@@ -10615,7 +10681,7 @@ var CheckoutDialog = () => {
10615
10681
  $height: "auto",
10616
10682
  $padding: "1.5rem",
10617
10683
  children: [
10618
- selectedPlan && subscriptionPrice && /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(Flex, { $justifyContent: "space-between", children: [
10684
+ selectedPlan && subscriptionPrice && /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(Flex, { $justifyContent: "space-between", $gap: "1rem", children: [
10619
10685
  /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Box, { $opacity: "0.625", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
10620
10686
  Text,
10621
10687
  {
@@ -10644,7 +10710,7 @@ var CheckoutDialog = () => {
10644
10710
  }
10645
10711
  ) })
10646
10712
  ] }),
10647
- charges && /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(Flex, { $justifyContent: "space-between", children: [
10713
+ charges && /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(Flex, { $justifyContent: "space-between", $gap: "1rem", children: [
10648
10714
  /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Box, { $opacity: "0.625", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
10649
10715
  Text,
10650
10716
  {
@@ -10662,17 +10728,47 @@ var CheckoutDialog = () => {
10662
10728
  $size: theme.typography.text.fontSize,
10663
10729
  $weight: theme.typography.text.fontWeight,
10664
10730
  $color: theme.typography.text.color,
10665
- children: formatCurrency(charges.dueNow)
10731
+ children: formatCurrency(Math.max(0, charges.dueNow))
10732
+ }
10733
+ ) })
10734
+ ] }),
10735
+ charges?.dueNow && charges.dueNow < 0 && /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(Flex, { $justifyContent: "space-between", $gap: "1rem", children: [
10736
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Box, { $opacity: "0.625", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
10737
+ Text,
10738
+ {
10739
+ $font: theme.typography.text.fontFamily,
10740
+ $size: theme.typography.text.fontSize,
10741
+ $weight: theme.typography.text.fontWeight,
10742
+ $color: theme.typography.text.color,
10743
+ children: "Credits to be applied to future invoices:"
10744
+ }
10745
+ ) }),
10746
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Box, { children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
10747
+ Text,
10748
+ {
10749
+ $font: theme.typography.text.fontFamily,
10750
+ $size: theme.typography.text.fontSize,
10751
+ $weight: theme.typography.text.fontWeight,
10752
+ $color: theme.typography.text.color,
10753
+ children: formatCurrency(Math.abs(charges.dueNow))
10666
10754
  }
10667
10755
  ) })
10668
10756
  ] }),
10669
10757
  checkoutStage === "plan" ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
10670
10758
  StyledButton,
10671
10759
  {
10672
- disabled: !selectedPlan,
10673
- ...selectedPlan && {
10674
- onClick: () => setCheckoutStage("checkout")
10675
- },
10760
+ ...allowCheckout ? {
10761
+ onClick: async () => {
10762
+ if (!data.component?.id) {
10763
+ return;
10764
+ }
10765
+ const { data: setupIntent2 } = await api.getSetupIntent({
10766
+ componentId: data.component.id
10767
+ });
10768
+ setSetupIntent(setupIntent2);
10769
+ setCheckoutStage("checkout");
10770
+ }
10771
+ } : { disabled: true },
10676
10772
  children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
10677
10773
  Flex,
10678
10774
  {
@@ -10690,31 +10786,9 @@ var CheckoutDialog = () => {
10690
10786
  ) : /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
10691
10787
  StyledButton,
10692
10788
  {
10693
- ...allowCheckout ? {
10694
- onClick: async () => {
10695
- const priceId = (planPeriod === "month" ? selectedPlan?.monthlyPrice : selectedPlan?.yearlyPrice)?.id;
10696
- if (!priceId) {
10697
- return;
10698
- }
10699
- try {
10700
- setIsLoading(true);
10701
- await api.checkout({
10702
- changeSubscriptionRequestBody: {
10703
- newPlanId: selectedPlan.id,
10704
- newPriceId: priceId,
10705
- ...paymentMethodId && { paymentMethodId }
10706
- }
10707
- });
10708
- setLayout("success");
10709
- } catch {
10710
- setError(
10711
- "Error processing payment. Please try a different payment method."
10712
- );
10713
- } finally {
10714
- setIsLoading(false);
10715
- }
10716
- }
10717
- } : { disabled: true },
10789
+ disabled: isLoading || !allowCheckout,
10790
+ isLoading,
10791
+ ...allowCheckout && { onClick: checkout },
10718
10792
  children: "Pay now"
10719
10793
  }
10720
10794
  ),
@@ -10735,8 +10809,8 @@ var CheckoutDialog = () => {
10735
10809
  $size: theme.typography.text.fontSize,
10736
10810
  $weight: theme.typography.text.fontWeight,
10737
10811
  $color: theme.typography.text.color,
10738
- children: checkoutStage === "plan" ? "Discounts & credits applied at checkout" : subscriptionPrice && `You will be billed ${subscriptionPrice} for this subscription
10739
- every ${planPeriod} on the ${data.subscription?.latestInvoice?.dueDate && formatOrdinal(new Date(data.subscription.latestInvoice.dueDate).getDate())} ${planPeriod === "year" && data.subscription?.latestInvoice?.dueDate ? `of ${getMonthName(data.subscription.latestInvoice.dueDate)}` : ""} unless you unsubscribe.`
10812
+ children: subscriptionPrice && `You will be billed ${subscriptionPrice} for this subscription
10813
+ every ${planPeriod} ${charges?.periodStart ? `on the ${formatOrdinal(charges.periodStart.getDate())}` : ""} ${planPeriod === "year" && charges?.periodStart ? `of ${getMonthName(charges.periodStart)}` : ""} unless you unsubscribe.`
10740
10814
  }
10741
10815
  ) })
10742
10816
  ]
@@ -10774,7 +10848,7 @@ var resolveDesignProps2 = (props) => {
10774
10848
  },
10775
10849
  callToAction: {
10776
10850
  isVisible: props.callToAction?.isVisible ?? true,
10777
- buttonSize: props.callToAction?.buttonSize ?? "lg",
10851
+ buttonSize: props.callToAction?.buttonSize ?? "md",
10778
10852
  buttonStyle: props.callToAction?.buttonStyle ?? "primary"
10779
10853
  }
10780
10854
  };
@@ -10782,13 +10856,13 @@ var resolveDesignProps2 = (props) => {
10782
10856
  var PlanManager = (0, import_react9.forwardRef)(({ children, className, portal, ...rest }, ref) => {
10783
10857
  const props = resolveDesignProps2(rest);
10784
10858
  const theme = nt();
10785
- const { data, layout, stripe, setLayout } = useEmbed();
10859
+ const { data, layout, setLayout } = useEmbed();
10786
10860
  const { currentPlan, canChangePlan } = (0, import_react9.useMemo)(() => {
10787
10861
  return {
10788
10862
  currentPlan: data.company?.plan,
10789
- canChangePlan: data.activePlans.length > 0 && data.stripeEmbed?.publishableKey && stripe !== null
10863
+ canChangePlan: data.activePlans.length > 0
10790
10864
  };
10791
- }, [data.company, data.activePlans, data.stripeEmbed, stripe]);
10865
+ }, [data.company, data.activePlans]);
10792
10866
  return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { ref, className, children: [
10793
10867
  /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
10794
10868
  Flex,
@@ -11200,7 +11274,7 @@ function resolveDesignProps5(props) {
11200
11274
  var UpcomingBill = (0, import_react12.forwardRef)(({ className, ...rest }, ref) => {
11201
11275
  const props = resolveDesignProps5(rest);
11202
11276
  const theme = nt();
11203
- const { data, stripe } = useEmbed();
11277
+ const { data } = useEmbed();
11204
11278
  const { upcomingInvoice } = (0, import_react12.useMemo)(() => {
11205
11279
  return {
11206
11280
  upcomingInvoice: {
@@ -11216,7 +11290,7 @@ var UpcomingBill = (0, import_react12.forwardRef)(({ className, ...rest }, ref)
11216
11290
  }
11217
11291
  };
11218
11292
  }, [data.subscription, data.upcomingInvoice]);
11219
- if (!stripe || !upcomingInvoice.amountDue || !upcomingInvoice.dueDate) {
11293
+ if (!upcomingInvoice.amountDue || !upcomingInvoice.dueDate) {
11220
11294
  return null;
11221
11295
  }
11222
11296
  return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { ref, className, children: [
@@ -11617,6 +11691,7 @@ var import_react18 = require("react");
11617
11691
  var StyledColumn = dt.div`
11618
11692
  flex-grow: 1;
11619
11693
  flex-basis: ${({ theme }) => `calc(${100 / theme.numberOfColumns}% - ${(theme.numberOfColumns - 1) / theme.numberOfColumns}rem)`};
11694
+ height: min-content;
11620
11695
  `;
11621
11696
 
11622
11697
  // src/components/layout/column/Column.tsx
@@ -11680,7 +11755,7 @@ var Loading = () => {
11680
11755
  $alignItems: "center",
11681
11756
  $justifyContent: "center",
11682
11757
  $padding: `${theme.card.padding / TEXT_BASE_SIZE}rem`,
11683
- children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(Loader, {})
11758
+ children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(Loader, { $size: "2xl", $color: "#194BFB" })
11684
11759
  }
11685
11760
  );
11686
11761
  };