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

Bugfix: Add Visit Button in Joined Organizations Filter #3278

Merged

Conversation

gkbishnoi07
Copy link

@gkbishnoi07 gkbishnoi07 commented Jan 14, 2025

What kind of change does this PR introduce?

Bugfix: Ensures the "Visit" button appears for all joined organizations when filtering by "Joined Organizations."

Issue Number:

Fixes #3162

Snapshots/Videos:

issue.3162.mp4

Summary

The issue was caused by a restrictive condition for rendering the "Visit" button. The button only appeared when membershipRequestStatus === 'accepted'. This PR modifies the logic to include all joined organizations by checking the props.isJoined property.

Does this PR introduce a breaking change?
No

Other information
The feature was tested in multiple scenarios to ensure seamless functionality.
Does this PR introduce a breaking change?

No, this PR does not introduce breaking changes.

Summary by CodeRabbit

  • New Features

    • Enhanced Organization Card with additional details, including admins, members, and description.
    • Added organization membership request and join functionality with success notifications.
    • Improved organization display with image, name, description, and address details.
    • Introduced membership status indicators for organizations within the user portal.
    • New TestWrapper component for enhanced testing capabilities.
  • Bug Fixes

    • Updated organization membership status handling to accurately reflect user membership.
    • Refined organization list pagination and display logic for clarity.
  • Documentation

    • Updated component prop descriptions and documentation to reflect new properties.

Copy link
Contributor

coderabbitai bot commented Jan 14, 2025

Walkthrough

The pull request introduces significant changes to the OrganizationCard component and its associated test file. Modifications enhance the component's functionality by adding new properties such as description, admins, members, address, and membership-related statuses. The testing setup has been updated to include necessary context providers like BrowserRouter and I18nextProvider. The changes aim to improve the organization card's rendering and interaction capabilities, particularly in displaying organization details and handling membership actions.

Changes

File Change Summary
src/components/OrganizationCard/OrganizationCard.spec.tsx - Added context providers for testing
- Created TestWrapper component
- Updated i18n initialization
- Modified test props and assertions
src/components/OrganizationCard/OrganizationCard.tsx - Expanded props interface
- Added new mutation functions for membership actions
- Enhanced rendering logic
- Implemented conditional button rendering
src/screens/UserPortal/Organizations/Organizations.tsx - Added isJoined property to organization objects
- Refined organization list handling
- Updated membership status logic
src/components/test-utils/TestWrapper.tsx - Introduced TestWrapper for testing with providers

Assessment against linked issues

