import { MinusCircle, PauseCircle } from 'lucide-react' import { useMemo } from 'react' import { plans as subscriptionsPlans } from 'shared-data/plans' import { Modal } from 'ui' import { Admonition } from 'ui-patterns' import { getComputeSize, OrgProject } from '@/data/projects/org-projects-infinite-query' import type { OrgSubscription, ProjectAddon } from '@/data/subscriptions/types' export interface DowngradeModalProps { visible: boolean subscription?: OrgSubscription onClose: () => void onConfirm: () => void projects: OrgProject[] } const ProjectDowngradeListItem = ({ projectAddon }: { projectAddon: ProjectAddon }) => { const needsRestart = projectAddon.addons.find((addon) => addon.type === 'compute_instance') /** * We do not include Log Drains and Advanced MFA Phone 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 and MFA Phone are addons */ const relevantAddonsToList = projectAddon.addons.filter( (addon) => !['log_drain', 'auth_mfa_phone'].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 ) : ( '' )}
  • ) } const DowngradeModal = ({ visible, subscription, onClose, onConfirm, projects, }: 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' }) return (
    {((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.
    • ))}
    )}
    {subscription?.billing_via_partner === true && subscription.billing_partner === 'fly' && (

    Your organization will be downgraded at the end of your current billing cycle.

    )}
    ) } export default DowngradeModal