54 lines
1.4 KiB
Markdown
54 lines
1.4 KiB
Markdown
# Groups + Switcher Plan
|
|
|
|
## Focus
|
|
Group create/join + group switcher in navbar.
|
|
|
|
## Goals
|
|
- Create groups and invite codes.
|
|
- Join groups via invite code.
|
|
- Persist active group selection per user.
|
|
- Enforce server-side group membership checks.
|
|
|
|
## Proposed changes
|
|
### Database (existing schema)
|
|
Use existing tables:
|
|
- `groups`, `group_members`.
|
|
|
|
### Backend
|
|
Add routes:
|
|
- `POST /api/groups` to create a group
|
|
- Body: `{ name }`
|
|
- Creates group, generates invite code, adds creator as GROUP_ADMIN.
|
|
- `POST /api/groups/join` to join by invite code
|
|
- Body: `{ inviteCode }`
|
|
- Adds user as MEMBER if not already in group.
|
|
- `GET /api/groups` to list groups for current user
|
|
- Returns list of groups and roles.
|
|
- `POST /api/groups/active` to set active group
|
|
- Persists in `user_settings` JSON.
|
|
|
|
Add server helpers:
|
|
- `getSessionUser()` already exists
|
|
- Add `requireSessionUser()` and `getUserGroups(userId)` helpers
|
|
- Add `getActiveGroup(userId)` helper
|
|
|
|
### Frontend
|
|
- Update navbar to show current group and dropdown of groups.
|
|
- Add minimal create/join UI (modal or simple dropdown actions).
|
|
|
|
### Tests
|
|
- Add API tests for create/join/list/active group.
|
|
|
|
## Files impacted (expected)
|
|
- `apps/web/app/api/groups/*`
|
|
- `apps/web/lib/groups.ts`
|
|
- `apps/web/components/navbar.tsx`
|
|
- `apps/web/app/page.tsx` (use active group)
|
|
- `apps/web/__tests__/groups.test.ts`
|
|
|
|
## Status
|
|
- Implemented
|
|
|
|
## Test output
|
|
- `create group inserts membership`
|