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

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.11';
158
158
  var createRequestHeaders = function (token) {
159
159
  var headers = common.createClientDevHeaders(token);
160
160
  // Add the components version header
@@ -22777,19 +22777,278 @@ var getApplicablePriceTier = function (charge, currencyId, priceDecimals) {
22777
22777
  : "".concat(common.formatCurrency(selectedTier.price, currencyId, priceDecimals));
22778
22778
  };
22779
22779
 
22780
+ 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";
22781
+ var billingDetailsUpdate = function (_a) {
22782
+ var attributes = _a.attributes, token = _a.token, apiHost = _a.apiHost;
22783
+ return __awaiter(void 0, void 0, void 0, function () {
22784
+ var vars, response, errors;
22785
+ var _b;
22786
+ return __generator(this, function (_c) {
22787
+ switch (_c.label) {
22788
+ case 0:
22789
+ vars = { attributes: attributes };
22790
+ return [4 /*yield*/, gqlRequest({
22791
+ query: MUTATION,
22792
+ token: token,
22793
+ vars: vars,
22794
+ apiHost: apiHost,
22795
+ })];
22796
+ case 1:
22797
+ response = _c.sent();
22798
+ errors = (_b = response === null || response === void 0 ? void 0 : response.billingDetailsUpdate) === null || _b === void 0 ? void 0 : _b.errors;
22799
+ if (errors)
22800
+ throw errors;
22801
+ return [2 /*return*/, response.billingDetailsUpdate];
22802
+ }
22803
+ });
22804
+ });
22805
+ };
22806
+
22807
+ // TODO: move this to common
22808
+ var billingDetailsQuery = function () {
22809
+ 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}";
22810
+ };
22811
+ var getBillingDetails = function (_a) {
22812
+ var token = _a.token, apiHost = _a.apiHost;
22813
+ return __awaiter(void 0, void 0, void 0, function () {
22814
+ var response;
22815
+ var _b;
22816
+ return __generator(this, function (_c) {
22817
+ switch (_c.label) {
22818
+ case 0: return [4 /*yield*/, gqlRequest({
22819
+ query: billingDetailsQuery(),
22820
+ token: token,
22821
+ apiHost: apiHost,
22822
+ })];
22823
+ case 1:
22824
+ response = _c.sent();
22825
+ if (response === null || response === void 0 ? void 0 : response.errors) {
22826
+ throw new Error((_b = response === null || response === void 0 ? void 0 : response.errors[0]) === null || _b === void 0 ? void 0 : _b.message);
22827
+ }
22828
+ return [2 /*return*/, response === null || response === void 0 ? void 0 : response.billingDetails];
22829
+ }
22830
+ });
22831
+ });
22832
+ };
22833
+
22834
+ var Text$7 = antd.Typography.Text;
22835
+ function BillingDetailsSection(_a) {
22836
+ var _this = this;
22837
+ var hidePaymentMethodForm = _a.hidePaymentMethodForm, countryListFilter = _a.countryListFilter;
22838
+ // State
22839
+ var _b = react.useState(false), isFormEdited = _b[0], setIsFormEdited = _b[1];
22840
+ var _c = react.useState(false), formIsValid = _c[0], setFormIsValid = _c[1];
22841
+ var form = antd.Form.useForm()[0];
22842
+ var values = antd.Form.useWatch([], form);
22843
+ // Context
22844
+ var apiHost = react.useContext(BunnyContext).apiHost;
22845
+ var token = useToken();
22846
+ // Hooks
22847
+ var isMobile = common.useIsMobile();
22848
+ var queryClient = reactQuery.useQueryClient();
22849
+ var showErrorNotification = common.useErrorNotification();
22850
+ var showSuccessNotification = common.useSuccessNotification();
22851
+ // Queries
22852
+ var _d = reactQuery.useQuery({
22853
+ queryKey: common.QueryKeyFactory.default.billingDetailsKey({ token: token }),
22854
+ queryFn: function () { return getBillingDetails({ token: token, apiHost: apiHost }); },
22855
+ }), billingDetails = _d.data, isLoadingBillingDetails = _d.isLoading;
22856
+ var _e = reactQuery.useMutation({
22857
+ mutationFn: function (changedFormData) { return __awaiter(_this, void 0, void 0, function () {
22858
+ var updatedBillingDetails;
22859
+ return __generator(this, function (_a) {
22860
+ switch (_a.label) {
22861
+ case 0: return [4 /*yield*/, billingDetailsUpdate({
22862
+ attributes: {
22863
+ name: changedFormData.name,
22864
+ billingStreet: changedFormData.billingStreet,
22865
+ billingCity: changedFormData.billingCity,
22866
+ billingZip: changedFormData.billingZip,
22867
+ billingState: changedFormData.billingState,
22868
+ billingCountry: changedFormData.billingCountry,
22869
+ billingContactEmail: changedFormData.billingContactEmail,
22870
+ taxNumber: changedFormData.taxNumber,
22871
+ },
22872
+ token: token,
22873
+ apiHost: apiHost,
22874
+ })];
22875
+ case 1:
22876
+ updatedBillingDetails = _a.sent();
22877
+ queryClient.setQueryData(common.QueryKeyFactory.default.billingDetailsKey({ token: token }), function (old) {
22878
+ return __assign(__assign({}, old), updatedBillingDetails.billingDetails);
22879
+ });
22880
+ return [2 /*return*/, updatedBillingDetails];
22881
+ }
22882
+ });
22883
+ }); },
22884
+ onSuccess: function () {
22885
+ showSuccessNotification('Your account details have been saved');
22886
+ queryClient.invalidateQueries({
22887
+ queryKey: common.QueryKeyFactory.default.taxationRequiredAccountFieldsKey({
22888
+ token: token,
22889
+ }),
22890
+ });
22891
+ },
22892
+ }), updateBillingDetails = _e.mutate, isUpdatingBillingDetails = _e.isPending;
22893
+ // Set form values when billing details are loaded
22894
+ react.useEffect(function () {
22895
+ var _a;
22896
+ if (billingDetails) {
22897
+ form.setFieldsValue({
22898
+ billingStreet: billingDetails.billingStreet,
22899
+ billingCity: billingDetails.billingCity,
22900
+ billingZip: billingDetails.billingZip,
22901
+ billingState: billingDetails.billingState,
22902
+ billingCountry: billingDetails.billingCountry,
22903
+ billingContactEmail: (_a = billingDetails.billingContact) === null || _a === void 0 ? void 0 : _a.email,
22904
+ taxNumber: billingDetails.taxNumber,
22905
+ });
22906
+ }
22907
+ }, [billingDetails]);
22908
+ react.useEffect(function () {
22909
+ form
22910
+ .validateFields({ validateOnly: true })
22911
+ .then(function () { return setFormIsValid(true); })
22912
+ .catch(function () { return setFormIsValid(false); });
22913
+ var isFormEdited = function () {
22914
+ var _a;
22915
+ if (!billingDetails)
22916
+ return false;
22917
+ var currentValues = form.getFieldsValue();
22918
+ var accountValues = {
22919
+ billingStreet: billingDetails.billingStreet,
22920
+ billingCity: billingDetails.billingCity,
22921
+ billingZip: billingDetails.billingZip,
22922
+ billingState: billingDetails.billingState,
22923
+ billingCountry: billingDetails.billingCountry,
22924
+ billingContactEmail: (_a = billingDetails.billingContact) === null || _a === void 0 ? void 0 : _a.email,
22925
+ taxNumber: billingDetails.taxNumber,
22926
+ };
22927
+ return Object.keys(currentValues).some(function (key) {
22928
+ var value = accountValues[key];
22929
+ return currentValues[key] !== value;
22930
+ });
22931
+ };
22932
+ setIsFormEdited(isFormEdited());
22933
+ }, [form, values, billingDetails]);
22934
+ // Validate form fields when isFormEdited changes
22935
+ react.useEffect(function () {
22936
+ var validateOnly = isFormEdited ? false : true;
22937
+ form.validateFields({ validateOnly: validateOnly });
22938
+ }, [isFormEdited]);
22939
+ var saveBillingDetails = function () { return __awaiter(_this, void 0, void 0, function () {
22940
+ var _this = this;
22941
+ return __generator(this, function (_a) {
22942
+ form.validateFields({ validateOnly: false }).then(function () { return __awaiter(_this, void 0, void 0, function () {
22943
+ var error_1;
22944
+ return __generator(this, function (_a) {
22945
+ switch (_a.label) {
22946
+ case 0:
22947
+ _a.trys.push([0, 2, 3, 4]);
22948
+ return [4 /*yield*/, form.validateFields()];
22949
+ case 1:
22950
+ _a.sent();
22951
+ updateBillingDetails(form.getFieldsValue());
22952
+ return [3 /*break*/, 4];
22953
+ case 2:
22954
+ error_1 = _a.sent();
22955
+ if (error_1 instanceof Error) {
22956
+ showErrorNotification('Failed to update account', error_1.message);
22957
+ }
22958
+ else {
22959
+ showErrorNotification('Please fill out all required fields');
22960
+ }
22961
+ return [3 /*break*/, 4];
22962
+ case 3:
22963
+ setIsFormEdited(false);
22964
+ return [7 /*endfinally*/];
22965
+ case 4: return [2 /*return*/];
22966
+ }
22967
+ });
22968
+ }); });
22969
+ return [2 /*return*/];
22970
+ });
22971
+ }); };
22972
+ var filteredCountryList = react.useMemo(function () {
22973
+ return countryListFilter ? common.Lists.COUNTRY_LIST.filter(countryListFilter) : common.Lists.COUNTRY_LIST;
22974
+ }, [countryListFilter]);
22975
+ 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: [
22976
+ {
22977
+ required: false,
22978
+ },
22979
+ ] }, { 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) {
22980
+ var _a, _b;
22981
+ return ((_a = option === null || option === void 0 ? void 0 : option.label) !== null && _a !== void 0 ? _a : '').toLowerCase().includes(input.toLowerCase()) ||
22982
+ ((_b = option === null || option === void 0 ? void 0 : option.value) !== null && _b !== void 0 ? _b : '').toLowerCase().includes(input.toLowerCase());
22983
+ } }) })) }))] })), jsxRuntime.jsx(antd.Form.Item, __assign({ label: "Email", name: "billingContactEmail", rules: [
22984
+ {
22985
+ required: true,
22986
+ message: 'Email is required',
22987
+ type: 'email',
22988
+ },
22989
+ ] }, { 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" }))] })) })));
22990
+ }
22991
+
22992
+ var BillingDetails = function (_a) {
22993
+ 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;
22994
+ // Hooks
22995
+ var isMobile = common.useIsMobile();
22996
+ 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] })) })));
22997
+ };
22998
+ var WrapperComponent = function (_a) {
22999
+ var children = _a.children, isCardEnabled = _a.isCardEnabled, shadow = _a.shadow, className = _a.className;
23000
+ return (jsxRuntime.jsx("div", __assign({ className: "".concat(className) }, { children: isCardEnabled ? jsxRuntime.jsx(Card, __assign({ className: "".concat(shadow) }, { children: children })) : jsxRuntime.jsx("div", { children: children }) })));
23001
+ };
23002
+ var ResponsiveDivider = function () {
23003
+ var isMobile = common.useIsMobile();
23004
+ 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" }) }));
23005
+ };
23006
+ var PaymentFormSection = function (_a) {
23007
+ var hideBillingDetailsForm = _a.hideBillingDetailsForm, isUpgradeFromTrial = _a.isUpgradeFromTrial, onSavePaymentMethod = _a.onSavePaymentMethod;
23008
+ var isMobile = common.useIsMobile();
23009
+ var onTokenExpired = react.useContext(BunnyContext).onTokenExpired;
23010
+ var handleAllErrorFormats = common.useAllErrorFormats(onTokenExpired);
23011
+ var showSuccessNotification = common.useSuccessNotification();
23012
+ var entityId = useCurrentUserData().entityId;
23013
+ 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) {
23014
+ handleAllErrorFormats(error);
23015
+ }, onSavePaymentMethod: function () {
23016
+ showSuccessNotification(isUpgradeFromTrial
23017
+ ? 'Payment method saved! Your trial will automatically convert to a paid subscription.'
23018
+ : 'Payment method saved successfully!');
23019
+ onSavePaymentMethod === null || onSavePaymentMethod === void 0 ? void 0 : onSavePaymentMethod();
23020
+ } }) })));
23021
+ };
23022
+
23023
+ var UpgradeFromTrial = function (_a) {
23024
+ var onClose = _a.onClose, open = _a.open;
23025
+ return (jsxRuntime.jsx(antd.Modal, __assign({ width: '80vw', open: open, onCancel: onClose, footer: null }, { children: jsxRuntime.jsx(BillingDetails, { isUpgradeFromTrial: true, onSavePaymentMethod: onClose }) })));
23026
+ };
23027
+
22780
23028
  var SubscriptionCardActions = function (_a) {
22781
23029
  var _b;
22782
23030
  var onChangePlanClick = _a.onChangePlanClick, onCancelSubscriptionClick = _a.onCancelSubscriptionClick, priceListChangeOptions = _a.priceListChangeOptions, subscription = _a.subscription;
23031
+ var apiHost = react.useContext(BunnyContext).apiHost;
23032
+ var token = useToken();
23033
+ var _c = usePaymentMethod({
23034
+ accountId: subscription.accountId,
23035
+ token: token,
23036
+ apiHost: apiHost,
23037
+ }), storedPaymentMethods = _c.paymentMethods, isPaymentMethodLoading = _c.isLoading;
23038
+ // Local state
23039
+ var _d = react.useState(false), isUpgradeFromTrialModalOpen = _d[0], setIsUpgradeFromTrialModalOpen = _d[1];
22783
23040
  // Derived state
22784
23041
  var isSelfServiceCancelable = subscription.plan.selfServiceCancel;
22785
23042
  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
23043
  var arePlansAvailable = ((productPlans === null || productPlans === void 0 ? void 0 : productPlans.length) || 0) > 0;
22787
23044
  var isInTrial = isSubscriptionTrial(subscription);
22788
23045
  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' })))] }));
23046
+ if (isPaymentMethodLoading)
23047
+ return null;
23048
+ 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
23049
  };
