Files
supabase/apps/docs/components/Feedback/FeedbackModal.tsx
Gildas Garcia 31c8601201 Chore/migrate modals 1 (#46216)
## Problem

We still use the deprecated `Modal` component in many places.

## Solution

Migrate to the new `Dialog` component.
Removed the design system page that was missing anyway:
https://supabase.com/design-system/docs/fragments/modal
This PR focuses on the design system and docs related components.

## How to test

- Docs videos: 
  - prod: https://supabase.com/docs/guides/auth
- staging:
https://docs-git-chore-migrate-modals-1-supabase.vercel.app/docs/guides/auth

- Feedback modal: not sure how to show it on staging but it should look
identical
- Privacy settings: not sure how to show it on staging but it should
look identical
- `PopupFrame`: this one is not used anywhere AFAIK. If confirmed I
could delete it.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

## Release Notes

* **Chores**
* Removed Modal component documentation entries and example patterns
from the design system.
* Migrated internal modal and dialog implementations to use the Dialog
component suite for standardized behavior and improved consistency
across the application.

<!-- review_stack_entry_start -->

[![Review Change
Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/supabase/supabase/pull/46216?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack)

<!-- review_stack_entry_end -->

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-05-21 15:30:03 +02:00

123 lines
3.8 KiB
TypeScript

import { zodResolver } from '@hookform/resolvers/zod'
import { SubmitHandler, useForm } from 'react-hook-form'
import {
Button,
Dialog,
DialogContent,
DialogFooter,
DialogHeader,
DialogSection,
DialogSectionSeparator,
DialogTitle,
Form,
FormControl,
FormField,
Input,
Textarea,
} from 'ui'
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
import * as z from 'zod'
const formSchema = z.object({
page: z.string(),
title: z.string().min(1, 'Required'),
comment: z.string().min(1, 'Required'),
})
export type FeedbackFields = z.infer<typeof formSchema>
type FeedbackModalProps = {
visible: boolean
page: string
onCancel: () => void
onSubmit: (values: FeedbackFields) => void
}
function FeedbackModal({ visible, page, onCancel, onSubmit }: FeedbackModalProps) {
const form = useForm<FeedbackFields>({
defaultValues: { page, title: '', comment: '' },
resolver: zodResolver(formSchema),
})
const formId = 'feedback-form'
const { reset } = form
const { isSubmitting } = form.formState
const handleCancel = () => {
reset()
onCancel()
}
const handleSubmit: SubmitHandler<FeedbackFields> = (values) => {
onSubmit(values)
reset()
}
return (
<Dialog open={visible} onOpenChange={() => onCancel()}>
<DialogContent>
<DialogHeader>
<DialogTitle>Leave a comment</DialogTitle>
</DialogHeader>
<DialogSectionSeparator />
<Form {...form}>
<form id={formId} onSubmit={form.handleSubmit(handleSubmit)}>
<DialogSection className="space-y-4">
<input type="hidden" id="page" {...form.register('page')} />
<FormField
control={form.control}
name="title"
render={({ field }) => (
<FormItemLayout layout="vertical" label="Title">
<FormControl className="col-span-6">
<Input {...field} />
</FormControl>
</FormItemLayout>
)}
/>
<FormField
control={form.control}
name="comment"
render={({ field }) => (
<FormItemLayout layout="vertical" label="Comment" afterLabel="(not anonymous)">
<FormControl className="col-span-6">
<Textarea {...field} rows={4} className="resize-none" />
</FormControl>
</FormItemLayout>
)}
/>
<div className="flex gap-2 text-xs text-foreground-light leading-relaxed">
<span className="shrink-0 mt-0.5">💡</span>
<div>
<strong>Need help or support?</strong> This feedback form is for documentation
improvements only. For technical support, please submit a{' '}
<a
href="https://supabase.com/dashboard/support/new"
target="_blank"
rel="noopener noreferrer"
className="text-brand-link hover:underline"
>
support request
</a>
.
</div>
</div>
</DialogSection>
</form>
</Form>
<DialogFooter>
<div className="flex items-center justify-end gap-2">
<Button htmlType="reset" type="default" onClick={handleCancel} disabled={isSubmitting}>
Cancel
</Button>
<Button htmlType="submit" form={formId} loading={isSubmitting} disabled={isSubmitting}>
Submit feedback
</Button>
</div>
</DialogFooter>
</DialogContent>
</Dialog>
)
}
export { FeedbackModal }