Team Management
Relevant source files
The following files were used as context for generating this wiki page:- apps/web/core/services/server/requests/organization-team.ts
- apps/web/core/hooks/organizations/teams/use-organization-teams.ts
- apps/web/core/components/pages/teams/team/team-members.tsx
- apps/web/app/[locale]/(main)/(teams)/team/[teamId]/[profileLink]/page.tsx
- apps/mobile/app/services/client/requests/organization-team.ts
- apps/web/core/lib/utils/team-members.utils.ts
- README.md
Team Management is a core feature of the Ever Teams platform, providing the foundational structure for collaboration, project management, and workforce organization. It allows users to create, view, update, and delete teams, manage team membership and roles, and associate teams with specific projects. The system is designed to be robust, with a clear separation between client-side state management and backend API services, supporting both web and mobile applications.
The architecture relies on a combination of Next.js for the web frontend, React Query for server state management, and Jotai for global client-side state. This ensures efficient data fetching, caching, and synchronization between the UI and the backend.
Architecture Overview
The Team Management feature follows a modern web application architecture. The client-side interacts with a set of dedicated API endpoints to perform CRUD (Create, Read, Update, Delete) operations on team-related data.
This diagram illustrates the high-level data flow for team management operations.
State Management
Client-side state is managed by a combination of React Query for server state and Jotai for global UI state. The useOrganizationTeams hook is the central point for all team-related state and operations in the UI.
Sources: apps/web/core/hooks/organizations/teams/use-organization-teams.ts
React Query Integration
React Query is used to fetch, cache, and update team data from the server. This simplifies data fetching logic and provides features like automatic refetching and stale-while-revalidate.
organizationTeamsQuery: Fetches the list of all teams for the current organization.organizationTeamQuery: Fetetches detailed information for a single, active team.- Mutations:
useMutationis used for creating, updating, and deleting teams, ensuring that the cache is invalidated and the UI is updated upon success.
The following diagram shows the sequence for fetching team data.
Jotai Atoms
Jotai is used for managing global client-side state that can be shared across different components.
| Atom Name | Description | Source File |
|---|---|---|
organizationTeamsState | Holds the array of all organization teams. | apps/web/core/hooks/organizations/teams/use-organization-teams.ts:140 |
activeTeamIdState | Stores the ID of the currently selected team. | apps/web/core/hooks/organizations/teams/use-organization-teams.ts:199 |
activeTeamState | A derived atom that provides the full object for the active team. | apps/web/core/hooks/organizations/teams/use-organization-teams.ts:143 |
isTeamMemberState | A boolean flag indicating if the current user is a member of any team. | apps/web/core/hooks/organizations/teams/use-organization-teams.ts:202 |
isTeamManagerState | A boolean flag indicating if the current user is a manager of the active team. | apps/web/core/hooks/organizations/teams/use-organization-teams.ts:211 |
isTeamMemberJustDeletedState | A flag to indicate if a member was recently removed, used to trigger UI updates. | apps/web/core/hooks/organizations/teams/use-organization-teams.ts:200 |
API Endpoints
The team management feature is powered by a set of RESTful API endpoints. The service layer, found in organization-team.ts, abstracts these API calls for both web and mobile clients.
Sources: apps/web/core/services/server/requests/organization-team.ts, apps/mobile/app/services/client/requests/organization-team.ts
| Method | Path | Description |
|---|---|---|
POST | /organization-team | Creates a new organization team. |
GET | /organization-team | Retrieves a paginated list of all teams. |
GET | /organization-team/:id | Retrieves detailed information for a single team. |
PUT | /organization-team/:id | Updates an existing team. |
DELETE | /organization-team/:id | Deletes a team. |
DELETE | /organization-team-employee/:employeeId | Removes an employee from their team. |
DELETE | /organization-team/teams/:userId | Removes a user from all teams they are a part of. |
Common Query Parameters
When fetching team data, the API supports several query parameters to customize the response. These are serialized using the qs library.
| Parameter | Type | Description |
|---|---|---|
organizationId | string | The ID of the organization to which the teams belong. |
tenantId | string | The ID of the tenant. |
relations | string[] | An array of related entities to include in the response (e.g., members, projects, members.employee.user). |
withLastWorkedTask | string | If 'true', includes the last task a member worked on. |
Sources: apps/web/core/services/server/requests/organization-team.ts:77-96, 119-136
Core Operations
Creating a Team
Creating a team is a two-step process on the backend. When a request to create a team is made, the system first creates an associated project with the same name. This project is then linked to the new team.
This sequence diagram shows the flow for creating a new team.
Deleting a Team
When a team is deleted, the deleteOrganizationTeam mutation is called. Upon successful deletion, a success toast is displayed, and the user is logged out after a 3-second delay to allow them to choose a new workspace.
Sources: apps/web/core/hooks/organizations/teams/use-organization-teams.ts:401-426
Removing a User from All Teams
The system provides a function to remove a user from all teams they are a member of. This is handled by the removeUserFromAllTeam mutation. This operation has significant side effects:
- It reloads all team data.
- It refreshes the user's authentication token.
- It refreshes the user's data to update their permissions and team associations.
Sources: apps/web/core/hooks/organizations/teams/use-organization-teams.ts:429-458, apps/web/core/services/server/requests/organization-team.ts:169-178
Team Membership and Display
Member Processing
The useProcessedTeamMembers hook is responsible for preparing the list of team members for display. It ensures the currently authenticated user is always present in the list, even if they are not yet an official member of the team (a placeholder is created in this case).
The useFilteredTeamMembers hook then applies filters based on the user's status (e.g., 'online', 'running', 'idle').
Sources: apps/web/core/components/pages/teams/team/team-members.tsx:50-52, apps/web/core/lib/utils/team-members.utils.ts:20-70
UI Views
The TeamMembers component is responsible for rendering the list of team members. It supports multiple view modes, controlled by the IssuesView enum:
CARDS: Displays each member as a card.TABLE: Displays members in a tabular format.BLOCKS: A block-based layout.
The component dynamically selects the appropriate view component (TeamMembersCardView, TeamMembersTableView, or TeamMembersBlockView) based on the current view mode.
Sources: apps/web/core/components/pages/teams/team/team-members.tsx:90-149
Public Team Page
The application supports public-facing team pages, accessible via a unique profile link (/[locale]/(main)/(teams)/team/[teamId]/[profileLink]). This page uses a separate hook, usePublicOrganizationTeams, to fetch public team data. It includes logic to automatically redirect authenticated members to the internal dashboard view if they try to access their own team's public page. The data on this page is periodically refreshed using useRefreshIntervalV2.
Sources: apps/web/app/[locale]/(main)/(teams)/team/[teamId]/[profileLink]/page.tsx
Summary
The Team Management system is a well-architected and central part of the Ever Teams platform. It effectively uses modern frontend technologies like React Query and Jotai to manage server and client state, providing a responsive and consistent user experience across different platforms. The API is clearly defined and handles complex operations, such as the implicit creation of a project when a team is created. The modular structure of hooks and components allows for flexible and maintainable UI development for displaying and interacting with team data.