22791
23050
 
22792
- var Text$7 = antd.Typography.Text;
23051
+ var Text$6 = antd.Typography.Text;
22793
23052
  var getSubscriptionStatusText = function (subscription) {
22794
23053
  var cancellationDate = subscription.cancellationDate, state = subscription.state, evergreen = subscription.evergreen, endDate = subscription.endDate;
22795
23054
  if (cancellationDate &&
@@ -22818,7 +23077,7 @@ var SubscriptionCardHeader = function (_a) {
22818
23077
  var isTrial = ((_b = subscription.state) === null || _b === void 0 ? void 0 : _b.toUpperCase()) === common.SubscriptionState.TRIAL;
22819
23078
  return (jsxRuntime.jsxs("div", __assign({ className: "bunny-flex bunny-items-center bunny-justify-between", style: {
22820
23079
  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 }))] }))] })));
23080
+ } }, { 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
23081
  };
22823
23082
 
22824
23083
  var SubscriptionChargeTotal = function (_a) {
@@ -22895,16 +23154,16 @@ var SubscriptionChargeUnitPrice = function (_a) {
22895
23154
  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
23155
  };
22897
23156
 
22898
- var Text$6 = antd.Typography.Text;
23157
+ var Text$5 = antd.Typography.Text;
22899
23158
  var SubscriptionCardColumnHeaders = function (_a) {
22900
23159
  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)); }) }));
