@bunnyapp/components 1.0.76-beta.10 → 1.0.76-beta.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/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.10';
157
+ var PACKAGE_VERSION = '1.0.76-beta.12';
158
158
  var createRequestHeaders = function (token) {
159
159
  var headers = common.createClientDevHeaders(token);
160
160
  // Add the components version header
@@ -22194,6 +22194,9 @@ var PriceListGridDesktop = function (_a) {
22194
22194
  }, [availablePriceLists, priceListChangeOptions, priceListStart]); _b.availablePriceListsArray; var displayPriceLists = _b.displayPriceLists;
22195
22195
  var everythingInPlus = selectedProduct === null || selectedProduct === void 0 ? void 0 : selectedProduct.everythingInPlus;
22196
22196
  var plansToDisplay = Math.min((selectedProduct === null || selectedProduct === void 0 ? void 0 : selectedProduct.plansToDisplay) || 3, availablePriceLists.length);
22197
+ var hasFeatureAddons = displayPriceLists.some(function (priceList) {
22198
+ return priceList.charges.some(function (charge) { return charge.featureAddon; });
22199
+ });
22197
22200
  return (jsxRuntime.jsxs("div", __assign({ className: "bunny-relative bunny-flex bunny-flex-col bunny-rounded-md bunny-shadow bunny-overflow-hidden bunny-bg-white" }, { children: [jsxRuntime.jsx(NextPriceListButton, { availablePriceLists: availablePriceLists, numberOfPlansToDisplay: plansToDisplay, priceListStart: priceListStart, setPriceListStart: setPriceListStart }), jsxRuntime.jsxs("div", __assign({ className: "bunny-grid bunny-w-full", style: {
22198
22201
  gridTemplateColumns: everythingInPlus
22199
22202
  ? "repeat(".concat(plansToDisplay, ", minmax(120px, 1fr))")
@@ -22204,7 +22207,7 @@ var PriceListGridDesktop = function (_a) {
22204
22207
  if (!priceList)
22205
22208
  return jsxRuntime.jsx(PlanPickerGridCell, { noBorder: !Boolean(doesPrevPriceListExist) }, index);
22206
22209
  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));
22207
- }), (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 }), jsxRuntime.jsx(PlanFeatureAddons, { displayPriceLists: displayPriceLists, plansToDisplay: plansToDisplay })] }))] }))] })));
22210
+ }), (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 }))] }))] }))] })));
22208
22211
  };
22209
22212
 
22210
22213
  var Text$9 = antd.Typography.Text;
@@ -22777,19 +22780,278 @@ var getApplicablePriceTier = function (charge, currencyId, priceDecimals) {
22777
22780
  : "".concat(common.formatCurrency(selectedTier.price, currencyId, priceDecimals));
22778
22781
  };
22779
22782
 
