Files
supabase__supabase/apps/studio/components/interfaces/Auth/Users/CreateUserModal.tsx
Danny White 1131e3e2ce fix(ui): default Button variant to default instead of primary (#50160)
## 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 -->
2026-09-10 11:23:17 +10:00

176 lines
5.6 KiB
TypeScript

import { zodResolver } from '@hookform/resolvers/zod'
import { PermissionAction } from '@supabase/shared-types/out/constants'
import { useParams } from 'common'
import { Lock, Mail } from 'lucide-react'
import { SubmitHandler, useForm } from 'react-hook-form'
import { toast } from 'sonner'
import {
Button,
Checkbox,
Dialog,
DialogContent,
DialogHeader,
DialogSectionSeparator,
DialogTitle,
Form,
FormControl,
FormField,
FormItem,
FormLabel,
FormMessage,
Input,
} from 'ui'
import * as z from 'zod'
import { useUserCreateMutation } from '@/data/auth/user-create-mutation'
import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions'
export type CreateUserModalProps = {
visible: boolean
setVisible: (visible: boolean) => void
}
const CreateUserFormSchema = z.object({
email: z.string().min(1, 'Email is required').email('Must be a valid email address'),
password: z.string().min(1, 'Password is required'),
autoConfirmUser: z.boolean(),
})
const CreateUserModal = ({ visible, setVisible }: CreateUserModalProps) => {
const { ref: projectRef } = useParams()
const { can: canCreateUsers } = useAsyncCheckPermissions(
PermissionAction.AUTH_EXECUTE,
'create_user'
)
const { mutate: createUser, isPending: isCreatingUser } = useUserCreateMutation({
onSuccess(res) {
toast.success(`Successfully created user: ${res.email}`)
form.reset({ email: '', password: '', autoConfirmUser: true })
setVisible(false)
},
})
const onCreateUser: SubmitHandler<z.infer<typeof CreateUserFormSchema>> = async (values) => {
if (!projectRef) return console.error('Project ref is required')
createUser({ projectRef, user: values })
}
const form = useForm<z.infer<typeof CreateUserFormSchema>>({
resolver: zodResolver(CreateUserFormSchema),
defaultValues: { email: '', password: '', autoConfirmUser: true },
})
return (
<Dialog open={visible} onOpenChange={setVisible}>
<DialogContent size="small">
<DialogHeader>
<DialogTitle>Create a new user</DialogTitle>
</DialogHeader>
<DialogSectionSeparator />
<Form {...form}>
<form
id="create-user"
className="flex flex-col gap-y-4 p-6"
onSubmit={form.handleSubmit(onCreateUser)}
>
<FormField
name="email"
control={form.control}
render={({ field }) => (
<FormItem className="flex flex-col gap-1">
<FormLabel>Email address</FormLabel>
<FormControl>
<div className="items-center relative">
<Mail
size={18}
className="absolute left-2 top-1/2 transform -translate-y-1/2"
strokeWidth={1.5}
/>
<Input
autoFocus
{...field}
autoComplete="off"
type="email"
name="email"
placeholder="user@example.com"
disabled={isCreatingUser}
className="pl-8"
/>
</div>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
name="password"
control={form.control}
render={({ field }) => (
<FormItem className="flex flex-col gap-1">
<FormLabel>User Password</FormLabel>
<FormControl>
<div className="items-center relative">
<Lock
size={18}
className="absolute left-2 top-1/2 transform -translate-y-1/2"
strokeWidth={1.5}
/>
<Input
{...field}
autoComplete="new-password"
type="password"
name="password"
placeholder="&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;"
disabled={isCreatingUser}
className="pl-8"
/>
</div>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
name="autoConfirmUser"
control={form.control}
render={({ field }) => (
<FormItem className="flex items-center gap-x-2">
<FormControl>
<Checkbox
checked={field.value}
onCheckedChange={(value) => field.onChange(value)}
/>
</FormControl>
<FormLabel>Auto confirm user?</FormLabel>
</FormItem>
)}
/>
<FormLabel>
<p className="text-sm text-foreground-lighter">
A confirmation email will not be sent when creating a user via this form.
</p>
</FormLabel>
<Button
variant="primary"
block
size="small"
type="submit"
loading={isCreatingUser}
disabled={!canCreateUsers || isCreatingUser}
>
Create user
</Button>
</form>
</Form>
</DialogContent>
</Dialog>
)
}
export default CreateUserModal