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

'Visit' Button Feature Added to Joined Organizations Filter #3232

Open
wants to merge 10 commits into
base: develop-postgres
Choose a base branch
from

Conversation

gkbishnoi07
Copy link

@gkbishnoi07 gkbishnoi07 commented Jan 10, 2025

What kind of change does this PR introduce?
Feature

Issue Number:
Fixes #3162

Did you add tests for your changes?
No

Snapshots/Videos:

issue.3162.mp4

Summary
This PR introduces a 'Visit' button in the Joined Organizations filter.

Enhances the user experience by providing direct navigation to organizations from the filter.
Solves the issue of limited navigation options in the Joined Organizations section.

Does this PR introduce a breaking change?
No

Other information

The feature was tested in multiple scenarios to ensure seamless functionality.

Have you read the contributing guide?
Yes

Summary by CodeRabbit

  • New Features

    • Enhanced organization card with additional details including description, admins, members, and address.
    • Added functionality for users to manage membership requests, including joining and withdrawing from organizations.
    • Introduced clearer membership status indicators for organizations in the user portal.
  • Bug Fixes

    • Implemented improved error handling for organization membership actions.
  • Tests

    • Comprehensive unit tests added for the OrganizationCard component.
    • Enhanced test coverage for various scenarios related to the organization card functionality.

Copy link
Contributor

coderabbitai bot commented Jan 10, 2025

Walkthrough

The pull request introduces comprehensive changes to the OrganizationCard component and its associated test suite. The modifications enhance the component's functionality by adding new properties like description, admins, members, and address, and improving membership request handling. The test suite has been updated to provide more robust coverage, testing various scenarios such as rendering with different membership statuses and interaction with buttons.

Changes

File Change Summary
src/components/OrganizationCard/OrganizationCard.spec.tsx Updated test suite with new imports, restructured tests, added comprehensive test cases for rendering and button interactions
src/components/OrganizationCard/OrganizationCard.tsx Enhanced component with new properties, added membership request handling functions, improved rendering logic
src/screens/UserPortal/Organizations/Organizations.tsx Added isJoined property to organization objects to explicitly track membership status
package.json Updated jest version and managed @testing-library/dom dependency

Assessment against linked issues

Objective Addressed Explanation
Visit Button Visibility [#3162]

Possibly related issues

Possibly related PRs

Suggested reviewers

  • disha1202
  • palisadoes
  • noman2002

Poem

🐰 A card of organizations bright,
With buttons that dance in the light,
Membership status clear and true,
A rabbit's code, both smart and new,
Hopping through features with delight! 🏠🔍


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
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 (12)
src/components/OrganizationCard/OrganizationCard.tsx (6)

184-186: Safely render props.description to prevent potential errors

If props.description is undefined or null, rendering it directly could cause unintended output or errors. Consider conditionally rendering the description only if it exists.

Modify the code to:

{props.description && (
  <h6 className={`${styles.orgdesc} fw-semibold`}>
    <span>{props.description}</span>
  </h6>
)}
🧰 Tools
🪛 Biome (1.9.4)

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

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


72-73: Ensure userId is not null before using it in queries

Since userId can be null, using it directly in GraphQL queries may result in errors or unintended behavior. Consider adding a null check before using it in useQuery or provide a default value.

Example:

const userId = getItem('userId');

if (userId) {
  const { refetch } = useQuery(USER_JOINED_ORGANIZATIONS, {
    variables: { id: userId },
  });
  // Rest of your code that depends on userId
}

Alternatively, you can handle the null case gracefully within the component or redirect the user to log in if userId is not available.


107-136: Handle potential errors more comprehensively in joinOrganization

The error handling in joinOrganization assumes that the error is an ApolloError with graphQLErrors. However, there's a possibility of other errors occurring. Consider adding a general error message or logging for unexpected error types.

Modify the catch block to handle unexpected errors:

} catch (error: unknown) {
  if (error instanceof ApolloError) {
    const errorCode = error.graphQLErrors[0]?.extensions?.code;

    if (errorCode === 'ALREADY_MEMBER') {
      toast.error(t('AlreadyJoined') as string);
    } else {
      toast.error(t('errorOccured') as string);
    }
  } else {
    // Handle non-ApolloError types
    toast.error(t('unexpectedError') as string);
    console.error('An unexpected error occurred:', error);
  }
}

