Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[Fix] Public link URL does not work #3146

Merged
merged 2 commits into from
Oct 13, 2024
Merged

[Fix] Public link URL does not work #3146

merged 2 commits into from
Oct 13, 2024

Conversation

paradoxe35
Copy link
Contributor

@paradoxe35 paradoxe35 commented Oct 10, 2024

Description

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

  • New Features
    • Introduced a new Invite component for inviting team members.
    • Added TeamMembersView component for improved rendering of team members.
  • Improvements
    • Enhanced readability and maintainability of several components through code reformatting.
    • Added conditional logic for API response handling based on user authentication status.
    • Improved interactivity with drag-and-drop functionality for team member reordering.
  • Bug Fixes
    • Streamlined state management for team data fetching with the addition of teamsFetching property.

@paradoxe35 paradoxe35 self-assigned this Oct 10, 2024
Eliminated a debug console log for cleaner output. Adjusted UI handling to conditionally render interaction elements only for non-public teams, improving user interface logic. Also refined layout width responsiveness for better-style consistency.
@paradoxe35 paradoxe35 added bug Something isn't working WEB Web app labels Oct 11, 2024
@paradoxe35 paradoxe35 marked this pull request as ready for review October 11, 2024 09:55
Copy link

coderabbitai bot commented Oct 11, 2024

Walkthrough

The changes in this pull request primarily focus on code formatting, organization, and the introduction of new components and state properties across various files. Key modifications include the restructuring of components for improved readability, the addition of a new Invite component for team member invitations, and the introduction of a teamsFetching property in hooks for better state management. Import statements have been consolidated for clarity, and existing functionalities have been preserved while enhancing maintainability.

Changes

File Path Change Summary
apps/web/app/[locale]/page-component.tsx Reformatted MainPage and TaskTimerSection for clarity; consolidated import statements.
apps/web/app/[locale]/team/[teamId]/[profileLink]/page.tsx Replaced TeamMembers with TeamMembersView; added new props for team member management; updated import statements.
apps/web/app/hooks/features/usePublicOrganizationTeams.ts Added teamsFetching property to the return object; reformatted code for consistency.
apps/web/app/hooks/features/useTaskStatistics.ts Adjusted formatting and indentation for improved readability; no logic changes.
apps/web/app/services/client/axios.ts Added APPLICATION_LANGUAGES_CODE import; introduced new conditional logic for handling 401 status codes in the response interceptor.
apps/web/lib/features/team-members-card-view.tsx Added Invite component for user invitations; enhanced rendering logic for team members with drag-and-drop functionality.
apps/web/lib/features/team-members.tsx Refactored TeamMembers to use useMemo for efficiency; created TeamMembersView for rendering logic; updated method signatures.
apps/web/lib/features/team/user-team-card/index.tsx Reformatted UserTeamCard for improved readability; no changes to logic.
apps/web/middleware.ts Updated middleware to use APPLICATION_LANGUAGES_CODE; added new path-checking logic while preserving existing token management functionality.

Assessment against linked issues

Objective Addressed Explanation
Public link should open team view without login (3126) Changes do not address the issue of public link accessibility.

🐰 "In the code, we hop and play,
With imports neat and clear today.
A new invite, a team to grow,
With drag and drop, watch members flow!
For public links, we still must strive,
To make sure all can join and thrive!" 🐇✨


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

@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: 9

🧹 Outside diff range and nitpick comments (5)
apps/web/app/[locale]/team/[teamId]/[profileLink]/page.tsx (1)

94-94: Remove commented-out code.

The commented-out TeamMembers component is no longer necessary as it has been replaced by TeamMembersView. To maintain a clean codebase, it's best to remove this line.

Please remove the following line:

- {/* <TeamMembers publicTeam={publicTeam} /> */}
apps/web/app/hooks/features/usePublicOrganizationTeams.ts (2)

30-91: Approve formatting changes and suggest minor optimization.

The reformatting of loadPublicTeamData improves readability and maintainability without changing its core functionality. The function effectively handles loading public team data and updating relevant states.

Consider this minor optimization to reduce unnecessary state updates:

- const newPublicTeamData = {
-   ...publicTeam,
-   ...res.data
- };
- if (!isEqual(newPublicTeamData, publicTeam)) {
-   setPublicTeam(newPublicTeamData);
- }
+ const newPublicTeamData = { ...publicTeam, ...res.data };
+ if (!isEqual(newPublicTeamData, publicTeam)) {
+   setPublicTeam(newPublicTeamData);
+ }

