Skip to content

Conversation

Innocent-Akim
Copy link
Contributor

@Innocent-Akim Innocent-Akim commented Nov 6, 2024

…ries with a reason

Description

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

    • Introduced a RejectSelectedModal for confirming rejection of selected entries, including a textarea for inputting rejection reasons.
    • Enhanced button functionality in the timesheet with dynamic actions for 'Approved', 'Rejected', and 'Pending' statuses.
    • Added optional property timeSheetStatus in the AddManualTimeModal to adapt the modal based on timesheet context.
  • Bug Fixes

    • Improved styling consistency across components, particularly in the TimesheetFilterDate.
  • UI Enhancements

    • Updated component layouts and styles for better visual presentation and user experience across various components.
    • Enhanced visual separation of content within the TimeSheet component.

Copy link
Contributor

coderabbitai bot commented Nov 6, 2024

Walkthrough

A new React functional component, RejectSelectedModal, has been added to manage the rejection of selected timesheet entries. This modal includes props for visibility and a close function, and it features a textarea for inputting rejection reasons. Additionally, the TimesheetAction component has been updated to handle button actions more dynamically, while styling adjustments have been made across various components, including the TimesheetFilterDate and DataTableTimeSheet. These changes enhance the user interface and functionality related to timesheet management.

Changes

File Change Summary
apps/web/app/[locale]/timesheet/[memberId]/components/RejectSelectedModal.tsx Introduced RejectSelectedModal component with props for visibility and close function, includes textarea for rejection reasons.
apps/web/app/[locale]/timesheet/[memberId]/components/TimesheetAction.tsx Updated getTimesheetButtons function to include onClick parameter and action property for button configurations.
apps/web/app/[locale]/timesheet/[memberId]/components/TimesheetFilterDate.tsx Adjusted class names for styling consistency and modified hover text colors for buttons.
apps/web/app/[locale]/timesheet/[memberId]/components/index.tsx Added export for RejectSelectedModal and made minor formatting adjustments to TimesheetAction export.
apps/web/app/[locale]/timesheet/[memberId]/page.tsx Enhanced UI with updated class names and added border/rounded corners for better content separation.
apps/web/lib/features/integrations/calendar/table-time-sheet.tsx Integrated RejectSelectedModal and added state management for modal visibility; updated button handling logic.
apps/web/lib/features/manual-time/add-manual-time-modal.tsx Added timeSheetStatus property to interface and modified rendering logic based on status.

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • Cedric921
  • evereq

Poem

🐰 In a modal bright, with reasons to share,
A click on "Reject," shows we care.
With buttons in hand, and styles so neat,
Timesheet entries, we now can defeat!
So hop on this change, let's make it right,
For every entry, we’ll shine a light! 🌟


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 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: 11

🧹 Outside diff range and nitpick comments (13)
apps/web/app/[locale]/timesheet/[memberId]/components/TimesheetAction.tsx (1)

31-43: Consider extracting color values and improving dark mode handling

While the button configuration structure is well-organized, the styling could be improved:

  1. Extract hardcoded colors like #2932417c into CSS variables or a theme configuration
  2. Consider using Tailwind's color palette instead of hex values for better consistency
  3. Implement a more systematic approach to dark mode styling

Example refactor:

- className="!text-[#2932417c] dark:!text-gray-400 rounded"
+ className="!text-gray-600/50 dark:!text-gray-400 rounded"
apps/web/app/[locale]/timesheet/[memberId]/page.tsx (3)

141-141: Consider using CSS variables for the height calculation.

The magic number 291px in the height calculation (calc(100vh-_291px)) could cause maintenance issues. Consider:

  1. Using CSS variables to store header heights
  2. Using React refs to calculate dynamic heights
  3. Adding a comment explaining the calculation

Example using CSS variables:

-<div className='h-[calc(100vh-_291px)] mt-3 overflow-y-auto border border-gray-200 rounded-lg dark:border-gray-800'>
+<div className='h-[calc(100vh-var(--header-height)-var(--filters-height))] mt-3 overflow-y-auto border border-gray-200 rounded-lg dark:border-gray-800'>

175-175: Improve documentation and remove sensitive information.

