Files
Ivan Vasilov 308cd791a2 chore: Prep work for migrating to Tailwind v4 (#45285)
This PR preps the monorepo for a migration to Tailwind v4:
- Bump all Tailwind dependencies and libraries to the latest possible
version, while still compatible with Tailwind 3.
- Cleans up obsolete Tailwind 3 specific options and configs.
- Cleans up unused CSS files and fixes the CSS imports.
- Migrates all `important` uses in `@apply` lines to using the `!`
prefix.
- Move `typography.css` to the `config` package and import it from the
apps.
- Migrated all occurrences of `flex-grow`, `flex-shrink`,
`overflow-clip` and `overflow-ellipsis` since they're deprecated and
will be removed in Tailwind 4.
- Make the default theme object typesafe in the `ui` package.
- Migrate all `bg-opacity`, `border-opacity`, `ring-opacity` and
`divider-opacity` to the new format where they're declared as part of
the property color.
- Bump and unify all imports of `postcss` dependency.
2026-04-28 11:33:53 +02:00

162 lines
4.9 KiB
TypeScript

import { zodResolver } from '@hookform/resolvers/zod'
import { useRouter } from 'next/router'
import { useEffect, useMemo } from 'react'
import { SubmitHandler, useForm } from 'react-hook-form'
import { toast } from 'sonner'
import {
Button,
Form,
Separator,
Sheet,
SheetContent,
SheetFooter,
SheetHeader,
SheetTitle,
} from 'ui'
import { usePgPartmanStatus } from '../usePgPartmanStatus'
import { CreateQueueForm, FormSchema } from './CreateQueueSheet.schema'
import { PartitionConfigFields } from './PartitionConfigFields'
import { PgPartmanCallout } from './PgPartmanCallout'
import { QueueNameField } from './QueueNameField'
import { QueueTypeSelector } from './QueueTypeSelector'
import { RlsSection } from './RlsSection'
import { DiscardChangesConfirmationDialog } from '@/components/ui-patterns/Dialogs/DiscardChangesConfirmationDialog'
import { useDatabaseQueueCreateMutation } from '@/data/database-queues/database-queues-create-mutation'
import { useQueuesExposePostgrestStatusQuery } from '@/data/database-queues/database-queues-expose-postgrest-status-query'
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
import { useConfirmOnClose } from '@/hooks/ui/useConfirmOnClose'
export interface CreateQueueSheetProps {
visible: boolean
onClose: () => void
}
const FORM_ID = 'create-queue-sidepanel'
export const CreateQueueSheet = ({ visible, onClose }: CreateQueueSheetProps) => {
const router = useRouter()
const { data: project } = useSelectedProjectQuery()
const { data: isExposed } = useQueuesExposePostgrestStatusQuery({
projectRef: project?.ref,
connectionString: project?.connectionString,
})
const { mutate: createQueue, isPending } = useDatabaseQueueCreateMutation()
const { isInstalled: pgPartmanInstalled } = usePgPartmanStatus()
const defaultValues: CreateQueueForm = useMemo(
() =>
pgPartmanInstalled
? {
name: '',
enableRls: true,
values: { type: 'partitioned', partitionInterval: 10000, retentionInterval: 100000 },
}
: { name: '', enableRls: true, values: { type: 'basic' } },
[pgPartmanInstalled]
)
const form = useForm<CreateQueueForm>({
resolver: zodResolver(FormSchema),
defaultValues,
})
useEffect(() => {
if (visible) {
form.reset(defaultValues)
}
}, [form, defaultValues, visible])
const checkIsDirty = () => form.formState.isDirty
const { confirmOnClose, handleOpenChange, modalProps } = useConfirmOnClose({
checkIsDirty,
onClose,
})
const onSubmit: SubmitHandler<CreateQueueForm> = async ({ name, enableRls, values }) => {
if (!project?.ref) {
toast.error('Project not found')
return
}
createQueue(
{
projectRef: project.ref,
connectionString: project?.connectionString,
name,
enableRls,
type: values.type,
configuration:
values.type === 'partitioned'
? {
partitionInterval: values.partitionInterval,
retentionInterval: values.retentionInterval,
}
: undefined,
},
{
onSuccess: () => {
toast.success(`Successfully created queue ${name}`)
router.push(`/project/${project?.ref}/integrations/queues/queues/${name}`)
onClose()
},
}
)
}
return (
<Sheet open={visible} onOpenChange={handleOpenChange}>
<SheetContent size="default" className="w-[35%]" tabIndex={undefined}>
<div className="flex flex-col h-full" tabIndex={-1}>
<SheetHeader>
<SheetTitle>Create a new queue</SheetTitle>
</SheetHeader>
<div className="overflow-auto grow">
<Form {...form}>
<form
id={FORM_ID}
className="grow overflow-auto"
onSubmit={form.handleSubmit(onSubmit)}
>
<QueueNameField form={form} />
<Separator />
<PgPartmanCallout />
<QueueTypeSelector form={form} />
<Separator />
<PartitionConfigFields form={form} />
<RlsSection form={form} isExposed={isExposed} projectRef={project?.ref} />
</form>
</Form>
</div>
<SheetFooter>
<Button
size="tiny"
type="default"
htmlType="button"
onClick={confirmOnClose}
disabled={isPending}
>
Cancel
</Button>
<Button
size="tiny"
type="primary"
form={FORM_ID}
htmlType="submit"
loading={isPending}
disabled={!project?.ref}
>
Create queue
</Button>
</SheetFooter>
</div>
<DiscardChangesConfirmationDialog {...modalProps} />
</SheetContent>
</Sheet>
)
}