Skip to content

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

Revert "[Dashboard] New project form now using react-hook-form" (#26995)

Alaister Young99af0e44833d
diff --git a/apps/studio/components/interfaces/ProjectCreation/RegionSelector.tsx b/apps/studio/components/interfaces/ProjectCreation/RegionSelector.tsx
index 120a9dbbbbb..dc0e81b0deb 100644
--- a/apps/studio/components/interfaces/ProjectCreation/RegionSelector.tsx
+++ b/apps/studio/components/interfaces/ProjectCreation/RegionSelector.tsx
@@ -1,29 +1,24 @@
-import { useDefaultRegionQuery } from 'data/misc/get-default-region-query'
import { CloudProvider, PROVIDERS } from 'lib/constants'
import { useRouter } from 'next/router'
import { useEffect } from 'react'
-import { ControllerRenderProps, UseFormReturn } from 'react-hook-form'
-import {
- SelectContent_Shadcn_,
- SelectGroup_Shadcn_,
- SelectItem_Shadcn_,
- SelectTrigger_Shadcn_,
- SelectValue_Shadcn_,
- Select_Shadcn_,
-} from 'ui'
-import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
+import { Listbox } from 'ui'
+
+import { useDefaultRegionQuery } from 'data/misc/get-default-region-query'
import { getAvailableRegions } from './ProjectCreation.utils'
interface RegionSelectorProps {
cloudProvider: CloudProvider
- field: ControllerRenderProps<any, 'dbRegion'>
- form: UseFormReturn<any>
+ selectedRegion: string
+ onSelectRegion: (value: string) => void
}
-export const RegionSelector = ({ cloudProvider, field, form }: RegionSelectorProps) => {
+export const RegionSelector = ({
+ cloudProvider,
+ selectedRegion,
+ onSelectRegion,
+}: RegionSelectorProps) => {
const router = useRouter()
const availableRegions = getAvailableRegions(PROVIDERS[cloudProvider].id)
-
const {
data: region,
isSuccess,
@@ -35,49 +30,45 @@ export const RegionSelector = ({ cloudProvider, field, form }: RegionSelectorPro
useEffect(() => {
// only pick a region if one hasn't already been selected
- if (isError && !field.value) {
+ if (isSuccess && region && !selectedRegion) {
+ onSelectRegion(region)
+ } else if (isError && !selectedRegion) {
// if an error happened, and the user haven't selected a region, just select the default one for him
- form.setValue('dbRegion', PROVIDERS[cloudProvider].default_region)
+ onSelectRegion(PROVIDERS[cloudProvider].default_region)
}
- }, [cloudProvider, isError, isSuccess, field.value, form])
+ }, [cloudProvider, isError, isSuccess, region, selectedRegion])
return (
- <FormItemLayout
+ <Listbox
layout="horizontal"
label="Region"
- description="Select the region closest to your users for the best performance."
+ type="select"
+ value={selectedRegion}
+ onChange={(value) => onSelectRegion(value)}
+ descriptionText="Select the region closest to your users for the best performance."
>
- <Select_Shadcn_
- value={field.value}
- onValueChange={(value) => {
- if (isSuccess && region && !field.value) {
- field.onChange(value)
- }
- }}
- >
- <SelectTrigger_Shadcn_>
- <SelectValue_Shadcn_ placeholder="Select a region for your project.." />
- </SelectTrigger_Shadcn_>
- <SelectContent_Shadcn_>
- <SelectGroup_Shadcn_>
- {Object.keys(availableRegions).map((option: string, i) => {
- const label = Object.values(availableRegions)[i] as string
- return (
- <SelectItem_Shadcn_ key={option} value={label}>
- <div className="flex items-center gap-3">
- <img
- alt="region icon"
- className="w-5 rounded-sm"
- src={`${router.basePath}/img/regions/${Object.keys(availableRegions)[i]}.svg`}
- />
- <span className="text-foreground">{label}</span>
- </div>
- </SelectItem_Shadcn_>
- )
- })}
- </SelectGroup_Shadcn_>
- </SelectContent_Shadcn_>
- </Select_Shadcn_>
- </FormItemLayout>
+ <Listbox.Option disabled key="empty" label="---" value="">
+ <span className="text-foreground">Select a region for your project</span>
+ </Listbox.Option>
+ {Object.keys(availableRegions).map((option: string, i) => {
+ const label = Object.values(availableRegions)[i] as string
+ return (
+ <Listbox.Option
+ key={option}
+ label={label}
+ value={label}
+ addOnBefore={() => (
+ <img
+ alt="region icon"
+ className="w-5 rounded-sm"
+ src={`${router.basePath}/img/regions/${Object.keys(availableRegions)[i]}.svg`}
+ />
+ )}
+ >
+ <span className="text-foreground">{label}</span>
+ </Listbox.Option>
+ )
+ })}
+ </Listbox>
)
}
diff --git a/apps/studio/components/interfaces/Settings/API/PostgrestConfig.tsx b/apps/studio/components/interfaces/Settings/API/PostgrestConfig.tsx
index 171494f2053..836dde124d4 100644
--- a/apps/studio/components/interfaces/Settings/API/PostgrestConfig.tsx
+++ b/apps/studio/components/interfaces/Settings/API/PostgrestConfig.tsx
@@ -1,12 +1,5 @@
import { zodResolver } from '@hookform/resolvers/zod'
import { PermissionAction } from '@supabase/shared-types/out/constants'
-import { indexOf } from 'lodash'
-import Link from 'next/link'
-import { useEffect } from 'react'
-import { useForm } from 'react-hook-form'
-import toast from 'react-hot-toast'
-import { z } from 'zod'
-
import { useParams } from 'common'
import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
import {
@@ -18,9 +11,15 @@ import {
} from 'components/ui/Forms'
import { useProjectPostgrestConfigQuery } from 'data/config/project-postgrest-config-query'
import { useProjectPostgrestConfigUpdateMutation } from 'data/config/project-postgrest-config-update-mutation'
+import { useDatabaseExtensionDisableMutation } from 'data/database-extensions/database-extension-disable-mutation'
import { useDatabaseExtensionsQuery } from 'data/database-extensions/database-extensions-query'
import { useSchemasQuery } from 'data/database/schemas-query'
import { useCheckPermissions } from 'hooks'
+import { indexOf } from 'lodash'
+import Link from 'next/link'
+import { useEffect } from 'react'
+import { useForm } from 'react-hook-form'
+import toast from 'react-hot-toast'
import {
Admonition,
AlertDescription_Shadcn_,
@@ -38,6 +37,7 @@ import {
Skeleton,
Switch,
} from 'ui'
+import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal'
import { WarningIcon } from 'ui-patterns/Icons/StatusIcons'
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
import {
@@ -48,6 +48,7 @@ import {
MultiSelectorList,
MultiSelectorTrigger,
} from 'ui-patterns/multi-select'
+import { z } from 'zod'
const formSchema = z
.object({
diff --git a/apps/studio/components/layouts/ProjectLayout/BuildingState.tsx b/apps/studio/components/layouts/ProjectLayout/BuildingState.tsx
index 78777a23cc8..84e5429d32b 100644
--- a/apps/studio/components/layouts/ProjectLayout/BuildingState.tsx
+++ b/apps/studio/components/layouts/ProjectLayout/BuildingState.tsx
@@ -13,7 +13,6 @@ import { invalidateProjectsQuery } from 'data/projects/projects-query'
import { useSelectedProject } from 'hooks'
import { getWithTimeout } from 'lib/common/fetch'
import { API_URL, PROJECT_STATUS } from 'lib/constants'
-import { Loader2 } from 'lucide-react'
const BuildingState = () => {
const { ref } = useParams()
@@ -54,9 +53,9 @@ const BuildingState = () => {
<div className=" flex flex-col gap-4">
<div className="flex items-center space-x-3">
<h1 className="text-3xl text-foreground">{project?.name}</h1>
- <Badge variant="default" className="bg-surface-100 bg-opacity-100">
+ <Badge variant="brand">
<div className="flex items-center gap-2">
- <Loader2 className="animate-spin" size={12} />
+ <IconLoader className="animate-spin" size={12} />
<span>
{project.status === PROJECT_STATUS.UNKNOWN
? 'Initiating project set up'
diff --git a/apps/studio/components/ui/PasswordStrengthBar.tsx b/apps/studio/components/ui/PasswordStrengthBar.tsx
index 45fdc93b2c7..4ee9414cdb3 100644
--- a/apps/studio/components/ui/PasswordStrengthBar.tsx
+++ b/apps/studio/components/ui/PasswordStrengthBar.tsx
@@ -22,13 +22,13 @@ const PasswordStrengthBar = ({
aria-valuenow={(PASSWORD_STRENGTH_PERCENTAGE as any)[passwordStrengthScore]}
aria-valuetext={(PASSWORD_STRENGTH_PERCENTAGE as any)[passwordStrengthScore]}
role="progressbar"
- className="mb-2 overflow-hidden transition-all border rounded bg-200 w-full"
+ className="mb-2 overflow-hidden transition-all border rounded bg-studio"
>
<div
style={{
width: (PASSWORD_STRENGTH_PERCENTAGE as any)[passwordStrengthScore],
}}
- className={`relative h-1 w-full ${
+ className={`relative h-2 w-full ${
(PASSWORD_STRENGTH_COLOR as any)[passwordStrengthScore]
} transition-all duration-500 ease-out shadow-inner`}
></div>
diff --git a/apps/studio/pages/new/[slug].tsx b/apps/studio/pages/new/[slug].tsx
index 76ae989ede1..8e4ee8884e5 100644
--- a/apps/studio/pages/new/[slug].tsx
+++ b/apps/studio/pages/new/[slug].tsx
@@ -1,16 +1,13 @@
-import { zodResolver } from '@hookform/resolvers/zod'
import { PermissionAction } from '@supabase/shared-types/out/constants'
+import { useParams } from 'common'
import generator from 'generate-password-browser'
import { debounce } from 'lodash'
-import { ExternalLink } from 'lucide-react'
import Link from 'next/link'
import { useRouter } from 'next/router'
import { PropsWithChildren, useEffect, useRef, useState } from 'react'
-import { useForm } from 'react-hook-form'
import toast from 'react-hot-toast'
-import { z } from 'zod'
+import { Badge, Button, IconExternalLink, IconUsers, Input, Listbox, Separator } from 'ui'
-import { useParams } from 'common'
import {
FreeProjectLimitWarning,
NotOrganizationOwnerWarning,
@@ -24,35 +21,23 @@ import type { components } from 'data/api'
import { useFreeProjectLimitCheckQuery } from 'data/organizations/free-project-limit-check-query'
import { useOrganizationsQuery } from 'data/organizations/organizations-query'
import {
+ DbInstanceSize,
ProjectCreateVariables,
useProjectCreateMutation,
} from 'data/projects/project-create-mutation'
import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'
import { useCheckPermissions, useFlag, withAuth } from 'hooks'
import {
+ AWS_REGIONS,
CloudProvider,
DEFAULT_MINIMUM_PASSWORD_STRENGTH,
DEFAULT_PROVIDER,
+ FLY_REGIONS,
PROVIDERS,
+ Region,
} from 'lib/constants'
-import { passwordStrength } from 'lib/helpers'
+import { passwordStrength, pluckObjectFields } from 'lib/helpers'
import type { NextPageWithLayout } from 'types'
-import {
- Badge,
- Button,
- FormControl_Shadcn_,
- FormField_Shadcn_,
- Form_Shadcn_,
- Input_Shadcn_,
- SelectContent_Shadcn_,
- SelectGroup_Shadcn_,
- SelectItem_Shadcn_,
- SelectTrigger_Shadcn_,
- SelectValue_Shadcn_,
- Select_Shadcn_,
-} from 'ui'
-import { Input } from 'ui-patterns/DataInputs/Input'
-import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
type DesiredInstanceSize = components['schemas']['DesiredInstanceSize']
@@ -65,8 +50,22 @@ const Wizard: NextPageWithLayout = () => {
const { data: membersExceededLimit, isLoading: isLoadingFreeProjectLimitCheck } =
useFreeProjectLimitCheckQuery({ slug })
+ const [projectName, setProjectName] = useState('')
+ const [postgresVersion, setPostgresVersion] = useState('')
+ const [cloudProvider, setCloudProvider] = useState<CloudProvider>(PROVIDERS[DEFAULT_PROVIDER].id)
+
+ const [dbPass, setDbPass] = useState('')
+ // Auto select region on staging/local for convenience as there's only one supported
+ const [dbRegion, setDbRegion] = useState(
+ ['staging', 'local'].includes(process.env.NEXT_PUBLIC_ENVIRONMENT ?? '')
+ ? PROVIDERS[cloudProvider].default_region
+ : ''
+ )
const [passwordStrengthMessage, setPasswordStrengthMessage] = useState('')
const [passwordStrengthWarning, setPasswordStrengthWarning] = useState('')
+ const [passwordStrengthScore, setPasswordStrengthScore] = useState(0)
+
+ const [instanceSize, setInstanceSize] = useState<DbInstanceSize>('micro')
const { data: organizations, isSuccess: isOrganizationsSuccess } = useOrganizationsQuery()
const currentOrg = organizations?.find((o: any) => o.slug === slug)
@@ -97,21 +96,129 @@ const Wizard: NextPageWithLayout = () => {
const canCreateProject = isAdmin && !freePlanWithExceedingLimits
+ const canSubmit =
+ projectName !== '' &&
+ passwordStrengthScore >= DEFAULT_MINIMUM_PASSWORD_STRENGTH &&
+ dbRegion !== undefined
+
const delayedCheckPasswordStrength = useRef(
debounce((value) => checkPasswordStrength(value), 300)
).current
- async function checkPasswordStrength(value: any) {
- const { message, warning, strength } = await passwordStrength(value)
+ useEffect(() => {
+ /*
+ * Handle no org
+ * redirect to new org route
+ */
+ if (isEmptyOrganizations) {
+ router.push(`/new`)
+ }
+ }, [isEmptyOrganizations, router])
+
+ useEffect(() => {
+ /*
+ * Redirect to first org if the slug doesn't match an org slug
+ * this is mainly to capture the /new/new-project url, which is redirected from database.new
+ */
+ if (isInvalidSlug && (organizations?.length ?? 0) > 0) {
+ router.push(`/new/${organizations?.[0].slug}`)
+ }
+ }, [isInvalidSlug, organizations])
+
+ useEffect(() => {
+ // User added a new payment method
+ if (router.query.setup_intent && router.query.redirect_status) {
+ toast.success('Successfully added new payment method')
+ }
+ }, [router.query.redirect_status, router.query.setup_intent])
+
+ function onProjectNameChange(e: any) {
+ e.target.value = e.target.value.replace(/\./g, '')
+ setProjectName(e.target.value)
+ }
+
+ function onDbPassChange(e: any) {
+ const value = e.target.value
+ setDbPass(value)
+ if (value == '') {
+ setPasswordStrengthScore(-1)
+ setPasswordStrengthMessage('')
+ } else delayedCheckPasswordStrength(value)
+ }
- form.setValue('dbPassStrength', strength)
- form.trigger('dbPassStrength')
- form.trigger('dbPass')
+ function onCloudProviderChange(cloudProviderId: CloudProvider) {
+ setCloudProvider(cloudProviderId)
+ // on local/staging quick-select the default region, don't wait for the cloudflare location
+ setDbRegion(
+ ['staging', 'local'].includes(process.env.NEXT_PUBLIC_ENVIRONMENT ?? '')
+ ? PROVIDERS[cloudProviderId].default_region
+ : ''
+ )
+ }
+ async function checkPasswordStrength(value: any) {
+ const { message, warning, strength } = await passwordStrength(value)
+ setPasswordStrengthScore(strength)
setPasswordStrengthWarning(warning)
setPasswordStrengthMessage(message)
}
+ const onClickNext = async () => {
+ if (!currentOrg) return console.error('Unable to retrieve current organization')
+
+ const data: ProjectCreateVariables = {
+ cloudProvider,
+ organizationId: currentOrg.id,
+ name: projectName.trim(),
+ dbPass: dbPass,
+ dbRegion: dbRegion,
+ // gets ignored due to org billing subscription anyway
+ dbPricingTierId: 'tier_free',
+ // only set the instance size on pro+ plans. Free plans always use micro (nano in the future) size.
+ dbInstanceSize: orgSubscription?.plan.id === 'free' ? undefined : instanceSize,
+ }
+ if (postgresVersion) {
+ if (!postgresVersion.match(/1[2-9]\..*/)) {
+ toast.error(
+ `Invalid Postgres version, should start with a number between 12-19, a dot and additional characters, i.e. 15.2 or 15.2.0-3`
+ )
+ }
+
+ data['customSupabaseRequest'] = {
+ ami: { search_tags: { 'tag:postgresVersion': postgresVersion } },
+ }
+ }
+
+ createProject(data)
+ }
+
+ // [Joshen] Refactor: DB Password could be a common component
+ // used in multiple pages with repeated logic
+ function generateStrongPassword() {
+ const password = generator.generate({
+ length: 16,
+ numbers: true,
+ uppercase: true,
+ })
+
+ setDbPass(password)
+ delayedCheckPasswordStrength(password)
+ }
+
+ // [Fran] Enforce APSE1 region on staging
+ function getAvailableRegions(cloudProvider: CloudProvider): Region {
+ if (cloudProvider === 'AWS') {
+ return process.env.NEXT_PUBLIC_ENVIRONMENT === 'staging'
+ ? pluckObjectFields(AWS_REGIONS, ['SOUTHEAST_ASIA'])
+ : AWS_REGIONS
+ // to do - may need to pluck regions for staging for FLY also
+ } else if (cloudProvider === 'FLY') {
+ return FLY_REGIONS
+ }
+
+ throw new Error('Invalid cloud provider')
+ }
+
const sizes: DesiredInstanceSize[] = [
'micro',
'small',
@@ -191,473 +298,261 @@ const Wizard: NextPageWithLayout = () => {
},
}
- const FormSchema = z
- .object({
- organization: z.string({
- required_error: 'Please select an organization',
- }),
- projectName: z
- .string()
- .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(),
- })
- .superRefine(({ dbPassStrength }, refinementContext) => {
- if (dbPassStrength < DEFAULT_MINIMUM_PASSWORD_STRENGTH) {
- refinementContext.addIssue({
- code: z.ZodIssueCode.custom,
- path: ['dbPass'],
- message: passwordStrengthWarning || 'Password not secure enough',
- })
- }
- })
-
- const form = useForm<z.infer<typeof FormSchema>>({
- resolver: zodResolver(FormSchema),
- mode: 'onChange',
- defaultValues: {
- organization: slug,
- projectName: '',
- postgresVersion: '',
- cloudProvider: PROVIDERS[DEFAULT_PROVIDER].id,
- dbPass: '',
- dbPassStrength: 0,
- dbRegion: ['staging', 'local'].includes(process.env.NEXT_PUBLIC_ENVIRONMENT ?? '')
- ? PROVIDERS[PROVIDERS[DEFAULT_PROVIDER].id].default_region
- : '',
- instanceSize: sizes[0],
- },
- })
-
- // [Joshen] Refactor: DB Password could be a common component
- // used in multiple pages with repeated logic
- function generateStrongPassword() {
- const password = generator.generate({
- length: 16,
- numbers: true,
- uppercase: true,
- })
-
- form.setValue('dbPass', password)
- form.trigger('dbPass')
- delayedCheckPasswordStrength(password)
- }
-
- const onClickNext = async (values: z.infer<typeof FormSchema>) => {
- if (!currentOrg) return console.error('Unable to retrieve current organization')
-
- const { cloudProvider, projectName, dbPass, dbRegion, postgresVersion, instanceSize } = values
-
- const data: ProjectCreateVariables = {
- cloudProvider: cloudProvider,
- organizationId: currentOrg.id,
- name: projectName,
- dbPass: dbPass,
- dbRegion: dbRegion,
- // gets ignored due to org billing subscription anyway
- dbPricingTierId: 'tier_free',
- // only set the instance size on pro+ plans. Free plans always use micro (nano in the future) size.
- dbInstanceSize:
- orgSubscription?.plan.id === 'free' ? undefined : (instanceSize as DesiredInstanceSize),
- }
- if (postgresVersion) {
- if (!postgresVersion.match(/1[2-9]\..*/)) {
- toast.error(
- `Invalid Postgres version, should start with a number between 12-19, a dot and additional characters, i.e. 15.2 or 15.2.0-3`
- )
+ return (
+ <Panel
+ loading={!isOrganizationsSuccess || isLoadingFreeProjectLimitCheck}
+ title={
+ <div key="panel-title">
+ <h3>Create a new project</h3>
+ <p className="text-sm text-foreground-lighter">
+ Your project will have its own dedicated instance and full postgres database.
+ <br />
+ An API will be set up so you can easily interact with your new database.
+ <br />
+ </p>
+ </div>
}
-
- data['customSupabaseRequest'] = {
- ami: { search_tags: { 'tag:postgresVersion': postgresVersion } },
+ footer={
+ <div key="panel-footer" className="flex items-center justify-between w-full">
+ <Button
+ type="default"
+ disabled={isCreatingNewProject || isSuccessNewProject}
+ onClick={() => router.push('/projects')}
+ >
+ Cancel
+ </Button>
+ <div className="items-center space-x-3">
+ {!projectCreationDisabled && (
+ <span className="text-xs text-foreground-lighter">
+ You can rename your project later
+ </span>
+ )}
+ <Button
+ onClick={onClickNext}
+ loading={isCreatingNewProject || isSuccessNewProject}
+ disabled={isCreatingNewProject || isSuccessNewProject || !canSubmit}
+ >
+ Create new project
+ </Button>
+ </div>
+ </div>
}
- }
-
- createProject(data)
- }
-
- useEffect(() => {
- // Handle no org: redirect to new org route
- if (isEmptyOrganizations) {
- router.push(`/new`)
- }
- }, [isEmptyOrganizations, router])
-
- useEffect(() => {
- // [Joshen] Cause slug depends on router which doesnt load immediately on render
- // While the form data does load immediately
- if (slug) form.setValue('organization', slug)
- }, [slug])
-
- useEffect(() => {
- // Redirect to first org if the slug doesn't match an org slug
- // this is mainly to capture the /new/new-project url, which is redirected from database.new
- if (isInvalidSlug && isOrganizationsSuccess && (organizations?.length ?? 0) > 0) {
- router.push(`/new/${organizations?.[0].slug}`)
- }
- }, [isInvalidSlug, isOrganizationsSuccess, organizations])
-
- return (
- <Form_Shadcn_ {...form}>
- <form onSubmit={form.handleSubmit(onClickNext)}>
- <Panel
- loading={!isOrganizationsSuccess || isLoadingFreeProjectLimitCheck}
- title={
- <div key="panel-title">
- <h3>Create a new project</h3>
- <p className="text-sm text-foreground-lighter">
- Your project will have its own dedicated instance and full postgres database.
- <br />
- An API will be set up so you can easily interact with your new database.
- <br />
- </p>
- </div>
- }
- footer={
- <div key="panel-footer" className="flex items-center justify-between w-full">
- <Button
- type="default"
- disabled={isCreatingNewProject || isSuccessNewProject}
- onClick={() => router.push('/projects')}
- >
- Cancel
- </Button>
- <div className="items-center space-x-3">
- {!projectCreationDisabled && (
- <span className="text-xs text-foreground-lighter">
- You can rename your project later
- </span>
- )}
- <Button
- htmlType="submit"
- loading={isCreatingNewProject || isSuccessNewProject}
- disabled={isCreatingNewProject || isSuccessNewProject}
+ >
+ <>
+ {projectCreationDisabled ? (
+ <Panel.Content className="pb-8">
+ <DisabledWarningDueToIncident title="Project creation is currently disabled" />
+ </Panel.Content>
+ ) : (
+ <div className="divide-y divide-border-muted">
+ <Panel.Content className={['space-y-4'].join(' ')}>
+ {(organizations?.length ?? 0) > 0 && (
+ <Listbox
+ label="Organization"
+ layout="horizontal"
+ value={currentOrg?.slug}
+ onChange={(slug) => router.push(`/new/${slug}`)}
>
- Create new project
- </Button>
- </div>
- </div>
- }
- >
- <>
- {projectCreationDisabled ? (
- <Panel.Content className="pb-8">
- <DisabledWarningDueToIncident title="Project creation is currently disabled" />
- </Panel.Content>
- ) : (
- <div className="divide-y divide-border-muted">
- <Panel.Content className={['space-y-4'].join(' ')}>
- <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}`)
- }}
- defaultValue={field.value}
- >
- <FormControl_Shadcn_>
- <SelectTrigger_Shadcn_>
- <SelectValue_Shadcn_ placeholder="Select an organization" />
- </SelectTrigger_Shadcn_>
- </FormControl_Shadcn_>
- <SelectContent_Shadcn_>
- <SelectGroup_Shadcn_>
- {organizations?.map((x: any) => (
- <SelectItem_Shadcn_ key={x.id} value={x.slug}>
- {x.name}
- </SelectItem_Shadcn_>
- ))}
- </SelectGroup_Shadcn_>
- </SelectContent_Shadcn_>
- </Select_Shadcn_>
- )}
- </FormItemLayout>
- )}
+ {organizations?.map((x: any) => (
+ <Listbox.Option
+ key={x.id}
+ label={x.name}
+ value={x.slug}
+ addOnBefore={() => <IconUsers />}
+ >
+ {x.name}
+ </Listbox.Option>
+ ))}
+ </Listbox>
+ )}
+
+ {!isAdmin && <NotOrganizationOwnerWarning />}
+ </Panel.Content>
+
+ {canCreateProject && (
+ <>
+ <Panel.Content>
+ <Input
+ id="project-name"
+ layout="horizontal"
+ label="Name"
+ type="text"
+ placeholder="Project name"
+ value={projectName}
+ onChange={onProjectNameChange}
+ autoFocus
/>
-
- {!isAdmin && <NotOrganizationOwnerWarning />}
</Panel.Content>
- {canCreateProject && (
- <>
- <Panel.Content>
- <FormField_Shadcn_
- control={form.control}
- name="projectName"
- render={({ field }) => (
- <FormItemLayout label="Project name" layout="horizontal">
- <FormControl_Shadcn_>
- <Input_Shadcn_
- placeholder="Project name"
- {...field}
- onChange={(event) => {
- field.onChange(event.target.value.replace(/\./g, ''))
- }}
- />
- </FormControl_Shadcn_>
- </FormItemLayout>
- )}
- />
- </Panel.Content>
-
- {showNonProdFields && (
- <Panel.Content>
- <FormField_Shadcn_
- control={form.control}
- name="postgresVersion"
- render={({ field }) => (
- <FormItemLayout
- label="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>
- )}
-
- {cloudProviderEnabled && showNonProdFields && (
- <Panel.Content>
- <FormField_Shadcn_
- control={form.control}
- name="cloudProvider"
- render={({ field }) => (
- <FormItemLayout label="Cloud provider" layout="horizontal">
- <Select_Shadcn_
- onValueChange={(value: CloudProvider) => {
- field.onChange(value)
-
- // on local/staging quick-select the default region, don't wait for the cloudflare location
- form.setValue(
- 'dbRegion',
- ['staging', 'local'].includes(
- process.env.NEXT_PUBLIC_ENVIRONMENT ?? ''
- )
- ? PROVIDERS[value].default_region
- : ''
- )
- }}
- 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).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>
- )}
-
- {orgSubscription?.plan.id !== 'free' && (
- <Panel.Content>
- <FormField_Shadcn_
- control={form.control}
- name="instanceSize"
- render={({ field }) => (
- <FormItemLayout
- layout="horizontal"
- label={
- <div className="space-y-4">
- <span>Instance Size</span>
-
- <div className="flex flex-col space-y-2">
- <Link
- href="https://supabase.com/docs/guides/platform/compute-add-ons"
- target="_blank"
- >
- <div className="flex items-center space-x-2 opacity-75 hover:opacity-100 transition">
- <p className="text-sm m-0">Compute Add-Ons</p>
- <ExternalLink size={16} strokeWidth={1.5} />
- </div>
- </Link>
-
- <Link
- href="https://supabase.com/docs/guides/platform/org-based-billing#usage-based-billing-for-compute"
- target="_blank"
- >
- <div className="flex items-center space-x-2 opacity-75 hover:opacity-100 transition">
- <p className="text-sm m-0">Compute Billing</p>
- <ExternalLink size={16} strokeWidth={1.5} />
- </div>
- </Link>
- </div>
- </div>
- }
- description={
- <>
- <p>
- Select the size for your dedicated database. You can always
- change this later.
- </p>
- <p className="mt-1">
- Your organization has $10/month in Compute Credits to cover one
- instance on Micro Compute or parts of any other instance size.
- </p>
- </>
- }
- >
- <Select_Shadcn_
- value={field.value}
- onValueChange={(value) => field.onChange(value)}
- >
- <SelectTrigger_Shadcn_ className="[&_.instance-details]:hidden">
- <SelectValue_Shadcn_ placeholder="Select an instance size" />
- </SelectTrigger_Shadcn_>
- <SelectContent_Shadcn_>
- <SelectGroup_Shadcn_>
- {sizes.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} CPU
- </span>
- <p className="text-xs text-muted instance-details">
- {instanceSizeSpecs[option].price}
- </p>
- </div>
- </div>
- </SelectItem_Shadcn_>
- )
- })}
- </SelectGroup_Shadcn_>
- </SelectContent_Shadcn_>
- </Select_Shadcn_>
- </FormItemLayout>
- )}
- />
- </Panel.Content>
- )}
-
- <Panel.Content>
- <FormField_Shadcn_
- control={form.control}
- name="dbPass"
- render={({ field }) => (
- <FormItemLayout
- label="Database Password"
- layout="horizontal"
- description={
- <>
- <PasswordStrengthBar
- passwordStrengthScore={form.getValues('dbPassStrength')}
- password={field.value}
- passwordStrengthMessage={passwordStrengthMessage}
- generateStrongPassword={generateStrongPassword}
- />
- </>
- }
- >
- <FormControl_Shadcn_>
- <Input
- copy={field.value.length > 0}
- type="password"
- placeholder="Type in a strong password"
- {...field}
- onChange={async (event) => {
- field.onChange(event)
- form.trigger('dbPassStrength')
- form.trigger('dbPass')
- 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>
-
- <Panel.Content>
- <></>
- <FormField_Shadcn_
- control={form.control}
- name="dbRegion"
- render={({ field }) => (
- <RegionSelector
- field={field}
- form={form}
- cloudProvider={form.getValues('cloudProvider') as CloudProvider}
- />
- )}
- />
- </Panel.Content>
- </>
+ {showNonProdFields && (
+ <Panel.Content>
+ <Input
+ id="custom-postgres-version"
+ layout="horizontal"
+ label="Postgres Version"
+ autoComplete="off"
+ descriptionText={
+ <p>
+ Specify a custom version of Postgres (Defaults to the latest)
+ <br />
+ This is only applicable for local/staging projects
+ </p>
+ }
+ type="text"
+ placeholder="Postgres Version"
+ value={postgresVersion}
+ onChange={(event: any) => setPostgresVersion(event.target.value)}
+ />
+ </Panel.Content>
)}
- {isAdmin && freePlanWithExceedingLimits && slug && (
+ {cloudProviderEnabled && showNonProdFields && (
<Panel.Content>
- <FreeProjectLimitWarning
- membersExceededLimit={membersExceededLimit || []}
- orgSlug={slug}
- />
+ <Listbox
+ layout="horizontal"
+ label="Cloud Provider"
+ type="select"
+ value={cloudProvider}
+ onChange={(value) => onCloudProviderChange(value)}
+ descriptionText="Cloud Provider (only for staging/local)"
+ >
+ {Object.values(PROVIDERS).map((providerObj) => {
+ const label = providerObj['name']
+ const value = providerObj['id']
+ return (
+ <Listbox.Option key={value} label={label} value={value}>
+ <span className="text-foreground">{label}</span>
+ </Listbox.Option>
+ )
+ })}
+ </Listbox>
+ </Panel.Content>
+ )}
+
+ {orgSubscription?.plan.id !== 'free' && (
+ <Panel.Content>
+ <Listbox
+ layout="horizontal"
+ label={
+ <div className="space-y-4">
+ <span>Instance Size</span>
+
+ <div className="flex flex-col space-y-2">
+ <Link
+ href="https://supabase.com/docs/guides/platform/compute-add-ons"
+ target="_blank"
+ >
+ <div className="flex items-center space-x-2 opacity-75 hover:opacity-100 transition">
+ <p className="text-sm m-0">Compute Add-Ons</p>
+ <IconExternalLink size={16} strokeWidth={1.5} />
+ </div>
+ </Link>
+
+ <Link
+ href="https://supabase.com/docs/guides/platform/org-based-billing#usage-based-billing-for-compute"
+ target="_blank"
+ >
+ <div className="flex items-center space-x-2 opacity-75 hover:opacity-100 transition">
+ <p className="text-sm m-0">Compute Billing</p>
+ <IconExternalLink size={16} strokeWidth={1.5} />
+ </div>
+ </Link>
+ </div>
+ </div>
+ }
+ type="select"
+ value={instanceSize}
+ onChange={(value) => setInstanceSize(value)}
+ descriptionText={
+ <>
+ <p>
+ Select the size for your dedicated database. You can always change this
+ later.
+ </p>
+ <p className="mt-1">
+ Your organization has $10/month in Compute Credits to cover one instance
+ on Micro Compute or parts of any other instance size.
+ </p>
+ </>
+ }
+ >
+ {sizes.map((option) => {
+ return (
+ <Listbox.Option
+ key={option}
+ label={`${instanceSizeSpecs[option].ram} RAM / ${instanceSizeSpecs[option].cpu} CPU (${instanceSizeSpecs[option].label})`}
+ value={option}
+ >
+ <div className="flex space-x-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} CPU
+ </span>
+ <p className="text-xs text-muted">
+ {instanceSizeSpecs[option].price}
+ </p>
+ </div>
+ </div>
+ </Listbox.Option>
+ )
+ })}
+ </Listbox>
</Panel.Content>
)}
- </div>
+
+ <Panel.Content>
+ <Input
+ id="password"
+ copy={dbPass.length > 0}
+ layout="horizontal"
+ label="Database Password"
+ type="password"
+ placeholder="Type in a strong password"
+ value={dbPass}
+ onChange={onDbPassChange}
+ descriptionText={
+ <PasswordStrengthBar
+ passwordStrengthScore={passwordStrengthScore}
+ password={dbPass}
+ passwordStrengthMessage={passwordStrengthMessage}
+ generateStrongPassword={generateStrongPassword}
+ />
+ }
+ error={passwordStrengthWarning}
+ />
+ </Panel.Content>
+
+ <Panel.Content>
+ <RegionSelector
+ cloudProvider={cloudProvider}
+ selectedRegion={dbRegion}
+ onSelectRegion={setDbRegion}
+ />
+ </Panel.Content>
+ </>
+ )}
+
+ {isAdmin && freePlanWithExceedingLimits && slug && (
+ <Panel.Content>
+ <FreeProjectLimitWarning
+ membersExceededLimit={membersExceededLimit || []}
+ orgSlug={slug}
+ />
+ </Panel.Content>
)}
- </>
- </Panel>
- </form>
- </Form_Shadcn_>
+ </div>
+ )}
+ </>
+ </Panel>
)
}