Timesheets and Manual Time
Relevant source files
The following files were used as context for generating this wiki page:
- apps/web/core/components/pages/timesheet/timesheet-page-content.tsx
- apps/web/core/hooks/activities/use-timesheet.ts
- apps/web/core/components/features/manual-time/add-manual-time-modal.tsx
- apps/web/core/services/client/api/timesheets/time-log.service.ts
- apps/web/core/components/features/timesheet/add-mask-modal.tsx
- apps/web/core/hooks/activities/use-timelog-filter-options.ts
- apps/web/core/types/schemas/timer/time-log.schema.ts
The Timesheets and Manual Time feature is a core part of the Ever Teams platform, providing comprehensive tools for work and workforce management. It allows users to track their time, view detailed activity reports, and manually add or edit time entries. This system is crucial for productivity tracking, project management, and billing.
The architecture is composed of several layers: UI components for user interaction, custom hooks for business logic and state management, and a dedicated service layer for communicating with the backend API. This separation of concerns ensures a maintainable and scalable system. Data fetching and mutations are managed by @tanstack/react-query, while global state is handled by Jotai.
Architecture Overview
The timesheet system follows a modern frontend architecture, separating presentation, logic, and data fetching.
This diagram illustrates the high-level interaction between the main parts of the timesheet feature.
Core Components
The user interface for timesheets is built from several key React components.
TimeSheetPageContent
This is the main component for the timesheet page. It orchestrates the entire view, including filters, data display, and modals.
Key Responsibilities:
- Manages the primary view mode:
ListVieworCalendarView. - Handles the date range selection for filtering timesheets.
- Integrates various child components for filtering (
LazyTimesheetFilter), data display (LazyTimesheetView,LazyCalendarView), and pagination (LazyTimesheetPagination). - Utilizes the
useTimesheethook to fetch, group, and manage timesheet data. - Renders summary cards for "Pending Tasks", "Men Hours", and "Members Worked".
- Opens modals for adding manual time (
AddManualTimeModal) and viewing details (TimesheetDetailModal).
Sources: apps/web/core/components/pages/timesheet/timesheet-page-content.tsx
AddManualTimeModal
This modal component provides a form for users to manually add a time log for a specific task.
Key Features:
- A form with fields for Date, Start Time, End Time, Team, Task, Description, and Reason.
- Client-side validation to ensure the end time is after the start time and all required fields are filled.
-e Calculates and displays the total duration of the time entry. - Uses the
useManualTimehook to submit the data to the backend. - Supports both regular users and managers, with managers having the ability to select employees.
Sources: apps/web/core/components/features/manual-time/add-manual-time-modal.tsx
AddTaskModal
This modal is another interface for adding time entries, with a focus on creating timesheets for specific projects and tasks.
Key Features:
- Allows adding one or more "shifts" (time periods) for a single entry.
- Form fields include Task, Employee, Project, Notes, and Billable status.
- Each shift has its own date, start time, and end time.
- Uses the
createTimesheetfunction from theuseTimesheethook to persist the data.
Sources: apps/web/core/components/features/timesheet/add-mask-modal.tsx
Hooks and State Management
Business logic and state are primarily managed through custom hooks and Jotai atoms.
useTimesheet Hook
This is the central hook for fetching and manipulating timesheet data. It leverages @tanstack/react-query for robust data fetching and caching.
Key Return Values & Functions:
| Name | Description |
|---|---|
loadingTimesheet | A boolean indicating if the timesheet data is currently being fetched. |
timesheet | An array of grouped timesheet entries, structured based on the selected view mode and grouping. |
getTaskTimesheet | A function to trigger a refetch of timesheet data with new parameters. |
deleteTaskTimesheet | A function to delete one or more time logs by their IDs. |
updateTimesheetStatus | A function to update the status (e.g., APPROVED, DENIED) of timesheet entries. |
createTimesheet | A function to create a new time log entry. |
updateTimesheet | A function to modify an existing time log entry. |
The hook automatically fetches data when its dependencies, such as startDate, endDate, or filter selections, change. It also provides mutation functions that automatically invalidate the relevant query cache upon success, ensuring the UI stays in sync.
Sources: apps/web/core/hooks/activities/use-timesheet.ts
useManualTime Hook
A specialized hook for handling the logic within the AddManualTimeModal.
Key Responsibilities:
- Wraps the
timeLogService.addManualTimeAPI call. - Manages the loading, success, and error states for the form submission.
- Provides feedback to the user by setting error messages.
Sources: apps/web/core/components/features/manual-time/add-manual-time-modal.tsx:43-53
useTimelogFilterOptions Hook
This hook centralizes the logic for managing filter states and user permissions related to timesheets.
Key Responsibilities:
- Manages filter states for employees, projects, tasks, and statuses using Jotai atoms.
- Provides a utility function
isUserAllowedToAccessto check if a user has manager-level permissions. - Handles the selection logic for bulk actions in the timesheet view.
Sources: apps/web/core/hooks/activities/use-timelog-filter-options.ts
API Service Layer (TimeLogService)
All communication with the backend for time log-related operations is handled by the TimeLogService class. This service abstracts the API calls and includes data validation using Zod schemas.
Sources: apps/web/core/services/client/api/timesheets/time-log.service.ts
Key Methods
addManualTime
This method sends a request to create a new manual time log.
- Endpoint:
POST /timesheet/time-log - Payload: The method takes a
TAddManualTimeRequestobject, converts thestartedAtandstoppedAtdates to ISO strings, and includestenantIdandorganizationId. - Response Validation: The API response is validated against the
timeLogSchemato ensure type safety.
The following diagram shows the sequence of events when a user adds manual time.
getTimeLogs
Fetches a list of time logs based on a set of filter criteria.
- Endpoint:
GET /timesheet/time-log - Query Parameters:
startDate,endDate(required)organizationId,tenantIdtimeZoneprojectIds,employeeIds,taskIds,status(arrays for filtering)
Sources: apps/web/core/services/client/api/timesheets/time-log.service.ts:133-172
deleteTaskTimesheetLogs
Performs a bulk deletion of time logs.
- Endpoint:
DELETE /timesheet/time-log - Query Parameters:
organizationId,tenantIdlogIds[]: An array of time log IDs to be deleted.
- Constraints: A maximum of 100 logs can be deleted in a single request.
Sources: apps/web/core/services/client/api/timesheets/time-log.service.ts:174-201
Data Structures
The system relies on well-defined data structures, validated by Zod, to ensure consistency.
TAddManualTimeRequest
This table describes the payload for creating a manual time entry.
| Field | Type | Description | Required |
|---|---|---|---|
startedAt | Date | The start date and time of the log. | Yes |
stoppedAt | Date | The end date and time of the log. | Yes |
taskId | string | The ID of the associated task. | Yes |
description | string | Optional notes about the time entry. | No |
reason | string | The reason for the manual entry. | No |
isBillable | boolean | Whether the time is billable. | No |
organizationId | string | The ID of the organization. | Yes |
Sources: apps/web/core/services/client/api/timesheets/time-log.service.ts:112-120
ITimeLog Interface
This interface represents a single time log record. Key fields include:
| Field | Type | Description |
|---|---|---|
id | string | Unique identifier for the time log. |
startedAt | Date or string | The start time of the log. |
stoppedAt | Date or string | The end time of the log. |
isBillable | boolean | Indicates if the log is billable. |
logType | ETimeLogType | Type of log (e.g., MANUAL, TRACKED). |
source | ETimeLogSource | Source of the log (e.g., BROWSER, DESKTOP). |
employee | IEmployee | The employee who logged the time. |
project | IProject | The project associated with the log. |
task | TTask | The task associated with the log. |
timesheet | ITimesheet | The parent timesheet object, containing status and creation date. |
Sources: apps/web/core/hooks/activities/use-timesheet.ts:19, apps/web/core/lib/helpers/helper-calendar.ts:13-107
Conclusion
The Timesheets and Manual Time feature is a well-architected system within the Ever Teams application. It effectively separates concerns between UI components, business logic hooks, and API services. The use of @tanstack/react-query ensures efficient data fetching and state synchronization, while Jotai manages global UI and filter states. The TimeLogService provides a clean, type-safe interface to the backend, with Zod schemas ensuring data integrity. This modular design makes the feature robust, maintainable, and easy to extend.