Files
K-Dog (Kevin) 653f914ca1 feat: post plan upgrade screen (#54003)
Right now, when customers upgrade from free → paid or even pro → team,
we simply redirect to the org billing page with a quick banner that
vanishes after 3 seconds confirming the plan was changed. it’s quite
unsatisfying and feels like a missed opportunity to display what the
customer now unlocked and next steps. I want to especially highlight
projects that are now upgradeable from nano → micro, but we can later
expand and make the “next steps” smarter and do it context-based.
2026-11-25 11:30:19 +00:00

51 lines
2.1 KiB
TypeScript

import { getComputeSize, type OrgProject } from '@/data/projects/org-projects-infinite-query'
import { PROJECT_STATUS } from '@/lib/constants'
/** Paid plans that land on the post-upgrade screen. */
export type UpgradedPlanId = 'pro' | 'team'
const isActive = (project: OrgProject) => project.status === PROJECT_STATUS.ACTIVE_HEALTHY
export interface MicroUpgradeRow {
project: OrgProject
/** The project is restarting onto its new compute size. */
isUpgrading: boolean
}
/**
* Projects to list in the Micro upgrade card. Paid plans bill Nano at the Micro rate, so every
* running Nano project can move to Micro at no extra cost. A project stays listed while it
* resizes, and drops off once it is back up on Micro.
*
* @param upgradeRequestedRefs Projects upgraded from the card. They may report Micro while
* still resizing, or still report Nano from a stale response, so the Nano check alone would
* drop them too early or re-enable the button.
*/
export const getMicroUpgradeRows = (
projects: OrgProject[],
upgradeRequestedRefs: ReadonlySet<string>
): MicroUpgradeRow[] =>
projects.flatMap((project): MicroUpgradeRow[] => {
const isNano = getComputeSize(project) === 'nano'
const isRequested = upgradeRequestedRefs.has(project.ref)
const isResizing = project.status === PROJECT_STATUS.RESIZING
// A requested project stays upgrading until it is active on non-Nano compute. A stale list
// response (sent before the request) can still report it as active on Nano.
if (isRequested && (isResizing || (isActive(project) && isNano))) {
return [{ project, isUpgrading: true }]
}
if (isResizing && isNano) return [{ project, isUpgrading: true }]
if (isActive(project) && isNano) return [{ project, isUpgrading: false }]
return []
})
/**
* The project that project-scoped links should open. With exactly one running project the
* link goes straight to it; otherwise the placeholder lets the user pick one.
*/
export const getLinkProjectRef = (projects: OrgProject[]) => {
const activeProjects = projects.filter(isActive)
return activeProjects.length === 1 ? activeProjects[0].ref : '_'
}