diff --git a/src/components/onboarding/baseline-fields.tsx b/src/components/onboarding/baseline-fields.tsx new file mode 100644 index 000000000..59ef5930a --- /dev/null +++ b/src/components/onboarding/baseline-fields.tsx @@ -0,0 +1,143 @@ +"use client"; + +import { Input } from "@/components/ui/input"; +import { DateField } from "@/components/ui/date-field"; +import { FieldGroup } from "@/components/ui/field-group"; +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from "@/components/ui/select"; +import { HeightFieldControl } from "@/components/profile/height-field-control"; +import { useTranslations } from "@/lib/i18n/context"; +import type { + HeightDraft, + HeightUnitAdapter, +} from "@/lib/profile/height-unit-display"; + +/** + * The four profile inputs of the onboarding baseline step. + * + * Split out of `baseline-form.tsx` so the markup can be rendered on its + * own against a server answer. The step's whole defect lived between + * the response and these inputs — the server named a field it refused + * and nothing on screen changed — so the seam a test needs is exactly + * here: field values in, markup out. + */ + +export interface BaselineFieldValues { + displayName: string; + height: HeightDraft; + dateOfBirth: string; + gender: string; +} + +const IDS = { + displayName: "ob-baseline-display-name", + heightCm: "ob-baseline-height", + dateOfBirth: "ob-baseline-dob", + gender: "ob-baseline-gender", +} as const; + +export function BaselineFields({ + value, + onChange, + heightAdapter, +}: { + value: BaselineFieldValues; + onChange: ( + key: K, + next: BaselineFieldValues[K], + ) => void; + heightAdapter: HeightUnitAdapter; +}) { + const { t } = useTranslations(); + + return ( +
+ {t("onboarding.baseline.title")} + + + onChange("displayName", e.target.value)} + autoComplete="nickname" + maxLength={50} + placeholder={t("onboarding.baseline.displayNamePlaceholder")} + /> + + +
+ + onChange("height", next)} + autoComplete="off" + /> + + + + +
+ + + onChange("dateOfBirth", next)} + max={new Date().toISOString().slice(0, 10)} + autoComplete="bday" + /> + +
+ ); +} diff --git a/src/components/onboarding/baseline-form.tsx b/src/components/onboarding/baseline-form.tsx index 7576be392..8d81811dc 100644 --- a/src/components/onboarding/baseline-form.tsx +++ b/src/components/onboarding/baseline-form.tsx @@ -8,17 +8,7 @@ import { toast } from "sonner"; import { Loader2 } from "lucide-react"; import { Button } from "@/components/ui/button"; -import { DateField } from "@/components/ui/date-field"; -import { FieldGroup } from "@/components/ui/field-group"; -import { Input } from "@/components/ui/input"; -import { - Select, - SelectContent, - SelectItem, - SelectTrigger, - SelectValue, -} from "@/components/ui/select"; -import { HeightFieldControl } from "@/components/profile/height-field-control"; +import { BaselineFields } from "@/components/onboarding/baseline-fields"; import { useUnitDisplay } from "@/hooks/use-unit-display"; import { EMPTY_HEIGHT_DRAFT, @@ -201,91 +191,11 @@ export function BaselineForm() {

-
- {t("onboarding.baseline.title")} - - - patch("displayName", e.target.value)} - autoComplete="nickname" - maxLength={50} - placeholder={t("onboarding.baseline.displayNamePlaceholder")} - /> - - -
- - patch("height", next)} - autoComplete="off" - /> - - - - -
- - - patch("dateOfBirth", value)} - max={new Date().toISOString().slice(0, 10)} - autoComplete="bday" - /> - -
+