mirror of
https://github.com/supabase/supabase.git
synced 2026-10-07 10:25:06 +03:00
## Context There's 2 areas of the dashboard that has the project creation flow - and this PR consolidates both to use the same UI components to minimise duplication + keep things consistent ### Before <img width="1920" height="957" alt="image" src="https://github.com/user-attachments/assets/2a7ab79d-71c7-43f2-925b-1e1666cc3a69" /> ### After <img width="1389" height="957" alt="image" src="https://github.com/user-attachments/assets/f8465568-af99-46eb-80ee-7ac345383231" /> ## Changes involved - What this means for the project creation flow for Vercel Integration: - Smart region can be selected - Compute size can be selected - Enable Data API can be checked - Automatic RLS enable can be checked - How it differs from the main project creation flow on `new/slug` - Organization selection is disabled (cannot be changed) - The following UI is hidden: - "Internal configuration" section - "GitHub repository" field - "Free project info" at the bottom - "Cancel" button Eventually we could looking into reducing the differences more, e.g having data seeding for both ways, and showing GitHub repository field for Vercel integration Resolves DEPR-616 Resolves FE-3905 ## To test Tbh, I'm not really sure how you'd be able to test the vercel integration locally or on staging, this seemingly can only be done when changes land on prod. - What I'd do however is to just test the project creation flow minimally by landing on `/integrations/vercel/_/deploy-button/new-project` - Project creation can work, but just not the connection creation part - And also test project creation on `/new/slug` as well <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Summary by CodeRabbit * **New Features** * Added “Create sample tables with seed data” during project creation. * Enhanced Vercel integration setup with a guided creation flow and post-creation connection step. * Added an option to disable organization selection in specialized flows. * Added support for triggering a callback after successful project creation. * Added support for hiding the Cancel button in specialized flows. * **UI Improvements** * Refined the connected GitHub repository selector button/dropdown visuals. * Improved security options behavior for different project creation contexts. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
103 lines
3.8 KiB
TypeScript
103 lines
3.8 KiB
TypeScript
import { PermissionAction } from '@supabase/shared-types/out/constants'
|
|
import { useQueryClient } from '@tanstack/react-query'
|
|
import { useParams } from 'common'
|
|
import { useRouter } from 'next/router'
|
|
import { useEffect } from 'react'
|
|
import { UseFormReturn } from 'react-hook-form'
|
|
import {
|
|
Badge,
|
|
FormControl,
|
|
FormField,
|
|
Select,
|
|
SelectContent,
|
|
SelectGroup,
|
|
SelectItem,
|
|
SelectTrigger,
|
|
SelectValue,
|
|
} from 'ui'
|
|
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
|
|
|
|
import { OrgNotFound } from '../Organization/OrgNotFound'
|
|
import { CreateProjectForm } from './ProjectCreation.schema'
|
|
import { NoPermission } from '@/components/ui/NoPermission'
|
|
import Panel from '@/components/ui/Panel'
|
|
import { useOrganizationsQuery } from '@/data/organizations/organizations-query'
|
|
import { permissionKeys } from '@/data/permissions/keys'
|
|
import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions'
|
|
import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'
|
|
|
|
interface OrganizationSelectorProps {
|
|
form: UseFormReturn<CreateProjectForm>
|
|
disableOrganizationSelection: boolean
|
|
}
|
|
|
|
export const OrganizationSelector = ({
|
|
form,
|
|
disableOrganizationSelection,
|
|
}: OrganizationSelectorProps) => {
|
|
const router = useRouter()
|
|
const { slug } = useParams()
|
|
const queryClient = useQueryClient()
|
|
const { data: currentOrg } = useSelectedOrganizationQuery()
|
|
const { can: isAdmin } = useAsyncCheckPermissions(PermissionAction.CREATE, 'projects')
|
|
|
|
// Permissions may be stale for newly created accounts due to replication lag between
|
|
// org setup and the permissions endpoint. Invalidate in the background on mount so the
|
|
// check reflects the latest state before the user tries to create a project.
|
|
useEffect(() => {
|
|
queryClient.invalidateQueries({ queryKey: permissionKeys.list() })
|
|
}, [queryClient])
|
|
|
|
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">
|
|
<FormField
|
|
control={form.control}
|
|
name="organization"
|
|
render={({ field }) => (
|
|
<FormItemLayout id="organization" label="Organization" layout="horizontal">
|
|
{(organizations?.length ?? 0) > 0 && (
|
|
<FormControl>
|
|
<Select
|
|
name="organization"
|
|
onValueChange={(slug) => {
|
|
field.onChange(slug)
|
|
router.push(`/new/${slug}`)
|
|
}}
|
|
value={field.value}
|
|
defaultValue={field.value}
|
|
disabled={disableOrganizationSelection}
|
|
>
|
|
<SelectTrigger id="organization">
|
|
<SelectValue placeholder="Select an organization" />
|
|
</SelectTrigger>
|
|
<SelectContent>
|
|
<SelectGroup>
|
|
{organizations?.map((x) => (
|
|
<SelectItem key={x.id} value={x.slug}>
|
|
<div className="flex justify-between items-center gap-2 w-full">
|
|
<span>{x.name}</span>
|
|
<Badge className="mt-px">{x.plan.name}</Badge>
|
|
</div>
|
|
</SelectItem>
|
|
))}
|
|
</SelectGroup>
|
|
</SelectContent>
|
|
</Select>
|
|
</FormControl>
|
|
)}
|
|
</FormItemLayout>
|
|
)}
|
|
/>
|
|
|
|
{isOrganizationsSuccess && !isAdmin && !orgNotFound && (
|
|
<NoPermission resourceText="create a project" />
|
|
)}
|
|
{orgNotFound && <OrgNotFound slug={slug} />}
|
|
</Panel.Content>
|
|
)
|
|
}
|