Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix(timesheet): Correct handling of timesheet updates in state #3497

Merged
merged 2 commits into from
Jan 6, 2025

Conversation

Innocent-Akim
Copy link
Contributor

@Innocent-Akim Innocent-Akim commented Jan 6, 2025

Description

#3441
Please include a summary of the changes and the related issue.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

Previous screenshots

Please add here videos or images of previous status

Current screenshots

Please add here videos or images of previous status

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced timesheet card time display with consistent two-digit formatting
    • Improved loading state and visual feedback for timesheet rejection process
  • Bug Fixes

    • Refined timesheet log date grouping logic
    • Improved error handling for timesheet API interactions
  • Performance

    • Streamlined timesheet creation and update processes
    • Enhanced state management for task and employee selection

Copy link
Contributor

coderabbitai bot commented Jan 6, 2025

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

apps/web/app/[locale]/timesheet/[memberId]/components/AddTaskModal.tsx

Oops! Something went wrong! :(

ESLint: 8.46.0

ESLint couldn't find the config "next/core-web-vitals" to extend from. Please check that the name of the config is correct.

The config "next/core-web-vitals" was referenced from the config file in "/apps/web/.eslintrc.json".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

Walkthrough

This pull request introduces several modifications across multiple files in the timesheet management section of the web application. The changes primarily focus on improving the handling of timesheet-related components, including task addition, editing, and status management. Key updates involve refining data handling in modal components, enhancing error logging in the useTimesheet hook, and improving time formatting consistency. The modifications aim to streamline the user experience and provide more robust data processing for timesheet entries.

Changes

File Change Summary
apps/web/app/[locale]/timesheet/[memberId]/components/AddTaskModal.tsx - Removed organizationContactId from payload
- Modified onChange handler to update state with entire value object
- Removed console.log and added direct closeModal() call
apps/web/app/[locale]/timesheet/[memberId]/components/EditTaskModal.tsx - Updated onChange handler to set employeeId to entire value object
apps/web/app/[locale]/timesheet/[memberId]/components/RejectSelectedModal.tsx - Added loadingUpdateTimesheetStatus variable
- Updated button disabled condition
- Added loading spinner with ReloadIcon
apps/web/app/[locale]/timesheet/[memberId]/page.tsx - Enhanced time formatting with padStart() for consistent hour/minute display
apps/web/app/hooks/features/useTimesheet.ts - Simplified createdAt property checks
- Improved error handling in createTimesheet
- Enhanced error logging and response validation

Sequence Diagram

sequenceDiagram
    participant User
    participant AddTaskModal
    participant useTimesheet
    participant API

    User->>AddTaskModal: Fill task details
    AddTaskModal->>useTimesheet: Create timesheet
    useTimesheet->>API: Send timesheet data
    API-->>useTimesheet: Return response
    useTimesheet-->>AddTaskModal: Confirm creation
    AddTaskModal->>User: Close modal
Loading

Possibly related PRs

Suggested labels

bug, WEB, Ever Teams, Improvement, Timesheets

Suggested reviewers

  • evereq

Poem

🐰 Timesheets dancing, bits in flight,
Modals tweaking with rabbit's might,
Padded hours, smooth as can be,
Code refactored, setting data free!
A hoppy update, clean and bright! 🕒✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
apps/web/app/[locale]/timesheet/[memberId]/components/AddTaskModal.tsx (1)

156-158: Directly storing the full value object.

Instead of extracting id alone, storing the entire value object opens possibilities for future enhancements (e.g., displaying additional task details). Ensure all references to formState.taskId still function correctly if value is an object instead of a plain string.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2adfad5 and 72076c6.

📒 Files selected for processing (5)
  • apps/web/app/[locale]/timesheet/[memberId]/components/AddTaskModal.tsx (2 hunks)
  • apps/web/app/[locale]/timesheet/[memberId]/components/EditTaskModal.tsx (1 hunks)
  • apps/web/app/[locale]/timesheet/[memberId]/components/RejectSelectedModal.tsx (4 hunks)
  • apps/web/app/[locale]/timesheet/[memberId]/page.tsx (1 hunks)
  • apps/web/app/hooks/features/useTimesheet.ts (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: deploy
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (13)
apps/web/app/[locale]/timesheet/[memberId]/components/RejectSelectedModal.tsx (5)

4-4: Great usage of ReloadIcon.

No concerns on this import; it integrates seamlessly for loading indicators.


37-37: Integration of the new hook variables looks good.

Using useTimesheet to access updateTimesheetStatus, loadingUpdateTimesheetStatus, and setSelectTimesheetId within this component ensures a cohesive state management flow. No immediate issues detected.


49-49: Modal closure timing is appropriate.

Closing the modal immediately after resetting the selectTimesheetId array is consistent with a clean success flow.


101-101: Improved button disabling condition.

Disabling the button based on loadingUpdateTimesheetStatus prevents duplicate submissions during status updates.


109-111: Better user feedback with a loading spinner.

Displaying the ReloadIcon while loadingUpdateTimesheetStatus is true helps clearly convey a loading state.

apps/web/app/[locale]/timesheet/[memberId]/page.tsx (1)

174-174: Well-structured zero-padding formatting.

Using String(...).padStart(2, '0') standardizes hour and minute display, improving readability for single-digit values.

apps/web/app/hooks/features/useTimesheet.ts (5)

10-10: Axios import check.

Importing axios here is reasonable for handling HTTP calls and error inspection.


29-40: Switched to directly checking item.createdAt.

Replacing checks for timesheet?.createdAt with item?.createdAt clarifies data access. The added warning and error logs provide improved visibility if createdAt is missing or invalid.


65-77: Consistent grouping function updates.

The logic follows the same pattern as in groupByDate. Ensuring item?.createdAt and logging errors if missing is a good approach for data integrity.


181-195: Enhanced error handling for createTimesheet.

Distinguishing between Axios and generic errors allows for more targeted debugging. Throwing a custom error message and logging the response status provides a clear audit trail.


201-230: Improved updateTimesheet flow.

  • Logging a warning when the user is unauthenticated (instead of throwing an error) is sensible if a no-op is intended.
  • Verifying response?.data?.id before patching the local state ensures safe partial updates.
  • Overall, these revisions reduce the likelihood of stale or incorrect state updates.
apps/web/app/[locale]/timesheet/[memberId]/components/AddTaskModal.tsx (2)

131-131: Explicitly mapping taskId in the payload.

Mirroring this assignment clarifies which field is being used for timesheet creation. This small addition reduces confusion in the codebase.


135-135: Immediate modal closure upon success.

Closing the modal right after creating timesheets helps maintain a clear user flow without extra steps.

@Innocent-Akim Innocent-Akim added bug Something isn't working feature Ever Teams Improvement Improvement labels Jan 6, 2025
@evereq evereq merged commit bfb5c25 into develop Jan 6, 2025
13 checks passed
@evereq evereq deleted the fix/timesheet-update-create-logic branch January 6, 2025 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Ever Teams feature Improvement Improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bugs] Timesheets | Non-functional Bulk Reject
2 participants