143-145: Improve type safety when finding membershipRequest

When finding the membershipRequest, ensure that userId is not null to avoid potential errors.

Add a null check for userId:

if (!userId) {
  toast.error(t('UserNotLoggedIn') as string);
  return;
}

const membershipRequest = props.membershipRequests.find(
  (request) => request.user._id === userId,
);

198-200: Handle undefined props.admins and props.members safely

In cases where props.admins or props.members might be undefined, using .length may cause errors. Consider providing default values to ensure safe access.

Modify the code to provide default empty arrays:

{tCommon('admins')}: <span>{props.admins?.length ?? 0}</span> &nbsp;
&nbsp; &nbsp; {tCommon('members')}: <span>{props.members?.length ?? 0}</span>

170-177: Simplify image rendering logic

You can simplify the conditional rendering of the organization image by leveraging short-circuit evaluation.

Simplify the code as follows:

<div className={styles.orgImgContainer}>
  {props.image ? (
    <img src={props.image} alt={`${props.name} image`} />
  ) : (
    <Avatar
      name={props.name}
      alt={`${props.name} image`}
      dataTestId="emptyContainerForImage"
    />
  )}
</div>

This maintains readability and reduces unnecessary complexity.

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

168-209: Separate tests for each membership status to improve clarity

Currently, the test displays correct button based on membership status uses rerender to test different statuses within a single test case. Separating these into individual test cases enhances readability and maintainability.

Refactor the tests as follows:

test('renders "Join Now" button when membershipRequestStatus is empty', () => {
  render(
    // ...
    <OrganizationCard {...defaultProps} membershipRequestStatus="" />
    // ...
  );
  expect(screen.getByTestId('joinBtn')).toBeInTheDocument();
});

test('renders "Visit" button when membershipRequestStatus is accepted', () => {
  render(
    // ...
    <OrganizationCard {...defaultProps} membershipRequestStatus="accepted" />
    // ...
  );
  const visitButton = screen.getByTestId('manageBtn');
  expect(visitButton).toBeInTheDocument();
  fireEvent.click(visitButton);
  expect(mockNavigate).toHaveBeenCalledWith('/user/organization/123');
});

test('renders "Withdraw" button when membershipRequestStatus is pending', () => {
  render(
    // ...
    <OrganizationCard {...defaultProps} membershipRequestStatus="pending" />
    // ...
  );
  expect(screen.getByTestId('withdrawBtn')).toBeInTheDocument();
});

19-23: Avoid side effects in mocks by using jest.fn() within the mock scope

To ensure that mocks do not leak between tests, consider defining mockNavigate within the mock scope rather than at the module level.

Modify the mock setup:

jest.mock('react-router-dom', () => {
  const originalModule = jest.requireActual('react-router-dom');
  return {
    ...originalModule,
    useNavigate: jest.fn(),
  };
});

Then, within your tests, you can access useNavigate:

import { useNavigate } from 'react-router-dom';

// Inside your test
const mockNavigate = useNavigate() as jest.Mock;
// Now you can assert on `mockNavigate`
src/screens/UserPortal/Organizations/Organizations.tsx (4)

254-258: Ensure membershipRequestStatus is accurately determined

In the mapping function, consider handling cases where membershipRequestStatus might not be 'accepted' or may be undefined. This ensures that isJoined reflects the actual membership status.

Add a default case for membershipRequestStatus:

return {
  ...organization,
  membershipRequestStatus,
  isJoined: membershipRequestStatus === 'accepted',
};

