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

feat(business-report): upgrade user-facing part of the social media data UI (BAL-2577) #2911

Merged
merged 6 commits into from
Dec 30, 2024

Conversation

r4zendev
Copy link
Collaborator

@r4zendev r4zendev commented Dec 27, 2024

  • Updates social media tab UI according to the one described in the initial ticket;
  • Updates lucide-react to a recent version (was required to pull the Ban icon that is in the UI scratch);
  • Removes redundant abstractions where possible and improves the logic in general;
  • Adds temporary replacement for ads section to display empty state as it was marked as unnecessary to complete now. I wasn't sure if this section is to be deprecated and removed from the design altogether or if we actually want to have it later, so I did not remove it completely for now.

Examples of the UI:
image
image

In 1920x1080 aspect ratio:
image

With disabled states:
image

Small explanation as to why the customers tab in the backoffice application was throwing 401 for me:
In services/workflows-service/src/common/middlewares/auth-key.middleware.ts there is a middleware that assigns the customer role to any request going through it. Changing the role to admin locally allowed me to make a request and see the customers tab. Just a note for you in case it needs to be fixed.

Note: we are missing decent loading states.
Note 2: I wasn't sure how we maintain our change logs and bump packages, so I just bumped the ui package and updated the CHANGELOG.md manually. I saw changesets but IIRC they keep the changelog for the entire monorepo and store it in the root. I didn't see any kind of npm script or anything similar in the ui package. Let me know if I should do something here.

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced a new build:watch script for building the project in watch mode.
    • Added a new button variant, browserLink, to enhance visual presentation.
    • New components FacebookIcon and InstagramIcon added for social media representation.
    • Enhanced AdsAndSocialMedia component with improved layout and functionality.
    • Added new functions toSocialMediaPresence and toAdsImages for structured data extraction.
  • Bug Fixes

    • Made width and height properties optional in the ImageProps interface.
  • Removals

    • Removed AdImageWithLink component and its associated exports.
    • Deleted exports for ads-provider-adapter and create-report-adapter, affecting accessibility in the application.
    • Removed export for report-adapter and its associated exports.
  • Refactor

    • Updated reportAdapter logic for better data processing and structure.
    • Restructured useReportTabs for clearer component organization.

@r4zendev r4zendev self-assigned this Dec 27, 2024
Copy link

changeset-bot bot commented Dec 27, 2024

⚠️ No Changeset found

Latest commit: 79dd7fc

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Dec 27, 2024

Warning

Rate limit exceeded

@r4zendev has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 11 minutes and 15 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 4f07e6f and 89bf73e.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (21)
  • apps/kyb-app/CHANGELOG.md (1 hunks)
  • apps/kyb-app/package.json (2 hunks)
  • packages/react-pdf-toolkit/CHANGELOG.md (1 hunks)
  • packages/react-pdf-toolkit/package.json (2 hunks)
  • packages/ui/CHANGELOG.md (1 hunks)
  • packages/ui/package.json (3 hunks)
  • packages/ui/src/components/atoms/Button/Button.tsx (1 hunks)
  • packages/ui/src/components/atoms/Image/interfaces.ts (1 hunks)
  • packages/ui/src/components/templates/report/adapters/ads-provider-adapter/ads-provider-adapter.ts (0 hunks)
  • packages/ui/src/components/templates/report/adapters/ads-provider-adapter/index.ts (0 hunks)
  • packages/ui/src/components/templates/report/adapters/create-report-adapter/index.ts (0 hunks)
  • packages/ui/src/components/templates/report/adapters/index.ts (0 hunks)
  • packages/ui/src/components/templates/report/adapters/report-adapter.ts (4 hunks)
  • packages/ui/src/components/templates/report/adapters/report-adapter/index.ts (0 hunks)
  • packages/ui/src/components/templates/report/components/AdImageWithLink/AdImageWithLink.tsx (0 hunks)
  • packages/ui/src/components/templates/report/components/AdImageWithLink/index.ts (0 hunks)
  • packages/ui/src/components/templates/report/components/AdsAndSocialMedia/AdsAndSocialMedia.tsx (1 hunks)
  • packages/ui/src/components/templates/report/components/AdsAndSocialMedia/icons/FacebookIcon.tsx (1 hunks)
  • packages/ui/src/components/templates/report/components/AdsAndSocialMedia/icons/InstagramIcon.tsx (1 hunks)
  • packages/ui/src/components/templates/report/components/index.ts (0 hunks)
  • packages/ui/src/components/templates/report/hooks/useReportTabs/useReportTabs.tsx (1 hunks)