The URL comment should:

  1. Explain why this URL is relevant (e.g., "Reference implementation for timesheet layout")
  2. Remove sensitive information (organizationId)
  3. Consider moving to project documentation if it's a long-term reference
-// https://demo.gauzy.co/#/pages/employees/timesheets/daily?organizationId=e4a6eeb6-3f13-4712-b880-34aa9ef1dd2f&date=2024-11-02&date_end=2024-11-02&unit_of_time=day&is_custom_date=false
+// Reference implementation: https://demo.gauzy.co/#/pages/employees/timesheets/daily

Line range hint 1-175: Consider component decomposition and search optimization.

The TimeSheet component has grown to handle multiple responsibilities. Consider:

  1. Extracting the search functionality into a separate SearchBar component
  2. Adding debounce to the search input to prevent excessive re-renders
  3. Moving the ViewToggleButton to a separate file since it's a reusable component
apps/web/lib/features/manual-time/add-manual-time-modal.tsx (6)

Line range hint 19-31: Update interface documentation to include the new timeSheetStatus prop

The interface documentation needs to be updated to include the newly added timeSheetStatus prop in the JSDoc comments.

Add the following to the interface documentation:

 * @property {boolean} isOpen - Indicates whether the modal is open or closed.
 * @property {"AddManuelTime" | "AddTime"} params - Determines the context in which the modal is used, either "AddManuelTime" for the Add Manuel Time view or "AddTime" for the   Add time.
 * @property {() => void} closeModal - Callback function to be called to close the modal.
+* @property {'ManagerTimesheet' | 'TeamMemberTimesheet'} [timeSheetStatus] - Optional prop to determine the context of the timesheet view.

204-204: Optimize modal styling classes

The className can be simplified by:

  1. Removing redundant h-[auto] as it's the default behavior
  2. Consolidating width classes
-className="bg-light--theme-light dark:bg-dark--theme-light p-5 rounded-xl w-full md:w-40 md:min-w-[24rem] h-[auto] justify-start"
+className="bg-light--theme-light dark:bg-dark--theme-light p-5 rounded-xl w-full md:min-w-[24rem] justify-start"

Line range hint 283-289: Remove debug console.log statements

Debug console.log statements should be removed before merging to production.

  const handleSelectedValuesChange = (values: { [key: string]: Item | null }) => {
-   console.log(values);
  };

  const handleChange = (field: string, selectedItem: Item | null) => {
-   console.log(`Field: ${field}, Selected Item:`, selectedItem);
  };

Line range hint 89-108: Refactor time validation logic and internationalize error messages

The time validation logic could be extracted into a separate utility function for better maintainability and reusability. Additionally, error messages should be internationalized using the translation system.

Consider refactoring like this:

const validateTimeRange = (startTime: string, endTime: string): boolean => {
  return endTime > startTime;
};

const handleSubmit = useCallback(
  (e: FormEvent<HTMLFormElement>) => {
    e.preventDefault();

    if (!date || !startTime || !endTime || !team || !taskId) {
      setErrorMsg(t('manualTime.errors.REQUIRED_FIELDS'));
      return;
    }

    if (!validateTimeRange(startTime, endTime)) {
      setErrorMsg(t('manualTime.errors.INVALID_TIME_RANGE'));
      return;
    }

    // ... rest of the submit logic
  },
  [/* ... dependencies ... */]
);

Line range hint 291-299: Remove commented out code

Remove the commented out team selection code block as it's no longer needed.

- {/* <div className="">
-   <label className="block text-gray-500 mb-1">
-     {t('manualTime.TEAM')}<span className="text-[#de5505e1] ml-1">*</span>
-   </label>
-   {
-     activeTeam ?
-       <SelectItems ... />
-       : <></>
-   }
- </div> */}

Line range hint 1-516: Consider breaking down the component for better maintainability

The component is quite large and handles multiple responsibilities. Consider breaking it down into smaller, more focused components:

  1. TimeRangeSelector for date and time inputs
  2. BillableToggle for the billable switch
  3. TaskSelectionForm for task-related fields
  4. DescriptionField for the description textarea

This would improve maintainability and make the code more testable.

Would you like me to provide an example of how to break down this component?

