mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 14:13:43 +01:00
[web] Add cancel-loss-messaging split test (#36363)
* [web] Add cancel-loss-messaging split test Populate the cancel confirmation step with plan-specific losses when the cancel-loss-messaging split test is enabled: "Are you sure you want to cancel?" heading, the subscription end date, and a card listing what the user loses moving to the Free plan (compile timeout, AI, collaborators, history), with the lost benefit struck through next to its Free-plan replacement. Shown only to non-trial Student/Standard/Pro individual subscribers with no other retention offer (trial extension or downgrade upsell) — those keep the existing confirmation. Copy matches the mockups in the ticket. No new analytics events; the existing subscription-page-cancel-button-click / subscription-cancelled funnel is used. Part of #35765 * [web] Consolidate ActiveSubscription stories, add cancel confirmation story Replace the 13 fixture-per-story exports with a single Dashboard story driven by controls (subscription fixture select, flexible licensing, cancel-loss-messaging variant), using the CSF factories pattern. Add a CancelConfirmation story that renders the cancel confirmation step directly so the cancel-loss-messaging variant can be previewed without clicking through, with a Professional fixture available to see the Pro loss rows. * [web] Use withSplitTests for the ActiveSubscription stories Register cancel-loss-messaging in defaultSplitTestsArgTypes and drive the stories' variant from the shared withSplitTests decorator (radio control, SplitTestContext provided from args) instead of hand-rolled meta tags and SplitTestProvider. Generalize withSplitTests' typing so it composes with CSF factories (preview.meta) as well as legacy meta objects. * [web] Fix Storybook indexing of the ActiveSubscription stories Storybook's static CSF indexer requires preview.meta() to receive an object literal, so spread withSplitTests' argTypes/decorators into the meta literal instead of wrapping the whole config in the helper call. * [web] Compose ActiveSubscription stories from orthogonal controls - Wrap the stories in #subscription-dashboard-root so the dashboard's scoped styles (e.g. the cancel-loss strikethrough) apply in Storybook - Replace the single fixture dropdown with independent controls (group, plan, period, currency, trial, status, pending plan change, add-ons, coupons, pending license change), building the subscription from the fixtures' base + patches - Guard impossible mixes with argTypes `if` conditions: individual-only controls hide when group is on, and pendingLicenseChange only shows for groups * [web] Add student plan to the ActiveSubscription story controls The cancel-loss-messaging variant has student-specific rows (AI Assistant / 10 collaborators), so the plan control needs a student option. Groups have no student plans, so for group subscriptions the student choice maps to the Standard group fixture. * [web] Provide ol-plans in the ActiveSubscription stories The cancel confirmation's downgrade branch (monthly Standard is isEligibleForDowngradeUpsell) looks up paid-personal in ol-plans and spins forever when the meta tag is missing. Provide ol-plans and ol-groupPlans from the fixtures, matching the test render helper. GitOrigin-RevId: e8491c8d39ed059e42ea3442e8d70c3ef304b009
This commit is contained in:
+122
@@ -0,0 +1,122 @@
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { TFunction } from 'i18next'
|
||||
import MaterialIcon from '@/shared/components/material-icon'
|
||||
import OLButton from '@/shared/components/ol/ol-button'
|
||||
import { useSubscriptionDashboardContext } from '../../../../../context/subscription-dashboard-context'
|
||||
|
||||
export type LossMessagingPlanType = 'student' | 'collaborator' | 'professional'
|
||||
|
||||
export function getLossMessagingPlanType(
|
||||
planCode: string
|
||||
): LossMessagingPlanType | null {
|
||||
if (planCode.startsWith('professional')) return 'professional'
|
||||
if (planCode.startsWith('collaborator')) return 'collaborator'
|
||||
if (planCode.startsWith('student')) return 'student'
|
||||
return null
|
||||
}
|
||||
|
||||
type LossRow = { lost: string; replacement: string }
|
||||
|
||||
function getAiLossRow(planType: LossMessagingPlanType, t: TFunction): LossRow {
|
||||
if (planType === 'student') {
|
||||
return { lost: t('ai_assistant'), replacement: t('no_ai_assistant') }
|
||||
}
|
||||
if (planType === 'collaborator') {
|
||||
return {
|
||||
lost: t('ai_assistant_and_higher_ai_allowance'),
|
||||
replacement: t('small_ai_allowance_no_assistant'),
|
||||
}
|
||||
}
|
||||
return {
|
||||
lost: t('ai_assistant_and_max_ai_allowance'),
|
||||
replacement: t('small_ai_allowance_no_assistant'),
|
||||
}
|
||||
}
|
||||
|
||||
function getCollaboratorsLossRow(
|
||||
planType: LossMessagingPlanType,
|
||||
t: TFunction
|
||||
): LossRow {
|
||||
return {
|
||||
lost:
|
||||
planType === 'professional'
|
||||
? t('unlimited_collaborators_per_project')
|
||||
: t('ten_collaborators_per_project'),
|
||||
replacement: t('one_collaborator_per_project'),
|
||||
}
|
||||
}
|
||||
|
||||
function getLossRows(planType: LossMessagingPlanType, t: TFunction): LossRow[] {
|
||||
return [
|
||||
{
|
||||
lost: t('plan_24x_longer_compile_timeout'),
|
||||
replacement: t('basic_compile_timeout_for_small_projects'),
|
||||
},
|
||||
getAiLossRow(planType, t),
|
||||
getCollaboratorsLossRow(planType, t),
|
||||
{
|
||||
lost: t('full_project_history'),
|
||||
replacement: t('history_24_hours_only'),
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
export function CancelSubscriptionLossMessaging({
|
||||
planType,
|
||||
terminationDate,
|
||||
onCancelSubscription,
|
||||
isButtonDisabled,
|
||||
isCancelLoading,
|
||||
}: {
|
||||
planType: LossMessagingPlanType
|
||||
terminationDate: string
|
||||
onCancelSubscription: () => void
|
||||
isButtonDisabled: boolean
|
||||
isCancelLoading: boolean
|
||||
}) {
|
||||
const { t } = useTranslation()
|
||||
const { setShowCancellation } = useSubscriptionDashboardContext()
|
||||
|
||||
return (
|
||||
<div className="cancel-loss-messaging">
|
||||
<h2>{t('are_you_sure_you_want_to_cancel')}</h2>
|
||||
<p>
|
||||
{t('cancelling_will_end_your_subscription_on', { terminationDate })}
|
||||
</p>
|
||||
<div className="cancel-loss-card">
|
||||
<h3 className="cancel-loss-card-heading">
|
||||
{t('youll_be_moved_to_the_free_plan')}
|
||||
</h3>
|
||||
<ul className="cancel-loss-list">
|
||||
{getLossRows(planType, t).map(row => (
|
||||
<li key={row.lost} className="cancel-loss-list-item">
|
||||
<MaterialIcon type="cancel" className="cancel-loss-icon" />
|
||||
<span>
|
||||
<del className="cancel-loss-lost">{row.lost}</del>{' '}
|
||||
{row.replacement}
|
||||
</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
<div className="cancel-loss-actions">
|
||||
<OLButton
|
||||
variant="secondary"
|
||||
disabled={isButtonDisabled}
|
||||
onClick={() => setShowCancellation(false)}
|
||||
>
|
||||
{t('keep_subscription')}
|
||||
</OLButton>
|
||||
<OLButton
|
||||
variant="danger-ghost"
|
||||
disabled={isButtonDisabled}
|
||||
isLoading={isCancelLoading}
|
||||
loadingLabel={t('processing_uppercase') + '…'}
|
||||
onClick={onCancelSubscription}
|
||||
>
|
||||
{t('cancel_subscription')}
|
||||
</OLButton>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
+35
@@ -14,6 +14,12 @@ import ExtendTrialButton from './extend-trial-button'
|
||||
import { useLocation } from '../../../../../../../shared/hooks/use-location'
|
||||
import { debugConsole } from '@/utils/debugging'
|
||||
import OLButton from '@/shared/components/ol/ol-button'
|
||||
import { useFeatureFlag } from '@/shared/context/split-test-context'
|
||||
import isInFreeTrial from '../../../../../util/is-in-free-trial'
|
||||
import {
|
||||
CancelSubscriptionLossMessaging,
|
||||
getLossMessagingPlanType,
|
||||
} from './cancel-subscription-loss-messaging'
|
||||
|
||||
const planCodeToDowngradeTo = 'paid-personal'
|
||||
|
||||
@@ -136,6 +142,7 @@ export function CancelSubscription() {
|
||||
const location = useLocation()
|
||||
const { personalSubscription, plans, userCanExtendTrial } =
|
||||
useSubscriptionDashboardContext()
|
||||
const lossMessagingEnabled = useFeatureFlag('cancel-loss-messaging')
|
||||
const {
|
||||
isLoading: isLoadingCancel,
|
||||
isError: isErrorCancel,
|
||||
@@ -176,6 +183,34 @@ export function CancelSubscription() {
|
||||
|
||||
const showExtendFreeTrial = userCanExtendTrial
|
||||
|
||||
// `cancel-loss-messaging` split test: show plan-specific losses instead of
|
||||
// the bare confirmation, for non-trial individual subscribers with no other
|
||||
// retention offer (trial extension or downgrade)
|
||||
const lossMessagingPlanType = getLossMessagingPlanType(
|
||||
personalSubscription.planCode
|
||||
)
|
||||
const showLossMessaging =
|
||||
lossMessagingEnabled &&
|
||||
!showExtendFreeTrial &&
|
||||
!showDowngrade &&
|
||||
lossMessagingPlanType !== null &&
|
||||
!isInFreeTrial(personalSubscription.payment.trialEndsAt)
|
||||
|
||||
if (showLossMessaging) {
|
||||
return (
|
||||
<>
|
||||
{isErrorCancel && <GenericErrorAlert />}
|
||||
<CancelSubscriptionLossMessaging
|
||||
planType={lossMessagingPlanType}
|
||||
terminationDate={personalSubscription.payment.nextPaymentDueDate}
|
||||
onCancelSubscription={handleCancelSubscription}
|
||||
isButtonDisabled={isButtonDisabled}
|
||||
isCancelLoading={isSuccessCancel || isLoadingCancel}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="text-center">
|
||||
|
||||
Reference in New Issue
Block a user