Back to work

03 — Case study

Personal project

State machines for multi-step forms

Explicit step models for sell, preorder, and limit-sharing flows instead of tangled conditionals.

Role

Frontend Lead

Context

Caroline.id marketplace, Cartalog consumer app

Period

March 2022 – present

Stack

TypeScript, React, Next.js

01 — Problem

Long forms spanned OTP, modals, and route changes—nested conditionals made it hard to know which step was active or what happened on back navigation.

The sell-car wizard runs five steps from car data through inspection booking, with different mobile drawers and a desktop stepper showing the same sequence. Preorder uses modal steps tied to submission and pathname changes. On Cartalog, the give-to-get limit dialog must move through limit explanation, share form, and success without leaving orphan state when the overlay closes.

02 — Approach

  1. Numbered wizard with one source of truth

    Sell flow keeps activeStep in a dedicated hook along with frozen domicile fields so later inspection steps still send the address captured at step one. Views only render the panel that matches activeStep.

  2. Typed steps for overlay flows

    Give-to-get uses a small union of step names and a single transition helper with short timeouts for enter/exit animation, resetting step and form key on close so reopening always starts at limit.

  3. Rejected scattered boolean flags

    Per-field “isStep2” flags across components duplicated guards and broke when mobile and desktop added different entry points. Central step state fixed that without adopting a heavyweight state-machine library.

GiveToGetDialog.tsx
type Step = 'limit' | 'share' | 'success';

function useStepFlow() {
const [step, setStep] = useState<Step>('limit');

const goStep = (next: Step) => {
  setStep(next);
};

const reset = () => {
  setStep('limit');
};

return { step, goStep, reset };
}

// Render: step === 'limit' ? <LimitStep /> : step === 'share' ? <ShareStep /> : <SuccessStep />
Fig. 1 — Typed steps and explicit transitions. Illustrative excerpt, not production code.

03 — Where AI helped

AI suggested test cases for step transitions and OTP edge cases in preorder; I kept production step order and which fields freeze across steps.

04 — Result

Multi-step bugs shrank to “wrong transition” fixes in one hook or dialog instead of hunting conditionals across views. Qualitative impact is clear; formal defect-rate numbers can follow when available.

Next project

04

Core Web Vitals and SEO

LCP tuning on the homepage hero, listing stability, and structured metadata on vehicle detail pages.

LCPCLSSEO