mirror of
https://github.com/supabase/supabase.git
synced 2026-10-12 21:05:06 +03:00
## What kind of change does this PR introduce? UI improvement for self-debugging efforts. ## What is the current behavior? https://github.com/supabase/supabase/pull/40937 removed our gating on the feedback form (plus some related affordances) in an effort to concentrate support entry into the Help dropdown instead: | Before | After | | --- | --- | | <img width="1090" height="579" alt="Inventory Nuts Bolts Supabase" src="https://github.com/user-attachments/assets/c7dacf40-5ae8-401c-a167-5e56c4c0635d" /> | _Not applicable. This step is skipped in the new version._ | | <img width="1090" height="579" alt="Inventory Nuts Bolts Supabase" src="https://github.com/user-attachments/assets/9bd2489d-7e87-49e5-99af-13eb5f387f60" /> | <img width="1090" height="579" alt="Inventory Nuts Bolts Supabase" src="https://github.com/user-attachments/assets/fa499a40-6d70-4674-9eb6-c7bd96019b27" /> | | <img width="1090" height="579" alt="Inventory Nuts Bolts Supabase" src="https://github.com/user-attachments/assets/e253381b-e8ba-476c-bd36-9dd522209498" /> | <img width="1090" height="579" alt="Inventory Nuts Bolts Supabase" src="https://github.com/user-attachments/assets/b5cf614b-329c-4517-90e9-c4d1b49bd139" /> | Despite putting other measures in place such as client-side form detection, the result is that people are increasingly writing in to support via the Feedback form. ## What is the new behavior? - Restores the gating - But also reuses the same self-debugging help options from the Help dropdown Other: - Renames `HelpPopover` to `HelpDropdown` to match others - Adjusts font size of `CommandMenu` _Search..._ | Before | After | | --- | --- | | <img width="1024" height="756" alt="Spinner Toolshed Supabase" src="https://github.com/user-attachments/assets/12e3be32-743d-488a-a13d-bf400fd0fd8d" /> | <img width="1024" height="756" alt="Spinner Toolshed Supabase" src="https://github.com/user-attachments/assets/bb064ef1-a771-416d-9b5b-dbdd774efed3" /> | | _Not applicable. This step is skipped in the old version._ | <img width="1024" height="756" alt="Spinner Toolshed Supabase" src="https://github.com/user-attachments/assets/3bc0b1c2-7003-4973-8e9c-2c7ee93fb0b4" /> | | <img width="1024" height="756" alt="Spinner Toolshed Supabase" src="https://github.com/user-attachments/assets/0bb18df4-d093-4440-8379-680f6c5e3cf9" /> | <img width="1024" height="756" alt="Spinner Toolshed Supabase" src="https://github.com/user-attachments/assets/1ef801d3-9cd7-4005-9082-8d229b7cdd19" /> | | <img width="1090" height="579" alt="Inventory Nuts Bolts Supabase" src="https://github.com/user-attachments/assets/e253381b-e8ba-476c-bd36-9dd522209498" /> | <img width="1024" height="794" alt="Spinner Toolshed Supabase" src="https://github.com/user-attachments/assets/b80de142-2199-420f-9018-8622b6d24312" /> | ## To test To test the “thanks” end state, add something like the following to `feedback-send.ts`: ```ts if (MOCK_FEEDBACK_SUCCESS) { return {} as Awaited<ReturnType<typeof sendFeedback>> } ``` Where `MOCK_FEEDBACK_SUCCESS` is `true`. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **New Features** * Introduced multi-stage feedback dropdown with Issue and Idea selection paths. * Added AI assistant integration in help menu for quick support access. * Enhanced help dropdown with expanded options: documentation, troubleshooting, Discord community, system status, and support links. * Added Community Support section featuring Discord community promotion. * **Style** * Refined command menu placeholder text sizing for improved visual hierarchy. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
328 lines
11 KiB
TypeScript
328 lines
11 KiB
TypeScript
import { useDebounce } from '@uidotdev/usehooks'
|
||
import { AnimatePresence, motion } from 'framer-motion'
|
||
import { toPng } from 'html-to-image'
|
||
import { Camera, CircleCheck, HelpCircle, Image as ImageIcon, Upload, X } from 'lucide-react'
|
||
import { useRouter } from 'next/router'
|
||
import { ChangeEvent, useEffect, useRef, useState } from 'react'
|
||
import { toast } from 'sonner'
|
||
|
||
import { LOCAL_STORAGE_KEYS, useParams } from 'common'
|
||
import { InlineLinkClassName } from 'components/ui/InlineLink'
|
||
import { SupportLink } from 'components/interfaces/Support/SupportLink'
|
||
import { useFeedbackCategoryQuery } from 'data/feedback/feedback-category'
|
||
import { useSendFeedbackMutation } from 'data/feedback/feedback-send'
|
||
import { useSendEventMutation } from 'data/telemetry/send-event-mutation'
|
||
import { useLocalStorageQuery } from 'hooks/misc/useLocalStorage'
|
||
import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization'
|
||
import { timeout } from 'lib/helpers'
|
||
import { useProfile } from 'lib/profile'
|
||
import {
|
||
Button,
|
||
cn,
|
||
DropdownMenu,
|
||
DropdownMenuContent,
|
||
DropdownMenuItem,
|
||
DropdownMenuSeparator,
|
||
DropdownMenuTrigger,
|
||
PopoverSeparator_Shadcn_,
|
||
TextArea_Shadcn_,
|
||
} from 'ui'
|
||
import { Admonition } from 'ui-patterns'
|
||
import {
|
||
convertB64toBlob,
|
||
isLikelySupportRequest,
|
||
uploadAttachment,
|
||
} from './FeedbackDropdown.utils'
|
||
|
||
interface FeedbackWidgetProps {
|
||
onClose: () => void
|
||
onSwitchToIssueOptions: () => void
|
||
}
|
||
|
||
export const FeedbackWidget = ({ onClose, onSwitchToIssueOptions }: FeedbackWidgetProps) => {
|
||
const router = useRouter()
|
||
const { profile } = useProfile()
|
||
const { ref, slug } = useParams()
|
||
const { data: org } = useSelectedOrganizationQuery()
|
||
|
||
const uploadButtonRef = useRef(null)
|
||
const [feedback, setFeedback] = useState('')
|
||
const [isSending, setSending] = useState(false)
|
||
const [isSavingScreenshot, setIsSavingScreenshot] = useState(false)
|
||
const [isFeedbackSent, setIsFeedbackSent] = useState(false)
|
||
|
||
const debouncedFeedback = useDebounce(feedback, 500)
|
||
|
||
const [storedFeedback, setStoredFeedback] = useLocalStorageQuery<string | null>(
|
||
LOCAL_STORAGE_KEYS.FEEDBACK_WIDGET_CONTENT,
|
||
null
|
||
)
|
||
const [screenshot, setScreenshot, { isSuccess }] = useLocalStorageQuery<string | null>(
|
||
LOCAL_STORAGE_KEYS.FEEDBACK_WIDGET_SCREENSHOT,
|
||
null
|
||
)
|
||
|
||
const { data: category } = useFeedbackCategoryQuery({ prompt: debouncedFeedback })
|
||
|
||
// Use client-side heuristic for immediate feedback, AI result takes precedence when available
|
||
const isLikelySupport = isLikelySupportRequest(feedback)
|
||
const effectiveCategory = category ?? (isLikelySupport ? 'support' : null)
|
||
|
||
const { mutate: sendEvent } = useSendEventMutation()
|
||
const { mutate: submitFeedback } = useSendFeedbackMutation({
|
||
onSuccess: () => {
|
||
setIsFeedbackSent(true)
|
||
setFeedback('')
|
||
setStoredFeedback(null)
|
||
setScreenshot(null)
|
||
setSending(false)
|
||
},
|
||
onError: (error) => {
|
||
toast.error(`Failed to submit feedback: ${error.message}`)
|
||
setSending(false)
|
||
},
|
||
})
|
||
|
||
const captureScreenshot = async () => {
|
||
setIsSavingScreenshot(true)
|
||
|
||
function filter(node: HTMLElement) {
|
||
if ((node?.children ?? []).length > 0) {
|
||
return node.children[0].id !== 'feedback-widget'
|
||
}
|
||
return true
|
||
}
|
||
|
||
// Give time for dropdown to close
|
||
await timeout(100)
|
||
toPng(document.body, { filter })
|
||
.then((dataUrl: any) => setScreenshot(dataUrl))
|
||
.catch(() => toast.error('Failed to capture screenshot'))
|
||
.finally(() => setIsSavingScreenshot(false))
|
||
}
|
||
|
||
const onFilesUpload = async (event: ChangeEvent<HTMLInputElement>) => {
|
||
event.persist()
|
||
const [file] = event.target.files || (event as any).dataTransfer.items
|
||
|
||
const reader = new FileReader()
|
||
reader.onload = function (event) {
|
||
const dataUrl = event.target?.result
|
||
if (typeof dataUrl === 'string') setScreenshot(dataUrl)
|
||
}
|
||
reader.readAsDataURL(file)
|
||
event.target.value = ''
|
||
}
|
||
|
||
const handlePasteEvent = async () => {
|
||
// [Joshen] Support pasting images via Cmd / Ctrl + V
|
||
const [data] = await navigator.clipboard.read()
|
||
|
||
if (screenshot === undefined && data.types[0] === 'image/png') {
|
||
const blob = await data.getType('image/png')
|
||
const reader = new FileReader()
|
||
reader.onload = function (event) {
|
||
const dataUrl = event.target?.result
|
||
if (typeof dataUrl === 'string') setScreenshot(dataUrl)
|
||
}
|
||
reader.readAsDataURL(blob)
|
||
}
|
||
}
|
||
|
||
const sendFeedback = async () => {
|
||
if (feedback.length === 0 && screenshot !== undefined) {
|
||
return toast.error('Please include a message in your feedback.')
|
||
} else if (feedback.length > 0) {
|
||
setSending(true)
|
||
|
||
const attachmentUrl =
|
||
screenshot && profile?.gotrue_id
|
||
? await uploadAttachment({
|
||
image: screenshot,
|
||
userId: profile.gotrue_id,
|
||
})
|
||
: undefined
|
||
const formattedFeedback =
|
||
attachmentUrl !== undefined ? `${feedback}\n\nAttachments:\n${attachmentUrl}` : feedback
|
||
|
||
submitFeedback({
|
||
projectRef: ref,
|
||
organizationSlug: slug,
|
||
message: formattedFeedback,
|
||
pathname: router.asPath,
|
||
})
|
||
}
|
||
}
|
||
|
||
// Hydrate form from localStorage once it's ready; deps intentionally omit storedFeedback/screenshot
|
||
// so we don't overwrite user edits when those values change after initial load.
|
||
useEffect(() => {
|
||
if (storedFeedback) setFeedback(storedFeedback)
|
||
if (screenshot) setScreenshot(screenshot)
|
||
// eslint-disable-next-line react-hooks/exhaustive-deps -- hydrate once when localStorage is ready only
|
||
}, [isSuccess])
|
||
|
||
// Persist debounced input to localStorage; only re-run when debounced value changes.
|
||
useEffect(() => {
|
||
if (debouncedFeedback.length > 0) setStoredFeedback(debouncedFeedback)
|
||
// eslint-disable-next-line react-hooks/exhaustive-deps -- setStoredFeedback is stable; only sync on debounced value
|
||
}, [debouncedFeedback])
|
||
|
||
const ThanksMessageView = () => (
|
||
<>
|
||
<div className="py-6 px-4 grid gap-4 text-center text-foreground-light">
|
||
<CircleCheck className="mx-auto text-brand-500" size={24} />
|
||
<div className="flex flex-col gap-1">
|
||
<p className="text-foreground text-base">Your feedback has been sent. Thanks!</p>
|
||
<p className="text-sm text-balance">
|
||
We don’t always respond to feedback. If you need help with your project, use the button
|
||
below.
|
||
</p>
|
||
</div>
|
||
</div>
|
||
<PopoverSeparator_Shadcn_ />
|
||
<div className="px-4 pt-4 pb-4 flex flex-row items-center justify-between">
|
||
<Button type="default" size="tiny" onClick={onSwitchToIssueOptions}>
|
||
Get help
|
||
</Button>
|
||
<Button type="default" size="tiny" onClick={onClose}>
|
||
Close
|
||
</Button>
|
||
</div>
|
||
</>
|
||
)
|
||
|
||
return isFeedbackSent ? (
|
||
<ThanksMessageView />
|
||
) : (
|
||
<>
|
||
<div className="p-4">
|
||
<TextArea_Shadcn_
|
||
placeholder="My idea for improving Supabase is..."
|
||
rows={6}
|
||
value={feedback}
|
||
onChange={(e) => setFeedback(e.target.value)}
|
||
onPaste={handlePasteEvent}
|
||
className="text-sm mb-1 resize-none"
|
||
/>
|
||
</div>
|
||
|
||
<AnimatePresence>
|
||
{effectiveCategory === 'support' && (
|
||
<motion.div
|
||
key="support-alert"
|
||
initial={{ opacity: 0, y: 16 }}
|
||
animate={{ opacity: 1, y: 0 }}
|
||
exit={{ opacity: 0, y: 16 }}
|
||
transition={{ duration: 0.2 }}
|
||
>
|
||
<Admonition
|
||
type="caution"
|
||
title="This looks like an issue that’s better handled by support"
|
||
className="rounded-none border-x-0 border-b-0"
|
||
>
|
||
<p>
|
||
Please{' '}
|
||
<SupportLink
|
||
className={cn(InlineLinkClassName)}
|
||
queryParams={{ projectRef: slug, message: feedback }}
|
||
>
|
||
open a support ticket
|
||
</SupportLink>{' '}
|
||
to get help, as we do not reply to all product feedback.
|
||
</p>
|
||
</Admonition>
|
||
</motion.div>
|
||
)}
|
||
</AnimatePresence>
|
||
|
||
<PopoverSeparator_Shadcn_ />
|
||
|
||
<div className="px-4 pt-4 pb-4 flex flex-row items-center justify-between">
|
||
<Button type="default" size="tiny" onClick={onSwitchToIssueOptions}>
|
||
Get help instead
|
||
</Button>
|
||
<div className="flex items-center gap-2 flex-row">
|
||
{!!screenshot ? (
|
||
<div
|
||
style={{ backgroundImage: `url("${screenshot}")` }}
|
||
onClick={() => {
|
||
const blob = convertB64toBlob(screenshot)
|
||
const blobUrl = URL.createObjectURL(blob)
|
||
window.open(blobUrl, '_blank')
|
||
}}
|
||
className="cursor-pointer rounded h-[26px] w-[26px] border border-control relative bg-cover bg-center bg-no-repeat"
|
||
>
|
||
<button
|
||
className={[
|
||
'cursor-pointer rounded-full bg-red-900 h-3 w-3',
|
||
'flex items-center justify-center absolute -top-1 -right-1',
|
||
].join(' ')}
|
||
onClick={(event) => {
|
||
event.stopPropagation()
|
||
setScreenshot(null)
|
||
}}
|
||
>
|
||
<X size={8} strokeWidth={3} />
|
||
</button>
|
||
</div>
|
||
) : (
|
||
<DropdownMenu>
|
||
<DropdownMenuTrigger asChild>
|
||
<Button
|
||
type="default"
|
||
disabled={isSavingScreenshot}
|
||
loading={isSavingScreenshot}
|
||
className="w-7"
|
||
icon={<ImageIcon size={14} />}
|
||
/>
|
||
</DropdownMenuTrigger>
|
||
<DropdownMenuContent side="bottom" align="end" className="w-fit">
|
||
<DropdownMenuItem
|
||
className="flex gap-2"
|
||
key="upload-screenshot"
|
||
onSelect={() => {
|
||
if (uploadButtonRef.current) (uploadButtonRef.current as any).click()
|
||
}}
|
||
>
|
||
<Upload size={14} />
|
||
Upload screenshot
|
||
</DropdownMenuItem>
|
||
<DropdownMenuSeparator />
|
||
<DropdownMenuItem
|
||
className="flex gap-2"
|
||
key="capture-screenshot"
|
||
onSelect={() => captureScreenshot()}
|
||
>
|
||
<Camera size={14} />
|
||
Capture screenshot
|
||
</DropdownMenuItem>
|
||
</DropdownMenuContent>
|
||
</DropdownMenu>
|
||
)}
|
||
<input
|
||
type="file"
|
||
ref={uploadButtonRef}
|
||
className="hidden"
|
||
accept="image/png"
|
||
onChange={onFilesUpload}
|
||
/>
|
||
<Button
|
||
disabled={feedback.length === 0 || isSending}
|
||
loading={isSending}
|
||
onClick={() => {
|
||
sendFeedback()
|
||
sendEvent({
|
||
action: 'send_feedback_button_clicked',
|
||
groups: { project: ref, organization: org?.slug },
|
||
})
|
||
}}
|
||
>
|
||
Send
|
||
</Button>
|
||
</div>
|
||
</div>
|
||
</>
|
||
)
|
||
}
|