Merge pull request #23161 from overleaf/rh-pause-no-plan-change

Prevent downgrade to personal plan during subscription pause

GitOrigin-RevId: e3ba2e8e4d9b909fa2ee9c3c7e15db2ed257e43b
This commit is contained in:
roo hutton
2025-01-30 09:59:39 +00:00
committed by Copybot
parent 83012e0961
commit 11bc20c950
3 changed files with 30 additions and 2 deletions

View File

@@ -164,7 +164,9 @@ export function CancelSubscription() {
const showDowngrade = showDowngradeOption(
personalSubscription.plan.planCode,
personalSubscription.plan.groupPlan,
personalSubscription.recurly.trial_ends_at
personalSubscription.recurly.trial_ends_at,
personalSubscription.recurly.pausedAt,
personalSubscription.recurly.remainingPauseCycles
)
const planToDowngradeTo = plans.find(
plan => plan.planCode === planCodeToDowngradeTo

View File

@@ -1,12 +1,17 @@
import { Nullable } from '../../../../../types/utils'
import isInFreeTrial from './is-in-free-trial'
import isMonthlyCollaboratorPlan from './is-monthly-collaborator-plan'
export default function showDowngradeOption(
planCode: string,
isGroupPlan?: boolean,
trialEndsAt?: string | null
trialEndsAt?: string | null,
pausedAt?: Nullable<string>,
remainingPauseCycles?: Nullable<number>
) {
return (
!pausedAt &&
!remainingPauseCycles &&
isMonthlyCollaboratorPlan(planCode, isGroupPlan) &&
!isInFreeTrial(trialEndsAt)
)

View File

@@ -44,4 +44,25 @@ describe('showDowngradeOption', function () {
showDowngradeOption('collaborator', false, '2000-02-16T17:59:07.000Z')
).to.be.true
})
it('returns false when on a monthly collaborator plan with a pending pause', function () {
expect(
showDowngradeOption(
'collaborator',
false,
null,
'2030-01-01T12:00:00.000Z'
)
).to.be.false
})
it('returns false when on a monthly collaborator plan with an active pause', function () {
expect(
showDowngradeOption(
'collaborator',
false,
null,
'2030-01-01T12:00:00.000Z',
5
)
).to.be.false
})
})