Files
dyolink/frontend
Amin Mousavi dc23c3dd1c fix(voice): prime the lab-drafts ref before the save that reads it
"برای دندون ۱۲ و ۱۴ یه فول متال کران" previewed correctly, then Apply failed
with TREATMENT_TOOTH_NOT_ON_DETAIL. The form still showed both teeth and both
crowns — that is React state. The database got a detail with no teeth.

applyVoiceResult called setLabCaseDrafts but never wrote
labCaseDraftsRef.current, which is only refreshed in the render body.
persistDraft runs in the same tick and starts by pruning each lab-dependent
detail down to the teeth its jobs cover, reading that stale ref. It found no
draft for the brand-new detail, so jobs were empty, so the detail was saved
with teeth: []. persistLabCases then posted rows for 12 and 14 against it,
and the server — which re-reads the detail's teeth from the database, because
the lab-case endpoint carries no teeth field — correctly refused.

detailsRef was already written by hand two lines above for exactly this
reason (3911477). This is the other half of the same mistake.

Two sibling handlers had the same gap and are fixed with it: adopting an
orphan lab case, and creating a new lab draft. Both call setLabCaseDrafts and
then persistDraft in the same tick. handleLabCasesChange was the only site
that already primed the ref, and it is the pattern the others now follow.

Adds a comment at the ref declaration, because the coupling between this ref
and persistDraft's prune is invisible at the call sites and has now cost two
bugs.

No automated test: this is state-and-ref ordering inside a React component,
and the frontend's Vitest scope is pure helpers only — no React, no DOM.
Mirroring the server's tooth rule on the client to make it testable would
duplicate a rule across layers, which decision 38 rules out.

Gates: tsc --noEmit clean, 37 Vitest tests, next build clean, ESLint warnings
unchanged at 10 (all pre-existing, count verified against HEAD).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-10 17:18:02 +08:00
..

Dyolink — Frontend (Next.js)

Prerequisites

  • Node.js 20+ and npm

First-time setup

  1. Clone the monorepo and go to the frontend app:

    git clone <repository-url> dyolink
    cd dyolink/frontend
    
  2. Install dependencies

    npm install
    
  3. Environment

    Create .env.local in this folder (not committed to git) with the public URLs your browser will use:

    NEXT_PUBLIC_APP_URL=http://localhost:3001
    NEXT_PUBLIC_API_URL=http://localhost:3000/api
    NEXT_PUBLIC_APP_NAME=Dyolink
    
    • Adjust NEXT_PUBLIC_API_URL if the Nest API runs on another host/port.
    • These values are baked in at build time for production images; for local dev, restart npm run dev after changing them.

Run (development)

npm run dev

Open http://localhost:3001 (dev server uses port 3001 so it does not clash with the API on 3000).

Ensure the backend is running and NEXT_PUBLIC_API_URL matches its base URL (including /api if your API is mounted there).

After pulling latest main

git pull
npm install

Useful commands

Command Purpose
npm run dev Development server (port 3001)
npm run build Production build
npm run start Serve production build (port 3000 — used inside Docker)
npm run lint ESLint

Docker

Image build and build-args (NEXT_PUBLIC_*) are documented in the repository root README.md.