-
Notifications
You must be signed in to change notification settings - Fork 74
[Feat]: Create RejectSelectedModal Component #3233
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
Conversation
…ries with a reason
WalkthroughA new React functional component, Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 handlingWhile the button configuration structure is well-organized, the styling could be improved:
- Extract hardcoded colors like
#2932417c
into CSS variables or a theme configuration- Consider using Tailwind's color palette instead of hex values for better consistency
- 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:
- Using CSS variables to store header heights
- Using React refs to calculate dynamic heights
- 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:
- Explain why this URL is relevant (e.g., "Reference implementation for timesheet layout")
- Remove sensitive information (organizationId)
- 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:
- Extracting the search functionality into a separate SearchBar component
- Adding debounce to the search input to prevent excessive re-renders
- 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 propThe 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 classesThe className can be simplified by:
- Removing redundant
h-[auto]
as it's the default behavior- 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 statementsDebug 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 messagesThe 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 codeRemove 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 maintainabilityThe component is quite large and handles multiple responsibilities. Consider breaking it down into smaller, more focused components:
- TimeRangeSelector for date and time inputs
- BillableToggle for the billable switch
- TaskSelectionForm for task-related fields
- 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 propThe 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 componentThe 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 constantThe 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
📒 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:
- TimesheetAction provides the rejection button with proper configuration
- When clicked, it triggers the onClick callback with "Rejected" status
- 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.
apps/web/app/[locale]/timesheet/[memberId]/components/RejectSelectedModal.tsx
Outdated
Show resolved
Hide resolved
apps/web/app/[locale]/timesheet/[memberId]/components/RejectSelectedModal.tsx
Outdated
Show resolved
Hide resolved
apps/web/app/[locale]/timesheet/[memberId]/components/RejectSelectedModal.tsx
Outdated
Show resolved
Hide resolved
apps/web/app/[locale]/timesheet/[memberId]/components/RejectSelectedModal.tsx
Outdated
Show resolved
Hide resolved
apps/web/app/[locale]/timesheet/[memberId]/components/RejectSelectedModal.tsx
Outdated
Show resolved
Hide resolved
apps/web/app/[locale]/timesheet/[memberId]/components/TimesheetFilterDate.tsx
Show resolved
Hide resolved
apps/web/app/[locale]/timesheet/[memberId]/components/TimesheetFilterDate.tsx
Show resolved
Hide resolved
apps/web/app/[locale]/timesheet/[memberId]/components/TimesheetFilterDate.tsx
Outdated
Show resolved
Hide resolved
apps/web/app/[locale]/timesheet/[memberId]/components/TimesheetFilterDate.tsx
Outdated
Show resolved
Hide resolved
apps/web/lib/features/integrations/calendar/table-time-sheet.tsx
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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 maintainabilityA few suggestions to improve the styling implementation:
- Consider using CSS variables for the height value instead of hardcoding
h-[50px]
- 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
📒 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
:
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:
…ries with a reason
Description
Please include a summary of the changes and the related issue.
Type of Change
Checklist
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
RejectSelectedModal
for confirming rejection of selected entries, including a textarea for inputting rejection reasons.timeSheetStatus
in theAddManualTimeModal
to adapt the modal based on timesheet context.Bug Fixes
TimesheetFilterDate
.UI Enhancements
TimeSheet
component.