This change combines the object creation and comparison into a single step, potentially improving performance slightly.

🧰 Tools
🪛 Biome

[error] 77-77: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


77-77: Consider using optional chaining for slight improvement.

The current code task.tags && task.tags?.length is correct, but it can be simplified using optional chaining.

Consider this minor improvement:

- if (task.tags && task.tags?.length) {
+ if (task.tags?.length) {

This change reduces verbosity while maintaining the same functionality.

🧰 Tools
🪛 Biome

[error] 77-77: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

apps/web/app/[locale]/page-component.tsx (1)

36-135: Improved MainPage component structure

The reformatting of the MainPage component enhances code readability while maintaining the existing functionality. The use of ResizablePanelGroup and ResizablePanel components aligns with the PR's objective of improving the layout.

Consider extracting the ResizablePanelGroup and its children into a separate component to further improve the maintainability of the MainPage component.

🧰 Tools
🪛 Biome

[error] 56-56: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

apps/web/lib/features/team-members.tsx (1)

54-54: Rename variable for clarity and consistency

The variable $teamsFetching includes a $ prefix, which may not align with the project's naming conventions and can cause confusion. Unless $ has a specific meaning in this context, consider renaming it for clarity.

Rename $teamsFetching to isTeamsFetching:

- const $teamsFetching = teamsFetching && members.length === 0;
+ const isTeamsFetching = teamsFetching && members.length === 0;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between a73cb5f and f5d6420.

📒 Files selected for processing (9)
  • apps/web/app/[locale]/page-component.tsx (2 hunks)
  • apps/web/app/[locale]/team/[teamId]/[profileLink]/page.tsx (1 hunks)
  • apps/web/app/hooks/features/usePublicOrganizationTeams.ts (2 hunks)
  • apps/web/app/hooks/features/useTaskStatistics.ts (2 hunks)
  • apps/web/app/services/client/axios.ts (2 hunks)
  • apps/web/lib/features/team-members-card-view.tsx (0 hunks)
  • apps/web/lib/features/team-members.tsx (1 hunks)
  • apps/web/lib/features/team/user-team-card/index.tsx (2 hunks)
  • apps/web/middleware.ts (3 hunks)
💤 Files with no reviewable changes (1)
  • apps/web/lib/features/team-members-card-view.tsx
🧰 Additional context used
🪛 Biome
apps/web/app/[locale]/page-component.tsx

[error] 56-56: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

apps/web/app/hooks/features/usePublicOrganizationTeams.ts

[error] 77-77: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

apps/web/app/hooks/features/useTaskStatistics.ts

[error] 183-183: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

apps/web/lib/features/team-members.tsx

[error] 176-182: 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)

apps/web/lib/features/team/user-team-card/index.tsx

[error] 92-96: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (19)
apps/web/app/[locale]/team/[teamId]/[profileLink]/page.tsx (5)

22-27: LGTM! Verify usage of teamsFetching.

The addition of teamsFetching in the destructured return from usePublicOrganizationTeams is a good improvement. This allows for better handling of the loading state.

To ensure teamsFetching is used correctly in the component, please run the following script:

#!/bin/bash
# Description: Verify the usage of teamsFetching in the file.

# Test: Check for usage of teamsFetching
rg --type typescript 'teamsFetching' apps/web/app/\[locale\]/team/\[teamId\]/\[profileLink\]/page.tsx

85-92: LGTM! Verify if TeamMembersView addresses the public link issue.

The replacement of TeamMembers with TeamMembersView and the addition of new props is a significant improvement. It provides better control over the component's behavior and display.

To ensure that these changes contribute to fixing the public link URL issue, please run the following checks:

#!/bin/bash
# Description: Verify TeamMembersView implementation and its relation to public link functionality.

# Test 1: Check TeamMembersView implementation
ast-grep --lang typescript --pattern $'const TeamMembersView = ({ $_ }) => {
  $$$
}'

# Test 2: Search for public link handling in TeamMembersView
rg --type typescript 'public.*link|link.*public' -C 5 | rg 'TeamMembersView'

32-38: LGTM! Verify alignment with public link fix.

The useEffect hook for user redirection remains unchanged, which is good for maintaining existing functionality. However, we should ensure this doesn't interfere with the fix for the public link URL issue.

