@micha.bigler/ui-core-micha 4.11.0 → 4.12.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.12.0 - UCM-BILL-8
4
+
5
+ `SubscriptionSection` accepts an optional `onChoosePlan` callback for apps that have their own plan page. With it, the
6
+ read-only state (no access) shows the "access ended" banner and one button "Abo waehlen" (`Billing.CHOOSE_PLAN`) that
7
+ calls `onChoosePlan()`, instead of the inline plan picker; the banner's "Abo erneuern" action calls it too (when an app
8
+ passes both `onRenew` and `onChoosePlan`, `onChoosePlan` wins for the banner action). Without the prop nothing
9
+ changes: the inline picker and the existing `onRenew` behaviour stay. The active-subscription view is untouched.
10
+
3
11
  ## 4.11.0 - UCM-BILL-7
4
12
 
5
13
  An entry of `AccountPage`'s `extraTabs` accepts an optional `group` naming one of the kit's navigation groups:
package/README.md CHANGED
@@ -23,6 +23,13 @@ the kit's navigation groups: `my-account` (Profile, Security), `management` (Use
23
23
  then appears in that group after the kit's own tabs, in the order of `extraTabs`, in the desktop sidebar and in the
24
24
  phone navigation. Without `group`, or with `more` or an unknown value, it stays in "More" as before.
25
25
 