Ensure that membershipRequestStatus is set correctly and consider handling other statuses like 'pending' if applicable.


Line range hint 98-100: Check for null userId before using it in queries

Since userId can be null, using it directly in useQuery may cause issues. Add a null check or default handling to prevent potential errors.

Example:

const userId: string | null = getItem('userId');

if (userId) {
  const { data: joinedOrganizationsData } = useQuery(USER_JOINED_ORGANIZATIONS, {
    variables: { id: userId },
  });

  const { data: createdOrganizationsData } = useQuery(
    USER_CREATED_ORGANIZATIONS,
    {
      variables: { id: userId },
    },
  );
} else {
  // Handle the case when userId is null, e.g., redirect to login
}

This ensures that queries relying on userId do not execute with invalid parameters.


266-272: Handle undefined data when mapping joinedOrganizations

When mapping over joinedOrganizations, ensure that the nested properties are not undefined to prevent runtime errors.

Modify the code:

const organizations =
  joinedOrganizationsData.users[0]?.user?.joinedOrganizations?.map(
    (org: InterfaceOrganization) => ({
      ...org,
      membershipRequestStatus: 'accepted',
      isJoined: true,
    }),
  ) || [];

Adding ? before .map ensures that the code does not attempt to map over undefined.


281-287: Handle undefined data when mapping createdOrganizations

Similar to the previous comment, ensure that createdOrganizations is defined before mapping.

Modify the code:

const organizations =
  createdOrganizationsData.users[0]?.appUserProfile?.createdOrganizations?.map(
    (org: InterfaceOrganization) => ({
      ...org,
      membershipRequestStatus: 'accepted',
      isJoined: true,
    }),
  ) || [];

This prevents runtime errors if createdOrganizations is undefined.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e9aec17 and 34335ce.

📒 Files selected for processing (5)
  • eslint.config.cjs (1 hunks)
  • eslint.config.js (1 hunks)
  • src/components/OrganizationCard/OrganizationCard.spec.tsx (2 hunks)
  • src/components/OrganizationCard/OrganizationCard.tsx (1 hunks)
  • src/screens/UserPortal/Organizations/Organizations.tsx (2 hunks)
🧰 Additional context used
🪛 GitHub Actions: PR Workflow
eslint.config.cjs

[error] SyntaxError: Unexpected identifier 'eslint' - Possible configuration file syntax error

🪛 Biome (1.9.4)
eslint.config.js

[error] 17-17: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 17-17: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)

src/components/OrganizationCard/OrganizationCard.tsx

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

eslint.config.cjs Outdated Show resolved Hide resolved
eslint.config.cjs Outdated Show resolved Hide resolved
eslint.config.js Outdated Show resolved Hide resolved
eslint.config.js Outdated
Comment on lines 1 to 18
// eslint.config.cjs
module.exports = {
extends: [
'eslint:recommended',
'plugin:react/recommended',
// Add other configurations as needed
],
parserOptions: {
ecmaVersion: 2021,
sourceType: 'module',
},
plugins: ['react'],
rules: {
// Your custom rules here
},
};
npx eslint --fix

Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Consolidate ESLint configurations.

This file duplicates the configuration from eslint.config.cjs. To maintain a single source of truth:

  1. Choose either .js or .cjs extension based on your module system
  2. Remove the duplicate file
  3. Update your tooling to use the chosen configuration file
🧰 Tools
🪛 Biome (1.9.4)

[error] 17-17: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 17-17: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)

@Cioppolo14
Copy link
Contributor

@gkbishnoi07 Please fix the failed tests and make sure coderabbit approves of the PR.

@gkbishnoi07
Copy link
Author

@Cioppolo14 working on failed test cases

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 (2)
src/components/OrganizationCard/OrganizationCard.tsx (2)

74-101: Destructure props for better code readability

