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

3155 bug settings enforce plans how it should work #3161

Conversation

CREDO23
Copy link
Contributor

@CREDO23 CREDO23 commented Oct 18, 2024

Description

This PR fixes #3155

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

Loom

Current screenshots

Loom

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced timer functionality with improved conditions for starting and stopping.
    • Added a loading indicator in the daily plan work hours modal for better user feedback.
    • Introduced new hooks for managing team tasks and timer status.
  • Bug Fixes

    • Corrected logic for handling daily plan suggestion modals based on user plans.
  • Documentation

    • Updated localization files to include new translations for deleting plans.
  • Chores

    • Simplified modal behaviors and improved state management across various components.

@CREDO23 CREDO23 added enhancement New feature or request WEB Web app Ever Teams labels Oct 18, 2024
@CREDO23 CREDO23 self-assigned this Oct 18, 2024
@CREDO23 CREDO23 linked an issue Oct 18, 2024 that may be closed by this pull request
Copy link

coderabbitai bot commented Oct 18, 2024

Walkthrough

The 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

File Change Summary
apps/web/app/hooks/features/useStartStopTimerHandler.ts Modified startStopTimerHandler to check hasPlan before verifying if the active task is planned.
apps/web/app/hooks/features/useTimer.ts Updated canRunTimer logic to remove canTrack check; ensured local timer status updates correctly when starting the timer.
apps/web/lib/components/modal.tsx Added closeOnOutsideClick property to Modal component to control closing behavior on outside clicks.
apps/web/lib/components/switch.tsx Introduced DAILY_PLAN_SUGGESTION_MODAL_DATE constant; modified local storage management based on enabled state in RequireDailyPlanToTrack.
apps/web/lib/features/daily-plan/add-daily-plan-work-hours-modal.tsx Added loading state management and improved submission handling in AddDailyPlanWorkHourModal.
apps/web/lib/features/daily-plan/add-task-estimation-hours-modal.tsx Simplified state management and updated submission logic in AddTasksEstimationHoursModal.
apps/web/lib/features/daily-plan/suggest-daily-plan-modal.tsx Integrated useTeamTasks and useTimer hooks; modified local storage management based on plan requirements.
apps/web/lib/features/user-profile-plans.tsx Enhanced logic for managing daily plans and user profile interactions with new hooks and memoization.
apps/web/locales/*.json Updated localization files to include "DELETE_THIS_PLAN" key in various languages.

Assessment against linked issues

Objective Addressed Explanation
Enforce plan requirement for tracking time (Bug #3155)
Allow users to close the 'Plan Today' popup when a plan exists (Bug #3155)
Ensure that the popup appears when no plan exists (Bug #3155)

Possibly related PRs

  • fixbug: fix suggest daily plan modal #3148: Involves modifications to the SuggestDailyPlanModal and the introduction of the HAS_SEEN_DAILY_PLAN_SUGGESTION_MODAL constant, related to daily plan suggestion management.

Suggested labels

bug, Bug fix

Suggested reviewers

  • evereq
  • Cedric921
  • EverTechDevOps

🐰 In the meadow, where plans do bloom,
A timer ticks, dispelling gloom.
With every click, the modal's grace,
Ensures our tasks find their place.
So hop along, let time unwind,
With plans in hand, success we’ll find! 🌼


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 27c6fb8 and 3665230.

📒 Files selected for processing (21)
  • apps/web/app/hooks/features/useStartStopTimerHandler.ts (1 hunks)
  • apps/web/app/hooks/features/useTimer.ts (1 hunks)
  • apps/web/lib/components/modal.tsx (3 hunks)
  • apps/web/lib/components/switch.tsx (2 hunks)
  • apps/web/lib/features/daily-plan/add-daily-plan-work-hours-modal.tsx (3 hunks)
  • apps/web/lib/features/daily-plan/add-task-estimation-hours-modal.tsx (4 hunks)
  • apps/web/lib/features/daily-plan/suggest-daily-plan-modal.tsx (2 hunks)
  • apps/web/lib/features/user-profile-plans.tsx (5 hunks)
  • apps/web/locales/ar.json (1 hunks)
  • apps/web/locales/bg.json (1 hunks)
  • apps/web/locales/de.json (1 hunks)
  • apps/web/locales/en.json (1 hunks)
  • apps/web/locales/es.json (1 hunks)
  • apps/web/locales/fr.json (1 hunks)
  • apps/web/locales/he.json (1 hunks)
  • apps/web/locales/it.json (1 hunks)
  • apps/web/locales/nl.json (1 hunks)
  • apps/web/locales/pl.json (1 hunks)
  • apps/web/locales/pt.json (1 hunks)
  • apps/web/locales/ru.json (1 hunks)
  • apps/web/locales/zh.json (1 hunks)
🧰 Additional context used
🪛 Biome
apps/web/lib/features/daily-plan/add-daily-plan-work-hours-modal.tsx

[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)

🔇 Additional comments (28)
apps/web/lib/components/modal.tsx (3)

18-18: LGTM: New prop addition aligns with PR objectives.

The addition of the closeOnOutsideClick prop is a good implementation to address the issue of users being unable to close the popup. This optional boolean prop provides the flexibility to control whether clicking outside the modal should close it or not.


49-49: LGTM: Effective implementation of conditional close on outside click.

This change successfully implements the ability to close the modal by clicking outside, based on the closeOnOutsideClick prop. The ternary operator provides a concise way to either call closeModal or do nothing, depending on the prop value. This directly addresses the PR objective and improves the user experience.


Line range hint 1-89: Summary: Successful implementation of modal closing functionality.

The changes in this file effectively address the PR objectives by implementing the ability to close the modal by clicking outside. The new closeOnOutsideClick prop provides the necessary flexibility, and the implementation is clean and concise. The modal structure has also been improved with the addition of Dialog.Panel.

A few minor suggestions have been made for further improvement:

  1. Grouping related props in the component definition.
  2. Moving the className prop to Dialog.Panel for consistency.

Overall, these changes significantly improve the user experience and resolve the issue described in the PR objectives.

apps/web/lib/components/switch.tsx (2)

8-8: LGTM: New import added correctly.

The new import DAILY_PLAN_SUGGESTION_MODAL_DATE from @app/constants is correctly placed and will be used in the RequireDailyPlanToTrack component.


Line range hint 1-170: Summary: Changes align well with PR objectives.

The modifications in this file, particularly in the RequireDailyPlanToTrack component, address the PR objectives by:

  1. Properly managing the "Plan Today" popup state when the feature is disabled.
  2. Ensuring that users won't be unnecessarily prompted with the popup when the feature is turned off.

These changes contribute to resolving the issue of users being unable to close the "Plan Today" popup, as described in the PR objectives. The implementation is correct and minimal, focusing on the core functionality without introducing unnecessary complexity.

apps/web/app/hooks/features/useTimer.ts (3)

Line range hint 387-406: LGTM: Enhanced timer start functionality

The modifications to the startTimer function improve the user experience by automatically setting the active task and updating the task status to "In Progress" when the timer is started. This aligns well with the PR objectives of enhancing timer functionality.

To ensure this automatic status change doesn't conflict with existing workflows, please confirm:

  1. Is this automatic status change to "In Progress" intended for all scenarios where the timer is started?
  2. Are there any cases where we wouldn't want the status to change automatically?

Consider adding a comment in the code explaining this behavior for future maintainers.


Line range hint 1-624: LGTM: Overall improvements to timer functionality

The changes in this file successfully address the PR objectives by enhancing the timer functionality, improving user experience, and fixing the issue with the "Plan Today" popup. The modifications are well-implemented and maintain the overall structure of the code.

As a final step, please ensure that all the changes are covered by appropriate unit tests to maintain the reliability of the timer functionality.


268-269: LGTM: Improved flexibility in timer functionality

The modification to canRunTimer logic aligns with the PR objectives by allowing the timer to run even when started from a different source. This change improves flexibility and addresses the issue of users being unable to close the "Plan Today" popup.

To ensure this change doesn't introduce unintended side effects, please run the following verification:

This will help us confirm that removing the canTrack check doesn't affect other parts of the codebase.

✅ Verification successful

To address the issue with the previous verification script, please run the following corrected shell script:


Verification Successful: No additional canTrack usages found

The search confirmed that there are no other occurrences of canTrack related to timer functionality outside of useTimer.ts. This ensures that the removal of the canTrack check does not introduce unintended side effects.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any other occurrences of canTrack in relation to timer functionality

# Search for canTrack usage in timer-related code
rg --type typescript 'canTrack.*timer|timer.*canTrack' -g '!**/useTimer.ts'

Length of output: 112


Script:

# 
#!/bin/bash
# Description: Check for any other occurrences of canTrack in relation to timer functionality

# Search for canTrack usage in timer-related TypeScript files
rg --type ts 'canTrack.*timer|timer.*canTrack' -g '!**/useTimer.ts'

Length of output: 69

apps/web/locales/he.json (1)

220-221: LGTM! New translation added for plan deletion.

The addition of the "DELETE_THIS_PLAN" key with its Hebrew translation "מחק את התוכנית הזו" (Delete this plan) is consistent with the existing entries and aligns well with the PR objectives. This new option will allow users to delete a plan, potentially improving the functionality of the "Plan Today" feature.

apps/web/locales/nl.json (2)

224-225: LGTM: New localization entries added correctly.

The new entries for "ADD_PLAN" and "DELETE_THIS_PLAN" have been added correctly to the "plan" section. They follow the existing format and naming conventions used throughout the file.


Line range hint 1-1000: Final verdict: Changes are approved with minor suggestions for future improvements.

The new localization entries have been added correctly and serve their purpose well. They integrate seamlessly with the existing structure of the file. While there are some minor inconsistencies in the overall file (such as punctuation and capitalization), these don't affect the functionality of the new additions.

For future updates to this file, consider:

  1. Standardizing punctuation usage at the end of entries.
  2. Using consistent capitalization for keys (preferably all caps).
  3. Maintaining the use of double quotes for all entries.

These suggestions will help maintain a clean and consistent localization file as it grows and evolves.

apps/web/locales/bg.json (1)

221-221: LGTM! New translation added for plan deletion.

The addition of the "DELETE_THIS_PLAN" key with its Bulgarian translation "Изтрийте този план" is correct and follows the file's conventions. This new string aligns with the PR objectives by potentially providing a way for users to delete or close the "Plan Today" popup, enhancing the user experience as requested.

apps/web/locales/it.json (2)

224-225: LGTM! New translation added for deleting a plan.

The addition of the new key-value pair "DELETE_THIS_PLAN": "Elimina questo piano" under the plan section is correct and consistent with the existing structure. The translation appears to be appropriate for the given context.


Line range hint 1-1024: Verify the usage and context of the new translation.

While the addition of the new translation "DELETE_THIS_PLAN": "Elimina questo piano" is straightforward and correct, it's important to ensure that this new string is being used appropriately in the application.

To confirm the proper implementation of this new translation, please run the following script:

This will help ensure that the new translation is being used in the correct context and that there are no missing implementations related to the plan deletion functionality.

apps/web/locales/ru.json (2)

Line range hint 1-1006: LGTM: Localization update is consistent with PR objectives

The changes to the Russian localization file are minimal and align well with the PR objectives. The addition of the "DELETE_THIS_PLAN" translation supports the new functionality for plan deletion. The rest of the file remains unchanged, preserving existing translations.


224-225: New translation added for plan deletion

The addition of the "DELETE_THIS_PLAN" translation is consistent with the PR objectives, allowing users to delete a plan. This change enhances the user experience by providing a localized option for plan deletion.

However, I noticed that the "ADD_PLAN" value hasn't changed visibly. Can you confirm if this modification was intentional?

To verify the changes in other language files, please run the following script:

This will help ensure consistency across all language files.

✅ Verification successful

Translations for "DELETE_THIS_PLAN" are consistent across all locales

All language files have been updated with the "DELETE_THIS_PLAN" key, and existing "ADD_PLAN" entries remain consistent. No issues were found during verification.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for similar changes in other language files

# Search for ADD_PLAN and DELETE_THIS_PLAN in all JSON files in the locales directory
echo "Checking ADD_PLAN changes:"
rg --type json '"ADD_PLAN"' apps/web/locales
echo "\nChecking DELETE_THIS_PLAN additions:"
rg --type json '"DELETE_THIS_PLAN"' apps/web/locales

Length of output: 1847

apps/web/locales/es.json (1)

Line range hint 1-1000: Overall structure and consistency look good.

The new entry "DELETE_THIS_PLAN" is consistent with the naming convention and structure used throughout the file. The translations appear to be comprehensive, covering various aspects of the application.

To ensure completeness, consider the following suggestions:

  1. Verify that all features mentioned in the PR objectives have corresponding translations in this file.
  2. Double-check that the "DELETE_THIS_PLAN" functionality is implemented consistently across all supported languages.

To help verify the consistency of the "DELETE_THIS_PLAN" translation across all language files, you can run the following script:

This script will help identify any language files that might be missing the new "DELETE_THIS_PLAN" translation.

✅ Verification successful

✅ Verification Successful

All locale files include the "DELETE_THIS_PLAN" translation, ensuring consistency across all supported languages.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for the presence of "DELETE_THIS_PLAN" in all locale files

# Find all JSON files in the locales directory
locale_files=$(fd -e json . apps/web/locales)

# Check each file for the presence of "DELETE_THIS_PLAN"
for file in $locale_files; do
  if grep -q "DELETE_THIS_PLAN" "$file"; then
    echo "Found in $file"
  else
    echo "Missing in $file"
  fi
done

Length of output: 2415

apps/web/locales/de.json (1)

220-221: LGTM: New translation key added correctly

The new translation key "DELETE_THIS_PLAN" has been added correctly to the "plan" section. The key follows the established naming convention (all caps), and the German translation "Diesen Plan löschen" is appropriate and grammatically correct.

apps/web/locales/fr.json (2)

Line range hint 1-1024: Overall, the changes look good.

The addition of the new translation key "DELETE_THIS_PLAN" is the only change in this file, and it has been implemented correctly. The rest of the file remains unchanged, maintaining the existing structure and translations.


220-221: LGTM! New translation key added correctly.

The new translation key "DELETE_THIS_PLAN" has been added correctly to the French localization file. The key follows the existing naming convention, and the translation "Supprimer ce plan" is appropriate.

To ensure consistency across all language files, let's check if this key has been added to other localization files:

✅ Verification successful

LGTM! The "DELETE_THIS_PLAN" translation key has been consistently added across all localization files.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if the new key exists in other language files
rg --type json '"DELETE_THIS_PLAN"' apps/web/locales

Length of output: 928

apps/web/lib/features/daily-plan/suggest-daily-plan-modal.tsx (2)

16-17: Appropriate use of hooks to retrieve plan and team information

The usage of useTimer and useTeamTasks hooks to obtain hasPlan and activeTeam is correct and aligns with best practices.


23-23: 🛠️ Refactor suggestion

Consider removing unnecessary useMemo for requirePlan

The useMemo hook is not needed here since accessing activeTeam?.requirePlanToTrack is not computationally expensive. Removing useMemo can simplify the code without impacting performance.

Apply this diff to simplify the code:

-	const requirePlan = useMemo(() => activeTeam?.requirePlanToTrack, [activeTeam?.requirePlanToTrack]);
+	const requirePlan = activeTeam?.requirePlanToTrack;

Likely invalid or redundant comment.

apps/web/lib/features/daily-plan/add-daily-plan-work-hours-modal.tsx (2)

26-26: Initialize loading state for submission process

The addition of the loading state using useState(false) is appropriate for managing the loading indicator during asynchronous operations.


94-98: Loading indicator enhances user feedback

Displaying the SpinnerLoader when loading is true provides visual feedback during the submission process, improving the user experience.

apps/web/lib/features/user-profile-plans.tsx (4)

13-20: Appropriate Hook Imports

The added hooks from @app/hooks are correctly imported and are necessary for the component's functionality.


85-87: Correct Use of useMemo for requirePlan Calculation

Using useMemo to memoize the value of requirePlan is appropriate and optimizes performance by avoiding unnecessary recalculations.


223-225: Consistent Calculation of requirePlan

Good job in using useMemo to calculate requirePlan, ensuring that the value is only recalculated when its dependencies change.


378-386: Consistent Use of Translation Keys

The translation keys {t('common.DELETE')} and {t('common.CANCEL')} are used consistently and appropriately.


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.

@CREDO23 CREDO23 changed the base branch from develop to 3156-bug-planned--the-issue-is-that-tracker-start-tracking-time-without-clicking-start-working October 18, 2024 01:49
Copy link

@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.

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 and closeOnOutsideClick 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 from Dialog.Overlay to Dialog.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 objectives

The 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 an else 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 plan

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

  1. Consistency in punctuation: Some entries end with a period while others don't. Consider standardizing this across the file.

  2. 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.

  3. 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 the plan 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 Naming

The 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 an if statement

Using 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 issue

Correct modal properties to always allow closing

Setting closeOnOutsideClick and showCloseIcon to requirePlan 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 issue

Simplify boolean expression in disabled prop

The 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 an if 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 using console.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 expression if (!requirePlan || (requirePlan && hasPlan)) is logically equivalent to if (!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 issue

Ensure plan.id Is Defined Before Deletion

Passing an empty string to deleteDailyPlan when plan.id is undefined may lead to unintended behavior. It's important to confirm that plan.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 issue

Ensure modal can be closed without submitting changes

Passing closeModalAndSubmit as the closeModal prop to the Modal 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 passing handleCloseModal 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 issue

Allow 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 the onClick handler to handleCloseModal.

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 issue

Replace console.log with proper error handling

Using 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.

@Cedric921 Cedric921 merged commit d517bf1 into 3156-bug-planned--the-issue-is-that-tracker-start-tracking-time-without-clicking-start-working Oct 18, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Ever Teams WEB Web app
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] Settings | Enforce plans - how it should work
2 participants