frontend
Technical notes on web development, DevOps, and AI integration.
173 articles
- 16:24backend
An Undocumented 404 Is a Contract Bug
Six lines of OpenAPI YAML and a regeneration changed what the frontend compiler knows. Error responses left undocumented are contract bugs.
TL;DR: What looked like a trivial six-line OpenAPI cleanup turned out to be critical for type safety. Since openapi-typescript only generates types for explicitly documented responses, an undocumented 404 forced the frontend to guess or use any. Documenting the error locks the contract so TypeScript catches missing handling early, saving hours of debugging later.
#openapi#api#typescript - 12:25frontend
Labels That Can Lie: When Status Vocabulary Lives in Two Places
A duplicated STATUS_MAP on the public page now reads labels from one lib: exhaustive types, an honest fallback for unknown values, countKey enforced.
TL;DR: The public status page broke because it kept its own four item map while the backend and shared lib handle six statuses. The fix makes STATUS_LABEL in layanan-flow the single source of truth, with TypeScript enforcing completeness and a runtime fallback to neutral raw text. CountKey is now required, so future status additions propagate automatically without silent display bugs.
#react#typescript#ui - 12:25frontend
Per-Status Counters in Admin Stats: Numbers From the Contract
Per-status snapshot counters joined AdminLayananStats additively; legacy fields kept, UI derives numbers from stats, no more meta.total tricks.
TL;DR: The dashboard showed dashes because the stats API only counted two of six statuses, leaving legacy fields at zero. The fix kept the old fields and added six current snapshot counters, with regenerated types now requiring a count for every tab and card. Counts respect user scope, and the queue badge now reads the submission counter directly with lightweight polling.
#go#api#openapi - 11:23frontend
An Honest Ticket Status Stepper: Learning from the History Array
The ticket stepper stops guessing from one status string: stage times come from the transition history, first row per status.
TL;DR: The stepper used to guess progress from one status string, now it maps real timestamps from the history array and falls back to created and updated times. Four display stages replace six cluttered steps, grouping terminal statuses while safely handling invalid dates and listing history in order. Transformations run during render, and const literal types prevent invalid pillar submissions.
#react#typescript#ux - 11:22frontend
Mirroring the Status Transition Map in the Frontend
A tiny frontend mirror of the backend transition map: one union type, one map, and impossible options disabled before the click.
TL;DR: I refactored the tangled status logic into a clean switch that maps six statuses to four display stages. A lean NEXT_STATUSES map only decides which options light up, leaving the backend as the true authority that returns 409s. I added type guards, fallback labels for unknown statuses, and real disabling beyond just aria-disabled.
#frontend#typescript#state-machine - 08:58backend
One Value, Two Meanings: Global Scope Is a Choice, Not Null
Null in a scope filter doing two jobs at once: not chosen yet and choose all. A design note on why an ALL sentinel in the enum is more honest.
TL;DR: The KotaPortal dropdown used null to mean both nothing selected and all units, which created confusing backend logic. Instead an explicit ALL value was added to the BidangScope enum so null only means untouched. This keeps the API contract clear, makes validation reliable, and stops teammates guessing what empty means.
#typescript#openapi#api - 10:49frontend
Moving /wisata: a 308 Redirect and a Menu That Survives
Renaming a public route is three moves at once: relocate the route tree, install a permanent 308, and migrate menu rows without stomping admin edits.
TL;DR: Renaming the public /wisata route to /pariwisata took more than a file move. The team added permanent 308 redirects for the old path and wildcard subpaths to preserve bookmarks and POST requests. A guarded MySQL migration renamed only untouched menu rows, shifted ordering, and left CMS-edited content intact.
#nextjs#redirect#mysql - 09:29frontend
The Tri-State Trap in React Category Pickers
A dropdown that is right for create is wrong for edit. A tri-state moduleScope makes the fetch wait for the entity to load.
TL;DR: Editing showed PARIWISATA categories instead of KEPEMUDAAN because the picker fetched before the module loaded and fell back to the default. The fix makes moduleScope tri-state and waits until it resolves before calling listAdminCategories via useEffect. The team also synced the OpenAPI spec, generated types, and frontend module list to prevent enum drift.
#react#typescript#openapi - 09:04frontend
Hiding Sidebar Links Is UX, Not Authorization
Hiding a sidebar item is a UX decision, not an authorization boundary. Layout checks go stale; the API must fail closed.
TL;DR: Hiding sidebar links isn't security since Next.js layouts don't recheck auth on navigation and typed URLs can bypass the UI. The fix belongs at the API layer, where the backend validates scopes and returns an empty list instead of a 403 to avoid leaking modules. Frontend caching keeps it efficient while tests ensure restricted URLs just show empty tables.
#nextjs#react#go