# One-time notices (remembered per account)

A notice is a screen that is shown once, such as the welcome dialog "Willkommen im neuen kulibri". Before 26 Oct 2026 the new UI
remembered only in the browser that it had been shown, so the same person saw it again on another browser or device. Now the
**account** remembers which notice it has seen and in which version of its text. Decision of the product owner, 26 Oct 2026; the
mechanism is generic, because more notices will follow.

## What is where

| What | Where |
|---|---|
| The seen state | table `user_notices` (`user_id`, `notice`, `version`, `seen_at`; one row per user and notice), model `App\Models\UserNotice` |
| The allowed notices | `App\Services\Notices::KEYS` (`whats-new`; `rollout-welcome` and `rollout-classic-poll`, the texts 1 and 2 of the rollout, `docs/ui-rollout.md`); the client cannot create keys of its own |
| Saving | `PUT /api/user/notices` `{ notice, version }`: login needed, the caller's own account only, unknown key or a missing or long version: 422. The key is in the body because the hashids middleware decodes every route parameter as an id |
| Reading | `GET /api/user` returns `notices`: `{ notice: version }` (`{}` for none), so the new UI needs no extra request |
| The new UI | `utils/notices.ts` (the decision), `composables/useNotice.ts` (`useNotice(notice, version, legacyKey?)` → `{ open, start }`), `utils/whatsNew.ts` (the constants of the first notice) |

## The rule (`noticeDecision`)

The screen decides who gets a notice and when it opens (for example "on the dashboard"); the mechanism only decides whether it was seen:

| The account has this version | This browser has it | Result |
|---|---|---|
| yes | any | **hidden** |
| no | yes (seen before the account kept it, or the save failed) | **sync**: no dialog, tell the account |
| no | no | **show**: open it, mark it seen, tell the account |

- The browser copy is `localStorage['kulibri.notice.<notice>']`. It stops the dialog from flashing again while the account is saved, covers a failed save (the account gets it with the next visit), and for `whats-new` the first version's key `kulibri.whatsNewSeen` still counts, so nobody who saw it before is shown it again.
- A server that does not send `notices` behaves as before: this browser alone decides, and nothing is sent.
- It is marked as seen the moment it opens, so a reload does not show it again. A failed request is harmless.

## Adding a notice

1. Add the key to `Notices::KEYS` (and a constant next to it).
2. In the new UI: `const { open, start } = useNotice('my-notice', MY_VERSION)` in the view that shows it, call `start()` when it arrives, open the dialog when `open` is true.
3. Tests like `whatsNew.spec.ts` and `homeWelcome.spec.ts`; a row in `TESTING-BACKLOG.md`.
4. Customer-facing text: add it to `docs/whats-new.md` or the privacy notice where it applies.

## Showing a notice again

- To everyone: raise the version in the client (`WHATS_NEW_VERSION` for the welcome dialog). Accounts keep the old version and see it once more.
- To one person (testing): `DELETE FROM user_notices WHERE user_id = ? AND notice = 'whats-new'`, and clear the browser key.

## Not built

- Who gets a notice (for example Beta users only), start and end dates, and broadcast messages written by an admin: these stay in each screen. A table of admin-written notices could use the same "seen" state later.
- `users.promotion_shown` (the classic promotion hint, with its own open endpoint and a reset command) is an older one-off of the same kind; moving it onto this mechanism is a separate decision.
- The data is functional (which dialogs a person has dismissed). Name it in the privacy notice if the product owner wants it listed.

Deploy: the migration `create_user_notices_table` must be run by hand (`php artisan migrate`); the deploy does not run it.
