mirror of
https://github.com/supabase/supabase.git
synced 2026-09-22 13:37:53 +08:00
476d4a5851
## What kind of change does this PR introduce? Mechanical cleanup on top of the Button default-variant change (#50160). ## What is the current behavior? Many callsites still pass `variant="default"` even though that is now the component default. ## What is the new behavior? Removes redundant static `variant="default"` from legacy `Button` and `ButtonTooltip` callsites. Keeps explicit defaults where they document the API: - `button-default.tsx` and `button-sizes.tsx` demos - `DocsButton`, which pins neutral styling at the wrapper boundary ## To test Studio: - [Auth → Rate Limits](https://studio-staging-2s957kwc4-supabase.vercel.app/dashboard/project/_/auth/rate-limits): dirty the form so Cancel appears; Cancel stays neutral, Save stays green - [Project Settings → API Keys](https://studio-staging-2s957kwc4-supabase.vercel.app/dashboard/project/_/settings/api-keys): `DocsButton` in the header actions stays neutral Design system: - [Design system → Button](https://design-system-git-dnywh-dc924ac1-supabase.vercel.app/design-system/docs/components/button): `button-default` / `button-sizes` still show explicit default styling; Primary (green) is restricted to the Primary section (and `asChild`) WWW: - [www → Brand assets](https://zone-www-dot-com-git-dnywh-dc924ac1-supabase.vercel.app/brand-assets): Download logo kit / Download button kit stay neutral
112 lines
3.2 KiB
TypeScript
112 lines
3.2 KiB
TypeScript
import { zodResolver } from '@hookform/resolvers/zod'
|
|
import { PermissionAction } from '@supabase/shared-types/out/constants'
|
|
import { useParams } from 'common'
|
|
import { SubmitHandler, useForm } from 'react-hook-form'
|
|
import { toast } from 'sonner'
|
|
import {
|
|
Button,
|
|
Dialog,
|
|
DialogContent,
|
|
DialogFooter,
|
|
DialogHeader,
|
|
DialogSection,
|
|
DialogSectionSeparator,
|
|
DialogTitle,
|
|
Form,
|
|
FormControl,
|
|
FormField,
|
|
Input,
|
|
} from 'ui'
|
|
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
|
|
import * as z from 'zod'
|
|
|
|
import { useUserInviteMutation } from '@/data/auth/user-invite-mutation'
|
|
import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions'
|
|
|
|
export type InviteUserModalProps = {
|
|
visible: boolean
|
|
setVisible: (visible: boolean) => void
|
|
}
|
|
|
|
const formSchema = z.object({
|
|
email: z.string().min(1, 'Please enter a valid email').email('Please enter a valid email'),
|
|
})
|
|
const formId = 'invite-user-form'
|
|
|
|
const InviteUserModal = ({ visible, setVisible }: InviteUserModalProps) => {
|
|
const { ref: projectRef } = useParams()
|
|
const form = useForm<z.infer<typeof formSchema>>({
|
|
resolver: zodResolver(formSchema),
|
|
defaultValues: {
|
|
email: '',
|
|
},
|
|
})
|
|
|
|
const handleToggle = () => setVisible(!visible)
|
|
const { mutate: inviteUser, isPending: isInviting } = useUserInviteMutation({
|
|
onSuccess: (_, variables) => {
|
|
toast.success(`Sent invite email to ${variables.email}`)
|
|
setVisible(false)
|
|
},
|
|
})
|
|
const { can: canInviteUsers } = useAsyncCheckPermissions(
|
|
PermissionAction.AUTH_EXECUTE,
|
|
'invite_user'
|
|
)
|
|
|
|
const onInviteUser: SubmitHandler<z.infer<typeof formSchema>> = async (values) => {
|
|
if (!projectRef) return console.error('Project ref is required')
|
|
inviteUser(
|
|
{ projectRef, email: values.email },
|
|
{
|
|
onSuccess: () => {
|
|
form.reset()
|
|
},
|
|
}
|
|
)
|
|
}
|
|
|
|
return (
|
|
<Dialog key="invite-user-modal" open={visible} onOpenChange={handleToggle}>
|
|
<DialogContent size="small">
|
|
<DialogHeader>
|
|
<DialogTitle>Invite a new user</DialogTitle>
|
|
</DialogHeader>
|
|
<DialogSectionSeparator />
|
|
<Form {...form}>
|
|
<DialogSection>
|
|
<form id={formId} onSubmit={form.handleSubmit(onInviteUser)} noValidate>
|
|
<FormField
|
|
control={form.control}
|
|
name="email"
|
|
render={({ field }) => (
|
|
<FormItemLayout layout="vertical" label="User email">
|
|
<FormControl className="relative col-span-6">
|
|
<Input {...field} />
|
|
</FormControl>
|
|
</FormItemLayout>
|
|
)}
|
|
/>
|
|
</form>
|
|
</DialogSection>
|
|
|
|
<DialogFooter>
|
|
<Button onClick={handleToggle}>Cancel</Button>
|
|
<Button
|
|
variant="primary"
|
|
form={formId}
|
|
type="submit"
|
|
loading={isInviting}
|
|
disabled={!canInviteUsers || isInviting}
|
|
>
|
|
Invite user
|
|
</Button>
|
|
</DialogFooter>
|
|
</Form>
|
|
</DialogContent>
|
|
</Dialog>
|
|
)
|
|
}
|
|
|
|
export default InviteUserModal
|