Files
K-Dog (Kevin) 412df7746e feat: revamped free plan limit modals / downgrade improvements (#53257)
Whenever customers run into their 2 Free Plan project limit, we were
previously just listed the affected members:

<img width="1044" height="566" alt="image"
src="https://github.com/user-attachments/assets/d1c1327d-2532-4d8e-8af2-425da9ce1ee5"
/>

While this lists the affected members, it is pretty unclear which
organizations are affected or which projects contribute to this and what
the best course of action is.

This PR revamps all components that are displayed in this situation (new
project launch, downgrade to Free, project unpause) to show the affected
organizations + projects primarily and give more actionable tips:

<img width="1014" height="638" alt="Screenshot 2026-11-11 at 3 57 45 PM
(1)"
src="https://github.com/user-attachments/assets/ae38f71d-bbde-4181-a623-24bef778afee"
/>

<img width="768" height="152" alt="image"
src="https://github.com/user-attachments/assets/b3b0efd7-678b-4ac0-9602-4cc5d735a9aa"
/>


---

Additionally, this contains small improvements to the downgrade flow:
- Rename button to "Downgrade Now" as opposed to "Confirm" to make it
more clear that this is immediate
- Explicitly mention downgrades are immediate and there is still another
invoice for unbilled usage
- Larger modal width for improved readability
2026-11-17 12:25:05 +08:00

205 lines
7.3 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { CircleDollarSignIcon, MinusCircleIcon, PauseCircleIcon, ZapIcon } from 'lucide-react'
import { useMemo } from 'react'
import { plans as subscriptionsPlans } from 'shared-data/plans'
import {
Button,
Dialog,
DialogContent,
DialogFooter,
DialogHeader,
DialogSectionSeparator,
DialogTitle,
} from 'ui'
import { Admonition } from 'ui-patterns/Admonition'
import { isBeforeFreeTierTemplateBlockCutoff } from '@/components/interfaces/Auth/EmailTemplates/EmailTemplates.utils'
import { InlineLink } from '@/components/ui/InlineLink'
import { getComputeSize, OrgProject } from '@/data/projects/org-projects-infinite-query'
import type { OrgSubscription, ProjectAddon } from '@/data/subscriptions/types'
import { DOCS_URL } from '@/lib/constants'
export interface DowngradeModalProps {
visible: boolean
subscription?: OrgSubscription
onClose: () => void
onConfirm: () => void
projects: OrgProject[]
confirmDisabled?: boolean
}
const ProjectDowngradeListItem = ({ projectAddon }: { projectAddon: ProjectAddon }) => {
const needsRestart = projectAddon.addons.find((addon) => addon.type === 'compute_instance')
/**
* We do not include Log Drains, Advanced MFA Phone, and Pipelines for the following reasons:
* 1. These addons are not removed automatically. Instead, users have to remove the respective configuration themselves
* 2. It's not obvious to users that Log Drains, MFA Phone, and Pipelines are addons
*/
const relevantAddonsToList = projectAddon.addons.filter(
(addon) => !['log_drain', 'auth_mfa_phone', 'etl_pipeline'].includes(addon.type)
)
const addonNames = relevantAddonsToList.map((addon) => {
if (addon.type === 'compute_instance') return `${addon.variant.name} Compute Instance`
return addon.variant.name
})
return (
<li>
{projectAddon.name}: {addonNames.join(', ')} will be removed.
{needsRestart ? (
<>
{' '}
Project will also <span className="font-bold">need to be restarted</span> due to change in
compute instance
</>
) : (
''
)}
</li>
)
}
export const DowngradeModal = ({
visible,
subscription,
onClose,
onConfirm,
projects,
confirmDisabled,
}: DowngradeModalProps) => {
const selectedPlan = useMemo(() => subscriptionsPlans.find((tier) => tier.id === 'tier_free'), [])
// Filter out the micro addon as we're dealing with that separately
const previousProjectAddons =
subscription?.project_addons.flatMap((projectAddons) => {
const addons = projectAddons.addons.filter((it) => it.variant.identifier !== 'ci_micro')
if (!addons.length) {
return []
} else {
return {
...projectAddons,
// Overwrite addons, filtered out the micro addon
addons,
}
}
}) || []
const hasInstancesOnMicro = projects.some((project) => {
const computeSize = getComputeSize(project)
return computeSize === 'micro'
})
// Only warn about template reset if at least one project is post-cutoff.
// Pre-cutoff projects are grandfathered and keep template editing access after downgrade.
const hasPostCutoffProjects = projects.some(
(project) => !isBeforeFreeTierTemplateBlockCutoff(project.inserted_at)
)
return (
<Dialog open={visible} onOpenChange={onClose}>
<DialogContent size="xlarge">
<DialogHeader>
<DialogTitle>Confirm to downgrade to {selectedPlan?.name} plan</DialogTitle>
</DialogHeader>
<DialogSectionSeparator />
<div className="px-5 py-4 text-foreground-light">
{((previousProjectAddons.length ?? 0) > 0 || hasInstancesOnMicro) && (
<div className="flex flex-col space-y-2">
<Admonition type="warning" title="Projects affected by the downgrade">
<ul className="!my-0 space-y-1 max-h-[100px] overflow-y-auto">
{previousProjectAddons.map((project) => (
<ProjectDowngradeListItem key={project.ref} projectAddon={project} />
))}
{projects
.filter((it) => {
const computeSize = getComputeSize(it)
return computeSize === 'micro'
})
.map((project) => (
<li key={project.ref}>
{project.name}: Compute will be downgraded. Project will also{' '}
<span className="font-bold">need to be restarted</span>.
</li>
))}
</ul>
</Admonition>
</div>
)}
{hasPostCutoffProjects && (
<Admonition
type="warning"
className="mt-2 mb-4"
title="Any custom email templates will be reset"
description="Downgrading will reset your custom email templates to their defaults. You won’t be able to edit them unless you set up custom SMTP after downgrading."
/>
)}
<ul className="flex flex-col gap-y-2 text-sm">
<li className="flex items-center gap-3">
<PauseCircleIcon size={18} />
<span>Projects will be paused after a week of inactivity</span>
</li>
<li className="flex items-center gap-3">
<MinusCircleIcon size={18} />
<span>Add ons from all projects under this organization will be removed.</span>
</li>
<li className="flex items-center gap-3">
<CircleDollarSignIcon size={18} />
<span>Any unbilled usage will be charged for in one final invoice.</span>
</li>
<li className="flex items-center gap-3 mb-2">
<ZapIcon size={18} />
<span>
Downgrades are immediate and you will receive prorated credits for unused time on
the Pro Plan.
</span>
</li>
<li className="flex gap-3">
<div className="mt-2">
<strong>Before you downgrade to the {selectedPlan?.name} plan, consider:</strong>
<ul className="space-y-2 mt-2">
<li className="list-disc ml-6 text-foreground-light">
Your projects no longer require their respective add-ons.
</li>
<li className="list-disc ml-6 text-foreground-light">
Your resource consumption are well within the {selectedPlan?.name} plan's quota.
</li>
<li className="list-disc ml-6 text-foreground-light">
Alternatively, you may also{' '}
<InlineLink href={`${DOCS_URL}/guides/platform/project-transfer`}>
transfer projects
</InlineLink>{' '}
across organizations.
</li>
</ul>
</div>
</li>
</ul>
</div>
<DialogFooter>
<Button variant={'default'} onClick={onClose}>
Cancel
</Button>
<Button
disabled={confirmDisabled ?? false}
variant="warning"
onClick={(e) => {
e.preventDefault()
onConfirm()
}}
>
Downgrade Now
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
)
}