22783
+ 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";
22784
+ var billingDetailsUpdate = function (_a) {
22785
+ var attributes = _a.attributes, token = _a.token, apiHost = _a.apiHost;
22786
+ return __awaiter(void 0, void 0, void 0, function () {
22787
+ var vars, response, errors;
22788
+ var _b;
22789
+ return __generator(this, function (_c) {
22790
+ switch (_c.label) {
22791
+ case 0:
22792
+ vars = { attributes: attributes };
22793
+ return [4 /*yield*/, gqlRequest({
22794
+ query: MUTATION,
22795
+ token: token,
22796
+ vars: vars,
22797
+ apiHost: apiHost,
22798
+ })];
22799
+ case 1:
22800
+ response = _c.sent();
22801
+ errors = (_b = response === null || response === void 0 ? void 0 : response.billingDetailsUpdate) === null || _b === void 0 ? void 0 : _b.errors;
22802
+ if (errors)
22803
+ throw errors;
22804
+ return [2 /*return*/, response.billingDetailsUpdate];
22805
+ }
22806
+ });
22807
+ });
22808
+ };
22809
+
22810
+ // TODO: move this to common
22811
+ var billingDetailsQuery = function () {
22812
+ 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}";
22813
+ };
22814
+ var getBillingDetails = function (_a) {
22815
+ var token = _a.token, apiHost = _a.apiHost;
22816
+ return __awaiter(void 0, void 0, void 0, function () {
22817
+ var response;
22818
+ var _b;
22819
+ return __generator(this, function (_c) {
22820
+ switch (_c.label) {
22821
+ case 0: return [4 /*yield*/, gqlRequest({
22822
+ query: billingDetailsQuery(),
22823
+ token: token,
22824
+ apiHost: apiHost,
22825
+ })];
22826
+ case 1:
22827
+ response = _c.sent();
22828
+ if (response === null || response === void 0 ? void 0 : response.errors) {
22829
+ throw new Error((_b = response === null || response === void 0 ? void 0 : response.errors[0]) === null || _b === void 0 ? void 0 : _b.message);
22830
+ }
22831
+ return [2 /*return*/, response === null || response === void 0 ? void 0 : response.billingDetails];
22832
+ }
22833
+ });
22834
+ });
22835
+ };
22836
+
22837
+ var Text$7 = antd.Typography.Text;
22838
+ function BillingDetailsSection(_a) {
22839
+ var _this = this;
22840
+ var hidePaymentMethodForm = _a.hidePaymentMethodForm, countryListFilter = _a.countryListFilter;
22841
+ // State
22842
+ var _b = react.useState(false), isFormEdited = _b[0], setIsFormEdited = _b[1];
22843
+ var _c = react.useState(false), formIsValid = _c[0], setFormIsValid = _c[1];
22844
+ var form = antd.Form.useForm()[0];
22845
+ var values = antd.Form.useWatch([], form);
22846
+ // Context
22847
+ var apiHost = react.useContext(BunnyContext).apiHost;
22848
+ var token = useToken();
22849
+ // Hooks
22850
+ var isMobile = common.useIsMobile();
22851
+ var queryClient = reactQuery.useQueryClient();
22852
+ var showErrorNotification = common.useErrorNotification();
22853
+ var showSuccessNotification = common.useSuccessNotification();
22854
+ // Queries
22855
+ var _d = reactQuery.useQuery({
22856
+ queryKey: common.QueryKeyFactory.default.billingDetailsKey({ token: token }),
22857
+ queryFn: function () { return getBillingDetails({ token: token, apiHost: apiHost }); },
22858
+ }), billingDetails = _d.data, isLoadingBillingDetails = _d.isLoading;
22859
+ var _e = reactQuery.useMutation({
22860
+ mutationFn: function (changedFormData) { return __awaiter(_this, void 0, void 0, function () {
22861
+ var updatedBillingDetails;
22862
+ return __generator(this, function (_a) {
22863
+ switch (_a.label) {
22864
+ case 0: return [4 /*yield*/, billingDetailsUpdate({
22865
+ attributes: {
22866
+ name: changedFormData.name,
22867
+ billingStreet: changedFormData.billingStreet,
22868
+ billingCity: changedFormData.billingCity,
22869
+ billingZip: changedFormData.billingZip,
22870
+ billingState: changedFormData.billingState,
22871
+ billingCountry: changedFormData.billingCountry,
22872
+ billingContactEmail: changedFormData.billingContactEmail,
22873
+ taxNumber: changedFormData.taxNumber,
22874
+ },
22875
+ token: token,
22876
+ apiHost: apiHost,
22877
+ })];
22878
+ case 1:
22879
+ updatedBillingDetails = _a.sent();
22880
+ queryClient.setQueryData(common.QueryKeyFactory.default.billingDetailsKey({ token: token }), function (old) {
22881
+ return __assign(__assign({}, old), updatedBillingDetails.billingDetails);
22882
+ });
22883
+ return [2 /*return*/, updatedBillingDetails];
22884
+ }
22885
+ });
22886
+ }); },
22887
+ onSuccess: function () {
22888
+ showSuccessNotification('Your account details have been saved');
22889
+ queryClient.invalidateQueries({
22890
+ queryKey: common.QueryKeyFactory.default.taxationRequiredAccountFieldsKey({
22891
+ token: token,
22892
+ }),
22893
+ });
22894
+ },
22895
+ }), updateBillingDetails = _e.mutate, isUpdatingBillingDetails = _e.isPending;
22896
+ // Set form values when billing details are loaded
22897
+ react.useEffect(function () {
22898
+ var _a;
22899
+ if (billingDetails) {
22900
+ form.setFieldsValue({
22901
+ billingStreet: billingDetails.billingStreet,
22902
+ billingCity: billingDetails.billingCity,
22903
+ billingZip: billingDetails.billingZip,
22904
+ billingState: billingDetails.billingState,
22905
+ billingCountry: billingDetails.billingCountry,
22906
+ billingContactEmail: (_a = billingDetails.billingContact) === null || _a === void 0 ? void 0 : _a.email,
22907
+ taxNumber: billingDetails.taxNumber,
22908
+ });
22909
+ }
22910
+ }, [billingDetails]);
22911
+ react.useEffect(function () {
22912
+ form
22913
+ .validateFields({ validateOnly: true })
22914
+ .then(function () { return setFormIsValid(true); })
22915
+ .catch(function () { return setFormIsValid(false); });
22916
+ var isFormEdited = function () {
22917
+ var _a;
22918
+ if (!billingDetails)
22919
+ return false;
22920
+ var currentValues = form.getFieldsValue();
22921
+ var accountValues = {
22922
+ billingStreet: billingDetails.billingStreet,
22923
+ billingCity: billingDetails.billingCity,
22924
+ billingZip: billingDetails.billingZip,
22925
+ billingState: billingDetails.billingState,
22926
+ billingCountry: billingDetails.billingCountry,
22927
+ billingContactEmail: (_a = billingDetails.billingContact) === null || _a === void 0 ? void 0 : _a.email,
22928
+ taxNumber: billingDetails.taxNumber,
22929
+ };
22930
+ return Object.keys(currentValues).some(function (key) {
22931
+ var value = accountValues[key];
22932
+ return currentValues[key] !== value;
22933
+ });
22934
+ };
22935
+ setIsFormEdited(isFormEdited());
22936
+ }, [form, values, billingDetails]);
22937
+ // Validate form fields when isFormEdited changes
22938
+ react.useEffect(function () {
22939
+ var validateOnly = isFormEdited ? false : true;
22940
+ form.validateFields({ validateOnly: validateOnly });
22941
+ }, [isFormEdited]);
22942
+ var saveBillingDetails = function () { return __awaiter(_this, void 0, void 0, function () {
22943
+ var _this = this;
22944
+ return __generator(this, function (_a) {
22945
+ form.validateFields({ validateOnly: false }).then(function () { return __awaiter(_this, void 0, void 0, function () {
22946
+ var error_1;
22947
+ return __generator(this, function (_a) {
22948
+ switch (_a.label) {
22949
+ case 0:
22950
+ _a.trys.push([0, 2, 3, 4]);
22951
+ return [4 /*yield*/, form.validateFields()];
22952
+ case 1:
22953
+ _a.sent();
22954
+ updateBillingDetails(form.getFieldsValue());
22955
+ return [3 /*break*/, 4];
22956
+ case 2:
22957
+ error_1 = _a.sent();
22958
+ if (error_1 instanceof Error) {
22959
+ showErrorNotification('Failed to update account', error_1.message);
22960
+ }
22961
+ else {
22962
+ showErrorNotification('Please fill out all required fields');
22963
+ }
22964
+ return [3 /*break*/, 4];
22965
+ case 3:
22966
+ setIsFormEdited(false);
22967
+ return [7 /*endfinally*/];
22968
+ case 4: return [2 /*return*/];
22969
+ }
22970
+ });
22971
+ }); });
22972
+ return [2 /*return*/];
22973
+ });
22974
+ }); };
22975
+ var filteredCountryList = react.useMemo(function () {
22976
+ return countryListFilter ? common.Lists.COUNTRY_LIST.filter(countryListFilter) : common.Lists.COUNTRY_LIST;
22977
+ }, [countryListFilter]);
22978
+ 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: [
22979
+ {
22980
+ required: false,
22981
+ },
22982
+ ] }, { 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) {
22983
+ var _a, _b;
22984
+ return ((_a = option === null || option === void 0 ? void 0 : option.label) !== null && _a !== void 0 ? _a : '').toLowerCase().includes(input.toLowerCase()) ||
22985
+ ((_b = option === null || option === void 0 ? void 0 : option.value) !== null && _b !== void 0 ? _b : '').toLowerCase().includes(input.toLowerCase());
22986
+ } }) })) }))] })), jsxRuntime.jsx(antd.Form.Item, __assign({ label: "Email", name: "billingContactEmail", rules: [
22987
+ {
22988
+ required: true,
22989
+ message: 'Email is required',
22990
+ type: 'email',
22991
+ },
22992
+ ] }, { 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" }))] })) })));
22993
+ }
22994
+
22995
+ var BillingDetails = function (_a) {
22996
+ 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;
22997
+ // Hooks
22998
+ var isMobile = common.useIsMobile();
22999
+ 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] })) })));
23000
+ };
23001
+ var WrapperComponent = function (_a) {
23002
+ var children = _a.children, isCardEnabled = _a.isCardEnabled, shadow = _a.shadow, className = _a.className;
23003
+ return (jsxRuntime.jsx("div", __assign({ className: "".concat(className) }, { children: isCardEnabled ? jsxRuntime.jsx(Card, __assign({ className: "".concat(shadow) }, { children: children })) : jsxRuntime.jsx("div", { children: children }) })));
23004
+ };
23005
+ var ResponsiveDivider = function () {
23006
+ var isMobile = common.useIsMobile();
23007
+ 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" }) }));
23008
+ };
23009
+ var PaymentFormSection = function (_a) {
23010
+ var hideBillingDetailsForm = _a.hideBillingDetailsForm, isUpgradeFromTrial = _a.isUpgradeFromTrial, onSavePaymentMethod = _a.onSavePaymentMethod;
23011
+ var isMobile = common.useIsMobile();
23012
+ var onTokenExpired = react.useContext(BunnyContext).onTokenExpired;
23013
+ var handleAllErrorFormats = common.useAllErrorFormats(onTokenExpired);
23014
+ var showSuccessNotification = common.useSuccessNotification();
23015
+ var entityId = useCurrentUserData().entityId;
23016
+ 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) {
23017
+ handleAllErrorFormats(error);
23018
+ }, onSavePaymentMethod: function () {
23019
+ showSuccessNotification(isUpgradeFromTrial
23020
+ ? 'Payment method saved! Your trial will automatically convert to a paid subscription.'
23021
+ : 'Payment method saved successfully!');
23022
+ onSavePaymentMethod === null || onSavePaymentMethod === void 0 ? void 0 : onSavePaymentMethod();
23023
+ } }) })));
23024
+ };
23025
+
23026
+ var UpgradeFromTrial = function (_a) {
23027
+ var onClose = _a.onClose, open = _a.open;
23028
+ return (jsxRuntime.jsx(antd.Modal, __assign({ width: '80vw', open: open, onCancel: onClose, footer: null }, { children: jsxRuntime.jsx(BillingDetails, { isUpgradeFromTrial: true, onSavePaymentMethod: onClose }) })));
23029
+ };
23030
+
22780
23031
  var SubscriptionCardActions = function (_a) {
22781
23032
  var _b;
22782
23033
  var onChangePlanClick = _a.onChangePlanClick, onCancelSubscriptionClick = _a.onCancelSubscriptionClick, priceListChangeOptions = _a.priceListChangeOptions, subscription = _a.subscription;
23034
+ var apiHost = react.useContext(BunnyContext).apiHost;
23035
+ var token = useToken();
23036
+ var _c = usePaymentMethod({
23037
+ accountId: subscription.accountId,
23038
+ token: token,
23039
+ apiHost: apiHost,
23040
+ }), storedPaymentMethods = _c.paymentMethods, isPaymentMethodLoading = _c.isLoading;
23041
+ // Local state
23042
+ var _d = react.useState(false), isUpgradeFromTrialModalOpen = _d[0], setIsUpgradeFromTrialModalOpen = _d[1];
22783
23043
  // Derived state
22784
23044
  var isSelfServiceCancelable = subscription.plan.selfServiceCancel;
22785
23045
  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; });
