// End of third-party imports import { SupportCategories } from '@supabase/shared-types/out/constants' import type { UseFormReturn } from 'react-hook-form' import { cn, FormControl, FormField, Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue, } from 'ui' import { Admonition } from 'ui-patterns/admonition' import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout' import { CATEGORY_OPTIONS, SEVERITY_OPTIONS, type ExtendedSupportCategories, } from './Support.constants' import type { SupportFormValues } from './SupportForm.schema' import { NO_PROJECT_MARKER } from './SupportForm.utils' import { InlineLink } from '@/components/ui/InlineLink' interface CategoryAndSeverityInfoProps { form: UseFormReturn category: ExtendedSupportCategories severity?: string projectRef: string showSeverity?: boolean showIssueSuggestion?: boolean } export function CategoryAndSeverityInfo({ form, category, severity, projectRef, showSeverity = true, showIssueSuggestion = true, }: CategoryAndSeverityInfoProps) { return (
{showSeverity && } {showIssueSuggestion && } {(severity === 'Urgent' || severity === 'High') && ( )}
) } interface CategorySelectorProps { form: UseFormReturn } function CategorySelector({ form }: CategorySelectorProps) { return ( { const { ref: _ref, ...fieldWithoutRef } = field // Radix Select fires `onValueChange('')` when its controlled value // transitions from `undefined` to a defined value whose matching // SelectItem isn't mounted yet (the dropdown is closed, so // SelectContent and the items it portals haven't registered). On // React 19's stricter scheduling this races our `setValue` from // useSupportForm and clobbers the prefilled category. No // SelectItem can have value="" (Radix throws), so `v === ''` is // always the spurious bubble — drop it. See // radix-ui/primitives#3381. const onValueChange = (v: string) => { if (v === '' && field.value) return field.onChange(v) } return ( ) }} /> ) } interface SeveritySelectorProps { form: UseFormReturn } function SeveritySelector({ form }: SeveritySelectorProps) { return ( { const { ref, ...fieldWithoutRef } = field return ( ) }} /> ) } const IssueSuggestion = ({ category, projectRef }: { category: string; projectRef?: string }) => { const baseUrl = `/project/${projectRef === NO_PROJECT_MARKER ? '_' : projectRef}` const className = 'col-span-2 mb-0' if (category === SupportCategories.PROBLEM) { return ( Logs can help you identify errors that you might be running into when using your project's API or client libraries. View logs for each product{' '} here. ) } if (category === SupportCategories.DATABASE_UNRESPONSIVE) { return ( High memory or low disk IO bandwidth may be slowing down your database. Verify by checking the infrastructure activity of your project{' '} here . ) } if (category === SupportCategories.PERFORMANCE_ISSUES) { return ( Identify slow running queries and get actionable insights on how to optimize them with the Query Performance Advisor{' '} here . ) } return null }