mirror of
https://github.com/supabase/supabase.git
synced 2026-10-10 20:05:06 +03:00
Refactors our help sidebar within Studio to include the actual support form itself when contact is selected. This PR also cleans up the initial state of the sidebar and the options within. ## To test: - Open an org and click the help icon top right - Click contact support - Submit a support ticket - Click done to return to support sidebar state <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Support form V3 and support sidebar with status button; direct-email helper and URL prefill * Success screen supports onFinish callback and customizable finish label * AI Assistant and Help options accept optional click callbacks; resource items gain keyboard/accessibility support * **Refactor** * Help panel split into home/support views with back navigation * Support components accept flexible align/className props and layout/styling tweaks * Initial URL params loader added for support form * **Tests** * New/updated tests for support flows, success screen, and help options interactions <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Gildas Garcia <1122076+djhi@users.noreply.github.com>
136 lines
3.2 KiB
TypeScript
136 lines
3.2 KiB
TypeScript
import { ChevronRight, MoreVertical } from 'lucide-react'
|
|
import Link from 'next/link'
|
|
import { forwardRef, HTMLAttributes, KeyboardEvent, ReactNode } from 'react'
|
|
import {
|
|
Button,
|
|
CardContent,
|
|
cn,
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuItem,
|
|
DropdownMenuTrigger,
|
|
} from 'ui'
|
|
|
|
export interface ResourceAction {
|
|
label: string
|
|
onClick: () => void
|
|
}
|
|
|
|
export interface ResourceItemProps extends HTMLAttributes<HTMLDivElement> {
|
|
media?: ReactNode
|
|
meta?: ReactNode
|
|
onClick?: () => void
|
|
children?: ReactNode
|
|
actions?: ResourceAction[]
|
|
href?: string
|
|
target?: string
|
|
rel?: string
|
|
}
|
|
|
|
export const ResourceItem = forwardRef<HTMLDivElement, ResourceItemProps>(
|
|
(
|
|
{
|
|
media,
|
|
meta,
|
|
onClick,
|
|
children,
|
|
className,
|
|
actions,
|
|
href,
|
|
target,
|
|
rel,
|
|
onKeyDown,
|
|
role,
|
|
tabIndex,
|
|
...props
|
|
},
|
|
ref
|
|
) => {
|
|
const handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
|
|
onKeyDown?.(event)
|
|
|
|
if (event.defaultPrevented || !onClick || event.target !== event.currentTarget) return
|
|
|
|
if (event.key === 'Enter' || event.key === ' ') {
|
|
event.preventDefault()
|
|
onClick()
|
|
}
|
|
}
|
|
|
|
const content = (
|
|
<>
|
|
{media && (
|
|
<div className="text-foreground-light flex items-center justify-center">{media}</div>
|
|
)}
|
|
<div className="flex-1">{children}</div>
|
|
{meta && <div>{meta}</div>}
|
|
{actions && actions.length > 0 ? (
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger asChild>
|
|
<Button
|
|
type="text"
|
|
className="px-1"
|
|
icon={<MoreVertical size={16} />}
|
|
onClick={(e) => {
|
|
e.stopPropagation()
|
|
}}
|
|
/>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent align="end">
|
|
{actions.map((action) => (
|
|
<DropdownMenuItem
|
|
key={action.label}
|
|
onClick={(e) => {
|
|
e.stopPropagation()
|
|
action.onClick()
|
|
}}
|
|
>
|
|
{action.label}
|
|
</DropdownMenuItem>
|
|
))}
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
) : (
|
|
onClick && <ChevronRight strokeWidth={1.5} size={16} />
|
|
)}
|
|
</>
|
|
)
|
|
|
|
const rootClassName = cn(
|
|
'flex items-center justify-between text-sm gap-4',
|
|
'border-b-0!',
|
|
(onClick || href) && 'cursor-pointer transition-colors duration-150 hover:bg-surface-200',
|
|
className
|
|
)
|
|
|
|
if (href) {
|
|
return (
|
|
<Link
|
|
href={href}
|
|
target={target}
|
|
rel={rel}
|
|
className={cn('py-4 px-(--card-padding-x) border-b last:border-none', rootClassName)}
|
|
>
|
|
{content}
|
|
</Link>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<CardContent
|
|
ref={ref}
|
|
className={rootClassName}
|
|
onClick={onClick}
|
|
onKeyDown={handleKeyDown}
|
|
role={onClick ? 'button' : role}
|
|
tabIndex={onClick ? (tabIndex ?? 0) : tabIndex}
|
|
{...props}
|
|
>
|
|
{content}
|
|
</CardContent>
|
|
)
|
|
}
|
|
)
|
|
|
|
ResourceItem.displayName = 'ResourceItem'
|