Staff 0.2.0: Clearer form errors and failed actions in the activity log
Staff 0.2.0 is a quality release for the PhoenixKit staff directory: some saves that used to crash now show a normal form error, failed actions are written to the activity log, and the detail pages stay in sync more reliably.
Errors you can act on
Linking a person to a user who is already on staff raised a database error instead of showing a message. The person form now shows already linked to a person on staff under the field. A team name that clashes with another team in the same department now shows its error under the name field, where you typed it.
Messages from the module’s actions are now translated at the page, so the same failure reads the same way everywhere.
Failed actions in the activity log
Until now only successful actions reached the activity log. A failed save on the department, team and person forms, and a failed delete or other destructive action on the lists, now also writes an entry marking the failure, without personal data in it.
Detail pages and birthdays
The department, team and person pages start listening for changes before they load their data, so an edit made at that moment is no longer missed. The person page no longer crashes when it receives an unrelated message. The upcoming birthdays display no longer moves a 29 February birthday to the 28th in a leap year.
Upgrading
No migration. If your own code calls Staff.rename_placeholder_email/2, it now returns an error atom (:blank_email, :placeholder_already_claimed or :email_already_taken) instead of a message; turn it into text with PhoenixKitStaff.Errors.message/1.
Full release notes: Staff 0.2.0
0.2.0 · 30 April 2026
Quality sweep + re-validation pipeline (PRs #2 and #3) plus the post-merge follow-up: form-Save audit rows, Errors fallback warning, Helpers merge-precedence fix.
Added
PhoenixKitStaff.Errors— atom → translated-string dispatcher. Context functions now return{:error, atom}; LiveViews callErrors.message/1at the presentation boundary. Unknown-atom fallback emits aLogger.warningso drift is loud in dev/staging.PhoenixKitStaff.Web.Helpers—log_operation_error/3writes a failure-side activity row withdb_pending: trueand PII-safe reason metadata. Resolves the tension between the module’s documented success-onlyActivityinvariant at the call site and the post-Apr pipeline’s both-branch audit-row requirement. Wired into all 5 destructive listing actions plus all 6 form Save error branches (department / team / person × create + edit).@type ton every Ecto schema; 41 new@specs across the public context and helper modules.- Test infrastructure under
test/support/:Test.Endpoint,Test.Router,Test.Layouts,DataCase,LiveCase,Hooks,ActivityLogAssertions.lazy_htmltest-only dep forPhoenix.LiveViewTestHTML parsing. mix test.setup/mix test.resetaliases for local DB bootstrap.
Changed
- BREAKING (return-shape):
Staff.rename_placeholder_email/2now returns{:error, atom}(:blank_email,:placeholder_already_claimed,:email_already_taken) instead of{:error, binary_message}. Callers must route throughPhoenixKitStaff.Errors.message/1at the presentation boundary. Helpers.log_operation_error/3metadata-merge precedence: caller- supplied metadata is now merged UNDER the helper-owned keys (db_pending/error_kind/error_keys/error_atom) so audit-feed readers can rely on those keys being authoritative.:resource_uuidopt is now optional (failed CREATE submissions have no uuid yet).PhoenixKitStaff.Activity.log/2rescue widened to canonical post-Apr shape: explicitPostgrex.Error -> :okandDBConnection.OwnershipError -> :okahead of the genericLogger.warningbranch, pluscatch :exit, _ -> :ok.PhoenixKitStaff.enabled?/0addscatch :exit, _ -> falsefor sandbox-shutdown safety.handle_info/2catch-all in all 7 admin LVs promoted from silent{:noreply, socket}toLogger.debug(...).Staff.next_birthday_and_days/2extracted sharedanniversary_in_year/2helper that mirrors PostgresINTERVAL '1 year'arithmetic.Staff.org_tree/0collapsesMapSetbuild viaMapSet.new/2.
Fixed
- Schema constraint name mismatch in
Schemas.Person.changeset/2(HIGH). The DB index isphoenix_kit_staff_people_user_index, but the changeset registered the Ecto-defaultphoenix_kit_staff_people_user_uuid_index, so duplicateuser_uuidinserts raisedEcto.ConstraintErrorinstead of returning{:error, %Ecto.Changeset{}}. Changeset now passesname: :phoenix_kit_staff_people_user_indexexplicitly. PersonShowLive.handle_info/2had no catch-all (MEDIUM). Any non-{:staff, ...}message reaching the LV’s mailbox would have raisedFunctionClauseError. Catch-all clause added.- Subscribe-after-fetch race on the 3 show pages (LOW).
department_show_live/team_show_live/person_show_livenow subscribe BEFORE the DB read so a broadcast in the gap doesn’t get silently dropped. - Leap-day display drift in
next_birthday_and_days/2(LOW). Wrap-to-next-year branch was unconditionally clamping Feb 29 → Feb 28 even when the target year was a leap year. Display now matches the Postgres SQL window filter exactly. Schemas.Team.changeset/2changesunique_constraintfrom[:department_uuid, :name](composite list — error attached to the first field) tounique_constraint(:name, name: ...)so inline form errors render below the field the user actually edits.
Performance
Staff.org_tree/0:MapSet.new(list, mapper)skips an intermediate list allocation.
Tests
- 49 → 302 tests, 0 failures, 5/5 stable.
mix test --cover: 62.64% → 95.07% line coverage.- New test files cover: per-atom
Errors.message/1pins, helpers unit tests with PII-safety assertions, error-branch logging, per-LVhandle_infocatch-allLogger.debugpins, subscribe-before-fetch source-pairing meta-test, edge-case Unicode/SQL-metacharacter inputs, all listing LVs, all form LVs with both happy-path AND failure-side audit-row pins.
Internal
mix.exstest_coverage [ignore_modules]filter somix test --coverreports production-only coverage.test_helper.exsrescuesErlangErrorfromSystem.cmd("psql", ...)somix test --exclude integrationworks in environments withoutpsqlon PATH.
Staff 0.2.0. Install or update: {:phoenix_kit_staff, "~> 0.2"}, then mix deps.get && mix phoenix_kit.update. Full history: CHANGELOG.