@bunnyapp/components 1.0.41 → 1.0.43

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/README.md CHANGED
@@ -30,6 +30,11 @@ Ensure all peer dependencies in the package.json are installed.
30
30
 
31
31
  To run the development server, run `npm run dev`.
32
32
 
33
- #### Storybook stories
33
+ ### Storybook stories
34
34
 
35
- To view the storybook stories, run `npm run storybook`.
35
+ To view the storybook stories, run `npx storybook dev`.
36
+
37
+ #### Visual tests
38
+
39
+ Once storybook is running, visual tests can be run by clicking on the visual tests tab, and then clicking on the "Run Tests" button.
40
+ Refer to [these docs](https://storybook.js.org/docs/writing-tests/visual-testing#enable-visual-tests) for more information.
package/dist/cjs/index.js CHANGED
@@ -19498,7 +19498,7 @@ var getBillingDetails = function (_a) {
19498
19498
  var Text$5 = antd.Typography.Text;
19499
19499
  var DrawerHeader = function (_a) {
19500
19500
  var description = _a.description, onClose = _a.onClose, title = _a.title, closeButtonClassName = _a.closeButtonClassName;
19501
- return (jsxRuntime.jsxs("div", __assign({ className: "flex flex-col gap-4" }, { children: [jsxRuntime.jsxs("div", __assign({ className: "flex items-center justify-between gap-2" }, { children: [jsxRuntime.jsx(Text$5, __assign({ className: "text-xl", style: { fontWeight: 400 } }, { children: title })), onClose ? (jsxRuntime.jsx("button", __assign({ onClick: onClose, className: closeButtonClassName }, { children: jsxRuntime.jsx(icons.CloseOutlined, {}) }))) : null] })), description && jsxRuntime.jsx("div", __assign({ className: "text-xs" }, { children: description }))] })));
19501
+ return (jsxRuntime.jsxs("div", __assign({ className: "flex flex-col gap-4" }, { children: [jsxRuntime.jsxs("div", __assign({ className: "flex items-center justify-between gap-2" }, { children: [jsxRuntime.jsx(Text$5, __assign({ className: "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: "text-xs" }, { children: description }))] })));
19502
19502
  };
19503
19503
 
19504
19504
  var PaymentMethod = function (_a) {
@@ -19555,7 +19555,7 @@ var PaymentMethodDisplay = function (_a) {
19555
19555
  body: {
19556
19556
  padding: "1rem 0 0 0",
19557
19557
  },
19558
- }, title: jsxRuntime.jsx("div", __assign({ className: "px-4" }, { children: jsxRuntime.jsx(DrawerHeader, { title: "New payment method", onClose: function () { return setShowModal(false); }, closeButtonClassName: "bg-transparent border-none cursor-pointer hover:bg-gray-100 p-2 rounded-sm transition-all duration-200" }) })), footer: null }, { children: children })));
19558
+ }, title: jsxRuntime.jsx("div", __assign({ className: "px-4" }, { children: jsxRuntime.jsx(DrawerHeader, { closeButtonClassName: "bg-transparent border-none cursor-pointer hover:bg-gray-100 p-2 rounded-sm transition-all duration-200", onClose: function () { return setShowModal(false); }, title: "New payment method" }) })), footer: null }, { children: children })));
19559
19559
  }
19560
19560
  return (jsxRuntime.jsx(antd.Drawer, __assign({ closeIcon: null, onClose: function () { return setShowModal(false); }, open: showModal, styles: {
19561
19561
  body: {
@@ -19931,8 +19931,8 @@ function InitialSignupForm(_a) {
19931
19931
  { required: true, message: "Please input your email!" },
19932
19932
  { type: "email", message: "Please enter a valid email!" },
19933
19933
  ] }, { children: jsxRuntime.jsx(antd.Input, { placeholder: "Email" }) })), jsxRuntime.jsx(antd.Form.Item, __assign({ name: "accountName", rules: [
19934
- { required: true, message: "Please input your account name!" },
19935
- ] }, { children: jsxRuntime.jsx(antd.Input, { placeholder: "Account name" }) }))] })), jsxRuntime.jsx(antd.Form.Item, { children: jsxRuntime.jsx(antd.Button, __assign({ type: "primary", onClick: handleSubmit, loading: submitting, className: "w-full mt-4" }, { children: "Proceed to payment" })) })] })));
19934
+ { required: true, message: "Please input your company name!" },
19935
+ ] }, { children: jsxRuntime.jsx(antd.Input, { placeholder: "Company name" }) }))] })), jsxRuntime.jsx(antd.Form.Item, { children: jsxRuntime.jsx(antd.Button, __assign({ type: "primary", onClick: handleSubmit, loading: submitting, className: "w-full mt-4" }, { children: "Proceed to payment" })) })] })));
19936
19936
  }
19937
19937
 
19938
19938
  var Title = antd.Typography.Title, Text$4 = antd.Typography.Text;
