Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Break down new project page into smaller components (#39812)

Joshen Lim6e2a7feee70d
diff --git a/apps/studio/components/interfaces/Organization/NewProject/FreeProjectLimitWarning.tsx b/apps/studio/components/interfaces/Organization/NewProject/FreeProjectLimitWarning.tsx
deleted file mode 100644
index 4aa43e5937c..00000000000
--- a/apps/studio/components/interfaces/Organization/NewProject/FreeProjectLimitWarning.tsx
+++ /dev/null
@@ -1,38 +0,0 @@
-import { UpgradePlanButton } from 'components/ui/UpgradePlanButton'
-import type { MemberWithFreeProjectLimit } from 'data/organizations/free-project-limit-check-query'
-import { Admonition } from 'ui-patterns/admonition'
-
-interface FreeProjectLimitWarningProps {
- membersExceededLimit: MemberWithFreeProjectLimit[]
-}
-
-export const FreeProjectLimitWarning = ({ membersExceededLimit }: FreeProjectLimitWarningProps) => {
- return (
- <Admonition
- type={'default'}
- title={'The organization has members who have exceeded their free project limits'}
- description={
- <div className="space-y-3">
- <p className="text-sm leading-normal">
- The following members have reached their maximum limits for the number of active free
- plan projects within organizations where they are an administrator or owner:
- </p>
- <ul className="pl-5 list-disc">
- {membersExceededLimit.map((member, idx: number) => (
- <li key={`member-${idx}`}>
- {member.username || member.primary_email} (Limit: {member.free_project_limit} free
- projects)
- </li>
- ))}
- </ul>
- <p className="text-sm leading-normal">
- These members will need to either delete, pause, or upgrade one or more of these
- projects before you're able to create a free project within this organization.
- </p>
-
- <UpgradePlanButton source="freeProjectLimitWarning">Upgrade plan</UpgradePlanButton>
- </div>
- }
- />
- )
-}
diff --git a/apps/studio/components/interfaces/Organization/NewProject/index.ts b/apps/studio/components/interfaces/Organization/NewProject/index.ts
deleted file mode 100644
index a52ded23d6b..00000000000
--- a/apps/studio/components/interfaces/Organization/NewProject/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export { default as NotOrganizationOwnerWarning } from './NotOrganizationOwnerWarning'
diff --git a/apps/studio/components/interfaces/ProjectCreation/AdvancedConfiguration.tsx b/apps/studio/components/interfaces/ProjectCreation/AdvancedConfiguration.tsx
index 9ed6663b7c9..18b4d4c5eb0 100644
--- a/apps/studio/components/interfaces/ProjectCreation/AdvancedConfiguration.tsx
+++ b/apps/studio/components/interfaces/ProjectCreation/AdvancedConfiguration.tsx
@@ -4,7 +4,6 @@ import { UseFormReturn } from 'react-hook-form'
import { DocsButton } from 'components/ui/DocsButton'
import Panel from 'components/ui/Panel'
import { DOCS_URL } from 'lib/constants'
-import { CreateProjectForm } from 'pages/new/[slug]'
import {
Badge,
cn,
@@ -19,6 +18,7 @@ import {
} from 'ui'
import { Admonition } from 'ui-patterns'
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
+import { CreateProjectForm } from './ProjectCreation.schema'
interface AdvancedConfigurationProps {
form: UseFormReturn<CreateProjectForm>
diff --git a/apps/studio/components/interfaces/ProjectCreation/CloudProviderSelector.tsx b/apps/studio/components/interfaces/ProjectCreation/CloudProviderSelector.tsx
new file mode 100644
index 00000000000..92e6f70ea57
--- /dev/null
+++ b/apps/studio/components/interfaces/ProjectCreation/CloudProviderSelector.tsx
@@ -0,0 +1,63 @@
+import { UseFormReturn } from 'react-hook-form'
+
+import Panel from 'components/ui/Panel'
+import { useCustomContent } from 'hooks/custom-content/useCustomContent'
+import { PROVIDERS } from 'lib/constants'
+import {
+ FormControl_Shadcn_,
+ FormField_Shadcn_,
+ Select_Shadcn_,
+ SelectContent_Shadcn_,
+ SelectGroup_Shadcn_,
+ SelectItem_Shadcn_,
+ SelectTrigger_Shadcn_,
+ SelectValue_Shadcn_,
+} from 'ui'
+import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
+import { CreateProjectForm } from './ProjectCreation.schema'
+
+interface CloudProviderSelectorProps {
+ form: UseFormReturn<CreateProjectForm>
+}
+
+export const CloudProviderSelector = ({ form }: CloudProviderSelectorProps) => {
+ const { infraCloudProviders: validCloudProviders } = useCustomContent(['infra:cloud_providers'])
+
+ return (
+ <Panel.Content>
+ <FormField_Shadcn_
+ control={form.control}
+ name="cloudProvider"
+ render={({ field }) => (
+ <FormItemLayout label="Cloud provider" layout="horizontal">
+ <Select_Shadcn_
+ onValueChange={(value) => field.onChange(value)}
+ defaultValue={field.value}
+ >
+ <FormControl_Shadcn_>
+ <SelectTrigger_Shadcn_>
+ <SelectValue_Shadcn_ placeholder="Select a cloud provider" />
+ </SelectTrigger_Shadcn_>
+ </FormControl_Shadcn_>
+ <SelectContent_Shadcn_>
+ <SelectGroup_Shadcn_>
+ {Object.values(PROVIDERS)
+ .filter((provider) => validCloudProviders?.includes(provider.id) ?? true)
+ .map((providerObj) => {
+ const label = providerObj['name']
+ const value = providerObj['id']
+ return (
+ <SelectItem_Shadcn_ key={value} value={value}>
+ {label}
+ </SelectItem_Shadcn_>
+ )
+ })}
+ </SelectGroup_Shadcn_>
+ </SelectContent_Shadcn_>
+ </Select_Shadcn_>
+ </FormItemLayout>
+ )}
+ />
+ </Panel.Content>
+ )
+}
diff --git a/apps/studio/components/interfaces/ProjectCreation/ComputeSizeSelector.tsx b/apps/studio/components/interfaces/ProjectCreation/ComputeSizeSelector.tsx
new file mode 100644
index 00000000000..8797c7619d4
--- /dev/null
+++ b/apps/studio/components/interfaces/ProjectCreation/ComputeSizeSelector.tsx
@@ -0,0 +1,122 @@
+import { UseFormReturn } from 'react-hook-form'
+
+import { InlineLink } from 'components/ui/InlineLink'
+import Panel from 'components/ui/Panel'
+import { instanceSizeSpecs } from 'data/projects/new-project.constants'
+import { getCloudProviderArchitecture } from 'lib/cloudprovider-utils'
+import { DOCS_URL } from 'lib/constants'
+import { CloudProvider } from 'shared-data'
+import {
+ Badge,
+ FormField_Shadcn_,
+ Select_Shadcn_,
+ SelectContent_Shadcn_,
+ SelectGroup_Shadcn_,
+ SelectItem_Shadcn_,
+ SelectTrigger_Shadcn_,
+ SelectValue_Shadcn_,
+} from 'ui'
+import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
+import { sizes } from './ProjectCreation.constants'
+import { CreateProjectForm } from './ProjectCreation.schema'
+
+interface ComputeSizeSelectorProps {
+ form: UseFormReturn<CreateProjectForm>
+}
+
+export const ComputeSizeSelector = ({ form }: ComputeSizeSelectorProps) => {
+ return (
+ <Panel.Content>
+ <FormField_Shadcn_
+ control={form.control}
+ name="instanceSize"
+ render={({ field }) => (
+ <FormItemLayout
+ layout="horizontal"
+ label="Compute size"
+ description={
+ <>
+ <p>
+ The size for your dedicated database. You can change this later. Learn more about{' '}
+ <InlineLink
+ target="_blank"
+ rel="noopener noreferrer"
+ className="text-inherit hover:text-foreground transition-colors"
+ href={`${DOCS_URL}/guides/platform/compute-add-ons`}
+ >
+ compute add-ons
+ </InlineLink>{' '}
+ and{' '}
+ <InlineLink
+ target="_blank"
+ rel="noopener noreferrer"
+ className="text-inherit hover:text-foreground transition-colors"
+ href={`${DOCS_URL}/guides/platform/manage-your-usage/compute`}
+ >
+ compute billing
+ </InlineLink>
+ .
+ </p>
+ </>
+ }
+ >
+ <Select_Shadcn_ value={field.value} onValueChange={(value) => field.onChange(value)}>
+ <SelectTrigger_Shadcn_ className="[&>span>div>div>[data-field=instance-details]]:hidden">
+ <SelectValue_Shadcn_ placeholder="Select a compute size" />
+ </SelectTrigger_Shadcn_>
+ <SelectContent_Shadcn_>
+ <SelectGroup_Shadcn_>
+ {sizes
+ .filter((option) =>
+ instanceSizeSpecs[option].cloud_providers.includes(
+ form.getValues('cloudProvider') as CloudProvider
+ )
+ )
+ .map((option) => {
+ return (
+ <SelectItem_Shadcn_ key={option} value={option}>
+ <div className="flex flex-row gap-2">
+ <div className="text-center w-[80px]">
+ <Badge
+ variant={option === 'micro' ? 'default' : 'brand'}
+ className="rounded-md w-16 text-center flex justify-center font-mono uppercase"
+ >
+ {instanceSizeSpecs[option].label}
+ </Badge>
+ </div>
+ <div className="text-sm">
+ <span className="text-foreground">
+ {instanceSizeSpecs[option].ram} RAM /{' '}
+ {instanceSizeSpecs[option].cpu}{' '}
+ {getCloudProviderArchitecture(
+ form.getValues('cloudProvider') as CloudProvider
+ )}{' '}
+ CPU
+ </span>
+ <p
+ translate="no"
+ className="text-xs text-foreground-light"
+ data-field="instance-details"
+ >
+ ${instanceSizeSpecs[option].priceHourly}/hour (~$
+ {instanceSizeSpecs[option].priceMonthly}/month)
+ </p>
+ </div>
+ </div>
+ </SelectItem_Shadcn_>
+ )
+ })}
+ <SelectItem_Shadcn_ key={'disabled'} value={'disabled'} disabled>
+ <div className="flex items-center justify-center w-full">
+ <span>Larger instance sizes available after creation</span>
+ </div>
+ </SelectItem_Shadcn_>
+ </SelectGroup_Shadcn_>
+ </SelectContent_Shadcn_>
+ </Select_Shadcn_>
+ </FormItemLayout>
+ )}
+ />
+ </Panel.Content>
+ )
+}
diff --git a/apps/studio/components/interfaces/ProjectCreation/CustomPostgresVersionInput.tsx b/apps/studio/components/interfaces/ProjectCreation/CustomPostgresVersionInput.tsx
new file mode 100644
index 00000000000..27e514e3dcc
--- /dev/null
+++ b/apps/studio/components/interfaces/ProjectCreation/CustomPostgresVersionInput.tsx
@@ -0,0 +1,32 @@
+import { UseFormReturn } from 'react-hook-form'
+
+import Panel from 'components/ui/Panel'
+import { FormControl_Shadcn_, FormField_Shadcn_, Input_Shadcn_ } from 'ui'
+import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
+import { CreateProjectForm } from './ProjectCreation.schema'
+
+interface CustomPostgresVersionInputProps {
+ form: UseFormReturn<CreateProjectForm>
+}
+
+export const CustomPostgresVersionInput = ({ form }: CustomPostgresVersionInputProps) => {
+ return (
+ <Panel.Content>
+ <FormField_Shadcn_
+ control={form.control}
+ name="postgresVersion"
+ render={({ field }) => (
+ <FormItemLayout
+ label="Custom Postgres version"
+ layout="horizontal"
+ description="Specify a custom version of Postgres (defaults to the latest). This is only applicable for local/staging projects."
+ >
+ <FormControl_Shadcn_>
+ <Input_Shadcn_ placeholder="Postgres version" {...field} autoComplete="off" />
+ </FormControl_Shadcn_>
+ </FormItemLayout>
+ )}
+ />
+ </Panel.Content>
+ )
+}
diff --git a/apps/studio/components/interfaces/ProjectCreation/DatabasePasswordInput.tsx b/apps/studio/components/interfaces/ProjectCreation/DatabasePasswordInput.tsx
new file mode 100644
index 00000000000..27779203902
--- /dev/null
+++ b/apps/studio/components/interfaces/ProjectCreation/DatabasePasswordInput.tsx
@@ -0,0 +1,102 @@
+import { debounce } from 'lodash'
+import { useRef } from 'react'
+import { UseFormReturn } from 'react-hook-form'
+
+import Panel from 'components/ui/Panel'
+import PasswordStrengthBar from 'components/ui/PasswordStrengthBar'
+import passwordStrength from 'lib/password-strength'
+import { generateStrongPassword } from 'lib/project'
+import { FormControl_Shadcn_, FormField_Shadcn_ } from 'ui'
+import { Input } from 'ui-patterns/DataInputs/Input'
+import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
+import { DATABASE_PASSWORD_REGEX } from './ProjectCreation.constants'
+import { CreateProjectForm } from './ProjectCreation.schema'
+import { SpecialSymbolsCallout } from './SpecialSymbolsCallout'
+
+interface DatabasePasswordInputProps {
+ form: UseFormReturn<CreateProjectForm>
+ passwordStrengthMessage: string
+ setPasswordStrengthMessage: (value: string) => void
+ setPasswordStrengthWarning: (value: string) => void
+}
+
+export const DatabasePasswordInput = ({
+ form,
+ passwordStrengthMessage,
+ setPasswordStrengthMessage,
+ setPasswordStrengthWarning,
+}: DatabasePasswordInputProps) => {
+ async function checkPasswordStrength(value: any) {
+ const { message, warning, strength } = await passwordStrength(value)
+
+ form.setValue('dbPassStrength', strength)
+ form.trigger('dbPassStrength')
+ form.trigger('dbPass')
+
+ setPasswordStrengthWarning(warning)
+ setPasswordStrengthMessage(message)
+ }
+
+ const delayedCheckPasswordStrength = useRef(
+ debounce((value) => checkPasswordStrength(value), 300)
+ ).current
+
+ // [Refactor] DB Password could be a common component used in multiple pages with repeated logic
+ function generatePassword() {
+ const password = generateStrongPassword()
+ form.setValue('dbPass', password)
+ delayedCheckPasswordStrength(password)
+ }
+
+ return (
+ <Panel.Content>
+ <FormField_Shadcn_
+ control={form.control}
+ name="dbPass"
+ render={({ field }) => {
+ const isInvalidDatabasePassword =
+ field.value.length > 0 && !field.value.match(DATABASE_PASSWORD_REGEX)
+
+ return (
+ <FormItemLayout
+ label="Database password"
+ layout="horizontal"
+ description={
+ <>
+ {isInvalidDatabasePassword && <SpecialSymbolsCallout />}
+ <PasswordStrengthBar
+ passwordStrengthScore={form.getValues('dbPassStrength')}
+ password={field.value}
+ passwordStrengthMessage={passwordStrengthMessage}
+ generateStrongPassword={generatePassword}
+ />
+ </>
+ }
+ >
+ <FormControl_Shadcn_>
+ <Input
+ copy={field.value.length > 0}
+ type="password"
+ placeholder="Type in a strong password"
+ {...field}
+ autoComplete="off"
+ onChange={async (event) => {
+ field.onChange(event)
+ form.trigger('dbPassStrength')
+ const value = event.target.value
+ if (event.target.value === '') {
+ await form.setValue('dbPassStrength', 0)
+ await form.trigger('dbPass')
+ } else {
+ await delayedCheckPasswordStrength(value)
+ }
+ }}
+ />
+ </FormControl_Shadcn_>
+ </FormItemLayout>
+ )
+ }}
+ />
+ </Panel.Content>
+ )
+}
diff --git a/apps/studio/components/interfaces/ProjectCreation/DisabledWarningDueToIncident.tsx b/apps/studio/components/interfaces/ProjectCreation/DisabledWarningDueToIncident.tsx
new file mode 100644
index 00000000000..e18d5efb3ad
--- /dev/null
+++ b/apps/studio/components/interfaces/ProjectCreation/DisabledWarningDueToIncident.tsx
@@ -0,0 +1,31 @@
+import { AlertCircle } from 'lucide-react'
+
+import InformationBox from 'components/ui/InformationBox'
+import Panel from 'components/ui/Panel'
+
+interface DisabledWarningDueToIncidentProps {
+ title: string
+}
+
+export const DisabledWarningDueToIncident = ({ title }: DisabledWarningDueToIncidentProps) => {
+ return (
+ <Panel.Content className="pb-8">
+ <InformationBox
+ icon={<AlertCircle size={20} strokeWidth={1.5} />}
+ defaultVisibility={true}
+ hideCollapse
+ title={title}
+ description={
+ <div className="space-y-3">
+ <p className="text-sm leading-normal">
+ Our engineers are currently working on a fix. You can follow updates on{' '}
+ <a className="text-brand" href="https://status.supabase.com/">
+ https://status.supabase.com/
+ </a>
+ </p>
+ </div>
+ }
+ />
+ </Panel.Content>
+ )
+}
diff --git a/apps/studio/components/interfaces/ProjectCreation/FreeProjectLimitWarning.tsx b/apps/studio/components/interfaces/ProjectCreation/FreeProjectLimitWarning.tsx
new file mode 100644
index 00000000000..00b5e33da99
--- /dev/null
+++ b/apps/studio/components/interfaces/ProjectCreation/FreeProjectLimitWarning.tsx
@@ -0,0 +1,41 @@
+import Panel from 'components/ui/Panel'
+import { UpgradePlanButton } from 'components/ui/UpgradePlanButton'
+import type { MemberWithFreeProjectLimit } from 'data/organizations/free-project-limit-check-query'
+import { Admonition } from 'ui-patterns/admonition'
+
+interface FreeProjectLimitWarningProps {
+ membersExceededLimit: MemberWithFreeProjectLimit[]
+}
+
+export const FreeProjectLimitWarning = ({ membersExceededLimit }: FreeProjectLimitWarningProps) => {
+ return (
+ <Panel.Content>
+ <Admonition
+ type="default"
+ title="The organization has members who have exceeded their free project limits"
+ description={
+ <div className="space-y-3">
+ <p className="text-sm leading-normal">
+ The following members have reached their maximum limits for the number of active free
+ plan projects within organizations where they are an administrator or owner:
+ </p>
+ <ul className="pl-5 list-disc">
+ {membersExceededLimit.map((member, idx: number) => (
+ <li key={`member-${idx}`}>
+ {member.username || member.primary_email} (Limit: {member.free_project_limit} free
+ projects)
+ </li>
+ ))}
+ </ul>
+ <p className="text-sm leading-normal">
+ These members will need to either delete, pause, or upgrade one or more of these
+ projects before you're able to create a free project within this organization.
+ </p>
+
+ <UpgradePlanButton source="freeProjectLimitWarning">Upgrade plan</UpgradePlanButton>
+ </div>
+ }
+ />
+ </Panel.Content>
+ )
+}
diff --git a/apps/studio/components/interfaces/Organization/NewProject/NotOrganizationOwnerWarning.tsx b/apps/studio/components/interfaces/ProjectCreation/NotOrganizationOwnerWarning.tsx
similarity index 88%
rename from apps/studio/components/interfaces/Organization/NewProject/NotOrganizationOwnerWarning.tsx
rename to apps/studio/components/interfaces/ProjectCreation/NotOrganizationOwnerWarning.tsx
index a74dcafae74..c08d172ebae 100644
--- a/apps/studio/components/interfaces/Organization/NewProject/NotOrganizationOwnerWarning.tsx
+++ b/apps/studio/components/interfaces/ProjectCreation/NotOrganizationOwnerWarning.tsx
@@ -6,7 +6,7 @@ interface NotOrganizationOwnerWarningProps {
}
// [Joshen] This can just use NoPermission component i think
-const NotOrganizationOwnerWarning = ({ slug }: NotOrganizationOwnerWarningProps) => {
+export const NotOrganizationOwnerWarning = ({ slug }: NotOrganizationOwnerWarningProps) => {
return (
<div className="mt-4">
<InformationBox
@@ -32,5 +32,3 @@ const NotOrganizationOwnerWarning = ({ slug }: NotOrganizationOwnerWarningProps)
</div>
)
}
-
-export default NotOrganizationOwnerWarning
diff --git a/apps/studio/components/interfaces/ProjectCreation/OrganizationSelector.tsx b/apps/studio/components/interfaces/ProjectCreation/OrganizationSelector.tsx
new file mode 100644
index 00000000000..39c8b32a8d8
--- /dev/null
+++ b/apps/studio/components/interfaces/ProjectCreation/OrganizationSelector.tsx
@@ -0,0 +1,89 @@
+import { PermissionAction } from '@supabase/shared-types/out/constants'
+import { useRouter } from 'next/router'
+import { UseFormReturn } from 'react-hook-form'
+
+import { useParams } from 'common'
+import Panel from 'components/ui/Panel'
+import { useOrganizationsQuery } from 'data/organizations/organizations-query'
+import { useAsyncCheckPermissions } from 'hooks/misc/useCheckPermissions'
+import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization'
+import {
+ Badge,
+ FormControl_Shadcn_,
+ FormField_Shadcn_,
+ Select_Shadcn_,
+ SelectContent_Shadcn_,
+ SelectGroup_Shadcn_,
+ SelectItem_Shadcn_,
+ SelectTrigger_Shadcn_,
+ SelectValue_Shadcn_,
+} from 'ui'
+import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
+import { OrgNotFound } from '../Organization/OrgNotFound'
+import { NotOrganizationOwnerWarning } from './NotOrganizationOwnerWarning'
+import { CreateProjectForm } from './ProjectCreation.schema'
+
+interface OrganizationSelectorProps {
+ form: UseFormReturn<CreateProjectForm>
+}
+
+export const OrganizationSelector = ({ form }: OrganizationSelectorProps) => {
+ const router = useRouter()
+ const { slug } = useParams()
+ const { data: currentOrg } = useSelectedOrganizationQuery()
+ const { can: isAdmin } = useAsyncCheckPermissions(PermissionAction.CREATE, 'projects')
+
+ const { data: organizations, isSuccess: isOrganizationsSuccess } = useOrganizationsQuery()
+ const isInvalidSlug = isOrganizationsSuccess && currentOrg === undefined
+ const orgNotFound = (organizations?.length ?? 0) > 0 && isInvalidSlug
+
+ return (
+ <Panel.Content className="space-y-4">
+ {isAdmin && !isInvalidSlug && (
+ <FormField_Shadcn_
+ control={form.control}
+ name="organization"
+ render={({ field }) => (
+ <FormItemLayout label="Organization" layout="horizontal">
+ {(organizations?.length ?? 0) > 0 && (
+ <Select_Shadcn_
+ onValueChange={(slug) => {
+ field.onChange(slug)
+ router.push(`/new/${slug}`)
+ }}
+ value={field.value}
+ defaultValue={field.value}
+ >
+ <FormControl_Shadcn_>
+ <SelectTrigger_Shadcn_>
+ <SelectValue_Shadcn_ placeholder="Select an organization" />
+ </SelectTrigger_Shadcn_>
+ </FormControl_Shadcn_>
+ <SelectContent_Shadcn_>
+ <SelectGroup_Shadcn_>
+ {organizations?.map((x) => (
+ <SelectItem_Shadcn_
+ key={x.id}
+ value={x.slug}
+ className="flex justify-between"
+ >
+ <span className="mr-2">{x.name}</span>
+ <Badge>{x.plan.name}</Badge>
+ </SelectItem_Shadcn_>
+ ))}
+ </SelectGroup_Shadcn_>
+ </SelectContent_Shadcn_>
+ </Select_Shadcn_>
+ )}
+ </FormItemLayout>
+ )}
+ />
+ )}
+
+ {isOrganizationsSuccess && !isAdmin && !orgNotFound && (
+ <NotOrganizationOwnerWarning slug={slug} />
+ )}
+ {orgNotFound && <OrgNotFound slug={slug} />}
+ </Panel.Content>
+ )
+}
diff --git a/apps/studio/components/interfaces/ProjectCreation/ProjectCreation.constants.ts b/apps/studio/components/interfaces/ProjectCreation/ProjectCreation.constants.ts
index 323ee0082d6..75ef67137ab 100644
--- a/apps/studio/components/interfaces/ProjectCreation/ProjectCreation.constants.ts
+++ b/apps/studio/components/interfaces/ProjectCreation/ProjectCreation.constants.ts
@@ -1,3 +1,5 @@
+import { DesiredInstanceSize } from 'data/projects/new-project.constants'
+
// [Joshen] Obtained from https://gist.github.com/tadast/8827699
export const COUNTRY_LAT_LON = {
AF: { lat: 33, lon: 65 },
@@ -253,4 +255,6 @@ export const COUNTRY_LAT_LON = {
ZW: { lat: -20, lon: 30 },
}
-export const SPECIAL_CHARS_REGEX = /^[^@:\/]*$/
+export const DATABASE_PASSWORD_REGEX = /^[^@:\/]*$/
+
+export const sizes: DesiredInstanceSize[] = ['micro', 'small', 'medium']
diff --git a/apps/studio/components/interfaces/ProjectCreation/ProjectCreation.schema.ts b/apps/studio/components/interfaces/ProjectCreation/ProjectCreation.schema.ts
new file mode 100644
index 00000000000..334050a6928
--- /dev/null
+++ b/apps/studio/components/interfaces/ProjectCreation/ProjectCreation.schema.ts
@@ -0,0 +1,33 @@
+import { z } from 'zod'
+
+export const FormSchema = z.object({
+ organization: z.string({
+ required_error: 'Please select an organization',
+ }),
+ projectName: z
+ .string()
+ .trim()
+ .min(1, 'Please enter a project name.') // Required field check
+ .min(3, 'Project name must be at least 3 characters long.') // Minimum length check
+ .max(64, 'Project name must be no longer than 64 characters.'), // Maximum length check
+ postgresVersion: z.string({
+ required_error: 'Please enter a Postgres version.',
+ }),
+ dbRegion: z.string({
+ required_error: 'Please select a region.',
+ }),
+ cloudProvider: z.string({
+ required_error: 'Please select a cloud provider.',
+ }),
+ dbPassStrength: z.number(),
+ dbPass: z
+ .string({ required_error: 'Please enter a database password.' })
+ .min(1, 'Password is required.'),
+ instanceSize: z.string().optional(),
+ dataApi: z.boolean(),
+ useApiSchema: z.boolean(),
+ postgresVersionSelection: z.string(),
+ useOrioleDb: z.boolean(),
+})
+
+export type CreateProjectForm = z.infer<typeof FormSchema>
diff --git a/apps/studio/components/interfaces/ProjectCreation/ProjectCreation.test.ts b/apps/studio/components/interfaces/ProjectCreation/ProjectCreation.test.ts
index 289c0475604..6c8c546b971 100644
--- a/apps/studio/components/interfaces/ProjectCreation/ProjectCreation.test.ts
+++ b/apps/studio/components/interfaces/ProjectCreation/ProjectCreation.test.ts
@@ -1,10 +1,10 @@
import { expect, test } from 'vitest'
-import { SPECIAL_CHARS_REGEX } from './ProjectCreation.constants'
+import { DATABASE_PASSWORD_REGEX } from './ProjectCreation.constants'
test('Regex test to surface if password contains @, : or /', () => {
- expect(!'teststring'.match(SPECIAL_CHARS_REGEX)).toEqual(false)
- expect(!'test@string'.match(SPECIAL_CHARS_REGEX)).toEqual(true)
- expect(!'te:ststring'.match(SPECIAL_CHARS_REGEX)).toEqual(true)
- expect(!`tests/tring`.match(SPECIAL_CHARS_REGEX)).toEqual(true)
- expect(!'!#$%^&*()'.match(SPECIAL_CHARS_REGEX)).toEqual(false)
+ expect(!'teststring'.match(DATABASE_PASSWORD_REGEX)).toEqual(false)
+ expect(!'test@string'.match(DATABASE_PASSWORD_REGEX)).toEqual(true)
+ expect(!'te:ststring'.match(DATABASE_PASSWORD_REGEX)).toEqual(true)
+ expect(!`tests/tring`.match(DATABASE_PASSWORD_REGEX)).toEqual(true)
+ expect(!'!#$%^&*()'.match(DATABASE_PASSWORD_REGEX)).toEqual(false)
})
diff --git a/apps/studio/components/interfaces/ProjectCreation/ProjectCreation.utils.ts b/apps/studio/components/interfaces/ProjectCreation/ProjectCreation.utils.ts
index 2db5478777f..142542f318c 100644
--- a/apps/studio/components/interfaces/ProjectCreation/ProjectCreation.utils.ts
+++ b/apps/studio/components/interfaces/ProjectCreation/ProjectCreation.utils.ts
@@ -1,3 +1,4 @@
+import { DesiredInstanceSize, instanceSizeSpecs } from 'data/projects/new-project.constants'
import type { CloudProvider, Region } from 'shared-data'
import { AWS_REGIONS, FLY_REGIONS } from 'shared-data'
import { SMART_REGION_TO_EXACT_REGION_MAP } from 'shared-data/regions'
@@ -29,3 +30,17 @@ export function getAvailableRegions(cloudProvider: CloudProvider): Region {
throw new Error('Invalid cloud provider')
}
}
+
+/**
+ * When launching new projects, they only get assigned a compute size once successfully launched,
+ * this might assume wrong compute size, but only for projects being rapidly launched after one another on non-default compute sizes.
+ *
+ * Needs to be in the API in the future [kevin]
+ */
+export const monthlyInstancePrice = (instance: string | undefined): number => {
+ return instanceSizeSpecs[instance as DesiredInstanceSize]?.priceMonthly || 10
+}
+
+export const instanceLabel = (instance: string | undefined): string => {
+ return instanceSizeSpecs[instance as DesiredInstanceSize]?.label || 'Micro'
+}
diff --git a/apps/studio/components/interfaces/ProjectCreation/ProjectCreationFooter.tsx b/apps/studio/components/interfaces/ProjectCreation/ProjectCreationFooter.tsx
new file mode 100644
index 00000000000..c64dd7795a5
--- /dev/null
+++ b/apps/studio/components/interfaces/ProjectCreation/ProjectCreationFooter.tsx
@@ -0,0 +1,197 @@
+import { useRouter } from 'next/router'
+import { UseFormReturn } from 'react-hook-form'
+
+import { LOCAL_STORAGE_KEYS, useFlag } from 'common'
+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'
+import {
+ Badge,
+ Button,
+ PopoverSeparator_Shadcn_,
+ 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'
+
+interface ProjectCreationFooterProps {
+ form: UseFormReturn<CreateProjectForm>
+ 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 (
+ <div key="panel-footer" className="grid grid-cols-12 w-full gap-4 items-center">
+ <div className="col-span-4">
+ {!isFreePlan &&
+ !projectCreationDisabled &&
+ canCreateProject &&
+ additionalMonthlySpend > 0 && (
+ <div className="flex justify-between text-sm">
+ <span>Additional costs</span>
+ <div className="text-brand flex gap-1 items-center font-mono font-medium">
+ <span>${additionalMonthlySpend}/m</span>
+ <InfoTooltip side="top" className="max-w-[450px] p-0">
+ <div className="p-4 text-sm text-foreground-light space-y-1">
+ <p>
+ Each project includes a dedicated Postgres instance running on its own server.
+ You are charged for the{' '}
+ <InlineLink href={`${DOCS_URL}/guides/platform/billing-on-supabase`}>
+ Compute resource
+ </InlineLink>{' '}
+ of that server, independent of your database usage.
+ </p>
+ {monthlyComputeCosts > 0 && (
+ <p>Compute costs are applied on top of your subscription plan costs.</p>
+ )}
+ </div>
+
+ <Table className="mt-2">
+ <TableHeader className="[&_th]:h-7">
+ <TableRow className="py-2">
+ <TableHead className="w-[170px]">Project</TableHead>
+ <TableHead>Compute Size</TableHead>
+ <TableHead className="text-right">Monthly Costs</TableHead>
+ </TableRow>
+ </TableHeader>
+ <TableBody className="[&_td]:py-2">
+ {organizationProjects.map((project) => {
+ const primaryDb = project.databases.find(
+ (db) => db.identifier === project.ref
+ )
+ return (
+ <TableRow key={project.ref} className="text-foreground-light">
+ <TableCell className="w-[170px] truncate">{project.name}</TableCell>
+ <TableCell className="text-center">
+ {instanceLabel(primaryDb?.infra_compute_size)}
+ </TableCell>
+ <TableCell className="text-right">
+ ${monthlyInstancePrice(primaryDb?.infra_compute_size)}
+ </TableCell>
+ </TableRow>
+ )
+ })}
+
+ <TableRow>
+ <TableCell className="w-[170px] flex gap-2">
+ <span className="truncate">
+ {form.getValues('projectName') ?? 'New project'}
+ </span>
+ <Badge size={'small'} variant={'default'}>
+ NEW
+ </Badge>
+ </TableCell>
+ <TableCell className="text-center">{instanceLabel(instanceSize)}</TableCell>
+ <TableCell className="text-right">
+ ${monthlyInstancePrice(instanceSize)}
+ </TableCell>
+ </TableRow>
+ </TableBody>
+ </Table>
+ <PopoverSeparator_Shadcn_ />
+ <Table>
+ <TableHeader className="[&_th]:h-7">
+ <TableRow>
+ <TableHead colSpan={2}>Compute Credits</TableHead>
+ <TableHead colSpan={1} className="text-right">
+ -$10
+ </TableHead>
+ </TableRow>
+ </TableHeader>
+ <TableBody className="[&_td]:py-2">
+ <TableRow className="text-foreground">
+ <TableCell colSpan={2}>
+ 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 && (
+ <p className="text-xs text-foreground-lighter">
+ Excluding Read replicas
+ </p>
+ )}
+ </TableCell>
+ <TableCell colSpan={1} className="text-right">
+ ${monthlyComputeCosts}
+ </TableCell>
+ </TableRow>
+ </TableBody>
+ </Table>
+ </InfoTooltip>
+ </div>
+ </div>
+ )}
+ </div>
+
+ <div className="flex items-end col-span-8 space-x-2 ml-auto">
+ <Button
+ type="default"
+ disabled={isCreatingNewProject || isSuccessNewProject}
+ onClick={() => {
+ if (!!lastVisitedOrganization) router.push(`/org/${lastVisitedOrganization}`)
+ else router.push('/organizations')
+ }}
+ >
+ Cancel
+ </Button>
+ <Button
+ htmlType="submit"
+ loading={isCreatingNewProject || isSuccessNewProject}
+ disabled={!canCreateProject}
+ >
+ Create new project
+ </Button>
+ </div>
+ </div>
+ )
+}
diff --git a/apps/studio/components/interfaces/ProjectCreation/ProjectNameInput.tsx b/apps/studio/components/interfaces/ProjectCreation/ProjectNameInput.tsx
new file mode 100644
index 00000000000..9d3be73eb22
--- /dev/null
+++ b/apps/studio/components/interfaces/ProjectCreation/ProjectNameInput.tsx
@@ -0,0 +1,28 @@
+import { UseFormReturn } from 'react-hook-form'
+
+import Panel from 'components/ui/Panel'
+import { FormControl_Shadcn_, FormField_Shadcn_, Input_Shadcn_ } from 'ui'
+import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
+import { CreateProjectForm } from './ProjectCreation.schema'
+
+interface ProjectNameInputProps {
+ form: UseFormReturn<CreateProjectForm>
+}
+
+export const ProjectNameInput = ({ form }: ProjectNameInputProps) => {
+ return (
+ <Panel.Content>
+ <FormField_Shadcn_
+ control={form.control}
+ name="projectName"
+ render={({ field }) => (
+ <FormItemLayout label="Project name" layout="horizontal">
+ <FormControl_Shadcn_>
+ <Input_Shadcn_ {...field} placeholder="Project name" />
+ </FormControl_Shadcn_>
+ </FormItemLayout>
+ )}
+ />
+ </Panel.Content>
+ )
+}
diff --git a/apps/studio/components/interfaces/ProjectCreation/RegionSelector.tsx b/apps/studio/components/interfaces/ProjectCreation/RegionSelector.tsx
index 7630a524b0b..d7578686bc4 100644
--- a/apps/studio/components/interfaces/ProjectCreation/RegionSelector.tsx
+++ b/apps/studio/components/interfaces/ProjectCreation/RegionSelector.tsx
@@ -1,7 +1,8 @@
-import { ControllerRenderProps } from 'react-hook-form'
+import { UseFormReturn } from 'react-hook-form'
import { useFlag, useParams } from 'common'
import AlertError from 'components/ui/AlertError'
+import Panel from 'components/ui/Panel'
import { useDefaultRegionQuery } from 'data/misc/get-default-region-query'
import { useOrganizationAvailableRegionsQuery } from 'data/organizations/organization-available-regions-query'
import type { DesiredInstanceSize } from 'data/projects/new-project.constants'
@@ -9,6 +10,7 @@ import { BASE_PATH, PROVIDERS } from 'lib/constants'
import type { CloudProvider } from 'shared-data'
import {
Badge,
+ FormField_Shadcn_,
SelectContent_Shadcn_,
SelectGroup_Shadcn_,
SelectItem_Shadcn_,
@@ -23,11 +25,11 @@ import {
cn,
} from 'ui'
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
+import { CreateProjectForm } from './ProjectCreation.schema'
import { getAvailableRegions } from './ProjectCreation.utils'
interface RegionSelectorProps {
- cloudProvider: CloudProvider
- field: ControllerRenderProps<any, 'dbRegion'>
+ form: UseFormReturn<CreateProjectForm>
instanceSize?: DesiredInstanceSize
layout?: 'vertical' | 'horizontal'
}
@@ -37,12 +39,12 @@ interface RegionSelectorProps {
// ^ can try again next time
export const RegionSelector = ({
- cloudProvider,
- field,
+ form,
instanceSize,
layout = 'horizontal',
}: RegionSelectorProps) => {
const { slug } = useParams()
+ const cloudProvider = form.getValues('cloudProvider') as CloudProvider
const smartRegionEnabled = useFlag('enableSmartRegion')
@@ -89,145 +91,164 @@ export const RegionSelector = ({
process.env.NEXT_PUBLIC_ENVIRONMENT === 'staging'
const allSelectableRegions = [...smartRegions, ...regionOptions]
- const selectedRegion = allSelectableRegions.find((region) => {
- return !!region.name && region.name === field.value
- })
if (isErrorAvailableRegions) {
return <AlertError subject="Error loading available regions" error={errorAvailableRegions} />
}
return (
- <FormItemLayout
- layout={layout}
- label="Region"
- description={
- <>
- <p>Select the region closest to your users for the best performance.</p>
- {showNonProdFields && (
- <div className="mt-2 text-warning">
- <p>Only these regions are supported for local/staging projects:</p>
- <ul className="list-disc list-inside mt-1">
- <li>East US (North Virginia)</li>
- <li>Central EU (Frankfurt)</li>
- <li>Southeast Asia (Singapore)</li>
- </ul>
- </div>
- )}
- </>
- }
- >
- <Select_Shadcn_ value={field.value} onValueChange={field.onChange} disabled={isLoading}>
- <SelectTrigger_Shadcn_ className="[&>:nth-child(1)]:w-full [&>:nth-child(1)]:flex [&>:nth-child(1)]:items-start">
- <SelectValue_Shadcn_
- placeholder={
- isLoading ? 'Loading available regions...' : 'Select a region for your project..'
- }
- >
- {field.value !== undefined && (
- <div className="flex items-center gap-x-3">
- {selectedRegion?.code && (
- <img
- alt="region icon"
- className="w-5 rounded-sm"
- src={`${BASE_PATH}/img/regions/${selectedRegion.code}.svg`}
- />
- )}
- <span className="text-foreground">{selectedRegion?.name ?? field.value}</span>
- </div>
- )}
- </SelectValue_Shadcn_>
- </SelectTrigger_Shadcn_>
- <SelectContent_Shadcn_>
- {smartRegionEnabled && (
- <>
- <SelectGroup_Shadcn_>
- <SelectLabel_Shadcn_>Smart Region Selection</SelectLabel_Shadcn_>
- {smartRegions.map((value) => {
- return (
- <SelectItem_Shadcn_
- key={value.code}
- value={value.name}
- className="w-full [&>:nth-child(2)]:w-full"
- >
- <div className="flex flex-row items-center justify-between w-full">
- <div className="flex items-center gap-x-3">
+ <Panel.Content>
+ <FormField_Shadcn_
+ control={form.control}
+ name="dbRegion"
+ render={({ field }) => {
+ const selectedRegion = allSelectableRegions.find((region) => {
+ return !!region.name && region.name === field.value
+ })
+
+ return (
+ <FormItemLayout
+ layout={layout}
+ label="Region"
+ description={
+ <>
+ <p>Select the region closest to your users for the best performance.</p>
+ {showNonProdFields && (
+ <div className="mt-2 text-warning">
+ <p>Only these regions are supported for local/staging projects:</p>
+ <ul className="list-disc list-inside mt-1">
+ <li>East US (North Virginia)</li>
+ <li>Central EU (Frankfurt)</li>
+ <li>Southeast Asia (Singapore)</li>
+ </ul>
+ </div>
+ )}
+ </>
+ }
+ >
+ <Select_Shadcn_
+ value={field.value}
+ onValueChange={field.onChange}
+ disabled={isLoading}
+ >
+ <SelectTrigger_Shadcn_ className="[&>:nth-child(1)]:w-full [&>:nth-child(1)]:flex [&>:nth-child(1)]:items-start">
+ <SelectValue_Shadcn_
+ placeholder={
+ isLoading
+ ? 'Loading available regions...'
+ : 'Select a region for your project..'
+ }
+ >
+ {field.value !== undefined && (
+ <div className="flex items-center gap-x-3">
+ {selectedRegion?.code && (
<img
alt="region icon"
className="w-5 rounded-sm"
- src={`${BASE_PATH}/img/regions/${value.code}.svg`}
+ src={`${BASE_PATH}/img/regions/${selectedRegion.code}.svg`}
/>
- <span className="text-foreground">{value.name}</span>
- </div>
-
- <div>
- {recommendedSmartRegions.has(value.code) && (
- <Badge variant="success" className="mr-1">
- Recommended
- </Badge>
- )}
- </div>
- </div>
- </SelectItem_Shadcn_>
- )
- })}
- </SelectGroup_Shadcn_>
- <SelectSeparator_Shadcn_ />
- </>
- )}
-
- <SelectGroup_Shadcn_>
- <SelectLabel_Shadcn_>All Regions</SelectLabel_Shadcn_>
- {regionOptions.map((value) => {
- return (
- <SelectItem_Shadcn_
- key={value.code}
- value={value.name}
- className={cn(
- 'w-full [&>:nth-child(2)]:w-full',
- value.status !== undefined && '!pointer-events-auto'
- )}
- disabled={value.status !== undefined}
- >
- <div className="flex flex-row items-center justify-between w-full gap-x-2">
- <div className="flex items-center gap-x-3">
- <img
- alt="region icon"
- className="w-5 rounded-sm"
- src={`${BASE_PATH}/img/regions/${value.code}.svg`}
- />
- <div className="flex items-center gap-x-2">
- <span className="text-foreground">{value.name}</span>
- <span className="text-xs text-foreground-lighter font-mono">
- {value.code}
+ )}
+ <span className="text-foreground">
+ {selectedRegion?.name ?? field.value}
</span>
</div>
- </div>
-
- {recommendedSpecificRegions.has(value.code) && (
- <Badge variant="success" className="mr-1">
- Recommended
- </Badge>
- )}
- {value.status !== undefined && value.status === 'capacity' && (
- <Tooltip>
- <TooltipTrigger>
- <Badge variant="warning" className="mr-1">
- Unavailable
- </Badge>
- </TooltipTrigger>
- <TooltipContent>
- Temporarily unavailable due to this region being at capacity.
- </TooltipContent>
- </Tooltip>
)}
- </div>
- </SelectItem_Shadcn_>
- )
- })}
- </SelectGroup_Shadcn_>
- </SelectContent_Shadcn_>
- </Select_Shadcn_>
- </FormItemLayout>
+ </SelectValue_Shadcn_>
+ </SelectTrigger_Shadcn_>
+ <SelectContent_Shadcn_>
+ {smartRegionEnabled && (
+ <>
+ <SelectGroup_Shadcn_>
+ <SelectLabel_Shadcn_>Smart Region Selection</SelectLabel_Shadcn_>
+ {smartRegions.map((value) => {
+ return (
+ <SelectItem_Shadcn_
+ key={value.code}
+ value={value.name}
+ className="w-full [&>:nth-child(2)]:w-full"
+ >
+ <div className="flex flex-row items-center justify-between w-full">
+ <div className="flex items-center gap-x-3">
+ <img
+ alt="region icon"
+ className="w-5 rounded-sm"
+ src={`${BASE_PATH}/img/regions/${value.code}.svg`}
+ />
+ <span className="text-foreground">{value.name}</span>
+ </div>
+
+ <div>
+ {recommendedSmartRegions.has(value.code) && (
+ <Badge variant="success" className="mr-1">
+ Recommended
+ </Badge>
+ )}
+ </div>
+ </div>
+ </SelectItem_Shadcn_>
+ )
+ })}
+ </SelectGroup_Shadcn_>
+ <SelectSeparator_Shadcn_ />
+ </>
+ )}
+
+ <SelectGroup_Shadcn_>
+ <SelectLabel_Shadcn_>All Regions</SelectLabel_Shadcn_>
+ {regionOptions.map((value) => {
+ return (
+ <SelectItem_Shadcn_
+ key={value.code}
+ value={value.name}
+ className={cn(
+ 'w-full [&>:nth-child(2)]:w-full',
+ value.status !== undefined && '!pointer-events-auto'
+ )}
+ disabled={value.status !== undefined}
+ >
+ <div className="flex flex-row items-center justify-between w-full gap-x-2">
+ <div className="flex items-center gap-x-3">
+ <img
+ alt="region icon"
+ className="w-5 rounded-sm"
+ src={`${BASE_PATH}/img/regions/${value.code}.svg`}
+ />
+ <div className="flex items-center gap-x-2">
+ <span className="text-foreground">{value.name}</span>
+ <span className="text-xs text-foreground-lighter font-mono">
+ {value.code}
+ </span>
+ </div>
+ </div>
+
+ {recommendedSpecificRegions.has(value.code) && (
+ <Badge variant="success" className="mr-1">
+ Recommended
+ </Badge>
+ )}
+ {value.status !== undefined && value.status === 'capacity' && (
+ <Tooltip>
+ <TooltipTrigger>
+ <Badge variant="warning" className="mr-1">
+ Unavailable
+ </Badge>
+ </TooltipTrigger>
+ <TooltipContent>
+ Temporarily unavailable due to this region being at capacity.
+ </TooltipContent>
+ </Tooltip>
+ )}
+ </div>
+ </SelectItem_Shadcn_>
+ )
+ })}
+ </SelectGroup_Shadcn_>
+ </SelectContent_Shadcn_>
+ </Select_Shadcn_>
+ </FormItemLayout>
+ )
+ }}
+ />
+ </Panel.Content>
)
}
diff --git a/apps/studio/components/interfaces/ProjectCreation/SecurityOptions.tsx b/apps/studio/components/interfaces/ProjectCreation/SecurityOptions.tsx
index 7e13206a3a5..69fd74fed25 100644
--- a/apps/studio/components/interfaces/ProjectCreation/SecurityOptions.tsx
+++ b/apps/studio/components/interfaces/ProjectCreation/SecurityOptions.tsx
@@ -2,7 +2,6 @@ import { ChevronRight } from 'lucide-react'
import { UseFormReturn } from 'react-hook-form'
import Panel from 'components/ui/Panel'
-import { CreateProjectForm } from 'pages/new/[slug]'
import {
Badge,
cn,
@@ -17,6 +16,7 @@ import {
} from 'ui'
import { Admonition } from 'ui-patterns'
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
+import { CreateProjectForm } from './ProjectCreation.schema'
interface SecurityOptionsProps {
form: UseFormReturn<CreateProjectForm>
diff --git a/apps/studio/components/interfaces/Settings/General/General.tsx b/apps/studio/components/interfaces/Settings/General/General.tsx
index 61c0f7d2236..fb8b87e4d54 100644
--- a/apps/studio/components/interfaces/Settings/General/General.tsx
+++ b/apps/studio/components/interfaces/Settings/General/General.tsx
@@ -1,6 +1,7 @@
import { PermissionAction } from '@supabase/shared-types/out/constants'
import { BarChart2 } from 'lucide-react'
import Link from 'next/link'
+import { useState } from 'react'
import { toast } from 'sonner'
import { FormActions } from 'components/ui/Forms/FormActions'
@@ -30,6 +31,9 @@ const General = () => {
const { data: project } = useSelectedProjectQuery()
const { data: organization } = useSelectedOrganizationQuery()
+ // [Joshen] Need to refactor to use RHF so we don't need manual error handlers like this
+ const [nameError, setNameError] = useState<string>()
+
const { data: parentProject } = useProjectDetailQuery({ ref: project?.parent_project_ref })
const isBranch = parentProject !== undefined
@@ -50,6 +54,11 @@ const General = () => {
const onSubmit = async (values: any, { resetForm }: any) => {
if (!project?.ref) return console.error('Ref is required')
+ if (values.name.length < 3) {
+ setNameError('Project name must be at least 3 characters long')
+ return
+ }
+
updateProject(
{ ref: project.ref, name: values.name.trim() },
{
@@ -95,7 +104,10 @@ const General = () => {
form={formId}
isSubmitting={isUpdating}
hasChanges={hasChanges}
- handleReset={handleReset}
+ handleReset={() => {
+ handleReset()
+ setNameError(undefined)
+ }}
helper={
!canUpdateProject
? "You need additional permissions to manage this project's settings"
@@ -112,6 +124,8 @@ const General = () => {
size="small"
label="Project name"
disabled={isBranch || !canUpdateProject}
+ onChange={() => setNameError(undefined)}
+ error={nameError}
/>
<Input copy disabled id="ref" size="small" label="Project ID" />
</FormSectionContent>
diff --git a/apps/studio/components/ui/DisabledWarningDueToIncident.tsx b/apps/studio/components/ui/DisabledWarningDueToIncident.tsx
deleted file mode 100644
index fc337e4a80a..00000000000
--- a/apps/studio/components/ui/DisabledWarningDueToIncident.tsx
+++ /dev/null
@@ -1,29 +0,0 @@
-import InformationBox from 'components/ui/InformationBox'
-import { AlertCircle } from 'lucide-react'
-
-interface DisabledWarningDueToIncidentProps {
- title: string
-}
-
-const DisabledWarningDueToIncident = ({ title }: DisabledWarningDueToIncidentProps) => {
- return (
- <InformationBox
- icon={<AlertCircle size={20} strokeWidth={1.5} />}
- defaultVisibility={true}
- hideCollapse
- title={title}
- description={
- <div className="space-y-3">
- <p className="text-sm leading-normal">
- Our engineers are currently working on a fix. You can follow updates on{' '}
- <a className="text-brand" href="https://status.supabase.com/">
- https://status.supabase.com/
- </a>
- </p>
- </div>
- }
- />
- )
-}
-
-export default DisabledWarningDueToIncident
diff --git a/apps/studio/data/organizations/keys.ts b/apps/studio/data/organizations/keys.ts
index 64dabc7a7f6..28fb5e039af 100644
--- a/apps/studio/data/organizations/keys.ts
+++ b/apps/studio/data/organizations/keys.ts
@@ -1,5 +1,3 @@
-import type { DesiredInstanceSizeForAvailableRegions } from './organization-available-regions-query'
-
export const organizationKeys = {
list: () => ['organizations'] as const,
detail: (slug?: string) => ['organizations', slug] as const,
@@ -22,9 +20,6 @@ export const organizationKeys = {
['organizations', slug, 'validate-token', token] as const,
projectClaim: (slug: string, token: string) =>
['organizations', slug, 'project-claim', token] as const,
- availableRegions: (
- slug: string | undefined,
- cloudProvider: string,
- size?: DesiredInstanceSizeForAvailableRegions
- ) => ['organizations', slug, 'available-regions', cloudProvider, size] as const,
+ availableRegions: (slug: string | undefined, cloudProvider: string, size?: string) =>
+ ['organizations', slug, 'available-regions', cloudProvider, size] as const,
}
diff --git a/apps/studio/pages/new/[slug].tsx b/apps/studio/pages/new/[slug].tsx
index d177c1220a2..3dc60cf8e8f 100644
--- a/apps/studio/pages/new/[slug].tsx
+++ b/apps/studio/pages/new/[slug].tsx
@@ -1,35 +1,39 @@
import { zodResolver } from '@hookform/resolvers/zod'
import { PermissionAction } from '@supabase/shared-types/out/constants'
-import { debounce } from 'lodash'
import Link from 'next/link'
import { useRouter } from 'next/router'
-import { PropsWithChildren, useEffect, useMemo, useRef, useState } from 'react'
+import { PropsWithChildren, useEffect, useMemo, useState } from 'react'
import { useForm } from 'react-hook-form'
import { toast } from 'sonner'
import { z } from 'zod'
-import { PopoverSeparator } from '@ui/components/shadcn/ui/popover'
import { LOCAL_STORAGE_KEYS, useFlag, useParams } from 'common'
-import { NotOrganizationOwnerWarning } from 'components/interfaces/Organization/NewProject'
-import { FreeProjectLimitWarning } from 'components/interfaces/Organization/NewProject/FreeProjectLimitWarning'
-import { OrgNotFound } from 'components/interfaces/Organization/OrgNotFound'
import { AdvancedConfiguration } from 'components/interfaces/ProjectCreation/AdvancedConfiguration'
+import { CloudProviderSelector } from 'components/interfaces/ProjectCreation/CloudProviderSelector'
+import { ComputeSizeSelector } from 'components/interfaces/ProjectCreation/ComputeSizeSelector'
+import { CustomPostgresVersionInput } from 'components/interfaces/ProjectCreation/CustomPostgresVersionInput'
+import { DatabasePasswordInput } from 'components/interfaces/ProjectCreation/DatabasePasswordInput'
+import { DisabledWarningDueToIncident } from 'components/interfaces/ProjectCreation/DisabledWarningDueToIncident'
+import { FreeProjectLimitWarning } from 'components/interfaces/ProjectCreation/FreeProjectLimitWarning'
+import { OrganizationSelector } from 'components/interfaces/ProjectCreation/OrganizationSelector'
import {
extractPostgresVersionDetails,
PostgresVersionSelector,
} from 'components/interfaces/ProjectCreation/PostgresVersionSelector'
-import { SPECIAL_CHARS_REGEX } from 'components/interfaces/ProjectCreation/ProjectCreation.constants'
-import { smartRegionToExactRegion } from 'components/interfaces/ProjectCreation/ProjectCreation.utils'
+import { sizes } from 'components/interfaces/ProjectCreation/ProjectCreation.constants'
+import { FormSchema } from 'components/interfaces/ProjectCreation/ProjectCreation.schema'
+import {
+ instanceLabel,
+ smartRegionToExactRegion,
+} from 'components/interfaces/ProjectCreation/ProjectCreation.utils'
+import { ProjectCreationFooter } from 'components/interfaces/ProjectCreation/ProjectCreationFooter'
+import { ProjectNameInput } from 'components/interfaces/ProjectCreation/ProjectNameInput'
import { RegionSelector } from 'components/interfaces/ProjectCreation/RegionSelector'
import { SecurityOptions } from 'components/interfaces/ProjectCreation/SecurityOptions'
-import { SpecialSymbolsCallout } from 'components/interfaces/ProjectCreation/SpecialSymbolsCallout'
import DefaultLayout from 'components/layouts/DefaultLayout'
import { WizardLayoutWithoutAuth } from 'components/layouts/WizardLayout'
-import DisabledWarningDueToIncident from 'components/ui/DisabledWarningDueToIncident'
-import { InlineLink } from 'components/ui/InlineLink'
import Panel from 'components/ui/Panel'
import PartnerManagedResource from 'components/ui/PartnerManagedResource'
-import PasswordStrengthBar from 'components/ui/PasswordStrengthBar'
import { useAvailableOrioleImageVersion } from 'data/config/project-creation-postgres-versions-query'
import { useOverdueInvoicesQuery } from 'data/invoices/invoices-overdue-query'
import { useDefaultRegionQuery } from 'data/misc/get-default-region-query'
@@ -43,93 +47,30 @@ import {
ProjectCreateVariables,
useProjectCreateMutation,
} from 'data/projects/project-create-mutation'
-import { useCustomContent } from 'hooks/custom-content/useCustomContent'
import { useAsyncCheckPermissions } from 'hooks/misc/useCheckPermissions'
import { useIsFeatureEnabled } from 'hooks/misc/useIsFeatureEnabled'
import { useLocalStorageQuery } from 'hooks/misc/useLocalStorage'
import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization'
import { withAuth } from 'hooks/misc/withAuth'
-import { getCloudProviderArchitecture } from 'lib/cloudprovider-utils'
import {
- AWS_REGIONS_DEFAULT,
DEFAULT_MINIMUM_PASSWORD_STRENGTH,
DOCS_URL,
- FLY_REGIONS_DEFAULT,
MANAGED_BY,
PROJECT_STATUS,
PROVIDERS,
useDefaultProvider,
} from 'lib/constants'
-import passwordStrength from 'lib/password-strength'
-import { generateStrongPassword } from 'lib/project'
import { useTrack } from 'lib/telemetry/track'
import { AWS_REGIONS, type CloudProvider } from 'shared-data'
import type { NextPageWithLayout } from 'types'
-import {
- Badge,
- Button,
- Form_Shadcn_,
- FormControl_Shadcn_,
- FormField_Shadcn_,
- Input_Shadcn_,
- Select_Shadcn_,
- SelectContent_Shadcn_,
- SelectGroup_Shadcn_,
- SelectItem_Shadcn_,
- SelectTrigger_Shadcn_,
- SelectValue_Shadcn_,
- Table,
- TableBody,
- TableCell,
- TableHead,
- TableHeader,
- TableRow,
-} from 'ui'
+import { Button, Form_Shadcn_, FormField_Shadcn_ } from 'ui'
import { Admonition } from 'ui-patterns/admonition'
-import { Input } from 'ui-patterns/DataInputs/Input'
import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal'
-import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
-import { InfoTooltip } from 'ui-patterns/info-tooltip'
-
-// [Joshen] This page is getting rather big and complex, let's aim to break this down into smaller components
-
-const sizes: DesiredInstanceSize[] = ['micro', 'small', 'medium']
const sizesWithNoCostConfirmationRequired: DesiredInstanceSize[] = ['micro', 'small']
-const FormSchema = z.object({
- organization: z.string({
- required_error: 'Please select an organization',
- }),
- projectName: z
- .string()
- .trim()
- .min(1, 'Please enter a project name.') // Required field check
- .min(3, 'Project name must be at least 3 characters long.') // Minimum length check
- .max(64, 'Project name must be no longer than 64 characters.'), // Maximum length check
- postgresVersion: z.string({
- required_error: 'Please enter a Postgres version.',
- }),
- dbRegion: z.string({
- required_error: 'Please select a region.',
- }),
- cloudProvider: z.string({
- required_error: 'Please select a cloud provider.',
- }),
- dbPassStrength: z.number(),
- dbPass: z
- .string({ required_error: 'Please enter a database password.' })
- .min(1, 'Password is required.'),
- instanceSize: z.string().optional(),
- dataApi: z.boolean(),
- useApiSchema: z.boolean(),
- postgresVersionSelection: z.string(),
- useOrioleDb: z.boolean(),
-})
-
-export type CreateProjectForm = z.infer<typeof FormSchema>
-
const Wizard: NextPageWithLayout = () => {
+ const track = useTrack()
const router = useRouter()
const { slug, projectName } = useParams()
const defaultProvider = useDefaultProvider()
@@ -143,6 +84,7 @@ const Wizard: NextPageWithLayout = () => {
''
)
const { can: isAdmin } = useAsyncCheckPermissions(PermissionAction.CREATE, 'projects')
+ const showAdvancedConfig = useIsFeatureEnabled('project_creation:show_advanced_config')
const smartRegionEnabled = useFlag('enableSmartRegion')
const projectCreationDisabled = useFlag('disableProjectCreationAndUpdate')
@@ -150,11 +92,9 @@ const Wizard: NextPageWithLayout = () => {
const cloudProviderEnabled = useFlag('enableFlyCloudProvider')
const isHomeNew = useFlag('homeNew')
- const showAdvancedConfig = useIsFeatureEnabled('project_creation:show_advanced_config')
- const { infraCloudProviders: validCloudProviders } = useCustomContent(['infra:cloud_providers'])
-
const showNonProdFields = process.env.NEXT_PUBLIC_ENVIRONMENT !== 'prod'
const isManagedByVercel = currentOrg?.managed_by === 'vercel-marketplace'
+ const isNotOnTeamOrEnterprisePlan = !['team', 'enterprise'].includes(currentOrg?.plan.id ?? '')
// This is to make the database.new redirect work correctly. The database.new redirect should be set to supabase.com/dashboard/new/last-visited-org
if (slug === 'last-visited-org') {
@@ -171,8 +111,6 @@ const Wizard: NextPageWithLayout = () => {
const [isComputeCostsConfirmationModalVisible, setIsComputeCostsConfirmationModalVisible] =
useState(false)
- const track = useTrack()
-
FormSchema.superRefine(({ dbPassStrength }, refinementContext) => {
if (dbPassStrength < DEFAULT_MINIMUM_PASSWORD_STRENGTH) {
refinementContext.addIssue({
@@ -210,56 +148,27 @@ const Wizard: NextPageWithLayout = () => {
// default instance size in this case.
const instanceSize = canChooseInstanceSize ? watchedInstanceSize ?? sizes[0] : undefined
- const { data: membersExceededLimit } = useFreeProjectLimitCheckQuery(
+ const { data: membersExceededLimit = [] } = useFreeProjectLimitCheckQuery(
{ slug },
{ enabled: isFreePlan }
)
- const hasMembersExceedingFreeTierLimit = (membersExceededLimit || []).length > 0
+ const hasMembersExceedingFreeTierLimit = membersExceededLimit.length > 0
const freePlanWithExceedingLimits = isFreePlan && hasMembersExceedingFreeTierLimit
- const { data: organizations, isSuccess: isOrganizationsSuccess } = useOrganizationsQuery()
- const isInvalidSlug = isOrganizationsSuccess && currentOrg === undefined
- const orgNotFound = isOrganizationsSuccess && (organizations?.length ?? 0) > 0 && isInvalidSlug
- const isEmptyOrganizations = (organizations?.length ?? 0) <= 0 && isOrganizationsSuccess
+ const { data: organizations = [], isSuccess: isOrganizationsSuccess } = useOrganizationsQuery()
+ const isEmptyOrganizations = isOrganizationsSuccess && organizations.length <= 0
- const { data: approvedOAuthApps } = useAuthorizedAppsQuery(
+ const { data: approvedOAuthApps = [] } = useAuthorizedAppsQuery(
{ slug },
{ enabled: !isFreePlan && slug !== '_' }
)
- const hasOAuthApps = approvedOAuthApps && approvedOAuthApps.length > 0
-
- const isNotOnTeamOrEnterprisePlan = useMemo(
- () => !['team', 'enterprise'].includes(currentOrg?.plan.id ?? ''),
- [currentOrg]
- )
+ const hasOAuthApps = approvedOAuthApps.length > 0
- const { data: allOverdueInvoices } = useOverdueInvoicesQuery({
+ const { data: allOverdueInvoices = [] } = useOverdueInvoicesQuery({
enabled: isNotOnTeamOrEnterprisePlan,
})
- const overdueInvoices = (allOverdueInvoices ?? []).filter(
- (x) => x.organization_id === currentOrg?.id
- )
- const hasOutstandingInvoices = overdueInvoices.length > 0 && isNotOnTeamOrEnterprisePlan
-
- const {
- mutate: createProject,
- isLoading: isCreatingNewProject,
- isSuccess: isSuccessNewProject,
- } = useProjectCreateMutation({
- onSuccess: (res) => {
- track(
- 'project_creation_simple_version_submitted',
- {
- instanceSize: form.getValues('instanceSize'),
- },
- {
- project: res.ref,
- organization: res.organization_slug,
- }
- )
- router.push(isHomeNew ? `/project/${res.ref}` : `/project/${res.ref}/building`)
- },
- })
+ const overdueInvoices = allOverdueInvoices.filter((x) => x.organization_id === currentOrg?.id)
+ const hasOutstandingInvoices = isNotOnTeamOrEnterprisePlan && overdueInvoices.length > 0
const { data: orgProjectsFromApi } = useOrgProjectsInfiniteQuery({ slug: currentOrg?.slug })
const allOrgProjects = useMemo(
@@ -268,6 +177,10 @@ const Wizard: NextPageWithLayout = () => {
)
const organizationProjects =
allProjects?.filter((project) => project.status !== PROJECT_STATUS.INACTIVE) ?? []
+ const availableComputeCredits = organizationProjects.length === 0 ? 10 : 0
+ const additionalMonthlySpend = isFreePlan
+ ? 0
+ : instanceSizeSpecs[instanceSize as DesiredInstanceSize]!.priceMonthly - availableComputeCredits
const { data: _defaultRegion, error: defaultRegionError } = useDefaultRegionQuery(
{
@@ -326,45 +239,25 @@ const Wizard: NextPageWithLayout = () => {
{ enabled: currentOrg !== null && !isManagedByVercel }
)
- // [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
-
- const availableComputeCredits = organizationProjects.length === 0 ? 10 : 0
-
- const additionalMonthlySpend = isFreePlan
- ? 0
- : instanceSizeSpecs[instanceSize as DesiredInstanceSize]!.priceMonthly - availableComputeCredits
-
- async function checkPasswordStrength(value: any) {
- const { message, warning, strength } = await passwordStrength(value)
-
- form.setValue('dbPassStrength', strength)
- form.trigger('dbPassStrength')
- form.trigger('dbPass')
-
- setPasswordStrengthWarning(warning)
- setPasswordStrengthMessage(message)
- }
- const delayedCheckPasswordStrength = useRef(
- debounce((value) => checkPasswordStrength(value), 300)
- ).current
-
- // [Refactor] DB Password could be a common component used in multiple pages with repeated logic
- function generatePassword() {
- const password = generateStrongPassword()
- form.setValue('dbPass', password)
- delayedCheckPasswordStrength(password)
- }
+ const {
+ mutate: createProject,
+ isLoading: isCreatingNewProject,
+ isSuccess: isSuccessNewProject,
+ } = useProjectCreateMutation({
+ onSuccess: (res) => {
+ track(
+ 'project_creation_simple_version_submitted',
+ {
+ instanceSize: form.getValues('instanceSize'),
+ },
+ {
+ project: res.ref,
+ organization: res.organization_slug,
+ }
+ )
+ router.push(isHomeNew ? `/project/${res.ref}` : `/project/${res.ref}/building`)
+ },
+ })
const onSubmitWithComputeCostsConfirmation = async (values: z.infer<typeof FormSchema>) => {
const launchingLargerInstance =
@@ -504,418 +397,44 @@ const Wizard: NextPageWithLayout = () => {
</div>
}
footer={
- <div key="panel-footer" className="grid grid-cols-12 w-full gap-4 items-center">
- <div className="col-span-4">
- {!isFreePlan &&
- !projectCreationDisabled &&
- canCreateProject &&
- additionalMonthlySpend > 0 && (
- <div className="flex justify-between text-sm">
- <span>Additional costs</span>
- <div className="text-brand flex gap-1 items-center font-mono font-medium">
- <span>${additionalMonthlySpend}/m</span>
- <InfoTooltip side="top" className="max-w-[450px] p-0">
- <div className="p-4 text-sm text-foreground-light space-y-1">
- <p>
- Each project includes a dedicated Postgres instance running on its own
- server. You are charged for the{' '}
- <InlineLink href={`${DOCS_URL}/guides/platform/billing-on-supabase`}>
- Compute resource
- </InlineLink>{' '}
- of that server, independent of your database usage.
- </p>
- {monthlyComputeCosts > 0 && (
- <p>
- Compute costs are applied on top of your subscription plan costs.
- </p>
- )}
- </div>
-
- <Table className="mt-2">
- <TableHeader className="[&_th]:h-7">
- <TableRow className="py-2">
- <TableHead className="w-[170px]">Project</TableHead>
- <TableHead>Compute Size</TableHead>
- <TableHead className="text-right">Monthly Costs</TableHead>
- </TableRow>
- </TableHeader>
- <TableBody className="[&_td]:py-2">
- {organizationProjects.map((project) => {
- const primaryDb = project.databases.find(
- (db) => db.identifier === project.ref
- )
- return (
- <TableRow key={project.ref} className="text-foreground-light">
- <TableCell className="w-[170px] truncate">
- {project.name}
- </TableCell>
- <TableCell className="text-center">
- {instanceLabel(primaryDb?.infra_compute_size)}
- </TableCell>
- <TableCell className="text-right">
- ${monthlyInstancePrice(primaryDb?.infra_compute_size)}
- </TableCell>
- </TableRow>
- )
- })}
-
- <TableRow>
- <TableCell className="w-[170px] flex gap-2">
- <span className="truncate">
- {form.getValues('projectName')
- ? form.getValues('projectName')
- : 'New project'}
- </span>
- <Badge size={'small'} variant={'default'}>
- NEW
- </Badge>
- </TableCell>
- <TableCell className="text-center">
- {instanceLabel(instanceSize)}
- </TableCell>
- <TableCell className="text-right">
- ${monthlyInstancePrice(instanceSize)}
- </TableCell>
- </TableRow>
- </TableBody>
- </Table>
- <PopoverSeparator />
- <Table>
- <TableHeader className="[&_th]:h-7">
- <TableRow>
- <TableHead colSpan={2}>Compute Credits</TableHead>
- <TableHead colSpan={1} className="text-right">
- -$10
- </TableHead>
- </TableRow>
- </TableHeader>
- <TableBody className="[&_td]:py-2">
- <TableRow className="text-foreground">
- <TableCell colSpan={2}>
- 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 && (
- <p className="text-xs text-foreground-lighter">
- Excluding Read replicas
- </p>
- )}
- </TableCell>
- <TableCell colSpan={1} className="text-right">
- ${monthlyComputeCosts}
- </TableCell>
- </TableRow>
- </TableBody>
- </Table>
- </InfoTooltip>
- </div>
- </div>
- )}
- </div>
-
- <div className="flex items-end col-span-8 space-x-2 ml-auto">
- <Button
- type="default"
- disabled={isCreatingNewProject || isSuccessNewProject}
- onClick={() => {
- if (!!lastVisitedOrganization) router.push(`/org/${lastVisitedOrganization}`)
- else router.push('/organizations')
- }}
- >
- Cancel
- </Button>
- <Button
- htmlType="submit"
- loading={isCreatingNewProject || isSuccessNewProject}
- disabled={!canCreateProject || isCreatingNewProject || isSuccessNewProject}
- >
- Create new project
- </Button>
- </div>
- </div>
+ <ProjectCreationFooter
+ form={form}
+ canCreateProject={canCreateProject}
+ instanceSize={instanceSize}
+ organizationProjects={organizationProjects}
+ isCreatingNewProject={isCreatingNewProject}
+ isSuccessNewProject={isSuccessNewProject}
+ />
}
>
<>
{projectCreationDisabled ? (
- <Panel.Content className="pb-8">
- <DisabledWarningDueToIncident title="Project creation is currently disabled" />
- </Panel.Content>
+ <DisabledWarningDueToIncident title="Project creation is currently disabled" />
) : (
<div className="divide-y divide-border-muted">
- <Panel.Content className={['space-y-4'].join(' ')}>
- {isAdmin && !isInvalidSlug && (
- <FormField_Shadcn_
- control={form.control}
- name="organization"
- render={({ field }) => (
- <FormItemLayout label="Organization" layout="horizontal">
- {(organizations?.length ?? 0) > 0 && (
- <Select_Shadcn_
- onValueChange={(slug) => {
- field.onChange(slug)
- router.push(`/new/${slug}`)
- }}
- value={field.value}
- defaultValue={field.value}
- >
- <FormControl_Shadcn_>
- <SelectTrigger_Shadcn_>
- <SelectValue_Shadcn_ placeholder="Select an organization" />
- </SelectTrigger_Shadcn_>
- </FormControl_Shadcn_>
- <SelectContent_Shadcn_>
- <SelectGroup_Shadcn_>
- {organizations?.map((x) => (
- <SelectItem_Shadcn_
- key={x.id}
- value={x.slug}
- className="flex justify-between"
- >
- <span className="mr-2">{x.name}</span>
- <Badge>{x.plan.name}</Badge>
- </SelectItem_Shadcn_>
- ))}
- </SelectGroup_Shadcn_>
- </SelectContent_Shadcn_>
- </Select_Shadcn_>
- )}
- </FormItemLayout>
- )}
- />
- )}
-
- {isOrganizationsSuccess && !isAdmin && !orgNotFound && (
- <NotOrganizationOwnerWarning slug={slug} />
- )}
- {orgNotFound && <OrgNotFound slug={slug} />}
- </Panel.Content>
+ <OrganizationSelector form={form} />
{canCreateProject && (
<>
- <Panel.Content>
- <FormField_Shadcn_
- control={form.control}
- name="projectName"
- render={({ field }) => (
- <FormItemLayout label="Project name" layout="horizontal">
- <FormControl_Shadcn_>
- <Input_Shadcn_ {...field} placeholder="Project name" />
- </FormControl_Shadcn_>
- </FormItemLayout>
- )}
- />
- </Panel.Content>
+ <ProjectNameInput form={form} />
{cloudProviderEnabled && showNonProdFields && (
- <Panel.Content>
- <FormField_Shadcn_
- control={form.control}
- name="cloudProvider"
- render={({ field }) => (
- <FormItemLayout label="Cloud provider" layout="horizontal">
- <Select_Shadcn_
- onValueChange={(value) => {
- field.onChange(value)
- form.setValue(
- 'dbRegion',
- value === 'FLY'
- ? FLY_REGIONS_DEFAULT.displayName
- : AWS_REGIONS_DEFAULT.displayName
- )
- }}
- defaultValue={field.value}
- >
- <FormControl_Shadcn_>
- <SelectTrigger_Shadcn_>
- <SelectValue_Shadcn_ placeholder="Select a cloud provider" />
- </SelectTrigger_Shadcn_>
- </FormControl_Shadcn_>
- <SelectContent_Shadcn_>
- <SelectGroup_Shadcn_>
- {Object.values(PROVIDERS)
- .filter(
- (provider) =>
- validCloudProviders?.includes(provider.id) ?? true
- )
- .map((providerObj) => {
- const label = providerObj['name']
- const value = providerObj['id']
- return (
- <SelectItem_Shadcn_ key={value} value={value}>
- {label}
- </SelectItem_Shadcn_>
- )
- })}
- </SelectGroup_Shadcn_>
- </SelectContent_Shadcn_>
- </Select_Shadcn_>
- </FormItemLayout>
- )}
- />
- </Panel.Content>
- )}
-
- {canChooseInstanceSize && (
- <Panel.Content>
- <FormField_Shadcn_
- control={form.control}
- name="instanceSize"
- render={({ field }) => (
- <FormItemLayout
- layout="horizontal"
- label="Compute size"
- description={
- <>
- <p>
- The size for your dedicated database. You can change this later.
- Learn more about{' '}
- <InlineLink
- href={`${DOCS_URL}/guides/platform/compute-add-ons`}
- >
- compute add-ons
- </InlineLink>{' '}
- and{' '}
- <InlineLink
- href={`${DOCS_URL}/guides/platform/manage-your-usage/compute`}
- >
- compute billing
- </InlineLink>
- .
- </p>
- </>
- }
- >
- <Select_Shadcn_
- value={field.value}
- onValueChange={(value) => field.onChange(value)}
- >
- <SelectTrigger_Shadcn_ className="[&_.instance-details]:hidden">
- <SelectValue_Shadcn_ placeholder="Select a compute size" />
- </SelectTrigger_Shadcn_>
- <SelectContent_Shadcn_>
- <SelectGroup_Shadcn_>
- {sizes
- .filter((option) =>
- instanceSizeSpecs[option].cloud_providers.includes(
- form.getValues('cloudProvider') as CloudProvider
- )
- )
- .map((option) => {
- return (
- <SelectItem_Shadcn_ key={option} value={option}>
- <div className="flex flex-row i gap-2">
- <div className="text-center w-[80px]">
- <Badge
- variant={option === 'micro' ? 'default' : 'brand'}
- className="rounded-md w-16 text-center flex justify-center font-mono uppercase"
- >
- {instanceSizeSpecs[option].label}
- </Badge>
- </div>
- <div className="text-sm">
- <span className="text-foreground">
- {instanceSizeSpecs[option].ram} RAM /{' '}
- {instanceSizeSpecs[option].cpu}{' '}
- {getCloudProviderArchitecture(
- form.getValues('cloudProvider') as CloudProvider
- )}{' '}
- CPU
- </span>
- <p
- className="text-xs text-foreground-light instance-details"
- translate="no"
- >
- ${instanceSizeSpecs[option].priceHourly}/hour (~$
- {instanceSizeSpecs[option].priceMonthly}/month)
- </p>
- </div>
- </div>
- </SelectItem_Shadcn_>
- )
- })}
- <SelectItem_Shadcn_
- key={'disabled'}
- value={'disabled'}
- disabled
- >
- <div className="flex items-center justify-center w-full">
- <span>Larger instance sizes available after creation</span>
- </div>
- </SelectItem_Shadcn_>
- </SelectGroup_Shadcn_>
- </SelectContent_Shadcn_>
- </Select_Shadcn_>
- </FormItemLayout>
- )}
- />
- </Panel.Content>
+ <CloudProviderSelector form={form} />
)}
- <Panel.Content>
- <FormField_Shadcn_
- control={form.control}
- name="dbPass"
- render={({ field }) => {
- const hasSpecialCharacters =
- field.value.length > 0 && !field.value.match(SPECIAL_CHARS_REGEX)
+ {canChooseInstanceSize && <ComputeSizeSelector form={form} />}
- return (
- <FormItemLayout
- label="Database password"
- layout="horizontal"
- description={
- <>
- {hasSpecialCharacters && <SpecialSymbolsCallout />}
- <PasswordStrengthBar
- passwordStrengthScore={form.getValues('dbPassStrength')}
- password={field.value}
- passwordStrengthMessage={passwordStrengthMessage}
- generateStrongPassword={generatePassword}
- />
- </>
- }
- >
- <FormControl_Shadcn_>
- <Input
- copy={field.value.length > 0}
- type="password"
- placeholder="Type in a strong password"
- {...field}
- autoComplete="off"
- onChange={async (event) => {
- field.onChange(event)
- form.trigger('dbPassStrength')
- const value = event.target.value
- if (event.target.value === '') {
- await form.setValue('dbPassStrength', 0)
- await form.trigger('dbPass')
- } else {
- await delayedCheckPasswordStrength(value)
- }
- }}
- />
- </FormControl_Shadcn_>
- </FormItemLayout>
- )
- }}
- />
- </Panel.Content>
+ <DatabasePasswordInput
+ form={form}
+ passwordStrengthMessage={passwordStrengthMessage}
+ setPasswordStrengthMessage={setPasswordStrengthMessage}
+ setPasswordStrengthWarning={setPasswordStrengthWarning}
+ />
- <Panel.Content>
- <FormField_Shadcn_
- control={form.control}
- name="dbRegion"
- render={({ field }) => (
- <RegionSelector
- field={field}
- cloudProvider={form.getValues('cloudProvider') as CloudProvider}
- instanceSize={instanceSize as DesiredInstanceSize}
- />
- )}
- />
- </Panel.Content>
+ <RegionSelector
+ form={form}
+ instanceSize={instanceSize as DesiredInstanceSize}
+ />
{showPostgresVersionSelector && (
<Panel.Content>
@@ -935,29 +454,7 @@ const Wizard: NextPageWithLayout = () => {
</Panel.Content>
)}
- {showNonProdFields && (
- <Panel.Content>
- <FormField_Shadcn_
- control={form.control}
- name="postgresVersion"
- render={({ field }) => (
- <FormItemLayout
- label="Custom Postgres version"
- layout="horizontal"
- description="Specify a custom version of Postgres (defaults to the latest). This is only applicable for local/staging projects."
- >
- <FormControl_Shadcn_>
- <Input_Shadcn_
- placeholder="Postgres version"
- {...field}
- autoComplete="off"
- />
- </FormControl_Shadcn_>
- </FormItemLayout>
- )}
- />
- </Panel.Content>
- )}
+ {showNonProdFields && <CustomPostgresVersionInput form={form} />}
<SecurityOptions form={form} />
{showAdvancedConfig && !!availableOrioleVersion && (
@@ -969,9 +466,7 @@ const Wizard: NextPageWithLayout = () => {
{freePlanWithExceedingLimits ? (
isAdmin &&
slug && (
- <Panel.Content>
- <FreeProjectLimitWarning membersExceededLimit={membersExceededLimit || []} />
- </Panel.Content>
+ <FreeProjectLimitWarning membersExceededLimit={membersExceededLimit || []} />
)
) : isManagedByVercel ? (
<Panel.Content>
@@ -1046,20 +541,6 @@ const Wizard: NextPageWithLayout = () => {
)
}
-/**
- * When launching new projects, they only get assigned a compute size once successfully launched,
- * this might assume wrong compute size, but only for projects being rapidly launched after one another on non-default compute sizes.
- *
- * Needs to be in the API in the future [kevin]
- */
-const monthlyInstancePrice = (instance: string | undefined): number => {
- return instanceSizeSpecs[instance as DesiredInstanceSize]?.priceMonthly || 10
-}
-
-const instanceLabel = (instance: string | undefined): string => {
- return instanceSizeSpecs[instance as DesiredInstanceSize]?.label || 'Micro'
-}
-
const PageLayout = withAuth(({ children }: PropsWithChildren) => {
return <WizardLayoutWithoutAuth>{children}</WizardLayoutWithoutAuth>
})