mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 18:05:11 +03:00
## What kind of change does this PR introduce? Bug fix / design-system alignment for the legacy `Button` from `ui`. ## What is the current behavior? Omitting `variant` on the legacy `Button` falls back to brand-green `primary`. That makes accidental greens easy, and it is hard to spot the real main action on busy pages. ## What is the new behavior? - Legacy `Button` now defaults to neutral `default` - Intentional primary CTAs (create, save, submit, marketing CTAs, and matching `ButtonTooltip` usages) now set `variant="primary"` so their appearance is unchanged - Neutral actions that previously relied on the old fallback (cancel, close, back, dashboard nav, and similar) become grey/white - Design-system docs updated; regression tests cover the new default `Button_Shadcn_` is unchanged. It already uses its own CVA default. This is PR 1 of 2 in a stack. PR 2 drops now-redundant `variant="default"` props. ## To test Studio (http://localhost:8082): - `/sign-in`: Sign in stays green - Open a project → Database → Tables: New table stays green - Auth → Users → Invite: Invite user stays green; Cancel / dismiss controls stay neutral - Project Settings → General: edit a field so Cancel and Save appear. Cancel is neutral, Save is green Design system (http://localhost:3003): - Components → Button: default demo is neutral; primary demo is green; featured preview is the default variant Marketing (optional): - www header: Start your project stays green; logged-in Dashboard is neutral <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Style** - Buttons now default to a neutral style, while primary actions across Studio, documentation, marketing pages, forms, dialogs, and error states use prominent primary styling. - Updated button examples and previews clarify the distinction between default and primary variants. - Event registration now includes a directional arrow icon. - **Tests** - Added coverage confirming default button styling and explicit primary styling behave as expected. - Updated related test fixtures to use primary styling where appropriate. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
200 lines
6.7 KiB
TypeScript
200 lines
6.7 KiB
TypeScript
import { zodResolver } from '@hookform/resolvers/zod'
|
|
import { useState } from 'react'
|
|
import { useForm } from 'react-hook-form'
|
|
import { toast } from 'sonner'
|
|
import {
|
|
Button,
|
|
Dialog,
|
|
DialogContent,
|
|
DialogDescription,
|
|
DialogFooter,
|
|
DialogHeader,
|
|
DialogSection,
|
|
DialogTitle,
|
|
Form,
|
|
FormControl,
|
|
FormField,
|
|
Input,
|
|
} from 'ui'
|
|
import { Input as PasswordInput } from 'ui-patterns/DataInputs/Input'
|
|
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
|
|
import { z } from 'zod'
|
|
|
|
import { AdditionalMonthlySpend } from './AdditionalMonthlySpend'
|
|
import { NewProjectPrice } from './RestoreToNewProject.utils'
|
|
import { PasswordStrengthBar } from '@/components/ui/PasswordStrengthBar'
|
|
import { useProjectCloneMutation } from '@/data/projects/clone-mutation'
|
|
import { useCloneBackupsQuery } from '@/data/projects/clone-query'
|
|
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
|
|
import { passwordStrength, PasswordStrengthScore } from '@/lib/password-strength'
|
|
import { generateStrongPassword } from '@/lib/project'
|
|
|
|
interface CreateNewProjectDialogProps {
|
|
open: boolean
|
|
selectedBackupId: number | null
|
|
recoveryTimeTarget: number | null
|
|
onOpenChange: (value: boolean) => void
|
|
onCloneSuccess: () => void
|
|
additionalMonthlySpend: NewProjectPrice
|
|
hasAccess?: boolean
|
|
}
|
|
|
|
export const CreateNewProjectDialog = ({
|
|
open,
|
|
selectedBackupId,
|
|
recoveryTimeTarget,
|
|
onOpenChange,
|
|
onCloneSuccess,
|
|
additionalMonthlySpend,
|
|
hasAccess,
|
|
}: CreateNewProjectDialogProps) => {
|
|
const { data: project } = useSelectedProjectQuery()
|
|
const [passwordStrengthScore, setPasswordStrengthScore] = useState(0)
|
|
const [passwordStrengthMessage, setPasswordStrengthMessage] = useState('')
|
|
|
|
const FormSchema = z.object({
|
|
name: z.string().min(1),
|
|
password: z.string().min(1),
|
|
})
|
|
|
|
const form = useForm<z.infer<typeof FormSchema>>({
|
|
resolver: zodResolver(FormSchema),
|
|
defaultValues: {
|
|
name: '',
|
|
password: '',
|
|
},
|
|
})
|
|
|
|
const { data: cloneBackups } = useCloneBackupsQuery(
|
|
{ projectRef: project?.ref },
|
|
{ enabled: hasAccess }
|
|
)
|
|
const hasPITREnabled = cloneBackups?.pitr_enabled
|
|
|
|
const { mutate: triggerClone, isPending: cloneMutationLoading } = useProjectCloneMutation({
|
|
onError: (error) => {
|
|
toast.error(`Failed to restore to new project: ${error.message}`)
|
|
},
|
|
onSuccess: () => {
|
|
toast.success('Restoration process started')
|
|
onCloneSuccess()
|
|
},
|
|
})
|
|
|
|
async function checkPasswordStrength(value: string) {
|
|
const { message, strength } = await passwordStrength(value)
|
|
setPasswordStrengthScore(strength)
|
|
setPasswordStrengthMessage(message)
|
|
}
|
|
|
|
const generatePassword = () => {
|
|
const password = generateStrongPassword()
|
|
form.setValue('password', password)
|
|
checkPasswordStrength(password)
|
|
}
|
|
|
|
return (
|
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
|
<DialogContent>
|
|
<DialogHeader className="border-b">
|
|
<DialogTitle>Create new project</DialogTitle>
|
|
<DialogDescription>
|
|
This process will create a new project and restore your database to it.
|
|
</DialogDescription>
|
|
</DialogHeader>
|
|
<Form {...form}>
|
|
<form
|
|
id={'create-new-project-form'}
|
|
onSubmit={form.handleSubmit((data) => {
|
|
if (!project?.ref) {
|
|
toast.error('Project ref is required')
|
|
return
|
|
}
|
|
|
|
if (hasPITREnabled && recoveryTimeTarget) {
|
|
triggerClone({
|
|
projectRef: project?.ref,
|
|
newProjectName: data.name,
|
|
newDbPass: data.password,
|
|
recoveryTimeTarget: recoveryTimeTarget,
|
|
cloneBackupId: undefined,
|
|
})
|
|
} else if (selectedBackupId) {
|
|
triggerClone({
|
|
projectRef: project?.ref,
|
|
cloneBackupId: selectedBackupId,
|
|
newProjectName: data.name,
|
|
newDbPass: data.password,
|
|
recoveryTimeTarget: undefined,
|
|
})
|
|
} else {
|
|
toast.error('No backup or point in time selected')
|
|
return
|
|
}
|
|
})}
|
|
>
|
|
<DialogSection className="pb-6 space-y-4 text-sm">
|
|
<FormField
|
|
control={form.control}
|
|
name="name"
|
|
render={({ field }) => (
|
|
<FormItemLayout label="New Project Name">
|
|
<FormControl>
|
|
<Input placeholder="Enter a name" type="text" {...field} />
|
|
</FormControl>
|
|
</FormItemLayout>
|
|
)}
|
|
/>
|
|
<FormField
|
|
control={form.control}
|
|
name="password"
|
|
render={({ field }) => (
|
|
<FormItemLayout
|
|
label="Database password"
|
|
description={
|
|
<PasswordStrengthBar
|
|
passwordStrengthScore={passwordStrengthScore as PasswordStrengthScore}
|
|
password={field.value}
|
|
passwordStrengthMessage={passwordStrengthMessage}
|
|
generateStrongPassword={generatePassword}
|
|
/>
|
|
}
|
|
>
|
|
<FormControl>
|
|
<PasswordInput
|
|
id="db-password"
|
|
type="password"
|
|
placeholder="Type in a strong password"
|
|
value={field.value}
|
|
copy={field.value?.length > 0}
|
|
reveal
|
|
onChange={(e) => {
|
|
const value = e.target.value
|
|
field.onChange(value)
|
|
if (value == '') {
|
|
setPasswordStrengthScore(-1)
|
|
setPasswordStrengthMessage('')
|
|
} else checkPasswordStrength(value)
|
|
}}
|
|
/>
|
|
</FormControl>
|
|
</FormItemLayout>
|
|
)}
|
|
/>
|
|
</DialogSection>
|
|
<AdditionalMonthlySpend additionalMonthlySpend={additionalMonthlySpend} />
|
|
<DialogFooter>
|
|
<Button type="reset" variant="outline" onClick={() => onOpenChange(false)}>
|
|
Cancel
|
|
</Button>
|
|
<Button variant="primary" type="submit" loading={cloneMutationLoading}>
|
|
Restore to new project
|
|
</Button>
|
|
</DialogFooter>
|
|
</form>
|
|
</Form>
|
|
</DialogContent>
|
|
</Dialog>
|
|
)
|
|
}
|