Daily Planning
Relevant source files
The following files were used as context for generating this wiki page:
- apps/web/core/hooks/daily-plans/use-daily-plan.ts
- apps/web/core/stores/daily-plan/daily-plan.ts
- apps/web/core/services/server/requests/daily-plan.ts
- apps/web/core/components/features/daily-plan/add-task-estimation-hours-modal.tsx
- apps/web/core/components/daily-plan/plan-header.tsx
- apps/web/core/components/features/daily-plan/create-daily-plan-form-modal.tsx
- apps/web/core/components/features/daily-plan/add-task-to-plan.tsx
- apps/web/core/components/pages/task/details-section/blocks/task-plans.tsx
- apps/web/locales/en.json
The Daily Planning feature allows users to organize their work by creating daily schedules, assigning tasks to specific dates, and setting planned work hours. This system is a cornerstone of the platform's time and work management capabilities, providing a structured way for employees and managers to plan and track productivity. It helps bridge the gap between task estimation and actual time spent, offering insights into daily progress and workload.
The feature is described as helping "organize the work process to achieve the best results."
Sources: apps/web/locales/en.json:766-766
Architecture Overview
The Daily Planning system is built on a client-server architecture. The frontend, built with React and Next.js, manages the user interface and client-side state. It communicates with a backend API to perform CRUD operations on daily plan data. State management on the client has transitioned from a purely Jotai-based approach to a hybrid model leveraging React Query for server state and Jotai for global UI state.
Data Flow
The diagram below illustrates the general data flow when a user interacts with the Daily Planning feature.
This diagram shows the flow of data from UI interaction to the backend API and back.
Sources: apps/web/core/hooks/daily-plans/use-daily-plan.ts, apps/web/core/services/server/requests/daily-plan.ts
Data Model
The core of the feature is the DailyPlan entity. Each plan is associated with an employee, a specific date, and contains a list of tasks.
| Field | Type | Description |
|---|---|---|
id | string | Unique identifier for the daily plan. |
date | string (ISO Date) | The date for which the plan is created. |
workTimePlanned | number | The total number of hours the user plans to work on that day. |
status | string (EDailyPlanStatus) | The status of the plan (e.g., 'OPEN'). |
employeeId | string | The ID of the employee to whom the plan belongs. |
organizationId | string | The ID of the organization. |
organizationTeamId | string | The ID of the team. |
tenantId | string | The ID of the tenant. |
tasks | TTask[] | An array of task objects associated with the plan. |
employee | object | The associated employee object, loaded via relations. |
Sources: apps/web/core/hooks/daily-plans/use-daily-plan.ts:24-30, apps/web/core/services/server/requests/daily-plan.ts:10-24
State Management
Client-side state for daily plans is managed through a combination of React Query and Jotai.
useDailyPlan Hook
This is the primary hook for interacting with daily plans. It has replaced several legacy Jotai atoms to ensure data consistency between different views (e.g., the home modal and the profile "Plans" tab). It uses React Query to fetch, cache, and mutate per-employee plan data.
Key responsibilities of the hook include:
- Fetching plans for a specific employee (
getDayPlansByEmployeeQuery) or the current user (getMyDailyPlansQuery). - Providing mutation functions for creating, updating, and deleting plans.
- Deriving different views of the plan data, such as
todayPlan,futurePlans,pastPlans, andoutstandingPlans.
Sources: apps/web/core/hooks/daily-plans/use-daily-plan.ts:44-436
The following diagram illustrates how the hook derives different plan categories from the fetched data.
This diagram shows how futurePlans, todayPlan, and pastPlans are derived from a single source of truth.
Sources: apps/web/core/hooks/daily-plans/use-daily-plan.ts:351-436
Jotai Atoms
A single Jotai atom, dailyPlanListState, remains for storing the team-wide list of all daily plans. This is used for broader, team-level views and is kept for backward compatibility.
Sources: apps/web/core/stores/daily-plan/daily-plan.ts:16-20
Backend API
The frontend communicates with the backend via a set of well-defined API endpoints. These are wrapped in the dailyPlanService on the client and handled by server-side request functions.
API Endpoints
| Method | Path | Description |
|---|---|---|
GET | /daily-plan | Get all daily plans for a team. |
GET | /daily-plan/me | Get all daily plans for the current user. |
GET | /daily-plan/employee/{employeeId} | Get all daily plans for a specific employee. |
GET | /daily-plan/task/{taskId} | Get all plans that include a specific task. |
POST | /daily-plan | Create a new daily plan. |
PUT | /daily-plan/{planId} | Update an existing daily plan. |
POST | /daily-plan/{planId}/task | Add a task to a daily plan. |
PUT | /daily-plan/{planId}/task | Remove a task from a daily plan. |
DELETE | /daily-plan/{planId} | Delete a daily plan. |
PUT | /daily-plan/{taskId}/remove | Remove a task from multiple plans at once. |
Sources: apps/web/core/services/server/requests/daily-plan.ts
Sequence Diagram: Creating a Plan
This diagram shows the sequence of events when a user creates a new daily plan.
This diagram illustrates the interactions for creating a daily plan.
Sources: apps/web/core/components/features/daily-plan/create-daily-plan-form-modal.tsx:102-124, apps/web/core/hooks/daily-plans/use-daily-plan.ts:285-291
UI Components
Several key React components make up the user interface for the Daily Planning feature.
AddTasksEstimationHoursModal
This is the central modal for managing a specific day's plan. It allows users to:
- Set the
workTimePlannedfor the day. - View, add, and remove tasks from the plan.
- Set time estimates for each task.
- Start the timer for a planned task.
The modal displays warnings to guide the user, such as when the total estimated time for tasks exceeds the planned work time, or when tasks are missing estimates.
Sources: apps/web/core/components/features/daily-plan/add-task-estimation-hours-modal.tsx
PlanHeader
This component displays a summary of a daily plan. It calculates and shows key metrics:
- Planned Time: The
workTimePlannedfor the day. - Estimated Time: The sum of estimates for all tasks in the plan.
- Total Time Worked: The sum of all time logs for the tasks on that day.
- Task Progress: Shows counts for completed, ready, and remaining tasks.
- Completion Percentage: A progress bar showing the percentage of completed tasks.
Sources: apps/web/core/components/daily-plan/plan-header.tsx:32-52
CreateDailyPlanFormModal
A modal form used to create a new daily plan for a specific task. It allows the user to select a date and, if they are a manager, to select an employee for whom the plan is being created.
Sources: apps/web/core/components/features/daily-plan/create-daily-plan-form-modal.tsx
AddTaskToPlan
A modal that allows a user to add a specific task to an existing or new daily plan. It presents a list of future plans to choose from or an option to create a new plan for a selected date.
Sources: apps/web/core/components/features/daily-plan/add-task-to-plan.tsx
TaskPlans
This component is displayed within a task's detail view. It fetches and lists all the daily plans that a specific task is a part of, grouped by the employee who planned it. This provides a reverse lookup to see on which dates a task has been scheduled.
Sources: apps/web/core/components/pages/task/details-section/blocks/task-plans.tsx
Conclusion
The Daily Planning feature is a sophisticated system for work scheduling and productivity management. It relies on a robust data model, a modern client-side state management strategy with React Query, and a clear set of API endpoints. The UI components provide a rich user experience, guiding users to effectively plan their workdays and track their progress against those plans. The architecture is designed to be scalable and maintainable, with a clear separation of concerns between data fetching, state management, and UI representation.