mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +00:00
I added the "Do you know how to code?" question (Yes / No, optional) to the onboarding survey on the new organization form and in the follow-up dialog. The answer is sent as `can_code` in the same survey request as the other answers. I removed an earlier version of this question before the survey shipped because the platform didn't store it; the platform now accepts `can_code`. **Changed:** - **New question, always visible**: it shows on both surfaces without waiting on another answer, so it can be answered on its own. Only the `org_form` arm of the experiment shows the survey. - **Follow-up dialog shows every question at once**: "What are you building?" used to appear only after "Who is this org for?" was answered. "How many people?" still appears only for the Company org type. - **Follow-up card above other banners**: I raised its priority in the banner stack so it sits in front of the project-page cards for its five-minute window. - **Telemetry**: I added a `hasCanCode` boolean to `onboarding_survey_submit_button_clicked` and `onboarding_survey_submit_failed`. **Note:** Merge only after the platform change that accepts `can_code` is in production: before that, the API drops the key and still returns 204, so answers are lost with no error. The change is live once `can_code` is listed under `OnboardingSurveyBody` in the production platform OpenAPI spec. I widened `OnboardingSurveyBody` locally because `packages/api-types` can only be regenerated once the production spec has the field. ## To test Setup: sign in and set the `onboardingSurveyPlacement` flag to `org_form` with the dev toolbar. Tested on the PR preview: - [x] Open `/new`: expect "Do you know how to code?" below "What are you building?" with Yes then No, before any other question is answered. Answer both and create the org: expect one `POST /platform/organizations/onboarding-survey` whose body has `building` and `can_code`. Observed: both questions on the untouched form, options Yes then No; one request, 204, body has `"can_code":"yes"`. - [x] Create an org with only "Do you know how to code?" answered: expect one request whose body has `can_code` and no `building` key. Observed: one request, 204, `"can_code":"no"`, no `building` key, and no follow-up card on the new org's page. - [x] Create an org with the org type changed to Company, a size picked and "Do you know how to code?" answered, leaving "What are you building?" blank: expect one request with `kind`, `size` and `can_code`, and no follow-up card on the new org's page. Observed: one request, 204, `"kind":"COMPANY","size":"50","can_code":"yes"`; no follow-up card. - [x] Create an org with "What are you building?" answered and the new question left blank: expect the request body to have no `can_code` key, and the org to be created. Observed: one request, 204, no `can_code` key. - [x] Create an org without touching the survey, then open the new org's page: expect the "Help improve Supabase" card. Click Answer: expect all three questions in the dialog right away. Answer all three questions and send: expect one request with `kind`, `building` and `can_code`. Observed: no survey request at creation; the card shows on the org page; the dialog opens with all three questions blank; one request, 204, body has `"can_code":"yes"`. - [x] Set the flag to `control` and open `/new`: expect no survey questions. Observed: none of the survey questions render. - [x] Added check: `onboarding_survey_submit_button_clicked` carries `hasCanCode`. Observed: `true` when answered on both surfaces, `false` when left blank. ## Linear - fixes GROWTH-1487
66 lines
1.7 KiB
TypeScript
66 lines
1.7 KiB
TypeScript
import { useMutation } from '@tanstack/react-query'
|
|
import type { components } from 'api-types'
|
|
|
|
import { handleError, post } from '@/data/fetchers'
|
|
import type { StudioError } from '@/lib/errors/studio-errors'
|
|
import type { UseCustomMutationOptions } from '@/types'
|
|
|
|
// `can_code` is missing from api-types until they are regenerated from the production spec
|
|
export type OnboardingSurveyBody = components['schemas']['OnboardingSurveyBody'] & {
|
|
can_code?: string
|
|
}
|
|
|
|
export type OnboardingSurveyVariables = {
|
|
slug: string
|
|
kind?: string
|
|
size?: string
|
|
building?: string
|
|
can_code?: string
|
|
}
|
|
|
|
const trim = (v?: string) => v?.trim() || undefined
|
|
|
|
function buildOnboardingSurveyPayload({
|
|
slug,
|
|
kind,
|
|
size,
|
|
building,
|
|
can_code,
|
|
}: OnboardingSurveyVariables): OnboardingSurveyBody {
|
|
return {
|
|
slug,
|
|
kind: trim(kind),
|
|
size: trim(size),
|
|
building: trim(building),
|
|
can_code: trim(can_code),
|
|
}
|
|
}
|
|
|
|
export async function submitOnboardingSurvey(variables: OnboardingSurveyVariables) {
|
|
const payload = buildOnboardingSurveyPayload(variables)
|
|
|
|
if (!payload.slug) {
|
|
throw new Error('Organization slug is required')
|
|
}
|
|
|
|
const { error } = await post('/platform/organizations/onboarding-survey', {
|
|
body: payload,
|
|
})
|
|
|
|
if (error) handleError(error)
|
|
}
|
|
|
|
type SubmitOnboardingSurveyData = Awaited<ReturnType<typeof submitOnboardingSurvey>>
|
|
|
|
export const useOnboardingSurveyMutation = (
|
|
options: Omit<
|
|
UseCustomMutationOptions<SubmitOnboardingSurveyData, StudioError, OnboardingSurveyVariables>,
|
|
'mutationFn'
|
|
> = {}
|
|
) => {
|
|
return useMutation<SubmitOnboardingSurveyData, StudioError, OnboardingSurveyVariables>({
|
|
mutationFn: submitOnboardingSurvey,
|
|
...options,
|
|
})
|
|
}
|