Walkthrough

This pull request introduces several modifications to the UI package, including updates to the package configuration, component refactoring, and removal of certain adapters and components. The changes involve updating the package.json script, modifying the Button component to include a new variant, making Image props optional, removing the ads-provider-adapter, and enhancing the AdsAndSocialMedia component with new icons and improved data handling.

Changes

File Change Summary
packages/ui/package.json - Added build:watch script
- Updated version to 0.5.55
- Updated lucide-react dependency from ^0.144.0 to ^0.245.0
packages/ui/src/components/atoms/Button/Button.tsx Added new browserLink variant to buttonVariants
packages/ui/src/components/atoms/Image/interfaces.ts Made width and height properties optional in ImageProps interface
packages/ui/src/components/templates/report/adapters/... - Removed ads-provider-adapter.ts
- Removed related index exports
packages/ui/src/components/templates/report/adapters/report-adapter.ts - Added toSocialMediaPresence function
- Added toAdsImages function
packages/ui/src/components/templates/report/components/... - Removed AdImageWithLink component
- Added FacebookIcon and InstagramIcon components
packages/ui/src/components/templates/report/components/AdsAndSocialMedia/AdsAndSocialMedia.tsx - Updated component props
- Refined rendering logic for social media and ads

Suggested labels

enhancement, Review effort [1-5]: 4

Suggested reviewers

  • Omri-Levy
  • tomer-shvadron

Possibly related PRs

Poem

🐰 A Rabbit's Ode to UI Delight 🎨

Scripts and icons, dancing with grace,
Buttons and images find their new space.
Adapters vanish, components shine bright,
CodeRabbit's magic takes playful flight!

Hop, hop, hooray! 🚀


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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@r4zendev r4zendev marked this pull request as ready for review December 27, 2024 01:08
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 (4)
packages/ui/src/components/templates/report/components/AdsAndSocialMedia/AdsAndSocialMedia.tsx (2)

114-116: Consider extracting and reusing shared logic.

You have a TODO indicating that this component can be decoupled and reused more broadly. Extracting the Ads/UI logic into smaller, composable pieces may improve maintainability and reduce duplication across other social media or ads components.

Would you like me to open a detailed issue or provide a sample refactor to break out these responsibilities?


221-227: Remove or replace constant conditionals.

Using false ? 'opacity-100' : 'opacity-60' and false ? ( ... ) : ( ... ) will never evaluate the true branch. This is likely a leftover placeholder. Consider replacing it with a dynamic condition or removing it altogether.

Below is a suggested snippet:

- false ? 'opacity-100' : 'opacity-60',
+ adsImages?.length ? 'opacity-100' : 'opacity-60',

