@bunnyapp/components 1.3.0-beta.4 → 1.3.0-beta.7

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.
Files changed (44) hide show
  1. package/dist/cjs/index.js +588 -509
  2. package/dist/cjs/src/components/BillingDetails/BillingDetails.d.ts +1 -1
  3. package/dist/cjs/src/components/PaymentForm/DemoPay/demoPayUtils.d.ts +2 -2
  4. package/dist/cjs/src/components/PaymentForm/PaymentForm.d.ts +2 -3
  5. package/dist/cjs/src/components/PaymentForm/PaymentMethodDetails.d.ts +1 -1
  6. package/dist/cjs/src/components/Subscriptions/PlanManager/PlanPicker/priceListCard/priceListCardUtils.d.ts +1 -2
  7. package/dist/cjs/src/components/Subscriptions/SubscriptionRequests.d.ts +0 -1
  8. package/dist/cjs/src/components/Subscriptions/subscriptionsList/subscriptionUtils.d.ts +1 -0
  9. package/dist/cjs/src/components/TaxationForm.d.ts +2 -2
  10. package/dist/cjs/src/graphql/QuoteRequests.d.ts +1 -0
  11. package/dist/cjs/src/graphql/mutations/subscriptionTrialConvert.d.ts +7 -0
  12. package/dist/cjs/src/graphql/queries/getCurrentUserData.d.ts +13 -0
  13. package/dist/cjs/src/graphql/queries/getFeatureUsage.d.ts +1 -4
  14. package/dist/cjs/src/graphql/queries/getFormattedQuote.d.ts +2 -4
  15. package/dist/cjs/src/graphql/queries/getPriceListChangeOptions.d.ts +2 -1
  16. package/dist/cjs/src/hooks/useCurrentUserData.d.ts +10 -1
  17. package/dist/cjs/src/hooks/usePaymentPlugins.d.ts +2 -2
  18. package/dist/cjs/src/mocks/handlers.d.ts +1 -1
  19. package/dist/cjs/src/utils/couponUtils.d.ts +2 -0
  20. package/dist/esm/index.js +589 -510
  21. package/dist/esm/src/components/BillingDetails/BillingDetails.d.ts +1 -1
  22. package/dist/esm/src/components/PaymentForm/DemoPay/demoPayUtils.d.ts +2 -2
  23. package/dist/esm/src/components/PaymentForm/PaymentForm.d.ts +2 -3
  24. package/dist/esm/src/components/PaymentForm/PaymentMethodDetails.d.ts +1 -1
  25. package/dist/esm/src/components/Subscriptions/PlanManager/PlanPicker/priceListCard/priceListCardUtils.d.ts +1 -2
  26. package/dist/esm/src/components/Subscriptions/SubscriptionRequests.d.ts +0 -1
  27. package/dist/esm/src/components/Subscriptions/subscriptionsList/subscriptionUtils.d.ts +1 -0
  28. package/dist/esm/src/components/TaxationForm.d.ts +2 -2
  29. package/dist/esm/src/graphql/QuoteRequests.d.ts +1 -0
  30. package/dist/esm/src/graphql/mutations/subscriptionTrialConvert.d.ts +7 -0
  31. package/dist/esm/src/graphql/queries/getCurrentUserData.d.ts +13 -0
  32. package/dist/esm/src/graphql/queries/getFeatureUsage.d.ts +1 -4
  33. package/dist/esm/src/graphql/queries/getFormattedQuote.d.ts +2 -4
  34. package/dist/esm/src/graphql/queries/getPriceListChangeOptions.d.ts +2 -1
  35. package/dist/esm/src/hooks/useCurrentUserData.d.ts +10 -1
  36. package/dist/esm/src/hooks/usePaymentPlugins.d.ts +2 -2
  37. package/dist/esm/src/mocks/handlers.d.ts +1 -1
  38. package/dist/esm/src/utils/couponUtils.d.ts +2 -0
  39. package/dist/index.d.ts +3 -4
  40. package/package.json +2 -2
  41. package/dist/cjs/src/components/UpgradeFromTrial.d.ts +0 -6
  42. package/dist/esm/src/components/UpgradeFromTrial.d.ts +0 -6
  43. /package/dist/cjs/src/components/icons/{iDeal.d.ts → IDeal.d.ts} +0 -0
  44. /package/dist/esm/src/components/icons/{iDeal.d.ts → IDeal.d.ts} +0 -0
package/dist/cjs/index.js CHANGED
@@ -154,7 +154,7 @@ var BrandContext = react.createContext({
154
154
  });
155
155
 
156
156
  // This will be replaced at build time by rollup-plugin-replace
157
- var PACKAGE_VERSION = '1.0.76-beta.15';
157
+ var PACKAGE_VERSION = '1.3.0-beta.6';
158
158
  var createRequestHeaders = function (token) {
159
159
  var headers = common.createClientDevHeaders(token);
160
160
  // Add the components version header
@@ -430,6 +430,7 @@ var DocumentTemplatePreview = function (_a) {
430
430
  URL.revokeObjectURL(url_1);
431
431
  };
432
432
  }
433
+ return undefined;
433
434
  }, [data]);
434
435
  if (isLoading) {
435
436
  return (jsxRuntime.jsx("div", __assign({ className: "flex items-center justify-center h-96" }, { children: jsxRuntime.jsx(antd.Spin, {}) })));
@@ -501,6 +502,7 @@ function LegacyDocument(_a) {
501
502
  setPdfUrl(url_1);
502
503
  return function () { return URL.revokeObjectURL(url_1); };
503
504
  }
505
+ return undefined;
504
506
  }, [pdfBlob]);
505
507
  if (isLoading || !pdfUrl)
506
508
  return jsxRuntime.jsx(jsxRuntime.Fragment, {});
@@ -547,7 +549,7 @@ var checkout = function (_a) {
547
549
  });
548
550
  };
549
551
 
