A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
refactor(app): split subscription card, no badge for Visionary
Hampuscde8bdb88a59
diff --git a/fluxer_app/src/features/app/components/dialogs/components/plutonium/ScheduledSubscriptionChangeDescription.tsx b/fluxer_app/src/features/app/components/dialogs/components/plutonium/ScheduledSubscriptionChangeDescription.tsxnew file mode 100644index 000000000..3e05406f1--- /dev/null+++ b/fluxer_app/src/features/app/components/dialogs/components/plutonium/ScheduledSubscriptionChangeDescription.tsx@@ -0,0 +1,88 @@+// SPDX-License-Identifier: AGPL-3.0-or-later++import type {PendingSubscriptionChangeResponse} from '@fluxer/schema/src/domains/premium/PremiumSchemas';+import {Trans} from '@lingui/react/macro';+import {observer} from 'mobx-react-lite';++interface ScheduledSubscriptionChangeDescriptionProps {+ hasPendingListPriceSwitch: boolean;+ pendingTargetPriceLabel: string | null;+ pendingChangeDate: string;+ pendingSubscriptionChange: PendingSubscriptionChangeResponse;+ pendingInitialPriceLabel: string | null;+ pendingRecurringPriceLabel: string | null;+ pendingCreditPriceLabel: string | null;+}++export const ScheduledSubscriptionChangeDescription = observer(+ ({+ hasPendingListPriceSwitch,+ pendingTargetPriceLabel,+ pendingChangeDate,+ pendingSubscriptionChange,+ pendingInitialPriceLabel,+ pendingRecurringPriceLabel,+ pendingCreditPriceLabel,+ }: ScheduledSubscriptionChangeDescriptionProps) => {+ if (hasPendingListPriceSwitch) {+ if (pendingTargetPriceLabel) {+ return (+ <Trans comment="Plutonium subscription card line shown when a move to a lower price is scheduled. {pendingChangeDate} is a date and {pendingTargetPriceLabel} is a currency amount, both already formatted and localized by code; never write a date or an amount into the translation.">+ New price scheduled for{' '}+ <strong data-flx="app.plutonium.subscription-card.strong--13">{pendingChangeDate}</strong>. Renewals will be{' '}+ {pendingTargetPriceLabel} from then on.+ </Trans>+ );+ }+ return (+ <Trans comment="Plutonium subscription card line shown when a move to a lower price is scheduled but the new amount is unknown. {pendingChangeDate} is a date already formatted and localized by code; never write a date into the translation.">+ New price scheduled for{' '}+ <strong data-flx="app.plutonium.subscription-card.strong--13">{pendingChangeDate}</strong>.+ </Trans>+ );+ }+ if (pendingSubscriptionChange?.target_billing_cycle === 'yearly') {+ if (!pendingInitialPriceLabel || !pendingRecurringPriceLabel) {+ return (+ <Trans>+ Yearly upgrade scheduled for{' '}+ <strong data-flx="app.plutonium.subscription-card.strong--12">{pendingChangeDate}</strong>.+ </Trans>+ );+ }+ if (pendingCreditPriceLabel) {+ return (+ <Trans>+ Yearly upgrade scheduled for{' '}+ <strong data-flx="app.plutonium.subscription-card.strong--12">{pendingChangeDate}</strong>. First yearly+ charge: {pendingInitialPriceLabel} after a {pendingCreditPriceLabel} credit. Future yearly renewals:{' '}+ {pendingRecurringPriceLabel}/year.+ </Trans>+ );+ }+ return (+ <Trans>+ Yearly upgrade scheduled for{' '}+ <strong data-flx="app.plutonium.subscription-card.strong--12">{pendingChangeDate}</strong>. First yearly+ charge: {pendingInitialPriceLabel}. Future yearly renewals: {pendingRecurringPriceLabel}/year.+ </Trans>+ );+ }+ if (pendingInitialPriceLabel && pendingRecurringPriceLabel) {+ return (+ <Trans>+ Monthly billing starts on{' '}+ <strong data-flx="app.plutonium.subscription-card.strong--12">{pendingChangeDate}</strong>. First monthly+ charge: {pendingInitialPriceLabel}. Future monthly renewals: {pendingRecurringPriceLabel}+ /month.+ </Trans>+ );+ }+ return (+ <Trans>+ Monthly billing starts on{' '}+ <strong data-flx="app.plutonium.subscription-card.strong--12">{pendingChangeDate}</strong>.+ </Trans>+ );+ },+);diff --git a/fluxer_app/src/features/app/components/dialogs/components/plutonium/SubscriptionActions.tsx b/fluxer_app/src/features/app/components/dialogs/components/plutonium/SubscriptionActions.tsxnew file mode 100644index 000000000..4e6890c47--- /dev/null+++ b/fluxer_app/src/features/app/components/dialogs/components/plutonium/SubscriptionActions.tsx@@ -0,0 +1,333 @@+// SPDX-License-Identifier: AGPL-3.0-or-later++import type {GracePeriodInfo} from '@app/features/app/components/dialogs/components/plutonium/hooks/useSubscriptionStatus';+import styles from '@app/features/app/components/dialogs/components/plutonium/SubscriptionCard.module.css';+import {JOIN_COMMUNITY_DESCRIPTOR} from '@app/features/i18n/utils/CommonMessageDescriptors';+import {PlutoniumPageButton} from '@app/features/premium/components/plutonium_page/PlutoniumPageButton';+import {MANAGE_SUBSCRIPTION_DESCRIPTOR} from '@app/features/premium/utils/PremiumMessageDescriptors';+import {Tooltip} from '@app/features/ui/tooltip/Tooltip';+import {openExternalUrl} from '@app/features/ui/utils/NativeUtils';+import type {PendingSubscriptionChangeResponse} from '@fluxer/schema/src/domains/premium/PremiumSchemas';+import type {PremiumStoreSubscriptionState} from '@fluxer/schema/src/domains/premium/StoreBillingSchemas';+import {Trans, useLingui} from '@lingui/react/macro';+import {observer} from 'mobx-react-lite';+import type {ReactElement, ReactNode} from 'react';++interface SubscriptionActionsProps {+ storeSubscription: PremiumStoreSubscriptionState | null;+ isInGracePeriod: boolean;+ premiumWillCancel: boolean;+ isGiftSubscription: boolean;+ isGiftGrace: boolean;+ billingUnavailable: boolean;+ canSubscribe: boolean;+ purchaseDisabled: boolean;+ tooltipText: string | (() => ReactNode);+ isFullyExpired: boolean;+ hasEverPurchased: boolean;+ shouldUseReactivateQuickAction: boolean;+ loadingReactivate: boolean;+ loadingPortal: boolean;+ isVisionary: boolean;+ loadingRejoinCommunity: boolean;+ shouldUseChangePlanQuickAction: boolean;+ targetBillingCycle: 'monthly' | 'yearly' | null;+ hasPendingSubscriptionChange: boolean;+ hasPendingListPriceSwitch: boolean;+ loadingChangeBillingCycle: 'monthly' | 'yearly' | null;+ canSwitchToListPrice: boolean;+ listPriceNewLabel: string | null;+ loadingSwitchToListPrice: boolean;+ loadingCancelPendingChange: boolean;+ pendingSubscriptionChange: PendingSubscriptionChangeResponse;+ shouldUseCancelQuickAction: boolean;+ loadingCancel: boolean;+ gracePeriodInfo: GracePeriodInfo;+ loadingEndGrace: boolean;+ handleStartSubscription: () => void;+ navigateToRedeemGift: () => void;+ handleReactivateSubscription: () => void;+ handleOpenCustomerPortal: () => void;+ handleCommunityButtonClick: () => void;+ handleConfirmBillingCycleChange: (cycle: 'monthly' | 'yearly') => void;+ handleConfirmSwitchToListPrice: () => void;+ handleCancelPendingSubscriptionChange: () => void;+ handleCancelSubscription: () => void;+ handleEndPremiumGracePeriod: () => void;+}++export const SubscriptionActions = observer(+ ({+ storeSubscription,+ isInGracePeriod,+ premiumWillCancel,+ isGiftSubscription,+ isGiftGrace,+ billingUnavailable,+ canSubscribe,+ purchaseDisabled,+ tooltipText,+ isFullyExpired,+ hasEverPurchased,+ shouldUseReactivateQuickAction,+ loadingReactivate,+ loadingPortal,+ isVisionary,+ loadingRejoinCommunity,+ shouldUseChangePlanQuickAction,+ targetBillingCycle,+ hasPendingSubscriptionChange,+ hasPendingListPriceSwitch,+ loadingChangeBillingCycle,+ canSwitchToListPrice,+ listPriceNewLabel,+ loadingSwitchToListPrice,+ loadingCancelPendingChange,+ pendingSubscriptionChange,+ shouldUseCancelQuickAction,+ loadingCancel,+ gracePeriodInfo,+ loadingEndGrace,+ handleStartSubscription,+ navigateToRedeemGift,+ handleReactivateSubscription,+ handleOpenCustomerPortal,+ handleCommunityButtonClick,+ handleConfirmBillingCycleChange,+ handleConfirmSwitchToListPrice,+ handleCancelPendingSubscriptionChange,+ handleCancelSubscription,+ handleEndPremiumGracePeriod,+ }: SubscriptionActionsProps) => {+ const {i18n} = useLingui();+ const wrapIfDisabled = (element: ReactElement, {key, disabled}: {key: string; disabled: boolean}) =>+ disabled ? (+ <Tooltip key={key} text={tooltipText} data-flx="app.plutonium.subscription-card.wrap-if-disabled.tooltip">+ <div data-flx="app.plutonium.subscription-card.wrap-if-disabled.div">{element}</div>+ </Tooltip>+ ) : (+ element+ );+ if (storeSubscription) {+ return (+ <PlutoniumPageButton+ variant={isInGracePeriod || premiumWillCancel ? 'primary' : 'secondary'}+ onClick={() => void openExternalUrl(storeSubscription.manage_url)}+ small+ className={styles.actionButton}+ data-flx="app.plutonium.subscription-card.action-button.open-store-subscription"+ >+ {i18n._(MANAGE_SUBSCRIPTION_DESCRIPTOR)}+ </PlutoniumPageButton>+ );+ }+ if (isGiftSubscription || isGiftGrace || billingUnavailable) {+ return (+ <>+ {canSubscribe &&+ !billingUnavailable &&+ wrapIfDisabled(+ <PlutoniumPageButton+ variant="primary"+ onClick={handleStartSubscription}+ small+ className={styles.actionButton}+ disabled={purchaseDisabled}+ data-flx="app.plutonium.subscription-card.action-button.start-subscription"+ >+ <Trans comment="Billing button that starts a recurring subscription for someone on gifted premium time.">+ Subscribe+ </Trans>+ </PlutoniumPageButton>,+ {key: 'start-subscription', disabled: purchaseDisabled},+ )}+ {wrapIfDisabled(+ <PlutoniumPageButton+ variant={canSubscribe && !billingUnavailable ? 'secondary' : 'primary'}+ onClick={navigateToRedeemGift}+ small+ className={styles.actionButton}+ disabled={purchaseDisabled}+ data-flx="app.plutonium.subscription-card.action-button.navigate-to-redeem-gift"+ >+ <Trans comment="Billing button for entering a premium gift code.">Redeem gift code</Trans>+ </PlutoniumPageButton>,+ {key: 'redeem-gift', disabled: purchaseDisabled},+ )}+ </>+ );+ }+ let primaryAction: ReactNode = false;+ if ((isFullyExpired || isInGracePeriod) && canSubscribe) {+ primaryAction = wrapIfDisabled(+ <PlutoniumPageButton+ variant="primary"+ onClick={handleStartSubscription}+ small+ className={styles.actionButton}+ disabled={purchaseDisabled}+ data-flx="app.plutonium.subscription-card.action-button.resubscribe"+ >+ {hasEverPurchased ? (+ <Trans comment="Billing button for starting a new subscription after premium ended.">Resubscribe</Trans>+ ) : (+ <Trans comment="Billing button that starts a recurring subscription for someone on gifted premium time.">+ Subscribe+ </Trans>+ )}+ </PlutoniumPageButton>,+ {key: 'resubscribe', disabled: purchaseDisabled},+ );+ } else if (hasEverPurchased) {+ let manageLabel: ReactNode;+ if (isFullyExpired) {+ manageLabel = (+ <Trans comment="Billing button for starting a new subscription after premium expired.">Resubscribe</Trans>+ );+ } else if (isInGracePeriod) {+ manageLabel = (+ <Trans comment="Billing button for restarting a subscription during the grace period.">Resubscribe</Trans>+ );+ } else if (premiumWillCancel) {+ manageLabel = (+ <Trans comment="Billing button that cancels a scheduled subscription cancellation.">Reactivate</Trans>+ );+ } else if (isVisionary) {+ manageLabel = <Trans comment="Billing button that opens the external customer portal.">Customer portal</Trans>;+ } else {+ manageLabel = i18n._(MANAGE_SUBSCRIPTION_DESCRIPTOR);+ }+ primaryAction = wrapIfDisabled(+ <PlutoniumPageButton+ variant={isFullyExpired || isInGracePeriod || premiumWillCancel ? 'primary' : 'secondary'}+ onClick={shouldUseReactivateQuickAction ? handleReactivateSubscription : handleOpenCustomerPortal}+ loading={shouldUseReactivateQuickAction ? loadingReactivate : loadingPortal}+ small+ className={styles.actionButton}+ disabled={purchaseDisabled && shouldUseReactivateQuickAction}+ data-flx="app.plutonium.subscription-card.action-button.reactivate-subscription"+ >+ {manageLabel}+ </PlutoniumPageButton>,+ {key: 'manage-reactivate', disabled: purchaseDisabled && shouldUseReactivateQuickAction},+ );+ }+ const communityAction = isVisionary && (+ <PlutoniumPageButton+ variant="secondary"+ onClick={handleCommunityButtonClick}+ loading={loadingRejoinCommunity}+ small+ className={styles.actionButton}+ data-flx="app.plutonium.subscription-card.action-button.community-button-click"+ >+ {i18n._(JOIN_COMMUNITY_DESCRIPTOR)}+ </PlutoniumPageButton>+ );+ const changePlanAction =+ shouldUseChangePlanQuickAction &&+ targetBillingCycle &&+ !hasPendingSubscriptionChange &&+ !hasPendingListPriceSwitch &&+ wrapIfDisabled(+ <PlutoniumPageButton+ variant="secondary"+ onClick={() => handleConfirmBillingCycleChange(targetBillingCycle)}+ loading={loadingChangeBillingCycle === targetBillingCycle}+ small+ className={styles.actionButton}+ disabled={purchaseDisabled}+ data-flx="app.plutonium.subscription-card.action-button.confirm-billing-cycle-change"+ >+ {targetBillingCycle === 'yearly' ? (+ <Trans comment="Billing button that opens confirmation to switch to yearly billing.">+ Switch to yearly+ </Trans>+ ) : (+ <Trans comment="Billing button that opens confirmation to switch to monthly billing.">+ Switch to monthly+ </Trans>+ )}+ </PlutoniumPageButton>,+ {key: 'change-plan', disabled: purchaseDisabled},+ );+ const listPriceAction = canSwitchToListPrice && listPriceNewLabel && (+ <PlutoniumPageButton+ variant="secondary"+ onClick={handleConfirmSwitchToListPrice}+ loading={loadingSwitchToListPrice}+ small+ className={styles.actionButton}+ data-flx="app.plutonium.subscription-card.action-button.confirm-switch-to-list-price"+ >+ <Trans comment="Billing button that opens confirmation to move the subscription down to the current price. {listPriceNewLabel} is the localized new price.">+ Switch to {listPriceNewLabel}+ </Trans>+ </PlutoniumPageButton>+ );+ let cancelPendingAction: ReactNode = false;+ if (hasPendingSubscriptionChange || hasPendingListPriceSwitch) {+ let cancelLabel: ReactNode;+ if (hasPendingListPriceSwitch) {+ cancelLabel = (+ <Trans comment="Billing button that cancels a scheduled move to a lower subscription price.">+ Cancel price change+ </Trans>+ );+ } else if (pendingSubscriptionChange?.target_billing_cycle === 'yearly') {+ cancelLabel = (+ <Trans comment="Billing button that cancels a scheduled yearly upgrade.">Cancel yearly upgrade</Trans>+ );+ } else {+ cancelLabel = (+ <Trans comment="Billing button that cancels a scheduled billing-cycle change.">Cancel scheduled switch</Trans>+ );+ }+ cancelPendingAction = (+ <PlutoniumPageButton+ variant="secondary"+ onClick={handleCancelPendingSubscriptionChange}+ loading={loadingCancelPendingChange}+ small+ className={styles.actionButton}+ data-flx="app.plutonium.subscription-card.action-button.cancel-pending-subscription-change"+ >+ {cancelLabel}+ </PlutoniumPageButton>+ );+ }+ return (+ <>+ {primaryAction}+ {communityAction}+ {changePlanAction}+ {listPriceAction}+ {cancelPendingAction}+ {shouldUseCancelQuickAction && (+ <PlutoniumPageButton+ variant="danger"+ onClick={handleCancelSubscription}+ loading={loadingCancel}+ small+ className={styles.actionButton}+ data-flx="app.plutonium.subscription-card.action-button.cancel-subscription"+ >+ <Trans comment="Billing button that starts subscription cancellation.">Cancel subscription</Trans>+ </PlutoniumPageButton>+ )}+ {isInGracePeriod && !gracePeriodInfo.isPaymentRecovery && (+ <PlutoniumPageButton+ variant="danger"+ onClick={handleEndPremiumGracePeriod}+ loading={loadingEndGrace}+ small+ className={styles.actionButton}+ data-flx="app.plutonium.subscription-card.action-button.end-premium-grace-period"+ >+ <Trans comment="Billing button that ends premium grace period immediately.">End grace now</Trans>+ </PlutoniumPageButton>+ )}+ </>+ );+ },+);diff --git a/fluxer_app/src/features/app/components/dialogs/components/plutonium/SubscriptionBillingChangeDescription.tsx b/fluxer_app/src/features/app/components/dialogs/components/plutonium/SubscriptionBillingChangeDescription.tsxnew file mode 100644index 000000000..b950fb44c--- /dev/null+++ b/fluxer_app/src/features/app/components/dialogs/components/plutonium/SubscriptionBillingChangeDescription.tsx@@ -0,0 +1,75 @@+// SPDX-License-Identifier: AGPL-3.0-or-later++import {PAYMENT_PROVIDER_NAME} from '@app/features/app/config/I18nDisplayConstants';+import {Trans} from '@lingui/react/macro';++interface SubscriptionBillingChangeDescriptionProps {+ effectiveAt: 'now' | 'period_end';+ isSwitchingToYearly: boolean;+ firstRenewalPriceLabel: string | null;+ creditLabel: string | null;+ renewalPrice: string;+}++export function SubscriptionBillingChangeDescription({+ effectiveAt,+ isSwitchingToYearly,+ firstRenewalPriceLabel,+ creditLabel,+ renewalPrice,+}: SubscriptionBillingChangeDescriptionProps) {+ if (effectiveAt === 'period_end') {+ if (isSwitchingToYearly && firstRenewalPriceLabel && creditLabel) {+ return (+ <Trans>+ Takes effect at your next renewal. We'll apply a {creditLabel} credit from your current monthly payment, so+ your first yearly charge will be{' '}+ <strong data-flx="app.plutonium.subscription-card.handle-confirm-billing-cycle-change.strong">+ {firstRenewalPriceLabel}+ </strong>+ . Future yearly renewals will be {renewalPrice}/year.+ </Trans>+ );+ }+ if (isSwitchingToYearly) {+ return (+ <Trans>+ Takes effect at your next renewal. Your subscription stays monthly until then, and your next renewal will be{' '}+ <strong data-flx="app.plutonium.subscription-card.handle-confirm-billing-cycle-change.strong">+ {renewalPrice}/year+ </strong>+ .+ </Trans>+ );+ }+ return (+ <Trans>+ Takes effect at your next renewal. Your subscription stays yearly until then, and your next renewal will be{' '}+ <strong data-flx="app.plutonium.subscription-card.handle-confirm-billing-cycle-change.strong--2">+ {renewalPrice}/month+ </strong>+ .+ </Trans>+ );+ }+ if (isSwitchingToYearly) {+ return (+ <Trans>+ Takes effect immediately. A prorated charge may apply via {PAYMENT_PROVIDER_NAME}. Your next renewal will be{' '}+ <strong data-flx="app.plutonium.subscription-card.handle-confirm-billing-cycle-change.strong">+ {renewalPrice}/year+ </strong>+ .+ </Trans>+ );+ }+ return (+ <Trans>+ Takes effect immediately. A prorated adjustment may apply via {PAYMENT_PROVIDER_NAME}. Your next renewal will be{' '}+ <strong data-flx="app.plutonium.subscription-card.handle-confirm-billing-cycle-change.strong--2">+ {renewalPrice}/month+ </strong>+ .+ </Trans>+ );+}diff --git a/fluxer_app/src/features/app/components/dialogs/components/plutonium/SubscriptionCard.tsx b/fluxer_app/src/features/app/components/dialogs/components/plutonium/SubscriptionCard.tsxindex 66e89e13d..bd2427424 100644--- a/fluxer_app/src/features/app/components/dialogs/components/plutonium/SubscriptionCard.tsx+++ b/fluxer_app/src/features/app/components/dialogs/components/plutonium/SubscriptionCard.tsx@@ -1,28 +1,25 @@// SPDX-License-Identifier: AGPL-3.0-or-laterimport {ConfirmModal} from '@app/features/app/components/dialogs/ConfirmModal';-import {PerksButton} from '@app/features/app/components/dialogs/components/PerksButton';import {useSubscriptionActions} from '@app/features/app/components/dialogs/components/plutonium/hooks/useSubscriptionActions';import type {GracePeriodInfo} from '@app/features/app/components/dialogs/components/plutonium/hooks/useSubscriptionStatus';-import statusStyles from '@app/features/app/components/dialogs/components/plutonium/PurchaseHistoryStatus.module.css';+import {ScheduledSubscriptionChangeDescription} from '@app/features/app/components/dialogs/components/plutonium/ScheduledSubscriptionChangeDescription';+import {SubscriptionActions} from '@app/features/app/components/dialogs/components/plutonium/SubscriptionActions';+import {SubscriptionBillingChangeDescription} from '@app/features/app/components/dialogs/components/plutonium/SubscriptionBillingChangeDescription';import styles from '@app/features/app/components/dialogs/components/plutonium/SubscriptionCard.module.css';-import {PAYMENT_PROVIDER_NAME} from '@app/features/app/config/I18nDisplayConstants';-import {JOIN_COMMUNITY_DESCRIPTOR} from '@app/features/i18n/utils/CommonMessageDescriptors';+import {SubscriptionDescription} from '@app/features/app/components/dialogs/components/plutonium/SubscriptionDescription';+import {SubscriptionStatusBadge} from '@app/features/app/components/dialogs/components/plutonium/SubscriptionStatusBadge';import PremiumState from '@app/features/premium/state/PremiumState';import {CLAIM_ACCOUNT_TO_PURCHASE_OR_REDEEM_PREMIUM_DESCRIPTOR,- MANAGE_SUBSCRIPTION_DESCRIPTOR,PREMIUM_SUBSCRIPTION_DESCRIPTOR,} from '@app/features/premium/utils/PremiumMessageDescriptors';-import {getPremiumProductFullName, getPremiumProductName, getStoreName} from '@app/features/premium/utils/PremiumUtils';-import {formatMinorUnitPrice} from '@app/features/premium/utils/PricingUtils';-import {Button} from '@app/features/ui/button/Button';+import {getPremiumProductFullName, getPremiumProductName} from '@app/features/premium/utils/PremiumUtils';import * as ModalCommands from '@app/features/ui/commands/ModalCommands';import {modal} from '@app/features/ui/commands/ModalCommands';-import {Tooltip} from '@app/features/ui/tooltip/Tooltip';-import {openExternalUrl} from '@app/features/ui/utils/NativeUtils';import Users from '@app/features/user/state/Users';import {getFormattedLongDate} from '@fluxer/date_utils/src/DateFormatting';+import {formatMinorUnitPrice} from '@fluxer/number_utils/src/PriceFormatting';import type {PendingSubscriptionChangeResponse} from '@fluxer/schema/src/domains/premium/PremiumSchemas';import type {PremiumStoreSubscriptionState} from '@fluxer/schema/src/domains/premium/StoreBillingSchemas';import {msg} from '@lingui/core/macro';@@ -79,6 +76,7 @@ interface SubscriptionCardProps {canSubscribe: boolean;storeSubscription: PremiumStoreSubscriptionState | null;premiumUntil: Date | null;+ renewsAt: Date | null;billingCycle: string | null;monthlyPrice: string;yearlyPrice: string;@@ -122,25 +120,6 @@ interface SubscriptionCardProps {billingUnavailable?: boolean;}-function getStatusBadgeClass(args: {- isFullyExpired: boolean;- isInGracePeriod: boolean;- perksDisabled: boolean;- premiumWillCancel: boolean;- hasPendingSubscriptionChange: boolean;- isVisionary: boolean;- isGiftSubscription: boolean;-}): string {- if (args.isFullyExpired) return statusStyles.danger;- if (args.isInGracePeriod) return statusStyles.pending;- if (args.perksDisabled) return statusStyles.muted;- if (args.premiumWillCancel) return statusStyles.pending;- if (args.hasPendingSubscriptionChange) return statusStyles.pending;- if (args.isVisionary) return statusStyles.neutral;- if (args.isGiftSubscription) return statusStyles.neutral;- return statusStyles.success;-}-export const SubscriptionCard: React.FC<SubscriptionCardProps> = observer(({locale,@@ -151,6 +130,7 @@ export const SubscriptionCard: React.FC<SubscriptionCardProps> = observer(canSubscribe,storeSubscription,premiumUntil,+ renewsAt,billingCycle,monthlyPrice,yearlyPrice,@@ -199,7 +179,12 @@ export const SubscriptionCard: React.FC<SubscriptionCardProps> = observer(: i18n._(CLAIM_ACCOUNT_TO_PURCHASE_OR_REDEEM_PREMIUM_DESCRIPTOR, {premiumProductFullName: getPremiumProductFullName(),});- const targetBillingCycle = billingCycle === 'monthly' ? 'yearly' : billingCycle === 'yearly' ? 'monthly' : null;+ let targetBillingCycle: 'monthly' | 'yearly' | null = null;+ if (billingCycle === 'monthly') {+ targetBillingCycle = 'yearly';+ } else if (billingCycle === 'yearly') {+ targetBillingCycle = 'monthly';+ }const effectiveMonthlyPrice =billingCycle === 'monthly' && currentSubscriptionPriceLabel ? currentSubscriptionPriceLabel : monthlyPrice;const effectiveYearlyPrice =@@ -210,33 +195,46 @@ export const SubscriptionCard: React.FC<SubscriptionCardProps> = observer(!storeSubscription && currentUserId != null && PremiumState.loadedForUserId === currentUserId? (PremiumState.state?.billing.list_price_switch ?? null): null;+ const countryCode = PremiumState.state?.pricing.country_code;const listPriceNewLabel = listPriceSwitch- ? formatMinorUnitPrice(listPriceSwitch.list_amount_minor, listPriceSwitch.currency, locale)+ ? formatMinorUnitPrice(listPriceSwitch.list_amount_minor, listPriceSwitch.currency, locale, countryCode): null;const listPriceCurrentLabel = listPriceSwitch- ? formatMinorUnitPrice(listPriceSwitch.current_amount_minor, listPriceSwitch.currency, locale)+ ? formatMinorUnitPrice(listPriceSwitch.current_amount_minor, listPriceSwitch.currency, locale, countryCode): null;const listPriceEffectiveDate = listPriceSwitch?.effective_at? getFormattedLongDate(listPriceSwitch.effective_at, locale): null;const hasPendingListPriceSwitch = listPriceSwitch?.pending === true && !premiumWillCancel;- const pendingChangeDate = pendingSubscriptionChange- ? getFormattedLongDate(new Date(pendingSubscriptionChange.effective_at), locale)- : hasPendingListPriceSwitch- ? listPriceEffectiveDate- : null;+ let pendingChangeDate: string | null = null;+ if (pendingSubscriptionChange) {+ pendingChangeDate = getFormattedLongDate(new Date(pendingSubscriptionChange.effective_at), locale);+ } else if (hasPendingListPriceSwitch) {+ pendingChangeDate = listPriceEffectiveDate;+ }const pendingInitialPriceLabel = pendingSubscriptionChange- ? formatMinorUnitPrice(pendingSubscriptionChange.initial_amount_minor, pendingSubscriptionChange.currency, locale)+ ? formatMinorUnitPrice(+ pendingSubscriptionChange.initial_amount_minor,+ pendingSubscriptionChange.currency,+ locale,+ countryCode,+ ): null;const pendingRecurringPriceLabel = pendingSubscriptionChange? formatMinorUnitPrice(pendingSubscriptionChange.recurring_amount_minor,pendingSubscriptionChange.currency,locale,+ countryCode,): null;const pendingCreditPriceLabel = pendingSubscriptionChange- ? formatMinorUnitPrice(pendingSubscriptionChange.credit_amount_minor, pendingSubscriptionChange.currency, locale)+ ? formatMinorUnitPrice(+ pendingSubscriptionChange.credit_amount_minor,+ pendingSubscriptionChange.currency,+ locale,+ countryCode,+ ): null;const canSwitchToListPrice =listPriceSwitch?.available === true &&@@ -280,11 +278,16 @@ export const SubscriptionCard: React.FC<SubscriptionCardProps> = observer(: null;const firstRenewalPriceLabel =firstInvoiceCreditAmountMinor != null && targetAmountMinor != null- ? formatMinorUnitPrice(targetAmountMinor - firstInvoiceCreditAmountMinor, priceCurrency, locale)+ ? formatMinorUnitPrice(+ targetAmountMinor - firstInvoiceCreditAmountMinor,+ priceCurrency,+ locale,+ countryCode,+ ): null;const creditLabel =firstInvoiceCreditAmountMinor != null- ? formatMinorUnitPrice(firstInvoiceCreditAmountMinor, priceCurrency, locale)+ ? formatMinorUnitPrice(firstInvoiceCreditAmountMinor, priceCurrency, locale, countryCode): null;ModalCommands.push(modal(() => (@@ -295,54 +298,14 @@ export const SubscriptionCard: React.FC<SubscriptionCardProps> = observer(: i18n._(SWITCH_TO_MONTHLY_BILLING_DESCRIPTOR)}description={- effectiveAt === 'period_end' ? (- isSwitchingToYearly && firstRenewalPriceLabel && creditLabel ? (- <Trans>- Takes effect at your next renewal. We'll apply a {creditLabel} credit from your current monthly- payment, so your first yearly charge will be{' '}- <strong data-flx="app.plutonium.subscription-card.handle-confirm-billing-cycle-change.strong">- {firstRenewalPriceLabel}- </strong>- . Future yearly renewals will be {renewalPrice}/year.- </Trans>- ) : isSwitchingToYearly ? (- <Trans>- Takes effect at your next renewal. Your subscription stays monthly until then, and your next- renewal will be{' '}- <strong data-flx="app.plutonium.subscription-card.handle-confirm-billing-cycle-change.strong">- {renewalPrice}/year- </strong>- .- </Trans>- ) : (- <Trans>- Takes effect at your next renewal. Your subscription stays yearly until then, and your next- renewal will be{' '}- <strong data-flx="app.plutonium.subscription-card.handle-confirm-billing-cycle-change.strong--2">- {renewalPrice}/month- </strong>- .- </Trans>- )- ) : isSwitchingToYearly ? (- <Trans>- Takes effect immediately. A prorated charge may apply via {PAYMENT_PROVIDER_NAME}. Your next renewal- will be{' '}- <strong data-flx="app.plutonium.subscription-card.handle-confirm-billing-cycle-change.strong">- {renewalPrice}/year- </strong>- .- </Trans>- ) : (- <Trans>- Takes effect immediately. A prorated adjustment may apply via {PAYMENT_PROVIDER_NAME}. Your next- renewal will be{' '}- <strong data-flx="app.plutonium.subscription-card.handle-confirm-billing-cycle-change.strong--2">- {renewalPrice}/month- </strong>- .- </Trans>- )+ <SubscriptionBillingChangeDescription+ effectiveAt={effectiveAt}+ isSwitchingToYearly={isSwitchingToYearly}+ firstRenewalPriceLabel={firstRenewalPriceLabel}+ creditLabel={creditLabel}+ renewalPrice={renewalPrice}+ data-flx="app.plutonium.subscription-card.handle-confirm-billing-cycle-change.subscription-billing-change-description"+ />}primaryText={isSwitchingToYearly ? i18n._(SWITCH_TO_YEARLY_DESCRIPTOR) : i18n._(SWITCH_TO_MONTHLY_DESCRIPTOR)@@ -359,6 +322,7 @@ export const SubscriptionCard: React.FC<SubscriptionCardProps> = observer(},[billingCycle,+ countryCode,currentSubscriptionAmountMinor,currentSubscriptionCurrency,effectiveMonthlyPrice,@@ -398,23 +362,7 @@ export const SubscriptionCard: React.FC<SubscriptionCardProps> = observer()),);}, [handleSwitchToListPrice, i18n, listPriceCurrentLabel, listPriceEffectiveDate, listPriceNewLabel]);- const wrapIfDisabled = (element: React.ReactElement, key: string, disabled: boolean) =>- disabled ? (- <Tooltip key={key} text={tooltipText} data-flx="app.plutonium.subscription-card.wrap-if-disabled.tooltip">- <div data-flx="app.plutonium.subscription-card.wrap-if-disabled.div">{element}</div>- </Tooltip>- ) : (- element- );- const badgeClass = getStatusBadgeClass({- isFullyExpired,- isInGracePeriod,- perksDisabled,- premiumWillCancel,- hasPendingSubscriptionChange,- isVisionary,- isGiftSubscription,- });+return (<div className={styles.card} data-flx="app.plutonium.subscription-card.card"><div className={styles.grid} data-flx="app.plutonium.subscription-card.grid">@@ -427,228 +375,39 @@ export const SubscriptionCard: React.FC<SubscriptionCardProps> = observer(i18n._(PREMIUM_SUBSCRIPTION_DESCRIPTOR, {premiumProductName: getPremiumProductName()}))}</h3>- <span className={badgeClass} data-flx="app.plutonium.subscription-card.badge">- {isFullyExpired ? (- <Trans comment="Subscription status badge meaning premium access has fully expired.">Expired</Trans>- ) : isInGracePeriod ? (- <Trans comment="Subscription status badge meaning access remains briefly after subscription end.">- Grace period- </Trans>- ) : perksDisabled ? (- <Trans comment="Subscription status badge meaning premium is paid but perks are temporarily disabled.">- Perks paused- </Trans>- ) : premiumWillCancel ? (- <Trans comment="Subscription status badge meaning cancellation is scheduled for the renewal date.">- Canceling- </Trans>- ) : hasPendingSubscriptionChange ? (- <Trans comment="Subscription status badge meaning a future billing plan change is scheduled.">- Change scheduled- </Trans>- ) : isVisionary ? (- <Trans comment="Subscription status badge meaning permanent premium access.">Lifetime</Trans>- ) : isGiftSubscription ? (- <Trans comment="Subscription status badge meaning premium access came from a gift.">Gift</Trans>- ) : (- <Trans comment="Subscription status badge meaning the paid subscription is active.">Active</Trans>- )}- </span>+ <SubscriptionStatusBadge+ isFullyExpired={isFullyExpired}+ isInGracePeriod={isInGracePeriod}+ perksDisabled={perksDisabled}+ premiumWillCancel={premiumWillCancel}+ hasPendingSubscriptionChange={hasPendingSubscriptionChange}+ isVisionary={isVisionary}+ isGiftSubscription={isGiftSubscription}+ data-flx="app.plutonium.subscription-card.subscription-status-badge"+ /></div><div className={styles.description} data-flx="app.plutonium.subscription-card.description">- {isFullyExpired ? (- (() => {- const expiredDate = graceEndDate ? getFormattedLongDate(graceEndDate, locale) : undefined;- return (- <Trans>- Expired on <strong data-flx="app.plutonium.subscription-card.strong">{expiredDate}</strong>.{' '}- <PerksButton- onClick={scrollToPerks}- data-flx="app.plutonium.subscription-card.perks-button.scroll-to-perks"- />{' '}- are no longer active. You can resubscribe at any time.- </Trans>- );- })()- ) : storeSubscription && gracePeriodInfo.isPaymentRecovery ? (- (() => {- const graceDate = graceEndDate ? getFormattedLongDate(graceEndDate, locale) : undefined;- const storeName = getStoreName(storeSubscription.provider);- return (- <Trans comment="Plutonium subscription card text shown while a failed App Store or Google Play renewal payment is being retried. {storeName} is the store brand name, App Store or Google Play, and must not be translated. {graceDate} is a date already formatted and localized by code; never write a date into the translation.">- Your {storeName} renewal payment failed but{' '}- <PerksButton- onClick={scrollToPerks}- data-flx="app.plutonium.subscription-card.perks-button.scroll-to-perks--10"- />{' '}- stay active until{' '}- <strong data-flx="app.plutonium.subscription-card.strong--17">{graceDate}</strong>. Update your{' '}- {storeName} payment method before then to keep your subscription.- </Trans>- );- })()- ) : gracePeriodInfo.isPaymentRecovery ? (- (() => {- const graceDate = graceEndDate ? getFormattedLongDate(graceEndDate, locale) : undefined;- return (- <Trans comment="Plutonium subscription card text shown while a failed renewal payment is being retried. {graceDate} is a date already formatted and localized by code; never write a date into the translation.">- Your renewal payment failed but{' '}- <PerksButton- onClick={scrollToPerks}- data-flx="app.plutonium.subscription-card.perks-button.scroll-to-perks--9"- />{' '}- stay active until{' '}- <strong data-flx="app.plutonium.subscription-card.strong--16">{graceDate}</strong>. Update your- payment method before then to keep your subscription.- </Trans>- );- })()- ) : isGiftGrace ? (- (() => {- const graceDate = graceEndDate ? getFormattedLongDate(graceEndDate, locale) : undefined;- return (- <Trans comment="Plutonium subscription card text shown in the short grace period after gifted premium time ends. {graceDate} is a date already formatted and localized by code; never write a date into the translation.">- Your gift time ended but{' '}- <PerksButton- onClick={scrollToPerks}- data-flx="app.plutonium.subscription-card.perks-button.scroll-to-perks--11"- />{' '}- stay active until{' '}- <strong data-flx="app.plutonium.subscription-card.strong--19">{graceDate}</strong>. Subscribe- before then to keep them.- </Trans>- );- })()- ) : isInGracePeriod ? (- (() => {- const graceDate = graceEndDate ? getFormattedLongDate(graceEndDate, locale) : undefined;- return (- <Trans>- Your subscription ended but{' '}- <PerksButton- onClick={scrollToPerks}- data-flx="app.plutonium.subscription-card.perks-button.scroll-to-perks--2"- />{' '}- stay active until{' '}- <strong data-flx="app.plutonium.subscription-card.strong--2">{graceDate}</strong>. Resubscribe- before then to keep your subscriber history.- </Trans>- );- })()- ) : storeSubscription && premiumWillCancel && premiumUntil ? (- (() => {- const storeName = getStoreName(storeSubscription.provider);- const endDate = getFormattedLongDate(premiumUntil, locale);- return (- <Trans comment="Plutonium subscription card text for an App Store or Google Play subscription that will not renew. {storeName} is the store brand name, App Store or Google Play, and must not be translated. {endDate} is a date already formatted and localized by code; never write a date into the translation.">- Billed through {storeName}. Ends on{' '}- <strong data-flx="app.plutonium.subscription-card.strong--18">{endDate}</strong>.- </Trans>- );- })()- ) : storeSubscription ? (- (() => {- const storeName = getStoreName(storeSubscription.provider);- return (- <Trans comment="Plutonium subscription card text for an App Store or Google Play subscription. {storeName} is the store brand name, App Store or Google Play, and must not be translated.">- Billed through {storeName}.- </Trans>- );- })()- ) : isGiftSubscription ? (- (() => {- const giftEndDate = premiumUntil ? getFormattedLongDate(premiumUntil, locale) : undefined;- return (- <Trans>- Gifted{' '}- <PerksButton- onClick={scrollToPerks}- data-flx="app.plutonium.subscription-card.perks-button.scroll-to-perks--3"- />{' '}- until <strong data-flx="app.plutonium.subscription-card.strong--5">{giftEndDate}</strong>. Does- not renew automatically. Redeem more gift codes to extend.- </Trans>- );- })()- ) : premiumWillCancel && premiumUntil ? (- (() => {- const cancelDate = getFormattedLongDate(premiumUntil, locale);- return (- <Trans>- Cancels on <strong data-flx="app.plutonium.subscription-card.strong--8">{cancelDate}</strong>.{' '}- <PerksButton- onClick={scrollToPerks}- data-flx="app.plutonium.subscription-card.perks-button.scroll-to-perks--4"- />{' '}- remain active until then.- </Trans>- );- })()- ) : perksDisabled ? (- <Trans>Your subscription is active but perks are temporarily paused.</Trans>- ) : isVisionary ? (- <Trans>- All{' '}- <PerksButton- onClick={scrollToPerks}- data-flx="app.plutonium.subscription-card.perks-button.scroll-to-perks--5"- />- , forever. No billing, no renewals.- </Trans>- ) : billingCycle === 'monthly' ? (- <>- <Trans>- All{' '}- <PerksButton- onClick={scrollToPerks}- data-flx="app.plutonium.subscription-card.perks-button.scroll-to-perks--6"- />{' '}- for{' '}- <strong data-flx="app.plutonium.subscription-card.strong--9">{effectiveMonthlyPrice}/month</strong>.- </Trans>- {isCurrentSubscriptionGrandfathered && (- <Tooltip text={grandfatheredTooltip} data-flx="app.plutonium.subscription-card.tooltip">- <span- className={styles.legacyRateBadge}- data-flx="app.plutonium.subscription-card.legacy-rate-badge"- >- <Trans>Legacy rate</Trans>- </span>- </Tooltip>- )}- </>- ) : billingCycle === 'yearly' ? (- <>- <Trans>- All{' '}- <PerksButton- onClick={scrollToPerks}- data-flx="app.plutonium.subscription-card.perks-button.scroll-to-perks--7"- />{' '}- for{' '}- <strong data-flx="app.plutonium.subscription-card.strong--10">{effectiveYearlyPrice}/year</strong>.- </Trans>- {isCurrentSubscriptionGrandfathered && (- <Tooltip text={grandfatheredTooltip} data-flx="app.plutonium.subscription-card.tooltip--2">- <span- className={styles.legacyRateBadge}- data-flx="app.plutonium.subscription-card.legacy-rate-badge--2"- >- <Trans>Legacy rate</Trans>- </span>- </Tooltip>- )}- </>- ) : (- <Trans>- All{' '}- <PerksButton- onClick={scrollToPerks}- data-flx="app.plutonium.subscription-card.perks-button.scroll-to-perks--8"- />{' '}- included with your subscription.- </Trans>- )}+ <SubscriptionDescription+ locale={locale}+ isFullyExpired={isFullyExpired}+ isInGracePeriod={isInGracePeriod}+ graceEndDate={graceEndDate}+ gracePeriodInfo={gracePeriodInfo}+ isGiftGrace={isGiftGrace}+ storeSubscription={storeSubscription}+ premiumWillCancel={premiumWillCancel}+ premiumUntil={premiumUntil}+ isGiftSubscription={isGiftSubscription}+ perksDisabled={perksDisabled}+ isVisionary={isVisionary}+ billingCycle={billingCycle}+ effectiveMonthlyPrice={effectiveMonthlyPrice}+ effectiveYearlyPrice={effectiveYearlyPrice}+ isCurrentSubscriptionGrandfathered={isCurrentSubscriptionGrandfathered}+ grandfatheredTooltip={grandfatheredTooltip}+ scrollToPerks={scrollToPerks}+ data-flx="app.plutonium.subscription-card.subscription-description"+ /></div>{!isVisionary &&(hasPendingSubscriptionChange || hasPendingListPriceSwitch) &&@@ -660,55 +419,16 @@ export const SubscriptionCard: React.FC<SubscriptionCardProps> = observer(className={styles.pendingChangeInfo}data-flx="app.plutonium.subscription-card.pending-change-info">- {hasPendingListPriceSwitch ? (- pendingTargetPriceLabel ? (- <Trans comment="Plutonium subscription card line shown when a move to a lower price is scheduled. {pendingChangeDate} is a date and {pendingTargetPriceLabel} is a currency amount, both already formatted and localized by code; never write a date or an amount into the translation.">- New price scheduled for{' '}- <strong data-flx="app.plutonium.subscription-card.strong--13">{pendingChangeDate}</strong>.- Renewals will be {pendingTargetPriceLabel} from then on.- </Trans>- ) : (- <Trans comment="Plutonium subscription card line shown when a move to a lower price is scheduled but the new amount is unknown. {pendingChangeDate} is a date already formatted and localized by code; never write a date into the translation.">- New price scheduled for{' '}- <strong data-flx="app.plutonium.subscription-card.strong--13">{pendingChangeDate}</strong>.- </Trans>- )- ) : pendingSubscriptionChange?.target_billing_cycle === 'yearly' ? (- pendingInitialPriceLabel && pendingRecurringPriceLabel ? (- pendingCreditPriceLabel ? (- <Trans>- Yearly upgrade scheduled for{' '}- <strong data-flx="app.plutonium.subscription-card.strong--12">{pendingChangeDate}</strong>.- First yearly charge: {pendingInitialPriceLabel} after a {pendingCreditPriceLabel} credit.- Future yearly renewals: {pendingRecurringPriceLabel}/year.- </Trans>- ) : (- <Trans>- Yearly upgrade scheduled for{' '}- <strong data-flx="app.plutonium.subscription-card.strong--12">{pendingChangeDate}</strong>.- First yearly charge: {pendingInitialPriceLabel}. Future yearly renewals:{' '}- {pendingRecurringPriceLabel}/year.- </Trans>- )- ) : (- <Trans>- Yearly upgrade scheduled for{' '}- <strong data-flx="app.plutonium.subscription-card.strong--12">{pendingChangeDate}</strong>.- </Trans>- )- ) : pendingInitialPriceLabel && pendingRecurringPriceLabel ? (- <Trans>- Monthly billing starts on{' '}- <strong data-flx="app.plutonium.subscription-card.strong--12">{pendingChangeDate}</strong>. First- monthly charge: {pendingInitialPriceLabel}. Future monthly renewals: {pendingRecurringPriceLabel}- /month.- </Trans>- ) : (- <Trans>- Monthly billing starts on{' '}- <strong data-flx="app.plutonium.subscription-card.strong--12">{pendingChangeDate}</strong>.- </Trans>- )}+ <ScheduledSubscriptionChangeDescription+ hasPendingListPriceSwitch={hasPendingListPriceSwitch}+ pendingTargetPriceLabel={pendingTargetPriceLabel}+ pendingChangeDate={pendingChangeDate}+ pendingSubscriptionChange={pendingSubscriptionChange}+ pendingInitialPriceLabel={pendingInitialPriceLabel}+ pendingRecurringPriceLabel={pendingRecurringPriceLabel}+ pendingCreditPriceLabel={pendingCreditPriceLabel}+ data-flx="app.plutonium.subscription-card.scheduled-subscription-change-description"+ /></div>)}{!isVisionary &&@@ -765,16 +485,13 @@ export const SubscriptionCard: React.FC<SubscriptionCardProps> = observer(</div>)}{!isVisionary &&- premiumUntil &&+ renewsAt &&!premiumWillCancel &&!isInGracePeriod &&!isFullyExpired &&!isGiftSubscription &&(() => {- const renewalDate = getFormattedLongDate(- storeSubscription ? new Date(storeSubscription.expires_at) : premiumUntil,- locale,- );+ const renewalDate = getFormattedLongDate(renewsAt, locale);return (<div className={styles.renewalInfo} data-flx="app.plutonium.subscription-card.renewal-info"><Trans>@@ -785,215 +502,49 @@ export const SubscriptionCard: React.FC<SubscriptionCardProps> = observer(})()}</div><div className={styles.actions} data-flx="app.plutonium.subscription-card.actions">- {storeSubscription ? (- <Button- variant={isInGracePeriod || premiumWillCancel ? 'primary' : 'secondary'}- onClick={() => void openExternalUrl(storeSubscription.manage_url)}- small- className={styles.actionButton}- data-flx="app.plutonium.subscription-card.action-button.open-store-subscription"- >- {i18n._(MANAGE_SUBSCRIPTION_DESCRIPTOR)}- </Button>- ) : isGiftSubscription || isGiftGrace || billingUnavailable ? (- <>- {canSubscribe &&- !billingUnavailable &&- wrapIfDisabled(- <Button- variant="primary"- onClick={handleStartSubscription}- small- className={styles.actionButton}- disabled={purchaseDisabled}- data-flx="app.plutonium.subscription-card.action-button.start-subscription"- >- <Trans comment="Billing button that starts a recurring subscription for someone on gifted premium time.">- Subscribe- </Trans>- </Button>,- 'start-subscription',- purchaseDisabled,- )}- {wrapIfDisabled(- <Button- variant={canSubscribe && !billingUnavailable ? 'secondary' : 'primary'}- onClick={navigateToRedeemGift}- small- className={styles.actionButton}- disabled={purchaseDisabled}- data-flx="app.plutonium.subscription-card.action-button.navigate-to-redeem-gift"- >- <Trans comment="Billing button for entering a premium gift code.">Redeem gift code</Trans>- </Button>,- 'redeem-gift',- purchaseDisabled,- )}- </>- ) : (- <>- {(isFullyExpired || isInGracePeriod) && canSubscribe- ? wrapIfDisabled(- <Button- variant="primary"- onClick={handleStartSubscription}- small- className={styles.actionButton}- disabled={purchaseDisabled}- data-flx="app.plutonium.subscription-card.action-button.resubscribe"- >- {hasEverPurchased ? (- <Trans comment="Billing button for starting a new subscription after premium ended.">- Resubscribe- </Trans>- ) : (- <Trans comment="Billing button that starts a recurring subscription for someone on gifted premium time.">- Subscribe- </Trans>- )}- </Button>,- 'resubscribe',- purchaseDisabled,- )- : hasEverPurchased &&- wrapIfDisabled(- <Button- variant={isFullyExpired || isInGracePeriod || premiumWillCancel ? 'primary' : 'secondary'}- onClick={- shouldUseReactivateQuickAction ? handleReactivateSubscription : handleOpenCustomerPortal- }- submitting={shouldUseReactivateQuickAction ? loadingReactivate : loadingPortal}- small- className={styles.actionButton}- disabled={purchaseDisabled && shouldUseReactivateQuickAction}- data-flx="app.plutonium.subscription-card.action-button.reactivate-subscription"- >- {isFullyExpired ? (- <Trans comment="Billing button for starting a new subscription after premium expired.">- Resubscribe- </Trans>- ) : isInGracePeriod ? (- <Trans comment="Billing button for restarting a subscription during the grace period.">- Resubscribe- </Trans>- ) : premiumWillCancel ? (- <Trans comment="Billing button that cancels a scheduled subscription cancellation.">- Reactivate- </Trans>- ) : isVisionary ? (- <Trans comment="Billing button that opens the external customer portal.">- Customer portal- </Trans>- ) : (- i18n._(MANAGE_SUBSCRIPTION_DESCRIPTOR)- )}- </Button>,- 'manage-reactivate',- purchaseDisabled && shouldUseReactivateQuickAction,- )}- {isVisionary && (- <Button- variant="secondary"- onClick={handleCommunityButtonClick}- submitting={loadingRejoinCommunity}- small- className={styles.actionButton}- data-flx="app.plutonium.subscription-card.action-button.community-button-click"- >- {i18n._(JOIN_COMMUNITY_DESCRIPTOR)}- </Button>- )}- {shouldUseChangePlanQuickAction &&- targetBillingCycle &&- !hasPendingSubscriptionChange &&- !hasPendingListPriceSwitch &&- wrapIfDisabled(- <Button- variant="secondary"- onClick={() => handleConfirmBillingCycleChange(targetBillingCycle)}- submitting={loadingChangeBillingCycle === targetBillingCycle}- small- className={styles.actionButton}- disabled={purchaseDisabled}- data-flx="app.plutonium.subscription-card.action-button.confirm-billing-cycle-change"- >- {targetBillingCycle === 'yearly' ? (- <Trans comment="Billing button that opens confirmation to switch to yearly billing.">- Switch to yearly- </Trans>- ) : (- <Trans comment="Billing button that opens confirmation to switch to monthly billing.">- Switch to monthly- </Trans>- )}- </Button>,- 'change-plan',- purchaseDisabled,- )}- {canSwitchToListPrice && listPriceNewLabel && (- <Button- variant="secondary"- onClick={handleConfirmSwitchToListPrice}- submitting={loadingSwitchToListPrice}- small- className={styles.actionButton}- data-flx="app.plutonium.subscription-card.action-button.confirm-switch-to-list-price"- >- <Trans comment="Billing button that opens confirmation to move the subscription down to the current price. {listPriceNewLabel} is the localized new price.">- Switch to {listPriceNewLabel}- </Trans>- </Button>- )}- {(hasPendingSubscriptionChange || hasPendingListPriceSwitch) && (- <Button- variant="secondary"- onClick={handleCancelPendingSubscriptionChange}- submitting={loadingCancelPendingChange}- small- className={styles.actionButton}- data-flx="app.plutonium.subscription-card.action-button.cancel-pending-subscription-change"- >- {hasPendingListPriceSwitch ? (- <Trans comment="Billing button that cancels a scheduled move to a lower subscription price.">- Cancel price change- </Trans>- ) : pendingSubscriptionChange?.target_billing_cycle === 'yearly' ? (- <Trans comment="Billing button that cancels a scheduled yearly upgrade.">- Cancel yearly upgrade- </Trans>- ) : (- <Trans comment="Billing button that cancels a scheduled billing-cycle change.">- Cancel scheduled switch- </Trans>- )}- </Button>- )}- {shouldUseCancelQuickAction && (- <Button- variant="danger"- onClick={handleCancelSubscription}- submitting={loadingCancel}- small- className={styles.actionButton}- data-flx="app.plutonium.subscription-card.action-button.cancel-subscription"- >- <Trans comment="Billing button that starts subscription cancellation.">Cancel subscription</Trans>- </Button>- )}- {isInGracePeriod && !gracePeriodInfo.isPaymentRecovery && (- <Button- variant="danger"- onClick={handleEndPremiumGracePeriod}- submitting={loadingEndGrace}- small- className={styles.actionButton}- data-flx="app.plutonium.subscription-card.action-button.end-premium-grace-period"- >- <Trans comment="Billing button that ends premium grace period immediately.">End grace now</Trans>- </Button>- )}- </>- )}+ <SubscriptionActions+ storeSubscription={storeSubscription}+ isInGracePeriod={isInGracePeriod}+ premiumWillCancel={premiumWillCancel}+ isGiftSubscription={isGiftSubscription}+ isGiftGrace={isGiftGrace}+ billingUnavailable={billingUnavailable}+ canSubscribe={canSubscribe}+ purchaseDisabled={purchaseDisabled}+ tooltipText={tooltipText}+ isFullyExpired={isFullyExpired}+ hasEverPurchased={hasEverPurchased}+ shouldUseReactivateQuickAction={shouldUseReactivateQuickAction}+ loadingReactivate={loadingReactivate}+ loadingPortal={loadingPortal}+ isVisionary={isVisionary}+ loadingRejoinCommunity={loadingRejoinCommunity}+ shouldUseChangePlanQuickAction={shouldUseChangePlanQuickAction}+ targetBillingCycle={targetBillingCycle}+ hasPendingSubscriptionChange={hasPendingSubscriptionChange}+ hasPendingListPriceSwitch={hasPendingListPriceSwitch}+ loadingChangeBillingCycle={loadingChangeBillingCycle}+ canSwitchToListPrice={canSwitchToListPrice}+ listPriceNewLabel={listPriceNewLabel}+ loadingSwitchToListPrice={loadingSwitchToListPrice}+ loadingCancelPendingChange={loadingCancelPendingChange}+ pendingSubscriptionChange={pendingSubscriptionChange}+ shouldUseCancelQuickAction={shouldUseCancelQuickAction}+ loadingCancel={loadingCancel}+ gracePeriodInfo={gracePeriodInfo}+ loadingEndGrace={loadingEndGrace}+ handleStartSubscription={handleStartSubscription}+ navigateToRedeemGift={navigateToRedeemGift}+ handleReactivateSubscription={handleReactivateSubscription}+ handleOpenCustomerPortal={handleOpenCustomerPortal}+ handleCommunityButtonClick={handleCommunityButtonClick}+ handleConfirmBillingCycleChange={handleConfirmBillingCycleChange}+ handleConfirmSwitchToListPrice={handleConfirmSwitchToListPrice}+ handleCancelPendingSubscriptionChange={handleCancelPendingSubscriptionChange}+ handleCancelSubscription={handleCancelSubscription}+ handleEndPremiumGracePeriod={handleEndPremiumGracePeriod}+ data-flx="app.plutonium.subscription-card.subscription-actions"+ /></div></div></div>diff --git a/fluxer_app/src/features/app/components/dialogs/components/plutonium/SubscriptionDescription.tsx b/fluxer_app/src/features/app/components/dialogs/components/plutonium/SubscriptionDescription.tsxnew file mode 100644index 000000000..687ed4551--- /dev/null+++ b/fluxer_app/src/features/app/components/dialogs/components/plutonium/SubscriptionDescription.tsx@@ -0,0 +1,238 @@+// SPDX-License-Identifier: AGPL-3.0-or-later++import {PerksButton} from '@app/features/app/components/dialogs/components/PerksButton';+import type {GracePeriodInfo} from '@app/features/app/components/dialogs/components/plutonium/hooks/useSubscriptionStatus';+import styles from '@app/features/app/components/dialogs/components/plutonium/SubscriptionCard.module.css';+import {getStoreName} from '@app/features/premium/utils/PremiumUtils';+import {Tooltip} from '@app/features/ui/tooltip/Tooltip';+import {getFormattedLongDate} from '@fluxer/date_utils/src/DateFormatting';+import type {PremiumStoreSubscriptionState} from '@fluxer/schema/src/domains/premium/StoreBillingSchemas';+import {Trans} from '@lingui/react/macro';+import {observer} from 'mobx-react-lite';++interface SubscriptionDescriptionProps {+ locale: string;+ isFullyExpired: boolean;+ isInGracePeriod: boolean;+ graceEndDate: Date | null;+ gracePeriodInfo: GracePeriodInfo;+ isGiftGrace: boolean;+ storeSubscription: PremiumStoreSubscriptionState | null;+ premiumWillCancel: boolean;+ premiumUntil: Date | null;+ isGiftSubscription: boolean;+ perksDisabled: boolean;+ isVisionary: boolean;+ billingCycle: string | null;+ effectiveMonthlyPrice: string;+ effectiveYearlyPrice: string;+ isCurrentSubscriptionGrandfathered: boolean;+ grandfatheredTooltip: string;+ scrollToPerks: () => void;+}++export const SubscriptionDescription = observer(+ ({+ locale,+ isFullyExpired,+ isInGracePeriod,+ graceEndDate,+ gracePeriodInfo,+ isGiftGrace,+ storeSubscription,+ premiumWillCancel,+ premiumUntil,+ isGiftSubscription,+ perksDisabled,+ isVisionary,+ billingCycle,+ effectiveMonthlyPrice,+ effectiveYearlyPrice,+ isCurrentSubscriptionGrandfathered,+ grandfatheredTooltip,+ scrollToPerks,+ }: SubscriptionDescriptionProps) => {+ if (isFullyExpired) {+ const expiredDate = graceEndDate ? getFormattedLongDate(graceEndDate, locale) : undefined;+ return (+ <Trans>+ Expired on <strong data-flx="app.plutonium.subscription-card.strong">{expiredDate}</strong>.{' '}+ <PerksButton+ onClick={scrollToPerks}+ data-flx="app.plutonium.subscription-card.perks-button.scroll-to-perks"+ />{' '}+ are no longer active. You can resubscribe at any time.+ </Trans>+ );+ }+ if (storeSubscription && gracePeriodInfo.isPaymentRecovery) {+ const graceDate = graceEndDate ? getFormattedLongDate(graceEndDate, locale) : undefined;+ const storeName = getStoreName(storeSubscription.provider);+ return (+ <Trans comment="Plutonium subscription card text shown while a failed App Store or Google Play renewal payment is being retried. {storeName} is the store brand name, App Store or Google Play, and must not be translated. {graceDate} is a date already formatted and localized by code; never write a date into the translation.">+ Your {storeName} renewal payment failed but{' '}+ <PerksButton+ onClick={scrollToPerks}+ data-flx="app.plutonium.subscription-card.perks-button.scroll-to-perks--10"+ />{' '}+ stay active until <strong data-flx="app.plutonium.subscription-card.strong--17">{graceDate}</strong>. Update+ your {storeName} payment method before then to keep your subscription.+ </Trans>+ );+ }+ if (gracePeriodInfo.isPaymentRecovery) {+ const graceDate = graceEndDate ? getFormattedLongDate(graceEndDate, locale) : undefined;+ return (+ <Trans comment="Plutonium subscription card text shown while a failed renewal payment is being retried. {graceDate} is a date already formatted and localized by code; never write a date into the translation.">+ Your renewal payment failed but{' '}+ <PerksButton+ onClick={scrollToPerks}+ data-flx="app.plutonium.subscription-card.perks-button.scroll-to-perks--9"+ />{' '}+ stay active until <strong data-flx="app.plutonium.subscription-card.strong--16">{graceDate}</strong>. Update+ your payment method before then to keep your subscription.+ </Trans>+ );+ }+ if (isGiftGrace) {+ const graceDate = graceEndDate ? getFormattedLongDate(graceEndDate, locale) : undefined;+ return (+ <Trans comment="Plutonium subscription card text shown in the short grace period after gifted premium time ends. {graceDate} is a date already formatted and localized by code; never write a date into the translation.">+ Your gift time ended but{' '}+ <PerksButton+ onClick={scrollToPerks}+ data-flx="app.plutonium.subscription-card.perks-button.scroll-to-perks--11"+ />{' '}+ stay active until <strong data-flx="app.plutonium.subscription-card.strong--19">{graceDate}</strong>.+ Subscribe before then to keep them.+ </Trans>+ );+ }+ if (isInGracePeriod) {+ const graceDate = graceEndDate ? getFormattedLongDate(graceEndDate, locale) : undefined;+ return (+ <Trans>+ Your subscription ended but{' '}+ <PerksButton+ onClick={scrollToPerks}+ data-flx="app.plutonium.subscription-card.perks-button.scroll-to-perks--2"+ />{' '}+ stay active until <strong data-flx="app.plutonium.subscription-card.strong--2">{graceDate}</strong>.+ Resubscribe before then to keep your subscriber history.+ </Trans>+ );+ }+ if (storeSubscription && premiumWillCancel && premiumUntil) {+ const storeName = getStoreName(storeSubscription.provider);+ const endDate = getFormattedLongDate(premiumUntil, locale);+ return (+ <Trans comment="Plutonium subscription card text for an App Store or Google Play subscription that will not renew. {storeName} is the store brand name, App Store or Google Play, and must not be translated. {endDate} is a date already formatted and localized by code; never write a date into the translation.">+ Billed through {storeName}. Ends on{' '}+ <strong data-flx="app.plutonium.subscription-card.strong--18">{endDate}</strong>.+ </Trans>+ );+ }+ if (storeSubscription) {+ const storeName = getStoreName(storeSubscription.provider);+ return (+ <Trans comment="Plutonium subscription card text for an App Store or Google Play subscription. {storeName} is the store brand name, App Store or Google Play, and must not be translated.">+ Billed through {storeName}.+ </Trans>+ );+ }+ if (isGiftSubscription) {+ const giftEndDate = premiumUntil ? getFormattedLongDate(premiumUntil, locale) : undefined;+ return (+ <Trans>+ Gifted{' '}+ <PerksButton+ onClick={scrollToPerks}+ data-flx="app.plutonium.subscription-card.perks-button.scroll-to-perks--3"+ />{' '}+ until <strong data-flx="app.plutonium.subscription-card.strong--5">{giftEndDate}</strong>. Does not renew+ automatically. Redeem more gift codes to extend.+ </Trans>+ );+ }+ if (premiumWillCancel && premiumUntil) {+ const cancelDate = getFormattedLongDate(premiumUntil, locale);+ return (+ <Trans>+ Cancels on <strong data-flx="app.plutonium.subscription-card.strong--8">{cancelDate}</strong>.{' '}+ <PerksButton+ onClick={scrollToPerks}+ data-flx="app.plutonium.subscription-card.perks-button.scroll-to-perks--4"+ />{' '}+ remain active until then.+ </Trans>+ );+ }+ if (perksDisabled) {+ return <Trans>Your subscription is active but perks are temporarily paused.</Trans>;+ }+ if (isVisionary) {+ return (+ <Trans>+ All{' '}+ <PerksButton+ onClick={scrollToPerks}+ data-flx="app.plutonium.subscription-card.perks-button.scroll-to-perks--5"+ />+ , forever. No billing, no renewals.+ </Trans>+ );+ }+ if (billingCycle === 'monthly') {+ return (+ <>+ <Trans>+ All{' '}+ <PerksButton+ onClick={scrollToPerks}+ data-flx="app.plutonium.subscription-card.perks-button.scroll-to-perks--6"+ />{' '}+ for <strong data-flx="app.plutonium.subscription-card.strong--9">{effectiveMonthlyPrice}/month</strong>.+ </Trans>+ {isCurrentSubscriptionGrandfathered && (+ <Tooltip text={grandfatheredTooltip} data-flx="app.plutonium.subscription-card.tooltip">+ <span className={styles.legacyRateBadge} data-flx="app.plutonium.subscription-card.legacy-rate-badge">+ <Trans>Legacy rate</Trans>+ </span>+ </Tooltip>+ )}+ </>+ );+ }+ if (billingCycle === 'yearly') {+ return (+ <>+ <Trans>+ All{' '}+ <PerksButton+ onClick={scrollToPerks}+ data-flx="app.plutonium.subscription-card.perks-button.scroll-to-perks--7"+ />{' '}+ for <strong data-flx="app.plutonium.subscription-card.strong--10">{effectiveYearlyPrice}/year</strong>.+ </Trans>+ {isCurrentSubscriptionGrandfathered && (+ <Tooltip text={grandfatheredTooltip} data-flx="app.plutonium.subscription-card.tooltip--2">+ <span className={styles.legacyRateBadge} data-flx="app.plutonium.subscription-card.legacy-rate-badge--2">+ <Trans>Legacy rate</Trans>+ </span>+ </Tooltip>+ )}+ </>+ );+ }+ return (+ <Trans>+ All{' '}+ <PerksButton+ onClick={scrollToPerks}+ data-flx="app.plutonium.subscription-card.perks-button.scroll-to-perks--8"+ />{' '}+ included with your subscription.+ </Trans>+ );+ },+);diff --git a/fluxer_app/src/features/app/components/dialogs/components/plutonium/SubscriptionStatusBadge.tsx b/fluxer_app/src/features/app/components/dialogs/components/plutonium/SubscriptionStatusBadge.tsxnew file mode 100644index 000000000..8c001e304--- /dev/null+++ b/fluxer_app/src/features/app/components/dialogs/components/plutonium/SubscriptionStatusBadge.tsx@@ -0,0 +1,74 @@+// SPDX-License-Identifier: AGPL-3.0-or-later++import statusStyles from '@app/features/app/components/dialogs/components/plutonium/PurchaseHistoryStatus.module.css';+import {Trans} from '@lingui/react/macro';+import type {ReactNode} from 'react';++interface SubscriptionStatusBadgeProps {+ isFullyExpired: boolean;+ isInGracePeriod: boolean;+ perksDisabled: boolean;+ premiumWillCancel: boolean;+ hasPendingSubscriptionChange: boolean;+ isVisionary: boolean;+ isGiftSubscription: boolean;+}++export function SubscriptionStatusBadge({+ isFullyExpired,+ isInGracePeriod,+ perksDisabled,+ premiumWillCancel,+ hasPendingSubscriptionChange,+ isVisionary,+ isGiftSubscription,+}: SubscriptionStatusBadgeProps) {+ let className: string;+ let label: ReactNode;+ if (isFullyExpired) {+ className = statusStyles.danger;+ label = <Trans comment="Subscription status badge meaning premium access has fully expired.">Expired</Trans>;+ } else if (isInGracePeriod) {+ className = statusStyles.pending;+ label = (+ <Trans comment="Subscription status badge meaning access remains briefly after subscription end.">+ Grace period+ </Trans>+ );+ } else if (perksDisabled) {+ className = statusStyles.muted;+ label = (+ <Trans comment="Subscription status badge meaning premium is paid but perks are temporarily disabled.">+ Perks paused+ </Trans>+ );+ } else if (premiumWillCancel) {+ className = statusStyles.pending;+ label = (+ <Trans comment="Subscription status badge meaning cancellation is scheduled for the renewal date.">+ Canceling+ </Trans>+ );+ } else if (hasPendingSubscriptionChange) {+ className = statusStyles.pending;+ label = (+ <Trans comment="Subscription status badge meaning a future billing plan change is scheduled.">+ Change scheduled+ </Trans>+ );+ } else if (isVisionary) {+ return null;+ } else if (isGiftSubscription) {+ className = statusStyles.neutral;+ label = <Trans comment="Subscription status badge meaning premium access came from a gift.">Gift</Trans>;+ } else {+ className = statusStyles.success;+ label = <Trans comment="Subscription status badge meaning the paid subscription is active.">Active</Trans>;+ }++ return (+ <span className={className} data-flx="app.plutonium.subscription-card.badge">+ {label}+ </span>+ );+}