Objective Addressed Explanation
Display Visit Button for Joined Organizations [#3162] The logic to display the "Visit" button for joined organizations was not explicitly addressed in the changes.

Possibly related issues

Suggested labels

refactor

Suggested reviewers

  • palisadoes

Poem

🐰 A card of organizations, shiny and bright,
With buttons that dance in the digital light!
Admins and members, now clearly displayed,
A rabbit's delight at the features arrayed!
Code hopping forward with joyful might! 🚀


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

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

Our Pull Request Approval Process

Thanks for contributing!

Testing Your Code

Remember, your PRs won't be reviewed until these criteria are met:

  1. We don't merge PRs with poor code quality.
    1. Follow coding best practices such that CodeRabbit.ai approves your PR.
  2. We don't merge PRs with failed tests.
    1. When tests fail, click on the Details link to learn more.
    2. Write sufficient tests for your changes (CodeCov Patch Test). Your testing level must be better than the target threshold of the repository
    3. Tests may fail if you edit sensitive files. Ask to add the ignore-sensitive-files-pr label if the edits are necessary.
  3. We cannot merge PRs with conflicting files. These must be fixed.

Our policies make our code better.

Reviewers

Do not assign reviewers. Our Queue Monitors will review your PR and assign them.
When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

CONTRIBUTING.md

Read our CONTRIBUTING.md file. Most importantly:

  1. PRs with issues not assigned to you will be closed by the reviewer
  2. Fix the first comment in the PR so that each issue listed automatically closes

Other

  1. 🎯 Please be considerate of our volunteers' time. Contacting the person who assigned the reviewers is not advised unless they ask for your input. Do not @ the person who did the assignment otherwise.
  2. Read the CONTRIBUTING.md file make

Copy link

codecov bot commented Jan 14, 2025

Codecov Report

Attention: Patch coverage is 77.58621% with 13 lines in your changes missing coverage. Please review.

Project coverage is 89.86%. Comparing base (334f0f7) to head (e711424).
Report is 3 commits behind head on develop-postgres.

Files with missing lines Patch % Lines
...c/components/OrganizationCard/OrganizationCard.tsx 81.63% 6 Missing and 3 partials ⚠️
...screens/UserPortal/Organizations/Organizations.tsx 50.00% 0 Missing and 3 partials ⚠️
src/components/test-utils/TestWrapper.tsx 66.66% 1 Missing ⚠️
Additional details and impacted files
@@                  Coverage Diff                  @@
##           develop-postgres    #3278       +/-   ##
=====================================================
+ Coverage              8.56%   89.86%   +81.30%     
=====================================================
  Files                   309      331       +22     
  Lines                  7954     8574      +620     
  Branches               1763     1898      +135     
=====================================================
+ Hits                    681     7705     +7024     
+ Misses                 7196      610     -6586     
- Partials                 77      259      +182     
Flag Coverage Δ
combined 89.86% <77.58%> (?)
jest 8.43% <0.00%> (?)
vitest 89.86% <77.58%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Nitpick comments (4)
src/components/OrganizationCard/OrganizationCard.tsx (1)

189-189: Simplify null checks using optional chaining

The conditional rendering of the address can be simplified by using optional chaining. This enhances readability and reduces complexity.

Apply this diff to simplify the null checks:

-              {address && address.city && (
+              {address?.city && (
🧰 Tools
🪛 Biome (1.9.4)

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

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

src/components/OrganizationCard/OrganizationCard.spec.tsx (2)

57-70: Remove unused props firstName and lastName from test data

The firstName and lastName props are no longer used in the OrganizationCard component as per the updated InterfaceOrganizationCardProps. Removing these props from the test data keeps the tests clean and avoids confusion.

Apply this diff to remove the unused props:

        const props = {
          id: '123',
          image: 'https://via.placeholder.com/80',
-         firstName: 'John',
-         lastName: 'Doe',
          name: 'Sample',
          description: '',
          admins: [],
          members: [],
          address: {
            city: '',
            countryCode: '',
            line1: '',
            postalCode: '',
            state: '',
          },
          membershipRequestStatus: '',
          userRegistrationRequired: false,
          membershipRequests: [],
        };

91-103: Remove unused props firstName and lastName from test data

The firstName and lastName props are no longer used in the OrganizationCard component as per the updated InterfaceOrganizationCardProps. Removing these props from the test data keeps the tests clean and avoids confusion.

Apply this diff to remove the unused props:

        const props = {
          id: '123',
          image: '',
-         firstName: 'John',
-         lastName: 'Doe',
          name: 'Sample',
          description: '',
          admins: [],
          members: [],
          address: {
            city: '',
            countryCode: '',
            line1: '',
            postalCode: '',
            state: '',
          },
          membershipRequestStatus: '',
          userRegistrationRequired: false,
          membershipRequests: [],
        };
src/screens/UserPortal/Organizations/Organizations.tsx (1)

Line range hint 393-420: Refactor repeated mapping logic into a helper function

The mapping logic for organizations is repeated in multiple places with slight variations. Consider refactoring this logic into a helper function to improve code reusability and reduce duplication.

Example refactor:

function mapOrganizations(orgs, membershipStatus, isJoined) {
  return orgs.map((org) => ({
    ...org,
    membershipRequestStatus: membershipStatus,
    isJoined,
  }));
}

// Usage:
const organizations = mapOrganizations(data.organizationsConnection, membershipRequestStatus, false);
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 334f0f7 and c6b5f16.

📒 Files selected for processing (3)
  • src/components/OrganizationCard/OrganizationCard.spec.tsx (3 hunks)
  • src/components/OrganizationCard/OrganizationCard.tsx (1 hunks)
  • src/screens/UserPortal/Organizations/Organizations.tsx (4 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
src/components/OrganizationCard/OrganizationCard.tsx

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

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Check Python Code Style
  • GitHub Check: Test Application
  • GitHub Check: Analyse Code With CodeQL (javascript)
🔇 Additional comments (1)
src/screens/UserPortal/Organizations/Organizations.tsx (1)

250-254: Ensure consistent isJoined property usage

You're correctly adding the isJoined property to the organization objects in different modes. However, ensure that all instances where organizations are mapped include the isJoined property for consistency. This helps in correctly determining the joined status across the application.

Also applies to: 262-268, 277-283

src/components/OrganizationCard/OrganizationCard.tsx Outdated Show resolved Hide resolved
src/components/OrganizationCard/OrganizationCard.tsx Outdated Show resolved Hide resolved
src/components/OrganizationCard/OrganizationCard.tsx Outdated Show resolved Hide resolved
coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 14, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

♻️ Duplicate comments (1)
src/components/OrganizationCard/OrganizationCard.tsx (1)

22-22: ⚠️ Potential issue

Remove hook call outside component.

The useLocalStorage hook is called outside the component, which violates React's rules of hooks.

Remove this line as the hook is already properly used inside the component at line 66.

-useLocalStorage();
🧰 Tools
🪛 GitHub Actions: PR Workflow

[error] Missing TSDoc comment. Component requires TSDoc documentation.

🧹 Nitpick comments (1)
src/components/OrganizationCard/OrganizationCard.tsx (1)

169-177: Simplify address conditional using optional chaining.

The address conditional can be simplified using optional chaining.

-          {address && address.city && (
+          {address?.city && (
             <div className={styles.address}>
               <h6 className="text-secondary">
                 <span className="address-line">{address.line1}, </span>
                 <span className="address-line">{address.city}, </span>
                 <span className="address-line">{address.countryCode}</span>
               </h6>
             </div>
           )}
🧰 Tools
🪛 Biome (1.9.4)

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

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🪛 GitHub Actions: PR Workflow

[error] Missing TSDoc comment. Component requires TSDoc documentation.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c6b5f16 and 441e842.

📒 Files selected for processing (2)
  • src/components/OrganizationCard/OrganizationCard.spec.tsx (3 hunks)
  • src/components/OrganizationCard/OrganizationCard.tsx (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
src/components/OrganizationCard/OrganizationCard.tsx

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

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🪛 GitHub Actions: PR Workflow
src/components/OrganizationCard/OrganizationCard.tsx

[error] Missing TSDoc comment. Component requires TSDoc documentation.

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyse Code With CodeQL (javascript)
🔇 Additional comments (2)
src/components/OrganizationCard/OrganizationCard.tsx (2)

50-50: 🛠️ Refactor suggestion

Follow camelCase naming convention for props.

The prop name isjoined should follow camelCase naming convention.

-  isjoined: boolean;
+  isJoined: boolean;

Also update the prop usage in the component parameters and JSX conditions.

Likely invalid or redundant comment.

🧰 Tools
🪛 GitHub Actions: PR Workflow

[error] Missing TSDoc comment. Component requires TSDoc documentation.


184-195: Verify the Visit button visibility logic.

The PR objective is to fix the Visit button visibility. The current implementation uses isjoined which aligns with the requirement to show the button for all joined organizations.

Let's verify the implementation:

✅ Verification successful

Visit button visibility logic is correctly implemented

The visibility is properly controlled by the isjoined prop, which is set to true for accepted memberships and false otherwise. The implementation aligns with the requirement to show the Visit button only for joined organizations.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify that the Visit button visibility is controlled by isJoined prop
ast-grep --pattern 'isjoined && (
  $$$
  <Button
    $$$
    {t("visit")}
  </Button>
  $$$
)'

Length of output: 97


Script:

#!/bin/bash
# Search for Button components with visit text and isjoined condition
ast-grep --pattern 'isjoined && <Button'

# Search for isjoined prop usage and type definition
rg "isjoined|isJoined" -A 2 -B 2

# Look for the component's interface
ast-grep --pattern 'interface $_ {
  $$$
  isjoined?: $_
  $$$
}'

Length of output: 3291

🧰 Tools
🪛 GitHub Actions: PR Workflow

[error] Missing TSDoc comment. Component requires TSDoc documentation.

src/components/OrganizationCard/OrganizationCard.spec.tsx Outdated Show resolved Hide resolved
src/components/OrganizationCard/OrganizationCard.spec.tsx Outdated Show resolved Hide resolved
src/components/OrganizationCard/OrganizationCard.tsx Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

♻️ Duplicate comments (1)
src/components/OrganizationCard/OrganizationCard.tsx (1)

22-22: ⚠️ Potential issue

Move hook call inside the component.

The useLocalStorage() hook is called outside the component, which violates React's rules of hooks. Hooks must only be called inside React function components.

Remove this line as the hook is already properly used inside the component at line 90.

- useLocalStorage();
🧹 Nitpick comments (2)
src/components/OrganizationCard/OrganizationCard.tsx (2)

72-74: Remove duplicate TSDoc entries.

The documentation contains duplicate @param props and @returns entries.

- * @param props - Properties for the organization card.
- * @returns JSX element representing the organization card.
- * @returns The organization card component.
+ * @returns The organization card component.

193-201: Use optional chaining for address checks.

The address property checks can be simplified using optional chaining.

-          {address && address.city && (
+          {address?.city && (
             <div className={styles.address}>
               <h6 className="text-secondary">
                 <span className="address-line">{address.line1}, </span>
                 <span className="address-line">{address.city}, </span>
                 <span className="address-line">{address.countryCode}</span>
               </h6>
             </div>
           )}
🧰 Tools
🪛 Biome (1.9.4)

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

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 441e842 and 75074ca.

📒 Files selected for processing (1)
  • src/components/OrganizationCard/OrganizationCard.tsx (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
src/components/OrganizationCard/OrganizationCard.tsx

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

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Test Application
  • GitHub Check: Analyse Code With CodeQL (javascript)
🔇 Additional comments (1)
src/components/OrganizationCard/OrganizationCard.tsx (1)

50-50: 🛠️ Refactor suggestion

Fix property name casing.

The property isjoined should follow JavaScript camelCase naming convention.

-  isjoined: boolean;
+  isJoined: boolean;

Likely invalid or redundant comment.

src/components/OrganizationCard/OrganizationCard.tsx Outdated Show resolved Hide resolved
src/components/OrganizationCard/OrganizationCard.tsx Outdated Show resolved Hide resolved
coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 14, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/components/OrganizationCard/OrganizationCard.tsx (2)

193-201: Use optional chaining for address properties.

The current condition can be simplified using optional chaining to make it more concise and maintainable.

-          {address && address.city && (
+          {address?.city && (
             <div className={styles.address}>
               <h6 className="text-secondary">
                 <span className="address-line">{address.line1}, </span>
                 <span className="address-line">{address.city}, </span>
                 <span className="address-line">{address.countryCode}</span>
               </h6>
             </div>
           )}
🧰 Tools
🪛 Biome (1.9.4)

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

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


149-170: Enhance error handling in withdrawMembershipRequest.

The error handling in this function could be improved to provide more specific error messages and type safety.

   async function withdrawMembershipRequest(): Promise<void> {
     const membershipRequest = membershipRequests.find(
       (request) => request.user._id === userId,
     );
     try {
       if (!membershipRequest) {
         toast.error(t('MembershipRequestNotFound') as string);
         return;
       }

       await cancelMembershipRequest({
         variables: {
           membershipRequestId: membershipRequest._id,
         },
       });

       toast.success(t('MembershipRequestWithdrawn') as string);
     } catch (error: unknown) {
-      console.error('Failed to withdraw membership request:', error);
-      toast.error(t('errorOccured') as string);
+      if (error instanceof ApolloError) {
+        const errorCode = error.graphQLErrors?.[0]?.extensions?.code;
+        if (errorCode) {
+          toast.error(t(errorCode) as string);
+        } else {
+          toast.error(t('errorOccured') as string);
+        }
+      }
+      console.error('Failed to withdraw membership request:', error);
     }
   }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 75074ca and 16b3a25.

📒 Files selected for processing (2)
  • src/components/OrganizationCard/OrganizationCard.spec.tsx (3 hunks)
  • src/components/OrganizationCard/OrganizationCard.tsx (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
src/components/OrganizationCard/OrganizationCard.tsx

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

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Check Python Code Style
  • GitHub Check: Test Application
  • GitHub Check: Analyse Code With CodeQL (javascript)
🔇 Additional comments (3)
src/components/OrganizationCard/OrganizationCard.spec.tsx (2)

35-48: LGTM! Well-structured test wrapper.

The TestWrapper component correctly provides all required contexts (MockedProvider, I18nextProvider, BrowserRouter) for testing the OrganizationCard component.


73-77: Add test coverage for joined organizations.

The test suite only tests the scenario where isJoined={false}. To ensure the "Visit" button functionality works correctly, add test cases for isJoined={true}.

Also applies to: 106-110

src/components/OrganizationCard/OrganizationCard.tsx (1)

208-219: LGTM! Visit button implementation aligns with PR objectives.

The Visit button is now correctly rendered based on the isJoined prop, which aligns with the PR objectives to display the Visit button for all joined organizations.

src/components/OrganizationCard/OrganizationCard.tsx Outdated Show resolved Hide resolved
@gkbishnoi07
Copy link
Author

@coderabbitai full review

Copy link
Contributor

coderabbitai bot commented Jan 14, 2025

✅ Actions performed

Full review triggered.

@palisadoes
Copy link
Contributor

Please make coderabbit approve your PR. See the error message

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (3)
src/components/OrganizationCard/OrganizationCard.tsx (3)

52-72: Clean up redundant TSDoc documentation.

Remove the duplicate @param props and @returns entries at lines 71-72 as they're already documented above.

 * @param membershipRequests - The list of membership requests with user IDs.
 *
-* @param props - Properties for the organization card.
-* @returns JSX element representing the organization card.
 * @returns The organization card component.
 */

116-145: Enhance error handling in joinOrganization function.

The error handling could be more specific about what went wrong. Consider adding more error codes and corresponding user-friendly messages.

         if (errorCode === 'ALREADY_MEMBER') {
           toast.error(t('AlreadyJoined') as string);
+        } else if (errorCode === 'ORGANIZATION_NOT_FOUND') {
+          toast.error(t('OrganizationNotFound') as string);
+        } else if (errorCode === 'USER_NOT_AUTHORIZED') {
+          toast.error(t('NotAuthorized') as string);
         } else {
           toast.error(t('errorOccured') as string);
         }
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 117-117: src/components/OrganizationCard/OrganizationCard.tsx#L117
Added line #L117 was not covered by tests


[warning] 119-119: src/components/OrganizationCard/OrganizationCard.tsx#L119
Added line #L119 was not covered by tests


[warning] 124-124: src/components/OrganizationCard/OrganizationCard.tsx#L124
Added line #L124 was not covered by tests


[warning] 126-126: src/components/OrganizationCard/OrganizationCard.tsx#L126
Added line #L126 was not covered by tests


[warning] 131-131: src/components/OrganizationCard/OrganizationCard.tsx#L131
Added line #L131 was not covered by tests


[warning] 133-133: src/components/OrganizationCard/OrganizationCard.tsx#L133
Added line #L133 was not covered by tests


[warning] 136-137: src/components/OrganizationCard/OrganizationCard.tsx#L136-L137
Added lines #L136 - L137 were not covered by tests


[warning] 139-139: src/components/OrganizationCard/OrganizationCard.tsx#L139
Added line #L139 was not covered by tests


[warning] 141-141: src/components/OrganizationCard/OrganizationCard.tsx#L141
Added line #L141 was not covered by tests


191-199: Use optional chaining for safer property access.

As suggested by static analysis, use optional chaining to safely access nested address properties.

-          {address && address.city && (
+          {address?.city && (
             <div className={styles.address}>
               <h6 className="text-secondary">
-                <span className="address-line">{address.line1}, </span>
-                <span className="address-line">{address.city}, </span>
-                <span className="address-line">{address.countryCode}</span>
+                <span className="address-line">{address?.line1}, </span>
+                <span className="address-line">{address?.city}, </span>
+                <span className="address-line">{address?.countryCode}</span>
               </h6>
             </div>
           )}
🧰 Tools
🪛 Biome (1.9.4)

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

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 16b3a25 and fb0328a.

📒 Files selected for processing (1)
  • src/components/OrganizationCard/OrganizationCard.tsx (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
src/components/OrganizationCard/OrganizationCard.tsx

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

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🪛 GitHub Check: codecov/patch
src/components/OrganizationCard/OrganizationCard.tsx

[warning] 88-89: src/components/OrganizationCard/OrganizationCard.tsx#L88-L89
Added lines #L88 - L89 were not covered by tests


[warning] 91-92: src/components/OrganizationCard/OrganizationCard.tsx#L91-L92
Added lines #L91 - L92 were not covered by tests


[warning] 94-94: src/components/OrganizationCard/OrganizationCard.tsx#L94
Added line #L94 was not covered by tests


[warning] 97-97: src/components/OrganizationCard/OrganizationCard.tsx#L97
Added line #L97 was not covered by tests


[warning] 102-102: src/components/OrganizationCard/OrganizationCard.tsx#L102
Added line #L102 was not covered by tests


[warning] 107-107: src/components/OrganizationCard/OrganizationCard.tsx#L107
Added line #L107 was not covered by tests


[warning] 112-112: src/components/OrganizationCard/OrganizationCard.tsx#L112
Added line #L112 was not covered by tests


[warning] 117-117: src/components/OrganizationCard/OrganizationCard.tsx#L117
Added line #L117 was not covered by tests


[warning] 119-119: src/components/OrganizationCard/OrganizationCard.tsx#L119
Added line #L119 was not covered by tests


[warning] 124-124: src/components/OrganizationCard/OrganizationCard.tsx#L124
Added line #L124 was not covered by tests


[warning] 126-126: src/components/OrganizationCard/OrganizationCard.tsx#L126
Added line #L126 was not covered by tests


[warning] 131-131: src/components/OrganizationCard/OrganizationCard.tsx#L131
Added line #L131 was not covered by tests


[warning] 133-133: src/components/OrganizationCard/OrganizationCard.tsx#L133
Added line #L133 was not covered by tests


[warning] 136-137: src/components/OrganizationCard/OrganizationCard.tsx#L136-L137
Added lines #L136 - L137 were not covered by tests


[warning] 139-139: src/components/OrganizationCard/OrganizationCard.tsx#L139
Added line #L139 was not covered by tests


[warning] 141-141: src/components/OrganizationCard/OrganizationCard.tsx#L141
Added line #L141 was not covered by tests


[warning] 148-149: src/components/OrganizationCard/OrganizationCard.tsx#L148-L149
Added lines #L148 - L149 were not covered by tests


[warning] 151-151: src/components/OrganizationCard/OrganizationCard.tsx#L151
Added line #L151 was not covered by tests


[warning] 153-154: src/components/OrganizationCard/OrganizationCard.tsx#L153-L154
Added lines #L153 - L154 were not covered by tests


[warning] 157-157: src/components/OrganizationCard/OrganizationCard.tsx#L157
Added line #L157 was not covered by tests


[warning] 163-163: src/components/OrganizationCard/OrganizationCard.tsx#L163
Added line #L163 was not covered by tests


[warning] 165-166: src/components/OrganizationCard/OrganizationCard.tsx#L165-L166
Added lines #L165 - L166 were not covered by tests


[warning] 212-212: src/components/OrganizationCard/OrganizationCard.tsx#L212
Added line #L212 was not covered by tests

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Test Application
🔇 Additional comments (2)
src/components/OrganizationCard/OrganizationCard.tsx (2)

3-20: Well-structured imports and comprehensive interface definition!

The imports are well-organized and the interface is properly typed with all necessary properties for the organization card functionality.

Also applies to: 24-48


206-217: Visit button implementation aligns with PR objectives.

The Visit button's visibility is now correctly controlled by the isJoined prop, which aligns with the PR's goal of fixing the visibility issue in the Joined Organizations filter.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 212-212: src/components/OrganizationCard/OrganizationCard.tsx#L212
Added line #L212 was not covered by tests

src/components/OrganizationCard/OrganizationCard.tsx Outdated Show resolved Hide resolved
src/components/OrganizationCard/OrganizationCard.tsx Outdated Show resolved Hide resolved
@gkbishnoi07
Copy link
Author

Please make coderabbit approve your PR. See the error message

I am resolving every error, but after each commit, new suggestions or potential issues keep appearing

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
src/components/OrganizationCard/OrganizationCard.tsx (4)

52-72: Clean up duplicate TSDoc entries.

The documentation contains duplicate entries that should be removed:

  • Duplicate @param props description
  • Duplicate @returns description

Apply this diff to clean up the documentation:

 /**
  * Component to display an organization's card with its image and owner details.
  * Displays an organization card with options to join or manage membership.
  *
  * Shows the organization's name, image, description, address, number of admins and members,
  * and provides buttons for joining, withdrawing membership requests, or visiting the organization page.
  *
  * @param props - The properties for the organization card.
  * @param id - The unique identifier of the organization.
  * @param name - The name of the organization.
  * @param image - The URL of the organization's image.
  * @param description - A description of the organization.
  * @param admins - The list of admins with their IDs.
  * @param members - The list of members with their IDs.
  * @param address - The address of the organization including city, country code, line1, postal code, and state.
  * @param membershipRequestStatus - The status of the membership request (accepted, pending, or empty).
  * @param userRegistrationRequired - Indicates if user registration is required to join the organization.
  * @param membershipRequests - The list of membership requests with user IDs.
- *
- * @param props - Properties for the organization card.
- * @returns JSX element representing the organization card.
  * @returns The organization card component.
  */

193-201: Use optional chaining for safer property access.

The address property access could be safer using optional chaining to prevent potential runtime errors.

Apply this diff:

-          {address && address.city && (
+          {address?.city && (
             <div className={styles.address}>
               <h6 className="text-secondary">
-                <span className="address-line">{address.line1}, </span>
-                <span className="address-line">{address.city}, </span>
-                <span className="address-line">{address.countryCode}</span>
+                <span className="address-line">{address?.line1}, </span>
+                <span className="address-line">{address?.city}, </span>
+                <span className="address-line">{address?.countryCode}</span>
               </h6>
             </div>
           )}
🧰 Tools
🪛 Biome (1.9.4)

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

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


221-241: Consider using enum or constants for membership status.

The membership status checks use string literals which could lead to maintenance issues. Consider defining an enum or constants for the status values.

Add this at the top of the file:

enum MembershipStatus {
  PENDING = 'pending',
  ACCEPTED = 'accepted',
  NONE = ''
}

Then update the conditions:

-      {membershipRequestStatus === 'pending' && (
+      {membershipRequestStatus === MembershipStatus.PENDING && (
         // ... Button component
       )}

-      {membershipRequestStatus === '' && (
+      {membershipRequestStatus === MembershipStatus.NONE && (
         // ... Button component
       )}

147-170: Improve error handling in withdrawMembershipRequest.

The error handling in the withdrawMembershipRequest function could be more specific about the type of error that occurred.

Apply this diff:

   async function withdrawMembershipRequest(): Promise<void> {
     const membershipRequest = membershipRequests.find(
       (request) => request.user._id === userId,
     );
     try {
       if (!membershipRequest) {
         toast.error(t('MembershipRequestNotFound') as string);
         return;
       }

       await cancelMembershipRequest({
         variables: {
           membershipRequestId: membershipRequest._id,
         },
       });

       toast.success(t('MembershipRequestWithdrawn') as string);
     } catch (error: unknown) {
-      if (process.env.NODE_ENV === 'development') {
-        console.error('Failed to withdraw membership request:', error);
+      if (error instanceof ApolloError) {
+        const errorCode = error.graphQLErrors?.[0]?.extensions?.code;
+        if (errorCode) {
+          toast.error(t(`errors.${errorCode}`) as string);
+        } else {
+          toast.error(t('errorOccured') as string);
+        }
+        if (process.env.NODE_ENV === 'development') {
+          console.error('Failed to withdraw membership request:', error);
+        }
       }
-      toast.error(t('errorOccured') as string);
     }
   }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fb0328a and 06e0030.

📒 Files selected for processing (1)
  • src/components/OrganizationCard/OrganizationCard.tsx (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
src/components/OrganizationCard/OrganizationCard.tsx

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

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Test Application
  • GitHub Check: Check Python Code Style
  • GitHub Check: Analyse Code With CodeQL (javascript)

@palisadoes
Copy link
Contributor

Please make code rabbit approve your PR

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (4)
src/components/OrganizationCard/OrganizationCard.tsx (3)

208-216: Use optional chaining for nested object access.

The condition address && address.city can be simplified using optional chaining to make the code more concise and maintainable.

-          {address && address.city && (
+          {address?.city && (
🧰 Tools
🪛 Biome (1.9.4)

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

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


147-156: Simplify error handling logic.

The type assertion error as ApolloError is redundant since you're already checking if the error is an instance of Error. Consider simplifying the error handling.

-      if (error instanceof Error) {
-        const apolloError = error as ApolloError;
-        const errorCode = apolloError.graphQLErrors?.[0]?.extensions?.code;
+      if (error instanceof ApolloError) {
+        const errorCode = error.graphQLErrors?.[0]?.extensions?.code;

116-126: Improve error handling in useEffect.

The error handling in the useEffect hook could be more specific. Instead of logging to console in production, consider adding error boundaries or more specific error handling.

   useEffect(() => {
     try {
-      // Use the custom hook to retrieve the userId
-      const id = getItem('userId'); // Adjust this line based on your actual localStorage key
+      const id = getItem('userId');
       setUserId(id);
     } catch (error) {
-      console.error('Failed to access localStorage:', error);
       setUserId(null); // Handle gracefully if localStorage is not available
-      toast.error('Failed to access user data');
+      toast.error(t('failedToAccessUserData') as string);
     }
   }, [getItem]);
src/components/OrganizationCard/OrganizationCard.spec.tsx (1)

198-219: Add edge case tests for address rendering.

The address rendering test should include edge cases where some address fields are missing.

it('should handle partial address information', () => {
  const props = {
    ...defaultProps,
    address: {
      city: 'Test City',
      countryCode: '',  // Missing country code
      line1: '',        // Missing line1
      postalCode: '',   // Missing postal code
      state: '',        // Missing state
    },
  };

  render(
    <TestWrapper mocks={successMocks}>
      <OrganizationCard isJoined={false} {...props} />
    </TestWrapper>
  );

  expect(screen.getByText(/Test City/)).toBeInTheDocument();
  expect(screen.queryByText(/,\s*,/)).not.toBeInTheDocument(); // Should not show consecutive commas
});
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 06e0030 and 8947da3.

📒 Files selected for processing (3)
  • src/components/OrganizationCard/OrganizationCard.spec.tsx (1 hunks)
  • src/components/OrganizationCard/OrganizationCard.tsx (1 hunks)
  • src/components/test-utils/TestWrapper.tsx (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: PR Workflow
src/components/test-utils/TestWrapper.tsx

[error] No TSDoc comment found in file. Documentation is required.

🪛 Biome (1.9.4)
src/components/OrganizationCard/OrganizationCard.tsx

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

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyse Code With CodeQL (javascript)
🔇 Additional comments (1)
src/components/OrganizationCard/OrganizationCard.tsx (1)

223-234: Verify button visibility logic aligns with PR objectives.

The PR's objective is to fix the "Visit" button visibility in joined organizations. The current implementation correctly uses the isJoined prop to determine visibility, which aligns with the PR objectives.

Let's verify the implementation with this script:

✅ Verification successful

Different implementations are intentionally context-specific

The different button visibility logic between the main OrganizationCard (isJoined) and UserPortal OrganizationCard (membershipRequestStatus === 'accepted') is intentional, as they serve different contexts. The main component is for general organization listing, while the UserPortal version is specifically for the user's organization dashboard. The PR's changes align with its objectives.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the Visit button visibility logic has been updated correctly
# across the codebase

# Check for any remaining instances of the old condition
rg "membershipRequestStatus === 'accepted'" --type ts

Length of output: 184


Script:

#!/bin/bash
# Check both OrganizationCard implementations
echo "=== Main OrganizationCard ==="
cat src/components/OrganizationCard/OrganizationCard.tsx

echo -e "\n=== UserPortal OrganizationCard ==="
cat src/components/UserPortal/OrganizationCard/OrganizationCard.tsx

echo -e "\n=== Check for imports of both components ==="
rg -l "import.*OrganizationCard" --type ts

Length of output: 16459


Script:

#!/bin/bash
# Check the Organizations component to understand usage
echo "=== Organizations.tsx content ==="
cat src/screens/UserPortal/Organizations/Organizations.tsx

# Check for any other files that might use these components
echo -e "\n=== Files containing OrganizationCard usage ==="
rg "OrganizationCard" --type ts -C 2

Length of output: 32688

src/components/test-utils/TestWrapper.tsx Outdated Show resolved Hide resolved
src/components/OrganizationCard/OrganizationCard.tsx Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/components/OrganizationCard/OrganizationCard.tsx (1)

147-156: Improve type safety in error handling.

The type casting of error as ApolloError could be unsafe. Consider checking if the error is an instance of ApolloError first.

-      if (error instanceof Error) {
-        const apolloError = error as ApolloError;
+      if (error instanceof ApolloError) {
+        const apolloError = error;
src/components/OrganizationCard/OrganizationCard.spec.tsx (1)

174-220: Add test coverage for Visit button rendering.

While the rendering tests are good, consider adding a specific test for the Visit button when isJoined is true.

it('should render Visit button when organization is joined', () => {
  render(
    <TestWrapper mocks={successMocks}>
      <OrganizationCard isJoined={true} {...defaultProps} />
    </TestWrapper>
  );
  
  expect(screen.getByText('visit')).toBeInTheDocument();
  expect(screen.getByTestId('manageBtn')).toBeInTheDocument();
});
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8947da3 and 91547bd.

📒 Files selected for processing (2)
  • src/components/OrganizationCard/OrganizationCard.spec.tsx (1 hunks)
  • src/components/OrganizationCard/OrganizationCard.tsx (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
src/components/OrganizationCard/OrganizationCard.tsx

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

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (6)
src/components/OrganizationCard/OrganizationCard.tsx (4)

1-20: LGTM! Comprehensive imports added for enhanced functionality.

The imports are well-organized and include all necessary dependencies for UI components, translations, and GraphQL operations.


24-47: LGTM! Interface properly extended with required properties.

The InterfaceOrganizationCardProps interface has been updated with all necessary properties, including the crucial isJoined property that aligns with the PR objectives.


86-114: LGTM! Hooks and mutations properly initialized.

The component correctly initializes all necessary hooks and GraphQL mutations with proper refetch queries.


221-232: LGTM! Visit button implementation aligns with PR objectives.

The Visit button is now correctly rendered based on the isJoined prop, which fixes the original issue mentioned in the PR objectives.

src/components/OrganizationCard/OrganizationCard.spec.tsx (2)

17-72: LGTM! Comprehensive test setup with proper mocks.

The test setup includes all necessary mocks for hooks, translations, and navigation, providing a solid foundation for testing.


269-368: LGTM! Comprehensive mutation test coverage.

The tests thoroughly cover all membership-related operations, including joining organizations and withdrawing membership requests, with both success and error scenarios.

@gkbishnoi07
Copy link
Author

@coderabbitai full review

Copy link
Contributor

coderabbitai bot commented Jan 15, 2025

✅ Actions performed

Full review triggered.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (6)
src/components/OrganizationCard/OrganizationCard.tsx (3)

206-206: Simplify conditional rendering using optional chaining

At line 206, you can simplify the condition by using optional chaining for better readability.

Apply this diff to simplify the condition:

-          {address && address.city && (
+          {address?.city && (
🧰 Tools
🪛 Biome (1.9.4)

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

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


119-119: Remove unnecessary inline comment

The comment seems to be a placeholder and can be removed to clean up the code.

Apply this diff:

-          const id = getItem('userId'); // Adjust this line based on your actual localStorage key
+          const id = getItem('userId');
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 119-120: src/components/OrganizationCard/OrganizationCard.tsx#L119-L120
Added lines #L119 - L120 were not covered by tests


129-157: Add test coverage for joinOrganization function

The joinOrganization function handles critical logic for joining organizations. The code coverage report indicates that these lines are not covered by tests.

Consider adding unit tests to cover:

  • Joining a public organization (userRegistrationRequired is false)
  • Sending a membership request to a private organization (userRegistrationRequired is true)
  • Error handling and toast notifications
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 129-129: src/components/OrganizationCard/OrganizationCard.tsx#L129
Added line #L129 was not covered by tests


[warning] 131-131: src/components/OrganizationCard/OrganizationCard.tsx#L131
Added line #L131 was not covered by tests


[warning] 136-136: src/components/OrganizationCard/OrganizationCard.tsx#L136
Added line #L136 was not covered by tests


[warning] 138-138: src/components/OrganizationCard/OrganizationCard.tsx#L138
Added line #L138 was not covered by tests


[warning] 143-143: src/components/OrganizationCard/OrganizationCard.tsx#L143
Added line #L143 was not covered by tests


[warning] 145-145: src/components/OrganizationCard/OrganizationCard.tsx#L145
Added line #L145 was not covered by tests


[warning] 148-149: src/components/OrganizationCard/OrganizationCard.tsx#L148-L149
Added lines #L148 - L149 were not covered by tests


[warning] 151-151: src/components/OrganizationCard/OrganizationCard.tsx#L151
Added line #L151 was not covered by tests


[warning] 153-153: src/components/OrganizationCard/OrganizationCard.tsx#L153
Added line #L153 was not covered by tests

src/components/OrganizationCard/OrganizationCard.spec.tsx (3)

150-151: Remove unused props firstName and lastName from defaultProps

The OrganizationCard component no longer uses firstName and lastName props. Including them in defaultProps is unnecessary.

Apply this diff:

         id: '123',
         image: 'https://via.placeholder.com/80',
-        firstName: 'John',
-        lastName: 'Doe',
         name: 'Sample',

237-238: Use translated text in assertions

When asserting button text, use the translated value instead of the translation key to ensure the test reflects the actual UI.

Apply this diff:

          expect(joinButton).toBeInTheDocument();
-         expect(joinButton).toHaveTextContent('joinNow');
+         expect(joinButton).toHaveTextContent('Join Now');

282-283: Use translated text when querying elements

When selecting elements by text, use the translated value rather than the translation key.

Apply this diff to both occurrences:

-          const joinButton = screen.getByText('joinNow');
+          const joinButton = screen.getByText('Join Now');

Also applies to: 301-302

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 334f0f7 and 3833bb8.

📒 Files selected for processing (4)
  • src/components/OrganizationCard/OrganizationCard.spec.tsx (1 hunks)
  • src/components/OrganizationCard/OrganizationCard.tsx (1 hunks)
  • src/components/test-utils/TestWrapper.tsx (1 hunks)
  • src/screens/UserPortal/Organizations/Organizations.tsx (4 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
src/components/test-utils/TestWrapper.tsx

[warning] 42-42: src/components/test-utils/TestWrapper.tsx#L42
Added line #L42 was not covered by tests


[warning] 46-46: src/components/test-utils/TestWrapper.tsx#L46
Added line #L46 was not covered by tests

src/components/OrganizationCard/OrganizationCard.tsx

[warning] 86-86: src/components/OrganizationCard/OrganizationCard.tsx#L86
Added line #L86 was not covered by tests


[warning] 88-89: src/components/OrganizationCard/OrganizationCard.tsx#L88-L89
Added lines #L88 - L89 were not covered by tests


[warning] 91-91: src/components/OrganizationCard/OrganizationCard.tsx#L91
Added line #L91 was not covered by tests


[warning] 94-94: src/components/OrganizationCard/OrganizationCard.tsx#L94
Added line #L94 was not covered by tests


[warning] 97-97: src/components/OrganizationCard/OrganizationCard.tsx#L97
Added line #L97 was not covered by tests


[warning] 102-102: src/components/OrganizationCard/OrganizationCard.tsx#L102
Added line #L102 was not covered by tests


[warning] 107-107: src/components/OrganizationCard/OrganizationCard.tsx#L107
Added line #L107 was not covered by tests


[warning] 112-112: src/components/OrganizationCard/OrganizationCard.tsx#L112
Added line #L112 was not covered by tests


[warning] 116-117: src/components/OrganizationCard/OrganizationCard.tsx#L116-L117
Added lines #L116 - L117 were not covered by tests


[warning] 119-120: src/components/OrganizationCard/OrganizationCard.tsx#L119-L120
Added lines #L119 - L120 were not covered by tests


[warning] 122-124: src/components/OrganizationCard/OrganizationCard.tsx#L122-L124
Added lines #L122 - L124 were not covered by tests


[warning] 129-129: src/components/OrganizationCard/OrganizationCard.tsx#L129
Added line #L129 was not covered by tests


[warning] 131-131: src/components/OrganizationCard/OrganizationCard.tsx#L131
Added line #L131 was not covered by tests


[warning] 136-136: src/components/OrganizationCard/OrganizationCard.tsx#L136
Added line #L136 was not covered by tests


[warning] 138-138: src/components/OrganizationCard/OrganizationCard.tsx#L138
Added line #L138 was not covered by tests


[warning] 143-143: src/components/OrganizationCard/OrganizationCard.tsx#L143
Added line #L143 was not covered by tests


[warning] 145-145: src/components/OrganizationCard/OrganizationCard.tsx#L145
Added line #L145 was not covered by tests


[warning] 148-149: src/components/OrganizationCard/OrganizationCard.tsx#L148-L149
Added lines #L148 - L149 were not covered by tests


[warning] 151-151: src/components/OrganizationCard/OrganizationCard.tsx#L151
Added line #L151 was not covered by tests


[warning] 153-153: src/components/OrganizationCard/OrganizationCard.tsx#L153
Added line #L153 was not covered by tests


[warning] 160-161: src/components/OrganizationCard/OrganizationCard.tsx#L160-L161
Added lines #L160 - L161 were not covered by tests


[warning] 164-164: src/components/OrganizationCard/OrganizationCard.tsx#L164
Added line #L164 was not covered by tests


[warning] 166-167: src/components/OrganizationCard/OrganizationCard.tsx#L166-L167
Added lines #L166 - L167 were not covered by tests


[warning] 170-170: src/components/OrganizationCard/OrganizationCard.tsx#L170
Added line #L170 was not covered by tests


[warning] 176-176: src/components/OrganizationCard/OrganizationCard.tsx#L176
Added line #L176 was not covered by tests


[warning] 179-179: src/components/OrganizationCard/OrganizationCard.tsx#L179
Added line #L179 was not covered by tests


[warning] 181-181: src/components/OrganizationCard/OrganizationCard.tsx#L181
Added line #L181 was not covered by tests


[warning] 227-227: src/components/OrganizationCard/OrganizationCard.tsx#L227
Added line #L227 was not covered by tests

🪛 Biome (1.9.4)
src/components/OrganizationCard/OrganizationCard.tsx

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

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (5)
src/components/OrganizationCard/OrganizationCard.tsx (2)

122-122: Remove console.error in production environment

The console.error statement should be removed or wrapped in a development-only condition to prevent logging errors in production.

Apply this diff:

-          console.error('Failed to access localStorage:', error);
+          if (process.env.NODE_ENV === 'development') {
+            console.error('Failed to access localStorage:', error);
+          }
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 122-124: src/components/OrganizationCard/OrganizationCard.tsx#L122-L124
Added lines #L122 - L124 were not covered by tests


222-233: Conditional rendering of the "Visit" button is correctly implemented

The "Visit" button now properly appears for joined organizations based on the isJoined prop, aligning with the PR objectives.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 227-227: src/components/OrganizationCard/OrganizationCard.tsx#L227
Added line #L227 was not covered by tests

src/screens/UserPortal/Organizations/Organizations.tsx (3)

262-268: LGTM! Well-structured mapping logic

The code properly handles:

  • Optional chaining for nested properties
  • Consistent property assignment
  • Fallback to empty array

Also applies to: 277-283


393-393: LGTM! Clean pagination implementation

The pagination logic is correctly implemented with proper null checks and array slicing.

Also applies to: 421-421


Line range hint 250-283: Verify complete implementation of Visit button fix

While the code adds the isJoined property to support the Visit button visibility fix mentioned in the PR objectives, the implementation appears incomplete:

  1. The property needs to be added to the InterfaceOrganizationCardProps
  2. The OrganizationCard component needs to use this property for rendering the Visit button

Let's verify the OrganizationCard component implementation:

coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 15, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
src/components/OrganizationCard/OrganizationCard.tsx (3)

67-70: Remove duplicate @param and @returns entries in TSDoc.

The documentation contains duplicate entries that should be removed for clarity:

  • Duplicate @param props
  • Duplicate @returns
 * @param membershipRequests - The list of membership requests with user IDs.
 *
- * @param props - Properties for the organization card.
- * @returns JSX element representing the organization card.
 * @returns The organization card component.

146-157: Improve error handling consistency in joinOrganization.

The error handling could be more consistent with the pattern used in withdrawMembershipRequest. Consider adding a development-only console.error and simplifying the error type checking.

     } catch (error: unknown) {
-      if (error instanceof Error) {
-        const apolloError = error as ApolloError;
-        const errorCode = apolloError.graphQLErrors?.[0]?.extensions?.code;
-        if (errorCode === 'ALREADY_MEMBER') {
-          toast.error(t('AlreadyJoined') as string);
-        } else {
-          toast.error(t('errorOccured') as string);
-        }
+      if (process.env.NODE_ENV === 'development') {
+        console.error('Failed to join organization:', error);
+      }
+      const apolloError = error as ApolloError;
+      const errorCode = apolloError.graphQLErrors?.[0]?.extensions?.code;
+      if (errorCode === 'ALREADY_MEMBER') {
+        toast.error(t('AlreadyJoined') as string);
+      } else {
+        toast.error(t('errorOccured') as string);
       }
     }

210-218: Use optional chaining for address check.

The current address check can be simplified using optional chaining for better readability and maintainability.

-          {address && address.city && (
+          {address?.city && (
             <div className={styles.address}>
               <h6 className="text-secondary">
                 <span className="address-line">{address.line1}, </span>
                 <span className="address-line">{address.city}, </span>
                 <span className="address-line">{address.countryCode}</span>
               </h6>
             </div>
🧰 Tools
🪛 Biome (1.9.4)

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

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3833bb8 and e711424.

📒 Files selected for processing (3)
  • src/components/OrganizationCard/OrganizationCard.tsx (1 hunks)
  • src/components/test-utils/TestWrapper.tsx (1 hunks)
  • src/screens/UserPortal/Organizations/Organizations.tsx (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/components/test-utils/TestWrapper.tsx
  • src/screens/UserPortal/Organizations/Organizations.tsx
🧰 Additional context used
🪛 Biome (1.9.4)
src/components/OrganizationCard/OrganizationCard.tsx

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

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Test Application
  • GitHub Check: Analyse Code With CodeQL (javascript)

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

Successfully merging this pull request may close these issues.

2 participants