mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 01:45:10 +03:00
## What kind of change does this PR introduce? Mechanical cleanup on top of the Button default-variant change (#50160). ## What is the current behavior? Many callsites still pass `variant="default"` even though that is now the component default. ## What is the new behavior? Removes redundant static `variant="default"` from legacy `Button` and `ButtonTooltip` callsites. Keeps explicit defaults where they document the API: - `button-default.tsx` and `button-sizes.tsx` demos - `DocsButton`, which pins neutral styling at the wrapper boundary ## To test Studio: - [Auth → Rate Limits](https://studio-staging-2s957kwc4-supabase.vercel.app/dashboard/project/_/auth/rate-limits): dirty the form so Cancel appears; Cancel stays neutral, Save stays green - [Project Settings → API Keys](https://studio-staging-2s957kwc4-supabase.vercel.app/dashboard/project/_/settings/api-keys): `DocsButton` in the header actions stays neutral Design system: - [Design system → Button](https://design-system-git-dnywh-dc924ac1-supabase.vercel.app/design-system/docs/components/button): `button-default` / `button-sizes` still show explicit default styling; Primary (green) is restricted to the Primary section (and `asChild`) WWW: - [www → Brand assets](https://zone-www-dot-com-git-dnywh-dc924ac1-supabase.vercel.app/brand-assets): Download logo kit / Download button kit stay neutral
163 lines
5.4 KiB
TypeScript
163 lines
5.4 KiB
TypeScript
import * as Sentry from '@sentry/nextjs'
|
|
import { useFlag } from 'common'
|
|
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 { SupportAssistantSuccessCard } from './SupportAssistantSuccessCard'
|
|
import { createInitialSupportFormState, supportFormReducer } from './SupportForm.state'
|
|
import { NO_PROJECT_MARKER, type SupportFormUrlKeys } from './SupportForm.utils'
|
|
import { SupportFormV3 } from './SupportFormV3'
|
|
import { useSupportForm } from './useSupportForm'
|
|
import { useIncidentStatusQuery } from '@/data/platform/incident-status-query'
|
|
import { useStateTransition } from '@/hooks/misc/useStateTransition'
|
|
import { useTrack } from '@/lib/telemetry/track'
|
|
|
|
function useSupportFormTelemetry() {
|
|
const track = useTrack()
|
|
|
|
return useCallback(
|
|
({
|
|
projectRef,
|
|
orgSlug,
|
|
category,
|
|
}: {
|
|
projectRef: string | undefined
|
|
orgSlug: string | undefined
|
|
category: ExtendedSupportCategories
|
|
}) =>
|
|
track(
|
|
'support_ticket_submitted',
|
|
{ ticketCategory: category },
|
|
{ project: projectRef, organization: orgSlug }
|
|
),
|
|
[track]
|
|
)
|
|
}
|
|
|
|
interface SupportFormProps {
|
|
initialParams?: Partial<SupportFormUrlKeys>
|
|
}
|
|
|
|
export function SupportForm({ initialParams }: SupportFormProps) {
|
|
const [state, dispatch] = useReducer(supportFormReducer, undefined, createInitialSupportFormState)
|
|
const { form, initialError, projectRef } = useSupportForm(dispatch, initialParams)
|
|
const showSupportAssistantFollowUp = useFlag('supportAssistantFollowUp') === true
|
|
|
|
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}`)
|
|
if (curr.code !== 429) {
|
|
Sentry.captureMessage(`Failed to submit Support Form: ${curr.message}`)
|
|
}
|
|
dispatch({ type: 'RETURN_TO_EDITING' })
|
|
})
|
|
|
|
const successState = state.type === 'success' ? state : null
|
|
const showAssistantSuccessCard =
|
|
showSupportAssistantFollowUp &&
|
|
successState !== null &&
|
|
successState.submittedRequest.projectRef !== undefined &&
|
|
successState.submittedRequest.projectRef !== NO_PROJECT_MARKER
|
|
|
|
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">
|
|
{successState ? (
|
|
<div className="flex flex-col gap-y-8 pt-2">
|
|
<Success
|
|
selectedProject={
|
|
successState.sentProjectRef === undefined
|
|
? (projectRef ?? undefined)
|
|
: successState.sentProjectRef
|
|
}
|
|
sentCategory={successState.sentCategory}
|
|
showFinishAction={false}
|
|
/>
|
|
{showAssistantSuccessCard && (
|
|
<SupportAssistantSuccessCard request={successState.submittedRequest} />
|
|
)}
|
|
</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
|
|
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>
|
|
)
|
|
}
|