23160
+ 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
23161
  };
22903
23162
 
22904
- var Text$5 = antd.Typography.Text;
23163
+ var Text$4 = antd.Typography.Text;
22905
23164
  var SubscriptionsListCell = function (_a) {
22906
23165
  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 })));
23166
+ 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
23167
  };
22909
23168
 
22910
23169
  var CARD_COLUMNS = [
@@ -22992,10 +23251,10 @@ var SubscriptionCardDesktopRow = function (_a) {
22992
23251
  : (_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
23252
  };
22994
23253
 
22995
- var Text$4 = antd.Typography.Text;
23254
+ var Text$3 = antd.Typography.Text;
22996
23255
  var SubscriptionCardCellMobile = function (_a) {
22997
23256
  var children = _a.children, className = _a.className, style = _a.style;
22998
- return (jsxRuntime.jsx(Text$4, __assign({ className: className, style: style }, { children: children })));
23257
+ return (jsxRuntime.jsx(Text$3, __assign({ className: className, style: style }, { children: children })));
22999
23258
  };
23000
23259
 
23001
23260
  var CHARGE_COLUMNS = [
@@ -23073,10 +23332,10 @@ var SubscriptionsListContainer = function (_a) {
23073
23332
  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
23333
  };
23075
23334
 
23076
- var Text$3 = antd.Typography.Text;
23335
+ var Text$2 = antd.Typography.Text;
23077
23336
  var DrawerHeader = function (_a) {
23078
23337
  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 }))] })));
