The Inquiries badge counts what nobody has opened by niteeshkanna-sh · Pull Request #71 · niteeshkanna-sh/create-react-app · GitHub
Skip to content

The Inquiries badge counts what nobody has opened - #71

Merged
niteeshkanna-sh merged 2 commits into
mainfrom
claude/stoic-rubin-fnglq7
Sep 22, 2026
Merged

niteeshkanna-sh merged 2 commits into
mainfrom
claude/stoic-rubin-fnglq7

Conversation

@niteeshkanna-sh

Copy link
Copy Markdown
Owner

The badge counted everything unresolved — New, Contacted and Pending — so it lit up the moment an enquiry arrived and stayed lit for days while somebody waited on a callback. In the screenshot that prompted this, ENQ-2026-0004 had already been contacted and the sidebar still said 1. A number that is always on is a number nobody reads, and the morning it says 3 looks like every other morning.

Read and resolved are different questions. Status says where an enquiry got to; viewed_at says whether anybody has seen it. The badge now asks the second, and opening an enquiry is what answers it — the count clears the moment the detail opens, without waiting for a status change.

What changed

  • enquiries.viewed_at and viewed_by, with the badge counting viewed_at IS NULL over the whole table — the list on screen is filtered, the badge is not.
  • The stamp is written once. WHERE ... AND viewed_at IS NULL means opening the same enquiry again does not move it, so when was this first picked up stays answerable. It records who looked.
  • The get endpoint returns the new count alongside the enquiry, so the badge is right the moment the modal appears rather than after the list behind it refreshes.
  • In the list, an unopened enquiry gets a gold edge and an "Unread" pill — the ones still needing a first look are findable, not only countable. Deliberately quiet: it marks new to you, not urgent.
  • Nothing is marked until the column exists. Without the migration every viewed_at reads as null, which is indistinguishable from never opened, and the whole list would have claimed to be unread — so the list response says whether the database tracks reading at all.
  • The migration backfills everything already handled as seen. Without that the badge would light up with the entire history the first time the panel loads after the update, which is exactly the noise this removes.
  • The three helpers moved into src/enquiry.php rather than living in the endpoint, so they can be tested without a session or a router, and so the alerts endpoint can reuse the count later.

One note on the guard: get is a GET, so it uses the read guard, not the write one — passing the write guard would have demanded a POST and broken every enquiry detail. Marking it read is a side effect of reading it, the way opening a message marks it read, and the worst a forged request could do is clear a badge for somebody already signed in.

Tested

  • 18 browser checks: the count on load, the "Unread" marker in the list, opening one clearing both the badge and the marker, a second open stamping nothing new, a newly arrived enquiry lighting it again, a Contacted enquiry staying unmarked because it was read, and a panel one migration behind marking nothing and still rendering.
  • 17 server checks: the count ignoring status, the stamp written once and only when null, the reader and enquiry recorded, and the migration guard writing and reading nothing when the column is absent.
  • The existing suites: 52 admin, 19 enquiry, 29 ERP, 28 fleet, 46 money, plus the cancellation and commission checks. All passing, no duplicate ids, no overflow at 390px.

One thing on your side

The database password is still in this repository's git history and has not been rotated. Change it in hPanel → Databases, then put the new one in nitesha-config/config.php above the document root. Nothing in the panel will work between the two steps, so do them together.

🤖 Generated with Claude Code

https://claude.ai/code/session_0128YzbhrfGdegUSc9RrARRf


Generated by Claude Code

It counted everything unresolved -- New, Contacted and Pending -- so it lit up
the moment an enquiry arrived and stayed lit for days while somebody waited on
a callback. A number that is always on is a number nobody reads, and the
morning it says 3 looks like every other morning.

Read and resolved are different questions. Status says where an enquiry got
to; viewed_at says whether anybody has seen it. The badge now asks the second,
and opening an enquiry is what answers it -- the count clears itself the
moment the detail opens, without waiting for a status change.

The stamp is written once. Opening the same enquiry again does not move it,
so "when was this first picked up" stays answerable, and it records who
looked.

In the list, an unopened enquiry gets a gold edge and an "Unread" pill, so the
ones still needing a first look are findable and not only countable. Nothing
is marked until the column exists: without the migration every viewed_at reads
as null, which is indistinguishable from never opened, and the whole list
would have claimed to be unread.

The migration backfills everything already dealt with as seen. Without it the
badge would light up with the entire history the first time the panel loads
after the update -- exactly the noise this removes.

The three helpers live in src/enquiry.php rather than in the endpoint, so they
can be tested without a session or a router, and so the alerts endpoint can
use the same count later.

Tested: 18 browser checks and 17 server checks, plus the existing suites.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0128YzbhrfGdegUSc9RrARRf
@niteeshkanna-sh
niteeshkanna-sh merged commit 3034de3 into main Sep 22, 2026
1 check failed
@niteeshkanna-sh
niteeshkanna-sh deleted the claude/stoic-rubin-fnglq7 branch September 22, 2026 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants