-
Notifications
You must be signed in to change notification settings - Fork 51
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
3155 bug settings enforce plans how it should work #3161
Conversation
WalkthroughThe pull request introduces several modifications across various components, primarily focusing on enhancing the logic for enforcing daily plans and managing timers. Key changes include the addition of conditions to check for existing plans before allowing timer actions, updates to modal behaviors, and the introduction of loading states during submissions. Additionally, localization files have been updated to include new keys for improved user experience. Overall, these changes aim to refine user interactions with task planning and time tracking functionalities. Changes
Assessment against linked issues
Possibly related PRs
Suggested labels
Suggested reviewers
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (21)
🧰 Additional context used🪛 Biome
🔇 Additional comments (28)
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.
Caution
Inline review comments failed to post
Actionable comments posted: 10
🧹 Outside diff range and nitpick comments (13)
apps/web/lib/components/modal.tsx (2)
31-32
: LGTM: Good defaults, consider grouping related props.The addition of default values for
showCloseIcon
andcloseOnOutsideClick
is a good practice. It ensures backward compatibility and provides clear expectations for the component's behavior.Consider grouping related props together in the destructuring for better readability. For example:
export function Modal({ isOpen, closeModal, customCloseModal, showCloseIcon = true, closeOnOutsideClick = false, // ... other props }: Props) { // ... }
57-82
: LGTM: Improved modal content structure with Dialog.Panel.The addition of
Dialog.Panel
wrapping the modal content is a good improvement. It aligns with Headless UI best practices and provides better semantic structure to the component.For consistency, consider moving the
className
prop fromDialog.Overlay
toDialog.Panel
:<Dialog.Overlay> <Dialog.Panel className={clsxm('flex justify-center items-center flex-col space-y-1 relative', className)} > {/* ... content ... */} </Dialog.Panel> </Dialog.Overlay>This change would make it clearer that the className is applied to the panel content rather than the overlay.
apps/web/lib/components/switch.tsx (1)
133-135
: LGTM: Proper handling of localStorage on toggle disable.The added code correctly removes the
DAILY_PLAN_SUGGESTION_MODAL_DATE
from localStorage when the "Require Daily Plan to Track" feature is disabled. This aligns with the PR objectives by ensuring that the "Plan Today" popup won't appear unnecessarily when the feature is turned off.For improved clarity, consider adding a brief comment explaining the purpose of this localStorage removal:
if (!enabled) { // Clear the daily plan suggestion date when the feature is disabled localStorage.removeItem(DAILY_PLAN_SUGGESTION_MODAL_DATE); }apps/web/app/hooks/features/useStartStopTimerHandler.ts (1)
165-165
: Approved: Improved enforcement logic aligns with PR objectivesThe addition of the
hasPlan
condition in the if statement improves the user experience by allowing users to close the "Plan Today" popup without immediately being forced to provide a plan. This change aligns well with the PR objectives and maintains the enforcement of planning requirements for time tracking.Consider handling the edge case where
hasPlan
is false explicitly. You could add anelse if
statement to handle this scenario, potentially opening a different modal or taking a different action. For example:} else if (requirePlan && hasPlan && !isActiveTaskPlaned) { openEnforcePlannedTaskModal(); } else if (requirePlan && !hasPlan) { // Handle case where plan is required but doesn't exist openSuggestDailyPlanModal(); } else { // ... rest of the existing code }This addition would make the logic more robust and ensure all scenarios are explicitly handled.
apps/web/locales/zh.json (1)
224-225
: LGTM! Consider adding an English translation comment.The addition of the "DELETE_THIS_PLAN" translation is appropriate and correctly placed within the
plan
object. The Chinese translation "删除此计划" accurately represents "Delete this plan" in English.For consistency with some other entries in this file, consider adding an English translation comment:
"ADD_PLAN": "添加计划", -"DELETE_THIS_PLAN": "删除此计划" +"DELETE_THIS_PLAN": "删除此计划" // Delete this planThis can help non-Chinese speaking developers quickly understand the purpose of this translation key.
apps/web/locales/ar.json (1)
220-221
: LGTM! Consider adding a trailing comma for consistency.The changes look good. The addition of the "DELETE_THIS_PLAN" key with its Arabic translation is appropriate and consistent with the existing translations. The trailing comma after "ADD_PLAN" is a good practice for maintainability.
For consistency, consider adding a trailing comma after the new "DELETE_THIS_PLAN" entry as well. This will make future additions easier and improve version control diffs. Here's the suggested change:
"ADD_PLAN": "إضافة خطة", -"DELETE_THIS_PLAN": "احذف هذه الخطة" +"DELETE_THIS_PLAN": "احذف هذه الخطة",apps/web/locales/en.json (1)
220-221
: LGTM! Consider adding a confirmation message.The addition of the "DELETE_THIS_PLAN" key is consistent with the file structure and naming conventions. It provides a clear label for a plan deletion action.
Consider adding a confirmation message for the plan deletion action to prevent accidental deletions. For example:
"plan": { "ADD_PLAN": "Add Plan", - "DELETE_THIS_PLAN": "Delete this plan" + "DELETE_THIS_PLAN": "Delete this plan", + "CONFIRM_DELETE_PLAN": "Are you sure you want to delete this plan?" },apps/web/locales/nl.json (1)
Line range hint
1-1000
: Overall localization file looks good, with minor suggestions for improvement.The localization file is well-structured and consistent overall. However, there are a few areas where small improvements could be made:
Consistency in punctuation: Some entries end with a period while others don't. Consider standardizing this across the file.
Capitalization: There's inconsistent capitalization in some keys. For example, "DELETE_THIS_PLAN" is all caps, while "Add_PLAN" is mixed case. Consider using all caps for all keys to maintain consistency.
Quotation marks: The file uses double quotes consistently, which is good. Ensure this practice is maintained for any future additions.
These are minor suggestions and don't affect the functionality of the localization. They would simply improve the overall consistency and maintainability of the file.
apps/web/locales/pl.json (1)
224-225
: LGTM! Consider adding a period for consistency.The addition of the "DELETE_THIS_PLAN" key with its Polish translation "Usuń ten plan" is appropriate and aligns with the PR objectives. The translation appears to be correct.
For consistency with other entries in this file, consider adding a period at the end of the translation:
- "DELETE_THIS_PLAN": "Usuń ten plan" + "DELETE_THIS_PLAN": "Usuń ten plan."This would match the style of similar entries like "Dodaj plan." on line 224.
apps/web/locales/pt.json (1)
224-225
: LGTM! Consider a minor improvement for consistency.The addition of the new translation key
"DELETE_THIS_PLAN": "Excluir este plano"
is appropriate and correctly placed within theplan
section. The translation appears accurate and aligns well with the existing content.For consistency with other keys in this section, consider capitalizing the entire key:
- "DELETE_THIS_PLAN": "Excluir este plano" + "DELETE_THIS_PLAN": "Excluir este plano"This change is optional but would maintain the naming convention used throughout the file.
apps/web/locales/es.json (1)
220-221
: LGTM! Minor formatting suggestion.The changes look good and add a new translation for deleting a plan. However, there's a minor formatting inconsistency.
Consider adding a comma at the end of line 220 to maintain consistency with other entries in the JSON structure. Here's the suggested change:
"plan": { ... - "FOR_TOMORROW": "Plan de mañana", + "FOR_TOMORROW": "Plan de mañana", "DELETE_THIS_PLAN": "Eliminar este plan" },apps/web/lib/features/user-profile-plans.tsx (1)
357-357
: Inconsistent Translation Key NamingThe translation key
{t('common.plan.DELETE_THIS_PLAN')}
might be inconsistent with other translation keys like{t('common.DELETE')}
and{t('common.CANCEL')}
. For consistency, consider adjusting the translation key.Apply this diff to align the translation key:
-{t('common.plan.DELETE_THIS_PLAN')} +{t('common.DELETE_THIS_PLAN')}apps/web/lib/features/daily-plan/add-task-estimation-hours-modal.tsx (1)
115-117
: Improve readability by using anif
statementUsing chained logical operators for control flow can reduce code readability. Consider replacing the logical operators with an
if
statement for clarity.Apply this diff:
- plan && - plan.workTimePlanned !== workTimePlanned && - (await updateDailyPlan({ workTimePlanned }, plan.id ?? '')); + if (plan && plan.workTimePlanned !== workTimePlanned) { + await updateDailyPlan({ workTimePlanned }, plan.id ?? ''); + }
🛑 Comments failed to post (10)
apps/web/lib/features/daily-plan/suggest-daily-plan-modal.tsx (2)
28-30: 🛠️ Refactor suggestion
Simplify conditional logic and reduce code duplication
The condition
(!requirePlan || (requirePlan && hasPlan))
can be simplified to!requirePlan || hasPlan
. This simplification enhances readability without changing the logic.Additionally, the same condition and action are used in both
if
statements. Combining them can reduce code duplication.Apply this diff to simplify the conditions and merge the code blocks:
const handleCloseModal = useCallback(() => { + if (!requirePlan || hasPlan) { localStorage.setItem(HAS_SEEN_DAILY_PLAN_SUGGESTION_MODAL, currentDate); if (path.split('/')[1] === 'profile') { localStorage.setItem(DAILY_PLAN_SUGGESTION_MODAL_DATE, currentDate); } } closeModal(); }, [closeModal, currentDate, hasPlan, path, requirePlan]);
Also applies to: 32-34
39-44:
⚠️ Potential issueCorrect modal properties to always allow closing
Setting
closeOnOutsideClick
andshowCloseIcon
torequirePlan
means that when a plan is required (requirePlan
is true), the modal can be closed, and when not required, it cannot be closed. This is opposite to the intended functionality described in the PR objectives.According to the objectives, users should always be able to close the "Plan Today" popup, regardless of whether a plan is required. To fix this, set these properties to
true
unconditionally.Apply this diff to correct the modal behavior:
<Modal - closeOnOutsideClick={requirePlan} + closeOnOutsideClick={true} isOpen={isOpen} closeModal={handleCloseModal} - showCloseIcon={requirePlan} + showCloseIcon={true} >📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.closeModal(); }, [closeModal, currentDate, hasPlan, path, requirePlan]); return ( <Modal closeOnOutsideClick={true} isOpen={isOpen} closeModal={handleCloseModal} showCloseIcon={true}
apps/web/lib/features/daily-plan/add-daily-plan-work-hours-modal.tsx (3)
90-90:
⚠️ Potential issueSimplify boolean expression in
disabled
propThe
disabled
prop uses unnecessary boolean literals in ternary expressions. Simplify the expression for better readability.Apply this diff to simplify the boolean expression:
- disabled={loading || (requirePlan ? (hasWorkHours ? false : true) : false)} + disabled={loading || (requirePlan && !hasWorkHours)}This change removes redundant ternary operators and clarifies the logic.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.disabled={loading || (requirePlan && !hasWorkHours)}
🧰 Tools
🪛 Biome
[error] 90-90: Unnecessary use of boolean literals in conditional expression.
Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with(lint/complexity/noUselessTernary)
38-40: 🛠️ Refactor suggestion
Refactor conditional logic for clarity
The chained logical
&&
operators can affect readability. Refactor using anif
statement for better clarity.Apply this diff to refactor the conditional logic:
- plan && - plan.workTimePlanned !== workTimePlanned && - (await updateDailyPlan({ workTimePlanned }, plan.id ?? '')); + if (plan && plan.workTimePlanned !== workTimePlanned) { + await updateDailyPlan({ workTimePlanned }, plan.id ?? ''); + }📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.if (plan && plan.workTimePlanned !== workTimePlanned) { await updateDailyPlan({ workTimePlanned }, plan.id ?? ''); }
33-50: 🛠️ Refactor suggestion
Improve error handling in
handleSubmit
Currently, errors in the
catch
block are logged to the console usingconsole.log(error)
. Consider providing user feedback by displaying an error message to enhance the user experience.Apply this diff to improve error handling:
const handleSubmit = useCallback(async () => { try { setLoading(true); // Update the plan work time only if the user changed it - plan && - plan.workTimePlanned !== workTimePlanned && - (await updateDailyPlan({ workTimePlanned }, plan.id ?? '')); + if (plan && plan.workTimePlanned !== workTimePlanned) { + await updateDailyPlan({ workTimePlanned }, plan.id ?? ''); + } startTimer(); handleCloseModal(); } catch (error) { - console.log(error); + // Display an error message to the user + // Example: set an error state and show it in the UI + console.error('Failed to submit daily plan:', error); } finally { setLoading(false); } }, [handleCloseModal, plan, startTimer, updateDailyPlan, workTimePlanned]);Committable suggestion was skipped due to low confidence.
apps/web/lib/features/user-profile-plans.tsx (2)
96-101: 🛠️ Refactor suggestion
Simplify the Conditional Logic
The condition in the
if
statement can be simplified for better readability. The expressionif (!requirePlan || (requirePlan && hasPlan))
is logically equivalent toif (!requirePlan || hasPlan)
.Apply this diff to simplify the condition:
-if (!requirePlan || (requirePlan && hasPlan)) { +if (!requirePlan || hasPlan) {📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.if (!requirePlan || hasPlan) { window.localStorage.setItem( DAILY_PLAN_SUGGESTION_MODAL_DATE, new Date().toISOString().split('T')[0] ); }
364-371:
⚠️ Potential issueEnsure
plan.id
Is Defined Before DeletionPassing an empty string to
deleteDailyPlan
whenplan.id
is undefined may lead to unintended behavior. It's important to confirm thatplan.id
is defined before attempting to delete the plan.Apply this diff to handle potential undefined
plan.id
:onClick={() => { if (requirePlan) { localStorage.removeItem( DAILY_PLAN_SUGGESTION_MODAL_DATE ); } - deleteDailyPlan(plan.id ?? ''); + if (plan.id) { + deleteDailyPlan(plan.id); + } else { + // Handle the case where plan.id is undefined + console.error('Plan ID is undefined. Unable to delete the plan.'); + } }}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.onClick={() => { if (requirePlan) { localStorage.removeItem( DAILY_PLAN_SUGGESTION_MODAL_DATE ); } if (plan.id) { deleteDailyPlan(plan.id); } else { // Handle the case where plan.id is undefined console.error('Plan ID is undefined. Unable to delete the plan.'); } }}
apps/web/lib/features/daily-plan/add-task-estimation-hours-modal.tsx (3)
495-495:
⚠️ Potential issueEnsure modal can be closed without submitting changes
Passing
closeModalAndSubmit
as thecloseModal
prop to theModal
component forces the submission of changes when the modal is closed. According to the PR objectives, users should be able to close the "Plan Today" popup without being required to submit a plan. Consider passinghandleCloseModal
instead to allow the modal to close without submitting.Apply this diff:
- <Modal isOpen={isOpen} closeModal={closeModalAndSubmit} showCloseIcon> + <Modal isOpen={isOpen} closeModal={handleCloseModal} showCloseIcon>📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.<Modal isOpen={isOpen} closeModal={handleCloseModal} showCloseIcon>
468-472:
⚠️ Potential issueAllow users to skip without submitting changes
The "Skip" button currently calls
closeModalAndSubmit
, which submits changes before closing the modal. To align with the PR objectives—allowing users to close the "Plan Today" popup without being forced to provide a plan—consider changing theonClick
handler tohandleCloseModal
.Apply this diff:
<Button disabled={loading} variant="outline" type="submit" className="py-3 px-5 w-40 rounded-md font-light text-md dark:text-white dark:bg-slate-700 dark:border-slate-600" - onClick={isRenderedInSoftFlow ? closeModalAndSubmit : handleCloseModal} + onClick={handleCloseModal} >📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.disabled={loading} variant="outline" type="submit" className="py-3 px-5 w-40 rounded-md font-light text-md dark:text-white dark:bg-slate-700 dark:border-slate-600" onClick={handleCloseModal}
123-124:
⚠️ Potential issueReplace
console.log
with proper error handlingUsing
console.log(error);
in production code is not recommended as it may expose sensitive information and is not user-friendly. Consider handling the error appropriately, such as displaying an error notification to the user or logging it using a logging service.Apply this diff:
} catch (error) { - console.log(error); + // Handle the error appropriately + showErrorNotification('An error occurred while submitting your changes.'); }Committable suggestion was skipped due to low confidence.
d517bf1
into
3156-bug-planned--the-issue-is-that-tracker-start-tracking-time-without-clicking-start-working
Description
This PR fixes #3155
Type of Change
Checklist
Previous screenshots
Loom
Current screenshots
Loom
Summary by CodeRabbit
Release Notes
New Features
Bug Fixes
Documentation
Chores