To verify that this redirection logic doesn't conflict with the public link fix, please check the following:


8-8: LGTM! Verify usage of new imports.

The changes in the import statements look good. The switch from TeamMembers to TeamMembersView and the addition of IssuesView suggest improvements in component structure and view control.

To ensure these changes are correctly implemented throughout the file, please run the following script:

Also applies to: 16-16

✅ Verification successful

Verified! The imports TeamMembersView and IssuesView are correctly used in apps/web/app/[locale]/team/[teamId]/[profileLink]/page.tsx.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of new imports in the file.

# Test: Check for usage of TeamMembersView and IssuesView
rg --type typescript 'TeamMembersView|IssuesView' apps/web/app/\[locale\]/team/\[teamId\]/\[profileLink\]/page.tsx

Length of output: 261


Script:

#!/bin/bash
# Description: Verify the usage of new imports in the file.

# Test: Check for usage of TeamMembersView and IssuesView
rg 'TeamMembersView|IssuesView' 'apps/web/app/[locale]/team/[teamId]/[profileLink]/page.tsx'

Length of output: 274


Line range hint 1-97: Please clarify how these changes address the public link URL issue.

The changes made to this file, including the switch to TeamMembersView and the addition of teamsFetching, are improvements to the component's structure and functionality. However, it's not immediately clear how these changes directly address the issue of the public link URL not working as described in the PR objectives.

Could you please provide more context on how these changes contribute to fixing the public link URL issue? Are there additional changes in other files that work in conjunction with these modifications?

To help understand the full scope of the changes related to the public link functionality, please run the following script:

This will help identify any other relevant changes that might be part of the fix for the public link URL issue.

apps/web/middleware.ts (4)

3-3: LGTM: Import of APPLICATION_LANGUAGES_CODE

The addition of APPLICATION_LANGUAGES_CODE import is appropriate and consistent with its usage in the middleware function. This change improves maintainability by centralizing language code definitions.


38-38: LGTM: Use of APPLICATION_LANGUAGES_CODE in createMiddleware

The use of APPLICATION_LANGUAGES_CODE for the locales parameter is a good practice. It centralizes the definition of supported languages, making it easier to maintain and update in the future.


Line range hint 34-134: LGTM: Overall changes to middleware function

The integration of the new path handling logic with the existing middleware function is well-structured. The placement ensures that certain paths can bypass token checks while maintaining the integrity of the existing authentication logic for protected routes.

To ensure the changes haven't introduced any regressions, please run the following tests:

#!/bin/bash
# Description: Verify the integrity of protected routes and authentication logic

# Test: Check for any changes to PROTECTED_APP_URL_PATHS
rg --type typescript "PROTECTED_APP_URL_PATHS" --glob "!apps/web/middleware.ts"

# Test: Ensure token validation logic is still intact for protected routes
rg --type typescript "TOKEN_COOKIE_NAME|REFRESH_TOKEN_COOKIE_NAME" --glob "!apps/web/middleware.ts"

47-55: ⚠️ Potential issue

Please clarify the purpose of the new path handling logic

The new path handling logic appears to be related to fixing the public link URL issue. However, a few points need clarification:

  1. Could you explain the rationale behind bypassing further middleware processing for these specific paths?
  2. The condition !paths.includes('join') seems broad. Are we certain this won't inadvertently bypass important checks for other routes?

Consider adding a comment to explain the purpose of this logic for future maintainability.

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

apps/web/app/hooks/features/usePublicOrganizationTeams.ts (4)

3-4: LGTM: Import statement formatting improved.

The reformatting of the import statements enhances code readability without affecting functionality.


93-112: LGTM: Formatting improvements in loadPublicTeamMiscData.

The reformatting of loadPublicTeamMiscData enhances readability and maintainability without altering its core functionality. The function effectively handles loading miscellaneous public team data and updating relevant states.


114-122: Approve addition of teamsFetching to the return object.

The inclusion of teamsFetching in the return object of usePublicOrganizationTeams is a positive change. It makes this new state property available to consumers of the hook, which can be crucial for managing loading states and potentially addressing the public link URL issue.


Line range hint 1-122: Summary: Positive changes with potential to address PR objectives.

The changes in this file, particularly the addition of teamsFetching, appear to be part of a larger effort to improve code quality and potentially address the public link URL issue described in the PR objectives. While most changes are formatting improvements, the new teamsFetching state could be key to solving the problem of users being redirected to a login page instead of viewing public content.