22786
23046
  var arePlansAvailable = ((productPlans === null || productPlans === void 0 ? void 0 : productPlans.length) || 0) > 0;
22787
23047
  var isInTrial = isSubscriptionTrial(subscription);
22788
23048
  var isActiveOrPending = isSubscriptionActiveOrPending(subscription);
22789
- 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 && (isInTrial || isActiveOrPending) && (jsxRuntime.jsx(antd.Button, __assign({ onClick: function () { return onChangePlanClick(subscription); }, type: "primary" }, { children: isInTrial ? 'Upgrade' : 'Change plan' })))] }));
23049
+ if (isPaymentMethodLoading)
23050
+ return null;
23051
+ 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 })] }));
22790
23052
  };
22791
23053
 
22792
- var Text$7 = antd.Typography.Text;
23054
+ var Text$6 = antd.Typography.Text;
22793
23055
  var getSubscriptionStatusText = function (subscription) {
22794
23056
  var cancellationDate = subscription.cancellationDate, state = subscription.state, evergreen = subscription.evergreen, endDate = subscription.endDate;
22795
23057
  if (cancellationDate &&
@@ -22818,7 +23080,7 @@ var SubscriptionCardHeader = function (_a) {
22818
23080
  var isTrial = ((_b = subscription.state) === null || _b === void 0 ? void 0 : _b.toUpperCase()) === common.SubscriptionState.TRIAL;
22819
23081
  return (jsxRuntime.jsxs("div", __assign({ className: "bunny-flex bunny-items-center bunny-justify-between", style: {
22820
23082
  backgroundColor: darkMode ? 'var(--row-background-dark)' : '',
22821
- } }, { 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 }))] }))] })));
23083
+ } }, { 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 }))] }))] })));
22822
23084
  };