23338
+ 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
23339
  };
23081
23340
 
23082
23341
  var formatDateForApi = function (date) {
@@ -23259,13 +23518,13 @@ var QuantityInput = function (_a) {
23259
23518
  }, status: isQuantityLowerThanOriginal(charge.quantity) ? 'error' : '', style: { width: '96px' }, value: value }) }));
23260
23519
  };
23261
23520
 
23262
- var Text$2 = antd.Typography.Text;
23521
+ var Text$1 = antd.Typography.Text;
23263
23522
  var QuantityChangeGridRow = function (_a) {
23264
23523
  var _b;
23265
23524
  var chargeIndex = _a.chargeIndex, editingQuote = _a.editingQuote, subscriptions = _a.subscriptions, subscriptionIndex = _a.subscriptionIndex, setEditingQuoteData = _a.setEditingQuoteData, subscription = _a.subscription, subscriptionCharge = _a.subscriptionCharge;
23266
23525
  if (!canShowQuantitiesInput(subscriptionCharge, subscription))
23267
23526
  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" })] }));
23527
+ 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
23528
  };
23270
23529
 
23271
23530
  var QuantityChangeGridTitle = function (_a) {
@@ -23376,7 +23635,7 @@ var SubscriptionsNavigation = function (_a) {
23376
23635
  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
23636
  };
23378
23637
 
23379
- var Text$1 = antd.Typography.Text;
23638
+ var Text = antd.Typography.Text;
23380
23639
  var SubscriptionsWrapper = function (_a) {
23381
23640
  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
23641
  var defaultStyles = {
@@ -23535,7 +23794,7 @@ var Subscriptions = function (_a) {
23535
23794
  setIsChangingPlan(false);
23536
23795
  }, handlePortalErrors: handlePortalErrors }));
23537
23796
  }
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 })] })));
23797
+ 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
23798
  };
23540
23799
  var PageHeaderWithActions = function (_a) {
23541
23800
  var children = _a.children, title = _a.title;
@@ -23550,246 +23809,6 @@ var PageSubTitle = function (_a) {
23550
23809
  return (jsxRuntime.jsx("div", __assign({ className: "bunny-shrink-0 bunny-font-medium", style: { color: secondaryColor } }, { children: title })));
23551
23810
  };
23552
23811
 
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
23812
  exports.BillingDetails = BillingDetails;
23794
23813
  exports.BunnyProvider = BunnyProvider;
23795
23814
  exports.Footer = Footer;