To ensure these changes effectively address the PR objectives, please verify the following:

  1. Test the public link URL functionality after these changes.
  2. Confirm that the teamsFetching state is being used correctly to manage loading states and prevent premature redirects.
  3. Update any relevant documentation or comments to reflect the new teamsFetching state.

Consider running the following script to check for any TODO comments related to this issue:

#!/bin/bash
# Description: Search for TODO comments related to public link or team fetching

echo "Searching for relevant TODO comments:"
rg --type-add 'web:*.{ts,tsx,js,jsx}' --type web 'TODO.*public.*link|TODO.*team.*fetch'
🧰 Tools
🪛 Biome

[error] 77-77: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

apps/web/app/services/client/axios.ts (2)

2-2: LGTM. Please clarify the purpose of APPLICATION_LANGUAGES_CODE.

The addition of APPLICATION_LANGUAGES_CODE to the imports is approved. However, could you please explain its role in addressing the public link URL issue? This will help in understanding how it contributes to the fix.


Line range hint 1-180: Summary: Changes address the issue, but clarification needed

The modifications to the apiDirect interceptor appear to address the public link URL issue by preventing unnecessary redirects to the login page. However, to ensure the PR fully resolves the problem:

  1. Please confirm that these changes cover all scenarios mentioned in issue [Bug] Common | Public link URL does not work #3126.
  2. Consider adding comments explaining the logic behind the path checks, especially regarding the 'join' path exclusion.
  3. Verify that this solution doesn't introduce any new issues for other parts of the application.

To ensure no unintended side effects:

#!/bin/bash
# Search for other uses of DEFAULT_APP_PATH to check for potential conflicts
rg --type typescript "DEFAULT_APP_PATH"
apps/web/app/[locale]/page-component.tsx (3)

11-11: Improved import organization

The consolidation of import statements for related components enhances code readability and organization. This change aligns with best practices for import management in React applications.

Also applies to: 32-32


138-169: Improved TaskTimerSection component readability

The TaskTimerSection component has been reformatted, enhancing code readability while preserving its original functionality. The conditional rendering and state management remain intact.


Line range hint 1-169: Alignment with PR objectives

While the code improvements in this file enhance readability and maintainability, they don't appear to directly address the stated PR objective of fixing the public link URL issue (Issue #3126).

Could you please clarify how these changes contribute to resolving the public link URL problem? If the fix is implemented in other files, it would be helpful to highlight those changes or provide additional context.

To verify the implementation of the fix, you can run the following script:

This script will help identify any relevant changes across the codebase that might be related to the public link URL fix.

🧰 Tools
🪛 Biome

[error] 56-56: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

apps/web/lib/features/team-members.tsx (1)

140-140: Verify the use of isMemberActive prop

The active prop is being passed to TeamMembersTableView as isMemberActive. Ensure that isMemberActive correctly represents the member's active status and that user?.isEmailVerified is the appropriate indicator for this. If isEmailVerified does not accurately reflect active membership, consider using a different property.

Run the following script to check where isMemberActive is used and what properties are available on user:

Comment on lines +20 to +28
const { loading, queryCall, loadingRef } = useQuery(getPublicOrganizationTeamsAPI);
const { loading: loadingMiscData, queryCall: queryCallMiscData } = useQuery(getPublicOrganizationTeamsMiscDataAPI);
const { activeTeam, teams, setTeams, teamsFetching } = useOrganizationTeams();
const { setAllTasks } = useTeamTasks();
const { setTaskStatus } = useTaskStatus();
const { setTaskSizes } = useTaskSizes();
const { setTaskPriorities } = useTaskPriorities();
const { setTaskLabels } = useTaskLabels();
const [publicTeam, setPublicTeam] = useAtom(publicactiveTeamState);
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

teamsFetching is not actively used in the codebase.

The property teamsFetching was added but does not appear to be utilized in any active code. Please ensure it is properly integrated or remove it if unnecessary.

🔗 Analysis chain

Approve addition of teamsFetching and verify its usage.

The inclusion of teamsFetching from useOrganizationTeams is a positive change that could help address the public link URL issue. This new state property likely provides better control over the loading state of team data.

To ensure this change is properly utilized, please run the following script to check its usage across the codebase:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of teamsFetching across the codebase