@@ -19965,6 +19965,7 @@ function Signup(_a) {
19965
19965
  var _j = react.useState(false), purchaseSucceeded = _j[0], setPurchaseSucceeded = _j[1];
19966
19966
  var _k = react.useState(undefined), paymentMethodGraphQLClient = _k[0], setPaymentMethodGraphQLClient = _k[1];
19967
19967
  var paymentMethod = usePaymentMethod({
19968
+ accountId: accountId,
19968
19969
  entityId: entityId,
19969
19970
  graphQLClient: paymentMethodGraphQLClient || graphQLClient,
19970
19971
  token: token,
@@ -19999,11 +20000,14 @@ function Signup(_a) {
19999
20000
  data = _a.sent();
20000
20001
  setAccountId(data.account.id);
20001
20002
  setPortalSessionToken(data.portalSessionToken);
20002
- setPaymentMethodGraphQLClient(createGraphQLClient(apiHost || "", data.portalSessionToken));
20003
+ setPaymentMethodGraphQLClient(createGraphQLClient(apiHost, data.portalSessionToken));
20003
20004
  // We must invalidate the accountPaymentMethodKey query in order to clear payment methods from the provided api token,
20004
20005
  // to instead use paymentMethods from portalSessionToken.
20005
20006
  queryClient.invalidateQueries({
20006
- queryKey: common.QueryKeyFactory.default.accountPaymentMethodKey({ entityId: entityId, token: token }),
20007
+ queryKey: common.QueryKeyFactory.default.accountPaymentMethodKey({
20008
+ entityId: entityId,
20009
+ token: token,
20010
+ }),
20007
20011
  });
20008
20012
  setProceedingToPayment(false);
20009
20013
  setQuote(data.quote);
@@ -20040,6 +20044,9 @@ function Signup(_a) {
20040
20044
  if (!(plugin === null || plugin === void 0 ? void 0 : plugin.id)) {
20041
20045
  throw new Error("Plugin ID is required");
20042
20046
  }
20047
+ if (!(paymentMethod === null || paymentMethod === void 0 ? void 0 : paymentMethod.id)) {
20048
+ throw new Error("Payment method ID is required");
20049
+ }
20043
20050
  return [4 /*yield*/, accountSignup({
20044
20051
  token: portalSessionToken,
20045
20052
  apiHost: apiHost,
@@ -20062,7 +20069,9 @@ function Signup(_a) {
20062
20069
  var children = _a.children, className = _a.className, style = _a.style;
20063
20070
  return isCardEnabled ? (jsxRuntime.jsx(Card, __assign({ className: className, style: style }, { children: children }))) : (jsxRuntime.jsx("div", __assign({ className: className, style: style }, { children: children })));
20064
20071
  };
20065
- return (jsxRuntime.jsx(WrapperComponent, __assign({ className: "p-4 flex flex-col ".concat(shadow, " ").concat(className), style: style }, { children: purchaseSucceeded ? (jsxRuntime.jsx(jsxRuntime.Fragment, { children: (quote === null || quote === void 0 ? void 0 : quote.currencyId) !== undefined ? (jsxRuntime.jsx(PaymentSuccessDisplay, { amountPaid: (quote === null || quote === void 0 ? void 0 : quote.amountDue) || 0, className: "w-full", companyName: companyName, returnUrl: returnUrl, currencyId: quote === null || quote === void 0 ? void 0 : quote.currencyId })) : (jsxRuntime.jsx("div", { children: "No currency ID found from Quote" })) })) : (jsxRuntime.jsxs("div", __assign({ className: "flex ".concat(isMobile ? "flex-col" : "flex-row", " h-full w-full") }, { children: [jsxRuntime.jsx("div", __assign({ className: "flex flex-col ".concat(isMobile ? "items-center" : "w-1/2 items-center") }, { children: jsxRuntime.jsx(PriceListDisplay, { priceListData: priceListData, topNavImageUrl: topNavImageUrl }) })), jsxRuntime.jsx("div", __assign({ className: "".concat(isMobile ? "h-full" : "my-4") }, { children: jsxRuntime.jsx(antd.Divider, { className: "h-full", type: isMobile ? undefined : "vertical" }) })), jsxRuntime.jsx("div", __assign({ className: "flex ".concat(isMobile ? "items-center justify-center my-12" : "w-1/2 items-center justify-center my-12") }, { children: jsxRuntime.jsx("div", __assign({ className: "".concat(isMobile ? "w-full" : "w-1/2") }, { children: jsxRuntime.jsx(PaymentForms, { entityId: entityId, quote: quote, handlePaymentSuccess: handlePaymentSuccess, handlePaymentFail: handlePaymentFail, handleSubmit: handleSubmit, proceedingToPayment: proceedingToPayment, accountId: accountId, overrideToken: portalSessionToken, customCheckoutFunction: accountSignupFunction }) })) }))] }))) })));
20072
+ return (jsxRuntime.jsx(WrapperComponent, __assign({ className: "p-4 flex flex-col ".concat(shadow, " ").concat(className), style: style }, { children: purchaseSucceeded ? (jsxRuntime.jsx(jsxRuntime.Fragment, { children: (quote === null || quote === void 0 ? void 0 : quote.currencyId) !== undefined ? (jsxRuntime.jsx(PaymentSuccessDisplay, { amountPaid: (quote === null || quote === void 0 ? void 0 : quote.amountDue) || 0, className: "w-full", companyName: companyName, returnUrl: returnUrl, currencyId: quote === null || quote === void 0 ? void 0 : quote.currencyId })) : (jsxRuntime.jsx("div", { children: "No currency ID found from Quote" })) })) : (jsxRuntime.jsxs("div", __assign({ className: "flex ".concat(isMobile ? "flex-col" : "flex-row", " h-full w-full") }, { children: [jsxRuntime.jsx("div", __assign({ className: "flex flex-col ".concat(isMobile ? "items-center" : "w-1/2 items-center") }, { children: jsxRuntime.jsx(PriceListDisplay, { priceListData: priceListData, topNavImageUrl: topNavImageUrl }) })), jsxRuntime.jsx("div", __assign({ className: "".concat(isMobile ? "h-full" : "my-4") }, { children: jsxRuntime.jsx(antd.Divider, { className: "h-full", type: isMobile ? undefined : "vertical" }) })), jsxRuntime.jsx("div", __assign({ className: "flex ".concat(isMobile
20073
+ ? "items-center justify-center my-12"
20074
+ : "w-1/2 items-center justify-center my-12") }, { children: jsxRuntime.jsx("div", __assign({ className: "".concat(isMobile ? "w-full" : "w-1/2") }, { children: jsxRuntime.jsx(PaymentForms, { entityId: entityId, quote: quote, handlePaymentSuccess: handlePaymentSuccess, handlePaymentFail: handlePaymentFail, handleSubmit: handleSubmit, proceedingToPayment: proceedingToPayment, accountId: accountId, overrideToken: portalSessionToken, customCheckoutFunction: accountSignupFunction }) })) }))] }))) })));
20066
20075
  }
20067
20076
 
20068
20077
  // WARNING: There is a preview button on APP that will need to be changed if this query is changed
@@ -20099,10 +20108,10 @@ var SUBSCRIPTIONS_QUERY = "\nquery subscriptions {\n subscriptions {\n n
20099
20108
  var getSubscriptions = function (_a) {
20100
20109
  var apiHost = _a.apiHost, entityId = _a.entityId, isInPreviewMode = _a.isInPreviewMode, token = _a.token;
20101
20110
  return __awaiter(void 0, void 0, void 0, function () {
20102
- var response;
20103
- var _b;
20104
- return __generator(this, function (_c) {
20105
- switch (_c.label) {
20111
+ var response, combinedSubscriptions;
20112
+ var _b, _c;
20113
+ return __generator(this, function (_d) {
20114
+ switch (_d.label) {
20106
20115
  case 0: return [4 /*yield*/, common.gqlRequest({
20107
20116
  isInPreviewMode: isInPreviewMode,
20108
20117
  query: SUBSCRIPTIONS_QUERY,
@@ -20111,78 +20120,14 @@ var getSubscriptions = function (_a) {
20111
20120
  apiHost: apiHost,
20112
20121
  })];
20113
20122
  case 1:
20114
- response = _c.sent();
20115
- return [2 /*return*/, (_b = response === null || response === void 0 ? void 0 : response.subscriptions) === null || _b === void 0 ? void 0 : _b.nodes];
20123
+ response = _d.sent();
20124
+ combinedSubscriptions = (_c = (_b = response === null || response === void 0 ? void 0 : response.subscriptions) === null || _b === void 0 ? void 0 : _b.nodes) === null || _c === void 0 ? void 0 : _c.map(function (subscription) { return (__assign(__assign({}, subscription), { charges: common.sortSubscriptionCharges(subscription.charges) })); });
20125
+ return [2 /*return*/, combinedSubscriptions];
20116
20126
  }
20117
20127
  });
20118
20128
  });
20119
20129
  };
20120
20130
 
20121
- var useSubscriptions = function (_a) {
20122
- var data = _a.data;
20123
- return react.useMemo(function () {
20124
- var clonedData = lodashExports.cloneDeep(data);
20125
- var combinedSubscriptions = clonedData === null || clonedData === void 0 ? void 0 : clonedData.map(function (subscription) {
20126
- var _a;
20127
- var orderedSubscriptionCharges = subscription.charges.sort(function (a, b) {
20128
- if (a.priceListChargeId !== b.priceListChargeId) {
20129
- return a.priceListChargeId.localeCompare(b.priceListChargeId);
20130
- }
20131
- if (a.kind === common.SubscriptionChargeKind.DISCOUNT &&
20132
- b.kind !== common.SubscriptionChargeKind.DISCOUNT) {
20133
- return 1;
20134
- }
20135
- if (a.kind !== common.SubscriptionChargeKind.DISCOUNT &&
20136
- b.kind === common.SubscriptionChargeKind.DISCOUNT) {
20137
- return -1;
20138
- }
20139
- return (a.endDate.localeCompare(b.endDate) ||
20140
- a.startDate.localeCompare(b.startDate));
20141
- });
20142
- var isTrial = ((_a = subscription.state) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === common.SubscriptionState.TRIAL;
20143
- var combinedSubscriptionCharges = [];
20144
- var aggregationCharge;
20145
- for (var index = 0; index < orderedSubscriptionCharges.length; index++) {
20146
- var charge = orderedSubscriptionCharges[index];
20147
- var nextCharge = orderedSubscriptionCharges[index + 1];
20148
- if (!aggregationCharge)
20149
- aggregationCharge = charge;
20150
- // If the next charge is the same priceListChargeId and endDate, aggregate the quantities
20151
- if (nextCharge &&
20152
- charge.priceListChargeId === nextCharge.priceListChargeId &&
20153
- charge.endDate === nextCharge.endDate &&
20154
- charge.startDate === nextCharge.startDate &&
20155
- charge.kind === nextCharge.kind) {
20156
- aggregationCharge.quantity += nextCharge.quantity;
20157
- // If the next charge is different, push the aggregationCharge to the combinedSubscriptionCharges
20158
- }
20159
- else if (nextCharge &&
20160
- charge.priceListChargeId === nextCharge.priceListChargeId &&
20161
- (charge.endDate !== nextCharge.endDate ||
20162
- charge.startDate !== nextCharge.startDate) &&
20163
- charge.kind === nextCharge.kind &&
20164
- (!isTrial || charge.trial) &&
20165
- (isTrial || !charge.trial)) {
20166
- nextCharge.name = "";
20167
- combinedSubscriptionCharges.push(aggregationCharge);
20168
- aggregationCharge = undefined;
20169
- }
20170
- else {
20171
- combinedSubscriptionCharges.push(aggregationCharge);
20172
- aggregationCharge = undefined;
20173
- }
20174
- }
20175
- subscription.charges = combinedSubscriptionCharges;
20176
- return subscription;
20177
- });
20178
- var subscriptionOrder = Object.values(common.SubscriptionState);
20179
- combinedSubscriptions === null || combinedSubscriptions === void 0 ? void 0 : combinedSubscriptions.sort(function (a, b) {
20180
- return subscriptionOrder.indexOf(a.state) - subscriptionOrder.indexOf(b.state);
20181
- });
20182
- return combinedSubscriptions;
20183
- }, [data]);
20184
- };
20185
-
20186
20131
  var ErrorView = function (_a) {
20187
20132
  var children = _a.children, message = _a.message;
20188
20133
  return (jsxRuntime.jsxs("div", __assign({ className: "flex flex-col w-full", style: { marginTop: "80px" } }, { children: [jsxRuntime.jsx("div", __assign({ style: { fontSize: "32px" } }, { children: message })), children] })));
@@ -20615,14 +20560,12 @@ var Subscriptions = function (_a) {
20615
20560
  }),
20616
20561
  queryFn: function () { return getSubscriptions({ entityId: entityId, token: token, apiHost: apiHost }); },
20617
20562
  enabled: Boolean(entityId),
20618
- }), rawSubscriptions = _d.data, subscriptionsAreLoading = _d.isLoading;
20563
+ }), subscriptions = _d.data, subscriptionsAreLoading = _d.isLoading;
20619
20564
  var _e = reactQuery.useQuery({
20620
20565
  queryKey: common.QueryKeyFactory.default.planChangeOptionsKey({ token: token }),
20621
20566
  queryFn: function () { return getPlanChangeOptions({ token: token, apiHost: apiHost }); },
20622
20567
  enabled: Boolean(onChangePlanClick),
20623
20568
  }), planChangeOptions = _e.data, arePlanChangeOptionsLoading = _e.isLoading;
20624
- // Derived state
20625
- var subscriptions = useSubscriptions({ data: rawSubscriptions });
20626
20569
  react.useEffect(function () {
20627
20570
  if (subscriptions)
20628
20571
  onSubscriptionsLoaded === null || onSubscriptionsLoaded === void 0 ? void 0 : onSubscriptionsLoaded(subscriptions);
@@ -2,7 +2,7 @@ import { PlanChangeOptions, Subscription } from "@bunnyapp/common";
2
2
  declare const SubscriptionCardActions: ({ onChangePlanClick, onCancelSubscriptionClick, planChangeOptions, subscription, }: {
3
3
  onChangePlanClick: (subscription: Subscription) => void;
4
4
  onCancelSubscriptionClick: (subscription: Subscription) => void;
5
- planChangeOptions?: PlanChangeOptions | undefined;
5
+ planChangeOptions?: any;
6
6
  subscription: Subscription;
7
7
  }) => import("react/jsx-runtime").JSX.Element | null;
8
8
  export default SubscriptionCardActions;
@@ -2,7 +2,7 @@ import { PlanChangeOptions, Subscription } from "@bunnyapp/common";
2
2
  declare const SubscriptionCardHeader: ({ onChangePlanClick, onCancelSubscriptionClick, planChangeOptions, subscription, }: {
3
3
  onChangePlanClick?: ((subscription: Subscription) => void) | undefined;
4
4
  onCancelSubscriptionClick?: ((subscription: Subscription) => void) | undefined;
5
- planChangeOptions?: PlanChangeOptions | undefined;
5
+ planChangeOptions?: any;
6
6
  subscription: Subscription;
7
7
  }) => import("react/jsx-runtime").JSX.Element;
8
8
  export default SubscriptionCardHeader;
@@ -3,7 +3,7 @@ declare const SubscriptionsList: ({ hideExpired, onChangePlanClick, onCancelSubs
3
3
  hideExpired: boolean;
4
4
  onChangePlanClick?: ((subscription: Subscription) => void) | undefined;
5
5
  onCancelSubscriptionClick?: ((subscription: Subscription) => void) | undefined;
6
- planChangeOptions?: PlanChangeOptions | undefined;
6
+ planChangeOptions?: any;
7
7
  subscriptions: Subscription[];
8
8
  }) => import("react/jsx-runtime").JSX.Element;
9
9
  export default SubscriptionsList;
@@ -2,7 +2,7 @@ import { PlanChangeOptions, Subscription } from "@bunnyapp/common";
2
2
  declare const SubscriptionCardDesktop: ({ onChangePlanClick, onCancelSubscriptionClick, planChangeOptions, subscription, }: {
3
3
  onChangePlanClick?: ((subscription: Subscription) => void) | undefined;
4
4
  onCancelSubscriptionClick?: ((subscription: Subscription) => void) | undefined;
5
- planChangeOptions?: PlanChangeOptions | undefined;
5
+ planChangeOptions?: any;
6
6
  subscription: Subscription;
7
7
  }) => import("react/jsx-runtime").JSX.Element;
8
8
  export default SubscriptionCardDesktop;
package/dist/esm/index.js CHANGED
@@ -4,7 +4,7 @@ import { Markup } from 'interweave';
4
4
  import { ConfigProvider, Button, Typography, Tag, Divider, Popconfirm, Input, Checkbox, Collapse, Skeleton, Modal, Form, Drawer, Card as Card$1, Select, Image, Dropdown } from 'antd';
5
5
  import { DownloadOutlined, CreditCardOutlined, BankOutlined, SearchOutlined, CloseOutlined, CheckCircleFilled } from '@ant-design/icons';
6
6
  import styled from 'styled-components';
7
- import { DEFAULT_ACCENT_COLOR, DEFAULT_BRAND_COLOR, DEFAULT_SECONDARY_COLOR, DEFAULT_TOP_NAV_IMAGE_URL, gqlRequest, QueryKeyFactory, useIsMobile, isColorTooDark, MARK_PRO, INPUT_BORDER_COLOR, SLATE_50, SLATE_400, SLATE_200, getPlugins, useAllErrorFormats, formatCurrency, invokePlugin, GRAY_500, GRAY_200, useErrorNotification, useSuccessNotification, getFormattedInvoice, PAYABLE_INVOICE_STATES, BreakpointNumbers, useGraphQLmutation, formatDate, FrontendTransaction, SLATE_600, WHITE, TransactionKind, Lists, getAccount, SubscriptionChargeKind, SubscriptionState as SubscriptionState$2, MODAL_MAX_HEIGHT, SLATE_500, DataInterval, TAG_COLORS, ChargeType, PricingModel } from '@bunnyapp/common';
7
+ import { DEFAULT_ACCENT_COLOR, DEFAULT_BRAND_COLOR, DEFAULT_SECONDARY_COLOR, DEFAULT_TOP_NAV_IMAGE_URL, gqlRequest, QueryKeyFactory, useIsMobile, isColorTooDark, MARK_PRO, INPUT_BORDER_COLOR, SLATE_50, SLATE_400, SLATE_200, getPlugins, useAllErrorFormats, formatCurrency, invokePlugin, GRAY_500, GRAY_200, useErrorNotification, useSuccessNotification, getFormattedInvoice, PAYABLE_INVOICE_STATES, BreakpointNumbers, useGraphQLmutation, formatDate, FrontendTransaction, SLATE_600, WHITE, TransactionKind, Lists, getAccount, sortSubscriptionCharges, MODAL_MAX_HEIGHT, SLATE_500, DataInterval, SubscriptionState as SubscriptionState$2, TAG_COLORS, ChargeType, SubscriptionChargeKind, PricingModel } from '@bunnyapp/common';
8
8
  import { QueryClient, QueryClientProvider, useQuery, useQueryClient, keepPreviousData, useMutation } from '@tanstack/react-query';
9
9
  import theme from 'antd/lib/theme/index.js';
10
10
  import { RecoilRoot } from 'recoil';
@@ -19470,7 +19470,7 @@ var getBillingDetails = function (_a) {
19470
19470
  var Text$5 = Typography.Text;
19471
19471
  var DrawerHeader = function (_a) {
19472
19472
  var description = _a.description, onClose = _a.onClose, title = _a.title, closeButtonClassName = _a.closeButtonClassName;
19473
- return (jsxs("div", __assign({ className: "flex flex-col gap-4" }, { children: [jsxs("div", __assign({ className: "flex items-center justify-between gap-2" }, { children: [jsx(Text$5, __assign({ className: "text-xl", style: { fontWeight: 400 } }, { children: title })), onClose ? (jsx("button", __assign({ onClick: onClose, className: closeButtonClassName }, { children: jsx(CloseOutlined, {}) }))) : null] })), description && jsx("div", __assign({ className: "text-xs" }, { children: description }))] })));
19473
+ return (jsxs("div", __assign({ className: "flex flex-col gap-4" }, { children: [jsxs("div", __assign({ className: "flex items-center justify-between gap-2" }, { children: [jsx(Text$5, __assign({ className: "text-xl", style: { fontWeight: 400 } }, { children: title })), onClose ? (jsx("button", __assign({ id: "closePayment", onClick: onClose, className: closeButtonClassName }, { children: jsx(CloseOutlined, {}) }))) : null] })), description && jsx("div", __assign({ className: "text-xs" }, { children: description }))] })));
19474
19474
  };
19475
19475
 
19476
19476
  var PaymentMethod = function (_a) {
@@ -19527,7 +19527,7 @@ var PaymentMethodDisplay = function (_a) {
19527
19527
  body: {
19528
19528
  padding: "1rem 0 0 0",
19529
19529
  },
19530
- }, title: jsx("div", __assign({ className: "px-4" }, { children: jsx(DrawerHeader, { title: "New payment method", onClose: function () { return setShowModal(false); }, closeButtonClassName: "bg-transparent border-none cursor-pointer hover:bg-gray-100 p-2 rounded-sm transition-all duration-200" }) })), footer: null }, { children: children })));
19530
+ }, title: jsx("div", __assign({ className: "px-4" }, { children: jsx(DrawerHeader, { closeButtonClassName: "bg-transparent border-none cursor-pointer hover:bg-gray-100 p-2 rounded-sm transition-all duration-200", onClose: function () { return setShowModal(false); }, title: "New payment method" }) })), footer: null }, { children: children })));
19531
19531
  }
19532
19532
  return (jsx(Drawer, __assign({ closeIcon: null, onClose: function () { return setShowModal(false); }, open: showModal, styles: {
19533
19533
  body: {
@@ -19903,8 +19903,8 @@ function InitialSignupForm(_a) {
19903
19903
  { required: true, message: "Please input your email!" },
19904
19904
  { type: "email", message: "Please enter a valid email!" },
19905
19905
  ] }, { children: jsx(Input, { placeholder: "Email" }) })), jsx(Form.Item, __assign({ name: "accountName", rules: [
19906
- { required: true, message: "Please input your account name!" },
19907
- ] }, { children: jsx(Input, { placeholder: "Account name" }) }))] })), jsx(Form.Item, { children: jsx(Button, __assign({ type: "primary", onClick: handleSubmit, loading: submitting, className: "w-full mt-4" }, { children: "Proceed to payment" })) })] })));
19906
+ { required: true, message: "Please input your company name!" },
19907
+ ] }, { children: jsx(Input, { placeholder: "Company name" }) }))] })), jsx(Form.Item, { children: jsx(Button, __assign({ type: "primary", onClick: handleSubmit, loading: submitting, className: "w-full mt-4" }, { children: "Proceed to payment" })) })] })));
19908
19908
  }
