Files
supabase/apps/studio/components/interfaces/Support/SupportForm.state.ts
T
Saxon Fletcher 033daf223c Support form Assistant Streamdown (#46248)
Re-adds support form Assistant response using a lighter weight
Streamdown component vs the more heavy `Message` component.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* AI Assistant follow-up card after ticket submission for project-scoped
requests.
* In-chat support request preview panels showing submitted subject and
message.

* **Improvements**
* Smarter project selection when opening the support form via
route/context.
* Success screen: cleaner layout, project-name messaging, optional
finish action, and a "Join Discord" button.
  * Category prompt text updated to "What issue are you having?"
  * New success/feedback section for consistent layouts.

* **Tests**
* Added tests covering support prompt serialization/parsing and UI
previews.

<!-- review_stack_entry_start -->

[![Review Change
Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/supabase/supabase/pull/46248?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack)

<!-- review_stack_entry_end -->
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-05-26 09:56:52 +00:00

111 lines
3.0 KiB
TypeScript

import type { ExtendedSupportCategories } from './Support.constants'
import type { SupportFormValues } from './SupportForm.schema'
import { neverGuard } from '@/lib/helpers'
export type SubmittedSupportRequest = Pick<
SupportFormValues,
'category' | 'severity' | 'subject' | 'message' | 'affectedServices' | 'allowSupportAccess'
> & {
organizationSlug: string | undefined
projectRef: string | undefined
library?: string
dashboardLogs?: string
}
export type SupportFormState =
| {
type: 'initializing'
}
| {
type: 'editing'
}
| {
type: 'submitting'
}
| {
type: 'success'
sentProjectRef: string | undefined
sentOrgSlug: string | undefined
sentCategory: ExtendedSupportCategories
submittedRequest: SubmittedSupportRequest
}
| {
type: 'error'
message: string
}
export type SupportFormActions =
| { type: 'INITIALIZE'; debugSource?: string }
| { type: 'SUBMIT'; debugSource?: string }
| {
type: 'SUCCESS'
sentProjectRef: string | undefined
sentOrgSlug: string | undefined
sentCategory: ExtendedSupportCategories
submittedRequest: SubmittedSupportRequest
debugSource?: string
}
| { type: 'ERROR'; message: string; debugSource?: string }
| { type: 'RETURN_TO_EDITING'; debugSource?: string }
export function createInitialSupportFormState(): SupportFormState {
return {
type: 'initializing',
}
}
export function supportFormReducer(
state: SupportFormState,
action: SupportFormActions
): SupportFormState {
switch (state.type) {
case 'initializing':
if (action.type === 'INITIALIZE') {
return { type: 'editing' }
}
console.warn(
`[SupportForm > supportFormReducer] ${action.type} action not allowed in 'initializing' state`
)
return state
case 'editing':
if (action.type === 'SUBMIT') {
return { type: 'submitting' }
}
console.warn(
`[SupportForm > supportFromReducer] ${action.type} action not allowed in 'filling_out' state`
)
return state
case 'submitting':
if (action.type === 'SUCCESS') {
return {
type: 'success',
sentProjectRef: action.sentProjectRef,
sentOrgSlug: action.sentOrgSlug,
sentCategory: action.sentCategory,
submittedRequest: action.submittedRequest,
}
}
if (action.type === 'ERROR') {
return {
type: 'error',
message: action.message,
}
}
console.warn(
`[SupportForm > supportFormReducer] ${action.type} action not allowed in 'submitting' state`
)
return state
case 'success':
console.warn(`[SupportForm > supportFormReducer] ${action.type} allowed in 'success' state`)
return state
case 'error':
if (action.type === 'RETURN_TO_EDITING') {
return { type: 'editing' }
}
console.warn(`[SupportForm > supportFormReducer] ${action.type} allowed in 'success' state`)
return state
default:
return neverGuard(state)
}
}