Multiple static analysis tools suggest destructuring props. This would improve code readability and follow React best practices.

-function OrganizationCard(props: InterfaceOrganizationCardProps): JSX.Element {
+function OrganizationCard({
+  id,
+  name,
+  image,
+  description,
+  admins,
+  members,
+  address,
+  membershipRequestStatus,
+  userRegistrationRequired,
+  membershipRequests
+}: InterfaceOrganizationCardProps): JSX.Element {
🧰 Tools
🪛 GitHub Check: Performs linting, formatting, type-checking, checking for different source and target branch

[failure] 85-85:
Must use destructuring props assignment


[failure] 90-90:
Must use destructuring props assignment


[failure] 95-95:
Must use destructuring props assignment

🪛 eslint

[error] 85-85: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 90-90: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 95-95: Must use destructuring props assignment

(react/destructuring-assignment)


186-196: Use optional chaining for address checks

Simplify the address check using optional chaining for better readability.

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

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

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🪛 eslint

[error] 186-186: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 186-186: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 189-189: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 190-190: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 192-192: Must use destructuring props assignment

(react/destructuring-assignment)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 34335ce and 60df684.

📒 Files selected for processing (1)
  • src/components/OrganizationCard/OrganizationCard.tsx (1 hunks)
🧰 Additional context used
🪛 GitHub Check: Performs linting, formatting, type-checking, checking for different source and target branch
src/components/OrganizationCard/OrganizationCard.tsx

[failure] 12-12:
'/home/runner/work/talawa-admin/talawa-admin/node_modules/@apollo/client/index.js' imported multiple times


[failure] 20-20:
All imports in the declaration are only used as types. Use import type


[failure] 20-20:
'/home/runner/work/talawa-admin/talawa-admin/node_modules/@apollo/client/index.js' imported multiple times


[failure] 85-85:
Must use destructuring props assignment


[failure] 90-90:
Must use destructuring props assignment


[failure] 95-95:
Must use destructuring props assignment


[failure] 108-108:
Must use destructuring props assignment


[failure] 111-111:
Must use destructuring props assignment


[failure] 118-118:
Must use destructuring props assignment


[failure] 143-143:
Must use destructuring props assignment

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

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

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🪛 eslint
src/components/OrganizationCard/OrganizationCard.tsx

[error] 12-12: '@apollo/client' imported multiple times.

(import/no-duplicates)


[error] 20-20: All imports in the declaration are only used as types. Use import type.

(@typescript-eslint/consistent-type-imports)


[error] 20-20: '@apollo/client' imported multiple times.

(import/no-duplicates)


[error] 85-85: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 90-90: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 95-95: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 108-108: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 111-111: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 118-118: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 143-143: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 159-159: 'error' is defined but never used.

(@typescript-eslint/no-unused-vars)


[error] 169-169: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 170-170: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 170-170: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 173-173: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 174-174: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 180-180: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 181-181: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 184-184: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 186-186: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 186-186: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 189-189: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 190-190: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 192-192: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 198-198: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 200-200: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 204-204: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 210-210: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 217-217: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 228-228: Must use destructuring props assignment

(react/destructuring-assignment)

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

[error] 12-12: '/home/runner/work/talawa-admin/talawa-admin/node_modules/@apollo/client/index.js' imported multiple times (import/no-duplicates)

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

26-49: LGTM! Well-structured interface definition.

The interface properties are well-defined and properly typed, providing a comprehensive structure for organization data.


52-71: LGTM! Excellent documentation.

The JSDoc documentation is comprehensive and clearly describes all component props and functionality.


204-214: LGTM! Visit button implementation.

The Visit button implementation aligns with the PR objectives, providing direct navigation to organizations from the filter.

🧰 Tools
🪛 eslint

[error] 204-204: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 210-210: Must use destructuring props assignment

(react/destructuring-assignment)


1-241: Add unit tests for the new Visit button feature

While the implementation looks good, the PR mentions that no tests were added. Consider adding tests for:

  • Visit button rendering conditions
  • Navigation functionality
  • Different membership states

Would you like me to help generate the test cases for the Visit button feature?

🧰 Tools
🪛 GitHub Check: Performs linting, formatting, type-checking, checking for different source and target branch

[failure] 12-12:
'/home/runner/work/talawa-admin/talawa-admin/node_modules/@apollo/client/index.js' imported multiple times


[failure] 20-20:
All imports in the declaration are only used as types. Use import type


[failure] 20-20:
'/home/runner/work/talawa-admin/talawa-admin/node_modules/@apollo/client/index.js' imported multiple times


[failure] 85-85:
Must use destructuring props assignment


[failure] 90-90:
Must use destructuring props assignment


[failure] 95-95:
Must use destructuring props assignment


[failure] 108-108:
Must use destructuring props assignment


[failure] 111-111:
Must use destructuring props assignment


[failure] 118-118:
Must use destructuring props assignment


[failure] 143-143:
Must use destructuring props assignment

🪛 Biome (1.9.4)

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

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🪛 eslint

[error] 12-12: '@apollo/client' imported multiple times.

(import/no-duplicates)


[error] 20-20: All imports in the declaration are only used as types. Use import type.

(@typescript-eslint/consistent-type-imports)


[error] 20-20: '@apollo/client' imported multiple times.

(import/no-duplicates)


[error] 85-85: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 90-90: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 95-95: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 108-108: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 111-111: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 118-118: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 143-143: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 159-159: 'error' is defined but never used.

(@typescript-eslint/no-unused-vars)


[error] 169-169: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 170-170: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 170-170: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 173-173: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 174-174: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 180-180: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 181-181: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 184-184: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 186-186: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 186-186: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 189-189: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 190-190: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 192-192: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 198-198: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 200-200: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 204-204: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 210-210: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 217-217: Must use destructuring props assignment

(react/destructuring-assignment)


[error] 228-228: Must use destructuring props assignment

(react/destructuring-assignment)

🪛 GitHub Actions: PR Workflow

[error] 12-12: '/home/runner/work/talawa-admin/talawa-admin/node_modules/@apollo/client/index.js' imported multiple times (import/no-duplicates)

src/components/OrganizationCard/OrganizationCard.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 (3)
src/components/OrganizationCard/OrganizationCard.tsx (3)

12-12: Fix formatting in imports

Remove the trailing comma after useQuery.

-import { useMutation, useQuery, } from '@apollo/client';
+import { useMutation, useQuery } from '@apollo/client';
🧰 Tools
🪛 eslint

[error] 12-12: Delete ,

(prettier/prettier)

🪛 GitHub Actions: PR Workflow

[warning] Code formatting issues detected. File needs to be formatted using Prettier.


113-143: Improve error type handling in joinOrganization

The error handling could be more type-safe. Consider creating a custom type for the GraphQL error structure.

+interface GraphQLErrorExtensions {
+  code: string;
+}
+
+interface CustomGraphQLError extends ApolloError {
+  graphQLErrors: Array<{
+    extensions?: GraphQLErrorExtensions;
+  }>;
+}

 async function joinOrganization(): Promise<void> {
   try {
     // ... existing code ...
   } catch (error: unknown) {
     if (error instanceof Error) {
-      const apolloError = error as ApolloError;
+      const apolloError = error as CustomGraphQLError;
       const errorCode = apolloError.graphQLErrors[0]?.extensions?.code;
🧰 Tools
🪛 GitHub Actions: PR Workflow

[warning] Code formatting issues detected. File needs to be formatted using Prettier.


189-197: Optimize conditional rendering with optional chaining

The address check can be simplified using optional chaining.

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

🪛 GitHub Actions: PR Workflow

[warning] Code formatting issues detected. File needs to be formatted using Prettier.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 60df684 and f9a2705.

📒 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] 189-189: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🪛 eslint
src/components/OrganizationCard/OrganizationCard.tsx

[error] 12-12: Delete ,

(prettier/prettier)

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

[warning] Code formatting issues detected. File needs to be formatted using Prettier.

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

27-49: LGTM! Well-structured interface definition

The interface is well-defined with proper typing for all properties. The nested structures for admins, members, address, and membershipRequests provide good type safety.

🧰 Tools
🪛 GitHub Actions: PR Workflow

[warning] Code formatting issues detected. File needs to be formatted using Prettier.


53-70: LGTM! Excellent documentation

The JSDoc comments are comprehensive and well-structured, clearly documenting all parameters and their purposes.

🧰 Tools
🪛 GitHub Actions: PR Workflow

[warning] Code formatting issues detected. File needs to be formatted using Prettier.


86-111: LGTM! Well-structured component setup

Good practices observed:

  • Proper translation setup with namespaces
  • GraphQL mutations with appropriate refetch queries
  • Clean organization of hooks and mutations
🧰 Tools
🪛 GitHub Actions: PR Workflow

[warning] Code formatting issues detected. File needs to be formatted using Prettier.


204-237: LGTM! Clean conditional rendering

The button rendering logic is well-organized with clear conditions and appropriate variants for different states.

🧰 Tools
🪛 GitHub Actions: PR Workflow

[warning] Code formatting issues detected. File needs to be formatted using Prettier.

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)

53-70: Consider adding usage examples to the documentation.

The documentation is comprehensive but could be even more helpful with examples showing different membership states and how they affect the component's rendering.


94-108: Consider extracting duplicate refetchQueries configuration.

The refetchQueries configuration is repeated across multiple mutations. Consider extracting it to a constant to improve maintainability.

+const MEMBERSHIP_REFETCH_QUERIES = [
+  { query: USER_ORGANIZATION_CONNECTION, variables: { id } },
+];

 const [sendMembershipRequest] = useMutation(SEND_MEMBERSHIP_REQUEST, {
-  refetchQueries: [
-    { query: USER_ORGANIZATION_CONNECTION, variables: { id } },
-  ],
+  refetchQueries: MEMBERSHIP_REFETCH_QUERIES,
 });

 const [joinPublicOrganization] = useMutation(JOIN_PUBLIC_ORGANIZATION, {
-  refetchQueries: [
-    { query: USER_ORGANIZATION_CONNECTION, variables: { id } },
-  ],
+  refetchQueries: MEMBERSHIP_REFETCH_QUERIES,
 });

 const [cancelMembershipRequest] = useMutation(CANCEL_MEMBERSHIP_REQUEST, {
-  refetchQueries: [
-    { query: USER_ORGANIZATION_CONNECTION, variables: { id } },
-  ],
+  refetchQueries: MEMBERSHIP_REFETCH_QUERIES,
 });

131-142: Consider creating a custom error type for better error handling.

The error handling could be more specific by creating a custom type for GraphQL errors. This would make the error handling more type-safe and maintainable.

type OrganizationError = {
  code: 'ALREADY_MEMBER' | 'MEMBERSHIP_NOT_FOUND' | 'UNKNOWN_ERROR';
  message: string;
};

// Usage in error handling
if (error instanceof ApolloError) {
  const errorCode = error.graphQLErrors[0]?.extensions?.code as OrganizationError['code'];
  // ...
}

189-197: Use optional chaining for safer address access.

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

-{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] 189-189: 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 f9a2705 and 074bf17.

📒 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] 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 (1)
  • GitHub Check: Test Application
🔇 Additional comments (3)
src/components/OrganizationCard/OrganizationCard.tsx (3)

12-12: Consolidate duplicate imports from '@apollo/client'

Combine the multiple imports from '@apollo/client' into a single import statement and use import type for type-only imports.

-import { useMutation, useQuery } from '@apollo/client';
-import type { ApolloError } from '@apollo/client';
+import { useMutation, useQuery } from '@apollo/client';
+import type { ApolloError } from '@apollo/client';

Also applies to: 20-20


28-49: LGTM! Well-structured interface with comprehensive type definitions.

The interface has been enhanced with well-defined types for organization properties including description, admins, members, address, and membership-related fields.


204-237: LGTM! Well-implemented conditional rendering for membership states.

The button rendering logic is clean and properly handles all membership states (accepted, pending, and new joins) with appropriate styling and functionality.

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.spec.tsx (3)

29-45: Consider adding validation for required props

The defaultProps object is well-structured, but consider adding JSDoc comments to document which props are required vs optional, especially for the new membershipRequestStatus prop.

Add documentation like this:

+/**
+ * Default props for OrganizationCard tests
+ * @property {string} id - Required. Organization ID
+ * @property {string} membershipRequestStatus - Required. Current membership status
+ */
const defaultProps = {

105-124: Add error handling test cases for navigation

While the basic navigation test is good, consider adding test cases for:

  1. Error handling when navigation fails
  2. Loading state during navigation

Add these test cases:

test('handles navigation errors gracefully', () => {
  mockNavigate.mockImplementationOnce(() => {
    throw new Error('Navigation failed');
  });
  // Test implementation
});

test('shows loading state during navigation', () => {
  // Test implementation with loading state check
});

47-171: Consider grouping related test cases

The test cases are well-written but could be better organized using describe blocks to group related tests.

Consider restructuring like this:

describe('OrganizationCard', () => {
  describe('Rendering', () => {
    // Tests for basic rendering (with/without image)
  });

  describe('Membership Status', () => {
    // Tests for different membership statuses
  });

  describe('Navigation', () => {
    // Tests for navigation functionality
  });
});
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 074bf17 and 480a62d.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • package.json (2 hunks)
  • src/components/OrganizationCard/OrganizationCard.spec.tsx (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Test Application
  • GitHub Check: Analyse Code With CodeQL (javascript)
🔇 Additional comments (3)
package.json (1)

152-152: Verify Jest upgrade compatibility

The significant version jump in Jest (27.4.5 to 29.7.0) might introduce breaking changes. Ensure all existing tests are compatible with the new version.

Run this script to check for potential compatibility issues:

✅ Verification successful

Jest upgrade appears safe to proceed

The codebase uses modern Jest patterns and APIs that are compatible with Jest 29.x. The configuration and test implementations follow current best practices without any deprecated features.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for Jest breaking changes and compatibility issues

# Search for Jest configuration files
echo "Searching for Jest config files..."
fd -e json -e js -e ts --full-path "jest.config"

# Look for potentially affected test patterns
echo "Checking for potentially affected test patterns..."
rg -l "jest.mock|jest.spyOn|jest.fn" -g "*.spec.{ts,tsx,js,jsx}"

Length of output: 378


Script:

#!/bin/bash
# Check Jest configuration and test implementation
echo "=== Jest Configuration ==="
cat jest.config.js

echo -e "\n=== Test Implementation ==="
cat src/components/OrganizationCard/OrganizationCard.spec.tsx

Length of output: 9088

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

20-27: LGTM! Well-structured navigation mock

The navigation mock is properly implemented using jest.mock, which is essential for testing the Visit button's navigation functionality.


105-124: LGTM! Tests align perfectly with PR objectives

The test coverage for the Visit button feature is comprehensive, including:

  • Correct button rendering based on membership status
  • Navigation functionality
  • Different membership states

Also applies to: 172-214

@palisadoes
Copy link
Contributor

Exclude the sensitive files from your PR. Don't delete them.

Your PR has too many unnecessary files that don’t relate to your issue. You can exclude them from the PR by running the commands below from the root directory of the repository

git add -u
git reset HEAD path/to/file
git commit
git push

Please apply these changes to this file(s).

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.

3 participants