[PR #133·134] Admin Web Follow-Up 1: Auto-Refreshing Customer Detail and Facility/Module Creation
While testing Kakao login on an Android phone, three gaps in the admin web showed up: it had no visual styling, it had no screen for creating facilities and modules, and its screens did not refresh by themselves. I approved a plan to fix these in separate pieces. This post covers the two functional ones (PR #133 and #134). The styling is covered in the next post.
At a glance
| PR | Where | Key change | Checked |
|---|---|---|---|
| #133 | Customer detail screen | Re-fetch every 5 s only while not set up; refresh related lists when the status changes |
145 tests passed |
| #134 | Facility/module creation | Same-name facility rejected with 409; add buttons and dialogs on the module overview | 163 tests passed |
PR #133: Auto-refresh on the customer detail screen
- What happened: A customer detail screen left open in the admin web did not notice that the customer had signed up in the app and their account had moved from
not set uptoactive. So thesuspendbutton never appeared. - What was done: Claude made two changes.
- While the account status is
not set up, the screen re-fetches the data every 5 seconds. - When it notices the status changed away from
not set up, it also refreshes that customer’s code list, invitation list, and summary.
- While the account status is
- Chosen approach: The data-fetching library (TanStack Query) takes a function for
refetchInterval, which returns 5000 (milliseconds) only while the status isnot set up. The official documentation confirms that a function is allowed and that polling pauses by default when the tab is in the background. - Dropped options: Having the server push updates (SSE or WebSockets) would touch the server, authentication, and deployment, so it was too big. Always re-fetching would be wasteful for screens that are already
active. - Deliberately left out: There is no time limit after which polling stops. A customer screen that stays
not set upand is left open will send 12 requests a minute while the tab is visible. A code search confirmed that admin reads have no server-side rate limit. A limit in front of the production environment could not be checked.
PR #134: Duplicate-name check and the facility/module creation screen
- What happened: The admin web had no screen for creating facilities and modules. During Android testing, the facility dropdown on the customer registration screen was empty, and entries had to be put into the test database by hand. The server already had the create endpoints (
POST /admin/farms,POST /admin/farms/:id/modules). - What I decided: Creating a facility with an existing name (compared after trimming spaces and ignoring case) is rejected by the server with 409
farm_name_taken. - What was done: Claude built the server check and the screens.
- Server: the duplicate-name check, plus the new code in the shared error-code list.
- Admin web: “Add facility” and “Add module” buttons and dialogs on top of the module overview screen. With no facility, “Add module” is disabled and a hint is shown. The customer registration screen shows a link to the module overview when there is no facility, or when there is no module at step 2.
- Chosen approach and dropped options:
- Duplicates are blocked only by a comparison in the service code (
lower(name) = lower(:name)). A unique constraint in the database (a rule that refuses duplicate values outright) is hard to undo and could clash with existing data, so it was left out. As a result, two admins creating the same name at the same moment could both succeed. With so few admins, this was accepted. - The screens sit on the existing module overview rather than under a new menu, to avoid changing the screen structure.
- Length is counted in code points (one character each), the same way as on the server.
- Facility and module names allow up to 50 characters, so they got their own error message instead of the existing one, which states the customer-name rule (1–30 characters).
- Duplicates are blocked only by a comparison in the service code (
Checking
- Tests came first. For #133, 5 tests failed before the implementation. For #134, one server test and 18 screen tests failed before the implementation, and passed afterwards.
- Results: The admin web tests passed (145 for #133, 163 for #134), and so did the type check. #134 also adds an e2e test (a test that walks through the real server and a browser from start to finish): create a facility, get the same name rejected, create a module, and see that module at step 2 of customer registration.
- Not checked: On my Windows computer, I could not run the e2e tests or the full
npm run verify. The e2e result was to be taken from GitHub CI.
What I learned
- A screen that waits for a state change should check only while it waits. Stopping once the state settles keeps the server load small, and refreshing the related lists at the moment of change keeps the screen consistent.
- Start hard-to-undo constraints with a check in server code. A database constraint is hard to remove once added, so it can wait until the usage is clear.
- Run
npm installfirst in a fresh working folder. Runningverifywithout it failed with a missing-package error.