mirror of
https://github.com/supabase/supabase.git
synced 2026-10-18 23:59:08 +03:00
* Update the design of the sonner toasts. Add the close button by default. * Migrate studio and www apps to use the SonnerToaster. * Migrate all toasts from studio. * Migrate all leftover toasts in studio. * Add a new toast component with progress. Use it in studio. * Migrate the design-system app. * Refactor the consent toast to use sonner. * Switch docs to use the new sonner toasts. * Remove toast examples from the design-system app. * Remove all toast-related components and old code. * Fix the progress bar in the toast progress component. Also make the bottom components vertically centered. * Fix the width of the toast progress. * Use text-foreground-lighter instead of muted for ToastProgress text * Rename ToastProgress to SonnerProgress. * Shorten the text in sonner progress. * Use the correct classes for the close button. Add a const var for the default toast duration. Remove the custom width class from sonner. * Set the position for all progress toasts to bottom right. Set the duration for all toasts to the default (when reusing a toast id from loading/progress toast, the duration is set to infinity). * Fix the playwright tests. * Refactor imports to use ui instead of @ui. * Change all imports of react-hot-toast with sonner. These components were merged since the last commit to this branch. * Remove react-hot-toast lib. --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com> Co-authored-by: Jonathan Summers-Muir <MildTomato@users.noreply.github.com>
125 lines
4.0 KiB
TypeScript
125 lines
4.0 KiB
TypeScript
import { zodResolver } from '@hookform/resolvers/zod'
|
|
import { PermissionAction } from '@supabase/shared-types/out/constants'
|
|
import { PlusIcon } from 'lucide-react'
|
|
import { useRouter } from 'next/router'
|
|
import { useEffect, useState } from 'react'
|
|
import { useForm } from 'react-hook-form'
|
|
import { toast } from 'sonner'
|
|
import { z } from 'zod'
|
|
|
|
import { FormMessage } from '@ui/components/shadcn/ui/form'
|
|
import { Input } from '@ui/components/shadcn/ui/input'
|
|
import { useParams } from 'common'
|
|
import { ButtonTooltip } from 'components/ui/ButtonTooltip'
|
|
import { useCreateCollection } from 'data/analytics/warehouse-collections-create-mutation'
|
|
import { useCheckPermissions } from 'hooks/misc/useCheckPermissions'
|
|
import { Button, FormControl_Shadcn_, FormField_Shadcn_, Form_Shadcn_, Modal } from 'ui'
|
|
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
|
|
|
|
export const CreateWarehouseCollectionModal = () => {
|
|
const [isOpen, setIsOpen] = useState(false)
|
|
const router = useRouter()
|
|
const { ref } = useParams()
|
|
|
|
const canCreateCollection = useCheckPermissions(PermissionAction.ANALYTICS_WRITE, 'logflare')
|
|
|
|
const { mutate: createCollection, isLoading } = useCreateCollection({
|
|
onSuccess: (data) => {
|
|
// todo: remove typecast once api types are fixed
|
|
setIsOpen(false)
|
|
router.push(`/project/${ref}/logs/collections/${(data as any).token}`)
|
|
},
|
|
onError: (error) => {
|
|
toast.error(error.message)
|
|
},
|
|
})
|
|
|
|
const FormSchema = z.object({
|
|
name: z.string().min(1),
|
|
})
|
|
|
|
const form = useForm<z.infer<typeof FormSchema>>({
|
|
resolver: zodResolver(FormSchema),
|
|
})
|
|
|
|
useEffect(() => {
|
|
if (!isOpen) {
|
|
form.reset()
|
|
}
|
|
}, [isOpen, form])
|
|
|
|
const onSubmit = form.handleSubmit(async (vals) => {
|
|
if (!ref) {
|
|
toast.error('Project ref not found')
|
|
return
|
|
}
|
|
createCollection({
|
|
projectRef: ref,
|
|
name: vals.name,
|
|
})
|
|
})
|
|
|
|
return (
|
|
<>
|
|
<ButtonTooltip
|
|
type="default"
|
|
disabled={!canCreateCollection}
|
|
className="justify-start flex-grow w-full"
|
|
icon={<PlusIcon size="14" />}
|
|
onClick={() => setIsOpen(!isOpen)}
|
|
tooltip={{
|
|
content: {
|
|
side: 'bottom',
|
|
text: 'You need additional permissions to create collections',
|
|
},
|
|
}}
|
|
>
|
|
New collection
|
|
</ButtonTooltip>
|
|
{/* <Button onClick={() => setIsOpen(!isOpen)}>Create collection</Button> */}
|
|
<Modal
|
|
size="medium"
|
|
onCancel={() => setIsOpen(!isOpen)}
|
|
header="Create an event collection"
|
|
visible={isOpen}
|
|
hideFooter
|
|
>
|
|
<Form_Shadcn_ {...form}>
|
|
<form onSubmit={onSubmit}>
|
|
<Modal.Content className="py-4">
|
|
<p className="pb-5 text-foreground-light text-sm">
|
|
An event collection stores generic timeseries events and metadata in
|
|
Supabase-managed analytics infrastructure. Events can be then be queried using SQL,
|
|
without impacting transactional workloads.
|
|
</p>
|
|
|
|
<FormField_Shadcn_
|
|
control={form.control}
|
|
name="name"
|
|
render={({ field }) => (
|
|
<FormItemLayout label="Collection name" layout="horizontal">
|
|
<FormControl_Shadcn_>
|
|
<Input placeholder="Events" {...field} />
|
|
</FormControl_Shadcn_>
|
|
</FormItemLayout>
|
|
)}
|
|
/>
|
|
|
|
<FormMessage />
|
|
</Modal.Content>
|
|
|
|
<Modal.Content className="py-4 border-t flex items-center justify-end gap-2">
|
|
<Button size="tiny" type="default" onClick={() => setIsOpen(!isOpen)}>
|
|
Cancel
|
|
</Button>
|
|
<Button size="tiny" loading={isLoading} disabled={isLoading} htmlType="submit">
|
|
Create table
|
|
</Button>
|
|
</Modal.Content>
|
|
</form>
|
|
</Form_Shadcn_>
|
|
</Modal>
|
|
</>
|
|
)
|
|
}
|