apps/web/lib/features/integrations/calendar/table-time-sheet.tsx (3)

232-234: Consider adding onReject callback prop

The modal integration looks good, but consider adding an onReject callback prop to handle the rejection action when confirmed.

 {<RejectSelectedModal
     closeModal={closeModal}
-    isOpen={isOpen} />}
+    isOpen={isOpen}
+    onReject={(reason: string) => {
+        // Handle rejection with reason
+        closeModal();
+    }} />}

265-271: Consider memoizing the Badge component

The Badge component with static content could be memoized to prevent unnecessary re-renders.

+ const TimesheetBadge = React.memo(() => (
+     <Badge variant={'outline'} className="flex items-center gap-x-2 h-[25px] rounded-md bg-[#E4E4E7] dark:bg-gray-800">
+         <span className="text-[#5f5f61]">Total</span>
+         <span className="text-[#868688]">24:30h</span>
+     </Badge>
+ ));

  // Replace the inline Badge with the memoized component
- <Badge variant={'outline'} className="flex items-center gap-x-2 h-[25px] rounded-md bg-[#E4E4E7] dark:bg-gray-800">
-     <span className="text-[#5f5f61]">Total</span>
-     <span className="text-[#868688]">24:30h</span>
- </Badge>
+ <TimesheetBadge />

279-280: Consider extracting styles to a constant

The inline styles and className could be organized better for reusability and maintainability.

+ const getTaskItemStyles = (status: StatusType) => ({
+   style: { backgroundColor: statusColor(status).bgOpacity, borderBottomColor: statusColor(status).bg },
+   className: clsxm(
+     "flex items-center border-b border-b-gray-200 dark:border-b-gray-600 space-x-4 p-1 h-[60px]"
+   )
+ });

- style={{ backgroundColor: statusColor(status).bgOpacity, borderBottomColor: statusColor(status).bg }}
- className={clsxm("flex items-center border-b border-b-gray-200 dark:border-b-gray-600 space-x-4 p-1 h-[60px]")}
+ {...getTaskItemStyles(status)}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a48a46a and c4093b5.