19909
19909
 
19910
19910
  var Title = Typography.Title, Text$4 = Typography.Text;
@@ -19937,6 +19937,7 @@ function Signup(_a) {
19937
19937
  var _j = useState(false), purchaseSucceeded = _j[0], setPurchaseSucceeded = _j[1];
19938
19938
  var _k = useState(undefined), paymentMethodGraphQLClient = _k[0], setPaymentMethodGraphQLClient = _k[1];
19939
19939
  var paymentMethod = usePaymentMethod({
19940
+ accountId: accountId,
19940
19941
  entityId: entityId,
19941
19942
  graphQLClient: paymentMethodGraphQLClient || graphQLClient,
19942
19943
  token: token,
@@ -19971,11 +19972,14 @@ function Signup(_a) {
19971
19972
  data = _a.sent();
19972
19973
  setAccountId(data.account.id);
19973
19974
  setPortalSessionToken(data.portalSessionToken);
19974
- setPaymentMethodGraphQLClient(createGraphQLClient(apiHost || "", data.portalSessionToken));
19975
+ setPaymentMethodGraphQLClient(createGraphQLClient(apiHost, data.portalSessionToken));
19975
19976
  // We must invalidate the accountPaymentMethodKey query in order to clear payment methods from the provided api token,
19976
19977
  // to instead use paymentMethods from portalSessionToken.
19977
19978
  queryClient.invalidateQueries({
19978
- queryKey: QueryKeyFactory.default.accountPaymentMethodKey({ entityId: entityId, token: token }),
19979
+ queryKey: QueryKeyFactory.default.accountPaymentMethodKey({
19980
+ entityId: entityId,
19981
+ token: token,
19982
+ }),
19979
19983
  });
19980
19984
  setProceedingToPayment(false);
19981
19985
  setQuote(data.quote);
@@ -20012,6 +20016,9 @@ function Signup(_a) {
20012
20016
  if (!(plugin === null || plugin === void 0 ? void 0 : plugin.id)) {
20013
20017
  throw new Error("Plugin ID is required");
20014
20018
  }
20019
+ if (!(paymentMethod === null || paymentMethod === void 0 ? void 0 : paymentMethod.id)) {
20020
+ throw new Error("Payment method ID is required");
20021
+ }
20015
20022
  return [4 /*yield*/, accountSignup({
20016
20023
  token: portalSessionToken,
20017
20024
  apiHost: apiHost,
@@ -20034,7 +20041,9 @@ function Signup(_a) {
20034
20041
  var children = _a.children, className = _a.className, style = _a.style;
20035
20042
  return isCardEnabled ? (jsx(Card, __assign({ className: className, style: style }, { children: children }))) : (jsx("div", __assign({ className: className, style: style }, { children: children })));
20036
20043
  };
20037
- return (jsx(WrapperComponent, __assign({ className: "p-4 flex flex-col ".concat(shadow, " ").concat(className), style: style }, { children: purchaseSucceeded ? (jsx(Fragment, { children: (quote === null || quote === void 0 ? void 0 : quote.currencyId) !== undefined ? (jsx(PaymentSuccessDisplay, { amountPaid: (quote === null || quote === void 0 ? void 0 : quote.amountDue) || 0, className: "w-full", companyName: companyName, returnUrl: returnUrl, currencyId: quote === null || quote === void 0 ? void 0 : quote.currencyId })) : (jsx("div", { children: "No currency ID found from Quote" })) })) : (jsxs("div", __assign({ className: "flex ".concat(isMobile ? "flex-col" : "flex-row", " h-full w-full") }, { children: [jsx("div", __assign({ className: "flex flex-col ".concat(isMobile ? "items-center" : "w-1/2 items-center") }, { children: jsx(PriceListDisplay, { priceListData: priceListData, topNavImageUrl: topNavImageUrl }) })), jsx("div", __assign({ className: "".concat(isMobile ? "h-full" : "my-4") }, { children: jsx(Divider, { className: "h-full", type: isMobile ? undefined : "vertical" }) })), jsx("div", __assign({ className: "flex ".concat(isMobile ? "items-center justify-center my-12" : "w-1/2 items-center justify-center my-12") }, { children: jsx("div", __assign({ className: "".concat(isMobile ? "w-full" : "w-1/2") }, { children: jsx(PaymentForms, { entityId: entityId, quote: quote, handlePaymentSuccess: handlePaymentSuccess, handlePaymentFail: handlePaymentFail, handleSubmit: handleSubmit, proceedingToPayment: proceedingToPayment, accountId: accountId, overrideToken: portalSessionToken, customCheckoutFunction: accountSignupFunction }) })) }))] }))) })));
20044
+ return (jsx(WrapperComponent, __assign({ className: "p-4 flex flex-col ".concat(shadow, " ").concat(className), style: style }, { children: purchaseSucceeded ? (jsx(Fragment, { children: (quote === null || quote === void 0 ? void 0 : quote.currencyId) !== undefined ? (jsx(PaymentSuccessDisplay, { amountPaid: (quote === null || quote === void 0 ? void 0 : quote.amountDue) || 0, className: "w-full", companyName: companyName, returnUrl: returnUrl, currencyId: quote === null || quote === void 0 ? void 0 : quote.currencyId })) : (jsx("div", { children: "No currency ID found from Quote" })) })) : (jsxs("div", __assign({ className: "flex ".concat(isMobile ? "flex-col" : "flex-row", " h-full w-full") }, { children: [jsx("div", __assign({ className: "flex flex-col ".concat(isMobile ? "items-center" : "w-1/2 items-center") }, { children: jsx(PriceListDisplay, { priceListData: priceListData, topNavImageUrl: topNavImageUrl }) })), jsx("div", __assign({ className: "".concat(isMobile ? "h-full" : "my-4") }, { children: jsx(Divider, { className: "h-full", type: isMobile ? undefined : "vertical" }) })), jsx("div", __assign({ className: "flex ".concat(isMobile
20045
+ ? "items-center justify-center my-12"
20046
+ : "w-1/2 items-center justify-center my-12") }, { children: jsx("div", __assign({ className: "".concat(isMobile ? "w-full" : "w-1/2") }, { children: jsx(PaymentForms, { entityId: entityId, quote: quote, handlePaymentSuccess: handlePaymentSuccess, handlePaymentFail: handlePaymentFail, handleSubmit: handleSubmit, proceedingToPayment: proceedingToPayment, accountId: accountId, overrideToken: portalSessionToken, customCheckoutFunction: accountSignupFunction }) })) }))] }))) })));
20038
20047
  }
20039
20048
 
20040
20049
  // WARNING: There is a preview button on APP that will need to be changed if this query is changed
@@ -20071,10 +20080,10 @@ var SUBSCRIPTIONS_QUERY = "\nquery subscriptions {\n subscriptions {\n n
20071
20080
  var getSubscriptions = function (_a) {
20072
20081
  var apiHost = _a.apiHost, entityId = _a.entityId, isInPreviewMode = _a.isInPreviewMode, token = _a.token;
20073
20082
  return __awaiter(void 0, void 0, void 0, function () {
20074
- var response;
20075
- var _b;
20076
- return __generator(this, function (_c) {
20077
- switch (_c.label) {
20083
+ var response, combinedSubscriptions;
20084
+ var _b, _c;
20085
+ return __generator(this, function (_d) {
20086
+ switch (_d.label) {
20078
20087
  case 0: return [4 /*yield*/, gqlRequest({
20079
20088
  isInPreviewMode: isInPreviewMode,
20080
20089
  query: SUBSCRIPTIONS_QUERY,
@@ -20083,78 +20092,14 @@ var getSubscriptions = function (_a) {
20083
20092
  apiHost: apiHost,
20084
20093
  })];
20085
20094
  case 1:
20086
- response = _c.sent();
20087
- return [2 /*return*/, (_b = response === null || response === void 0 ? void 0 : response.subscriptions) === null || _b === void 0 ? void 0 : _b.nodes];
20095
+ response = _d.sent();
20096
+ combinedSubscriptions = (_c = (_b = response === null || response === void 0 ? void 0 : response.subscriptions) === null || _b === void 0 ? void 0 : _b.nodes) === null || _c === void 0 ? void 0 : _c.map(function (subscription) { return (__assign(__assign({}, subscription), { charges: sortSubscriptionCharges(subscription.charges) })); });
20097
+ return [2 /*return*/, combinedSubscriptions];
20088
20098
  }
20089
20099
  });
20090
20100
  });
20091
20101
  };
20092
20102
 
20093
- var useSubscriptions = function (_a) {
20094
- var data = _a.data;
20095
- return useMemo(function () {
20096
- var clonedData = lodashExports.cloneDeep(data);
20097
- var combinedSubscriptions = clonedData === null || clonedData === void 0 ? void 0 : clonedData.map(function (subscription) {
20098
- var _a;
20099
- var orderedSubscriptionCharges = subscription.charges.sort(function (a, b) {
20100
- if (a.priceListChargeId !== b.priceListChargeId) {
20101
- return a.priceListChargeId.localeCompare(b.priceListChargeId);
20102
- }
20103
- if (a.kind === SubscriptionChargeKind.DISCOUNT &&
20104
- b.kind !== SubscriptionChargeKind.DISCOUNT) {
20105
- return 1;
20106
- }
20107
- if (a.kind !== SubscriptionChargeKind.DISCOUNT &&
20108
- b.kind === SubscriptionChargeKind.DISCOUNT) {
20109
- return -1;
20110
- }
20111
- return (a.endDate.localeCompare(b.endDate) ||
20112
- a.startDate.localeCompare(b.startDate));
20113
- });
20114
- var isTrial = ((_a = subscription.state) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === SubscriptionState$2.TRIAL;
20115
- var combinedSubscriptionCharges = [];
20116
- var aggregationCharge;
20117
- for (var index = 0; index < orderedSubscriptionCharges.length; index++) {
20118
- var charge = orderedSubscriptionCharges[index];
20119
- var nextCharge = orderedSubscriptionCharges[index + 1];
20120
- if (!aggregationCharge)
20121
- aggregationCharge = charge;
20122
- // If the next charge is the same priceListChargeId and endDate, aggregate the quantities
20123
- if (nextCharge &&
20124
- charge.priceListChargeId === nextCharge.priceListChargeId &&
20125
- charge.endDate === nextCharge.endDate &&
20126
- charge.startDate === nextCharge.startDate &&
20127
- charge.kind === nextCharge.kind) {
20128
- aggregationCharge.quantity += nextCharge.quantity;
20129
- // If the next charge is different, push the aggregationCharge to the combinedSubscriptionCharges
20130
- }
20131
- else if (nextCharge &&
20132
- charge.priceListChargeId === nextCharge.priceListChargeId &&
20133
- (charge.endDate !== nextCharge.endDate ||
20134
- charge.startDate !== nextCharge.startDate) &&
20135
- charge.kind === nextCharge.kind &&
20136
- (!isTrial || charge.trial) &&
20137
- (isTrial || !charge.trial)) {
20138
- nextCharge.name = "";
20139
- combinedSubscriptionCharges.push(aggregationCharge);
20140
- aggregationCharge = undefined;
20141
- }
20142
- else {
20143
- combinedSubscriptionCharges.push(aggregationCharge);
20144
- aggregationCharge = undefined;
20145
- }
20146
- }
20147
- subscription.charges = combinedSubscriptionCharges;
20148
- return subscription;
20149
- });
20150
- var subscriptionOrder = Object.values(SubscriptionState$2);
20151
- combinedSubscriptions === null || combinedSubscriptions === void 0 ? void 0 : combinedSubscriptions.sort(function (a, b) {
20152
- return subscriptionOrder.indexOf(a.state) - subscriptionOrder.indexOf(b.state);
20153
- });
20154
- return combinedSubscriptions;
20155
- }, [data]);
20156
- };
20157
-
20158
20103
  var ErrorView = function (_a) {
20159
20104
  var children = _a.children, message = _a.message;
20160
20105
  return (jsxs("div", __assign({ className: "flex flex-col w-full", style: { marginTop: "80px" } }, { children: [jsx("div", __assign({ style: { fontSize: "32px" } }, { children: message })), children] })));
@@ -20587,14 +20532,12 @@ var Subscriptions = function (_a) {
20587
20532
  }),
20588
20533
  queryFn: function () { return getSubscriptions({ entityId: entityId, token: token, apiHost: apiHost }); },
20589
20534
  enabled: Boolean(entityId),
20590
- }), rawSubscriptions = _d.data, subscriptionsAreLoading = _d.isLoading;
20535
+ }), subscriptions = _d.data, subscriptionsAreLoading = _d.isLoading;
20591
20536
  var _e = useQuery({
20592
20537
  queryKey: QueryKeyFactory.default.planChangeOptionsKey({ token: token }),
20593
20538
  queryFn: function () { return getPlanChangeOptions({ token: token, apiHost: apiHost }); },
20594
20539
  enabled: Boolean(onChangePlanClick),
20595
20540
  }), planChangeOptions = _e.data, arePlanChangeOptionsLoading = _e.isLoading;
20596
- // Derived state
20597
- var subscriptions = useSubscriptions({ data: rawSubscriptions });
20598
20541
  useEffect(function () {
20599
20542
  if (subscriptions)
20600
20543
  onSubscriptionsLoaded === null || onSubscriptionsLoaded === void 0 ? void 0 : onSubscriptionsLoaded(subscriptions);
@@ -2,7 +2,7 @@ import { PlanChangeOptions, Subscription } from "@bunnyapp/common";
2
2
  declare const SubscriptionCardActions: ({ onChangePlanClick, onCancelSubscriptionClick, planChangeOptions, subscription, }: {
3
3
  onChangePlanClick: (subscription: Subscription) => void;
4
4
  onCancelSubscriptionClick: (subscription: Subscription) => void;
5
- planChangeOptions?: PlanChangeOptions | undefined;
5
+ planChangeOptions?: any;
6
6
  subscription: Subscription;
7
7
  }) => import("react/jsx-runtime").JSX.Element | null;
8
8
  export default SubscriptionCardActions;
@@ -2,7 +2,7 @@ import { PlanChangeOptions, Subscription } from "@bunnyapp/common";
2
2
  declare const SubscriptionCardHeader: ({ onChangePlanClick, onCancelSubscriptionClick, planChangeOptions, subscription, }: {
3
3
  onChangePlanClick?: ((subscription: Subscription) => void) | undefined;
4
4
  onCancelSubscriptionClick?: ((subscription: Subscription) => void) | undefined;
5
- planChangeOptions?: PlanChangeOptions | undefined;
5
+ planChangeOptions?: any;
6
6
  subscription: Subscription;
7
7
  }) => import("react/jsx-runtime").JSX.Element;
8
8
  export default SubscriptionCardHeader;
@@ -3,7 +3,7 @@ declare const SubscriptionsList: ({ hideExpired, onChangePlanClick, onCancelSubs
3
3
  hideExpired: boolean;
4
4
  onChangePlanClick?: ((subscription: Subscription) => void) | undefined;
5
5
  onCancelSubscriptionClick?: ((subscription: Subscription) => void) | undefined;
6
- planChangeOptions?: PlanChangeOptions | undefined;
6
+ planChangeOptions?: any;
7
7
  subscriptions: Subscription[];
8
8
  }) => import("react/jsx-runtime").JSX.Element;
9
9
  export default SubscriptionsList;
@@ -2,7 +2,7 @@ import { PlanChangeOptions, Subscription } from "@bunnyapp/common";
2
2
  declare const SubscriptionCardDesktop: ({ onChangePlanClick, onCancelSubscriptionClick, planChangeOptions, subscription, }: {
3
3
  onChangePlanClick?: ((subscription: Subscription) => void) | undefined;
4
4
  onCancelSubscriptionClick?: ((subscription: Subscription) => void) | undefined;
5
- planChangeOptions?: PlanChangeOptions | undefined;
5
+ planChangeOptions?: any;
6
6
  subscription: Subscription;
7
7
  }) => import("react/jsx-runtime").JSX.Element;
8
8
  export default SubscriptionCardDesktop;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bunnyapp/components",
3
- "version": "1.0.41",
3
+ "version": "1.0.43",
4
4
  "description": "Components from the Bunny portal to embed Bunny UI functionality into your application.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -63,7 +63,8 @@
63
63
  "vite": "^6.2.1"
64
64
  },
65
65
  "peerDependencies": {
66
- "@bunnyapp/common": "^1.0.47",
66
+ "@ant-design/icons": "^5.6.1",
67
+ "@bunnyapp/common": "^1.0.52",
67
68
  "@fortawesome/fontawesome-svg-core": "^6.7.2",
68
69
  "@fortawesome/free-brands-svg-icons": "^6.7.2",
69
70
  "@fortawesome/free-regular-svg-icons": "^6.7.2",
@@ -78,17 +79,19 @@
78
79
  "interweave": "^13.1.0",
79
80
  "less": "^4.2.0",
80
81
  "lodash-es": "^4.17.21",
82
+ "pluralize": "^8.0.0",
81
83
  "react": "^18.3.1",
82
84
  "react-dom": "^18.3.1",
83
85
  "recharts": "^2.15.0",
84
86
  "recoil": "^0.7.7",
85
- "@ant-design/icons": "^5.6.1",
86
- "styled-components": "^6.1.13",
87
- "pluralize": "^8.0.0"
87
+ "styled-components": "^6.1.13"
88
88
  },
89
89
  "msw": {
90
90
  "workerDirectory": [
91
91
  "public"
92
92
  ]
93
+ },
94
+ "dependencies": {
95
+ "msw-storybook-addon": "^2.0.4"
93
96
  }
94
97
  }
@@ -1,5 +0,0 @@
1
- import { Subscription } from "@bunnyapp/common";
2
- declare const useSubscriptions: ({ data }: {
3
- data: Subscription[];
4
- }) => Subscription[];
5
- export default useSubscriptions;
@@ -1,5 +0,0 @@
1
- import { Subscription } from "@bunnyapp/common";
2
- declare const useSubscriptions: ({ data }: {
3
- data: Subscription[];
4
- }) => Subscription[];
5
- export default useSubscriptions;