mirror of
https://github.com/supabase/supabase.git
synced 2026-06-20 20:16:04 +08: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>
154 lines
4.9 KiB
TypeScript
154 lines
4.9 KiB
TypeScript
import * as Sentry from '@sentry/nextjs'
|
|
import { Loader2 } from 'lucide-react'
|
|
import Link from 'next/link'
|
|
import { useCallback, useReducer } from 'react'
|
|
import { toast } from 'sonner'
|
|
import { Button, cn, Tooltip, TooltipContent, TooltipTrigger } from 'ui'
|
|
|
|
import { IncidentAdmonition } from './IncidentAdmonition'
|
|
import { Success } from './Success'
|
|
import type { ExtendedSupportCategories } from './Support.constants'
|
|
import { createInitialSupportFormState, supportFormReducer } from './SupportForm.state'
|
|
import type { SupportFormUrlKeys } from './SupportForm.utils'
|
|
import { SupportFormV3 } from './SupportFormV3'
|
|
import { useSupportForm } from './useSupportForm'
|
|
import { useIncidentStatusQuery } from '@/data/platform/incident-status-query'
|
|
import { useSendEventMutation } from '@/data/telemetry/send-event-mutation'
|
|
import { useStateTransition } from '@/hooks/misc/useStateTransition'
|
|
|
|
function useSupportFormTelemetry() {
|
|
const { mutate: sendEvent } = useSendEventMutation()
|
|
|
|
return useCallback(
|
|
({
|
|
projectRef,
|
|
orgSlug,
|
|
category,
|
|
}: {
|
|
projectRef: string | undefined
|
|
orgSlug: string | undefined
|
|
category: ExtendedSupportCategories
|
|
}) =>
|
|
sendEvent({
|
|
action: 'support_ticket_submitted',
|
|
properties: {
|
|
ticketCategory: category,
|
|
},
|
|
groups: {
|
|
project: projectRef,
|
|
organization: orgSlug,
|
|
},
|
|
}),
|
|
[sendEvent]
|
|
)
|
|
}
|
|
|
|
interface SupportFormProps {
|
|
initialParams?: Partial<SupportFormUrlKeys>
|
|
onFinish?: () => void
|
|
}
|
|
|
|
export function SupportForm({ initialParams, onFinish }: SupportFormProps) {
|
|
const [state, dispatch] = useReducer(supportFormReducer, undefined, createInitialSupportFormState)
|
|
const { form, initialError, projectRef } = useSupportForm(dispatch, initialParams)
|
|
|
|
const {
|
|
data: allStatusPageEvents,
|
|
isPending: isIncidentsPending,
|
|
isError: isIncidentsError,
|
|
} = useIncidentStatusQuery()
|
|
const { incidents = [] } = allStatusPageEvents ?? {}
|
|
const hasActiveIncidents =
|
|
!isIncidentsPending && !isIncidentsError && incidents && incidents.length > 0
|
|
|
|
const sendTelemetry = useSupportFormTelemetry()
|
|
useStateTransition(state, 'submitting', 'success', (_, curr) => {
|
|
toast.success('Support request sent. Thank you!')
|
|
sendTelemetry({
|
|
projectRef: curr.sentProjectRef,
|
|
orgSlug: curr.sentOrgSlug,
|
|
category: curr.sentCategory,
|
|
})
|
|
})
|
|
|
|
useStateTransition(state, 'submitting', 'error', (_, curr) => {
|
|
toast.error(`Failed to submit support ticket: ${curr.message}`)
|
|
Sentry.captureMessage(`Failed to submit Support Form: ${curr.message}`)
|
|
dispatch({ type: 'RETURN_TO_EDITING' })
|
|
})
|
|
|
|
const isSuccess = state.type === 'success'
|
|
|
|
return (
|
|
<div className="relative h-full overflow-y-auto overflow-x-hidden">
|
|
<IncidentAdmonition
|
|
isActive={hasActiveIncidents}
|
|
className="rounded-none border-x-0 shadow-none"
|
|
/>
|
|
<div className="min-h-full px-5 pt-5">
|
|
<div className="flex flex-col gap-y-8">
|
|
{isSuccess ? (
|
|
<div className="pt-2">
|
|
<Success
|
|
selectedProject={projectRef ?? undefined}
|
|
sentCategory={state.sentCategory}
|
|
onFinish={onFinish}
|
|
finishLabel={onFinish ? 'Done' : undefined}
|
|
/>
|
|
</div>
|
|
) : (
|
|
<SupportFormV3
|
|
form={form}
|
|
initialError={initialError}
|
|
state={state}
|
|
dispatch={dispatch}
|
|
selectedProjectRef={projectRef}
|
|
/>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export function SupportFormStatusButton() {
|
|
const { data: allStatusPageEvents, isPending: isLoading, isError } = useIncidentStatusQuery()
|
|
const { incidents = [], maintenanceEvents = [] } = allStatusPageEvents ?? {}
|
|
const isMaintenance = maintenanceEvents.length > 0
|
|
const isIncident = incidents.length > 0
|
|
|
|
return (
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<Button
|
|
asChild
|
|
type="default"
|
|
size="tiny"
|
|
icon={
|
|
isLoading ? (
|
|
<Loader2 className="animate-spin" />
|
|
) : (
|
|
<div className={cn('h-2 w-2 rounded-full', isIncident ? 'bg-warning' : 'bg-brand')} />
|
|
)
|
|
}
|
|
>
|
|
<Link href="https://status.supabase.com/" target="_blank" rel="noreferrer">
|
|
{isLoading
|
|
? 'Checking status'
|
|
: isError
|
|
? 'Failed to check status'
|
|
: isIncident
|
|
? 'Active incident ongoing'
|
|
: isMaintenance
|
|
? 'Scheduled maintenance'
|
|
: 'All systems operational'}
|
|
</Link>
|
|
</Button>
|
|
</TooltipTrigger>
|
|
<TooltipContent side="bottom" align="center">
|
|
Check the Supabase status page
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
)
|
|
}
|