Files
evig/scripts/db/migrations/134_team_space_links.sql
GandClaude Fable 5 6bea23a407 feat(teams): team space — AI form assist, task/protocol connections, members-first UI (#216)
* feat(teams): invite members by email + seed Forschung & Entwicklung team

Team onboarding gets a full email-invite flow, unified on the existing
placeholder-claim mechanism (one path, no parallel invitation table):

- Invite by name + email on the team page (super admin): registered staff
  are added directly and notified; unknown addresses get a placeholder
  account with the membership plus a claim link (14d, single-use) by email
  (POST /api/admin/teams/[id]/invitations)
- Placeholder "Einladen" can now send the claim link by email (optional
  address field) instead of clipboard-only delivery
- Claim page prefills the email field from the delivery address
- Direct member-add notifies the person by email (self-join stays silent)
- New templates teamClaimInvite / teamMemberAdded (Swiss German, escaped)
- Migration 132 seeds the Forschung & Entwicklung team with Georgy as lead
- Docs: EMAILS.md trigger table gains the Teams rows

Tests: 18 new (templates + schemas); typecheck, lint, lint:umlauts clean.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Akm86ZwqhiSM2BfdKH96cN

* fix(ci): repair inherited E2E breakage — seed columns + moved admin route

Both failures predate this branch (main's last five CI runs fail the same
two jobs):

- e2e-seed.ts still wrote technician_profiles.is_verified /
  verification_date, dropped in migration 122 (identity moved to
  user_profiles in 121). Seed now sets the verified flag on user_profiles,
  keeping the "verified technician" premise.
- inventory-routes.ts pointed at /admin/repairer-applications — the one
  hardcoded path in the list, which drifted when the section moved. Now
  uses ROUTES.admin.hrApplications (config-driven like every other row).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Akm86ZwqhiSM2BfdKH96cN

* fix(db): recreate ensure_seller_profile() without dropped display_name

Migration 122 dropped seller_profiles.display_name but the trigger
function from 031 still inserted it, so the first listing insert of any
user without a seller_profiles row errored — surfaced by the E2E seed,
and a live bug for new P2P sellers. Migration 133 recreates the function
inserting only user_id (identity lives on user_profiles since 121).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Akm86ZwqhiSM2BfdKH96cN

* fix(e2e): first() on assertions whose text legitimately renders twice

Timecard submit ("Zur Prüfung gesendet" in status banner + summary line),
tasks empty state, and blog body/excerpt all resolve to two elements,
tripping Playwright strict mode — timecard failed every retry, the other
two were flaky. Assert on .first(); either occurrence being visible is
what the journeys actually verify.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Akm86ZwqhiSM2BfdKH96cN

* fix(timecards): race-safe draft creation + stale E2E heading assertion

Two concurrent first-hits of GET /api/timecards for the same user+period
both passed the existence check and raced the
UNIQUE(user_id, period_start, period_end) insert — the loser 500'd
("Zeitkarte konnte nicht geladen werden"). Insert now uses ON CONFLICT DO
NOTHING and serves the row the winner created.

The timecard journey also asserted a "Zeitkarten" heading on
/admin/zeiterfassung — that page's H1 is "Zeiterfassung" (the Zeitkarten
approval queue moved to its own page). Assert the real heading.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Akm86ZwqhiSM2BfdKH96cN

* feat(teams): AI form assist on team create/edit

The team-config form (/admin/teams/new) was one of the few creation
forms without the shared AIFormAssist bar. Standard two-step wiring:

- FORM_AI_REGISTRY entry 'team-config' — describe the team in a sentence
  and name/purpose/mail_folders/meeting_cadence/accent are filled; accent
  options derive from the teams config SSOT, no invented mail addresses
- AIFormAssist dropped into TeamFormClient (expanded on create, refine
  available on edit); AI-filled mail_folders array maps onto the form's
  newline-joined field, accent validated against the config enum
- Accent labels hoisted from the component into TEAM_ACCENT_LABELS in
  src/config/teams.ts (SSOT — form select and AI prompt share one list)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Akm86ZwqhiSM2BfdKH96cN

* feat(teams): team space — tasks + protocols connected to the team page

The team page becomes a working space by connecting existing systems
instead of adding new ones (goals, KPIs, focus, coverage already live
there):

- Migration 134: optional team_id on tasks + meeting_protocols
  (ON DELETE SET NULL, indexed) — org-wide records stay untouched
- Task form gains an optional Team select (create + edit); protocol
  form the same (options server-fed from listTeams)
- "Neue Aufgabe" / "Neues Protokoll" on the team page preselect the
  team via ?team= (validated against real teams before prefill)
- Team page shows two new panels: open tasks (due-first, assignee +
  priority) and recent protocols (status-badged), with empty states
- New team-space service (SoC: queries only); panels are pure server
  components reusing config label/color SSOTs

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Akm86ZwqhiSM2BfdKH96cN

* fix(teams): members first, one add/invite element below the list

The Mitglieder section led with two stacked forms before showing a
single member — backwards for a page you mostly read. Now the member
list comes first; below it sits ONE card: the staff picker row, and
for super admins a fold-out «Noch nicht registriert? Per E-Mail
einladen» containing the email invite (no second card, no chrome).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Akm86ZwqhiSM2BfdKH96cN

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-07-16 11:33:50 +02:00

15 lines
719 B
SQL

-- Migration 134: connect tasks + protocols to teams (team space)
--
-- The team page (/admin/teams/[slug]) becomes a working space: a team's open
-- tasks and its meeting protocols show up there. Both links are OPTIONAL —
-- org-wide tasks/protocols keep team_id NULL, nothing existing changes.
-- ON DELETE SET NULL: deleting a team never deletes its work records.
ALTER TABLE tasks
ADD COLUMN IF NOT EXISTS team_id uuid REFERENCES teams(id) ON DELETE SET NULL;
CREATE INDEX IF NOT EXISTS idx_tasks_team ON tasks(team_id);
ALTER TABLE meeting_protocols
ADD COLUMN IF NOT EXISTS team_id uuid REFERENCES teams(id) ON DELETE SET NULL;
CREATE INDEX IF NOT EXISTS idx_protocols_team ON meeting_protocols(team_id);