# Search for teamsFetching in TypeScript and JavaScript files
echo "Searching for teamsFetching usage:"
rg --type-add 'web:*.{ts,tsx,js,jsx}' --type web 'teamsFetching'

# Search for loading states related to team fetching
echo "\nSearching for related loading states:"
rg --type-add 'web:*.{ts,tsx,js,jsx}' --type web 'loading.*team|team.*loading'

Length of output: 809

Comment on lines +73 to +80
const paths = location.pathname.split('/').filter(Boolean);
if (
!paths.includes('join') &&
(paths[0] === 'team' || (APPLICATION_LANGUAGES_CODE.includes(paths[0]) && paths[1] === 'team'))
) {
return error.response;
}

Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Duplicate Path Checking Logic Identified.

The path checking logic introduced in apps/web/app/services/client/axios.ts is also present in apps/web/middleware.ts. This duplication can lead to maintenance challenges and potential inconsistencies.

Consider extracting the shared path checking logic into a utility function and refactoring both files to utilize this centralized approach.

🔗 Analysis chain

Approved. Consider refactoring for clarity and provide additional context.

The new conditional check addresses the public link URL issue by preventing redirection to the login page for specific paths. This aligns well with the PR objective. However, the logic could be more readable. Consider refactoring as follows:

const isJoinPath = paths.includes('join');
const isTeamPath = paths[0] === 'team' || (APPLICATION_LANGUAGES_CODE.includes(paths[0]) && paths[1] === 'team');

if (!isJoinPath && isTeamPath) {
  return error.response;
}

Also, please provide additional context:

  1. Why is the 'join' path excluded from this logic?
  2. How does this change ensure that public link URLs work correctly for all scenarios mentioned in the issue?

To verify the impact of this change, let's check for any other occurrences of similar logic:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for similar path checking logic in other files
rg --type typescript -e "pathname.split\\('/'\\)" -e "includes\\('join'\\)" -e "APPLICATION_LANGUAGES_CODE"

Length of output: 265


Script:

#!/bin/bash
# Search for similar path checking logic in TypeScript files
rg --glob '*.ts' --glob '*.tsx' -e "pathname\.split\('/'\)" -e "includes\('join'\)" -e "APPLICATION_LANGUAGES_CODE"

Length of output: 1266

Comment on lines +55 to +58
React.useEffect(() => {
window && window?.localStorage.getItem('conf-fullWidth-mode');
setFullWidth(JSON.parse(window?.localStorage.getItem('conf-fullWidth-mode') || 'true'));
}, [setFullWidth]);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Improve window object access safety

The useEffect hook for setting the fullWidth state directly accesses the window object, which could lead to issues in environments where window is not defined (e.g., server-side rendering).

Consider using optional chaining and nullish coalescing for safer access:

React.useEffect(() => {
  const storedFullWidth = window?.localStorage?.getItem('conf-fullWidth-mode') ?? 'true';
  setFullWidth(JSON.parse(storedFullWidth));
}, [setFullWidth]);

This change ensures that the code works safely in all environments and addresses the static analysis tool's suggestion.

🧰 Tools
🪛 Biome

[error] 56-56: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

Comment on lines +176 to +182
return user_a.timerStatus == 'running' ||
(user_a.timerStatus == 'online' && user_b.timerStatus != 'running') ||
(user_a.timerStatus == 'pause' && user_b.timerStatus !== 'running' && user_b.timerStatus !== 'online') ||
(user_a.timerStatus == 'idle' && user_b.timerStatus == 'suspended') ||
(user_a.timerStatus === undefined && user_b.timerStatus == 'suspended')
? true
: false;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Address the static analysis warning

The static analysis tool Biome has identified an unnecessary use of boolean literals in the conditional expression within sortByWorkStatus. By removing the ternary operator, you adhere to cleaner coding practices and resolve the warning.

🧰 Tools
🪛 Biome

[error] 176-182: 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)


🛠️ Refactor suggestion

Simplify the return statement in sortByWorkStatus

The ternary operator returning true or false is unnecessary since the expression already evaluates to a boolean. Simplify the code by directly returning the expression for improved readability.

Apply this change:

- return user_a.timerStatus == 'running' ||
-     (user_a.timerStatus == 'online' && user_b.timerStatus != 'running') ||
-     (user_a.timerStatus == 'pause' && user_b.timerStatus !== 'running' && user_b.timerStatus !== 'online') ||
-     (user_a.timerStatus == 'idle' && user_b.timerStatus == 'suspended') ||
-     (user_a.timerStatus === undefined && user_b.timerStatus == 'suspended')
-     ? true
-     : false;
+ return user_a.timerStatus == 'running' ||
+     (user_a.timerStatus == 'online' && user_b.timerStatus != 'running') ||
+     (user_a.timerStatus == 'pause' && user_b.timerStatus !== 'running' && user_b.timerStatus !== 'online') ||
+     (user_a.timerStatus == 'idle' && user_b.timerStatus == 'suspended') ||
+     (user_a.timerStatus === undefined && user_b.timerStatus == 'suspended');
📝 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.

Suggested change
return user_a.timerStatus == 'running' ||
(user_a.timerStatus == 'online' && user_b.timerStatus != 'running') ||
(user_a.timerStatus == 'pause' && user_b.timerStatus !== 'running' && user_b.timerStatus !== 'online') ||
(user_a.timerStatus == 'idle' && user_b.timerStatus == 'suspended') ||
(user_a.timerStatus === undefined && user_b.timerStatus == 'suspended')
? true
: false;
return user_a.timerStatus == 'running' ||
(user_a.timerStatus == 'online' && user_b.timerStatus != 'running') ||
(user_a.timerStatus == 'pause' && user_b.timerStatus !== 'running' && user_b.timerStatus !== 'online') ||
(user_a.timerStatus == 'idle' && user_b.timerStatus == 'suspended') ||
(user_a.timerStatus === undefined && user_b.timerStatus == 'suspended');
🧰 Tools
🪛 Biome

[error] 176-182: 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)

Comment on lines +28 to +33
const [members, orderedMembers] = useMemo(() => {
const members = (activeTeam?.members || []).filter((member) => member.employee !== null);
const orderedMembers = [...members].sort((a, b) => (sortByWorkStatus(a, b) ? -1 : 1));

const currentUser = members.find((m) => m.employee.userId === user?.id);
return [members, orderedMembers];
}, [activeTeam]);
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Optimize useMemo dependencies and return value

When using useMemo, it's generally advised to avoid returning multiple values as an array, which can affect readability and performance optimizations. Instead, consider creating separate useMemo hooks for members and orderedMembers. This approach clarifies dependencies and makes the memoization more efficient.

Apply this refactor:

- const [members, orderedMembers] = useMemo(() => {
-     const members = (activeTeam?.members || []).filter((member) => member.employee !== null);
-     const orderedMembers = [...members].sort((a, b) => (sortByWorkStatus(a, b) ? -1 : 1));
-     return [members, orderedMembers];
- }, [activeTeam]);
+ const members = useMemo(() => {
+     return (activeTeam?.members || []).filter((member) => member.employee !== null);
+ }, [activeTeam]);
+ 
+ const orderedMembers = useMemo(() => {
+     return [...members].sort((a, b) => (sortByWorkStatus(a, b) ? -1 : 1));
+ }, [members]);
📝 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.

Suggested change
const [members, orderedMembers] = useMemo(() => {
const members = (activeTeam?.members || []).filter((member) => member.employee !== null);
const orderedMembers = [...members].sort((a, b) => (sortByWorkStatus(a, b) ? -1 : 1));
const currentUser = members.find((m) => m.employee.userId === user?.id);
return [members, orderedMembers];
}, [activeTeam]);
const members = useMemo(() => {
return (activeTeam?.members || []).filter((member) => member.employee !== null);
}, [activeTeam]);
const orderedMembers = useMemo(() => {
return [...members].sort((a, b) => (sortByWorkStatus(a, b) ? -1 : 1));
}, [members]);

Comment on lines +49 to +51
if (a.order && b.order) return a.order > b.order ? -1 : 1;
else return -1;
});
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Handle undefined order property in sorting

The sorting function assumes that both a.order and b.order are defined, but if either is undefined, it could lead to unexpected behavior. Consider adding checks to handle undefined order values to ensure consistent sorting.

Modify the sorting logic:

- if (a.order && b.order) return a.order > b.order ? -1 : 1;
- else return -1;
+ if (a.order != null && b.order != null) {
+     return a.order > b.order ? -1 : 1;
+ } else if (a.order != null) {
+     return -1;
+ } else if (b.order != null) {
+     return 1;
+ } else {
+     return 0;
+ }
📝 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.

Suggested change
if (a.order && b.order) return a.order > b.order ? -1 : 1;
else return -1;
});
if (a.order != null && b.order != null) {
return a.order > b.order ? -1 : 1;
} else if (a.order != null) {
return -1;
} else if (b.order != null) {
return 1;
} else {
return 0;
}
});

Comment on lines +36 to +40
return activeFilter == 'all'
? orderedMembers
: activeFilter == 'idle'
? orderedMembers.filter((m: OT_Member) => m.timerStatus == undefined || m.timerStatus == 'idle')
: orderedMembers.filter((m) => m.timerStatus === activeFilter);
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Ensure consistent use of strict equality operators

The code uses both == and === for equality checks. It's best practice to use strict equality operators (=== and !==) to prevent unexpected type coercion, which can lead to subtle bugs.

Consider updating the equality checks:

- return activeFilter == 'all'
+ return activeFilter === 'all'

- : activeFilter == 'idle'
+ : activeFilter === 'idle'

- (m.timerStatus == undefined || m.timerStatus == 'idle')
+ (m.timerStatus === undefined || m.timerStatus === 'idle')
📝 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.

Suggested change
return activeFilter == 'all'
? orderedMembers
: activeFilter == 'idle'
? orderedMembers.filter((m: OT_Member) => m.timerStatus == undefined || m.timerStatus == 'idle')
: orderedMembers.filter((m) => m.timerStatus === activeFilter);
return activeFilter === 'all'
? orderedMembers
: activeFilter === 'idle'
? orderedMembers.filter((m: OT_Member) => m.timerStatus === undefined || m.timerStatus === 'idle')
: orderedMembers.filter((m) => m.timerStatus === activeFilter);

Comment on lines +93 to +160
switch (true) {
case members.length === 0:
teamMembersView = (
<Container fullWidth={fullWidth}>
<div className="hidden lg:block">
<UserTeamCardSkeletonCard />
<InviteUserTeamCardSkeleton />
</div>
<div className="block lg:hidden">
<UserCard />
<UserCard />
<UserCard />
</div>
</Container>
);
break;
case view === IssuesView.CARDS:
teamMembersView = (
<>
{/* <UserTeamCardHeader /> */}
<Container fullWidth={fullWidth}>
<TeamMembersCardView
teamMembers={members}
currentUser={currentUser}
publicTeam={publicTeam}
teamsFetching={teamsFetching}
/>
</Container>
</>
);
break;
case view === IssuesView.TABLE:
teamMembersView = (
<Container fullWidth={fullWidth}>
<Transition
show={!!currentUser}
enter="transition-opacity duration-75"
enterFrom="opacity-0"
enterTo="opacity-100"
leave="transition-opacity duration-150"
leaveFrom="opacity-100"
leaveTo="opacity-0"
>
<TeamMembersTableView
teamMembers={members}
currentUser={currentUser}
publicTeam={publicTeam}
active={isMemberActive}
/>
</Transition>
</Container>
);
break;

case view == IssuesView.BLOCKS:
teamMembersView = (
<Container fullWidth={fullWidth}>
<TeamMembersBlockView
teamMembers={blockViewMembers}
currentUser={currentUser}
publicTeam={publicTeam}
teamsFetching={teamsFetching}
/>
</Container>
);
break;
default:
teamMembersView = (
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider refactoring the switch(true) statement

Using switch(true) with boolean expressions in case statements can be less readable and harder to maintain. An if-else if chain might be more appropriate for evaluating boolean conditions.

Refactor the switch statement:

- switch (true) {
-     case members.length === 0:
-         // ...
-         break;
-     case view === IssuesView.CARDS:
-         // ...
-         break;
-     case view === IssuesView.TABLE:
-         // ...
-         break;
-     case view == IssuesView.BLOCKS:
-         // ...
-         break;
-     default:
-         // ...
- }
+ if (members.length === 0) {
+     // ...
+ } else if (view === IssuesView.CARDS) {
+     // ...
+ } else if (view === IssuesView.TABLE) {
+     // ...
+ } else if (view === IssuesView.BLOCKS) {
+     // ...
+ } else {
+     // ...
+ }

Committable suggestion was skipped due to low confidence.

@evereq evereq merged commit 1810361 into develop Oct 13, 2024
13 checks passed
@evereq evereq deleted the fix-public-team-link branch October 13, 2024 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working WEB Web app
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] Common | Public link URL does not work
2 participants