# Comments

**Status:** in production
**Lives at:** nav 💬 bell · `app/actions/comments.ts` · `components/comments-bell.tsx` · table `public.comments`

## Summary
A simple org-wide comment board reachable from the top nav. Anyone in
the org can drop a note ("@Adi please rename project X"), anyone can
mark it resolved, authors can delete their own.

## Why
2026-05-22 — "I want to add a comments so I can say something like
'@Adi please update the prompt victoria project to PlusROI : Prompt
Victoria in clockify'. … Just a comment icon in the top menu bar and I
can @ a user to leave a comment for him. He can see it and resolve it.
It doesn't need to be per row."

## Behavior
- 💬 icon in the right side of the top nav (next to View-as / Sign out).
- Red badge with the count of currently unresolved comments.
- Click the icon → dropdown panel:
  - **Open / Resolved tabs** at the top.
  - Comments listed newest first; each shows author, time-ago, body,
    and per-comment action buttons.
  - **Resolve** button on open comments (anyone in org can resolve).
  - **Reopen** button on resolved comments (anyone in org).
  - **Delete** button on comments authored by the current user.
  - **Post comment** form at the bottom with a textarea + Post button.
- `@username` patterns in the body are highlighted (yellow background)
  but don't route notifications yet.
- Up to 50 most recent comments are shown in the bell (capacity bump
  if/when the board fills).

## Constraints & edge cases
- RLS: org members can read; authors can insert (with `author_id =
  auth.uid()`); anyone in org can update (used for resolve / reopen);
  authors and super admins can delete.
- The layout fetches comments + author/resolver names on every nav
  render (50 rows + a profile lookup). Cheap today; could become a
  separate RPC if it gets slow.
- Post / Resolve / Delete all `revalidatePath('/', 'layout')` so the
  layout re-fetches and the badge count updates.

## Permissions
- Read: any org member.
- Post: any org member (their own author_id).
- Resolve / Reopen: any org member (it's a shared board).
- Delete: author or super admin.

## Open considerations
- No threading / replies yet — a single linear board. Add a
  `parent_id` if needed later.
- No notifications. `@Adi` is currently just text; will route
  to email / Slack later.
- No edit-after-post. Delete + repost if needed.
- The 50-row cap is global. Could become per-month later.

## Tests
- 🟡 COM-101 Posting a comment shows it in the bell for every org member.
- 🟡 COM-102 Resolve flips `resolved_at` and removes the unresolved badge count.
- 🟡 COM-103 Author / super admin can delete; others get RLS denied.

## Changelog
- **2026-05-22** — Initial. Replaces the per-entry comments that lived
  briefly on 2026-05-22 (see decisions.md #020 / #022).
