mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +00:00
## Problem After a support ticket is resolved, customers receive an email with a link to a satisfaction survey. That survey page is currently served from a standalone function outside this repo. We are consolidating it into the dashboard so it is deployed, monitored and tested with everything else. Linear: [TOOLING-1425](https://linear.app/supabase/issue/TOOLING-1425/build-csat-in-supase-studio) ## Solution Adds a public page at `/support/csat` that collects the survey answer and posts it to a new Platform endpoint, `POST /platform/support/csat`, which records the answer on the support conversation. Key choices: - **Pre-auth page**, modelled on `/verify-email`. Customers arrive from an email and may not have a dashboard session. Hosted platform only; self-hosted routes to 404. - **URL shape** `?conversation_id=cnv_…&helpful=yes|no` matches the links already sent in survey emails, so the email template only needs its host changed. `helpful` preselects the answer, defaulting to Yes. - **Copy and behaviour match the existing survey page**: same title, question, labels, button text, and result messages. - **Form** uses react-hook-form + zod; Yes/No are toggle buttons, the comment is optional. - **States**: missing or malformed ticket reference, already submitted (409), ticket mismatch (404), and a generic error that keeps the form so the customer can retry. - The mutation uses `fetchHandler` directly, like the email-verification mutation, because the endpoint is not in the generated API types yet. Screenshot: <img width="977" height="801" alt="image" src="https://github.com/user-attachments/assets/2331861e-e8e9-43e1-84fc-3bf5786c145e" /> Depends on the Platform endpoint https://github.com/supabase/platform/pull/40027. Until it is deployed, submissions fail with the generic error state. ## Review instructions 1. Run Studio against a Platform stack that has the `POST /platform/support/csat` endpoint. 2. Open `/support/csat?conversation_id=<a support conversation id>&helpful=yes` while logged out. The page renders without redirecting to sign in, with Yes preselected. 3. Pick an answer, optionally add a comment, and submit. The success message appears and the answer is recorded on the conversation. 4. Submit again for the same conversation: the page reports that the survey has already been submitted. 5. Open the page with no `conversation_id`: the page reports an invalid ticket. 6. `pnpm --filter studio exec vitest --run components/interfaces/Support/CsatSurvey` passes (18 tests). ## Checklist Check all before review: - [x] I have read [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) - [x] If I wrote a new docs topic or edited an existing topic, I used the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs [style guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide) --------- Co-authored-by: Gildas Garcia <1122076+djhi@users.noreply.github.com>
160 lines
4.8 KiB
TypeScript
160 lines
4.8 KiB
TypeScript
import { zodResolver } from '@hookform/resolvers/zod'
|
|
import { useParams } from 'common'
|
|
import type { ReactNode } from 'react'
|
|
import { useForm, useWatch } from 'react-hook-form'
|
|
import { Button, Form, FormControl, FormField, TextArea } from 'ui'
|
|
import { Admonition } from 'ui-patterns/Admonition'
|
|
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
|
|
|
|
import {
|
|
CSAT_COMMENT_MAX_LENGTH,
|
|
CsatSurveyFormSchema,
|
|
csatSurveyParamsSchema,
|
|
type CsatSurveyFormValues,
|
|
} from './CsatSurvey.schema'
|
|
import { InterstitialLayout, SupabaseLogo } from '@/components/layouts/InterstitialLayout'
|
|
import { useCsatSurveyMutation } from '@/data/support/csat-survey-mutation'
|
|
|
|
const PAGE_TITLE = 'Customer Satisfaction Survey'
|
|
|
|
const withLayout = (children: ReactNode) => (
|
|
<InterstitialLayout logo={<SupabaseLogo />} title={PAGE_TITLE}>
|
|
<div className="px-6 pb-6">{children}</div>
|
|
</InterstitialLayout>
|
|
)
|
|
|
|
export const CsatSurvey = () => {
|
|
const { conversation_id, helpful } = useParams()
|
|
const paramsParsingResult = csatSurveyParamsSchema.safeParse({ conversation_id, helpful })
|
|
|
|
if (!paramsParsingResult.success) {
|
|
return withLayout(
|
|
<Admonition type="destructive" title="Error" description="Invalid or mismatched ticket" />
|
|
)
|
|
}
|
|
|
|
return (
|
|
<CsatSurveyForm
|
|
conversationId={paramsParsingResult.data.conversation_id}
|
|
initialSatisfied={paramsParsingResult.data.helpful}
|
|
/>
|
|
)
|
|
}
|
|
|
|
const CsatSurveyForm = ({
|
|
conversationId,
|
|
initialSatisfied,
|
|
}: {
|
|
conversationId: string
|
|
initialSatisfied: boolean
|
|
}) => {
|
|
const {
|
|
mutate: submitSurvey,
|
|
isPending,
|
|
isSuccess,
|
|
isError,
|
|
error,
|
|
} = useCsatSurveyMutation({ onError: () => {} })
|
|
|
|
const form = useForm<CsatSurveyFormValues>({
|
|
resolver: zodResolver(CsatSurveyFormSchema),
|
|
defaultValues: { satisfied: initialSatisfied, comment: '' },
|
|
})
|
|
const satisfied = useWatch({ control: form.control, name: 'satisfied' })
|
|
|
|
const onSubmit = (values: CsatSurveyFormValues) => {
|
|
submitSurvey({
|
|
conversationId,
|
|
satisfied: values.satisfied,
|
|
comment: values.comment || undefined,
|
|
})
|
|
}
|
|
|
|
if (isSuccess) {
|
|
return withLayout(
|
|
<Admonition
|
|
type="success"
|
|
title="Success"
|
|
description="Survey response recorded. You can now close this window."
|
|
/>
|
|
)
|
|
}
|
|
|
|
const isAlreadySubmitted = isError && error.code === 409
|
|
if (isAlreadySubmitted) {
|
|
return withLayout(
|
|
<Admonition
|
|
type="destructive"
|
|
title="Error"
|
|
description="This survey has already been submitted"
|
|
/>
|
|
)
|
|
}
|
|
|
|
const isTicketMismatch = isError && error.code === 404
|
|
if (isTicketMismatch) {
|
|
return withLayout(
|
|
<Admonition type="destructive" title="Error" description="Invalid or mismatched ticket" />
|
|
)
|
|
}
|
|
|
|
return withLayout(
|
|
<Form {...form}>
|
|
<form onSubmit={form.handleSubmit(onSubmit)} className="flex flex-col gap-4">
|
|
<FormField
|
|
control={form.control}
|
|
name="satisfied"
|
|
render={({ field }) => (
|
|
<FormItemLayout
|
|
layout="vertical"
|
|
label="Were you satisfied with your Supabase Support Experience?"
|
|
>
|
|
<FormControl>
|
|
<div
|
|
className="flex gap-2"
|
|
role="group"
|
|
aria-label="Were you satisfied with your Supabase Support Experience?"
|
|
>
|
|
<Button
|
|
type="button"
|
|
variant={satisfied === true ? 'primary' : 'default'}
|
|
aria-pressed={satisfied === true}
|
|
onClick={() => field.onChange(true)}
|
|
block
|
|
>
|
|
Yes
|
|
</Button>
|
|
<Button
|
|
type="button"
|
|
variant={satisfied === false ? 'primary' : 'default'}
|
|
aria-pressed={satisfied === false}
|
|
onClick={() => field.onChange(false)}
|
|
block
|
|
>
|
|
No
|
|
</Button>
|
|
</div>
|
|
</FormControl>
|
|
</FormItemLayout>
|
|
)}
|
|
/>
|
|
<FormField
|
|
control={form.control}
|
|
name="comment"
|
|
render={({ field }) => (
|
|
<FormItemLayout layout="vertical" label="Would you like to add a comment?">
|
|
<FormControl>
|
|
<TextArea {...field} rows={4} maxLength={CSAT_COMMENT_MAX_LENGTH} />
|
|
</FormControl>
|
|
</FormItemLayout>
|
|
)}
|
|
/>
|
|
{isError && <Admonition type="destructive" title="Error" description={error.message} />}
|
|
<Button type="submit" variant="primary" loading={isPending} block>
|
|
Submit
|
|
</Button>
|
|
</form>
|
|
</Form>
|
|
)
|
|
}
|