Skip to content

Toast CRUD feedback in the top-right corner - #66

Merged
DeryChris merged 1 commit into
mainfrom
arena/69624470-ghs-etraining-hub
Dec 2, 2026
Merged

DeryChris merged 1 commit into
mainfrom
arena/69624470-ghs-etraining-hub

Conversation

@DeryChris

Copy link
Copy Markdown
Owner

Slide-in toasts for every create, update and delete that reports through a server action, colour-coded by what happened.

What was wrong

Every action already answers — { ok, message } or { error, done } — but it answers at the bottom of the form it came from. On a phone that is off-screen; on a long desktop form it is below the fold. The save worked and nothing appeared to.

What this does

  • src/components/ui/toast.tsx — a ToastProvider mounted once in the root layout, a useToast() hook and a useActionToast(state, { success }) bridge. Toasts enter from the right (x: 40 → 0), stack up to four, exit the same way, and are dismissible.
  • Timings: 5 s for success and info, 7 s for a warning, 9 s for a refusal — errors need reading. Hovering or focusing pauses the countdown; leaving restarts it.
  • Colour follows the kind of answer (success/info/warning/error) against the existing tokens, but is never the only signal: an icon and the words travel with it, and failures carry role="alert" for a screen reader.
  • prefers-reduced-motion is honoured by the app-wide MotionConfig already in place.
  • src/lib/action-feedback.ts — readFeedback(), a pure function with tests, decides what a state means. This matters because an untouched form is { ok: false, message: null }: the same shape as a refusal. Without it, every form would announce "not saved" on mount.
  • The provider's hook falls back to silence outside a provider, so components rendered in isolation (the existing user-row DOM test) still work and the inline message still carries the answer.

Wired

Settings (appearance, notifications, support contacts, banner save and clear) — Users (create, details, role, access, reset link, active, password) — Trainings (create/update, roster add and bulk, discussion, cover image) — Authoring (new draft, submit for review, review decision, publish, archive) — Complaints (respond, reset access) — Messages (send).

The inline FormFeedback stays everywhere it was. A toast is a second copy, not a replacement.

Deliberately left out

Server-action forms that carry no state at all (the geography and programme-area drawers, the sign-out and menu one-liners). They revalidate the page and show the result inline; wrapping each in a state just to raise a toast would be more machinery than the problem deserves. Say the word and they can be converted.

Gates

  • npx tsc --noEmit clean
  • npx eslint . clean
  • npx vitest run — 62 files / 385 tests (4 new for readFeedback, 5 DOM tests for the provider and hook: untouched form says nothing, success once with the server's sentence, refusal as alert, no repeat on re-render, silence outside a provider)
  • next build compiles

docs/ui-ux.md §"Feedback on every action" now describes the corner and why it exists alongside the inline message.

A save on a long form answers at the bottom of that form: off-screen on a
phone, below the fold on a desktop. The work happened and nothing appeared to.

Toasts now slide in from the top-right, say the server's own sentence, and
slide out after five seconds (seven for a warning, nine for a refusal). They
pause while the pointer or the keyboard is over them, carry an icon and the
words so colour is never the only signal, and raise an alert role when the
answer is a refusal. Reduced motion is honoured by the app-wide MotionConfig.

readFeedback() decides what a state means in a pure function: an untouched
form is { ok: false, message: null } — identical in shape to a refusal — and
must not announce that nothing was saved before anything was pressed.

Wired to every CRUD form that already reports through useActionState: settings
(appearance, notifications, support contacts, banner), users (create, details,
role, access, reset, active), trainings (create/update, roster, discussion,
cover), authoring (draft, review decision, publish, archive), complaints
(respond, reset access) and messages. The inline message stays; the toast is a
second copy, which is why the hook falls silent outside the provider.

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
@vercel

vercel Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
ghs-training-library Ready Ready Preview Dec 2, 2026 11:51am UTC

@DeryChris
DeryChris merged commit 23c5a1c into main Dec 2, 2026
5 checks passed

This branch was successfully deployed

1 active deployment
Preview — b10a7fc8 Deployed Dec 2, 2026 by vercel[bot]
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.

1 participant