import { LOCAL_STORAGE_KEYS, useFlag } from 'common' import { useRouter } from 'next/router' import { UseFormReturn } from 'react-hook-form' import { Badge, Button, PopoverSeparator, Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from 'ui' import { InfoTooltip } from 'ui-patterns/info-tooltip' import { CreateProjectForm } from './ProjectCreation.schema' import { instanceLabel, monthlyInstancePrice } from './ProjectCreation.utils' import { InlineLink } from '@/components/ui/InlineLink' import { DesiredInstanceSize, instanceSizeSpecs } from '@/data/projects/new-project.constants' import { OrgProject } from '@/data/projects/org-projects-infinite-query' import { useLocalStorageQuery } from '@/hooks/misc/useLocalStorage' import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization' import { DOCS_URL } from '@/lib/constants' interface ProjectCreationFooterProps { form: UseFormReturn canCreateProject: boolean instanceSize?: string organizationProjects: OrgProject[] isCreatingNewProject: boolean isSuccessNewProject: boolean } export const ProjectCreationFooter = ({ form, canCreateProject, instanceSize, organizationProjects, isCreatingNewProject, isSuccessNewProject, }: ProjectCreationFooterProps) => { const router = useRouter() const { data: currentOrg } = useSelectedOrganizationQuery() const isFreePlan = currentOrg?.plan?.id === 'free' const projectCreationDisabled = useFlag('disableProjectCreationAndUpdate') const [lastVisitedOrganization] = useLocalStorageQuery( LOCAL_STORAGE_KEYS.LAST_VISITED_ORGANIZATION, '' ) const availableComputeCredits = organizationProjects.length === 0 ? 10 : 0 const additionalMonthlySpend = isFreePlan ? 0 : instanceSizeSpecs[instanceSize as DesiredInstanceSize]!.priceMonthly - availableComputeCredits // [kevin] This will eventually all be provided by a new API endpoint to preview and validate project creation, this is just for kaizen now const monthlyComputeCosts = // current project costs organizationProjects.reduce((prev, acc) => { const primaryDatabase = acc.databases.find((db) => db.identifier === acc.ref) const cost = !!primaryDatabase ? monthlyInstancePrice(primaryDatabase.infra_compute_size) : 0 return prev + cost }, 0) + // selected compute size monthlyInstancePrice(instanceSize) - // compute credits 10 return (
{!isFreePlan && !projectCreationDisabled && canCreateProject && additionalMonthlySpend > 0 && (
Additional costs
${additionalMonthlySpend}/m

Each project includes a dedicated Postgres instance running on its own server. You are charged for the{' '} Compute resource {' '} of that server, independent of your database usage.

{monthlyComputeCosts > 0 && (

Compute costs are applied on top of your subscription plan costs.

)}
Project Compute Size Monthly Costs {organizationProjects.map((project) => { const primaryDb = project.databases.find( (db) => db.identifier === project.ref ) return ( {project.name} {instanceLabel(primaryDb?.infra_compute_size)} ${monthlyInstancePrice(primaryDb?.infra_compute_size)} ) })} {form.getValues('projectName') || 'New project'} New {instanceLabel(instanceSize)} ${monthlyInstancePrice(instanceSize)}
Compute Credits -$10 Total Monthly Compute Costs {/** * API currently doesnt output replica information on the projects list endpoint. Until then, we cannot correctly calculate the costs including RRs. * Will be adjusted in the future [kevin] */} {organizationProjects.length > 0 && (

Excluding Read replicas

)}
${monthlyComputeCosts}
)}
) }