26
+ ## Account section: plan choice on the app's own page
27
+
28
+ `SubscriptionSection` shows an inline plan picker for an account without access. An app with its own plan page passes
29
+ `onChoosePlan`: the section then shows the "access ended" banner and one button "Abo waehlen" that calls
30
+ `onChoosePlan()` (the banner's renew action calls it too, and wins over `onRenew`), and no inline picker. Without the
31
+ prop the section behaves as before.
32
+
26
33
  ## Consumer integration check
27
34
 
28
35
  ```js
@@ -20,8 +20,9 @@ function activeUntil(access, t, language) {
20
20
  const date = formatDate(access === null || access === void 0 ? void 0 : access.ends_at, language);
21
21
  return date ? t('Billing.ACTIVE_UNTIL', { date }) : null;
22
22
  }
23
- export function SubscriptionSection({ api = defaultBillingApi, redirect = (url) => window.location.assign(url), allowedHosts = DEFAULT_PAYMENT_HOSTS, onRenew, describePlan, withdrawal = true, seatCandidates, sx }) {
23
+ export function SubscriptionSection({ api = defaultBillingApi, redirect = (url) => window.location.assign(url), allowedHosts = DEFAULT_PAYMENT_HOSTS, onRenew, onChoosePlan, describePlan, withdrawal = true, seatCandidates, sx }) {
24
24
  var _a, _b, _c;
25
+ // Apps can hand read-only accounts off to their own plan page.
25
26
  const { t, i18n } = useTranslation();
26
27
  const { state, me, reload } = useBilling(api);
27
28
  const [withdrawnPurchases, setWithdrawnPurchases] = useState({});
@@ -103,11 +104,13 @@ export function SubscriptionSection({ api = defaultBillingApi, redirect = (url)
103
104
  const selectedSeatCandidate = eligibleSeatCandidates.find((candidate) => String(candidate.id) === seatInput);
104
105
  if (!sourceLine && access.status === 'active')
105
106
  return _jsx(Alert, { severity: "error", sx: SUBSCRIPTION_SECTION_ALERT_SX, children: t('Billing.ERROR_LOAD') });
106
- return _jsxs(Stack, { sx: sx, spacing: 2, children: [access.status === 'read_only' ? _jsxs(_Fragment, { children: [_jsx(AccessEndedBanner, { endedAt: access.ends_at, onRenew: onRenew || (() => {
107
+ return _jsxs(Stack, { sx: sx, spacing: 2, children: [access.status === 'read_only' ? _jsxs(_Fragment, { children: [_jsx(AccessEndedBanner, { endedAt: access.ends_at, onRenew: typeof onChoosePlan === 'function' ? () => onChoosePlan() : onRenew || (() => {
107
108
  var _a, _b, _c, _d;
108
109
  (_b = (_a = renewalPickerRef.current) === null || _a === void 0 ? void 0 : _a.scrollIntoView) === null || _b === void 0 ? void 0 : _b.call(_a, { behavior: 'smooth', block: 'start' });
109
110
  (_d = (_c = renewalPickerRef.current) === null || _c === void 0 ? void 0 : _c.querySelector('input[type="radio"]')) === null || _d === void 0 ? void 0 : _d.focus();
110
- }) }), _jsx("div", { ref: renewalPickerRef, children: _jsx(PlanPicker, { plans: me.plans || [], api: api, redirect: redirect, allowedHosts: allowedHosts, describePlan: describePlan }) })] }) : _jsxs(_Fragment, { children: [_jsx(Typography, { variant: "h5", children: t('Billing.HEADING') }), _jsx(Typography, { children: sourceLine }), access.source !== 'free' && dateLine && _jsx(Typography, { children: dateLine }), me.subscription && typeof me.subscription === 'object' && typeof me.subscription.plan_key === 'string' && typeof me.subscription.renews === 'boolean' && formatDate(me.subscription.current_period_end, i18n.language) && _jsxs(Stack, { spacing: 0.5, children: [_jsx(Typography, { children: t('Billing.OP_PLAN', { plan: me.subscription.plan_name || me.subscription.plan_key }) }), formatDate(me.subscription.current_period_end, i18n.language) && _jsx(Typography, { children: formatDate(me.subscription.current_period_start, i18n.language) ? `${formatDate(me.subscription.current_period_start, i18n.language)} – ${formatDate(me.subscription.current_period_end, i18n.language)}` : t('Billing.OP_UNTIL', { date: formatDate(me.subscription.current_period_end, i18n.language) }) }), typeof me.subscription.renews === 'boolean' && _jsx(Typography, { children: t(me.subscription.renews ? 'Billing.OP_RENEWS' : 'Billing.OP_ENDS') })] }), access.source === 'subscription' && _jsxs(Stack, { direction: "row", spacing: 1, alignItems: "center", children: [_jsx(Button, { disabled: busy, onClick: () => safeRedirect(() => api.openPortal(), 'Billing.ERROR_PORTAL'), children: t('Billing.MANAGE') }), _jsx(Typography, { children: t('Billing.MANAGE_DETAILS') })] }), access.source === 'team' && seatError && !seats && _jsx(Alert, { severity: "error", sx: SUBSCRIPTION_SECTION_ALERT_SX, children: t('Billing.ERROR_LOAD') }), me.team && Number.isInteger(me.team.seats_used) && Number.isInteger(me.team.seats_total) && _jsxs(Stack, { spacing: 0.5, children: [_jsx(Typography, { children: t('Billing.OP_SEATS_USED', { n: formatTokens(me.team.seats_used, i18n.language), m: formatTokens(me.team.seats_total, i18n.language) }) }), (Array.isArray(me.team.seat_holders) ? me.team.seat_holders : []).map((holder) => _jsxs(Stack, { children: [_jsx(Typography, { children: holder.name || holder.email }), holder.name && _jsx(Typography, { color: "text.secondary", children: holder.email })] }, holder.user_id))] }), access.source === 'team' && seats && _jsxs(Stack, { spacing: 1, children: [_jsx(Typography, { children: t('Billing.TEAM_SEATS') }), seats.map((seat) => _jsxs(Stack, { direction: "row", spacing: 1, alignItems: "center", children: [(() => { var _a; const holder = (((_a = me.team) === null || _a === void 0 ? void 0 : _a.seat_holders) || []).find((entry) => String(entry.user_id) === String(seat.user_id)); return _jsxs(Stack, { children: [_jsx(Typography, { children: (holder === null || holder === void 0 ? void 0 : holder.name) || (holder === null || holder === void 0 ? void 0 : holder.email) || String(seat.user_id) }), (holder === null || holder === void 0 ? void 0 : holder.name) && _jsx(Typography, { color: "text.secondary", children: holder.email })] }); })(), _jsx(Button, { disabled: busy, onClick: () => updateSeat(() => api.removeSeat({ userId: seat.user_id })), children: t('Billing.SEAT_REMOVE') })] }, seat.user_id)), hasSeatLimit ? _jsx(Typography, { color: "text.secondary", children: t('Billing.ERROR_SEAT_LIMIT') }) : _jsxs(Stack, { direction: "row", spacing: 1, children: [Array.isArray(seatCandidates) ? _jsxs(TextField, { select: true, SelectProps: { displayEmpty: true, SelectDisplayProps: { 'aria-label': t('Billing.SEAT_PICK'), 'aria-labelledby': undefined } }, size: "small", value: seatInput, onChange: (event) => setSeatInput(event.target.value), sx: SUBSCRIPTION_SECTION_SEAT_SELECT_SX, children: [_jsx(MenuItem, { value: "", children: t('Billing.SEAT_PICK') }), eligibleSeatCandidates.map((candidate) => _jsx(MenuItem, { value: String(candidate.id), children: _jsxs(Stack, { children: [_jsx(Typography, { children: candidate.name }), candidate.email && _jsx(Typography, { variant: "body2", color: "text.secondary", children: candidate.email })] }) }, String(candidate.id)))] }) : _jsx(TextField, { size: "small", label: t('Billing.SEAT_USER'), value: seatInput, onChange: (event) => setSeatInput(event.target.value) }), _jsx(Button, { sx: SUBSCRIPTION_SECTION_SEAT_ADD_SX, disabled: busy || (Array.isArray(seatCandidates) ? !selectedSeatCandidate : !seatInput.trim()), onClick: () => updateSeat(() => {
111
+ }) }), typeof onChoosePlan === 'function'
112
+ ? _jsx(Button, { variant: "contained", onClick: () => onChoosePlan(), children: t('Billing.CHOOSE_PLAN') })
113
+ : _jsx("div", { ref: renewalPickerRef, children: _jsx(PlanPicker, { plans: me.plans || [], api: api, redirect: redirect, allowedHosts: allowedHosts, describePlan: describePlan }) })] }) : _jsxs(_Fragment, { children: [_jsx(Typography, { variant: "h5", children: t('Billing.HEADING') }), _jsx(Typography, { children: sourceLine }), access.source !== 'free' && dateLine && _jsx(Typography, { children: dateLine }), me.subscription && typeof me.subscription === 'object' && typeof me.subscription.plan_key === 'string' && typeof me.subscription.renews === 'boolean' && formatDate(me.subscription.current_period_end, i18n.language) && _jsxs(Stack, { spacing: 0.5, children: [_jsx(Typography, { children: t('Billing.OP_PLAN', { plan: me.subscription.plan_name || me.subscription.plan_key }) }), formatDate(me.subscription.current_period_end, i18n.language) && _jsx(Typography, { children: formatDate(me.subscription.current_period_start, i18n.language) ? `${formatDate(me.subscription.current_period_start, i18n.language)} – ${formatDate(me.subscription.current_period_end, i18n.language)}` : t('Billing.OP_UNTIL', { date: formatDate(me.subscription.current_period_end, i18n.language) }) }), typeof me.subscription.renews === 'boolean' && _jsx(Typography, { children: t(me.subscription.renews ? 'Billing.OP_RENEWS' : 'Billing.OP_ENDS') })] }), access.source === 'subscription' && _jsxs(Stack, { direction: "row", spacing: 1, alignItems: "center", children: [_jsx(Button, { disabled: busy, onClick: () => safeRedirect(() => api.openPortal(), 'Billing.ERROR_PORTAL'), children: t('Billing.MANAGE') }), _jsx(Typography, { children: t('Billing.MANAGE_DETAILS') })] }), access.source === 'team' && seatError && !seats && _jsx(Alert, { severity: "error", sx: SUBSCRIPTION_SECTION_ALERT_SX, children: t('Billing.ERROR_LOAD') }), me.team && Number.isInteger(me.team.seats_used) && Number.isInteger(me.team.seats_total) && _jsxs(Stack, { spacing: 0.5, children: [_jsx(Typography, { children: t('Billing.OP_SEATS_USED', { n: formatTokens(me.team.seats_used, i18n.language), m: formatTokens(me.team.seats_total, i18n.language) }) }), (Array.isArray(me.team.seat_holders) ? me.team.seat_holders : []).map((holder) => _jsxs(Stack, { children: [_jsx(Typography, { children: holder.name || holder.email }), holder.name && _jsx(Typography, { color: "text.secondary", children: holder.email })] }, holder.user_id))] }), access.source === 'team' && seats && _jsxs(Stack, { spacing: 1, children: [_jsx(Typography, { children: t('Billing.TEAM_SEATS') }), seats.map((seat) => _jsxs(Stack, { direction: "row", spacing: 1, alignItems: "center", children: [(() => { var _a; const holder = (((_a = me.team) === null || _a === void 0 ? void 0 : _a.seat_holders) || []).find((entry) => String(entry.user_id) === String(seat.user_id)); return _jsxs(Stack, { children: [_jsx(Typography, { children: (holder === null || holder === void 0 ? void 0 : holder.name) || (holder === null || holder === void 0 ? void 0 : holder.email) || String(seat.user_id) }), (holder === null || holder === void 0 ? void 0 : holder.name) && _jsx(Typography, { color: "text.secondary", children: holder.email })] }); })(), _jsx(Button, { disabled: busy, onClick: () => updateSeat(() => api.removeSeat({ userId: seat.user_id })), children: t('Billing.SEAT_REMOVE') })] }, seat.user_id)), hasSeatLimit ? _jsx(Typography, { color: "text.secondary", children: t('Billing.ERROR_SEAT_LIMIT') }) : _jsxs(Stack, { direction: "row", spacing: 1, children: [Array.isArray(seatCandidates) ? _jsxs(TextField, { select: true, SelectProps: { displayEmpty: true, SelectDisplayProps: { 'aria-label': t('Billing.SEAT_PICK'), 'aria-labelledby': undefined } }, size: "small", value: seatInput, onChange: (event) => setSeatInput(event.target.value), sx: SUBSCRIPTION_SECTION_SEAT_SELECT_SX, children: [_jsx(MenuItem, { value: "", children: t('Billing.SEAT_PICK') }), eligibleSeatCandidates.map((candidate) => _jsx(MenuItem, { value: String(candidate.id), children: _jsxs(Stack, { children: [_jsx(Typography, { children: candidate.name }), candidate.email && _jsx(Typography, { variant: "body2", color: "text.secondary", children: candidate.email })] }) }, String(candidate.id)))] }) : _jsx(TextField, { size: "small", label: t('Billing.SEAT_USER'), value: seatInput, onChange: (event) => setSeatInput(event.target.value) }), _jsx(Button, { sx: SUBSCRIPTION_SECTION_SEAT_ADD_SX, disabled: busy || (Array.isArray(seatCandidates) ? !selectedSeatCandidate : !seatInput.trim()), onClick: () => updateSeat(() => {
111
114
  if (Array.isArray(seatCandidates)) {
112
115
  return selectedSeatCandidate ? api.addSeat({ userId: selectedSeatCandidate.id }) : undefined;
113
116
  }
@@ -18,6 +18,7 @@ export const billingTranslations = {
18
18
  'Billing.ENDED_ON': { de: 'Beendet am {{date}}', de_informal: 'Beendet am {{date}}', en: 'Ended on {{date}}', fr: 'Terminé le {{date}}', sw: 'Uliisha tarehe {{date}}' },
19
19
  'Billing.DELETION_ON': { de: 'Löschung am {{date}}', de_informal: 'Löschung am {{date}}', en: 'Deletion on {{date}}', fr: 'Suppression le {{date}}', sw: 'Kufutwa tarehe {{date}}' },
20
20
  'Billing.RENEW': { de: 'Abo erneuern', de_informal: 'Abo erneuern', en: 'Renew subscription', fr: 'Renouveler l’abonnement', sw: 'Fanya upya usajili' },
21
+ 'Billing.CHOOSE_PLAN': { de: 'Abo wählen', de_informal: 'Abo wählen', en: 'Choose a plan', fr: 'Choisir un abonnement', sw: 'Chagua usajili' },
21
22
  'Billing.MONTHLY': { de: 'Monatlich', de_informal: 'Monatlich', en: 'Monthly', fr: 'Mensuel', sw: 'Kila mwezi' },
22
23
  'Billing.YEARLY': { de: 'Jährlich', de_informal: 'Jährlich', en: 'Yearly', fr: 'Annuel', sw: 'Kila mwaka' },
23
24
  'Billing.PER_MONTH': { de: '/ Monat', de_informal: '/ Monat', en: '/ month', fr: '/ mois', sw: '/ mwezi' },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micha.bigler/ui-core-micha",
3
- "version": "4.11.0",
3
+ "version": "4.12.0",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "exports": {