mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
## Problem - docs layout v2 (variant `option-1` of the `docs-ia-mvp-v1` flag) is about to roll out and a reader in the rollout has no way back to the classic layout ## Solution - adds a toggle button bottom of the guide right column so user in the rollout can switch back - adds a dialog that asks for an optional reason when a reader switches back to classic, and stores the reason in `feedback_comments` with `metadata.source = 'docs_layout_switch'` so we relying on existing - adds the `docs_layout_updated` event and stops new experiment exposures for readers who picked a layout | toggle | survey | | -------|------| | <img width="654" height="312" alt="image" src="https://github.com/user-attachments/assets/69bcd4b8-7dd2-4fd3-9045-e3246625ccf9" /> | <img width="654" height="312" alt="image" src="https://github.com/user-attachments/assets/4b18eb76-b9f1-4d96-be25-14a960b11475" /> | <!-- ## Preview links If relevant, include links to changed pages for easy review access. Copy the preview base URL from the Vercel bot comment on this PR. Use the following table as an example template. | Site | Live | Preview | Search for | | -------------- | ------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ | ----------------------------- | | WWW | [/blog/your-post](https://supabase.com/blog/your-post) | [/blog/your-post](https://zone-www-dot-com-git-branch-name-supabase.vercel.app/blog/your-post) | unique phrase from the change | | Docs | [/docs/guides/your-page](https://supabase.com/docs/guides/your-page) | [/docs/guides/your-page](https://docs-git-branch-name-supabase.vercel.app/docs/guides/your-page) | unique phrase from the change | | Studio | [/dashboard](https://supabase.com/dashboard) | [/dashboard](https://studio-git-branch-name-supabase.vercel.app/dashboard) | unique phrase from the change | | Design system | [/design-system](https://supabase.com/design-system) | [/design-system](https://design-system-git-branch-name-supabase.vercel.app/design-system) | unique phrase from the change | | UI library | [/library](https://supabase.com/library) | [/library](https://ui-library-git-branch-name-supabase.vercel.app/library) | unique phrase from the change | | Knowledge base | [/kb/guides/your-page](https://supabase.com/kb/guides/your-page) | [/kb/guides/your-page](https://kb-git-branch-name-supabase.vercel.app/kb/guides/your-page) | unique phrase from the change | --> <!-- ## Additional context Optionally add any other context or screenshots. --> ## Review instructions 1. open [/docs/guides/database/prisma?docs-ia-mvp-v1=option-1](https://docs-git-antlio-feat-docs-layout-switch-v2-supabase.vercel.app/docs/guides/database/prisma?docs-ia-mvp-v1=option-1) 2. click "Switch to classic layout" in the notice and make sure that a dialog asks "What made you switch back?" ## Checklist Check all before review: - [x] I have read [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) - [ ] If I wrote a new docs topic or edited an existing topic, I used the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs [style guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)
113 lines
3.1 KiB
TypeScript
113 lines
3.1 KiB
TypeScript
'use client'
|
|
|
|
import { zodResolver } from '@hookform/resolvers/zod'
|
|
import { useId, type RefObject } from 'react'
|
|
import { useForm, type SubmitHandler } from 'react-hook-form'
|
|
import {
|
|
Button,
|
|
Dialog,
|
|
DialogContent,
|
|
DialogFooter,
|
|
DialogHeader,
|
|
DialogSection,
|
|
DialogSectionSeparator,
|
|
DialogTitle,
|
|
Form,
|
|
FormControl,
|
|
FormField,
|
|
Textarea,
|
|
} from 'ui'
|
|
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
|
|
import * as z from 'zod'
|
|
|
|
interface LayoutSwitchFeedbackDialogProps {
|
|
isOpen: boolean
|
|
returnFocusRef: RefObject<HTMLButtonElement | null>
|
|
onCancel: () => void
|
|
onSubmit: (comment: string) => Promise<void>
|
|
}
|
|
|
|
const formSchema = z.object({
|
|
comment: z.string().trim(),
|
|
})
|
|
|
|
type LayoutSwitchFeedbackFields = z.infer<typeof formSchema>
|
|
|
|
const DEFAULT_VALUES: LayoutSwitchFeedbackFields = { comment: '' }
|
|
|
|
export const LayoutSwitchFeedbackDialog = ({
|
|
isOpen,
|
|
returnFocusRef,
|
|
onCancel,
|
|
onSubmit,
|
|
}: LayoutSwitchFeedbackDialogProps) => {
|
|
const form = useForm<LayoutSwitchFeedbackFields>({
|
|
defaultValues: DEFAULT_VALUES,
|
|
resolver: zodResolver(formSchema),
|
|
})
|
|
const { isSubmitting } = form.formState
|
|
const formId = useId()
|
|
|
|
const handleOpenChange = (isNextOpen: boolean) => {
|
|
if (isNextOpen || isSubmitting) return
|
|
form.reset()
|
|
onCancel()
|
|
}
|
|
|
|
const handleCancel = () => handleOpenChange(false)
|
|
|
|
// the dialog has no trigger, so radix has no element to return focus to
|
|
const handleCloseAutoFocus = (event: Event) => {
|
|
event.preventDefault()
|
|
returnFocusRef.current?.focus()
|
|
}
|
|
|
|
const handleSubmit: SubmitHandler<LayoutSwitchFeedbackFields> = ({ comment }) => onSubmit(comment)
|
|
|
|
return (
|
|
<Dialog open={isOpen} onOpenChange={handleOpenChange}>
|
|
<DialogContent onCloseAutoFocus={handleCloseAutoFocus}>
|
|
<DialogHeader>
|
|
<DialogTitle>Switch to classic layout</DialogTitle>
|
|
</DialogHeader>
|
|
<DialogSectionSeparator />
|
|
<Form {...form}>
|
|
<form id={formId} onSubmit={form.handleSubmit(handleSubmit)}>
|
|
<DialogSection>
|
|
<FormField
|
|
control={form.control}
|
|
name="comment"
|
|
render={({ field }) => (
|
|
<FormItemLayout
|
|
layout="vertical"
|
|
label="What made you switch back?"
|
|
labelOptional="Optional"
|
|
>
|
|
<FormControl>
|
|
<Textarea {...field} rows={4} className="resize-none" />
|
|
</FormControl>
|
|
</FormItemLayout>
|
|
)}
|
|
/>
|
|
</DialogSection>
|
|
</form>
|
|
</Form>
|
|
<DialogFooter>
|
|
<Button disabled={isSubmitting} onClick={handleCancel}>
|
|
Cancel
|
|
</Button>
|
|
<Button
|
|
variant="primary"
|
|
type="submit"
|
|
form={formId}
|
|
loading={isSubmitting}
|
|
disabled={isSubmitting}
|
|
>
|
|
Switch to classic layout
|
|
</Button>
|
|
</DialogFooter>
|
|
</DialogContent>
|
|
</Dialog>
|
|
)
|
|
}
|