22823
23085
 
22824
23086
  var SubscriptionChargeTotal = function (_a) {
@@ -22895,16 +23157,16 @@ var SubscriptionChargeUnitPrice = function (_a) {
22895
23157
  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) }));
22896
23158
  };
22897
23159
 
22898
- var Text$6 = antd.Typography.Text;
23160
+ var Text$5 = antd.Typography.Text;
22899
23161
  var SubscriptionCardColumnHeaders = function (_a) {
22900
23162
  var columns = _a.columns;
22901
- 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)); }) }));
23163
+ 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)); }) }));
22902
23164
  };
22903
23165
 
22904
- var Text$5 = antd.Typography.Text;
23166
+ var Text$4 = antd.Typography.Text;
22905
23167
  var SubscriptionsListCell = function (_a) {
22906
23168
  var children = _a.children, className = _a.className, gridColumn = _a.gridColumn, right = _a.right, style = _a.style;
22907
- 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 })));
23169
+ 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 })));
22908
23170
  };
22909
23171
 
22910
23172
  var CARD_COLUMNS = [
@@ -22992,10 +23254,10 @@ var SubscriptionCardDesktopRow = function (_a) {
22992
23254
  : (_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 }) }))] })));
22993
23255
  };
22994
23256
 
22995
- var Text$4 = antd.Typography.Text;
23257
+ var Text$3 = antd.Typography.Text;
22996
23258
  var SubscriptionCardCellMobile = function (_a) {
22997
23259
  var children = _a.children, className = _a.className, style = _a.style;
22998
- return (jsxRuntime.jsx(Text$4, __assign({ className: className, style: style }, { children: children })));
23260
+ return (jsxRuntime.jsx(Text$3, __assign({ className: className, style: style }, { children: children })));
22999
23261
  };