📒 Files selected for processing (7)
  • apps/web/app/[locale]/timesheet/[memberId]/components/RejectSelectedModal.tsx (1 hunks)
  • apps/web/app/[locale]/timesheet/[memberId]/components/TimesheetAction.tsx (1 hunks)
  • apps/web/app/[locale]/timesheet/[memberId]/components/TimesheetFilterDate.tsx (4 hunks)
  • apps/web/app/[locale]/timesheet/[memberId]/components/index.tsx (1 hunks)
  • apps/web/app/[locale]/timesheet/[memberId]/page.tsx (3 hunks)
  • apps/web/lib/features/integrations/calendar/table-time-sheet.tsx (5 hunks)
  • apps/web/lib/features/manual-time/add-manual-time-modal.tsx (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • apps/web/app/[locale]/timesheet/[memberId]/components/index.tsx
🧰 Additional context used
🪛 GitHub Check: Cspell
apps/web/lib/features/integrations/calendar/table-time-sheet.tsx

[warning] 216-216:
Unknown word (cours)


[warning] 222-222:
Unknown word (cours)


[warning] 225-225:
Unknown word (inconnue)

🔇 Additional comments (4)
apps/web/app/[locale]/timesheet/[memberId]/components/TimesheetAction.tsx (2)

29-29: LGTM! Function signature enhancement improves component flexibility

The addition of the onClick callback parameter with proper typing enhances the component's reusability while maintaining type safety.


29-52: Verify integration with RejectSelectedModal

Let's ensure that the rejection action properly triggers the RejectSelectedModal component.

✅ Verification successful

Integration with RejectSelectedModal is properly implemented

The codebase analysis shows that:

  • RejectSelectedModal is correctly imported and used in the table-time-sheet component
  • TimesheetAction.tsx properly handles the rejection action by passing it through the onClick callback
  • The modal's state (isOpen) and closeModal handler are properly managed

The integration flow works as follows:

  1. TimesheetAction provides the rejection button with proper configuration
  2. When clicked, it triggers the onClick callback with "Rejected" status
  3. The parent component (table-time-sheet) handles this action and shows the RejectSelectedModal
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for RejectSelectedModal usage in relation to this component
rg -l "RejectSelectedModal.*TimesheetAction" --type tsx

# Verify the rejection flow implementation
ast-grep --pattern 'onClick={$_} $$$' apps/web/app/[locale]/timesheet/[memberId]

Length of output: 170


Script:

#!/bin/bash
# Search for RejectSelectedModal usage in the codebase
rg "RejectSelectedModal" --type ts --type tsx -A 5

# Find files containing TimesheetAction
fd "TimesheetAction" --type f

# Look for onClick handlers in timesheet-related files
rg "onClick.*Reject" --type ts --type tsx -A 5

Length of output: 259


Script:

#!/bin/bash
# Search for RejectSelectedModal without file type restrictions
rg "RejectSelectedModal" -A 5

# Look at the content of TimesheetAction.tsx
cat apps/web/app/[locale]/timesheet/[memberId]/components/TimesheetAction.tsx

# Search for rejection-related handlers without file type restrictions
rg "onClick.*Reject|handleReject" -A 5

Length of output: 5544

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

64-65: LGTM: Improved header styling and positioning.

The styling changes enhance the visual hierarchy with proper fixed positioning, z-index, and visual separation using borders and background colors.

apps/web/lib/features/integrations/calendar/table-time-sheet.tsx (1)

59-59: LGTM: Import statements are well-structured

The new imports align with the PR objective of adding rejection functionality.

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: 4

🧹 Outside diff range and nitpick comments (2)
apps/web/app/[locale]/timesheet/[memberId]/components/RejectSelectedModal.tsx (1)

4-10: Add default values for optional props and improve type safety.

While the interface is well-defined, the component could benefit from default values for optional props and stricter type checking.

 export interface IRejectSelectedModalProps {
     isOpen: boolean;
     closeModal: () => void;
     onReject: (reason: string) => void;
-    minReasonLength?: number;
-    maxReasonLength?: number;
+    minReasonLength?: number | undefined;
+    maxReasonLength?: number | undefined;
 }

+const DEFAULT_MIN_LENGTH = 10;
+const DEFAULT_MAX_LENGTH = 120;
apps/web/lib/features/integrations/calendar/table-time-sheet.tsx (1)

257-257: Consider improving style maintainability

A few suggestions to improve the styling implementation:

  1. Consider using CSS variables for the height value instead of hardcoding h-[50px]
  2. The style properties could be consolidated into a single className using your styling system

Consider this approach:

- style={{ backgroundColor: statusColor(status).bgOpacity, borderBottomColor: statusColor(status).bg }}
- className={clsxm("flex items-center border-b border-b-gray-200 dark:border-b-gray-600 space-x-4 p-1 h-[60px]")}
+ className={clsxm(
+   "flex items-center border-b space-x-4 p-1",
+   "border-b-gray-200 dark:border-b-gray-600",
+   "h-[var(--task-item-height)]",
+   statusColor(status).className
+ )}

Add to your CSS:

:root {
  --task-item-height: 60px;
}

Also applies to: 284-285

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c4093b5 and 2988c39.

📒 Files selected for processing (3)
  • apps/web/app/[locale]/timesheet/[memberId]/components/RejectSelectedModal.tsx (1 hunks)
  • apps/web/app/[locale]/timesheet/[memberId]/components/TimesheetFilterDate.tsx (4 hunks)
  • apps/web/lib/features/integrations/calendar/table-time-sheet.tsx (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/web/app/[locale]/timesheet/[memberId]/components/TimesheetFilterDate.tsx
🔇 Additional comments (2)
apps/web/app/[locale]/timesheet/[memberId]/components/RejectSelectedModal.tsx (1)

1-82: Verify component integration with parent components.

Let's ensure the component is properly integrated with parent components and the rejection flow is complete.

apps/web/lib/features/integrations/calendar/table-time-sheet.tsx (1)

232-239: ⚠️ Potential issue

Implement the onReject callback

The onReject callback is currently empty with a "Pending implementation" comment. This is a critical functionality that needs to be implemented to handle the rejection action.

Let's verify if there are any existing rejection handlers in the codebase:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants