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 (
  • {projectAddon.name}: {addonNames.join(', ')} will be removed. {needsRestart ? ( <> {' '} Project will also need to be restarted due to change in compute instance ) : ( '' )}
  • ) } 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 ( Confirm to downgrade to {selectedPlan?.name} plan
    {((previousProjectAddons.length ?? 0) > 0 || hasInstancesOnMicro) && (
      {previousProjectAddons.map((project) => ( ))} {projects .filter((it) => { const computeSize = getComputeSize(it) return computeSize === 'micro' }) .map((project) => (
    • {project.name}: Compute will be downgraded. Project will also{' '} need to be restarted.
    • ))}
    )} {hasPostCutoffProjects && ( )}
    • Projects will be paused after a week of inactivity
    • Add ons from all projects under this organization will be removed.
    • Any unbilled usage will be charged for in one final invoice.
    • Downgrades are immediate and you will receive prorated credits for unused time on the Pro Plan.
    • Before you downgrade to the {selectedPlan?.name} plan, consider:
      • Your projects no longer require their respective add-ons.
      • Your resource consumption are well within the {selectedPlan?.name} plan's quota.
      • Alternatively, you may also{' '} transfer projects {' '} across organizations.
    ) }