23000
23262
 
23001
23263
  var CHARGE_COLUMNS = [
@@ -23073,10 +23335,10 @@ var SubscriptionsListContainer = function (_a) {
23073
23335
  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") }) })))) }));
23074
23336
  };
23075
23337
 
23076
- var Text$3 = antd.Typography.Text;
23338
+ var Text$2 = antd.Typography.Text;
23077
23339
  var DrawerHeader = function (_a) {
23078
23340
  var description = _a.description, onClose = _a.onClose, title = _a.title, closeButtonClassName = _a.closeButtonClassName;
23079
- 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 }))] })));
23341
+ 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 }))] })));
23080
23342
  };
23081
23343
 
23082
23344
  var formatDateForApi = function (date) {
@@ -23259,13 +23521,13 @@ var QuantityInput = function (_a) {
23259
23521
  }, status: isQuantityLowerThanOriginal(charge.quantity) ? 'error' : '', style: { width: '96px' }, value: value }) }));
23260
23522
  };
23261
23523
 
23262
- var Text$2 = antd.Typography.Text;
23524
+ var Text$1 = antd.Typography.Text;
23263
23525
  var QuantityChangeGridRow = function (_a) {
23264
23526
  var _b;
23265
23527
  var chargeIndex = _a.chargeIndex, editingQuote = _a.editingQuote, subscriptions = _a.subscriptions, subscriptionIndex = _a.subscriptionIndex, setEditingQuoteData = _a.setEditingQuoteData, subscription = _a.subscription, subscriptionCharge = _a.subscriptionCharge;
23266
23528
  if (!canShowQuantitiesInput(subscriptionCharge, subscription))
23267
23529
  return null;
23268
- 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" })] }));
23530
+ 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" })] }));
23269
23531
  };
23270
23532
 
