@bunnyapp/components 1.6.0-beta.9.3 → 1.6.0-beta.9.4

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
@@ -52,7 +52,7 @@ var css_248z = ":root {\n --row-background: #ffffff;\n --row-background-altern
52
52
  styleInject(css_248z);
53
53
 
54
54
  // This will be replaced at build time by rollup-plugin-replace
55
- const PACKAGE_VERSION = '1.6.0-beta.9.2';
55
+ const PACKAGE_VERSION = '1.6.0-beta.9.4';
56
56
  const createRequestHeaders = (token) => {
57
57
  const headers = createClientDevHeaders({ token });
58
58
  // Add the components version header
@@ -22919,7 +22919,7 @@ const isSubscriptionActiveOrPending = (subscription) => {
22919
22919
  const isSubscriptionTrial = (subscription) => { var _a; return ((_a = subscription.state) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === common.SubscriptionState.TRIAL; };
22920
22920
  const isSubscriptionTrialExpired = (subscription) => { var _a; return ((_a = subscription.state) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === common.SubscriptionState.TRIAL_EXPIRED; };
22921
22921
  // Helper function to check if charge is a discount
22922
- const isDiscount = (kind) => kind === common.QuoteChangeKind.DISCOUNT || kind === common.QuoteChangeKind.FREE_PERIOD_DISCOUNT;
22922
+ const isDiscount$1 = (kind) => kind === common.QuoteChangeKind.DISCOUNT || kind === common.QuoteChangeKind.FREE_PERIOD_DISCOUNT;
22923
22923
  const hasPriceTiers = (charge) => {
22924
22924
  var _a;
22925
22925
  return Boolean((_a = charge === null || charge === void 0 ? void 0 : charge.priceTiers) === null || _a === void 0 ? void 0 : _a.length);
@@ -23068,10 +23068,9 @@ var BillingPeriodConverter;
23068
23068
  })(BillingPeriodConverter || (BillingPeriodConverter = {}));
23069
23069
  var BillingPeriodConverter$1 = BillingPeriodConverter;
23070
23070
 
23071
- const SubscriptionChargeTotal = ({ charge, subscription, }) => {
23071
+ const SubscriptionChargeTotal = ({ charge, currencyId, }) => {
23072
23072
  const billingPeriod = charge.billingPeriod && BillingPeriodConverter$1[charge.billingPeriod];
23073
23073
  const isMobile = common.useIsMobile();
23074
- const { currencyId } = subscription;
23075
23074
  const formattedDiscountedPrice = common.formatCurrency(charge.price, currencyId);
23076
23075
  const formattedPeriodPrice = common.formatCurrency(charge.periodPrice, currencyId);
23077
23076
  return (jsxRuntime.jsx("div", { className: `bunny-flex bunny-gap-1 ${isMobile ? 'bunny-flex-col' : ''}`, children: charge.chargeType === common.ChargeType.USAGE || charge.trial
@@ -23137,7 +23136,7 @@ const SubscriptionChargeUnitPrice = ({ charge, currencyId, }) => {
23137
23136
  const price = charge.trial
23138
23137
  ? '-'
23139
23138
  : common.formatCurrency(charge.discountedPrice, currencyId, charge.priceDecimals);
23140
- const isChargeDiscount = isDiscount(charge.kind);
23139
+ const isChargeDiscount = isDiscount$1(charge.kind);
23141
23140
  return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: hasPriceTiers(charge) ? (jsxRuntime.jsx(TieredDisplayDropdown, { charge: charge, currencyId: currencyId, truncatedText: `${charge.kind === common.QuoteChangeKind.PRICE_UPDATE ? 'new ' : ''}${getApplicablePriceTier(charge, currencyId, charge.priceDecimals)}` })) : isChargeDiscount ? (`-${price}`) : (price) }));
23142
23141
  };
23143
23142
 
@@ -23156,6 +23155,37 @@ const SubscriptionsListCell = ({ children, className, gridColumn, right, style,
23156
23155
  }, children: children }));
23157
23156
  };
23158
23157
 
23158
+ // Helper function to check if charge is a discount
23159
+ const isDiscount = (kind) => kind === common.QuoteChangeKind.DISCOUNT;
23160
+ const sortSubscriptionCharges = (charges) => {
23161
+ // Make a copy of charges array and sort them by specific criteria
23162
+ const orderedCharges = [...charges].sort((a, b) => {
23163
+ // First group by priceListChargeId to keep related charges together
23164
+ if (a.priceListChargeId !== b.priceListChargeId) {
23165
+ return a.priceListChargeId.localeCompare(b.priceListChargeId);
23166
+ }
23167
+ // Move discount charges to the end within each priceList group
23168
+ if (isDiscount(a.kind) && !isDiscount(b.kind)) {
23169
+ return 1;
23170
+ }
23171
+ if (!isDiscount(a.kind) && isDiscount(b.kind)) {
23172
+ return -1;
23173
+ }
23174
+ // Then sort by end date, start date, and finally show amendments last
23175
+ return (a.endDate.localeCompare(b.endDate) ||
23176
+ a.startDate.localeCompare(b.startDate) ||
23177
+ (a.isAmendment ? 1 : -1));
23178
+ });
23179
+ return orderedCharges;
23180
+ };
23181
+
23182
+ const filterSubscriptionCharges = (charges) => {
23183
+ return charges.filter(charge => {
23184
+ const isEndDateBeforeCurrentDate = dayjs(charge.endDate).isBefore(dayjs(), 'day');
23185
+ return !isEndDateBeforeCurrentDate;
23186
+ });
23187
+ };
23188
+
23159
23189
  const NON_ADDON_CARD_COLUMNS = [
23160
23190
  {
23161
23191
  title: 'Charge',
@@ -23210,6 +23240,7 @@ const SubscriptionCardDesktop = ({ onChangePlanClick, onCancelSubscriptionClick,
23210
23240
  var _a;
23211
23241
  const { shadow } = react.useContext(SubscriptionsContext);
23212
23242
  const CARD_COLUMNS = isAddon ? ADDON_CARD_COLUMNS : NON_ADDON_CARD_COLUMNS;
23243
+ const charges = sortSubscriptionCharges(filterSubscriptionCharges((_a = subscription === null || subscription === void 0 ? void 0 : subscription.chargeReport) !== null && _a !== void 0 ? _a : []));
23213
23244
  return (jsxRuntime.jsxs(Card, { className: `bunny-p-4 ${shadow ? `shadow-${shadow}` : ''}`, children: [jsxRuntime.jsx(SubscriptionCardHeader, { onChangePlanClick: onChangePlanClick, onCancelSubscriptionClick: onCancelSubscriptionClick, subscription: subscription }), jsxRuntime.jsx(antd.Divider, { className: "bunny-my-4", style: {
23214
23245
  gridColumn: '1 / 5',
23215
23246
  width: 'calc(100% + 32px)',
@@ -23217,15 +23248,15 @@ const SubscriptionCardDesktop = ({ onChangePlanClick, onCancelSubscriptionClick,
23217
23248
  } }), jsxRuntime.jsxs("div", { className: "bunny-grid bunny-w-full", style: {
23218
23249
  gridTemplateColumns: CARD_COLUMNS.map(column => column.width).join(' '),
23219
23250
  rowGap: '0.75rem',
23220
- }, children: [jsxRuntime.jsx(SubscriptionCardColumnHeaders, { columns: CARD_COLUMNS }), (_a = subscription === null || subscription === void 0 ? void 0 : subscription.chargeReport) === null || _a === void 0 ? void 0 : _a.map((charge, chargeIndex) => {
23221
- return (jsxRuntime.jsx(SubscriptionCardDesktopRow, { charge: charge, chargeIndex: chargeIndex, subscription: subscription }, chargeIndex));
23251
+ }, children: [jsxRuntime.jsx(SubscriptionCardColumnHeaders, { columns: CARD_COLUMNS }), charges.map((charge, chargeIndex) => {
23252
+ return (jsxRuntime.jsx(SubscriptionCardDesktopRow, { charge: charge, chargeIndex: chargeIndex, charges: charges, currencyId: subscription.currencyId }, chargeIndex));
23222
23253
  })] })] }));
23223
23254
  };
23224
- const SubscriptionCardDesktopRow = ({ charge, chargeIndex, subscription, }) => {
23225
- var _a, _b, _c;
23255
+ const SubscriptionCardDesktopRow = ({ charge, chargeIndex, charges, currencyId, }) => {
23256
+ var _a, _b;
23226
23257
  // Derived state
23227
23258
  const { isRamp } = charge;
23228
- const prevCharge = (_a = subscription === null || subscription === void 0 ? void 0 : subscription.chargeReport) === null || _a === void 0 ? void 0 : _a[chargeIndex - 1];
23259
+ const prevCharge = charges === null || charges === void 0 ? void 0 : charges[chargeIndex - 1];
23229
23260
  const chargePeriod = `${common.formatDate(charge.startDate)} - ${common.formatDate(charge.endDate)}`;
23230
23261
  const isRampFirstRow = isRamp && chargeIndex === 0;
23231
23262
  const isTrial = charge.trial;
@@ -23234,13 +23265,13 @@ const SubscriptionCardDesktopRow = ({ charge, chargeIndex, subscription, }) => {
23234
23265
  !isDiscount &&
23235
23266
  (!isTrial || (prevCharge === null || prevCharge === void 0 ? void 0 : prevCharge.trial)) &&
23236
23267
  (isTrial || !(prevCharge === null || prevCharge === void 0 ? void 0 : prevCharge.trial));
23237
- return (jsxRuntime.jsxs("div", { className: "bunny-contents", children: [(isRampFirstRow || !isRamp) && (jsxRuntime.jsx(SubscriptionsListCell, { gridColumn: isRamp ? '1/-1' : '1', children: jsxRuntime.jsx("div", { className: `bunny-flex bunny-items-center bunny-gap-2 ${isDiscount ? 'bunny-pl-4' : ''}`, children: jsxRuntime.jsx("div", { children: isRampFirstRow || (!isRamp && !dontShowChargeName) ? charge.name : '' }) }) })), jsxRuntime.jsx(SubscriptionsListCell, { gridColumn: 2, children: jsxRuntime.jsx("div", { children: chargePeriod }) }), jsxRuntime.jsx(SubscriptionsListCell, { right: true, children: charge.kind === common.QuoteChangeKind.DISCOUNT
23268
+ return (jsxRuntime.jsxs("div", { className: "bunny-contents", children: [(isRampFirstRow || !isRamp) && (jsxRuntime.jsx(SubscriptionsListCell, { gridColumn: isRamp ? '1/-1' : '1', children: jsxRuntime.jsx("div", { className: `bunny-flex bunny-items-center bunny-gap-2 ${isDiscount ? 'bunny-pl-0' : ''}`, children: jsxRuntime.jsx("div", { children: isRampFirstRow || (!isRamp && !dontShowChargeName) ? charge.name : '' }) }) })), jsxRuntime.jsx(SubscriptionsListCell, { gridColumn: 2, children: jsxRuntime.jsx("div", { children: chargePeriod }) }), jsxRuntime.jsx(SubscriptionsListCell, { right: true, children: charge.kind === common.QuoteChangeKind.DISCOUNT
23238
23269
  ? ''
23239
23270
  : charge.chargeType === common.ChargeType.USAGE
23240
23271
  ? charge.histogram && (jsxRuntime.jsx(FeatureUsageGraph, { charge: charge, featureUsage: charge.histogram, useAreaChart: true }))
23241
23272
  : charge.isAmendment
23242
- ? `+${(_b = charge.quantity) === null || _b === void 0 ? void 0 : _b.toLocaleString()}`
23243
- : (_c = charge.quantity) === null || _c === void 0 ? void 0 : _c.toLocaleString() }), jsxRuntime.jsx(SubscriptionsListCell, { right: true, children: jsxRuntime.jsx(SubscriptionChargeUnitPrice, { charge: charge, currencyId: subscription.currencyId }) }), jsxRuntime.jsx(SubscriptionsListCell, { right: true, children: jsxRuntime.jsx(SubscriptionChargeTotal, { charge: charge, subscription: subscription }) })] }));
23273
+ ? `+${(_a = charge.quantity) === null || _a === void 0 ? void 0 : _a.toLocaleString()}`
23274
+ : (_b = charge.quantity) === null || _b === void 0 ? void 0 : _b.toLocaleString() }), jsxRuntime.jsx(SubscriptionsListCell, { right: true, children: jsxRuntime.jsx(SubscriptionChargeUnitPrice, { charge: charge, currencyId: currencyId }) }), jsxRuntime.jsx(SubscriptionsListCell, { right: true, children: jsxRuntime.jsx(SubscriptionChargeTotal, { charge: charge, currencyId: currencyId }) })] }));
23244
23275
  };
23245
23276
 
23246
23277
  function AddonSubscriptionsCards({ onCancelSubscriptionClick, subscriptions, subscription, showInactive, }) {
@@ -23284,6 +23315,7 @@ const SubscriptionCard = ({ subscription }) => {
23284
23315
  const { shadow } = react.useContext(SubscriptionsContext);
23285
23316
  // Derived state
23286
23317
  const backgroundColor = darkMode ? 'var(--row-background-dark)' : 'var(--row-background)';
23318
+ const charges = sortSubscriptionCharges(filterSubscriptionCharges((_a = subscription === null || subscription === void 0 ? void 0 : subscription.chargeReport) !== null && _a !== void 0 ? _a : []));
23287
23319
  return (jsxRuntime.jsxs(Card, { className: `bunny-flex bunny-flex-col bunny-p-4 ${shadow ? `shadow-${shadow}` : ''}`, children: [jsxRuntime.jsx(SubscriptionCardHeader, { subscription: subscription }), jsxRuntime.jsx(antd.Divider, { className: "bunny-my-4", style: {
23288
23320
  gridColumn: '1 / -1',
23289
23321
  width: 'calc(100% + 32px)',
@@ -23293,10 +23325,10 @@ const SubscriptionCard = ({ subscription }) => {
23293
23325
  gridTemplateColumns: `1fr auto auto auto`,
23294
23326
  rowGap: '0.75rem',
23295
23327
  backgroundColor,
23296
- }, children: [CHARGE_COLUMNS.map((subscriptionColumn, index) => (jsxRuntime.jsx(SubscriptionCardCellMobile, { className: `bunny-text-slate-400 ${subscriptionColumn.className}`, style: { fontSize: '11px' }, children: subscriptionColumn.title }, index))), (_a = subscription === null || subscription === void 0 ? void 0 : subscription.chargeReport) === null || _a === void 0 ? void 0 : _a.map((charge, chargeIndex) => {
23328
+ }, children: [CHARGE_COLUMNS.map((subscriptionColumn, index) => (jsxRuntime.jsx(SubscriptionCardCellMobile, { className: `bunny-text-slate-400 ${subscriptionColumn.className}`, style: { fontSize: '11px' }, children: subscriptionColumn.title }, index))), charges.map((charge, chargeIndex) => {
23297
23329
  const { isRamp } = charge;
23298
23330
  const chargePeriod = `${common.formatDate(charge.startDate)} - ${common.formatDate(charge.endDate)}`;
23299
- return (jsxRuntime.jsxs("div", { className: "bunny-contents", children: [((isRamp && chargeIndex === 0) || !isRamp) && (jsxRuntime.jsxs(SubscriptionCardCellMobile, { className: CHARGE_COLUMNS[0].className, style: { gridColumn: isRamp ? '1/-1' : '1' }, children: [jsxRuntime.jsx("span", { children: charge.name }), !isRamp ? ` - ${chargePeriod}` : ''] })), isRamp && (jsxRuntime.jsx(SubscriptionCardCellMobile, { className: CHARGE_COLUMNS[0].className, children: `- ${chargePeriod}` })), jsxRuntime.jsx(SubscriptionCardCellMobile, { className: CHARGE_COLUMNS[1].className, children: charge.kind === common.QuoteChangeKind.DISCOUNT ? '' : charge.quantity }), jsxRuntime.jsx(SubscriptionCardCellMobile, { className: CHARGE_COLUMNS[2].className, children: jsxRuntime.jsx(SubscriptionChargeUnitPrice, { charge: charge, currencyId: subscription.currencyId }) }), jsxRuntime.jsx(SubscriptionCardCellMobile, { className: CHARGE_COLUMNS[3].className, children: jsxRuntime.jsx(SubscriptionChargeTotal, { charge: charge, subscription: subscription }) })] }, chargeIndex));
23331
+ return (jsxRuntime.jsxs("div", { className: "bunny-contents", children: [((isRamp && chargeIndex === 0) || !isRamp) && (jsxRuntime.jsxs(SubscriptionCardCellMobile, { className: CHARGE_COLUMNS[0].className, style: { gridColumn: isRamp ? '1/-1' : '1' }, children: [jsxRuntime.jsx("span", { children: charge.name }), !isRamp ? ` - ${chargePeriod}` : ''] })), isRamp && (jsxRuntime.jsx(SubscriptionCardCellMobile, { className: CHARGE_COLUMNS[0].className, children: `- ${chargePeriod}` })), jsxRuntime.jsx(SubscriptionCardCellMobile, { className: CHARGE_COLUMNS[1].className, children: charge.kind === common.QuoteChangeKind.DISCOUNT ? '' : charge.quantity }), jsxRuntime.jsx(SubscriptionCardCellMobile, { className: CHARGE_COLUMNS[2].className, children: jsxRuntime.jsx(SubscriptionChargeUnitPrice, { charge: charge, currencyId: subscription.currencyId }) }), jsxRuntime.jsx(SubscriptionCardCellMobile, { className: CHARGE_COLUMNS[3].className, children: jsxRuntime.jsx(SubscriptionChargeTotal, { charge: charge, currencyId: subscription.currencyId }) })] }, chargeIndex));
23300
23332
  })] })] }));
23301
23333
  };
23302
23334
 
@@ -1,6 +1,6 @@
1
- import { Subscription, SubscriptionCharge } from '@bunnyapp/common';
2
- declare const SubscriptionChargeTotal: ({ charge, subscription, }: {
1
+ import { SubscriptionCharge } from '@bunnyapp/common';
2
+ declare const SubscriptionChargeTotal: ({ charge, currencyId, }: {
3
3
  charge: SubscriptionCharge;
4
- subscription: Subscription;
4
+ currencyId: string;
5
5
  }) => import("react/jsx-runtime").JSX.Element;
6
6
  export default SubscriptionChargeTotal;
@@ -0,0 +1,2 @@
1
+ import { SubscriptionCharge } from '../../../../types/SubscriptionCharge';
2
+ export declare const filterSubscriptionCharges: (charges: SubscriptionCharge[]) => SubscriptionCharge[];
@@ -0,0 +1,2 @@
1
+ import { SubscriptionCharge } from '../../../../types/SubscriptionCharge';
2
+ export declare const sortSubscriptionCharges: (charges: SubscriptionCharge[]) => SubscriptionCharge[];
package/dist/esm/index.js CHANGED
@@ -50,7 +50,7 @@ var css_248z = ":root {\n --row-background: #ffffff;\n --row-background-altern
50
50
  styleInject(css_248z);
51
51
 
52
52
  // This will be replaced at build time by rollup-plugin-replace
53
- const PACKAGE_VERSION = '1.6.0-beta.9.2';
53
+ const PACKAGE_VERSION = '1.6.0-beta.9.4';
54
54
  const createRequestHeaders = (token) => {
55
55
  const headers = createClientDevHeaders({ token });
56
56
  // Add the components version header
@@ -22917,7 +22917,7 @@ const isSubscriptionActiveOrPending = (subscription) => {
22917
22917
  const isSubscriptionTrial = (subscription) => { var _a; return ((_a = subscription.state) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === SubscriptionState$2.TRIAL; };
22918
22918
  const isSubscriptionTrialExpired = (subscription) => { var _a; return ((_a = subscription.state) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === SubscriptionState$2.TRIAL_EXPIRED; };
22919
22919
  // Helper function to check if charge is a discount
22920
- const isDiscount = (kind) => kind === QuoteChangeKind.DISCOUNT || kind === QuoteChangeKind.FREE_PERIOD_DISCOUNT;
22920
+ const isDiscount$1 = (kind) => kind === QuoteChangeKind.DISCOUNT || kind === QuoteChangeKind.FREE_PERIOD_DISCOUNT;
22921
22921
  const hasPriceTiers = (charge) => {
22922
22922
  var _a;
22923
22923
  return Boolean((_a = charge === null || charge === void 0 ? void 0 : charge.priceTiers) === null || _a === void 0 ? void 0 : _a.length);
@@ -23066,10 +23066,9 @@ var BillingPeriodConverter;
23066
23066
  })(BillingPeriodConverter || (BillingPeriodConverter = {}));
23067
23067
  var BillingPeriodConverter$1 = BillingPeriodConverter;
23068
23068
 
23069
- const SubscriptionChargeTotal = ({ charge, subscription, }) => {
23069
+ const SubscriptionChargeTotal = ({ charge, currencyId, }) => {
23070
23070
  const billingPeriod = charge.billingPeriod && BillingPeriodConverter$1[charge.billingPeriod];
23071
23071
  const isMobile = useIsMobile();
23072
- const { currencyId } = subscription;
23073
23072
  const formattedDiscountedPrice = formatCurrency(charge.price, currencyId);
23074
23073
  const formattedPeriodPrice = formatCurrency(charge.periodPrice, currencyId);
23075
23074
  return (jsx("div", { className: `bunny-flex bunny-gap-1 ${isMobile ? 'bunny-flex-col' : ''}`, children: charge.chargeType === ChargeType.USAGE || charge.trial
@@ -23135,7 +23134,7 @@ const SubscriptionChargeUnitPrice = ({ charge, currencyId, }) => {
23135
23134
  const price = charge.trial
23136
23135
  ? '-'
23137
23136
  : formatCurrency(charge.discountedPrice, currencyId, charge.priceDecimals);
23138
- const isChargeDiscount = isDiscount(charge.kind);
23137
+ const isChargeDiscount = isDiscount$1(charge.kind);
23139
23138
  return (jsx(Fragment, { children: hasPriceTiers(charge) ? (jsx(TieredDisplayDropdown, { charge: charge, currencyId: currencyId, truncatedText: `${charge.kind === QuoteChangeKind.PRICE_UPDATE ? 'new ' : ''}${getApplicablePriceTier(charge, currencyId, charge.priceDecimals)}` })) : isChargeDiscount ? (`-${price}`) : (price) }));
23140
23139
  };
23141
23140
 
@@ -23154,6 +23153,37 @@ const SubscriptionsListCell = ({ children, className, gridColumn, right, style,
23154
23153
  }, children: children }));
23155
23154
  };
23156
23155
 
23156
+ // Helper function to check if charge is a discount
23157
+ const isDiscount = (kind) => kind === QuoteChangeKind.DISCOUNT;
23158
+ const sortSubscriptionCharges = (charges) => {
23159
+ // Make a copy of charges array and sort them by specific criteria
23160
+ const orderedCharges = [...charges].sort((a, b) => {
23161
+ // First group by priceListChargeId to keep related charges together
23162
+ if (a.priceListChargeId !== b.priceListChargeId) {
23163
+ return a.priceListChargeId.localeCompare(b.priceListChargeId);
23164
+ }
23165
+ // Move discount charges to the end within each priceList group
23166
+ if (isDiscount(a.kind) && !isDiscount(b.kind)) {
23167
+ return 1;
23168
+ }
23169
+ if (!isDiscount(a.kind) && isDiscount(b.kind)) {
23170
+ return -1;
23171
+ }
23172
+ // Then sort by end date, start date, and finally show amendments last
23173
+ return (a.endDate.localeCompare(b.endDate) ||
23174
+ a.startDate.localeCompare(b.startDate) ||
23175
+ (a.isAmendment ? 1 : -1));
23176
+ });
23177
+ return orderedCharges;
23178
+ };
23179
+
23180
+ const filterSubscriptionCharges = (charges) => {
23181
+ return charges.filter(charge => {
23182
+ const isEndDateBeforeCurrentDate = dayjs(charge.endDate).isBefore(dayjs(), 'day');
23183
+ return !isEndDateBeforeCurrentDate;
23184
+ });
23185
+ };
23186
+
23157
23187
  const NON_ADDON_CARD_COLUMNS = [
23158
23188
  {
23159
23189
  title: 'Charge',
@@ -23208,6 +23238,7 @@ const SubscriptionCardDesktop = ({ onChangePlanClick, onCancelSubscriptionClick,
23208
23238
  var _a;
23209
23239
  const { shadow } = useContext(SubscriptionsContext);
23210
23240
  const CARD_COLUMNS = isAddon ? ADDON_CARD_COLUMNS : NON_ADDON_CARD_COLUMNS;
23241
+ const charges = sortSubscriptionCharges(filterSubscriptionCharges((_a = subscription === null || subscription === void 0 ? void 0 : subscription.chargeReport) !== null && _a !== void 0 ? _a : []));
23211
23242
  return (jsxs(Card, { className: `bunny-p-4 ${shadow ? `shadow-${shadow}` : ''}`, children: [jsx(SubscriptionCardHeader, { onChangePlanClick: onChangePlanClick, onCancelSubscriptionClick: onCancelSubscriptionClick, subscription: subscription }), jsx(Divider, { className: "bunny-my-4", style: {
23212
23243
  gridColumn: '1 / 5',
23213
23244
  width: 'calc(100% + 32px)',
@@ -23215,15 +23246,15 @@ const SubscriptionCardDesktop = ({ onChangePlanClick, onCancelSubscriptionClick,
23215
23246
  } }), jsxs("div", { className: "bunny-grid bunny-w-full", style: {
23216
23247
  gridTemplateColumns: CARD_COLUMNS.map(column => column.width).join(' '),
23217
23248
  rowGap: '0.75rem',
23218
- }, children: [jsx(SubscriptionCardColumnHeaders, { columns: CARD_COLUMNS }), (_a = subscription === null || subscription === void 0 ? void 0 : subscription.chargeReport) === null || _a === void 0 ? void 0 : _a.map((charge, chargeIndex) => {
23219
- return (jsx(SubscriptionCardDesktopRow, { charge: charge, chargeIndex: chargeIndex, subscription: subscription }, chargeIndex));
23249
+ }, children: [jsx(SubscriptionCardColumnHeaders, { columns: CARD_COLUMNS }), charges.map((charge, chargeIndex) => {
23250
+ return (jsx(SubscriptionCardDesktopRow, { charge: charge, chargeIndex: chargeIndex, charges: charges, currencyId: subscription.currencyId }, chargeIndex));
23220
23251
  })] })] }));
23221
23252
  };
23222
- const SubscriptionCardDesktopRow = ({ charge, chargeIndex, subscription, }) => {
23223
- var _a, _b, _c;
23253
+ const SubscriptionCardDesktopRow = ({ charge, chargeIndex, charges, currencyId, }) => {
23254
+ var _a, _b;
23224
23255
  // Derived state
23225
23256
  const { isRamp } = charge;
23226
- const prevCharge = (_a = subscription === null || subscription === void 0 ? void 0 : subscription.chargeReport) === null || _a === void 0 ? void 0 : _a[chargeIndex - 1];
23257
+ const prevCharge = charges === null || charges === void 0 ? void 0 : charges[chargeIndex - 1];
23227
23258
  const chargePeriod = `${formatDate(charge.startDate)} - ${formatDate(charge.endDate)}`;
23228
23259
  const isRampFirstRow = isRamp && chargeIndex === 0;
23229
23260
  const isTrial = charge.trial;
@@ -23232,13 +23263,13 @@ const SubscriptionCardDesktopRow = ({ charge, chargeIndex, subscription, }) => {
23232
23263
  !isDiscount &&
23233
23264
  (!isTrial || (prevCharge === null || prevCharge === void 0 ? void 0 : prevCharge.trial)) &&
23234
23265
  (isTrial || !(prevCharge === null || prevCharge === void 0 ? void 0 : prevCharge.trial));
23235
- return (jsxs("div", { className: "bunny-contents", children: [(isRampFirstRow || !isRamp) && (jsx(SubscriptionsListCell, { gridColumn: isRamp ? '1/-1' : '1', children: jsx("div", { className: `bunny-flex bunny-items-center bunny-gap-2 ${isDiscount ? 'bunny-pl-4' : ''}`, children: jsx("div", { children: isRampFirstRow || (!isRamp && !dontShowChargeName) ? charge.name : '' }) }) })), jsx(SubscriptionsListCell, { gridColumn: 2, children: jsx("div", { children: chargePeriod }) }), jsx(SubscriptionsListCell, { right: true, children: charge.kind === QuoteChangeKind.DISCOUNT
23266
+ return (jsxs("div", { className: "bunny-contents", children: [(isRampFirstRow || !isRamp) && (jsx(SubscriptionsListCell, { gridColumn: isRamp ? '1/-1' : '1', children: jsx("div", { className: `bunny-flex bunny-items-center bunny-gap-2 ${isDiscount ? 'bunny-pl-0' : ''}`, children: jsx("div", { children: isRampFirstRow || (!isRamp && !dontShowChargeName) ? charge.name : '' }) }) })), jsx(SubscriptionsListCell, { gridColumn: 2, children: jsx("div", { children: chargePeriod }) }), jsx(SubscriptionsListCell, { right: true, children: charge.kind === QuoteChangeKind.DISCOUNT
23236
23267
  ? ''
23237
23268
  : charge.chargeType === ChargeType.USAGE
23238
23269
  ? charge.histogram && (jsx(FeatureUsageGraph, { charge: charge, featureUsage: charge.histogram, useAreaChart: true }))
23239
23270
  : charge.isAmendment
23240
- ? `+${(_b = charge.quantity) === null || _b === void 0 ? void 0 : _b.toLocaleString()}`
23241
- : (_c = charge.quantity) === null || _c === void 0 ? void 0 : _c.toLocaleString() }), jsx(SubscriptionsListCell, { right: true, children: jsx(SubscriptionChargeUnitPrice, { charge: charge, currencyId: subscription.currencyId }) }), jsx(SubscriptionsListCell, { right: true, children: jsx(SubscriptionChargeTotal, { charge: charge, subscription: subscription }) })] }));
23271
+ ? `+${(_a = charge.quantity) === null || _a === void 0 ? void 0 : _a.toLocaleString()}`
23272
+ : (_b = charge.quantity) === null || _b === void 0 ? void 0 : _b.toLocaleString() }), jsx(SubscriptionsListCell, { right: true, children: jsx(SubscriptionChargeUnitPrice, { charge: charge, currencyId: currencyId }) }), jsx(SubscriptionsListCell, { right: true, children: jsx(SubscriptionChargeTotal, { charge: charge, currencyId: currencyId }) })] }));
23242
23273
  };
23243
23274
 
23244
23275
  function AddonSubscriptionsCards({ onCancelSubscriptionClick, subscriptions, subscription, showInactive, }) {
@@ -23282,6 +23313,7 @@ const SubscriptionCard = ({ subscription }) => {
23282
23313
  const { shadow } = useContext(SubscriptionsContext);
23283
23314
  // Derived state
23284
23315
  const backgroundColor = darkMode ? 'var(--row-background-dark)' : 'var(--row-background)';
23316
+ const charges = sortSubscriptionCharges(filterSubscriptionCharges((_a = subscription === null || subscription === void 0 ? void 0 : subscription.chargeReport) !== null && _a !== void 0 ? _a : []));
23285
23317
  return (jsxs(Card, { className: `bunny-flex bunny-flex-col bunny-p-4 ${shadow ? `shadow-${shadow}` : ''}`, children: [jsx(SubscriptionCardHeader, { subscription: subscription }), jsx(Divider, { className: "bunny-my-4", style: {
23286
23318
  gridColumn: '1 / -1',
23287
23319
  width: 'calc(100% + 32px)',
@@ -23291,10 +23323,10 @@ const SubscriptionCard = ({ subscription }) => {
23291
23323
  gridTemplateColumns: `1fr auto auto auto`,
23292
23324
  rowGap: '0.75rem',
23293
23325
  backgroundColor,
23294
- }, children: [CHARGE_COLUMNS.map((subscriptionColumn, index) => (jsx(SubscriptionCardCellMobile, { className: `bunny-text-slate-400 ${subscriptionColumn.className}`, style: { fontSize: '11px' }, children: subscriptionColumn.title }, index))), (_a = subscription === null || subscription === void 0 ? void 0 : subscription.chargeReport) === null || _a === void 0 ? void 0 : _a.map((charge, chargeIndex) => {
23326
+ }, children: [CHARGE_COLUMNS.map((subscriptionColumn, index) => (jsx(SubscriptionCardCellMobile, { className: `bunny-text-slate-400 ${subscriptionColumn.className}`, style: { fontSize: '11px' }, children: subscriptionColumn.title }, index))), charges.map((charge, chargeIndex) => {
23295
23327
  const { isRamp } = charge;
23296
23328
  const chargePeriod = `${formatDate(charge.startDate)} - ${formatDate(charge.endDate)}`;
23297
- return (jsxs("div", { className: "bunny-contents", children: [((isRamp && chargeIndex === 0) || !isRamp) && (jsxs(SubscriptionCardCellMobile, { className: CHARGE_COLUMNS[0].className, style: { gridColumn: isRamp ? '1/-1' : '1' }, children: [jsx("span", { children: charge.name }), !isRamp ? ` - ${chargePeriod}` : ''] })), isRamp && (jsx(SubscriptionCardCellMobile, { className: CHARGE_COLUMNS[0].className, children: `- ${chargePeriod}` })), jsx(SubscriptionCardCellMobile, { className: CHARGE_COLUMNS[1].className, children: charge.kind === QuoteChangeKind.DISCOUNT ? '' : charge.quantity }), jsx(SubscriptionCardCellMobile, { className: CHARGE_COLUMNS[2].className, children: jsx(SubscriptionChargeUnitPrice, { charge: charge, currencyId: subscription.currencyId }) }), jsx(SubscriptionCardCellMobile, { className: CHARGE_COLUMNS[3].className, children: jsx(SubscriptionChargeTotal, { charge: charge, subscription: subscription }) })] }, chargeIndex));
23329
+ return (jsxs("div", { className: "bunny-contents", children: [((isRamp && chargeIndex === 0) || !isRamp) && (jsxs(SubscriptionCardCellMobile, { className: CHARGE_COLUMNS[0].className, style: { gridColumn: isRamp ? '1/-1' : '1' }, children: [jsx("span", { children: charge.name }), !isRamp ? ` - ${chargePeriod}` : ''] })), isRamp && (jsx(SubscriptionCardCellMobile, { className: CHARGE_COLUMNS[0].className, children: `- ${chargePeriod}` })), jsx(SubscriptionCardCellMobile, { className: CHARGE_COLUMNS[1].className, children: charge.kind === QuoteChangeKind.DISCOUNT ? '' : charge.quantity }), jsx(SubscriptionCardCellMobile, { className: CHARGE_COLUMNS[2].className, children: jsx(SubscriptionChargeUnitPrice, { charge: charge, currencyId: subscription.currencyId }) }), jsx(SubscriptionCardCellMobile, { className: CHARGE_COLUMNS[3].className, children: jsx(SubscriptionChargeTotal, { charge: charge, currencyId: subscription.currencyId }) })] }, chargeIndex));
23298
23330
  })] })] }));
23299
23331
  };
23300
23332
 
@@ -1,6 +1,6 @@
1
- import { Subscription, SubscriptionCharge } from '@bunnyapp/common';
2
- declare const SubscriptionChargeTotal: ({ charge, subscription, }: {
1
+ import { SubscriptionCharge } from '@bunnyapp/common';
2
+ declare const SubscriptionChargeTotal: ({ charge, currencyId, }: {
3
3
  charge: SubscriptionCharge;
4
- subscription: Subscription;
4
+ currencyId: string;
5
5
  }) => import("react/jsx-runtime").JSX.Element;
6
6
  export default SubscriptionChargeTotal;
@@ -0,0 +1,2 @@
1
+ import { SubscriptionCharge } from '../../../../types/SubscriptionCharge';
2
+ export declare const filterSubscriptionCharges: (charges: SubscriptionCharge[]) => SubscriptionCharge[];
@@ -0,0 +1,2 @@
1
+ import { SubscriptionCharge } from '../../../../types/SubscriptionCharge';
2
+ export declare const sortSubscriptionCharges: (charges: SubscriptionCharge[]) => SubscriptionCharge[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bunnyapp/components",
3
- "version": "1.6.0-beta.9.3",
3
+ "version": "1.6.0-beta.9.4",
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",