- {false ? (
-   <>The ads should be displayed here</>
- ) : (
+ {adsImages?.length ? (
+   <>The ads should be displayed here</>
+ ) : (
   <div className="flex items-center gap-2 text-gray-400">
     ...
   </div>
 )}
🧰 Tools
🪛 Biome (1.9.4)

[error] 221-221: Unexpected constant condition.

(lint/correctness/noConstantCondition)


[error] 225-225: Unexpected constant condition.

(lint/correctness/noConstantCondition)

packages/ui/src/components/templates/report/components/AdsAndSocialMedia/icons/FacebookIcon.tsx (1)

1-23: Consider adding ARIA attributes for accessibility.

Including role="img" and an aria-label (or title) helps screen readers describe the icon.

-export const FacebookIcon = ({ className }: { className?: string }) => (
+export const FacebookIcon = ({ className }: { className?: string }) => {
+  const label = 'Facebook Icon';
+  return (
+    <svg
+      xmlns="http://www.w3.org/2000/svg"
+      viewBox="0 0 48 48"
+      className={className}
+      role="img"
+      aria-label={label}
+    >
       ...
+    </svg>
+  );
+}
packages/ui/src/components/templates/report/components/AdsAndSocialMedia/icons/InstagramIcon.tsx (1)

1-47: Add ARIA acknowledgment for screen readers.

As with the Facebook icon, providing role="img" and an aria-label will make the icon more accessible.

-export const InstagramIcon = ({ className }: { className?: string }) => (
+export const InstagramIcon = ({ className }: { className?: string }) => {
+  const label = 'Instagram Icon';
+  return (
+    <svg
+      xmlns="http://www.w3.org/2000/svg"
+      viewBox="0 0 48 48"
+      className={className}
+      role="img"
+      aria-label={label}
+    >
        ...
+    </svg>
+  );
+}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 01c1a6c and 72d5306.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (16)
  • packages/ui/package.json (2 hunks)
  • packages/ui/src/components/atoms/Button/Button.tsx (1 hunks)
  • packages/ui/src/components/atoms/Image/interfaces.ts (1 hunks)
  • packages/ui/src/components/templates/report/adapters/ads-provider-adapter/ads-provider-adapter.ts (0 hunks)
  • packages/ui/src/components/templates/report/adapters/ads-provider-adapter/index.ts (0 hunks)
  • packages/ui/src/components/templates/report/adapters/create-report-adapter/index.ts (0 hunks)
  • packages/ui/src/components/templates/report/adapters/index.ts (0 hunks)
  • packages/ui/src/components/templates/report/adapters/report-adapter.ts (4 hunks)
  • packages/ui/src/components/templates/report/adapters/report-adapter/index.ts (0 hunks)
  • packages/ui/src/components/templates/report/components/AdImageWithLink/AdImageWithLink.tsx (0 hunks)
  • packages/ui/src/components/templates/report/components/AdImageWithLink/index.ts (0 hunks)
  • packages/ui/src/components/templates/report/components/AdsAndSocialMedia/AdsAndSocialMedia.tsx (1 hunks)
  • packages/ui/src/components/templates/report/components/AdsAndSocialMedia/icons/FacebookIcon.tsx (1 hunks)
  • packages/ui/src/components/templates/report/components/AdsAndSocialMedia/icons/InstagramIcon.tsx (1 hunks)
  • packages/ui/src/components/templates/report/components/index.ts (0 hunks)
  • packages/ui/src/components/templates/report/hooks/useReportTabs/useReportTabs.tsx (1 hunks)
💤 Files with no reviewable changes (8)
  • packages/ui/src/components/templates/report/components/index.ts
  • packages/ui/src/components/templates/report/adapters/index.ts
  • packages/ui/src/components/templates/report/adapters/create-report-adapter/index.ts
  • packages/ui/src/components/templates/report/adapters/ads-provider-adapter/index.ts
  • packages/ui/src/components/templates/report/adapters/ads-provider-adapter/ads-provider-adapter.ts
  • packages/ui/src/components/templates/report/components/AdImageWithLink/index.ts
  • packages/ui/src/components/templates/report/components/AdImageWithLink/AdImageWithLink.tsx
  • packages/ui/src/components/templates/report/adapters/report-adapter/index.ts
🧰 Additional context used
🪛 Biome (1.9.4)
packages/ui/src/components/templates/report/components/AdsAndSocialMedia/AdsAndSocialMedia.tsx

[error] 144-144: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)


[error] 221-221: Unexpected constant condition.

(lint/correctness/noConstantCondition)


[error] 225-225: Unexpected constant condition.

(lint/correctness/noConstantCondition)

🔇 Additional comments (12)
packages/ui/src/components/templates/report/components/AdsAndSocialMedia/AdsAndSocialMedia.tsx (1)

144-144: Verify custom shadow class usage.

shadow-l is not a standard Tailwind utility class and may be a typo or custom style. Ensure it’s intentional; otherwise, change it to a standard utility (e.g., shadow-lg) for consistency.

🧰 Tools
🪛 Biome (1.9.4)

[error] 144-144: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

packages/ui/src/components/atoms/Image/interfaces.ts (1)

7-8: LGTM on making width and height optional.

Allowing flexible dimensions improves reusability and responsiveness.

packages/ui/src/components/atoms/Button/Button.tsx (1)

18-19: New variant added successfully.

The new “browserLink” variant appears consistent with the existing style strategy.

packages/ui/src/components/templates/report/hooks/useReportTabs/useReportTabs.tsx (2)

2-2: Imports look consistent.
All imported modules are utilized appropriately within this file.


6-12: Refactored import block for clarity.
These imports are reorganized to include the AdsAndSocialMedia, WebsitesCompany, WebsiteLineOfBusiness, and WebsiteCredibility components. This is consistent with their usage below, ensuring minimal confusion and better readability.

packages/ui/src/components/templates/report/adapters/report-adapter.ts (5)

1-3: New imports enhance code clarity.
Using booleanToYesOrNo from @ballerine/common is a clean way to transform boolean fields into more descriptive text. This reduces code duplication.


25-49: Introduce toSocialMediaPresence function for structured data.
This function cleanly extracts and organizes social media data for Facebook and Instagram. The usage of booleanToYesOrNo for isBusinessAccount and isVerified is a succinct approach. Ensure any additional platforms in the future follow the same pattern for consistency.


51-65: Introduce toAdsImages function for ad images data.
Similarly, toAdsImages extracts and organizes Facebook and Instagram ad images. This design fosters separation of concerns, making it easier to extend or add new properties if more platforms or image types are needed.


84-84: Accurate mapping for adsAndSocialMediaPresence.
By calling toSocialMediaPresence(report?.socialMedia) directly, the code becomes more legible, removing the need for multi-step transformations. This streamlined approach leads to improved maintainability.


145-145: Include adsImages from toAdsImages.
Generating adsImages in a dedicated function keeps data transformations centralized, reducing complexity in the main adapter logic. Good move!

packages/ui/package.json (2)

21-21: New build watch script added.
The build:watch script will be helpful for rapid feedback in development.


57-57: Version bump for lucide-react.
Upgrading from ^0.144.0 to ^0.245.0 may introduce new icons and experimental API changes. Please test thoroughly to ensure backward compatibility of existing icons.

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 (4)
packages/ui/src/components/templates/report/components/AdsAndSocialMedia/AdsAndSocialMedia.tsx (4)

1-27: Consider optimizing icon imports

The large number of individual icon imports could be optimized using a namespace import.

-import {
-  BanIcon,
-  BriefcaseIcon,
-  CalendarIcon,
-  CheckIcon,
-  InfoIcon,
-  LinkIcon,
-  MailIcon,
-  MapPinIcon,
-  PhoneIcon,
-  TagIcon,
-  ThumbsUpIcon,
-  UsersIcon,
-} from 'lucide-react';
+import * as LucideIcons from 'lucide-react';

This would make the code more maintainable and reduce the number of import lines.


28-74: Consider extracting social media mapper configuration

The social media mapper configuration is well-structured but tightly coupled to the component. Consider moving it to a separate configuration file for better maintainability and reusability.

Create a new file socialMediaConfig.ts:

import * as LucideIcons from 'lucide-react';
import { FacebookIcon } from './icons/FacebookIcon';
import { InstagramIcon } from './icons/InstagramIcon';

export const socialMediaConfig = {
  facebook: {
    icon: <FacebookIcon className="h-8 w-8" />,
    fields: {
      // ... existing fields
    },
  },
  instagram: {
    icon: <InstagramIcon className="h-8 w-8" />,
    fields: {
      // ... existing fields
    },
  },
} as const;

100-112: Enhance URL validation in cleanLink function

The cleanLink function could be more robust in handling edge cases and invalid URLs.

 const cleanLink = (link: string) => {
-  if (!link || !z.string().url().safeParse(link).success) {
+  if (!link?.trim() || !z.string().url().safeParse(link).success) {
     return 'N/A';
   }
 
-  let { hostname, pathname } = new URL(link);
+  try {
+    let { hostname, pathname } = new URL(link);
 
-  if (hostname.startsWith('www.')) {
-    hostname = hostname.slice(4);
-  }
+    hostname = hostname.replace(/^www\./, '');
+    pathname = pathname === '/' ? '' : pathname;
 
-  return `${hostname}${pathname}`;
+    return `${hostname}${pathname}`;
+  } catch (error) {
+    return 'N/A';
+  }
 };

136-210: Consider extracting social media card rendering logic

The social media card rendering logic is complex and could benefit from being extracted into a separate component for better readability and maintainability.

Consider creating a SocialMediaCard component:

type SocialMediaCardProps = {
  provider: string;
  mediaPresence: AdsAndSocialMediaProps['mediaPresence'][keyof AdsAndSocialMediaProps['mediaPresence']];
  adsImage: AdsAndSocialMediaProps['adsImages'][keyof AdsAndSocialMediaProps['adsImages']];
};

const SocialMediaCard: FunctionComponent<SocialMediaCardProps> = ({
  provider,
  mediaPresence,
  adsImage,
}) => {
  // Extract current card rendering logic here
};
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 72d5306 and 539e88f.

📒 Files selected for processing (1)
  • packages/ui/src/components/templates/report/components/AdsAndSocialMedia/AdsAndSocialMedia.tsx (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
packages/ui/src/components/templates/report/components/AdsAndSocialMedia/AdsAndSocialMedia.tsx

[error] 221-221: Unexpected constant condition.

(lint/correctness/noConstantCondition)


[error] 225-225: Unexpected constant condition.

(lint/correctness/noConstantCondition)

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 (3)
packages/ui/src/components/templates/report/components/AdsAndSocialMedia/AdsAndSocialMedia.tsx (3)

28-74: Consider extracting social media mapper to a separate file

The social media mapper configuration is well-structured but could be moved to a separate file for better maintainability and reusability.

Consider creating a new file socialMediaConfig.ts:

import { ReactNode } from 'react';
import { FacebookIcon } from './icons/FacebookIcon';
import { InstagramIcon } from './icons/InstagramIcon';
import {
  CalendarIcon,
  PhoneIcon,
  // ... other icons
} from 'lucide-react';

export const socialMediaMapper = {
  facebook: {
    // ... existing configuration
  },
  instagram: {
    // ... existing configuration
  },
} as const;

100-112: Enhance URL validation error handling

The cleanLink function could benefit from more robust error handling for malformed URLs.

Consider this enhanced implementation:

 const cleanLink = (link: string) => {
-  if (!link || !z.string().url().safeParse(link).success) {
+  if (!link) {
     return 'N/A';
   }
+  
+  try {
+    if (!z.string().url().safeParse(link).success) {
+      return 'Invalid URL';
+    }
 
-  let { hostname, pathname } = new URL(link);
+    let { hostname, pathname } = new URL(link);
 
-  if (hostname.startsWith('www.')) {
-    hostname = hostname.slice(4);
-  }
+    if (hostname.startsWith('www.')) {
+      hostname = hostname.slice(4);
+    }
 
-  return `${hostname}${pathname}`;
+    return `${hostname}${pathname}`;
+  } catch (error) {
+    console.error('Error parsing URL:', error);
+    return 'Invalid URL';
+  }
 };

124-236: Consider breaking down the component for better maintainability

The component has grown complex with multiple responsibilities. Consider splitting it into smaller, focused components:

  • SocialMediaSection
  • AdsSection
  • SocialMediaCard

Would you like me to help generate the component structure?

🧰 Tools
🪛 Biome (1.9.4)

[error] 221-221: Unexpected constant condition.

(lint/correctness/noConstantCondition)


[error] 225-225: Unexpected constant condition.

(lint/correctness/noConstantCondition)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 539e88f and cc8e6ca.

📒 Files selected for processing (1)
  • packages/ui/src/components/templates/report/components/AdsAndSocialMedia/AdsAndSocialMedia.tsx (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
packages/ui/src/components/templates/report/components/AdsAndSocialMedia/AdsAndSocialMedia.tsx

[error] 221-221: Unexpected constant condition.

(lint/correctness/noConstantCondition)


[error] 225-225: Unexpected constant condition.

(lint/correctness/noConstantCondition)

🔇 Additional comments (3)
packages/ui/src/components/templates/report/components/AdsAndSocialMedia/AdsAndSocialMedia.tsx (3)

1-27: LGTM! Well-organized imports

The imports are logically grouped and all appear to be used within the component.


114-115: Component decoupling reminder

The TODO comments about component decoupling are still present and should be addressed.


214-232: Remove hardcoded conditions in ads section

The ads section contains hardcoded false conditions that should be replaced with actual logic.

🧰 Tools
🪛 Biome (1.9.4)

[error] 221-221: Unexpected constant condition.

(lint/correctness/noConstantCondition)


[error] 225-225: Unexpected constant condition.

(lint/correctness/noConstantCondition)

Copy link
Collaborator

@MatanYadaev MatanYadaev left a comment

Choose a reason for hiding this comment

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

Great work Sasha! Two comments:

  1. A new version should be published. You can do it with 2 commands: pnpm changeset and then pnpm version-packages
  2. Please hide the ads section. Currently it doesn't work well, we prefer to not show this section to our clients at the moments.

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)
packages/ui/src/components/templates/report/components/AdsAndSocialMedia/AdsAndSocialMedia.tsx (4)

28-74: Consider moving socialMediaMapper to a separate configuration file.

The social media mapper configuration is well-structured and type-safe, but it would be better organized in a dedicated configuration file to improve maintainability and separation of concerns.

Create a new file socialMediaConfig.ts:

import { ReactNode } from 'react';
import { FacebookIcon } from './icons/FacebookIcon';
import { InstagramIcon } from './icons/InstagramIcon';
import {
  CalendarIcon,
  PhoneIcon,
  MailIcon,
  MapPinIcon,
  ThumbsUpIcon,
  TagIcon,
  BriefcaseIcon,
  CheckIcon,
  UsersIcon,
  InfoIcon,
} from 'lucide-react';
import type { AdsAndSocialMediaProps } from './AdsAndSocialMedia';

export const socialMediaMapper = {
  // ... existing configuration
} as const;

100-112: Enhance URL validation and error handling in cleanLink function.

While the function handles basic URL validation, it could be improved to handle more edge cases.

 const cleanLink = (link: string) => {
-  if (!link || !z.string().url().safeParse(link).success) {
+  if (!link) {
     return 'N/A';
   }
+  
+  try {
+    if (!z.string().url().safeParse(link).success) {
+      return 'N/A';
+    }
 
-  let { hostname, pathname } = new URL(link);
+    let { hostname, pathname, search } = new URL(link);
 
-  if (hostname.startsWith('www.')) {
-    hostname = hostname.slice(4);
-  }
+    hostname = hostname.replace(/^www\./, '');
+    pathname = pathname.replace(/\/$/, '');
 
-  return `${hostname}${pathname}`;
+    return `${hostname}${pathname}${search}`;
+  } catch {
+    return 'N/A';
+  }
 };

214-231: Consider using a placeholder component instead of commenting out code.

Rather than commenting out the ads section, consider creating a placeholder component that clearly indicates the work-in-progress status.

const AdsPlaceholder: FC = () => (
  <div>
    <h3 className="mb-2 text-base font-bold">Ads</h3>
    <Card className="flex w-full justify-between p-4 shadow-lg opacity-60">
      <div className="flex items-center gap-2 text-gray-400">
        <BanIcon className="h-5 w-5" />
        <span className="text-sm">Ads section coming soon</span>
      </div>
    </Card>
  </div>
);

136-142: Add type safety for provider access.

The current implementation assumes the provider will always be either 'facebook' or 'instagram'. Add type safety to prevent potential runtime errors.

-AdsProviders.map(toLowerCase).map(provider => {
+AdsProviders.map(toLowerCase).map((provider: keyof typeof socialMediaMapper) => {
   const { page, ...rest } = mediaPresence[provider] ?? {};
   const { src, link } = adsImages[provider] ?? {};

   // || because empty string is not a valid case
   const idValue = ('id' in rest ? rest.id : rest.userName) || null;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3cfc859 and 4f07e6f.

📒 Files selected for processing (5)
  • apps/kyb-app/CHANGELOG.md (1 hunks)
  • apps/kyb-app/package.json (2 hunks)
  • packages/react-pdf-toolkit/CHANGELOG.md (1 hunks)
  • packages/react-pdf-toolkit/package.json (2 hunks)
  • packages/ui/src/components/templates/report/components/AdsAndSocialMedia/AdsAndSocialMedia.tsx (1 hunks)
✅ Files skipped from review due to trivial changes (4)
  • packages/react-pdf-toolkit/CHANGELOG.md
  • apps/kyb-app/package.json
  • packages/react-pdf-toolkit/package.json
  • apps/kyb-app/CHANGELOG.md
🔇 Additional comments (3)
packages/ui/src/components/templates/report/components/AdsAndSocialMedia/AdsAndSocialMedia.tsx (3)

1-27: LGTM! Imports are well-organized and aligned with PR objectives.

The imports are logically grouped and include the new Ban icon from the upgraded lucide-react library as mentioned in the PR objectives.


116-123: Props type is well-defined using adapter return types.

The use of adapter return types for props provides good type safety and maintainability.


193-199: Add error handling for image loading.

The Image component should handle loading errors gracefully.

@alonp99 alonp99 merged commit 5219746 into dev Dec 30, 2024
10 checks passed
@alonp99 alonp99 deleted the bal2577 branch December 30, 2024 12:55
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