feat(groups): add active group foundation#148
Conversation
Adds a nullable active_group_id column on profiles (FK to groups, cleared on group deletion) and a resolveActiveGroupId helper that treats a user's sole group as active when no explicit choice has been persisted yet. A useActiveGroup hook exposes this derived state for future tickets, and the header's Groups button now surfaces the active group name or a create/join CTA when the user has no groups. Closes #123 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CKMx3D6cDTnUEYacpy9Mn6
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Deploy →
|
…tyles Remove the speculative active_group_id case from useUpdateProfile.ts (no caller sets it yet; issue #124 will add explicit switching), and extract the shared Groups button className in Navigation.tsx to avoid duplication between the active-group and zero-group CTA branches. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CKMx3D6cDTnUEYacpy9Mn6
There was a problem hiding this comment.
Pull request overview
This PR lays the groundwork for an “Active Group” concept by adding a persisted active_group_id on profiles, introducing a pure helper for determining the effective active group, and updating the header to display the active group name (or a create/join CTA when the user has no groups).
Changes:
- Adds
profiles.active_group_idas a nullable FK togroups(id)withON DELETE SET NULL, plus an index. - Introduces
resolveActiveGroupId(and unit tests) to select a persisted active group when valid or auto-activate a sole membership. - Adds
useActiveGroupand updates the App Header “Groups” button to display the active group name or a create/join CTA.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| supabase/migrations/20260710154342_add_active_group_id_to_profiles.sql | Adds the active_group_id column and index on profiles with FK behavior. |
| src/lib/activeGroup.ts | Adds helper to resolve the effective active group from profile + memberships. |
| src/lib/activeGroup.test.ts | Adds Vitest coverage for single/multi/zero-group and stale persisted ID scenarios. |
| src/integrations/supabase/types.ts | Updates generated Supabase types to include active_group_id + FK relationship metadata. |
| src/hooks/useActiveGroup.ts | Adds hook to expose active group state derived from profile + memberships. |
| src/components/layout/AppHeader/Navigation.tsx | Updates header Groups button to show active group name or create/join CTA. |
| src/api/auth/useUpdateProfile.ts | Extends profile update typing to allow active_group_id updates. |
| const activeGroupId = resolveActiveGroupId({ | ||
| profileActiveGroupId: profile?.active_group_id, | ||
| groupIds: groups.map((group) => group.id), | ||
| }); |
Addresses Copilot review comments on PR #148: the header briefly showed the "Create/Join a Group" CTA for users who do have groups while useUserGroupsQuery was still resolving.
|
Fixed the two loading-state comments in c847a00: On the third comment ( Generated by Claude Code |
Adds a nullable
active_group_idcolumn on profiles (FK to groups, cleared automatically on group deletion) plus aresolveActiveGroupIdhelper anduseActiveGrouphook that auto-activates a user's sole group when no explicit choice is persisted. The header's Groups button now shows the active group's name, or a create/join CTA when the user has no groups.Closes #123
Verification
pnpm testpasses, including newsrc/lib/activeGroup.test.tscases for auto-activation, multi-group, stale/deleted active group, and zero-group scenarios.Generated by Claude Code