23271
23533
  var QuantityChangeGridTitle = function (_a) {
@@ -23376,7 +23638,7 @@ var SubscriptionsNavigation = function (_a) {
23376
23638
  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 })) }))] }));
23377
23639
  };
23378
23640
 
23379
- var Text$1 = antd.Typography.Text;
23641
+ var Text = antd.Typography.Text;
23380
23642
  var SubscriptionsWrapper = function (_a) {
23381
23643
  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;
23382
23644
  var defaultStyles = {
@@ -23535,7 +23797,7 @@ var Subscriptions = function (_a) {
23535
23797
  setIsChangingPlan(false);
23536
23798
  }, handlePortalErrors: handlePortalErrors }));
23537
23799
  }
23538
- 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 })] })));
23800
+ 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 })] })));
23539
23801
  };
23540
23802
  var PageHeaderWithActions = function (_a) {
23541
23803
  var children = _a.children, title = _a.title;
@@ -23550,246 +23812,6 @@ var PageSubTitle = function (_a) {
23550
23812
  return (jsxRuntime.jsx("div", __assign({ className: "bunny-shrink-0 bunny-font-medium", style: { color: secondaryColor } }, { children: title })));
23551
23813
  };
23552
23814
 
23553
- 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";
23554
- var billingDetailsUpdate = function (_a) {
23555
- var attributes = _a.attributes, token = _a.token, apiHost = _a.apiHost;
23556
- return __awaiter(void 0, void 0, void 0, function () {
23557
- var vars, response, errors;
23558
- var _b;
23559
- return __generator(this, function (_c) {
23560
- switch (_c.label) {
23561
- case 0:
23562
- vars = { attributes: attributes };
23563
- return [4 /*yield*/, gqlRequest({
23564
- query: MUTATION,
23565
- token: token,
23566
- vars: vars,
23567
- apiHost: apiHost,
23568
- })];
23569
- case 1:
23570
- response = _c.sent();
23571
- errors = (_b = response === null || response === void 0 ? void 0 : response.billingDetailsUpdate) === null || _b === void 0 ? void 0 : _b.errors;
23572
- if (errors)
23573
- throw errors;
23574
- return [2 /*return*/, response.billingDetailsUpdate];
23575
- }
23576
- });
23577
- });
23578
- };
23579
-
23580
- // TODO: move this to common
23581
- var billingDetailsQuery = function () {
23582
- 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}";
23583
- };
23584
- var getBillingDetails = function (_a) {
23585
- var token = _a.token, apiHost = _a.apiHost;
23586
- return __awaiter(void 0, void 0, void 0, function () {
23587
- var response;
23588
- var _b;
23589
- return __generator(this, function (_c) {
23590
- switch (_c.label) {
23591
- case 0: return [4 /*yield*/, gqlRequest({
23592
- query: billingDetailsQuery(),
23593
- token: token,
23594
- apiHost: apiHost,
23595
- })];
23596
- case 1:
23597
- response = _c.sent();
23598
- if (response === null || response === void 0 ? void 0 : response.errors) {
23599
- throw new Error((_b = response === null || response === void 0 ? void 0 : response.errors[0]) === null || _b === void 0 ? void 0 : _b.message);
23600
- }
23601
- return [2 /*return*/, response === null || response === void 0 ? void 0 : response.billingDetails];
23602
- }
23603
- });
23604
- });
23605
- };
23606
-
23607
- var Text = antd.Typography.Text;
23608
- function BillingDetailsSection(_a) {
23609
- var _this = this;
23610
- var hidePaymentMethodForm = _a.hidePaymentMethodForm, countryListFilter = _a.countryListFilter;
23611
- // State
23612
- var _b = react.useState(false), isFormEdited = _b[0], setIsFormEdited = _b[1];
23613
- var _c = react.useState(false), formIsValid = _c[0], setFormIsValid = _c[1];
23614
- var form = antd.Form.useForm()[0];
23615
- var values = antd.Form.useWatch([], form);
23616
- // Context
23617
- var apiHost = react.useContext(BunnyContext).apiHost;
23618
- var token = useToken();
23619
- // Hooks
23620
- var isMobile = common.useIsMobile();
23621
- var queryClient = reactQuery.useQueryClient();
23622
- var showErrorNotification = common.useErrorNotification();
23623
- var showSuccessNotification = common.useSuccessNotification();
23624
- // Queries
23625
- var _d = reactQuery.useQuery({
23626
- queryKey: common.QueryKeyFactory.default.billingDetailsKey({ token: token }),
23627
- queryFn: function () { return getBillingDetails({ token: token, apiHost: apiHost }); },
23628
- }), billingDetails = _d.data, isLoadingBillingDetails = _d.isLoading;
23629
- var _e = reactQuery.useMutation({
23630
- mutationFn: function (changedFormData) { return __awaiter(_this, void 0, void 0, function () {
23631
- var updatedBillingDetails;
23632
- return __generator(this, function (_a) {
23633
- switch (_a.label) {
23634
- case 0: return [4 /*yield*/, billingDetailsUpdate({
23635
- attributes: {
23636
- name: changedFormData.name,
23637
- billingStreet: changedFormData.billingStreet,
23638
- billingCity: changedFormData.billingCity,
23639
- billingZip: changedFormData.billingZip,
23640
- billingState: changedFormData.billingState,
23641
- billingCountry: changedFormData.billingCountry,
23642
- billingContactEmail: changedFormData.billingContactEmail,
23643
- taxNumber: changedFormData.taxNumber,
23644
- },
23645
- token: token,
23646
- apiHost: apiHost,
23647
- })];
23648
- case 1:
23649
- updatedBillingDetails = _a.sent();
23650
- queryClient.setQueryData(common.QueryKeyFactory.default.billingDetailsKey({ token: token }), function (old) {
23651
- return __assign(__assign({}, old), updatedBillingDetails.billingDetails);
23652
- });
23653
- return [2 /*return*/, updatedBillingDetails];
23654
- }
23655
- });
23656
- }); },
23657
- onSuccess: function () {
23658
- showSuccessNotification('Your account details have been saved');
23659
- queryClient.invalidateQueries({
23660
- queryKey: common.QueryKeyFactory.default.taxationRequiredAccountFieldsKey({
23661
- token: token,
23662
- }),
23663
- });
23664
- },
23665
- }), updateBillingDetails = _e.mutate, isUpdatingBillingDetails = _e.isPending;
23666
- // Set form values when billing details are loaded
23667
- react.useEffect(function () {
23668
- var _a;
23669
- if (billingDetails) {
23670
- form.setFieldsValue({
23671
- billingStreet: billingDetails.billingStreet,
23672
- billingCity: billingDetails.billingCity,
23673
- billingZip: billingDetails.billingZip,
23674
- billingState: billingDetails.billingState,
23675
- billingCountry: billingDetails.billingCountry,
23676
- billingContactEmail: (_a = billingDetails.billingContact) === null || _a === void 0 ? void 0 : _a.email,
23677
- taxNumber: billingDetails.taxNumber,
23678
- });
23679
- }
23680
- }, [billingDetails]);
23681
- react.useEffect(function () {
23682
- form
23683
- .validateFields({ validateOnly: true })
23684
- .then(function () { return setFormIsValid(true); })
23685
- .catch(function () { return setFormIsValid(false); });
23686
- var isFormEdited = function () {
23687
- var _a;
23688
- if (!billingDetails)
23689
- return false;
23690
- var currentValues = form.getFieldsValue();
23691
- var accountValues = {
23692
- billingStreet: billingDetails.billingStreet,
23693
- billingCity: billingDetails.billingCity,
23694
- billingZip: billingDetails.billingZip,
23695
- billingState: billingDetails.billingState,
23696
- billingCountry: billingDetails.billingCountry,
23697
- billingContactEmail: (_a = billingDetails.billingContact) === null || _a === void 0 ? void 0 : _a.email,
23698
- taxNumber: billingDetails.taxNumber,
23699
- };
23700
- return Object.keys(currentValues).some(function (key) {
23701
- var value = accountValues[key];
23702
- return currentValues[key] !== value;
23703
- });
23704
- };
23705
- setIsFormEdited(isFormEdited());
23706
- }, [form, values, billingDetails]);
23707
- // Validate form fields when isFormEdited changes
23708
- react.useEffect(function () {
23709
- var validateOnly = isFormEdited ? false : true;
23710
- form.validateFields({ validateOnly: validateOnly });
23711
- }, [isFormEdited]);
23712
- var saveBillingDetails = function () { return __awaiter(_this, void 0, void 0, function () {
23713
- var _this = this;
23714
- return __generator(this, function (_a) {
23715
- form.validateFields({ validateOnly: false }).then(function () { return __awaiter(_this, void 0, void 0, function () {
23716
- var error_1;
23717
- return __generator(this, function (_a) {
23718
- switch (_a.label) {
23719
- case 0:
23720
- _a.trys.push([0, 2, 3, 4]);
23721
- return [4 /*yield*/, form.validateFields()];
23722
- case 1:
23723
- _a.sent();
23724
- updateBillingDetails(form.getFieldsValue());
23725
- return [3 /*break*/, 4];
23726
- case 2:
23727
- error_1 = _a.sent();
23728
- if (error_1 instanceof Error) {
23729
- showErrorNotification('Failed to update account', error_1.message);
23730
- }
23731
- else {
23732
- showErrorNotification('Please fill out all required fields');
23733
- }
23734
- return [3 /*break*/, 4];
23735
- case 3:
23736
- setIsFormEdited(false);
23737
- return [7 /*endfinally*/];
23738
- case 4: return [2 /*return*/];
23739
- }
23740
- });
23741
- }); });
23742
- return [2 /*return*/];
23743
- });
23744
- }); };
23745
- var filteredCountryList = react.useMemo(function () {
23746
- return countryListFilter ? common.Lists.COUNTRY_LIST.filter(countryListFilter) : common.Lists.COUNTRY_LIST;
23747
- }, [countryListFilter]);
23748
- 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: [
23749
- {
23750
- required: false,
23751
- },
23752
- ] }, { 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) {
23753
- var _a, _b;
23754
- return ((_a = option === null || option === void 0 ? void 0 : option.label) !== null && _a !== void 0 ? _a : '').toLowerCase().includes(input.toLowerCase()) ||
23755
- ((_b = option === null || option === void 0 ? void 0 : option.value) !== null && _b !== void 0 ? _b : '').toLowerCase().includes(input.toLowerCase());
23756
- } }) })) }))] })), jsxRuntime.jsx(antd.Form.Item, __assign({ label: "Email", name: "billingContactEmail", rules: [
23757
- {
23758
- required: true,
23759
- message: 'Email is required',
23760
- type: 'email',
23761
- },
23762
- ] }, { 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" }))] })) })));
23763
- }
23764
-
23765
- var BillingDetails = function (_a) {
23766
- var _b = _a.isCardEnabled, isCardEnabled = _b === void 0 ? true : _b, _c = _a.shadow, shadow = _c === void 0 ? 'shadow-md' : _c, className = _a.className, _d = _a.hidePaymentMethodForm, hidePaymentMethodForm = _d === void 0 ? false : _d, _e = _a.hideBillingDetailsForm, hideBillingDetailsForm = _e === void 0 ? false : _e, countryListFilter = _a.countryListFilter;
23767
- // Hooks
23768
- var isMobile = common.useIsMobile();
23769
- 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 })) : null] })) })));
23770
- };
23771
- var WrapperComponent = function (_a) {
23772
- var children = _a.children, isCardEnabled = _a.isCardEnabled, shadow = _a.shadow, className = _a.className;
23773
- return (jsxRuntime.jsx("div", __assign({ className: "".concat(className) }, { children: isCardEnabled ? jsxRuntime.jsx(Card, __assign({ className: "".concat(shadow) }, { children: children })) : jsxRuntime.jsx("div", { children: children }) })));
23774
- };
23775
- var ResponsiveDivider = function () {
23776
- var isMobile = common.useIsMobile();
23777
- 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" }) }));
23778
- };
23779
- var PaymentFormSection = function (_a) {
23780
- var hideBillingDetailsForm = _a.hideBillingDetailsForm;
23781
- var isMobile = common.useIsMobile();
23782
- var onTokenExpired = react.useContext(BunnyContext).onTokenExpired;
23783
- var handleAllErrorFormats = common.useAllErrorFormats(onTokenExpired);
23784
- var showSuccessNotification = common.useSuccessNotification();
23785
- var entityId = useCurrentUserData().entityId;
23786
- 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) {
23787
- handleAllErrorFormats(error);
23788
- }, onSavePaymentMethod: function () {
23789
- showSuccessNotification('Your payment method has been saved');
23790
- } }) })));
23791
- };
23792
-
23793
23815
  exports.BillingDetails = BillingDetails;
23794
23816
  exports.BunnyProvider = BunnyProvider;
23795
23817
  exports.Footer = Footer;