550
- var paymentMethodsQuery = function (filter) { return "query paymentMethods {\n paymentMethods ".concat(filter ? "(".concat(filter, ")") : '', " {\n nodes {\n id\n pluginId\n accountId\n expirationDate\n plugin {\n guid\n id\n }\n state\n metadata {\n issuer\n identifier\n kind\n description\n icon\n type\n }\n isDefault\n }\n }\n}"); };
552
+ var paymentMethodsQuery = function () { return "query PaymentMethods($accountId: ID) {\n paymentMethods (accountId: $accountId) {\n nodes {\n id\n pluginId\n accountId\n expirationDate\n plugin {\n guid\n id\n }\n state\n metadata {\n issuer\n identifier\n kind\n description\n icon\n type\n }\n isDefault\n }\n }\n}"; };
551
553
  var getPaymentMethods = function (_a) {
552
554
  var apiHost = _a.apiHost, token = _a.token, accountId = _a.accountId;
553
555
  return __awaiter(void 0, void 0, void 0, function () {
@@ -556,9 +558,10 @@ var getPaymentMethods = function (_a) {
556
558
  return __generator(this, function (_c) {
557
559
  switch (_c.label) {
558
560
  case 0: return [4 /*yield*/, gqlRequest({
559
- query: paymentMethodsQuery(accountId ? "filter: \"accountId is ".concat(accountId, "\"") : ''),
561
+ query: paymentMethodsQuery(),
560
562
  token: token,
561
563
  apiHost: apiHost,
564
+ vars: { accountId: accountId },
562
565
  })];
563
566
  case 1:
564
567
  response = _c.sent();
@@ -586,20 +589,11 @@ var usePaymentMethod = function (_a) {
586
589
  };
587
590
 
588
591
  var filterPaymentPlugins = function (plugins) {
589
- return plugins === null || plugins === void 0 ? void 0 : plugins.filter(function (plugin) { var _a, _b; return ((_a = plugin.type) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'payment' && ((_b = plugin.status) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === 'valid'; }).filter(function (plugin) { return plugin.name !== 'Manual Payment'; });
590
- };
591
- var filterPaymentPluginsByEntity = function (plugins, selectedEntityId) {
592
- return plugins === null || plugins === void 0 ? void 0 : plugins.filter(function (plugin) {
593
- var _a, _b;
594
- return selectedEntityId === undefined ||
595
- selectedEntityId === null ||
596
- ((_a = plugin.entities) === null || _a === void 0 ? void 0 : _a.includes(selectedEntityId)) ||
597
- ((_b = plugin.entities) === null || _b === void 0 ? void 0 : _b.length) === 0;
598
- });
592
+ return plugins === null || plugins === void 0 ? void 0 : plugins.filter(function (plugin) { var _a, _b; return ((_a = plugin.type) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'payment' && ((_b = plugin.status) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === 'valid'; });
599
593
  };
600
- var MUTATION$9 = "{\n paymentPlugins {\n enabled\n entities\n guid\n hidden\n id\n name\n status\n type\n webhookEnabled\n components\n }\n}";
594
+ var MUTATION$9 = "query PaymentPlugins($accountId: ID) {\n paymentPlugins (accountId: $accountId) {\n enabled\n entities\n guid\n hidden\n id\n name\n status\n type\n webhookEnabled\n components\n }\n}";
601
595
  var getPaymentPlugins = function (_a) {
602
- var apiHost = _a.apiHost, token = _a.token;
596
+ var apiHost = _a.apiHost, token = _a.token, accountId = _a.accountId;
603
597
  return __awaiter(void 0, void 0, void 0, function () {
604
598
  var response;
605
599
  return __generator(this, function (_b) {
@@ -610,6 +604,7 @@ var getPaymentPlugins = function (_a) {
610
604
  query: MUTATION$9,
611
605
  token: token,
612
606
  apiHost: apiHost,
607
+ vars: { accountId: accountId },
613
608
  })];
614
609
  case 1:
615
610
  response = _b.sent();
@@ -623,18 +618,15 @@ var getPaymentPlugins = function (_a) {
623
618
  });
624
619
  };
625
620
  var usePaymentPlugins = function (_a) {
626
- var apiHost = _a.apiHost, token = _a.token, selectedEntityId = _a.selectedEntityId;
621
+ var apiHost = _a.apiHost, token = _a.token, accountId = _a.accountId;
627
622
  var _b = reactQuery.useQuery({
628
623
  queryKey: ['paymentPlugins', token],
629
- queryFn: function () { return getPaymentPlugins({ apiHost: apiHost, token: token }); },
624
+ queryFn: function () { return getPaymentPlugins({ apiHost: apiHost, token: token, accountId: accountId }); },
630
625
  staleTime: 5 * 60 * 1000, // Consider data fresh for 5 minutes
631
626
  }), paymentPlugins = _b.data, isFetched = _b.isFetched;
632
627
  var filteredPaymentPlugins = filterPaymentPlugins(paymentPlugins);
633
- var filteredPaymentPluginsByEntity = selectedEntityId
634
- ? filterPaymentPluginsByEntity(filteredPaymentPlugins, selectedEntityId)
635
- : filteredPaymentPlugins;
636
628
  return {
637
- paymentPlugins: filteredPaymentPluginsByEntity,
629
+ paymentPlugins: filteredPaymentPlugins,
638
630
  isFetched: isFetched,
639
631
  };
640
632
  };
@@ -18613,13 +18605,13 @@ var isCardExpired = function (expiry) {
18613
18605
  var formatCardExpiry = function (cardExpiry) {
18614
18606
  if (cardExpiry.length <= 2)
18615
18607
  return cardExpiry;
18616
- return cardExpiry.substring(0, 2) + "/" + cardExpiry.substring(2);
18608
+ return cardExpiry.substring(0, 2) + '/' + cardExpiry.substring(2);
18617
18609
  };
18618
18610
  // removes spaces from a credit card number
18619
18611
  var unformatCardNumber = function (cardNumber) {
18620
- var cardNumberArray = cardNumber.split("");
18621
- var unformattedCardNumberArray = cardNumberArray.filter(function (character) { return character !== " "; });
18622
- return unformattedCardNumberArray.join("");
18612
+ var cardNumberArray = cardNumber.split('');
18613
+ var unformattedCardNumberArray = cardNumberArray.filter(function (character) { return character !== ' '; });
18614
+ return unformattedCardNumberArray.join('');
18623
18615
  };
18624
18616
  var storePayment = function (options, plugin, apiHost, accountId) { return __awaiter(void 0, void 0, void 0, function () {
18625
18617
  var testCreditCardNumber, testCreditCardCvc, testCreditCardExpirationDate, token, response;
@@ -18628,7 +18620,7 @@ var storePayment = function (options, plugin, apiHost, accountId) { return __awa
18628
18620
  case 0:
18629
18621
  testCreditCardNumber = options.testCreditCardNumber, testCreditCardCvc = options.testCreditCardCvc, testCreditCardExpirationDate = options.testCreditCardExpirationDate, token = options.token;
18630
18622
  return [4 /*yield*/, common.invokePlugin({
18631
- method: "store_payment_method",
18623
+ method: 'store_payment_method',
18632
18624
  plugin: plugin,
18633
18625
  payload: {
18634
18626
  test_credit_card_number: testCreditCardNumber,
@@ -18641,7 +18633,7 @@ var storePayment = function (options, plugin, apiHost, accountId) { return __awa
18641
18633
  })];
18642
18634
  case 1:
18643
18635
  response = _a.sent();
18644
- if ((response === null || response === void 0 ? void 0 : response.status) !== "success")
18636
+ if ((response === null || response === void 0 ? void 0 : response.status) !== 'success')
18645
18637
  throw new Error(response === null || response === void 0 ? void 0 : response.message);
18646
18638
  return [2 /*return*/, response];
18647
18639
  }
@@ -18958,7 +18950,7 @@ var PaymentMethodDetails = function (_a) {
18958
18950
  case 'StripePayment':
18959
18951
  return (jsxRuntime.jsx(StripeForm, { onFail: onFail, onSavePaymentMethod: onSavePaymentMethod, plugin: plugin }));
18960
18952
  case 'DemoPayPayment':
18961
- return (jsxRuntime.jsx(DemoPayForm, { onFail: onFail, onSavePaymentMethod: onSavePaymentMethod, plugin: plugin }));
18953
+ return (jsxRuntime.jsx(DemoPayForm, { onFail: onFail, onSavePaymentMethod: function (response) { return onSavePaymentMethod(response); }, plugin: plugin }));
18962
18954
  default:
18963
18955
  console.warn('Can not find form for plugin', plugin);
18964
18956
  return jsxRuntime.jsx(jsxRuntime.Fragment, {});
@@ -19104,7 +19096,7 @@ function useSetDefaultPaymentMethod(paymentPlugins, apiHost, token, accountId, o
19104
19096
  var showErrorNotification$2 = common.useErrorNotification();
19105
19097
  var PaymentForm = function (_a) {
19106
19098
  var _b;
19107
- var invoice = _a.invoice, onFail = _a.onFail, onPaymentSuccess = _a.onPaymentSuccess, onPaymentHoldSuccess = _a.onPaymentHoldSuccess, quote = _a.quote, accountId = _a.accountId, onSavePaymentMethod = _a.onSavePaymentMethod, onRemovePaymentMethod = _a.onRemovePaymentMethod, onSetDefaultPaymentMethod = _a.onSetDefaultPaymentMethod, entityId = _a.entityId, overrideToken = _a.overrideToken, customCheckoutFunction = _a.customCheckoutFunction, currencyIdFromProps = _a.currencyId, paymentHoldOptions = _a.paymentHoldOptions;
19099
+ var invoice = _a.invoice, onFail = _a.onFail, onPaymentSuccess = _a.onPaymentSuccess, onPaymentHoldSuccess = _a.onPaymentHoldSuccess, quote = _a.quote, accountId = _a.accountId, onSavePaymentMethod = _a.onSavePaymentMethod, onRemovePaymentMethod = _a.onRemovePaymentMethod, onSetDefaultPaymentMethod = _a.onSetDefaultPaymentMethod, overrideToken = _a.overrideToken, customCheckoutFunction = _a.customCheckoutFunction, currencyIdFromProps = _a.currencyId, paymentHoldOptions = _a.paymentHoldOptions;
19108
19100
  // Local state
19109
19101
  var _c = react.useState(false), showPaymentMethodForm = _c[0], setShowPaymentMethodForm = _c[1];
19110
19102
  // Simple hooks
@@ -19118,7 +19110,7 @@ var PaymentForm = function (_a) {
19118
19110
  apiHost: apiHost,
19119
19111
  }), storedPaymentMethods = _d.paymentMethods, defaultPaymentMethod = _d.defaultPaymentMethod, isPaymentMethodLoading = _d.isLoading;
19120
19112
  // Complex hooks
19121
- var paymentPlugins = usePaymentPlugins({ apiHost: apiHost, selectedEntityId: entityId, token: token }).paymentPlugins;
19113
+ var paymentPlugins = usePaymentPlugins({ apiHost: apiHost, token: token, accountId: accountId }).paymentPlugins;
19122
19114
  var selectedPaymentMethodPlugin = react.useMemo(function () {
19123
19115
  // TODO: consolate PluginData and PaymentPlugin into one type. Needs to be done on API side.
19124
19116
  return paymentPlugins === null || paymentPlugins === void 0 ? void 0 : paymentPlugins.find(function (plugin) { var _a, _b, _c; return ((_a = plugin.id) === null || _a === void 0 ? void 0 : _a.toString()) === ((_c = (_b = defaultPaymentMethod === null || defaultPaymentMethod === void 0 ? void 0 : defaultPaymentMethod.plugin) === null || _b === void 0 ? void 0 : _b.id) === null || _c === void 0 ? void 0 : _c.toString()); });
@@ -19176,14 +19168,14 @@ var PaymentForm = function (_a) {
19176
19168
  setShowPaymentMethodForm(false);
19177
19169
  onPaymentSuccess === null || onPaymentSuccess === void 0 ? void 0 : onPaymentSuccess();
19178
19170
  };
19179
- var handleSavePaymentMethod = function () {
19171
+ var handleSavePaymentMethod = function (response) {
19180
19172
  queryClient.invalidateQueries({
19181
19173
  queryKey: common.QueryKeyFactory.default.accountPaymentMethodKey({
19182
19174
  accountId: accountId,
19183
19175
  token: token,
19184
19176
  }),
19185
19177
  });
19186
- onSavePaymentMethod === null || onSavePaymentMethod === void 0 ? void 0 : onSavePaymentMethod();
19178
+ onSavePaymentMethod === null || onSavePaymentMethod === void 0 ? void 0 : onSavePaymentMethod(response);
19187
19179
  setShowPaymentMethodForm(false);
19188
19180
  };
19189
19181
  function handleClickAddPaymentMethod() {
@@ -19225,15 +19217,6 @@ function StripeWrapper(_a) {
19225
19217
  return (jsxRuntime.jsx(reactStripeJs.Elements, __assign({ options: options, stripe: stripe }, { children: children })));
19226
19218
  }
19227
19219
 
19228
- var useCurrentUserData = function () {
19229
- var queryClient = reactQuery.useQueryClient();
19230
- var token = useToken();
19231
- var currentUser = queryClient.getQueryData(common.QueryKeyFactory.default.currentUserKey(token));
19232
- if (!currentUser)
19233
- return {};
19234
- return currentUser;
19235
- };
19236
-
19237
19220
  function Invoice(_a) {
19238
19221
  var id = _a.id, invoiceQuoteViewComponent = _a.invoiceQuoteViewComponent, backButtonName = _a.backButtonName, onBackButtonClick = _a.onBackButtonClick, onInvoiceDownloadError = _a.onInvoiceDownloadError, onPaymentSuccess = _a.onPaymentSuccess, _b = _a.shadow, shadow = _b === void 0 ? 'shadow-md' : _b, className = _a.className, _c = _a.hideDownloadButton, hideDownloadButton = _c === void 0 ? false : _c, onInvoiceLoaded = _a.onInvoiceLoaded;
19239
19222
  return (jsxRuntime.jsx(InvoiceQuoteContext.Provider, __assign({ value: {
@@ -19256,7 +19239,6 @@ function ActualInvoice() {
19256
19239
  var _b = react.useContext(BunnyContext), apiHost = _b.apiHost, onTokenExpired = _b.onTokenExpired;
19257
19240
  var _c = react.useContext(InvoiceQuoteContext), hideDownloadButton = _c.hideDownloadButton, onInvoiceLoaded = _c.onInvoiceLoaded;
19258
19241
  var token = useToken();
19259
- var entityId = useCurrentUserData().entityId;
19260
19242
  // Hooks
19261
19243
  var showSuccessNotification = common.useSuccessNotification();
19262
19244
  var handleAllErrorFormats = common.useAllErrorFormats(onTokenExpired);
@@ -19292,12 +19274,12 @@ function ActualInvoice() {
19292
19274
  }, [formattedInvoice]);
19293
19275
  if (!formattedInvoice)
19294
19276
  return jsxRuntime.jsx(jsxRuntime.Fragment, {});
19295
- return (jsxRuntime.jsx("div", __assign({ className: "bunny-invoice-container" }, { children: jsxRuntime.jsxs("div", __assign({ className: "bunny-flex bunny-gap-6 ".concat(isMobile ? 'bunny-flex-col bunny-w-full' : '', " ").concat(className) }, { children: [formattedInvoice.isLegacy ? (jsxRuntime.jsx("div", __assign({ className: "bunny-flex bunny-justify-center bunny-w-full" }, { children: jsxRuntime.jsx(LegacyDocument, { documentUuid: formattedInvoice.uuid, documentType: "invoice" }) }))) : (invoiceQuoteViewComponent || (jsxRuntime.jsx(InvoiceQuoteView, { html: formattedInvoice.html, formattedInvoice: formattedInvoice, backButtonName: backButtonName, onBackButtonClick: onBackButtonClick }))), isInvoicePayable && (jsxRuntime.jsx("div", __assign({ className: "bunny-w-full ".concat(hideDownloadButton || formattedInvoice.isLegacy ? '' : 'pt-12') }, { children: jsxRuntime.jsx(PaymentForm, { entityId: entityId, onPaymentSuccess: onSuccess, onFail: onFail, invoice: formattedInvoice }) })))] })) })));
19277
+ return (jsxRuntime.jsx("div", __assign({ className: "bunny-invoice-container" }, { children: jsxRuntime.jsxs("div", __assign({ className: "bunny-flex bunny-gap-6 ".concat(isMobile ? 'bunny-flex-col bunny-w-full' : '', " ").concat(className) }, { children: [formattedInvoice.isLegacy ? (jsxRuntime.jsx("div", __assign({ className: "bunny-flex bunny-justify-center bunny-w-full" }, { children: jsxRuntime.jsx(LegacyDocument, { documentUuid: formattedInvoice.uuid, documentType: "invoice" }) }))) : (invoiceQuoteViewComponent || (jsxRuntime.jsx(InvoiceQuoteView, { html: formattedInvoice.html, formattedInvoice: formattedInvoice, backButtonName: backButtonName, onBackButtonClick: onBackButtonClick }))), isInvoicePayable && (jsxRuntime.jsx("div", __assign({ className: "bunny-w-full ".concat(hideDownloadButton || formattedInvoice.isLegacy ? '' : 'pt-12') }, { children: jsxRuntime.jsx(PaymentForm, { onPaymentSuccess: onSuccess, onFail: onFail, invoice: formattedInvoice }) })))] })) })));
19296
19278
  }
19297
19279
 
19298
- var MUTATION$8 = function (id) { return "\n query formattedQuote ($id: ID) {\n formattedQuote (id: $id) {\n quote {\n documentTemplateId\n documents { id filename size date url }\n firstInvoice {\n id\n state\n }\n payableId\n id\n payToAccept\n currentPaymentHold {\n createdAt\n expiresAt\n id\n updatedAt\n paymentMethod {\n accountId\n createdAt\n expirationDate\n failureCode\n id\n isDefault\n lastSuccess\n paymentType\n pluginId\n state\n updatedAt\n metadata {\n description\n expiration\n icon\n identifier\n issuer\n kind\n }\n }\n }\n }\n payableId\n acceptedAt\n acceptedByName\n amount\n amountDue\n amountsByPeriod {\n id\n name\n amount\n }\n billingCity\n billingCountry\n billingState\n billingStreet\n billingZip\n contactName\n currency\n customerBillingCity\n customerBillingCountry\n customerBillingState\n customerBillingStreet\n customerBillingZip\n customerName\n discount\n discountValue\n duration\n endDate\n expiresAt\n html\n formattedLines {\n amount\n amountsByPeriod {\n quantity\n id\n name\n startDate\n endDate\n amount\n amountsByTier {\n id\n tier {\n starts\n ends\n price\n }\n quantity\n amount\n }\n prorationRate\n }\n billingPeriodEnd\n billingPeriodStart\n chargeType\n discount\n frequency\n isRamp\n periods\n planName\n position\n price\n priceDecimals\n priceListChargeId\n priceListChargeName\n priceListId\n priceListName\n priceTiers {\n price\n starts\n }\n pricingModel\n productName\n prorationRate\n quantity\n showProductNameOnLineItem\n taxCode\n trialEndDate\n trialStartDate\n unitOfMeasure\n vatCode\n }\n netPaymentDays\n notes\n number\n poNumberRequired\n salesContactEmail\n sharedAt\n startDate\n state\n subtotal\n taxAmount\n taxNumberLabel\n taxNumberRequired\n vendorName\n }\n }"; };
19280
+ var MUTATION$8 = function () { return "\n query formattedQuote ($id: ID) {\n formattedQuote (id: $id) {\n quote {\n documentTemplateId\n documents { id filename size date url }\n firstInvoice {\n id\n state\n }\n payableId\n id\n payToAccept\n currentPaymentHold {\n createdAt\n expiresAt\n id\n updatedAt\n paymentMethod {\n accountId\n createdAt\n expirationDate\n failureCode\n id\n isDefault\n lastSuccess\n paymentType\n pluginId\n state\n updatedAt\n metadata {\n description\n expiration\n icon\n identifier\n issuer\n kind\n }\n }\n }\n }\n payableId\n acceptedAt\n acceptedByName\n amount\n amountDue\n amountsByPeriod {\n id\n name\n amount\n }\n billingCity\n billingCountry\n billingState\n billingStreet\n billingZip\n contactName\n currency\n customerBillingCity\n customerBillingCountry\n customerBillingState\n customerBillingStreet\n customerBillingZip\n customerName\n discount\n discountValue\n duration\n endDate\n expiresAt\n html\n formattedLines {\n amount\n amountsByPeriod {\n quantity\n id\n name\n startDate\n endDate\n amount\n amountsByTier {\n id\n tier {\n starts\n ends\n price\n }\n quantity\n amount\n }\n prorationRate\n }\n billingPeriodEnd\n billingPeriodStart\n chargeType\n discount\n frequency\n isRamp\n periods\n planName\n position\n price\n priceDecimals\n priceListChargeId\n priceListChargeName\n priceListId\n priceListName\n priceTiers {\n price\n starts\n }\n pricingModel\n productName\n prorationRate\n quantity\n showProductNameOnLineItem\n taxCode\n trialEndDate\n trialStartDate\n unitOfMeasure\n vatCode\n }\n netPaymentDays\n notes\n number\n poNumberRequired\n salesContactEmail\n sharedAt\n startDate\n state\n subtotal\n taxAmount\n taxNumberLabel\n taxNumberRequired\n vendorName\n }\n }"; };
19299
19281
  var getFormattedQuote = function (_a) {
19300
- var id = _a.id, token = _a.token, apiHost = _a.apiHost;
19282
+ var token = _a.token, apiHost = _a.apiHost;
19301
19283
  return __awaiter(void 0, void 0, void 0, function () {
19302
19284
  var response;
19303
19285
  return __generator(this, function (_b) {
@@ -19306,12 +19288,11 @@ var getFormattedQuote = function (_a) {
19306
19288
  query: MUTATION$8(),
19307
19289
  token: token,
19308
19290
  apiHost: apiHost,
19309
- vars: { id: id },
19310
19291
  })];
19311
19292
  case 1:
19312
19293
  response = _b.sent();
19313
- if (response === null || response === void 0 ? void 0 : response.formattedQuote.error) {
19314
- throw new Error(response === null || response === void 0 ? void 0 : response.formattedQuote.error);
19294
+ if (response.errors && response.errors.length > 0) {
19295
+ throw new Error(response.errors[0].message);
19315
19296
  }
19316
19297
  return [2 /*return*/, response === null || response === void 0 ? void 0 : response.formattedQuote];
19317
19298
  }
@@ -19606,10 +19587,9 @@ var PaymentHoldModal = function (_a) {
19606
19587
  var visible = _a.visible, setVisible = _a.setVisible, quote = _a.quote;
19607
19588
  var queryClient = reactQuery.useQueryClient();
19608
19589
  var token = useToken();
19609
- var entityId = useCurrentUserData().entityId;
19610
19590
  return (jsxRuntime.jsxs(StyledModal$1, __assign({ centered: true, onCancel: function () {
19611
19591
  setVisible(false);
19612
- }, footer: null, open: visible, width: 600 }, { children: [jsxRuntime.jsx(Title$2, __assign({ className: "mt-4 pb-4 mx-4", level: 5 }, { children: "Pay to accept" })), jsxRuntime.jsx("div", __assign({ className: "mb-4" }, { children: jsxRuntime.jsx(PaymentForm, { entityId: entityId, quote: {
19592
+ }, footer: null, open: visible, width: 600 }, { children: [jsxRuntime.jsx(Title$2, __assign({ className: "mt-4 pb-4 mx-4", level: 5 }, { children: "Pay to accept" })), jsxRuntime.jsx("div", __assign({ className: "mb-4" }, { children: jsxRuntime.jsx(PaymentForm, { quote: {
19613
19593
  amount: quote.amount,
19614
19594
  currencyId: quote.currency,
19615
19595
  id: quote.quote.id,
@@ -19672,18 +19652,10 @@ function ActualQuote() {
19672
19652
  var _f = reactQuery.useQuery({
19673
19653
  queryKey: common.QueryKeyFactory.default.createQuoteKey({ id: id, token: token }),
19674
19654
  queryFn: function () { return __awaiter(_this, void 0, void 0, function () {
19675
- var error_1;
19676
19655
  return __generator(this, function (_a) {
19677
19656
  switch (_a.label) {
19678
- case 0:
19679
- _a.trys.push([0, 2, , 3]);
19680
- return [4 /*yield*/, getFormattedQuote({ token: token, apiHost: apiHost, id: id })];
19657
+ case 0: return [4 /*yield*/, getFormattedQuote({ token: token, apiHost: apiHost })];
19681
19658
  case 1: return [2 /*return*/, _a.sent()];
19682
- case 2:
19683
- error_1 = _a.sent();
19684
- showErrorNotification(error_1.message);
19685
- return [3 /*break*/, 3];
19686
- case 3: return [2 /*return*/];
19687
19659
  }
19688
19660
  });
19689
19661
  }); },
@@ -19698,7 +19670,6 @@ function ActualQuote() {
19698
19670
  }), acceptBoxVisible = _g.acceptBoxVisible, isAccepting = _g.isAccepting, sendAccept = _g.sendAccept, setAcceptBoxVisible = _g.setAcceptBoxVisible, setIsAccepting = _g.setIsAccepting, startAcceptance = _g.startAcceptance, pandadocPollingModalVisible = _g.pandadocPollingModalVisible, setPandadocPollingModalVisible = _g.setPandadocPollingModalVisible, isSendAcceptPending = _g.isSendAcceptPending;
19699
19671
  useSigningComplete({ data: formattedQuote, token: token });
19700
19672
  var isMobile = common.useIsMobile();
19701
- var showErrorNotification = common.useErrorNotification();
19702
19673
  react.useEffect(function () {
19703
19674
  if (formattedQuote) {
19704
19675
  onQuoteLoaded === null || onQuoteLoaded === void 0 ? void 0 : onQuoteLoaded(formattedQuote);
@@ -20018,7 +19989,7 @@ function Transactions(_a) {
20018
19989
  function TransactionsDisplay(_a) {
20019
19990
  var _b, _c;
20020
19991
  var transactions = _a.transactions, onSearchValueChanged = _a.onSearchValueChanged, search = _a.search;
20021
- var _d = react.useContext(TransactionsListContext), showSearchBar = _d.showSearchBar, showTitle = _d.showTitle, title = _d.title, transactionComponent = _d.transactionComponent, useModal = _d.useModal, suppressTransactionDisplay = _d.suppressTransactionDisplay, className = _d.className, shadow = _d.shadow, searchBarClassName = _d.searchBarClassName, style = _d.style, onTransactionClick = _d.onTransactionClick, onTransactionDisplayClose = _d.onTransactionDisplayClose, kindsToShow = _d.kindsToShow, filterTransactions = _d.filterTransactions, sortTransactions = _d.sortTransactions; _d.transactionDateType;
19992
+ var _d = react.useContext(TransactionsListContext), showSearchBar = _d.showSearchBar, showTitle = _d.showTitle, title = _d.title, transactionComponent = _d.transactionComponent, useModal = _d.useModal, suppressTransactionDisplay = _d.suppressTransactionDisplay, className = _d.className, shadow = _d.shadow, searchBarClassName = _d.searchBarClassName, style = _d.style, onTransactionClick = _d.onTransactionClick, onTransactionDisplayClose = _d.onTransactionDisplayClose, kindsToShow = _d.kindsToShow, filterTransactions = _d.filterTransactions, sortTransactions = _d.sortTransactions;
20022
19993
  var columns = react.useContext(TransactionsListContext).columns;
20023
19994
  var darkMode = react.useContext(BunnyContext).darkMode;
20024
19995
  var secondaryColor = react.useContext(BrandContext).secondaryColor;
@@ -20312,7 +20283,7 @@ var getPriceList = function (_a) {
20312
20283
  });
20313
20284
  };
20314
20285
 
20315
- var QUOTE_QUERY = function (id) { return "\n query quote {\n quote ".concat(id ? "(id: ".concat(id, ")") : '', " {\n accountId\n amount\n amountDue\n smallUnitAmountDue\n currencyId\n formattedQuote {\n html\n }\n id\n payableId\n periodAmount\n subtotal\n taxAmount\n startDate\n amountsByPeriod {\n amount\n startDate\n }\n quoteChanges {\n currencyId\n id\n kind\n charges {\n subtotal\n amountsByPeriod {\n amount\n startDate\n }\n amount\n billingPeriod\n currencyId\n feature {\n unitName\n }\n id\n name\n priceListCharge {\n id\n }\n priceList {\n id\n }\n coupon {\n couponCode\n }\n quantity\n kind\n }\n priceList {\n id\n plan {\n name\n }\n product {\n name\n }\n }\n\n }\n }\n }"); };
20286
+ var QUOTE_QUERY = function (id) { return "\n query quote {\n quote ".concat(id ? "(id: ".concat(id, ")") : '', " {\n accountId\n amount\n amountDue\n smallUnitAmountDue\n currencyId\n formattedQuote {\n html\n }\n id\n payableId\n periodAmount\n subtotal\n taxAmount\n startDate\n amountsByPeriod {\n amount\n startDate\n }\n kind\n quoteChanges {\n currencyId\n id\n kind\n charges {\n subtotal\n amountsByPeriod {\n amount\n startDate\n }\n amount\n billingPeriod\n currencyId\n feature {\n unitName\n }\n id\n name\n priceListCharge {\n id\n }\n priceList {\n id\n }\n coupon {\n couponCode\n }\n quantity\n kind\n }\n priceList {\n id\n plan {\n name\n }\n product {\n name\n }\n }\n\n }\n }\n }"); };
20316
20287
  var getQuote = function (_a) {
20317
20288
  var id = _a.id, token = _a.token, apiHost = _a.apiHost;
20318
20289
  return __awaiter(void 0, void 0, void 0, function () {
@@ -20467,6 +20438,45 @@ var useUpdateCoupons = function (_a) {
20467
20438
  };
20468
20439
  };
20469
20440
 
20441
+ var CURRENT_USER_DATA_QUERY = "{\n company {\n name\n }\n currentUser {\n account {\n billingCountry\n currencyId\n }\n authObjectName\n payload {\n returnUrl\n }\n privacyUrl\n termsUrl\n entityId\n }\n }";
20442
+ var getCurrentUserData = function (_a) {
20443
+ var token = _a.token, apiHost = _a.apiHost;
20444
+ return __awaiter(void 0, void 0, void 0, function () {
20445
+ var response;
20446
+ var _b, _c, _d, _e, _f, _g, _h, _j;
20447
+ return __generator(this, function (_k) {
20448
+ switch (_k.label) {
20449
+ case 0: return [4 /*yield*/, common.gqlRequest({
20450
+ query: CURRENT_USER_DATA_QUERY,
20451
+ token: token,
20452
+ apiHost: apiHost,
20453
+ })];
20454
+ case 1:
20455
+ response = _k.sent();
20456
+ return [2 /*return*/, {
20457
+ authObjectName: (_b = response === null || response === void 0 ? void 0 : response.currentUser) === null || _b === void 0 ? void 0 : _b.authObjectName,
20458
+ account: (_c = response === null || response === void 0 ? void 0 : response.currentUser) === null || _c === void 0 ? void 0 : _c.account,
20459
+ companyName: (_d = response === null || response === void 0 ? void 0 : response.company) === null || _d === void 0 ? void 0 : _d.name,
20460
+ returnUrl: (_f = (_e = response === null || response === void 0 ? void 0 : response.currentUser) === null || _e === void 0 ? void 0 : _e.payload) === null || _f === void 0 ? void 0 : _f.returnUrl,
20461
+ privacyUrl: (_g = response === null || response === void 0 ? void 0 : response.currentUser) === null || _g === void 0 ? void 0 : _g.privacyUrl,
20462
+ termsUrl: (_h = response === null || response === void 0 ? void 0 : response.currentUser) === null || _h === void 0 ? void 0 : _h.termsUrl,
20463
+ entityId: (_j = response === null || response === void 0 ? void 0 : response.currentUser) === null || _j === void 0 ? void 0 : _j.entityId,
20464
+ }];
20465
+ }
20466
+ });
20467
+ });
20468
+ };
20469
+
20470
+ var useCurrentUserData = function (token) {
20471
+ var apiHost = react.useContext(BunnyContext).apiHost;
20472
+ var currentUserData = reactQuery.useQuery({
20473
+ queryKey: common.QueryKeyFactory.default.currentUserKey(token),
20474
+ queryFn: function () { return getCurrentUserData({ token: token, apiHost: apiHost }); },
20475
+ enabled: Boolean(token),
20476
+ }).data;
20477
+ return currentUserData || {};
20478
+ };
20479
+
20470
20480
  var BunnyFooterIcon = function (_a) {
20471
20481
  var color = _a.color;
20472
20482
  return (jsxRuntime.jsxs("svg", __assign({ width: "45", height: "15", viewBox: "0 0 39 13", fill: "none", xmlns: "http://www.w3.org/2000/svg" }, { children: [jsxRuntime.jsxs("g", __assign({ clipPath: "url(#clip0_6_851)" }, { children: [jsxRuntime.jsx("path", { className: "bunny-icon-path", d: "M14.5898 7.19708C14.5898 9.35053 13.0926 10.325 11.2495 10.325C9.39955 10.325 7.90234 9.35001 7.90234 7.18967V3.26221H10.1125V7.00052C10.1125 7.87719 10.5855 8.27725 11.2495 8.27725C11.9061 8.27725 12.3865 7.87719 12.3865 7.00052V3.26221H14.5898V7.19708Z", fill: color }), jsxRuntime.jsx("path", { className: "bunny-icon-path", d: "M31.8943 12.9625H29.4793L31.8523 8.62816L28.9355 3.26221H31.4708L33.0457 6.35524L34.5924 3.26221H37.0075L31.8943 12.9625Z", fill: color }), jsxRuntime.jsx("path", { className: "bunny-icon-path", d: "M15.1602 5.96827C15.1602 3.8148 16.6574 2.84033 18.5005 2.84033C20.3504 2.84033 21.8476 3.81533 21.8476 5.97568V10.1473H19.6374V6.16483C19.6374 5.28815 19.1645 4.8881 18.5005 4.8881C17.8439 4.8881 17.3634 5.28815 17.3634 6.16483V10.1473H15.1602V5.96827Z", fill: color }), jsxRuntime.jsx("path", { className: "bunny-icon-path", d: "M22.4316 5.96827C22.4316 3.8148 23.9289 2.84033 25.7719 2.84033C27.6219 2.84033 29.1191 3.81533 29.1191 5.97568V10.1473H26.9089V6.16483C26.9089 5.28815 26.4359 4.8881 25.7719 4.8881C25.1154 4.8881 24.6349 5.28815 24.6349 6.16483V10.1473H22.4316V5.96827Z", fill: color }), jsxRuntime.jsx("path", { className: "bunny-icon-path", d: "M7.40511 6.68957C7.40511 8.7236 6.02815 10.3227 4.17816 10.3227C3.23907 10.3227 2.61071 9.94378 2.19358 9.40371V10.1404H0.0605469V0.0405273H2.26381V3.91939C2.68041 3.42158 3.28802 3.07069 4.17763 3.07069C6.02759 3.07069 7.40511 4.66981 7.40511 6.68957ZM2.17229 6.69642C2.17229 7.60802 2.77937 8.2744 3.64823 8.2744C4.53783 8.2744 5.13107 7.59372 5.13107 6.69642C5.13107 5.79912 4.53783 5.11844 3.64823 5.11844C2.77937 5.11844 2.17229 5.78482 2.17229 6.69642Z", fill: color }), jsxRuntime.jsx("path", { className: "bunny-icon-path", d: "M38.966 8.94801C38.966 9.76181 38.2668 10.4631 37.4618 10.4631C36.6499 10.4631 35.9434 9.76181 35.9434 8.94801C35.9434 8.14846 36.6494 7.46094 37.4618 7.46094C38.2668 7.46094 38.966 8.14846 38.966 8.94801Z", fill: color })] })), jsxRuntime.jsx("defs", { children: jsxRuntime.jsx("clipPath", __assign({ id: "clip0_6_851" }, { children: jsxRuntime.jsx("rect", { width: "39", height: "13", fill: "white" }) })) })] })));
@@ -20475,7 +20485,8 @@ var BunnyFooterIcon = function (_a) {
20475
20485
  var Text$g = antd.Typography.Text;
20476
20486
  var Footer = function (_a) {
20477
20487
  var className = _a.className;
20478
- var _b = useCurrentUserData(), privacyUrl = _b.privacyUrl, termsUrl = _b.termsUrl;
20488
+ var token = useToken();
20489
+ var _b = useCurrentUserData(token), privacyUrl = _b.privacyUrl, termsUrl = _b.termsUrl;
20479
20490
  var isMobile = common.useIsMobile();
20480
20491
  return (jsxRuntime.jsxs("div", __assign({ className: "bunny-flex bunny-items-center bunny-justify-between bunny-shrink-0 ".concat(isMobile ? 'bunny-flex-col bunny-gap-2' : '', " ").concat(className) }, { children: [(termsUrl || privacyUrl) && (jsxRuntime.jsxs("div", __assign({ className: "bunny-flex bunny-items-center bunny-gap-3" }, { children: [termsUrl && (jsxRuntime.jsx(StyedLink, __assign({ className: "bunny-text-xs bunny-text-slate-400", href: termsUrl, rel: "noopener noreferrer", target: "_blank", type: "text" }, { children: "Terms" }))), privacyUrl && (jsxRuntime.jsx(StyedLink, __assign({ className: "bunny-text-xs bunny-text-slate-400", href: privacyUrl, rel: "noopener noreferrer", target: "_blank", type: "text" }, { children: "Privacy" })))] }))), jsxRuntime.jsx(BunnyMarketingLink, {})] })));
20481
20492
  };
@@ -20488,6 +20499,22 @@ var StyedLink = styled__default["default"].a(templateObject_1$5 || (templateObje
20488
20499
  var StyledBunnyLink = styled__default["default"](StyedLink)(templateObject_2$1 || (templateObject_2$1 = __makeTemplateObject(["\n &:hover {\n color: ", " !important;\n }\n"], ["\n &:hover {\n color: ", " !important;\n }\n"])), common.PRIMARY_COLOR);
20489
20500
  var templateObject_1$5, templateObject_2$1;
20490
20501
 
20502
+ function shouldShowCouponEditor(quote, activeCouponsExist, upgradingSubscription) {
20503
+ var _a;
20504
+ var upgradingFromTrial = ((_a = upgradingSubscription === null || upgradingSubscription === void 0 ? void 0 : upgradingSubscription.state) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === common.SubscriptionState.TRIAL;
20505
+ function upgradingFromFree() {
20506
+ var totalPrice = upgradingSubscription === null || upgradingSubscription === void 0 ? void 0 : upgradingSubscription.charges.reduce(function (acc, charge) { return acc + Number((charge === null || charge === void 0 ? void 0 : charge.discountedPrice) || 0); }, 0);
20507
+ return totalPrice === 0;
20508
+ }
20509
+ if (quote.kind === common.QuoteChangeKind.SUBSCRIBE) {
20510
+ return activeCouponsExist;
20511
+ }
20512
+ else if (quote.kind === common.QuoteChangeKind.ADJUSTMENT) {
20513
+ return activeCouponsExist && (upgradingFromTrial || upgradingFromFree());
20514
+ }
20515
+ return false;
20516
+ }
20517
+
20491
20518
  function CouponEditor(_a) {
20492
20519
  var className = _a.className, onAddCoupon = _a.onAddCoupon, isAddingCoupon = _a.isAddingCoupon, couponCode = _a.couponCode, setCouponCode = _a.setCouponCode;
20493
20520
  function handleAddCoupon() {
@@ -20501,9 +20528,12 @@ function CouponEditor(_a) {
20501
20528
  return (jsxRuntime.jsx("div", __assign({ className: "bunny-flex bunny-flex-col bunny-gap-2 ".concat(className) }, { children: jsxRuntime.jsxs("div", __assign({ className: "bunny-flex bunny-flex-row bunny-gap-2" }, { children: [jsxRuntime.jsx(antd.Input, { value: couponCode, onChange: function (e) { return setCouponCode(e.target.value); }, placeholder: "Coupon code", disabled: isAddingCoupon, size: "small" }), jsxRuntime.jsx(antd.Button, __assign({ loading: isAddingCoupon, type: "primary", onClick: handleAddCoupon, disabled: couponCode.length === 0 }, { children: "Apply" }))] })) })));
20502
20529
  }
20503
20530
 
20531
+ var SubscriptionsContext = react.createContext({});
20532
+
20504
20533
  var Text$f = antd.Typography.Text;
20505
20534
  function CheckoutSummary(_a) {
20506
20535
  var quote = _a.quote, className = _a.className, onAddCoupon = _a.onAddCoupon, onRemoveCoupon = _a.onRemoveCoupon, isRemovingCoupon = _a.isRemovingCoupon, priceListData = _a.priceListData, isAddingCoupon = _a.isAddingCoupon, couponCode = _a.couponCode, setCouponCode = _a.setCouponCode, activeCouponsExist = _a.activeCouponsExist;
20536
+ var upgradingSubscription = react.useContext(SubscriptionsContext).upgradingSubscription;
20507
20537
  return (jsxRuntime.jsxs("div", __assign({ className: "".concat(className, " bunny-space-y-4") }, { children: [jsxRuntime.jsxs(Text$f, { children: [jsxRuntime.jsxs("div", __assign({ className: "bunny-text-lg bunny-font-medium bunny-mb-4" }, { children: ["Checkout summary - ", priceListData === null || priceListData === void 0 ? void 0 : priceListData.product.name, " ", priceListData === null || priceListData === void 0 ? void 0 : priceListData.name] })), jsxRuntime.jsx("div", __assign({ className: "bunny-space-y-4" }, { children: quote === null || quote === void 0 ? void 0 : quote.quoteChanges.map(function (quoteChange) {
20508
20538
  return quoteChange === null || quoteChange === void 0 ? void 0 : quoteChange.charges.map(function (charge) {
20509
20539
  var _a;
@@ -20519,7 +20549,8 @@ function CheckoutSummary(_a) {
20519
20549
  onRemoveCoupon((_b = charge.coupon) === null || _b === void 0 ? void 0 : _b.couponCode);
20520
20550
  }, className: "bunny-text-orange-500 hover:bunny-text-orange-400 bunny-cursor-pointer" }, { children: "Remove" }))) : (jsxRuntime.jsx("div", { children: charge.quantity })) })), jsxRuntime.jsx("div", __assign({ className: "bunny-col-span-1 bunny-text-right" }, { children: common.formatCurrency(multiplier * (charge.subtotal || 0), charge.currencyId) }))] }), charge.id));
20521
20551
  });
20522
- }) })), jsxRuntime.jsx(CheckoutSummaryDivider, {}), jsxRuntime.jsxs("div", __assign({ className: "bunny-space-y-4" }, { children: [jsxRuntime.jsxs("div", __assign({ className: "bunny-flex bunny-justify-between" }, { children: [jsxRuntime.jsx("div", { children: "Subtotal" }), jsxRuntime.jsx("div", { children: common.formatCurrency(quote.subtotal, quote.currencyId) })] })), jsxRuntime.jsxs("div", __assign({ className: "bunny-flex bunny-justify-between" }, { children: [jsxRuntime.jsx("div", { children: "Taxes" }), jsxRuntime.jsx("div", { children: common.formatCurrency(quote.taxAmount, quote.currencyId) })] }))] })), jsxRuntime.jsx(CheckoutSummaryDivider, {}), jsxRuntime.jsxs("div", __assign({ className: "bunny-flex bunny-justify-between" }, { children: [jsxRuntime.jsx("div", { children: "Total" }), jsxRuntime.jsx("div", { children: common.formatCurrency(quote.amountDue, quote.currencyId) })] }))] }), activeCouponsExist && (jsxRuntime.jsx(CouponEditor, { className: "bunny-w-full", quote: quote, onAddCoupon: onAddCoupon, isAddingCoupon: isAddingCoupon, couponCode: couponCode, setCouponCode: setCouponCode }))] })));
20552
+ }) })), jsxRuntime.jsx(CheckoutSummaryDivider, {}), jsxRuntime.jsxs("div", __assign({ className: "bunny-space-y-4" }, { children: [jsxRuntime.jsxs("div", __assign({ className: "bunny-flex bunny-justify-between" }, { children: [jsxRuntime.jsx("div", { children: "Subtotal" }), jsxRuntime.jsx("div", { children: common.formatCurrency(quote.subtotal, quote.currencyId) })] })), jsxRuntime.jsxs("div", __assign({ className: "bunny-flex bunny-justify-between" }, { children: [jsxRuntime.jsx("div", { children: "Taxes" }), jsxRuntime.jsx("div", { children: common.formatCurrency(quote.taxAmount, quote.currencyId) })] }))] })), jsxRuntime.jsx(CheckoutSummaryDivider, {}), jsxRuntime.jsxs("div", __assign({ className: "bunny-flex bunny-justify-between" }, { children: [jsxRuntime.jsx("div", { children: "Total" }), jsxRuntime.jsx("div", { children: common.formatCurrency(quote.amountDue, quote.currencyId) })] }))] }), upgradingSubscription &&
20553
+ shouldShowCouponEditor(quote, activeCouponsExist, upgradingSubscription) && (jsxRuntime.jsx(CouponEditor, { className: "bunny-w-full", quote: quote, onAddCoupon: onAddCoupon, isAddingCoupon: isAddingCoupon, couponCode: couponCode, setCouponCode: setCouponCode }))] })));
20523
20554
  }
20524
20555
  var CheckoutSummaryDivider = function () {
20525
20556
  return (jsxRuntime.jsx("div", __assign({ className: "bunny-my-2" }, { children: jsxRuntime.jsx(antd.Divider, { className: "m-0" }) })));
@@ -20528,8 +20559,7 @@ var CheckoutSummaryDivider = function () {
20528
20559
  var Title$1 = antd.Typography.Title;
20529
20560
  function PaymentForms(_a) {
20530
20561
  var quote = _a.quote, handlePaymentSuccess = _a.handlePaymentSuccess, handlePaymentFail = _a.handlePaymentFail, handleSubmit = _a.handleSubmit, proceedingToPayment = _a.proceedingToPayment, accountId = _a.accountId, overrideToken = _a.overrideToken, customCheckoutFunction = _a.customCheckoutFunction, defaultValues = _a.defaultValues;
20531
- var entityId = useCurrentUserData().entityId;
20532
- return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: quote ? (jsxRuntime.jsx(jsxRuntime.Fragment, { children: overrideToken ? (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(Title$1, __assign({ className: "bunny-px-4 bunny-m-0", level: 2 }, { children: "Payment" })), jsxRuntime.jsx("div", __assign({ className: "bunny-overflow-y-auto bunny-max-h-[calc(100vh-10rem)]" }, { children: jsxRuntime.jsx(PaymentForm, { entityId: entityId, onFail: handlePaymentFail, onPaymentSuccess: handlePaymentSuccess, accountId: accountId, quote: quote, overrideToken: overrideToken, customCheckoutFunction: customCheckoutFunction }) }))] })) : null })) : (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(Title$1, __assign({ className: "bunny-px-4 bunny-m-0", level: 2 }, { children: "Signup" })), jsxRuntime.jsx(InitialSignupForm, { className: "bunny-px-4", onSubmit: handleSubmit, submitting: proceedingToPayment, defaultValues: defaultValues })] })) }));
20562
+ return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: quote ? (jsxRuntime.jsx(jsxRuntime.Fragment, { children: overrideToken ? (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(Title$1, __assign({ className: "bunny-px-4 bunny-m-0", level: 2 }, { children: "Payment" })), jsxRuntime.jsx("div", __assign({ className: "bunny-overflow-y-auto bunny-max-h-[calc(100vh-10rem)]" }, { children: jsxRuntime.jsx(PaymentForm, { onFail: handlePaymentFail, onPaymentSuccess: handlePaymentSuccess, accountId: accountId, quote: quote, overrideToken: overrideToken, customCheckoutFunction: customCheckoutFunction }) }))] })) : null })) : (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(Title$1, __assign({ className: "bunny-px-4 bunny-m-0", level: 2 }, { children: "Signup" })), jsxRuntime.jsx(InitialSignupForm, { className: "bunny-px-4", onSubmit: handleSubmit, submitting: proceedingToPayment, defaultValues: defaultValues })] })) }));
20533
20563
  }
20534
20564
  function InitialSignupForm(_a) {
20535
20565
  var className = _a.className, onSubmit = _a.onSubmit, submitting = _a.submitting, defaultValues = _a.defaultValues;
@@ -20840,8 +20870,22 @@ var useQuoteDelete = function () {
20840
20870
  });
20841
20871
  }); };
20842
20872
  };
20873
+ var useQuoteSubscriptionActivate = function () {
20874
+ var graphQLRequest = useGraphQLRequest();
20875
+ return function (subscriptionId, apiHost, token) { return __awaiter(void 0, void 0, void 0, function () {
20876
+ var response;
20877
+ return __generator(this, function (_a) {
20878
+ switch (_a.label) {
20879
+ case 0: return [4 /*yield*/, graphQLRequest("mutation QuoteSubscriptionActivate($subscriptionId: ID!) {\n quoteSubscriptionActivate(subscriptionId: $subscriptionId) {\n quote {\n id\n }\n }\n }", apiHost, token, { subscriptionId: subscriptionId })];
20880
+ case 1:
20881
+ response = _a.sent();
20882
+ return [2 /*return*/, response];
20883
+ }
20884
+ });
20885
+ }); };
20886
+ };
20843
20887
 
20844
- var SUBSCRIPTIONS_QUERY = "\nquery subscriptions {\n subscriptions {\n nodes {\n cancellationDate\n currencyId\n endDate\n evergreen\n id\n period\n plan { id name selfServiceBuy selfServiceCancel selfServiceRenew }\n priceList { id periodMonths }\n product { id name showProductNameOnLineItem }\n startDate\n state\n trialEndDate\n trialPeriod\n trialStartDate\n daysLeftInTrial\n charges {\n priceListCharge {\n priceListChargeTiers {\n price\n starts\n }\n featureAddon\n id\n }\n amount\n billingPeriod\n chargeType\n discount\n discountedPrice\n endDate\n expired\n feature { name }\n id\n isAmendment\n isRamp\n kind\n name\n periodPrice\n price\n priceDecimals\n priceListChargeId\n priceTiers { starts price }\n pricingModel\n quantity\n selfServiceQuantity\n startDate\n trial\n }\n }\n }\n }";
20888
+ var SUBSCRIPTIONS_QUERY = "\nquery subscriptions {\n subscriptions {\n nodes {\n cancellationDate\n currencyId\n endDate\n evergreen\n id\n period\n plan { id name selfServiceBuy selfServiceCancel selfServiceRenew }\n priceList { id periodMonths }\n product { id name showProductNameOnLineItem }\n startDate\n state\n trialEndDate\n trialPeriod\n trialStartDate\n daysLeftInTrial\n trialExpirationAction\n charges {\n priceListCharge {\n priceListChargeTiers {\n price\n starts\n }\n featureAddon\n id\n }\n amount\n billingPeriod\n chargeType\n discount\n discountedPrice\n endDate\n expired\n feature { name }\n id\n isAmendment\n isRamp\n kind\n name\n periodPrice\n price\n priceDecimals\n priceListChargeId\n priceTiers { starts price }\n pricingModel\n quantity\n selfServiceQuantity\n startDate\n trial\n }\n }\n }\n }";
20845
20889
  var getSubscriptions = function (_a) {
20846
20890
  var apiHost = _a.apiHost, isInPreviewMode = _a.isInPreviewMode, token = _a.token;
20847
20891
  return __awaiter(void 0, void 0, void 0, function () {
@@ -20927,7 +20971,7 @@ var accountUpdate = function (_a) {
20927
20971
  });
20928
20972
  };
20929
20973
 
20930
- var COUNTRIES_REQUIRING_STATE = ["US", "CA"];
20974
+ var COUNTRIES_REQUIRING_STATE = ['US', 'CA'];
20931
20975
  var TaxationForm = function (_a) {
20932
20976
  var account = _a.account, quote = _a.quote;
20933
20977
  // Hooks
@@ -20955,19 +20999,18 @@ var TaxationForm = function (_a) {
20955
20999
  }); },
20956
21000
  onSuccess: function () {
20957
21001
  queryClient.invalidateQueries({
20958
- queryKey: ["getTaxationRequiredAccountFields", token],
21002
+ queryKey: ['getTaxationRequiredAccountFields', token],
20959
21003
  });
20960
21004
  },
20961
21005
  }), updateAccount = _b.mutate, isUpdatingAccount = _b.isPending;
20962
- return (jsxRuntime.jsxs(antd.Form, __assign({ className: "bunny-flex bunny-flex-col bunny-gap-4", form: form, initialValues: account, layout: "vertical", onFinish: updateAccount }, { children: [jsxRuntime.jsx(antd.Form.Item, __assign({ label: "Billing street", name: "billingStreet" }, { children: jsxRuntime.jsx(antd.Input, { placeholder: "Street" }) })), jsxRuntime.jsx(antd.Form.Item, __assign({ label: "Billing city", name: "billingCity" }, { children: jsxRuntime.jsx(antd.Input, { placeholder: "City" }) })), jsxRuntime.jsx(FormBillingState, { form: form }), jsxRuntime.jsx(antd.Form.Item, __assign({ label: "Billing country", name: "billingCountry", rules: [{ required: true }] }, { children: jsxRuntime.jsx(antd.Select, { options: common.Lists.COUNTRY_LIST, placeholder: "Select a country", showSearch: true, filterOption: function (input, option) {
21006
+ return (jsxRuntime.jsxs(antd.Form, __assign({ className: "bunny-flex bunny-flex-col bunny-gap-4", form: form, initialValues: account, layout: "vertical", onFinish: updateAccount }, { children: [jsxRuntime.jsx(antd.Form.Item, __assign({ label: "Billing street", name: "billingStreet" }, { children: jsxRuntime.jsx(antd.Input, { placeholder: "Street" }) })), jsxRuntime.jsx(antd.Form.Item, __assign({ label: "Billing city", name: "billingCity" }, { children: jsxRuntime.jsx(antd.Input, { placeholder: "City" }) })), jsxRuntime.jsx(FormBillingState, {}), jsxRuntime.jsx(antd.Form.Item, __assign({ label: "Billing country", name: "billingCountry", rules: [{ required: true }] }, { children: jsxRuntime.jsx(antd.Select, { options: common.Lists.COUNTRY_LIST, placeholder: "Select a country", showSearch: true, filterOption: function (input, option) {
20963
21007
  var _a, _b;
20964
- return ((_a = option === null || option === void 0 ? void 0 : option.label) !== null && _a !== void 0 ? _a : "").toLowerCase().includes(input.toLowerCase()) ||
20965
- ((_b = option === null || option === void 0 ? void 0 : option.value) !== null && _b !== void 0 ? _b : "").toLowerCase().includes(input.toLowerCase());
21008
+ return ((_a = option === null || option === void 0 ? void 0 : option.label) !== null && _a !== void 0 ? _a : '').toLowerCase().includes(input.toLowerCase()) ||
21009
+ ((_b = option === null || option === void 0 ? void 0 : option.value) !== null && _b !== void 0 ? _b : '').toLowerCase().includes(input.toLowerCase());
20966
21010
  } }) })), jsxRuntime.jsx(antd.Form.Item, __assign({ label: "Billing zip", name: "billingZip" }, { children: jsxRuntime.jsx(antd.Input, { placeholder: "Zip" }) })), jsxRuntime.jsx(antd.Form.Item, { children: jsxRuntime.jsx(antd.Button, __assign({ className: "bunny-w-full", disabled: isUpdatingAccount, htmlType: "submit", type: "primary" }, { children: "Submit" })) })] })));
20967
21011
  };
20968
- var FormBillingState = function (_a) {
20969
- _a.form;
20970
- var billingCountry = antd.Form.useWatch("billingCountry");
21012
+ var FormBillingState = function () {
21013
+ var billingCountry = antd.Form.useWatch('billingCountry');
20971
21014
  var billingStateRequired = COUNTRIES_REQUIRING_STATE.includes(billingCountry);
20972
21015
  return (jsxRuntime.jsx(antd.Form.Item, __assign({ label: "Billing state", name: "billingState", rules: [{ required: billingStateRequired }] }, { children: jsxRuntime.jsx(antd.Input, { placeholder: "State" }) })));
20973
21016
  };
@@ -20977,11 +21020,11 @@ var QuoteCheckout = function (_a) {
20977
21020
  var _b, _c;
20978
21021
  var account = _a.account, onSuccess = _a.onSuccess, onFail = _a.onFail, quote = _a.quote, taxationRequiredAccountFields = _a.taxationRequiredAccountFields, onRecalculateTaxes = _a.onRecalculateTaxes;
20979
21022
  var apiHost = react.useContext(BunnyContext).apiHost;
21023
+ var upgradingSubscription = react.useContext(SubscriptionsContext).upgradingSubscription;
20980
21024
  var token = useToken();
20981
21025
  var isMobile = common.useIsMobile();
20982
21026
  var _d = react.useState(false), isSaving = _d[0], setIsSaving = _d[1];
20983
21027
  var paymentRequired = getQuoteAmountDue(quote) > 0;
20984
- var entityId = useCurrentUserData().entityId;
20985
21028
  var queryClient = reactQuery.useQueryClient();
20986
21029
  var _e = react.useState(''), couponCode = _e[0], setCouponCode = _e[1];
20987
21030
  var _f = useUpdateCoupons({
@@ -21042,7 +21085,8 @@ var QuoteCheckout = function (_a) {
21042
21085
  }
21043
21086
  if (taxationRequiredAccountFields)
21044
21087
  return (jsxRuntime.jsx(PaymentFormWrapper, __assign({ setMaxHeight: false }, { children: jsxRuntime.jsx(TaxationForm, { account: account, quote: quote }) })));
21045
- return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: paymentRequired ? (jsxRuntime.jsxs("div", __assign({ className: "bunny-flex bunny-flex-col bunny-gap-2 bunny-w-full" }, { children: [jsxRuntime.jsx(PaymentForm, { entityId: entityId, onFail: onFail, onPaymentSuccess: onSuccess, quote: quote }), (couponsOnQuote === null || couponsOnQuote === void 0 ? void 0 : couponsOnQuote.length) === 0 ? (jsxRuntime.jsx(jsxRuntime.Fragment, { children: activeCouponsExist && (jsxRuntime.jsx(CouponEditor, { className: "bunny-px-4 bunny-pt-1", quote: quote, onAddCoupon: addCoupon, isAddingCoupon: isAddingCoupon, couponCode: couponCode, setCouponCode: setCouponCode })) })) : (jsxRuntime.jsx(antd.Button, __assign({ type: "link", loading: isRemovingCoupon, onClick: function () {
21088
+ return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: paymentRequired ? (jsxRuntime.jsxs("div", __assign({ className: "bunny-flex bunny-flex-col bunny-gap-2 bunny-w-full" }, { children: [jsxRuntime.jsx(PaymentForm, { onFail: onFail, onPaymentSuccess: onSuccess, quote: quote }), (couponsOnQuote === null || couponsOnQuote === void 0 ? void 0 : couponsOnQuote.length) === 0 ? (jsxRuntime.jsx(jsxRuntime.Fragment, { children: upgradingSubscription &&
21089
+ shouldShowCouponEditor(quote, activeCouponsExist, upgradingSubscription) && (jsxRuntime.jsx(CouponEditor, { className: "bunny-px-4 bunny-pt-1", quote: quote, onAddCoupon: addCoupon, isAddingCoupon: isAddingCoupon, couponCode: couponCode, setCouponCode: setCouponCode })) })) : (jsxRuntime.jsx(antd.Button, __assign({ type: "link", loading: isRemovingCoupon, onClick: function () {
21046
21090
  couponsOnQuote === null || couponsOnQuote === void 0 ? void 0 : couponsOnQuote.forEach(function (couponCharge) {
21047
21091
  var _a;
21048
21092
  var couponCode = (_a = couponCharge === null || couponCharge === void 0 ? void 0 : couponCharge.coupon) === null || _a === void 0 ? void 0 : _a.couponCode;
@@ -21191,8 +21235,6 @@ var PageTitle = function (_a) {
21191
21235
  } })), title] })));
21192
21236
  };
21193
21237
 
21194
- var SubscriptionsContext = react.createContext({});
21195
-
21196
21238
  var QUOTE_CHARGE_UPDATE = "\n mutation QuoteChargeUpdate (\n $discount: Float,\n $endDate: ISO8601Date,\n $name: String,\n $price: Float,\n $quantity: Int,\n $quoteChargeId: ID!\n $startDate: ISO8601Date\n $subtotal: Float,\n ) {\n quoteChargeUpdate(\n discount: $discount\n endDate: $endDate\n name: $name\n price: $price\n quantity: $quantity\n quoteChargeId: $quoteChargeId\n startDate: $startDate\n subtotal: $subtotal\n ) {\n quoteCharge {\n id\n }\n }\n }\n";
21197
21239
  var quoteChargeUpdate = function (_a) {
21198
21240
  var discount = _a.discount, name = _a.name, price = _a.price, quantity = _a.quantity, quoteChargeId = _a.quoteChargeId, startDate = _a.startDate, subtotal = _a.subtotal, apiHost = _a.apiHost, token = _a.token;
@@ -21284,10 +21326,112 @@ var billingPeriodConverter = function (period) {
21284
21326
  return 12;
21285
21327
  };
21286
21328
 
21329
+ var canShowQuantitiesInput = function (charge, subscription) {
21330
+ // Check if the subscription is active, pending, or in trial,
21331
+ // the pricing model is not flat,
21332
+ // and if it's not a trial, also check if the current charge is the last one in the subscription.
21333
+ var _a, _b, _c;
21334
+ var isActiveSubscription = ((_a = subscription.state) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === common.SubscriptionState.ACTIVE;
21335
+ var isPendingSubscription = ((_b = subscription.state) === null || _b === void 0 ? void 0 : _b.toUpperCase()) === common.SubscriptionState.PENDING;
21336
+ var isTrialSubscription = ((_c = subscription.state) === null || _c === void 0 ? void 0 : _c.toUpperCase()) === common.SubscriptionState.TRIAL;
21337
+ var isFlatPricing = charge.pricingModel === 'FLAT';
21338
+ var shouldProcessCharge = (isActiveSubscription || isPendingSubscription || isTrialSubscription) &&
21339
+ !isFlatPricing &&
21340
+ charge.selfServiceQuantity &&
21341
+ !charge.expired;
21342
+ // Now you can use the value of shouldProcessCharge to determine whether to process the charge.
21343
+ return shouldProcessCharge;
21344
+ };
21345
+ var createQuoteParams = function (quote, subscriptionQuantity, editedSubscription) {
21346
+ var quoteChange = quote.quoteChanges.find(function (quoteChange) { return quoteChange.priceList.id === (editedSubscription === null || editedSubscription === void 0 ? void 0 : editedSubscription.subscription.priceList.id); });
21347
+ var quoteChangeCharge = quoteChange === null || quoteChange === void 0 ? void 0 : quoteChange.charges.find(function (charge) { return charge.priceListCharge.id === editedSubscription.chargeId; });
21348
+ var charges = [
21349
+ {
21350
+ id: quoteChangeCharge.id,
21351
+ quantity: editedSubscription.quantity - subscriptionQuantity,
21352
+ },
21353
+ ];
21354
+ return { charges: charges, quoteChange: quoteChange };
21355
+ };
21356
+ var canShowChangeQuantities = function (_a) {
21357
+ var subscriptions = _a.subscriptions;
21358
+ return subscriptions === null || subscriptions === void 0 ? void 0 : subscriptions.some(function (subscription) {
21359
+ return subscription.charges.some(function (charge) {
21360
+ return canShowQuantitiesInput(charge, subscription);
21361
+ });
21362
+ });
21363
+ };
21364
+ var canSubscriptionUpgradeFromTrial = function (subscription) {
21365
+ var _a;
21366
+ return (((_a = subscription.state) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === common.SubscriptionState.TRIAL &&
21367
+ subscription.plan.selfServiceBuy) ||
21368
+ false;
21369
+ };
21370
+ var isSubscriptionNotActive = function (subscription) {
21371
+ var _a, _b;
21372
+ return ((_a = subscription.state) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === common.SubscriptionState.EXPIRED ||
21373
+ ((_b = subscription.state) === null || _b === void 0 ? void 0 : _b.toUpperCase()) === common.SubscriptionState.CANCELED;
21374
+ };
21375
+ var isSubscriptionActiveOrPending = function (subscription) {
21376
+ var _a, _b;
21377
+ return ((_a = subscription.state) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === common.SubscriptionState.ACTIVE ||
21378
+ ((_b = subscription.state) === null || _b === void 0 ? void 0 : _b.toUpperCase()) === common.SubscriptionState.PENDING;
21379
+ };
21380
+ var isSubscriptionTrial = function (subscription) { var _a; return ((_a = subscription.state) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === common.SubscriptionState.TRIAL; };
21381
+ // Helper function to check if charge is a discount
21382
+ var isDiscount = function (kind) {
21383
+ return kind === common.QuoteChangeKind.DISCOUNT || kind === common.QuoteChangeKind.FREE_PERIOD_DISCOUNT;
21384
+ };
21385
+ var hasPriceTiers = function (charge) {
21386
+ var _a;
21387
+ return Boolean((_a = charge === null || charge === void 0 ? void 0 : charge.priceTiers) === null || _a === void 0 ? void 0 : _a.length);
21388
+ };
21389
+ var hasMultiplePriceTiers = function (charge) {
21390
+ var _a;
21391
+ return ((_a = charge === null || charge === void 0 ? void 0 : charge.priceTiers) === null || _a === void 0 ? void 0 : _a.length) > 1;
21392
+ };
21393
+ var getApplicablePriceTier = function (charge, currencyId, priceDecimals) {
21394
+ var _a;
21395
+ if (!((_a = charge.priceTiers) === null || _a === void 0 ? void 0 : _a.length))
21396
+ return '';
21397
+ var selectedTier;
21398
+ // For TIERED pricing model: always show the first tier
21399
+ if (charge.pricingModel === common.PricingModel.TIERED) {
21400
+ selectedTier = charge.priceTiers[0];
21401
+ }
21402
+ // For VOLUME and BANDS pricing models: find the tier that contains the current quantity
21403
+ else if (charge.pricingModel === common.PricingModel.VOLUME ||
21404
+ charge.pricingModel === common.PricingModel.BANDS) {
21405
+ // Find the appropriate tier based on quantity
21406
+ selectedTier = charge.priceTiers.find(function (tier, index) {
21407
+ var nextTier = charge.priceTiers[index + 1];
21408
+ var tierStart = tier.starts;
21409
+ var tierEnd = nextTier ? nextTier.starts - 1 : Infinity;
21410
+ return charge.quantity >= tierStart && charge.quantity <= tierEnd;
21411
+ });
21412
+ // Fallback to first tier if no tier found (shouldn't happen with proper data)
21413
+ selectedTier = selectedTier || charge.priceTiers[0];
21414
+ }
21415
+ // Default fallback for any other pricing models
21416
+ else {
21417
+ selectedTier = charge.priceTiers[0];
21418
+ }
21419
+ if (!selectedTier)
21420
+ return '';
21421
+ // Calculate the tier range for display
21422
+ var tierIndex = charge.priceTiers.indexOf(selectedTier);
21423
+ var starts = selectedTier.starts;
21424
+ var nextTier = charge.priceTiers[tierIndex + 1];
21425
+ var ends = nextTier ? nextTier.starts - 1 : '∞';
21426
+ return hasMultiplePriceTiers(charge)
21427
+ ? "".concat(starts, "-").concat(ends, ": ").concat(common.formatCurrency(selectedTier.price, currencyId, priceDecimals))
21428
+ : "".concat(common.formatCurrency(selectedTier.price, currencyId, priceDecimals));
21429
+ };
21430
+
21287
21431
  var removeHTMLTagsRegex = /<br>(?=(?:\s*<[^>]*>)*$)|(<br>)|<[^>]*>/gi;
21288
21432
  // Description is a string that can contain HTML tags. We want to remove all HTML tags except <br> tags.
21289
21433
  var createPlanDescription = function (priceList) {
21290
- return (priceList.plan.description || '').replace(removeHTMLTagsRegex, function (x, y) {
21434
+ return (priceList.plan.description || '').replace(removeHTMLTagsRegex, function (_, y) {
21291
21435
  return y ? ' & ' : '';
21292
21436
  });
21293
21437
  };
@@ -21329,25 +21473,17 @@ var getActivePlanPriceData = function (priceList, selectedPriceList) {
21329
21473
  };
21330
21474
  };
21331
21475
  var isPriceListDisabled = function (_a) {
21332
- var priceList = _a.priceList, subscriptions = _a.subscriptions, upgradingSubscription = _a.upgradingSubscription, canPurchaseFeatureAddons = _a.canPurchaseFeatureAddons;
21333
- // Plan already has a subscription
21334
- var existingSubscription = subscriptions === null || subscriptions === void 0 ? void 0 : subscriptions.find(function (subscription) {
21335
- var _a, _b;
21336
- var isCurrentUpgradingSubscription = subscription.id === (upgradingSubscription === null || upgradingSubscription === void 0 ? void 0 : upgradingSubscription.id);
21337
- var subscriptionAlreadyExists = isCurrentUpgradingSubscription
21338
- ? subscription.priceList.id === priceList.id
21339
- : subscription.plan.id === priceList.plan.id;
21340
- return (subscriptionAlreadyExists &&
21341
- subscription.plan.id === priceList.plan.id &&
21342
- ((_a = subscription.state) === null || _a === void 0 ? void 0 : _a.toUpperCase()) !== common.SubscriptionState.CANCELED &&
21343
- ((_b = subscription.state) === null || _b === void 0 ? void 0 : _b.toUpperCase()) !== common.SubscriptionState.EXPIRED);
21344
- });
21345
- var isUpgradingPriceList = (upgradingSubscription === null || upgradingSubscription === void 0 ? void 0 : upgradingSubscription.priceList.id) === priceList.id;
21346
- if (existingSubscription) {
21347
- return true;
21348
- }
21349
- if (isUpgradingPriceList && !canPurchaseFeatureAddons) {
21350
- return true;
21476
+ var priceList = _a.priceList, upgradingSubscription = _a.upgradingSubscription, canPurchaseFeatureAddons = _a.canPurchaseFeatureAddons;
21477
+ var existingSubscriptionInTrial = upgradingSubscription && canSubscriptionUpgradeFromTrial(upgradingSubscription);
21478
+ var isUpgradingSubscriptionPriceList = (upgradingSubscription === null || upgradingSubscription === void 0 ? void 0 : upgradingSubscription.priceList.id) === priceList.id;
21479
+ // When should priceList be disabled?
21480
+ // if upgradingSubscription?.priceList.id === priceList.id
21481
+ // AND the upgradingSubscription is not in trial
21482
+ // AND cannot purchase feature addons
21483
+ // AND cannot purchase add-on plans
21484
+ // AND selfServiceBuy is false
21485
+ if (isUpgradingSubscriptionPriceList) {
21486
+ return !existingSubscriptionInTrial && !canPurchaseFeatureAddons;
21351
21487
  }
21352
21488
  return false;
21353
21489
  };
@@ -21376,11 +21512,13 @@ var CheckoutBarSummarySection = function (_a) {
21376
21512
  // Context
21377
21513
  var apiHost = react.useContext(BunnyContext).apiHost;
21378
21514
  var quotePreviewData = react.useContext(QuotePreviewContext).quotePreviewData;
21515
+ var accountId = react.useContext(PaymentContext).accountId;
21379
21516
  // Hooks
21380
21517
  var token = useToken();
21381
21518
  var paymentPlugins = usePaymentPlugins({
21382
21519
  apiHost: apiHost,
21383
21520
  token: token,
21521
+ accountId: accountId,
21384
21522
  }).paymentPlugins;
21385
21523
  var queryClient = reactQuery.useQueryClient();
21386
21524
  var isMobile = common.useIsMobile();
@@ -21433,31 +21571,32 @@ var PlanPickerCheckoutBar = function (_a) {
21433
21571
  }).defaultPaymentMethod;
21434
21572
  var createSubscriptionUpgradeQuote = useQuoteSubscriptionUpgrade();
21435
21573
  var createSubscriptionUpdateQuote = useCreateSubscriptionQuote();
21574
+ var quoteSubscriptionActivate = useQuoteSubscriptionActivate();
21436
21575
  // Mutations
21437
21576
  var createQuote = reactQuery.useMutation({
21438
21577
  mutationFn: function (_a) {
21439
21578
  var subscriptionId = _a.subscriptionId, priceListId = _a.priceListId;
21440
21579
  return createSubscriptionUpgradeQuote(subscriptionId, priceListId, apiHost, token);
21441
21580
  },
21442
- onSuccess: function (subscriptionUpdateData) {
21581
+ onSuccess: function (response) {
21443
21582
  var _a;
21444
- var quote = (_a = subscriptionUpdateData === null || subscriptionUpdateData === void 0 ? void 0 : subscriptionUpdateData.quoteSubscriptionUpgrade) === null || _a === void 0 ? void 0 : _a.quote;
21583
+ var quote = (_a = response === null || response === void 0 ? void 0 : response.quoteSubscriptionUpgrade) === null || _a === void 0 ? void 0 : _a.quote;
21445
21584
  setEditingQuoteData === null || setEditingQuoteData === void 0 ? void 0 : setEditingQuoteData(quote.id);
21446
21585
  handleSetEditingQuote(quote.id);
21447
21586
  },
21448
- });
21587
+ }).mutate;
21449
21588
  var createEmptyQuote = reactQuery.useMutation({
21450
21589
  mutationFn: function (_a) {
21451
21590
  var subscriptionId = _a.subscriptionId;
21452
21591
  return createSubscriptionUpdateQuote([subscriptionId], apiHost, token);
21453
21592
  },
21454
- onSuccess: function (subscriptionUpdateData) {
21593
+ onSuccess: function (response) {
21455
21594
  var _a;
21456
- var quote = (_a = subscriptionUpdateData === null || subscriptionUpdateData === void 0 ? void 0 : subscriptionUpdateData.quoteSubscriptionUpdate) === null || _a === void 0 ? void 0 : _a.quote;
21595
+ var quote = (_a = response === null || response === void 0 ? void 0 : response.quoteSubscriptionUpdate) === null || _a === void 0 ? void 0 : _a.quote;
21457
21596
  setEditingQuoteData === null || setEditingQuoteData === void 0 ? void 0 : setEditingQuoteData(quote.id);
21458
21597
  handleSetEditingQuote(quote.id);
21459
21598
  },
21460
- });
21599
+ }).mutate;
21461
21600
  var updateCharge = reactQuery.useMutation({
21462
21601
  mutationFn: quoteChargeUpdate,
21463
21602
  onSuccess: function () {
@@ -21470,6 +21609,32 @@ var PlanPickerCheckoutBar = function (_a) {
21470
21609
  });
21471
21610
  },
21472
21611
  }).mutate;
21612
+ var subscriptionActivate = reactQuery.useMutation({
21613
+ mutationFn: function (_a) {
21614
+ var subscriptionId = _a.subscriptionId;
21615
+ return __awaiter(void 0, void 0, void 0, function () {
21616
+ return __generator(this, function (_b) {
21617
+ switch (_b.label) {
21618
+ case 0: return [4 /*yield*/, quoteSubscriptionActivate(subscriptionId, apiHost, token)];
21619
+ case 1: return [2 /*return*/, _b.sent()];
21620
+ }
21621
+ });
21622
+ });
21623
+ },
21624
+ onSuccess: function (response) {
21625
+ var _a;
21626
+ var quote = (_a = response === null || response === void 0 ? void 0 : response.quoteSubscriptionActivate) === null || _a === void 0 ? void 0 : _a.quote;
21627
+ setEditingQuoteData === null || setEditingQuoteData === void 0 ? void 0 : setEditingQuoteData(quote.id);
21628
+ handleSetEditingQuote(quote.id);
21629
+ queryClient.invalidateQueries({
21630
+ queryKey: common.QueryKeyFactory.default.createObjectKey({
21631
+ objectName: 'editingQuote',
21632
+ id: editingQuote === null || editingQuote === void 0 ? void 0 : editingQuote.id,
21633
+ token: token,
21634
+ }),
21635
+ });
21636
+ },
21637
+ }).mutate;
21473
21638
  // Queries
21474
21639
  var quote = reactQuery.useQuery({
21475
21640
  queryKey: common.QueryKeyFactory.default.createObjectKey({
@@ -21499,18 +21664,26 @@ var PlanPickerCheckoutBar = function (_a) {
21499
21664
  enabled: Boolean(editingQuote === null || editingQuote === void 0 ? void 0 : editingQuote.id),
21500
21665
  }).data;
21501
21666
  react.useEffect(function () {
21667
+ var _a;
21502
21668
  if (!(upgradingSubscription === null || upgradingSubscription === void 0 ? void 0 : upgradingSubscription.id)) {
21503
21669
  console.error('upgradingSubscription is undefined');
21504
21670
  return;
21505
21671
  }
21506
21672
  var upgradingCurrentSubscription = (upgradingSubscription === null || upgradingSubscription === void 0 ? void 0 : upgradingSubscription.priceList.id) === (selectedPriceList === null || selectedPriceList === void 0 ? void 0 : selectedPriceList.id);
21507
21673
  if (upgradingCurrentSubscription) {
21508
- createEmptyQuote.mutate({
21509
- subscriptionId: upgradingSubscription === null || upgradingSubscription === void 0 ? void 0 : upgradingSubscription.id,
21510
- });
21674
+ if (((_a = upgradingSubscription === null || upgradingSubscription === void 0 ? void 0 : upgradingSubscription.state) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === common.SubscriptionState.TRIAL) {
21675
+ subscriptionActivate({
21676
+ subscriptionId: upgradingSubscription === null || upgradingSubscription === void 0 ? void 0 : upgradingSubscription.id,
21677
+ });
21678
+ }
21679
+ else {
21680
+ createEmptyQuote({
21681
+ subscriptionId: upgradingSubscription === null || upgradingSubscription === void 0 ? void 0 : upgradingSubscription.id,
21682
+ });
21683
+ }
21511
21684
  }
21512
21685
  else {
21513
- createQuote.mutate({
21686
+ createQuote({
21514
21687
  subscriptionId: upgradingSubscription === null || upgradingSubscription === void 0 ? void 0 : upgradingSubscription.id,
21515
21688
  priceListId: selectedPriceList === null || selectedPriceList === void 0 ? void 0 : selectedPriceList.id,
21516
21689
  });
@@ -21585,7 +21758,7 @@ var PlanPickerCheckoutBar = function (_a) {
21585
21758
  // WARNING: There is a preview button on APP that will need to be changed if this query is changed
21586
21759
  var PRICE_LIST_CHANGE_OPTIONS_QUERY = "\n query priceListChangeOptions($subscriptionId: ID, $productId: ID) {\n priceListChangeOptions(subscriptionId: $subscriptionId, productId: $productId) {\n products {\n everythingInPlus\n id\n name\n plansToDisplay\n features(sort: \"position asc\") {\n description\n id\n isVisible\n kind\n name\n position\n }\n }\n priceLists {\n showPriceAsMonthly\n basePrice\n currencyId\n id\n monthlyBasePrice\n periodMonths\n plan {\n code\n contactUsLabel\n contactUsUrl\n description\n id\n name\n position\n pricingDescription\n pricingStyle\n planFeatures {\n featureId\n value\n feature {\n name\n }\n }\n }\n product {\n id\n }\n charges {\n featureAddon\n basePrice\n billingPeriod\n chargeType\n id\n name\n priceDecimals\n pricingModel\n quantityMax\n quantityMin\n selfServiceQuantity\n priceList {\n id\n }\n feature {\n name\n unitName\n }\n }\n }\n }\n }";
21587
21760
  var getPriceListChangeOptions = function (_a) {
21588
- var apiHost = _a.apiHost, isInPreviewMode = _a.isInPreviewMode, productId = _a.productId, token = _a.token, upgradingSubscription = _a.upgradingSubscription;
21761
+ var apiHost = _a.apiHost, isInPreviewMode = _a.isInPreviewMode, productId = _a.productId, token = _a.token, upgradingSubscription = _a.upgradingSubscription, accountCurrencyId = _a.accountCurrencyId;
21589
21762
  return __awaiter(void 0, void 0, void 0, function () {
21590
21763
  var response, priceListChangeOptions;
21591
21764
  return __generator(this, function (_b) {
@@ -21606,6 +21779,8 @@ var getPriceListChangeOptions = function (_a) {
21606
21779
  if (priceListChangeOptions === null || priceListChangeOptions === void 0 ? void 0 : priceListChangeOptions.priceLists) {
21607
21780
  priceListChangeOptions.priceLists.sort(function (a, b) { return a.plan.position - b.plan.position; });
21608
21781
  }
21782
+ // Filter out price lists that don't have the same currency as the account
21783
+ priceListChangeOptions.priceLists = priceListChangeOptions.priceLists.filter(function (priceList) { return priceList.currencyId === accountCurrencyId; });
21609
21784
  return [2 /*return*/, priceListChangeOptions];
21610
21785
  }
21611
21786
  });
@@ -21737,7 +21912,10 @@ var PriceListCardButton = function (_a) {
21737
21912
  subscriptionPlan &&
21738
21913
  priceListHasUnpurchasedFeatureAddons(priceList, upgradingSubscription);
21739
21914
  var isPriceListNonSubscribedCurrentPlan = (upgradingSubscription === null || upgradingSubscription === void 0 ? void 0 : upgradingSubscription.plan.id) === priceList.plan.id && !isPriceListCurrentSubscription;
21915
+ var canUpgradeFromTrial = upgradingSubscription && canSubscriptionUpgradeFromTrial(upgradingSubscription);
21740
21916
  var createButtonText = function () {
21917
+ if (isPriceListCurrentSubscription && canUpgradeFromTrial)
21918
+ return 'Upgrade from trial';
21741
21919
  if (isPriceListCurrentSubscription)
21742
21920
  return 'Current';
21743
21921
  if (isSelected)
@@ -21891,7 +22069,6 @@ var PriceListCard = function (_a) {
21891
22069
  var canPurchaseFeatureAddons = priceListHasUnpurchasedFeatureAddons(priceList, upgradingSubscription);
21892
22070
  var disableOnClick = isPriceListDisabled({
21893
22071
  priceList: priceList,
21894
- subscriptions: subscriptions,
21895
22072
  upgradingSubscription: upgradingSubscription,
21896
22073
  canPurchaseFeatureAddons: canPurchaseFeatureAddons,
21897
22074
  });
@@ -22188,14 +22365,14 @@ var FeatureTitle = function (_a) {
22188
22365
 
22189
22366
  var PriceListGridDesktop = function (_a) {
22190
22367
  var availablePriceLists = _a.availablePriceLists, onChangePriceList = _a.onChangePriceList, priceListChangeOptions = _a.priceListChangeOptions, priceListStart = _a.priceListStart, selectedPriceList = _a.selectedPriceList, selectedProduct = _a.selectedProduct, setPriceListStart = _a.setPriceListStart, subscriptions = _a.subscriptions, trialRemainingDays = _a.trialRemainingDays;
22191
- var _b = react.useMemo(function () {
22368
+ var displayPriceLists = react.useMemo(function () {
22192
22369
  return getAvailablePlansAndPriceLists({
22193
22370
  availablePriceLists: availablePriceLists,
22194
22371
  priceListChangeOptions: priceListChangeOptions,
22195
22372
  priceListStart: priceListStart,
22196
22373
  plansToDisplay: (selectedProduct === null || selectedProduct === void 0 ? void 0 : selectedProduct.plansToDisplay) || 3,
22197
22374
  });
22198
- }, [availablePriceLists, priceListChangeOptions, priceListStart]); _b.availablePriceListsArray; var displayPriceLists = _b.displayPriceLists;
22375
+ }, [availablePriceLists, priceListChangeOptions, priceListStart]).displayPriceLists;
22199
22376
  var everythingInPlus = selectedProduct === null || selectedProduct === void 0 ? void 0 : selectedProduct.everythingInPlus;
22200
22377
  var plansToDisplay = Math.min((selectedProduct === null || selectedProduct === void 0 ? void 0 : selectedProduct.plansToDisplay) || 3, availablePriceLists.length);
22201
22378
  var hasFeatureAddons = displayPriceLists.some(function (priceList) {
@@ -22210,7 +22387,7 @@ var PriceListGridDesktop = function (_a) {
22210
22387
  var doesPrevPriceListExist = displayPriceLists[index - 1];
22211
22388
  if (!priceList)
22212
22389
  return jsxRuntime.jsx(PlanPickerGridCell, { noBorder: !Boolean(doesPrevPriceListExist) }, index);
22213
- return (jsxRuntime.jsx(PriceListCard, { isSelected: priceList.plan.id === (selectedPriceList === null || selectedPriceList === void 0 ? void 0 : selectedPriceList.plan.id), onClick: onChangePriceList, priceList: priceList, subscriptions: subscriptions, trialRemainingDays: trialRemainingDays }, index));
22390
+ return (jsxRuntime.jsx(PriceListCard, { isSelected: priceList.id === (selectedPriceList === null || selectedPriceList === void 0 ? void 0 : selectedPriceList.id), onClick: onChangePriceList, priceList: priceList, subscriptions: subscriptions, trialRemainingDays: trialRemainingDays }, index));
22214
22391
  }), (selectedProduct === null || selectedProduct === void 0 ? void 0 : selectedProduct.everythingInPlus) ? (jsxRuntime.jsx(EverythingPlanFeatures, { displayPriceLists: displayPriceLists, plansToDisplay: plansToDisplay, selectedProduct: selectedProduct })) : (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(PlanFeatures, { displayPriceLists: displayPriceLists, plansToDisplay: plansToDisplay, selectedProduct: selectedProduct }), hasFeatureAddons && (jsxRuntime.jsx(PlanFeatureAddons, { displayPriceLists: displayPriceLists, plansToDisplay: plansToDisplay }))] }))] }))] })));
22215
22392
  };
22216
22393
 
@@ -22284,7 +22461,6 @@ var PriceListSelector = function (_a) {
22284
22461
  priceList.plan.id === ((_a = quotePreviewData === null || quotePreviewData === void 0 ? void 0 : quotePreviewData.priceList) === null || _a === void 0 ? void 0 : _a.plan.id) &&
22285
22462
  !isPriceListDisabled({
22286
22463
  priceList: priceList,
22287
- subscriptions: subscriptions,
22288
22464
  upgradingSubscription: upgradingSubscription,
22289
22465
  canPurchaseFeatureAddons: priceListHasUnpurchasedFeatureAddons(quotePreviewData === null || quotePreviewData === void 0 ? void 0 : quotePreviewData.priceList, upgradingSubscription),
22290
22466
  });
@@ -22302,13 +22478,7 @@ var PriceListSelector = function (_a) {
22302
22478
  });
22303
22479
  }
22304
22480
  }
22305
- }, [
22306
- quotePreviewData,
22307
- priceListChangeOptions,
22308
- subscriptions,
22309
- upgradingSubscription,
22310
- setQuotePreviewData,
22311
- ]);
22481
+ }, [quotePreviewData, priceListChangeOptions, upgradingSubscription, setQuotePreviewData]);
22312
22482
  var onChangeProduct = react.useCallback(function (product) {
22313
22483
  var newAvailableBillingPeriods = createAvailableBillingPeriods(priceListChangeOptions === null || priceListChangeOptions === void 0 ? void 0 : priceListChangeOptions.priceLists, product);
22314
22484
  if (!(newAvailableBillingPeriods === null || newAvailableBillingPeriods === void 0 ? void 0 : newAvailableBillingPeriods.includes(billingPeriodConverter(selectedBillingPeriod)))) {
@@ -22353,7 +22523,6 @@ var PriceListSelector = function (_a) {
22353
22523
  !isInPreviewMode &&
22354
22524
  !isPriceListDisabled({
22355
22525
  priceList: initialPriceList,
22356
- subscriptions: subscriptions,
22357
22526
  upgradingSubscription: upgradingSubscription,
22358
22527
  canPurchaseFeatureAddons: priceListHasUnpurchasedFeatureAddons(initialPriceList, upgradingSubscription),
22359
22528
  })) {
@@ -22371,7 +22540,6 @@ var PriceListSelector = function (_a) {
22371
22540
  selectedPriceList,
22372
22541
  selectedProduct,
22373
22542
  setQuotePreviewData,
22374
- subscriptions,
22375
22543
  upgradingSubscription,
22376
22544
  ]);
22377
22545
  return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(BillingPeriodSelector, { availableBillingPeriods: availableBillingPeriods, onChangeBillingPeriod: onChangeBillingPeriod, products: priceListChangeOptions === null || priceListChangeOptions === void 0 ? void 0 : priceListChangeOptions.products, selectedBillingPeriod: selectedBillingPeriod, selectedProduct: selectedProduct, onChangeProduct: onChangeProduct }), jsxRuntime.jsx(PriceListGrid, { availablePriceLists: availablePriceLists, onChangePriceList: onChangePriceList, priceListChangeOptions: priceListChangeOptions, priceListStart: priceListStart, selectedPriceList: selectedPriceList, selectedProduct: selectedProduct, setPriceListStart: setPriceListStart, subscriptions: subscriptions, upgradingSubscriptionState: upgradingSubscription })] }));
@@ -22384,6 +22552,7 @@ var PlanPicker = function () {
22384
22552
  var apiHost = react.useContext(BunnyContext).apiHost;
22385
22553
  var _b = react.useContext(SubscriptionsContext), isInPreviewMode = _b.isInPreviewMode, productId = _b.productId, upgradingSubscription = _b.upgradingSubscription;
22386
22554
  var _c = react.useContext(QuotePreviewContext), quotePreviewData = _c.quotePreviewData, setQuotePreviewData = _c.setQuotePreviewData;
22555
+ var account = useCurrentUserData(token).account;
22387
22556
  // Hooks
22388
22557
  var showInfoNotification = common.useInfoNotification();
22389
22558
  // Queries
@@ -22406,6 +22575,7 @@ var PlanPicker = function () {
22406
22575
  productId: productId,
22407
22576
  token: token,
22408
22577
  upgradingSubscription: upgradingSubscription,
22578
+ accountCurrencyId: account === null || account === void 0 ? void 0 : account.currencyId,
22409
22579
  });
22410
22580
  },
22411
22581
  enabled: !areSubscriptionsLoading,
@@ -22568,7 +22738,7 @@ var SubscriptionState$1 = SubscriptionState;
22568
22738
 
22569
22739
  var FEATURE_USAGE_MUTATION = "\nquery GetFeatureUsage($id: ID!) {\n featureUsageHistogram(subscriptionChargeId: $id) {\n subscriptionCharge { \n id\n name\n amount\n currentPeriodPriceByTiers { \n tier { starts price } \n quantity\n amount\n }\n }\n feature { id name }\n periodRange\n dataInterval\n data {\n periodStart\n periodEnd\n intervals {\n intervalStart\n intervalUsage\n }\n intervalsTotal\n }\n }\n}\n";
22570
22740
  var getFeatureUsage = function (_a) {
22571
- var subscriptionChargeId = _a.subscriptionChargeId; _a.startDate; _a.endDate; _a.dataInterval; var token = _a.token, apiHost = _a.apiHost;
22741
+ var subscriptionChargeId = _a.subscriptionChargeId, token = _a.token, apiHost = _a.apiHost;
22572
22742
  return __awaiter(void 0, void 0, void 0, function () {
22573
22743
  var vars, response;
22574
22744
  var _b;
@@ -22688,381 +22858,45 @@ var FeatureBarChart = function (_a) {
22688
22858
  var StyledBarChart = defaultStyled(recharts.BarChart)(templateObject_1$2 || (templateObject_1$2 = __makeTemplateObject(["\n .recharts-surface {\n overflow: visible;\n }\n"], ["\n .recharts-surface {\n overflow: visible;\n }\n"])));
22689
22859
  var templateObject_1$2;
22690
22860
 
22691
- var canShowQuantitiesInput = function (charge, subscription) {
22692
- // Check if the subscription is active, pending, or in trial,
22693
- // the pricing model is not flat,
22694
- // and if it's not a trial, also check if the current charge is the last one in the subscription.
22695
- var _a, _b, _c;
22696
- var isActiveSubscription = ((_a = subscription.state) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === common.SubscriptionState.ACTIVE;
22697
- var isPendingSubscription = ((_b = subscription.state) === null || _b === void 0 ? void 0 : _b.toUpperCase()) === common.SubscriptionState.PENDING;
22698
- var isTrialSubscription = ((_c = subscription.state) === null || _c === void 0 ? void 0 : _c.toUpperCase()) === common.SubscriptionState.TRIAL;
22699
- var isFlatPricing = charge.pricingModel === 'FLAT';
22700
- var shouldProcessCharge = (isActiveSubscription || isPendingSubscription || isTrialSubscription) &&
22701
- !isFlatPricing &&
22702
- charge.selfServiceQuantity &&
22703
- !charge.expired;
22704
- // Now you can use the value of shouldProcessCharge to determine whether to process the charge.
22705
- return shouldProcessCharge;
22706
- };
22707
- var createQuoteParams = function (quote, subscriptionQuantity, editedSubscription) {
22708
- var quoteChange = quote.quoteChanges.find(function (quoteChange) { return quoteChange.priceList.id === (editedSubscription === null || editedSubscription === void 0 ? void 0 : editedSubscription.subscription.priceList.id); });
22709
- var quoteChangeCharge = quoteChange === null || quoteChange === void 0 ? void 0 : quoteChange.charges.find(function (charge) { return charge.priceListCharge.id === editedSubscription.chargeId; });
22710
- var charges = [
22711
- {
22712
- id: quoteChangeCharge.id,
22713
- quantity: editedSubscription.quantity - subscriptionQuantity,
22714
- },
22715
- ];
22716
- return { charges: charges, quoteChange: quoteChange };
22717
- };
22718
- var canShowChangeQuantities = function (_a) {
22719
- var subscriptions = _a.subscriptions;
22720
- return subscriptions === null || subscriptions === void 0 ? void 0 : subscriptions.some(function (subscription) {
22721
- return subscription.charges.some(function (charge, chargeIndex) {
22722
- return canShowQuantitiesInput(charge, subscription);
22723
- });
22724
- });
22725
- };
22726
- var isSubscriptionNotActive = function (subscription) {
22727
- var _a, _b;
22728
- return ((_a = subscription.state) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === common.SubscriptionState.EXPIRED ||
22729
- ((_b = subscription.state) === null || _b === void 0 ? void 0 : _b.toUpperCase()) === common.SubscriptionState.CANCELED;
22730
- };
22731
- var isSubscriptionActiveOrPending = function (subscription) {
22732
- var _a, _b;
22733
- return ((_a = subscription.state) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === common.SubscriptionState.ACTIVE ||
22734
- ((_b = subscription.state) === null || _b === void 0 ? void 0 : _b.toUpperCase()) === common.SubscriptionState.PENDING;
22735
- };
22736
- var isSubscriptionTrial = function (subscription) { var _a; return ((_a = subscription.state) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === common.SubscriptionState.TRIAL; };
22737
- // Helper function to check if charge is a discount
22738
- var isDiscount = function (kind) {
22739
- return kind === common.QuoteChangeKind.DISCOUNT || kind === common.QuoteChangeKind.FREE_PERIOD_DISCOUNT;
22740
- };
22741
- var hasPriceTiers = function (charge) {
22742
- var _a;
22743
- return Boolean((_a = charge === null || charge === void 0 ? void 0 : charge.priceTiers) === null || _a === void 0 ? void 0 : _a.length);
22744
- };
22745
- var hasMultiplePriceTiers = function (charge) {
22746
- var _a;
22747
- return ((_a = charge === null || charge === void 0 ? void 0 : charge.priceTiers) === null || _a === void 0 ? void 0 : _a.length) > 1;
22748
- };
22749
- var getApplicablePriceTier = function (charge, currencyId, priceDecimals) {
22750
- var _a;
22751
- if (!((_a = charge.priceTiers) === null || _a === void 0 ? void 0 : _a.length))
22752
- return '';
22753
- var selectedTier;
22754
- // For TIERED pricing model: always show the first tier
22755
- if (charge.pricingModel === common.PricingModel.TIERED) {
22756
- selectedTier = charge.priceTiers[0];
22757
- }
22758
- // For VOLUME and BANDS pricing models: find the tier that contains the current quantity
22759
- else if (charge.pricingModel === common.PricingModel.VOLUME ||
22760
- charge.pricingModel === common.PricingModel.BANDS) {
22761
- // Find the appropriate tier based on quantity
22762
- selectedTier = charge.priceTiers.find(function (tier, index) {
22763
- var nextTier = charge.priceTiers[index + 1];
22764
- var tierStart = tier.starts;
22765
- var tierEnd = nextTier ? nextTier.starts - 1 : Infinity;
22766
- return charge.quantity >= tierStart && charge.quantity <= tierEnd;
22767
- });
22768
- // Fallback to first tier if no tier found (shouldn't happen with proper data)
22769
- selectedTier = selectedTier || charge.priceTiers[0];
22770
- }
22771
- // Default fallback for any other pricing models
22772
- else {
22773
- selectedTier = charge.priceTiers[0];
22774
- }
22775
- if (!selectedTier)
22776
- return '';
22777
- // Calculate the tier range for display
22778
- var tierIndex = charge.priceTiers.indexOf(selectedTier);
22779
- var starts = selectedTier.starts;
22780
- var nextTier = charge.priceTiers[tierIndex + 1];
22781
- var ends = nextTier ? nextTier.starts - 1 : '∞';
22782
- return hasMultiplePriceTiers(charge)
22783
- ? "".concat(starts, "-").concat(ends, ": ").concat(common.formatCurrency(selectedTier.price, currencyId, priceDecimals))
22784
- : "".concat(common.formatCurrency(selectedTier.price, currencyId, priceDecimals));
22785
- };
22786
-
22787
- var MUTATION = "\nmutation BillingDetailsUpdate(\n $attributes: BillingDetailsAttributes!) {\n billingDetailsUpdate(\n attributes: $attributes\n ) {\n billingDetails {\n billingCity\n billingContact {\n email\n }\n billingCountry\n billingState\n billingStreet\n billingZip\n name\n taxNumber\n }\n errors\n }\n }\n";
22788
- var billingDetailsUpdate = function (_a) {
22789
- var attributes = _a.attributes, token = _a.token, apiHost = _a.apiHost;
22790
- return __awaiter(void 0, void 0, void 0, function () {
22791
- var vars, response, errors;
22792
- var _b;
22793
- return __generator(this, function (_c) {
22794
- switch (_c.label) {
22795
- case 0:
22796
- vars = { attributes: attributes };
22797
- return [4 /*yield*/, gqlRequest({
22798
- query: MUTATION,
22799
- token: token,
22800
- vars: vars,
22801
- apiHost: apiHost,
22802
- })];
22803
- case 1:
22804
- response = _c.sent();
22805
- errors = (_b = response === null || response === void 0 ? void 0 : response.billingDetailsUpdate) === null || _b === void 0 ? void 0 : _b.errors;
22806
- if (errors)
22807
- throw errors;
22808
- return [2 /*return*/, response.billingDetailsUpdate];
22809
- }
22810
- });
22811
- });
22861
+ var SubscriptionCardActions = function (_a) {
22862
+ var _b;
22863
+ var onChangePlanClick = _a.onChangePlanClick, onCancelSubscriptionClick = _a.onCancelSubscriptionClick, priceListChangeOptions = _a.priceListChangeOptions, subscription = _a.subscription;
22864
+ var apiHost = react.useContext(BunnyContext).apiHost;
22865
+ var token = useToken();
22866
+ var isPaymentMethodLoading = usePaymentMethod({
22867
+ accountId: subscription.accountId,
22868
+ token: token,
22869
+ apiHost: apiHost,
22870
+ }).isLoading;
22871
+ // Derived state
22872
+ var isSelfServiceCancelable = subscription.plan.selfServiceCancel;
22873
+ var productPlans = (_b = priceListChangeOptions === null || priceListChangeOptions === void 0 ? void 0 : priceListChangeOptions.priceLists) === null || _b === void 0 ? void 0 : _b.filter(function (priceList) { return priceList.product.id === subscription.product.id; });
22874
+ var arePlansAvailable = ((productPlans === null || productPlans === void 0 ? void 0 : productPlans.length) || 0) > 0;
22875
+ var isInTrial = isSubscriptionTrial(subscription);
22876
+ var isActiveOrPending = isSubscriptionActiveOrPending(subscription);
22877
+ if (isPaymentMethodLoading)
22878
+ return null;
22879
+ return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [isSelfServiceCancelable && (isInTrial || isActiveOrPending) && (jsxRuntime.jsx(antd.Popconfirm, __assign({ icon: null, onConfirm: function () { return onCancelSubscriptionClick === null || onCancelSubscriptionClick === void 0 ? void 0 : onCancelSubscriptionClick(subscription); }, title: "Cancel subscription" }, { children: jsxRuntime.jsx(antd.Button, __assign({ className: "bunny-p-0", type: "link" }, { children: "Cancel subscription" })) }))), arePlansAvailable && (isActiveOrPending || isInTrial) && (jsxRuntime.jsx(antd.Button, __assign({ onClick: function () { return onChangePlanClick(subscription); }, type: 'primary' }, { children: isInTrial ? 'Upgrade from trial' : 'Change plan' }))), !arePlansAvailable && isInTrial && jsxRuntime.jsx(antd.Tag, __assign({ color: "warning" }, { children: "Cannot upgrade" }))] }));
22812
22880
  };
22813
22881
 
22814
- // TODO: move this to common
22815
- var billingDetailsQuery = function () {
22816
- return "\nquery BillingDetails {\n billingDetails {\n billingCity\n billingContact {\n email\n }\n billingCountry\n billingState\n billingStreet\n billingZip\n name\n taxNumber\n currency {\n id\n }\n }\n}";
22817
- };
22818
- var getBillingDetails = function (_a) {
22819
- var token = _a.token, apiHost = _a.apiHost;
22820
- return __awaiter(void 0, void 0, void 0, function () {
22821
- var response;
22822
- var _b;
22823
- return __generator(this, function (_c) {
22824
- switch (_c.label) {
22825
- case 0: return [4 /*yield*/, gqlRequest({
22826
- query: billingDetailsQuery(),
22827
- token: token,
22828
- apiHost: apiHost,
22829
- })];
22830
- case 1:
22831
- response = _c.sent();
22832
- if (response === null || response === void 0 ? void 0 : response.errors) {
22833
- throw new Error((_b = response === null || response === void 0 ? void 0 : response.errors[0]) === null || _b === void 0 ? void 0 : _b.message);
22834
- }
22835
- return [2 /*return*/, response === null || response === void 0 ? void 0 : response.billingDetails];
22836
- }
22837
- });
22838
- });
22839
- };
22840
-
22841
- var Text$7 = antd.Typography.Text;
22842
- function BillingDetailsSection(_a) {
22843
- var _this = this;
22844
- var hidePaymentMethodForm = _a.hidePaymentMethodForm, countryListFilter = _a.countryListFilter;
22845
- // State
22846
- var _b = react.useState(false), isFormEdited = _b[0], setIsFormEdited = _b[1];
22847
- var _c = react.useState(false), formIsValid = _c[0], setFormIsValid = _c[1];
22848
- var form = antd.Form.useForm()[0];
22849
- var values = antd.Form.useWatch([], form);
22850
- // Context
22851
- var apiHost = react.useContext(BunnyContext).apiHost;
22852
- var token = useToken();
22853
- // Hooks
22854
- var isMobile = common.useIsMobile();
22855
- var queryClient = reactQuery.useQueryClient();
22856
- var showErrorNotification = common.useErrorNotification();
22857
- var showSuccessNotification = common.useSuccessNotification();
22858
- // Queries
22859
- var _d = reactQuery.useQuery({
22860
- queryKey: common.QueryKeyFactory.default.billingDetailsKey({ token: token }),
22861
- queryFn: function () { return getBillingDetails({ token: token, apiHost: apiHost }); },
22862
- }), billingDetails = _d.data, isLoadingBillingDetails = _d.isLoading;
22863
- var _e = reactQuery.useMutation({
22864
- mutationFn: function (changedFormData) { return __awaiter(_this, void 0, void 0, function () {
22865
- var updatedBillingDetails;
22866
- return __generator(this, function (_a) {
22867
- switch (_a.label) {
22868
- case 0: return [4 /*yield*/, billingDetailsUpdate({
22869
- attributes: {
22870
- name: changedFormData.name,
22871
- billingStreet: changedFormData.billingStreet,
22872
- billingCity: changedFormData.billingCity,
22873
- billingZip: changedFormData.billingZip,
22874
- billingState: changedFormData.billingState,
22875
- billingCountry: changedFormData.billingCountry,
22876
- billingContactEmail: changedFormData.billingContactEmail,
22877
- taxNumber: changedFormData.taxNumber,
22878
- },
22879
- token: token,
22880
- apiHost: apiHost,
22881
- })];
22882
- case 1:
22883
- updatedBillingDetails = _a.sent();
22884
- queryClient.setQueryData(common.QueryKeyFactory.default.billingDetailsKey({ token: token }), function (old) {
22885
- return __assign(__assign({}, old), updatedBillingDetails.billingDetails);
22886
- });
22887
- return [2 /*return*/, updatedBillingDetails];
22888
- }
22889
- });
22890
- }); },
22891
- onSuccess: function () {
22892
- showSuccessNotification('Your account details have been saved');
22893
- queryClient.invalidateQueries({
22894
- queryKey: common.QueryKeyFactory.default.taxationRequiredAccountFieldsKey({
22895
- token: token,
22896
- }),
22897
- });
22898
- },
22899
- }), updateBillingDetails = _e.mutate, isUpdatingBillingDetails = _e.isPending;
22900
- // Set form values when billing details are loaded
22901
- react.useEffect(function () {
22902
- var _a;
22903
- if (billingDetails) {
22904
- form.setFieldsValue({
22905
- billingStreet: billingDetails.billingStreet,
22906
- billingCity: billingDetails.billingCity,
22907
- billingZip: billingDetails.billingZip,
22908
- billingState: billingDetails.billingState,
22909
- billingCountry: billingDetails.billingCountry,
22910
- billingContactEmail: (_a = billingDetails.billingContact) === null || _a === void 0 ? void 0 : _a.email,
22911
- taxNumber: billingDetails.taxNumber,
22912
- });
22913
- }
22914
- }, [billingDetails]);
22915
- react.useEffect(function () {
22916
- form
22917
- .validateFields({ validateOnly: true })
22918
- .then(function () { return setFormIsValid(true); })
22919
- .catch(function () { return setFormIsValid(false); });
22920
- var isFormEdited = function () {
22921
- var _a;
22922
- if (!billingDetails)
22923
- return false;
22924
- var currentValues = form.getFieldsValue();
22925
- var accountValues = {
22926
- billingStreet: billingDetails.billingStreet,
22927
- billingCity: billingDetails.billingCity,
22928
- billingZip: billingDetails.billingZip,
22929
- billingState: billingDetails.billingState,
22930
- billingCountry: billingDetails.billingCountry,
22931
- billingContactEmail: (_a = billingDetails.billingContact) === null || _a === void 0 ? void 0 : _a.email,
22932
- taxNumber: billingDetails.taxNumber,
22933
- };
22934
- return Object.keys(currentValues).some(function (key) {
22935
- var value = accountValues[key];
22936
- return currentValues[key] !== value;
22937
- });
22938
- };
22939
- setIsFormEdited(isFormEdited());
22940
- }, [form, values, billingDetails]);
22941
- // Validate form fields when isFormEdited changes
22942
- react.useEffect(function () {
22943
- var validateOnly = isFormEdited ? false : true;
22944
- form.validateFields({ validateOnly: validateOnly });
22945
- }, [isFormEdited]);
22946
- var saveBillingDetails = function () { return __awaiter(_this, void 0, void 0, function () {
22947
- var _this = this;
22948
- return __generator(this, function (_a) {
22949
- form.validateFields({ validateOnly: false }).then(function () { return __awaiter(_this, void 0, void 0, function () {
22950
- var error_1;
22951
- return __generator(this, function (_a) {
22952
- switch (_a.label) {
22953
- case 0:
22954
- _a.trys.push([0, 2, 3, 4]);
22955
- return [4 /*yield*/, form.validateFields()];
22956
- case 1:
22957
- _a.sent();
22958
- updateBillingDetails(form.getFieldsValue());
22959
- return [3 /*break*/, 4];
22960
- case 2:
22961
- error_1 = _a.sent();
22962
- if (error_1 instanceof Error) {
22963
- showErrorNotification('Failed to update account', error_1.message);
22964
- }
22965
- else {
22966
- showErrorNotification('Please fill out all required fields');
22967
- }
22968
- return [3 /*break*/, 4];
22969
- case 3:
22970
- setIsFormEdited(false);
22971
- return [7 /*endfinally*/];
22972
- case 4: return [2 /*return*/];
22973
- }
22974
- });
22975
- }); });
22976
- return [2 /*return*/];
22977
- });
22978
- }); };
22979
- var filteredCountryList = react.useMemo(function () {
22980
- return countryListFilter ? common.Lists.COUNTRY_LIST.filter(countryListFilter) : common.Lists.COUNTRY_LIST;
22981
- }, [countryListFilter]);
22982
- return (jsxRuntime.jsx("div", __assign({ className: "".concat(isMobile || hidePaymentMethodForm ? 'bunny-w-full' : 'bunny-w-1/2') }, { children: jsxRuntime.jsxs("div", __assign({ className: "bunny-px-4" }, { children: [jsxRuntime.jsxs(antd.Skeleton, __assign({ loading: isLoadingBillingDetails }, { children: [jsxRuntime.jsx("div", __assign({ className: "bunny-mb-2" }, { children: jsxRuntime.jsx(Text$7, __assign({ className: "bunny-font-medium bunny-text-lg" }, { children: (billingDetails === null || billingDetails === void 0 ? void 0 : billingDetails.name) || 'No company name' })) })), jsxRuntime.jsxs(antd.Form, __assign({ className: "bunny-flex bunny-flex-col bunny-gap-2", form: form, layout: "vertical", disabled: isUpdatingBillingDetails, autoComplete: "off" }, { children: [jsxRuntime.jsx(antd.Form.Item, __assign({ label: "Street address", name: "billingStreet", rules: [{ required: true, message: 'Street address is required' }] }, { children: jsxRuntime.jsx(antd.Input, {}) })), jsxRuntime.jsxs("div", __assign({ className: "bunny-flex bunny-gap-4" }, { children: [jsxRuntime.jsx(antd.Form.Item, __assign({ label: "City", name: "billingCity", rules: [{ required: true, message: 'City is required' }], className: "bunny-flex-1" }, { children: jsxRuntime.jsx(antd.Input, {}) })), jsxRuntime.jsx(antd.Form.Item, __assign({ label: "Zipcode", name: "billingZip", rules: [{ required: true, message: 'Zipcode is required' }], className: "bunny-flex-1" }, { children: jsxRuntime.jsx(antd.Input, {}) }))] })), jsxRuntime.jsxs("div", __assign({ className: "bunny-flex ".concat(isMobile ? 'bunny-flex-row bunny-pb-2' : 'bunny-flex-row', " bunny-gap-4") }, { children: [jsxRuntime.jsx("div", __assign({ className: "bunny-flex-1 bunny-w-1/2" }, { children: jsxRuntime.jsx(antd.Form.Item, __assign({ label: "State", name: "billingState", rules: [
22983
- {
22984
- required: false,
22985
- },
22986
- ] }, { children: jsxRuntime.jsx(antd.Input, {}) })) })), jsxRuntime.jsx("div", __assign({ className: "bunny-flex-1 bunny-w-1/2" }, { children: jsxRuntime.jsx(antd.Form.Item, __assign({ label: "Country", name: "billingCountry", rules: [{ required: true, message: 'Country is required' }] }, { children: jsxRuntime.jsx(antd.Select, { className: "bunny-w-full", options: filteredCountryList, placeholder: "Select a country", popupMatchSelectWidth: false, showSearch: true, filterOption: function (input, option) {
22987
- var _a, _b;
22988
- return ((_a = option === null || option === void 0 ? void 0 : option.label) !== null && _a !== void 0 ? _a : '').toLowerCase().includes(input.toLowerCase()) ||
22989
- ((_b = option === null || option === void 0 ? void 0 : option.value) !== null && _b !== void 0 ? _b : '').toLowerCase().includes(input.toLowerCase());
22990
- } }) })) }))] })), jsxRuntime.jsx(antd.Form.Item, __assign({ label: "Email", name: "billingContactEmail", rules: [
22991
- {
22992
- required: true,
22993
- message: 'Email is required',
22994
- type: 'email',
22995
- },
22996
- ] }, { children: jsxRuntime.jsx(antd.Input, {}) })), jsxRuntime.jsx(antd.Form.Item, __assign({ label: "Tax ID", name: "taxNumber", tooltip: "Tax ID will be printed on quotes and invoices below the account's address", rules: [{ required: false }] }, { children: jsxRuntime.jsx(antd.Input, {}) }))] }))] })), jsxRuntime.jsx(antd.Button, __assign({ disabled: !isFormEdited || isUpdatingBillingDetails || !formIsValid, className: "bunny-w-full bunny-mt-4", type: "primary", onClick: saveBillingDetails }, { children: "Save" }))] })) })));
22997
- }
22998
-
22999
- var BillingDetails = function (_a) {
23000
- var className = _a.className, countryListFilter = _a.countryListFilter, _b = _a.hideBillingDetailsForm, hideBillingDetailsForm = _b === void 0 ? false : _b, _c = _a.hidePaymentMethodForm, hidePaymentMethodForm = _c === void 0 ? false : _c, _d = _a.isCardEnabled, isCardEnabled = _d === void 0 ? true : _d, _e = _a.isUpgradeFromTrial, isUpgradeFromTrial = _e === void 0 ? false : _e, _f = _a.shadow, shadow = _f === void 0 ? 'shadow-md' : _f, onSavePaymentMethod = _a.onSavePaymentMethod;
23001
- // Hooks
23002
- var isMobile = common.useIsMobile();
23003
- return (jsxRuntime.jsx(WrapperComponent, __assign({ isCardEnabled: isCardEnabled, shadow: shadow, className: className }, { children: jsxRuntime.jsxs("div", __assign({ className: "bunny-flex bunny-py-2 bunny-my-2 ".concat(isMobile ? 'bunny-flex-col bunny-space-y-4' : 'bunny-flex-row', " bunny-gap-4") }, { children: [!hideBillingDetailsForm ? (jsxRuntime.jsx(BillingDetailsSection, { hidePaymentMethodForm: hidePaymentMethodForm, countryListFilter: countryListFilter })) : null, !hideBillingDetailsForm && !hidePaymentMethodForm ? jsxRuntime.jsx(ResponsiveDivider, {}) : null, !hidePaymentMethodForm ? (jsxRuntime.jsx(PaymentFormSection, { hideBillingDetailsForm: hideBillingDetailsForm, isUpgradeFromTrial: isUpgradeFromTrial, onSavePaymentMethod: onSavePaymentMethod })) : null] })) })));
23004
- };
23005
- var WrapperComponent = function (_a) {
23006
- var children = _a.children, isCardEnabled = _a.isCardEnabled, shadow = _a.shadow, className = _a.className;
23007
- return (jsxRuntime.jsx("div", __assign({ className: "".concat(className) }, { children: isCardEnabled ? jsxRuntime.jsx(Card, __assign({ className: "".concat(shadow) }, { children: children })) : jsxRuntime.jsx("div", { children: children }) })));
23008
- };
23009
- var ResponsiveDivider = function () {
23010
- var isMobile = common.useIsMobile();
23011
- return isMobile ? (jsxRuntime.jsx("div", __assign({ className: "bunny-mx-4" }, { children: jsxRuntime.jsx(antd.Divider, {}) }))) : (jsxRuntime.jsx("div", { children: jsxRuntime.jsx(antd.Divider, { className: "bunny-h-full", type: "vertical" }) }));
23012
- };
23013
- var PaymentFormSection = function (_a) {
23014
- var hideBillingDetailsForm = _a.hideBillingDetailsForm, isUpgradeFromTrial = _a.isUpgradeFromTrial, onSavePaymentMethod = _a.onSavePaymentMethod;
23015
- var isMobile = common.useIsMobile();
23016
- var onTokenExpired = react.useContext(BunnyContext).onTokenExpired;
23017
- var handleAllErrorFormats = common.useAllErrorFormats(onTokenExpired);
23018
- var showSuccessNotification = common.useSuccessNotification();
23019
- var entityId = useCurrentUserData().entityId;
23020
- return (jsxRuntime.jsx("div", __assign({ className: "".concat(isMobile || hideBillingDetailsForm ? 'bunny-w-full' : 'bunny-w-1/2 bunny-pt-4', " bunny-flex bunny-justify-center") }, { children: jsxRuntime.jsx(PaymentForm, { entityId: entityId, onFail: function (error) {
23021
- handleAllErrorFormats(error);
23022
- }, onSavePaymentMethod: function () {
23023
- showSuccessNotification(isUpgradeFromTrial
23024
- ? 'Payment method saved! Your trial will automatically convert to a paid subscription.'
23025
- : 'Payment method saved successfully!');
23026
- onSavePaymentMethod === null || onSavePaymentMethod === void 0 ? void 0 : onSavePaymentMethod();
23027
- } }) })));
23028
- };
23029
-
23030
- var UpgradeFromTrial = function (_a) {
23031
- var onClose = _a.onClose, open = _a.open;
23032
- return (jsxRuntime.jsx(antd.Modal, __assign({ width: '80vw', open: open, onCancel: onClose, footer: null }, { children: jsxRuntime.jsx(BillingDetails, { isUpgradeFromTrial: true, onSavePaymentMethod: onClose }) })));
23033
- };
23034
-
23035
- var SubscriptionCardActions = function (_a) {
23036
- var _b;
23037
- var onChangePlanClick = _a.onChangePlanClick, onCancelSubscriptionClick = _a.onCancelSubscriptionClick, priceListChangeOptions = _a.priceListChangeOptions, subscription = _a.subscription;
23038
- var apiHost = react.useContext(BunnyContext).apiHost;
23039
- var token = useToken();
23040
- var _c = usePaymentMethod({
23041
- accountId: subscription.accountId,
23042
- token: token,
23043
- apiHost: apiHost,
23044
- }), storedPaymentMethods = _c.paymentMethods, isPaymentMethodLoading = _c.isLoading;
23045
- // Local state
23046
- var _d = react.useState(false), isUpgradeFromTrialModalOpen = _d[0], setIsUpgradeFromTrialModalOpen = _d[1];
23047
- // Derived state
23048
- var isSelfServiceCancelable = subscription.plan.selfServiceCancel;
23049
- var productPlans = (_b = priceListChangeOptions === null || priceListChangeOptions === void 0 ? void 0 : priceListChangeOptions.priceLists) === null || _b === void 0 ? void 0 : _b.filter(function (priceList) { return priceList.product.id === subscription.product.id; });
23050
- var arePlansAvailable = ((productPlans === null || productPlans === void 0 ? void 0 : productPlans.length) || 0) > 0;
23051
- var isInTrial = isSubscriptionTrial(subscription);
23052
- var isActiveOrPending = isSubscriptionActiveOrPending(subscription);
23053
- if (isPaymentMethodLoading)
23054
- return null;
23055
- return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [isSelfServiceCancelable && (isInTrial || isActiveOrPending) && (jsxRuntime.jsx(antd.Popconfirm, __assign({ icon: null, onConfirm: function () { return onCancelSubscriptionClick === null || onCancelSubscriptionClick === void 0 ? void 0 : onCancelSubscriptionClick(subscription); }, title: "Cancel subscription" }, { children: jsxRuntime.jsx(antd.Button, __assign({ className: "bunny-p-0", type: "link" }, { children: "Cancel subscription" })) }))), isInTrial && !(storedPaymentMethods === null || storedPaymentMethods === void 0 ? void 0 : storedPaymentMethods.length) && (jsxRuntime.jsx(antd.Button, __assign({ onClick: function () { return setIsUpgradeFromTrialModalOpen(true); }, type: "primary" }, { children: "Upgrade from trial" }))), arePlansAvailable && (isInTrial || isActiveOrPending) && (jsxRuntime.jsx(antd.Button, __assign({ onClick: function () { return onChangePlanClick(subscription); }, type: isInTrial ? 'default' : 'primary' }, { children: "Change plan" }))), jsxRuntime.jsx(UpgradeFromTrial, { onClose: function () { return setIsUpgradeFromTrialModalOpen(false); }, open: isUpgradeFromTrialModalOpen })] }));
23056
- };
23057
-
23058
- var Text$6 = antd.Typography.Text;
22882
+ var Text$7 = antd.Typography.Text;
23059
22883
  var getSubscriptionStatusText = function (subscription) {
23060
- var cancellationDate = subscription.cancellationDate, state = subscription.state, evergreen = subscription.evergreen, endDate = subscription.endDate;
22884
+ var _a;
22885
+ var cancellationDate = subscription.cancellationDate, state = subscription.state, evergreen = subscription.evergreen, endDate = subscription.endDate, trialExpirationAction = subscription.trialExpirationAction;
22886
+ var isTrial = ((_a = subscription.state) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === common.SubscriptionState.TRIAL;
23061
22887
  if (cancellationDate &&
23062
22888
  (state === null || state === void 0 ? void 0 : state.toUpperCase()) !== common.SubscriptionState.CANCELED &&
23063
22889
  (state === null || state === void 0 ? void 0 : state.toUpperCase()) !== common.SubscriptionState.EXPIRED) {
23064
22890
  return (jsxRuntime.jsxs(CustomizedTag, __assign({ color: "red" }, { children: ["Canceled - ends on ", common.formatDate(cancellationDate)] })));
23065
22891
  }
22892
+ if (isTrial) {
22893
+ switch (trialExpirationAction) {
22894
+ case 'ACTIVATE':
22895
+ return "Activates on ".concat(common.formatDate(endDate));
22896
+ case 'CANCEL':
22897
+ return "Trial ends on ".concat(common.formatDate(endDate));
22898
+ }
22899
+ }
23066
22900
  if (evergreen) {
23067
22901
  return "Renews on ".concat(common.formatDate(endDate));
23068
22902
  }
@@ -23084,7 +22918,7 @@ var SubscriptionCardHeader = function (_a) {
23084
22918
  var isTrial = ((_b = subscription.state) === null || _b === void 0 ? void 0 : _b.toUpperCase()) === common.SubscriptionState.TRIAL;
23085
22919
  return (jsxRuntime.jsxs("div", __assign({ className: "bunny-flex bunny-items-center bunny-justify-between", style: {
23086
22920
  backgroundColor: darkMode ? 'var(--row-background-dark)' : '',
23087
- } }, { children: [jsxRuntime.jsxs("div", __assign({ className: "bunny-flex bunny-flex-col bunny-gap-2" }, { children: [((_c = subscription === null || subscription === void 0 ? void 0 : subscription.product) === null || _c === void 0 ? void 0 : _c.name) && (jsxRuntime.jsx(Text$6, __assign({ style: __assign({ fontSize: '11px', fontWeight: 500, color: brandColor }, subscriptionProductNameStyle) }, { children: (_d = subscription.product.name) === null || _d === void 0 ? void 0 : _d.toUpperCase() }))), jsxRuntime.jsxs("div", __assign({ className: "bunny-flex bunny-grow bunny-items-center bunny-gap-2" }, { children: [((_e = subscription === null || subscription === void 0 ? void 0 : subscription.plan) === null || _e === void 0 ? void 0 : _e.name) && (jsxRuntime.jsx(Text$6, __assign({ className: "bunny-text-lg" }, { children: subscription.plan.name }))), jsxRuntime.jsxs(CustomizedTag, __assign({ color: common.TAG_COLORS[(_f = subscription.state) === null || _f === void 0 ? void 0 : _f.toUpperCase()] }, { children: [lodashExports.capitalize(subscription.state.toLowerCase()), isTrial ? " (".concat(trialDaysLeft || 'N/A', " days left)") : ''] }))] }))] })), jsxRuntime.jsxs("div", __assign({ className: "bunny-flex bunny-items-center bunny-gap-6" }, { children: [jsxRuntime.jsx(Text$6, __assign({ className: "bunny-grow bunny-text-xs" }, { children: getSubscriptionStatusText(subscription) })), !isMobile && priceListChangeOptions && onChangePlanClick && onCancelSubscriptionClick && (jsxRuntime.jsx(SubscriptionCardActions, { onChangePlanClick: onChangePlanClick, onCancelSubscriptionClick: onCancelSubscriptionClick, priceListChangeOptions: priceListChangeOptions, subscription: subscription }))] }))] })));
22921
+ } }, { children: [jsxRuntime.jsxs("div", __assign({ className: "bunny-flex bunny-flex-col bunny-gap-2" }, { children: [((_c = subscription === null || subscription === void 0 ? void 0 : subscription.product) === null || _c === void 0 ? void 0 : _c.name) && (jsxRuntime.jsx(Text$7, __assign({ style: __assign({ fontSize: '11px', fontWeight: 500, color: brandColor }, subscriptionProductNameStyle) }, { children: (_d = subscription.product.name) === null || _d === void 0 ? void 0 : _d.toUpperCase() }))), jsxRuntime.jsxs("div", __assign({ className: "bunny-flex bunny-grow bunny-items-center bunny-gap-2" }, { children: [((_e = subscription === null || subscription === void 0 ? void 0 : subscription.plan) === null || _e === void 0 ? void 0 : _e.name) && (jsxRuntime.jsx(Text$7, __assign({ className: "bunny-text-lg" }, { children: subscription.plan.name }))), jsxRuntime.jsxs(CustomizedTag, __assign({ color: common.TAG_COLORS[(_f = subscription.state) === null || _f === void 0 ? void 0 : _f.toUpperCase()] }, { children: [lodashExports.capitalize(subscription.state.toLowerCase()), isTrial ? " (".concat(trialDaysLeft || 'N/A', " days left)") : ''] }))] }))] })), jsxRuntime.jsxs("div", __assign({ className: "bunny-flex bunny-items-center bunny-gap-6" }, { children: [jsxRuntime.jsx(Text$7, __assign({ className: "bunny-grow bunny-text-xs" }, { children: getSubscriptionStatusText(subscription) })), !isMobile && priceListChangeOptions && onChangePlanClick && onCancelSubscriptionClick && (jsxRuntime.jsx(SubscriptionCardActions, { onChangePlanClick: onChangePlanClick, onCancelSubscriptionClick: onCancelSubscriptionClick, priceListChangeOptions: priceListChangeOptions, subscription: subscription }))] }))] })));
23088
22922
  };
23089
22923
 
23090
22924
  var SubscriptionChargeTotal = function (_a) {
@@ -23161,16 +22995,16 @@ var SubscriptionChargeUnitPrice = function (_a) {
23161
22995
  return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: hasPriceTiers(charge) ? (jsxRuntime.jsx(TieredDisplayDropdown, { charge: charge, currencyId: currencyId, truncatedText: "".concat(charge.kind === common.QuoteChangeKind.PRICE_UPDATE ? 'new ' : '').concat(getApplicablePriceTier(charge, currencyId, charge.priceDecimals)) })) : isChargeDiscount ? ("-".concat(price)) : (price) }));
23162
22996
  };
23163
22997
 
23164
- var Text$5 = antd.Typography.Text;
22998
+ var Text$6 = antd.Typography.Text;
23165
22999
  var SubscriptionCardColumnHeaders = function (_a) {
23166
23000
  var columns = _a.columns;
23167
- return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: columns.map(function (subscriptionColumn, index) { return (jsxRuntime.jsx(Text$5, __assign({ className: "bunny-text-slate-400 ".concat(subscriptionColumn.className), style: { fontSize: "11px" } }, { children: subscriptionColumn.title }), index)); }) }));
23001
+ return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: columns.map(function (subscriptionColumn, index) { return (jsxRuntime.jsx(Text$6, __assign({ className: "bunny-text-slate-400 ".concat(subscriptionColumn.className), style: { fontSize: "11px" } }, { children: subscriptionColumn.title }), index)); }) }));
23168
23002
  };
23169
23003
 
23170
- var Text$4 = antd.Typography.Text;
23004
+ var Text$5 = antd.Typography.Text;
23171
23005
  var SubscriptionsListCell = function (_a) {
23172
23006
  var children = _a.children, className = _a.className, gridColumn = _a.gridColumn, right = _a.right, style = _a.style;
23173
- return (jsxRuntime.jsx(Text$4, __assign({ className: "bunny-flex bunny-items-center bunny-text-sm bunny-whitespace-nowrap ".concat(className), style: __assign({ gridColumn: gridColumn, textAlign: right ? "right" : "left", justifyContent: right ? "flex-end" : "flex-start" }, style) }, { children: children })));
23007
+ return (jsxRuntime.jsx(Text$5, __assign({ className: "bunny-flex bunny-items-center bunny-text-sm bunny-whitespace-nowrap ".concat(className), style: __assign({ gridColumn: gridColumn, textAlign: right ? "right" : "left", justifyContent: right ? "flex-end" : "flex-start" }, style) }, { children: children })));
23174
23008
  };
23175
23009
 
23176
23010
  var CARD_COLUMNS = [
@@ -23230,11 +23064,9 @@ var SubscriptionCardDesktopRow = function (_a) {
23230
23064
  var chargePeriod = "".concat(common.formatDate(charge.startDate), " - ").concat(common.formatDate(charge.endDate));
23231
23065
  // Queries
23232
23066
  var data = reactQuery.useQuery({
23233
- queryKey: ['getFeatureUsage', charge.id, charge.startDate, charge.endDate],
23067
+ queryKey: ['getFeatureUsage', charge.id],
23234
23068
  queryFn: function () {
23235
23069
  return getFeatureUsage({
23236
- endDate: charge.endDate,
23237
- startDate: charge.startDate,
23238
23070
  subscriptionChargeId: charge.id,
23239
23071
  token: token,
23240
23072
  apiHost: apiHost,
@@ -23258,10 +23090,10 @@ var SubscriptionCardDesktopRow = function (_a) {
23258
23090
  : (_c = charge.quantity) === null || _c === void 0 ? void 0 : _c.toLocaleString() })), jsxRuntime.jsx(SubscriptionsListCell, __assign({ right: true }, { children: jsxRuntime.jsx(SubscriptionChargeUnitPrice, { charge: charge, currencyId: subscription.currencyId }) })), jsxRuntime.jsx(SubscriptionsListCell, __assign({ right: true }, { children: jsxRuntime.jsx(SubscriptionChargeTotal, { charge: charge, subscription: subscription }) }))] })));
23259
23091
  };
23260
23092
 
23261
- var Text$3 = antd.Typography.Text;
23093
+ var Text$4 = antd.Typography.Text;
23262
23094
  var SubscriptionCardCellMobile = function (_a) {
23263
23095
  var children = _a.children, className = _a.className, style = _a.style;
23264
- return (jsxRuntime.jsx(Text$3, __assign({ className: className, style: style }, { children: children })));
23096
+ return (jsxRuntime.jsx(Text$4, __assign({ className: className, style: style }, { children: children })));
23265
23097
  };
23266
23098
 
23267
23099
  var CHARGE_COLUMNS = [
@@ -23327,10 +23159,13 @@ var SubscriptionsListContainer = function (_a) {
23327
23159
  var apiHost = react.useContext(BunnyContext).apiHost;
23328
23160
  var gap = react.useContext(SubscriptionsContext).gap;
23329
23161
  var token = useToken();
23162
+ var account = useCurrentUserData(token).account;
23330
23163
  // Queries
23331
23164
  var _c = reactQuery.useQuery({
23332
23165
  queryKey: common.QueryKeyFactory.default.planChangeOptionsKey({ token: token }),
23333
- queryFn: function () { return getPriceListChangeOptions({ apiHost: apiHost, token: token }); },
23166
+ queryFn: function () {
23167
+ return getPriceListChangeOptions({ apiHost: apiHost, token: token, accountCurrencyId: account === null || account === void 0 ? void 0 : account.currencyId });
23168
+ },
23334
23169
  enabled: Boolean(onChangePlanClick),
23335
23170
  }), priceListChangeOptions = _c.data, arePriceListChangeOptionsLoading = _c.isLoading;
23336
23171
  if (subscriptionsAreLoading ||
@@ -23339,10 +23174,10 @@ var SubscriptionsListContainer = function (_a) {
23339
23174
  return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: (subscriptions === null || subscriptions === void 0 ? void 0 : subscriptions.length) > 0 ? (jsxRuntime.jsx("div", __assign({ className: "bunny-flex bunny-flex-col bunny-gap-".concat(gap, " bunny-shrink bunny-overflow-auto") }, { children: jsxRuntime.jsx(SubscriptionsList, { hideExpired: hideExpired, onChangePlanClick: onChangePlanClick, onCancelSubscriptionClick: onCancelSubscriptionClick, priceListChangeOptions: priceListChangeOptions, subscriptions: subscriptions }) }))) : (noSubscriptionsComponent || (jsxRuntime.jsx("div", __assign({ className: "bunny-flex bunny-flex-col bunny-items-center bunny-w-full" }, { children: jsxRuntime.jsx(ErrorView, { message: "You have no subscriptions with ".concat(companyName, " yet") }) })))) }));
23340
23175
  };
23341
23176
 
23342
- var Text$2 = antd.Typography.Text;
23177
+ var Text$3 = antd.Typography.Text;
23343
23178
  var DrawerHeader = function (_a) {
23344
23179
  var description = _a.description, onClose = _a.onClose, title = _a.title, closeButtonClassName = _a.closeButtonClassName;
23345
- return (jsxRuntime.jsxs("div", __assign({ className: "bunny-flex bunny-flex-col bunny-gap-4" }, { children: [jsxRuntime.jsxs("div", __assign({ className: "bunny-flex bunny-items-center bunny-justify-between bunny-gap-2" }, { children: [jsxRuntime.jsx(Text$2, __assign({ className: "bunny-text-xl", style: { fontWeight: 400 } }, { children: title })), onClose ? (jsxRuntime.jsx("button", __assign({ id: "closePayment", onClick: onClose, className: closeButtonClassName }, { children: jsxRuntime.jsx(icons.CloseOutlined, {}) }))) : null] })), description && jsxRuntime.jsx("div", __assign({ className: "bunny-text-xs" }, { children: description }))] })));
23180
+ return (jsxRuntime.jsxs("div", __assign({ className: "bunny-flex bunny-flex-col bunny-gap-4" }, { children: [jsxRuntime.jsxs("div", __assign({ className: "bunny-flex bunny-items-center bunny-justify-between bunny-gap-2" }, { children: [jsxRuntime.jsx(Text$3, __assign({ className: "bunny-text-xl", style: { fontWeight: 400 } }, { children: title })), onClose ? (jsxRuntime.jsx("button", __assign({ id: "closePayment", onClick: onClose, className: closeButtonClassName }, { children: jsxRuntime.jsx(icons.CloseOutlined, {}) }))) : null] })), description && jsxRuntime.jsx("div", __assign({ className: "bunny-text-xs" }, { children: description }))] })));
23346
23181
  };
23347
23182
 
23348
23183
  var formatDateForApi = function (date) {
@@ -23525,13 +23360,13 @@ var QuantityInput = function (_a) {
23525
23360
  }, status: isQuantityLowerThanOriginal(charge.quantity) ? 'error' : '', style: { width: '96px' }, value: value }) }));
23526
23361
  };
23527
23362
 
23528
- var Text$1 = antd.Typography.Text;
23363
+ var Text$2 = antd.Typography.Text;
23529
23364
  var QuantityChangeGridRow = function (_a) {
23530
23365
  var _b;
23531
23366
  var chargeIndex = _a.chargeIndex, editingQuote = _a.editingQuote, subscriptions = _a.subscriptions, subscriptionIndex = _a.subscriptionIndex, setEditingQuoteData = _a.setEditingQuoteData, subscription = _a.subscription, subscriptionCharge = _a.subscriptionCharge;
23532
23367
  if (!canShowQuantitiesInput(subscriptionCharge, subscription))
23533
23368
  return null;
23534
- return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(Text$1, __assign({ className: "bunny-font-medium bunny-text-orange-600 bunny-col-span-full", style: { fontSize: "11px" } }, { children: subscription.plan.name })), jsxRuntime.jsx(Text$1, __assign({ className: "bunny-font-medium bunny-text-base bunny-text-gray-900" }, { children: (_b = subscriptionCharge.name) === null || _b === void 0 ? void 0 : _b.toUpperCase() })), jsxRuntime.jsx(Text$1, __assign({ className: "bunny-flex bunny-items-center bunny-justify-end bunny-font-medium bunny-text-base bunny-text-gray-900" }, { children: subscriptionCharge.quantity })), jsxRuntime.jsxs("div", __assign({ className: "bunny-flex bunny-flex-col bunny-items-end" }, { children: [jsxRuntime.jsx(QuantityInput, { charge: subscriptionCharge, chargeIndex: chargeIndex, editingQuote: editingQuote, setEditingQuoteData: setEditingQuoteData, subscription: subscription, subscriptionIndex: subscriptionIndex, subscriptions: subscriptions }), jsxRuntime.jsx("div", {})] })), jsxRuntime.jsx(antd.Divider, { className: "bunny-col-span-full bunny-my-2" })] }));
23369
+ return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(Text$2, __assign({ className: "bunny-font-medium bunny-text-orange-600 bunny-col-span-full", style: { fontSize: "11px" } }, { children: subscription.plan.name })), jsxRuntime.jsx(Text$2, __assign({ className: "bunny-font-medium bunny-text-base bunny-text-gray-900" }, { children: (_b = subscriptionCharge.name) === null || _b === void 0 ? void 0 : _b.toUpperCase() })), jsxRuntime.jsx(Text$2, __assign({ className: "bunny-flex bunny-items-center bunny-justify-end bunny-font-medium bunny-text-base bunny-text-gray-900" }, { children: subscriptionCharge.quantity })), jsxRuntime.jsxs("div", __assign({ className: "bunny-flex bunny-flex-col bunny-items-end" }, { children: [jsxRuntime.jsx(QuantityInput, { charge: subscriptionCharge, chargeIndex: chargeIndex, editingQuote: editingQuote, setEditingQuoteData: setEditingQuoteData, subscription: subscription, subscriptionIndex: subscriptionIndex, subscriptions: subscriptions }), jsxRuntime.jsx("div", {})] })), jsxRuntime.jsx(antd.Divider, { className: "bunny-col-span-full bunny-my-2" })] }));
23535
23370
  };
23536
23371
 
23537
23372
  var QuantityChangeGridTitle = function (_a) {
@@ -23642,7 +23477,7 @@ var SubscriptionsNavigation = function (_a) {
23642
23477
  return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [!isMobile && expiredSwitchVisible && (jsxRuntime.jsx(HideExpiredToggle, { hideExpired: hideExpired, setHideExpired: setHideExpired })), jsxRuntime.jsx("div", __assign({ className: "bunny-flex bunny-grow bunny-gap-2 ".concat(isMobile ? 'bunny-flex-col' : 'bunny-justify-end') }, { children: canShowChangeQuantitiesButton && (jsxRuntime.jsx(ChangeQuantitiesButton, { canShowChangeQuantitiesButton: canShowChangeQuantitiesButton, setQuantityDrawerOpen: setQuantityDrawerOpen })) }))] }));
23643
23478
  };
23644
23479
 
23645
- var Text = antd.Typography.Text;
23480
+ var Text$1 = antd.Typography.Text;
23646
23481
  var SubscriptionsWrapper = function (_a) {
23647
23482
  var handlePortalErrors = _a.handlePortalErrors, companyName = _a.companyName, _b = _a.isInPreviewMode, isInPreviewMode = _b === void 0 ? false : _b, productId = _a.productId, className = _a.className, _c = _a.styles, userStyles = _c === void 0 ? {} : _c, noSubscriptionsComponent = _a.noSubscriptionsComponent, _d = _a.hideTitle, hideTitle = _d === void 0 ? false : _d, hideExpired = _a.hideExpired, _e = _a.hideExpiredToggle, hideExpiredToggle = _e === void 0 ? false : _e;
23648
23483
  var defaultStyles = {
@@ -23801,7 +23636,7 @@ var Subscriptions = function (_a) {
23801
23636
  setIsChangingPlan(false);
23802
23637
  }, handlePortalErrors: handlePortalErrors }));
23803
23638
  }
23804
- return (jsxRuntime.jsxs("div", __assign({ className: className }, { children: [!hideTitle ? jsxRuntime.jsx(PageTitle, { title: 'Subscriptions' }) : null, jsxRuntime.jsx(PageHeaderWithActions, __assign({ title: jsxRuntime.jsx(jsxRuntime.Fragment, { children: !hideExpiredToggle && (jsxRuntime.jsxs(Text, __assign({ className: "bunny-flex bunny-items-center bunny-justify-between", style: { minWidth: '120px' } }, { children: [hideExpired ? 'Active subscriptions' : 'All subscriptions', isMobile && expiredSwitchVisible && (jsxRuntime.jsx(HideExpiredToggle, { hideExpired: hideExpired, setHideExpired: setHideExpiredState }))] }))) }) }, { children: !isMobile && (jsxRuntime.jsx(SubscriptionsNavigation, { expiredSwitchVisible: !hideExpiredToggle && expiredSwitchVisible, hideExpired: hideExpired, setHideExpired: setHideExpiredState, setQuantityDrawerOpen: setQuantityDrawerOpen, subscriptions: subscriptions })) })), jsxRuntime.jsx(SubscriptionsListContainer, { companyName: companyName, hideExpired: hideExpired, onCancelSubscriptionClick: onCancelSubscriptionClick, onChangePlanClick: onChangePlanClick, subscriptions: subscriptions, subscriptionsAreLoading: subscriptionsAreLoading, noSubscriptionsComponent: noSubscriptionsComponent }), isMobile && (jsxRuntime.jsx("div", __assign({ className: "bunny-pt-4 bunny-pb-2" }, { children: jsxRuntime.jsx(SubscriptionsNavigation, { expiredSwitchVisible: expiredSwitchVisible, hideExpired: hideExpired, setHideExpired: setHideExpiredState, setQuantityDrawerOpen: setQuantityDrawerOpen, subscriptions: subscriptions }) }))), jsxRuntime.jsx(QuantityChangeDrawerDesktop, { editingQuote: quote, editingQuoteData: editingQuoteData, onClose: onClose, open: quantityDrawerOpen, openCheckout: function () { return setPayModalVisible(true); }, setEditingQuoteData: setEditingQuoteData, subscriptions: subscriptions }), jsxRuntime.jsx(Checkout, { onCancel: onCancel, onSuccess: onSuccess, onFail: onFail, open: payModalVisible, quote: quote, token: token, storedPaymentMethod: defaultPaymentMethod })] })));
23639
+ return (jsxRuntime.jsxs("div", __assign({ className: className }, { children: [!hideTitle ? jsxRuntime.jsx(PageTitle, { title: 'Subscriptions' }) : null, jsxRuntime.jsx(PageHeaderWithActions, __assign({ title: jsxRuntime.jsx(jsxRuntime.Fragment, { children: !hideExpiredToggle && (jsxRuntime.jsxs(Text$1, __assign({ className: "bunny-flex bunny-items-center bunny-justify-between", style: { minWidth: '120px' } }, { children: [hideExpired ? 'Active subscriptions' : 'All subscriptions', isMobile && expiredSwitchVisible && (jsxRuntime.jsx(HideExpiredToggle, { hideExpired: hideExpired, setHideExpired: setHideExpiredState }))] }))) }) }, { children: !isMobile && (jsxRuntime.jsx(SubscriptionsNavigation, { expiredSwitchVisible: !hideExpiredToggle && expiredSwitchVisible, hideExpired: hideExpired, setHideExpired: setHideExpiredState, setQuantityDrawerOpen: setQuantityDrawerOpen, subscriptions: subscriptions })) })), jsxRuntime.jsx(SubscriptionsListContainer, { companyName: companyName, hideExpired: hideExpired, onCancelSubscriptionClick: onCancelSubscriptionClick, onChangePlanClick: onChangePlanClick, subscriptions: subscriptions, subscriptionsAreLoading: subscriptionsAreLoading, noSubscriptionsComponent: noSubscriptionsComponent }), isMobile && (jsxRuntime.jsx("div", __assign({ className: "bunny-pt-4 bunny-pb-2" }, { children: jsxRuntime.jsx(SubscriptionsNavigation, { expiredSwitchVisible: expiredSwitchVisible, hideExpired: hideExpired, setHideExpired: setHideExpiredState, setQuantityDrawerOpen: setQuantityDrawerOpen, subscriptions: subscriptions }) }))), jsxRuntime.jsx(QuantityChangeDrawerDesktop, { editingQuote: quote, editingQuoteData: editingQuoteData, onClose: onClose, open: quantityDrawerOpen, openCheckout: function () { return setPayModalVisible(true); }, setEditingQuoteData: setEditingQuoteData, subscriptions: subscriptions }), jsxRuntime.jsx(Checkout, { onCancel: onCancel, onSuccess: onSuccess, onFail: onFail, open: payModalVisible, quote: quote, token: token, storedPaymentMethod: defaultPaymentMethod })] })));
23805
23640
  };
23806
23641
  var PageHeaderWithActions = function (_a) {
23807
23642
  var children = _a.children, title = _a.title;
@@ -23816,6 +23651,250 @@ var PageSubTitle = function (_a) {
23816
23651
  return (jsxRuntime.jsx("div", __assign({ className: "bunny-shrink-0 bunny-font-medium", style: { color: secondaryColor } }, { children: title })));
23817
23652
  };
23818
23653
 
23654
+ var MUTATION = "\nmutation BillingDetailsUpdate(\n $attributes: BillingDetailsAttributes!) {\n billingDetailsUpdate(\n attributes: $attributes\n ) {\n billingDetails {\n billingCity\n billingContact {\n email\n }\n billingCountry\n billingState\n billingStreet\n billingZip\n name\n taxNumber\n }\n errors\n }\n }\n";
23655
+ var billingDetailsUpdate = function (_a) {
23656
+ var attributes = _a.attributes, token = _a.token, apiHost = _a.apiHost;
23657
+ return __awaiter(void 0, void 0, void 0, function () {
23658
+ var vars, response, errors;
23659
+ var _b;
23660
+ return __generator(this, function (_c) {
23661
+ switch (_c.label) {
23662
+ case 0:
23663
+ vars = { attributes: attributes };
23664
+ return [4 /*yield*/, gqlRequest({
23665
+ query: MUTATION,
23666
+ token: token,
23667
+ vars: vars,
23668
+ apiHost: apiHost,
23669
+ })];
23670
+ case 1:
23671
+ response = _c.sent();
23672
+ errors = (_b = response === null || response === void 0 ? void 0 : response.billingDetailsUpdate) === null || _b === void 0 ? void 0 : _b.errors;
23673
+ if (errors)
23674
+ throw errors;
23675
+ return [2 /*return*/, response.billingDetailsUpdate];
23676
+ }
23677
+ });
23678
+ });
23679
+ };
23680
+
23681
+ // TODO: move this to common
23682
+ var billingDetailsQuery = function () {
23683
+ return "\nquery BillingDetails {\n billingDetails {\n billingCity\n billingContact {\n email\n }\n billingCountry\n billingState\n billingStreet\n billingZip\n name\n taxNumber\n currency {\n id\n }\n }\n}";
23684
+ };
23685
+ var getBillingDetails = function (_a) {
23686
+ var token = _a.token, apiHost = _a.apiHost;
23687
+ return __awaiter(void 0, void 0, void 0, function () {
23688
+ var response;
23689
+ var _b;
23690
+ return __generator(this, function (_c) {
23691
+ switch (_c.label) {
23692
+ case 0: return [4 /*yield*/, gqlRequest({
23693
+ query: billingDetailsQuery(),
23694
+ token: token,
23695
+ apiHost: apiHost,
23696
+ })];
23697
+ case 1:
23698
+ response = _c.sent();
23699
+ if (response === null || response === void 0 ? void 0 : response.errors) {
23700
+ throw new Error((_b = response === null || response === void 0 ? void 0 : response.errors[0]) === null || _b === void 0 ? void 0 : _b.message);
23701
+ }
23702
+ return [2 /*return*/, response === null || response === void 0 ? void 0 : response.billingDetails];
23703
+ }
23704
+ });
23705
+ });
23706
+ };
23707
+
23708
+ var Text = antd.Typography.Text;
23709
+ function BillingDetailsSection(_a) {
23710
+ var _this = this;
23711
+ var hidePaymentMethodForm = _a.hidePaymentMethodForm, countryListFilter = _a.countryListFilter;
23712
+ // State
23713
+ var _b = react.useState(false), isFormEdited = _b[0], setIsFormEdited = _b[1];
23714
+ var _c = react.useState(false), formIsValid = _c[0], setFormIsValid = _c[1];
23715
+ var form = antd.Form.useForm()[0];
23716
+ var values = antd.Form.useWatch([], form);
23717
+ // Context
23718
+ var apiHost = react.useContext(BunnyContext).apiHost;
23719
+ var token = useToken();
23720
+ // Hooks
23721
+ var isMobile = common.useIsMobile();
23722
+ var queryClient = reactQuery.useQueryClient();
23723
+ var showErrorNotification = common.useErrorNotification();
23724
+ var showSuccessNotification = common.useSuccessNotification();
23725
+ // Queries
23726
+ var _d = reactQuery.useQuery({
23727
+ queryKey: common.QueryKeyFactory.default.billingDetailsKey({ token: token }),
23728
+ queryFn: function () { return getBillingDetails({ token: token, apiHost: apiHost }); },
23729
+ }), billingDetails = _d.data, isLoadingBillingDetails = _d.isLoading;
23730
+ var _e = reactQuery.useMutation({
23731
+ mutationFn: function (changedFormData) { return __awaiter(_this, void 0, void 0, function () {
23732
+ var updatedBillingDetails;
23733
+ return __generator(this, function (_a) {
23734
+ switch (_a.label) {
23735
+ case 0: return [4 /*yield*/, billingDetailsUpdate({
23736
+ attributes: {
23737
+ name: changedFormData.name,
23738
+ billingStreet: changedFormData.billingStreet,
23739
+ billingCity: changedFormData.billingCity,
23740
+ billingZip: changedFormData.billingZip,
23741
+ billingState: changedFormData.billingState,
23742
+ billingCountry: changedFormData.billingCountry,
23743
+ billingContactEmail: changedFormData.billingContactEmail,
23744
+ taxNumber: changedFormData.taxNumber,
23745
+ },
23746
+ token: token,
23747
+ apiHost: apiHost,
23748
+ })];
23749
+ case 1:
23750
+ updatedBillingDetails = _a.sent();
23751
+ queryClient.setQueryData(common.QueryKeyFactory.default.billingDetailsKey({ token: token }), function (old) {
23752
+ return __assign(__assign({}, old), updatedBillingDetails.billingDetails);
23753
+ });
23754
+ return [2 /*return*/, updatedBillingDetails];
23755
+ }
23756
+ });
23757
+ }); },
23758
+ onSuccess: function () {
23759
+ showSuccessNotification('Your account details have been saved');
23760
+ queryClient.invalidateQueries({
23761
+ queryKey: common.QueryKeyFactory.default.taxationRequiredAccountFieldsKey({
23762
+ token: token,
23763
+ }),
23764
+ });
23765
+ },
23766
+ }), updateBillingDetails = _e.mutate, isUpdatingBillingDetails = _e.isPending;
23767
+ // Set form values when billing details are loaded
23768
+ react.useEffect(function () {
23769
+ var _a;
23770
+ if (billingDetails) {
23771
+ form.setFieldsValue({
23772
+ billingStreet: billingDetails.billingStreet,
23773
+ billingCity: billingDetails.billingCity,
23774
+ billingZip: billingDetails.billingZip,
23775
+ billingState: billingDetails.billingState,
23776
+ billingCountry: billingDetails.billingCountry,
23777
+ billingContactEmail: (_a = billingDetails.billingContact) === null || _a === void 0 ? void 0 : _a.email,
23778
+ taxNumber: billingDetails.taxNumber,
23779
+ });
23780
+ }
23781
+ }, [billingDetails]);
23782
+ react.useEffect(function () {
23783
+ form
23784
+ .validateFields({ validateOnly: true })
23785
+ .then(function () { return setFormIsValid(true); })
23786
+ .catch(function () { return setFormIsValid(false); });
23787
+ var isFormEdited = function () {
23788
+ var _a;
23789
+ if (!billingDetails)
23790
+ return false;
23791
+ var currentValues = form.getFieldsValue();
23792
+ var accountValues = {
23793
+ billingStreet: billingDetails.billingStreet,
23794
+ billingCity: billingDetails.billingCity,
23795
+ billingZip: billingDetails.billingZip,
23796
+ billingState: billingDetails.billingState,
23797
+ billingCountry: billingDetails.billingCountry,
23798
+ billingContactEmail: (_a = billingDetails.billingContact) === null || _a === void 0 ? void 0 : _a.email,
23799
+ taxNumber: billingDetails.taxNumber,
23800
+ };
23801
+ return Object.keys(currentValues).some(function (key) {
23802
+ var value = accountValues[key];
23803
+ return currentValues[key] !== value;
23804
+ });
23805
+ };
23806
+ setIsFormEdited(isFormEdited());
23807
+ }, [form, values, billingDetails]);
23808
+ // Validate form fields when isFormEdited changes
23809
+ react.useEffect(function () {
23810
+ var validateOnly = isFormEdited ? false : true;
23811
+ form.validateFields({ validateOnly: validateOnly });
23812
+ }, [isFormEdited]);
23813
+ var saveBillingDetails = function () { return __awaiter(_this, void 0, void 0, function () {
23814
+ var _this = this;
23815
+ return __generator(this, function (_a) {
23816
+ form.validateFields({ validateOnly: false }).then(function () { return __awaiter(_this, void 0, void 0, function () {
23817
+ var error_1;
23818
+ return __generator(this, function (_a) {
23819
+ switch (_a.label) {
23820
+ case 0:
23821
+ _a.trys.push([0, 2, 3, 4]);
23822
+ return [4 /*yield*/, form.validateFields()];
23823
+ case 1:
23824
+ _a.sent();
23825
+ updateBillingDetails(form.getFieldsValue());
23826
+ return [3 /*break*/, 4];
23827
+ case 2:
23828
+ error_1 = _a.sent();
23829
+ if (error_1 instanceof Error) {
23830
+ showErrorNotification('Failed to update account', error_1.message);
23831
+ }
23832
+ else {
23833
+ showErrorNotification('Please fill out all required fields');
23834
+ }
23835
+ return [3 /*break*/, 4];
23836
+ case 3:
23837
+ setIsFormEdited(false);
23838
+ return [7 /*endfinally*/];
23839
+ case 4: return [2 /*return*/];
23840
+ }
23841
+ });
23842
+ }); });
23843
+ return [2 /*return*/];
23844
+ });
23845
+ }); };
23846
+ var filteredCountryList = react.useMemo(function () {
23847
+ return countryListFilter ? common.Lists.COUNTRY_LIST.filter(countryListFilter) : common.Lists.COUNTRY_LIST;
23848
+ }, [countryListFilter]);
23849
+ return (jsxRuntime.jsx("div", __assign({ className: "".concat(isMobile || hidePaymentMethodForm ? 'bunny-w-full' : 'bunny-w-1/2') }, { children: jsxRuntime.jsxs("div", __assign({ className: "bunny-px-4" }, { children: [jsxRuntime.jsxs(antd.Skeleton, __assign({ loading: isLoadingBillingDetails }, { children: [jsxRuntime.jsx("div", __assign({ className: "bunny-mb-2" }, { children: jsxRuntime.jsx(Text, __assign({ className: "bunny-font-medium bunny-text-lg" }, { children: (billingDetails === null || billingDetails === void 0 ? void 0 : billingDetails.name) || 'No company name' })) })), jsxRuntime.jsxs(antd.Form, __assign({ className: "bunny-flex bunny-flex-col bunny-gap-2", form: form, layout: "vertical", disabled: isUpdatingBillingDetails, autoComplete: "off" }, { children: [jsxRuntime.jsx(antd.Form.Item, __assign({ label: "Street address", name: "billingStreet", rules: [{ required: true, message: 'Street address is required' }] }, { children: jsxRuntime.jsx(antd.Input, {}) })), jsxRuntime.jsxs("div", __assign({ className: "bunny-flex bunny-gap-4" }, { children: [jsxRuntime.jsx(antd.Form.Item, __assign({ label: "City", name: "billingCity", rules: [{ required: true, message: 'City is required' }], className: "bunny-flex-1" }, { children: jsxRuntime.jsx(antd.Input, {}) })), jsxRuntime.jsx(antd.Form.Item, __assign({ label: "Zipcode", name: "billingZip", rules: [{ required: true, message: 'Zipcode is required' }], className: "bunny-flex-1" }, { children: jsxRuntime.jsx(antd.Input, {}) }))] })), jsxRuntime.jsxs("div", __assign({ className: "bunny-flex ".concat(isMobile ? 'bunny-flex-row bunny-pb-2' : 'bunny-flex-row', " bunny-gap-4") }, { children: [jsxRuntime.jsx("div", __assign({ className: "bunny-flex-1 bunny-w-1/2" }, { children: jsxRuntime.jsx(antd.Form.Item, __assign({ label: "State", name: "billingState", rules: [
23850
+ {
23851
+ required: false,
23852
+ },
23853
+ ] }, { children: jsxRuntime.jsx(antd.Input, {}) })) })), jsxRuntime.jsx("div", __assign({ className: "bunny-flex-1 bunny-w-1/2" }, { children: jsxRuntime.jsx(antd.Form.Item, __assign({ label: "Country", name: "billingCountry", rules: [{ required: true, message: 'Country is required' }] }, { children: jsxRuntime.jsx(antd.Select, { className: "bunny-w-full", options: filteredCountryList, placeholder: "Select a country", popupMatchSelectWidth: false, showSearch: true, filterOption: function (input, option) {
23854
+ var _a, _b;
23855
+ return ((_a = option === null || option === void 0 ? void 0 : option.label) !== null && _a !== void 0 ? _a : '').toLowerCase().includes(input.toLowerCase()) ||
23856
+ ((_b = option === null || option === void 0 ? void 0 : option.value) !== null && _b !== void 0 ? _b : '').toLowerCase().includes(input.toLowerCase());
23857
+ } }) })) }))] })), jsxRuntime.jsx(antd.Form.Item, __assign({ label: "Email", name: "billingContactEmail", rules: [
23858
+ {
23859
+ required: true,
23860
+ message: 'Email is required',
23861
+ type: 'email',
23862
+ },
23863
+ ] }, { children: jsxRuntime.jsx(antd.Input, {}) })), jsxRuntime.jsx(antd.Form.Item, __assign({ label: "Tax ID", name: "taxNumber", tooltip: "Tax ID will be printed on quotes and invoices below the account's address", rules: [{ required: false }] }, { children: jsxRuntime.jsx(antd.Input, {}) }))] }))] })), jsxRuntime.jsx(antd.Button, __assign({ disabled: !isFormEdited || isUpdatingBillingDetails || !formIsValid, className: "bunny-w-full bunny-mt-4", type: "primary", onClick: saveBillingDetails }, { children: "Save" }))] })) })));
23864
+ }
23865
+
23866
+ var BillingDetails = function (_a) {
23867
+ var className = _a.className, countryListFilter = _a.countryListFilter, _b = _a.hideBillingDetailsForm, hideBillingDetailsForm = _b === void 0 ? false : _b, _c = _a.hidePaymentMethodForm, hidePaymentMethodForm = _c === void 0 ? false : _c, _d = _a.isCardEnabled, isCardEnabled = _d === void 0 ? true : _d, _e = _a.isUpgradeFromTrial, isUpgradeFromTrial = _e === void 0 ? false : _e, _f = _a.shadow, shadow = _f === void 0 ? 'shadow-md' : _f, onSavePaymentMethod = _a.onSavePaymentMethod;
23868
+ // Hooks
23869
+ var isMobile = common.useIsMobile();
23870
+ return (jsxRuntime.jsx(WrapperComponent, __assign({ isCardEnabled: isCardEnabled, shadow: shadow, className: className }, { children: jsxRuntime.jsxs("div", __assign({ className: "bunny-flex bunny-py-2 bunny-my-2 ".concat(isMobile ? 'bunny-flex-col bunny-space-y-4' : 'bunny-flex-row', " bunny-gap-4") }, { children: [!hideBillingDetailsForm ? (jsxRuntime.jsx(BillingDetailsSection, { hidePaymentMethodForm: hidePaymentMethodForm, countryListFilter: countryListFilter })) : null, !hideBillingDetailsForm && !hidePaymentMethodForm ? jsxRuntime.jsx(ResponsiveDivider, {}) : null, !hidePaymentMethodForm ? (jsxRuntime.jsx(PaymentFormSection, { hideBillingDetailsForm: hideBillingDetailsForm, isUpgradeFromTrial: isUpgradeFromTrial, onSavePaymentMethod: onSavePaymentMethod })) : null] })) })));
23871
+ };
23872
+ var WrapperComponent = function (_a) {
23873
+ var children = _a.children, isCardEnabled = _a.isCardEnabled, shadow = _a.shadow, className = _a.className;
23874
+ return (jsxRuntime.jsx("div", __assign({ className: "".concat(className) }, { children: isCardEnabled ? jsxRuntime.jsx(Card, __assign({ className: "".concat(shadow) }, { children: children })) : jsxRuntime.jsx("div", { children: children }) })));
23875
+ };
23876
+ var ResponsiveDivider = function () {
23877
+ var isMobile = common.useIsMobile();
23878
+ return isMobile ? (jsxRuntime.jsx("div", __assign({ className: "bunny-mx-4" }, { children: jsxRuntime.jsx(antd.Divider, {}) }))) : (jsxRuntime.jsx("div", { children: jsxRuntime.jsx(antd.Divider, { className: "bunny-h-full", type: "vertical" }) }));
23879
+ };
23880
+ var PaymentFormSection = function (_a) {
23881
+ var hideBillingDetailsForm = _a.hideBillingDetailsForm, isUpgradeFromTrial = _a.isUpgradeFromTrial, onSavePaymentMethod = _a.onSavePaymentMethod;
23882
+ var isMobile = common.useIsMobile();
23883
+ var onTokenExpired = react.useContext(BunnyContext).onTokenExpired;
23884
+ var handleAllErrorFormats = common.useAllErrorFormats(onTokenExpired);
23885
+ var showSuccessNotification = common.useSuccessNotification();
23886
+ return (jsxRuntime.jsx("div", __assign({ className: "".concat(isMobile || hideBillingDetailsForm ? 'bunny-w-full' : 'bunny-w-1/2 bunny-pt-4', " bunny-flex bunny-justify-center") }, { children: jsxRuntime.jsx(PaymentForm, { onFail: function (error) {
23887
+ handleAllErrorFormats(error);
23888
+ }, onSavePaymentMethod: function (response) {
23889
+ showSuccessNotification(isUpgradeFromTrial
23890
+ ? 'Payment method saved! Your trial will automatically convert to a paid subscription.'
23891
+ : 'Payment method saved successfully!');
23892
+ // TODO: onSavePaymentMethod(response: any) should be cleaned up to have a response type (not any)
23893
+ // and work with both stripe and demo pay requests
23894
+ onSavePaymentMethod === null || onSavePaymentMethod === void 0 ? void 0 : onSavePaymentMethod(response);
23895
+ } }) })));
23896
+ };
23897
+
23819
23898
  exports.BillingDetails = BillingDetails;
23820
23899
  exports.BunnyProvider = BunnyProvider;
23821
23900
  exports.Footer = Footer;