)
}
interface MicroComputeUpgradeCardProps {
/** The paid plan the organization just upgraded to. */
planId: UpgradedPlanId
organizationSlug: string
/** All projects in the organization. The card picks the ones that can move to Micro. */
projects: OrgProject[]
}
/**
* Paid plans bill Nano compute at the Micro rate, so every Nano project left behind after an
* upgrade pays for resources it doesn't get. Lists those projects and upgrades each one to
* Micro in place, following it until it is back up.
*/
export const MicroComputeUpgradeCard = ({
planId,
organizationSlug,
projects,
}: MicroComputeUpgradeCardProps) => {
const track = useTrack()
const { setProjectStatus } = useSetProjectStatus()
const [upgradeRequestedRefs, setUpgradeRequestedRefs] = useState>(
() => new Set()
)
const [projectToUpgrade, setProjectToUpgrade] = useState()
const rows = getMicroUpgradeRows(projects, upgradeRequestedRefs)
const nanoProjectCount = rows.filter((row) => !row.isUpgrading).length
const isAnyProjectUpgrading = rows.some((row) => row.isUpgrading)
// Same query key as the list that feeds `projects`, so polling here refreshes the rows.
useOrgProjectsInfiniteQuery(
{ slug: organizationSlug },
{
enabled: isAnyProjectUpgrading,
refetchInterval: isAnyProjectUpgrading ? UPGRADE_POLL_INTERVAL_MS : false,
}
)
const { mutate: updateAddon, isPending: isUpdatingAddon } = useProjectAddonUpdateMutation({
onSuccess: (_data, { projectRef }) => {
if (!projectRef) return
// The project reports RESIZING on its next status poll; show it straight away.
setProjectStatus({ ref: projectRef, slug: organizationSlug, status: PROJECT_STATUS.RESIZING })
setUpgradeRequestedRefs((refs) => new Set(refs).add(projectRef))
setProjectToUpgrade(undefined)
},
})
if (rows.length === 0) return null
// `projectToUpgrade` is a snapshot from when the row was clicked. Only confirm against the
// current rows, in case the project changed size or started upgrading from another session.
const selectedRow = rows.find((row) => row.project.ref === projectToUpgrade?.ref)
const projectToConfirm = selectedRow && !selectedRow.isUpgrading ? selectedRow.project : undefined
const handleConfirmUpgrade = () => {
if (!projectToConfirm) {
setProjectToUpgrade(undefined)
return
}
track(
'plan_upgraded_micro_compute_upgrade_submitted',
{ planId, nanoProjectCount },
// The screen sits on an org page, so name the project being upgraded.
{ project: projectToConfirm.ref }
)
updateAddon({ projectRef: projectToConfirm.ref, type: 'compute_instance', variant: 'ci_micro' })
}
return (
<>
{rows.length} {pluralize(rows.length, 'project')} can upgrade to Micro Compute for no
additional costs
You're already billed at the Micro Compute rate. Upgrading just unlocks the extra
capacity.