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

Bal 1641 #2331

Open
wants to merge 42 commits into
base: dev
Choose a base branch
from
Open

Bal 1641 #2331

wants to merge 42 commits into from

Conversation

chesterkmr
Copy link
Collaborator

@chesterkmr chesterkmr commented May 1, 2024

User description

Description

  • Implemented certificate generation for cases.

image

Sample PDF

certificate).pdf
empty states .pdf


Type

enhancement


Description

  • Added various PDF rendering logics for different types of data including company ownership, sanctions, identity verifications, and more.
  • Implemented a new component CaseOptions with functionality to download PDF certificates.
  • Introduced an abstract class IPDFRenderer to standardize PDF rendering operations.
  • Enhanced several components and hooks to support new features related to PDF handling and customer data management.

Changes walkthrough

Relevant files
Enhancement
14 files
svg-to-png.ts
Add SVG to PNG Conversion Utility                                               

apps/backoffice-v2/src/common/utils/svg-to-png/svg-to-png.ts

  • Added a new utility function svgToPng to convert SVG images to PNG
    format.
  • +23/-0   
    fetchers.ts
    Refactor Customer Data Schema Definition                                 

    apps/backoffice-v2/src/domains/customer/fetchers.ts

  • Refactored the schema definition for customer data into a separate
    constant CustomerSchema.
  • Updated the fetchCustomer function to use the new CustomerSchema.
  • +19/-15 
    fetchers.ts
    Enhance Workflow Fetchers with New Schemas and Fields       

    apps/backoffice-v2/src/domains/workflows/fetchers.ts

  • Added imports and adjusted the order of existing imports.
  • Introduced new schema WorkflowDefinitionByIdSchema and AmlSchema.
  • Added a new optional field childWorkflows to BaseWorkflowByIdSchema.
  • +8/-7     
    useUbosRegistryProvidedBlock.tsx
    Export Ubo Type from useUbosRegistryProvidedBlock Hook     

    apps/backoffice-v2/src/lib/blocks/hooks/useUbosRegistryProvidedBlock/useUbosRegistryProvidedBlock.tsx

    • Changed the type Ubo from local to exported.
    +3/-3     
    Case.Actions.tsx
    Integrate CaseOptions Component into Case Actions               

    apps/backoffice-v2/src/pages/Entity/components/Case/Case.Actions.tsx

  • Added import for CaseOptions.
  • Modified class names to adjust layout.
  • Integrated CaseOptions component into the UI.
  • +3/-1     
    CaseOptions.tsx
    Implement CaseOptions Component with PDF Download               

    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/CaseOptions.tsx

  • Implemented CaseOptions component with dropdown menu for downloading
    PDF certificates.
  • +27/-0   
    company-ownership-page.pdf.tsx
    Add Company Ownership PDF Rendering Logic                               

    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/company-ownership-page.pdf.tsx

    • Added PDF rendering logic for company ownership data.
    +50/-0   
    company-sanctions-page.pdf.tsx
    Add Company Sanctions PDF Rendering Logic                               

    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/company-sanctions-page.pdf.tsx

    • Added PDF rendering logic for company sanctions data.
    +55/-0   
    identity-verifications-page.pdf.tsx
    Add Identity Verifications PDF Rendering Logic                     

    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/identity-verifications-page.pdf.tsx

    • Added PDF rendering logic for identity verifications data.
    +69/-0   
    individual-sanctions-page.pdf.tsx
    Add Individual Sanctions PDF Rendering Logic                         

    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/individual-sanctions-page.pdf.tsx

    • Added PDF rendering logic for individual sanctions data.
    +119/-0 
    pdf-renderer.abstract.ts
    Introduce Abstract PDF Renderer Class                                       

    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/pdf-renderer.abstract.ts

  • Introduced an abstract class IPDFRenderer for PDF rendering
    operations.
  • +19/-0   
    registry-page.pdf.tsx
    Add Registry Page PDF Rendering Logic                                       

    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/registry-page.pdf.tsx

    • Added PDF rendering logic for registry page data.
    +82/-0   
    title-page.pdf.tsx
    Add Title Page PDF Rendering Logic                                             

    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/title-page.pdf.tsx

    • Added PDF rendering logic for title page data.
    +32/-0   
    useCaseOptionsLogic.tsx
    Implement PDF Certificate Generation and Download Logic   

    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/useCaseOptionsLogic.tsx

  • Implemented logic for generating and downloading a PDF certificate.
  • +72/-0   

    PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    Summary by CodeRabbit

    • New Features

      • Introduced PDF generation functionality with options for various document types (e.g., Company Ownership, Sanctions, Identity Verifications).
      • Added a dropdown menu component for generating and opening PDF certificates.
      • Implemented SVG to PNG conversion utility.
    • Bug Fixes

      • Added error message for failed PDF certificate opening.
    • Enhancements

      • Improved workflow schema with optional child workflows.
      • Updated case actions to include new PDF options.
    • Dependencies

      • Added new dependencies for PDF rendering and utility functions.

    @chesterkmr chesterkmr requested a review from Omri-Levy May 1, 2024 09:53
    Copy link

    changeset-bot bot commented May 1, 2024

    ⚠️ No Changeset found

    Latest commit: c4f941c

    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 May 1, 2024

    Walkthrough

    The recent updates to the backoffice-v2 application introduce new dependencies for PDF handling, including @ballerine/react-pdf-toolkit and @react-pdf/renderer. Enhancements include new utilities for SVG to PNG conversion and value handling, as well as a comprehensive set of components and hooks for generating and rendering PDF documents with various data schemas. These changes improve the application's ability to generate detailed PDF reports and certificates.

    Changes

    File(s) Change Summary
    apps/backoffice-v2/package.json Added new dependencies: @ballerine/react-pdf-toolkit, @react-pdf/renderer, lodash, and @types/lodash.
    apps/backoffice-v2/src/domains/workflows/fetchers.ts Reordered imports, updated schemas, removed WorkflowByIdSchema, and added childWorkflows to BaseWorkflowByIdSchema.
    apps/backoffice-v2/src/pages/Entity/components/Case/Case.Actions.tsx Added CaseOptions component import and included <CaseOptions /> in the Actions component.
    apps/backoffice-v2/public/locales/en/toast.json Added new key-value pair "pdf_certificate" with the error message "Failed to open PDF certificate.".
    apps/backoffice-v2/src/common/utils/svg-to-png/svg-to-png.ts Introduced svgToPng function to convert SVG to PNG.
    apps/backoffice-v2/src/common/utils/value-or-none/value-or-none.ts Introduced valueOrNone function to handle value fallback scenarios.
    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/CaseOptions.tsx Introduced CaseOptions component for generating and opening PDF certificates.
    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic.tsx Introduced useCaseOptionsLogic hook for managing case options logic.
    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/mutations/... Introduced useGeneratePDFMutation hook for generating PDFs.
    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/... Introduced various PDF renderer classes (CompanyOwnershipPagePDF, CompanySanctionsPagePDF, IdentityVerificationsPagePDF, IndividualSanctionsPagePDF).
    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/TitlePage/TitlePage.tsx Introduced TitlePage component for generating title pages in PDFs.
    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/TitlePage/index.ts Exported TitlePage module.
    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/schemas/base-case-information-pdf.schema.ts Introduced BaseCaseInformationPdfSchema and TBaseCaseInformationPdf for base case information in PDFs.

    Poem

    In the back office, changes bloom,
    With PDFs now in full zoom.
    From workflows clear to cases bright,
    New tools ensure all's set right.
    With logic hooks and renderers keen,
    Our documents now shine, pristine.
    So here's a cheer, a rabbit's glee,
    For all the code, from you and me! 🐇📜✨


    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>.
      • 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 generate interesting stats about this repository and render them as a table.
      • @coderabbitai show all the console.log statements in this repository.
      • @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 as PR comments)

    • @coderabbitai pause to pause the reviews on a PR.
    • @coderabbitai resume to resume the paused reviews.
    • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
    • @coderabbitai full review to do a full review from scratch and review all the files again.
    • @coderabbitai summary to regenerate the summary of the PR.
    • @coderabbitai resolve resolve all the CodeRabbit review comments.
    • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
    • @coderabbitai help to get help.

    Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

    CodeRabbit Configration 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.

    @github-actions github-actions bot added the enhancement New feature or request label May 1, 2024
    Copy link
    Contributor

    github-actions bot commented May 1, 2024

    PR Description updated to latest commit (da3d438)

    1 similar comment
    Copy link
    Contributor

    github-actions bot commented May 1, 2024

    PR Description updated to latest commit (da3d438)

    Copy link
    Contributor

    github-actions bot commented May 1, 2024

    PR Review

    (Review updated until commit 8f21348)

    ⏱️ Estimated effort to review [1-5]

    4, due to the extensive changes across multiple files involving complex logic related to PDF generation and data handling. The PR introduces new components, utilities, and modifies existing structures which require careful review to ensure functionality and integration.

    🧪 Relevant tests

    No

    🔍 Possible issues

    Possible Bug: The canvas element created in svgToPng is not appended to the document before being removed, which could lead to errors or unexpected behavior.

    Data Handling Concern: The data extraction and transformation logic in PDF rendering classes are quite complex and tightly coupled with specific data structures, which might lead to maintenance challenges or bugs if the data structure changes.

    🔒 Security concerns

    No

    Code feedback:
    relevant fileapps/backoffice-v2/src/common/utils/svg-to-png/svg-to-png.ts
    suggestion      

    Consider appending the canvas to the document body before removing it to avoid potential errors in the DOM manipulation process. This change ensures that the canvas element is properly managed in the DOM lifecycle. [important]

    relevant linedocument.body.removeChild(canvas);

    relevant fileapps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/company-ownership-page.pdf.tsx
    suggestion      

    Implement error handling for data validation in the isValid method to manage exceptions or errors that may occur during the schema validation process. This will improve the robustness of the PDF rendering process. [important]

    relevant lineCompanyOwnershipSchema.parse(data);

    relevant fileapps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/pdf-renderer.abstract.ts
    suggestion      

    Add error handling for the svgToPng call within getLogoUrl to gracefully handle cases where the logo URL might be invalid or the conversion fails. This prevents the entire PDF generation process from failing due to issues with logo conversion. [important]

    relevant linereturn svgToPng(this.customer?.logoImageUri || '');

    relevant fileapps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/useCaseOptionsLogic.tsx
    suggestion      

    Refactor the genereateAndDownloadPDFCertificate function to separate concerns, such as data preparation, PDF generation, and file handling, into distinct functions or methods. This enhances readability and maintainability. [medium]

    relevant lineconst genereateAndDownloadPDFCertificate = useCallback(async () => {


    ✨ Review tool usage guide:

    Overview:
    The review tool scans the PR code changes, and generates a PR review which includes several types of feedbacks, such as possible PR issues, security threats and relevant test in the PR. More feedbacks can be added by configuring the tool.

    The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on any PR.

    • When commenting, to edit configurations related to the review tool (pr_reviewer section), use the following template:
    /review --pr_reviewer.some_config1=... --pr_reviewer.some_config2=...
    
    [pr_reviewer]
    some_config1=...
    some_config2=...
    

    See the review usage page for a comprehensive guide on using this tool.

    Copy link
    Contributor

    github-actions bot commented May 1, 2024

    Persistent review updated to latest commit 8f21348

    Copy link
    Contributor

    github-actions bot commented May 1, 2024

    PR Code Suggestions

    CategorySuggestions                                                                                                                                                       
    Bug
    Ensure the canvas is added to the document before removal to prevent errors.

    It's important to add the newly created canvas element to the document body before calling
    removeChild to avoid a potential error if the canvas is not found in the document. This
    ensures that the canvas is part of the DOM when attempting to remove it.

    apps/backoffice-v2/src/common/utils/svg-to-png/svg-to-png.ts [16]

    +document.body.appendChild(canvas);
     document.body.removeChild(canvas);
     
    Rename the static property to correctly represent its content.

    The PDF_NAME static property is misleadingly named 'titlePage' which might be a copy-paste
    error from another renderer. It should be renamed to reflect the actual content it
    represents, such as 'registryPage'.

    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/registry-page.pdf.tsx [11]

    -static PDF_NAME = 'titlePage';
    +static PDF_NAME = 'registryPage';
     
    Add null check in isEmpty method to prevent potential runtime errors.

    The method isEmpty should handle cases where data might be null or undefined to prevent
    runtime errors. You should add a check at the beginning of the method to return true if
    data is falsy.

    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/registry-page.pdf.tsx [58]

     private isEmpty(data: TRegistryInformationData) {
    +  if (!data) return true;
       const values = [
         data.registrationNumber,
         data.incorporationDate,
         data.companyType,
         data.companyStatus,
         data.registrationAddress,
         data.registryPage,
         data.lastUpdate,
         data.registeredAt,
       ];
     
    Best practice
    Clean up image resources to prevent memory leaks.

    To prevent potential memory leaks, it's advisable to clean up the img element by
    nullifying its src and removing event listeners after the image is loaded or if an error
    occurs.

    apps/backoffice-v2/src/common/utils/svg-to-png/svg-to-png.ts [21]

    +img.onload = () => {
    +  // existing onload code
    +  img.src = '';
    +  img.onload = null;
    +  img.onerror = null;
    +};
    +img.onerror = error => {
    +  // existing onerror code
    +  img.src = '';
    +  img.onload = null;
    +  img.onerror = null;
    +};
     img.src = imageUrl;
     
    Enforce the implementation of PDF_NAME in subclasses to prevent runtime errors.

    To ensure that the PDF_NAME static property is not accidentally left unassigned in
    subclasses, consider making PDF_NAME an abstract getter in the IPDFRenderer class. This
    enforces that each subclass must provide its own implementation.

    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/pdf-renderer.abstract.ts [6]

    -static PDF_NAME: string;
    +abstract get PDF_NAME(): string;
     
    Use predefined style objects to enhance performance and code clarity.

    Replace inline style definitions with a predefined style object to improve readability and
    performance by reducing the object creation overhead on each render.

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/CompanySanctionsPage/CompanySanctionsPage.tsx [22]

    -<View style={tw('mb-3')}>
    +const viewStyle = tw('mb-3');
    +...
    +<View style={viewStyle}>
     
    Standardize the date format string across the application for consistency.

    Use a constant for the date format string used in the subtitle of
    CaseInformationPageSectionHeader to ensure consistency across different components or
    files.

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/CompanySanctionsPage/CompanySanctionsPage.tsx [31]

    -subtitle={`Check conducted at: ${new Date().toISOString()}`}
    +const DATE_FORMAT = 'yyyy-MM-ddTHH:mm:ss.sssZ';
    +...
    +subtitle={`Check conducted at: ${new Date().toISOString(DATE_FORMAT)}`}
     
    Define a constant for common text styles to reduce duplication and ease future modifications.

    Use a constant for repeated style values to avoid duplication and facilitate easier
    updates or theming in the future.

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/IdentityVerificationsPage/components/IdentityItem/IdentityItem.tsx [26-72]

    -<Typography styles={[tw('text-[8px] leading-[1.45rem]')]} weight="bold">
    +<Typography styles={[commonTextStyle]} weight="bold">
     
    Replace hardcoded widths with responsive design or theming system for better adaptability and consistency.

    Avoid using hardcoded widths in the styles. Consider using a responsive design approach or
    a theming system to handle different screen sizes and maintain consistency across the
    application.

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/IdentityVerificationsPage/components/IdentityItem/IdentityItem.tsx [25-126]

    -<View style={tw('w-[80px]')}>
    -<View style={tw('w-[400px]')}>
    +<View style={tw('w-small')}>
    +<View style={tw('w-large')}>
     
    Enhancement
    Improve type safety by specifying a more detailed schema for childWorkflows.

    Consider using a more specific type than z.any() for the childWorkflows field in the
    schema to enhance type safety and validation.

    apps/backoffice-v2/src/domains/customer/fetchers.ts [97]

    -childWorkflows: z.any().optional(),
    +childWorkflows: z.array(z.object({
    +  id: z.string(),
    +  status: z.enum(['Active', 'Inactive']),
    +  // Add more specific fields here
    +})).optional(),
     
    Usability
    Enhance user feedback by disabling the options button during PDF generation.

    To improve user experience, consider disabling the button while the PDF is generating,
    providing feedback that an operation is in progress.

    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/CaseOptions.tsx [14]

    -<Button variant="outline">Options</Button>
    +<Button variant="outline" disabled={isGeneratingPDF}>{isGeneratingPDF ? 'Generating...' : 'Options'}</Button>
     
    Maintainability
    Refactor data extraction to a separate method to improve code clarity and maintainability.

    The getData method uses multiple get calls with default values that could be simplified or
    managed more cleanly using a utility function or by restructuring the data access pattern
    to reduce redundancy and improve maintainability.

    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/registry-page.pdf.tsx [23-49]

    -const pdfData: TRegistryInformationData = {
    -  companyName: get(this.workflow.context, 'entity.data.companyName', ''),
    -  creationDate: new Date(),
    -  logoUrl: await this.getLogoUrl(),
    -  registrationNumber: get(this.workflow.context, 'entity.data.registrationNumber', ''),
    -  incorporationDate: get(
    -    this.workflow.context,
    -    'entity.data.additionalInfo.dateOfEstablishment',
    -    null,
    -  ),
    -  companyType: get(this.workflow.context, 'entity.data.businessType', ''),
    -  companyStatus: get(this.workflow.context, 'entity.data.status', ''),
    -  registrationAddress: [
    -    get(this.workflow.context, 'entity.data.headquarters.street', ''),
    -    get(this.workflow.context, 'entity.data.headquarters.streetNumber', ''),
    -    get(this.workflow.context, 'entity.data.headquarters.city', ''),
    -    get(this.workflow.context, 'entity.data.headquarters.country', ''),
    -    get(this.workflow.context, 'entity.data.headquarters.postalCode', ''),
    -  ]
    -    .filter(Boolean)
    -    .join(', '),
    -  registryPage: get(this.workflow.context, 'entity.data.registryPage', ''),
    -  lastUpdate: new Date(),
    -  registeredAt: get(this.workflow.context, 'entity.data.registeredAt', ''),
    -};
    +const pdfData: TRegistryInformationData = this.extractPDFData();
     
    Refactor inline filtering logic into a separate utility function for better reusability and testability.

    Extract the inline function for filtering valid URLs to a separate utility function to
    improve code reusability and testing.

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/CompanySanctionsPage/CompanySanctionsPage.tsx [63]

    -sources={item.sources.filter(source => isValidUrl(source))}
    +sources={filterValidUrls(item.sources)}
     
    Improve code readability by using more descriptive variable names.

    Consider using a more descriptive variable name than tw for the Tailwind CSS utility
    function to enhance code readability.

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/CompanySanctionsPage/CompanySanctionsPage.tsx [22]

    -style={tw('mb-3')}
    +style={tailwind('mb-3')}
     
    Replace inline date formatting with a utility function to enhance maintainability and consistency.

    Consider using a utility function to format dates instead of repeating new
    Date(date).toISOString() inline. This will improve code maintainability and make it easier
    to apply consistent date formatting or adjustments across your application.

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/IdentityVerificationsPage/components/IdentityItem/IdentityItem.tsx [31-97]

    -<ValueOrNone value={checkDate ? new Date(checkDate).toISOString() : undefined} />
    -<ValueOrNone value={dateOfBirth ? new Date(dateOfBirth).toISOString() : undefined} />
    +<ValueOrNone value={formatDate(checkDate)} />
    +<ValueOrNone value={formatDate(dateOfBirth)} />
     
    Refactor status-based conditional rendering into a separate component for clarity and reusability.

    Refactor the repeated conditional rendering of Typography components for different
    statuses into a separate function or component. This will make the code cleaner and more
    modular.

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/IdentityVerificationsPage/components/IdentityItem/IdentityItem.tsx [41-56]

    -{status === 'approved' && (
    -  <Typography
    -    styles={[tw('text-[8px] leading-[1.45rem] text-[#00BD59]')]}
    -    weight="bold"
    -  >
    -    Approved
    -  </Typography>
    -)}
    -{status === 'rejected' && (
    -  <Typography
    -    styles={[tw('text-[8px] leading-[1.45rem] text-[#DF2222]')]}
    -    weight="bold"
    -  >
    -    Rejected
    -  </Typography>
    -)}
    +<StatusTypography status={status} />
     
    Extract repeated view structures into a separate component to enhance code modularity and readability.

    Extract the repeated View structure used for displaying attributes into a separate
    component to reduce code duplication and improve readability.

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/IdentityVerificationsPage/components/IdentityItem/IdentityItem.tsx [24-32]

    -<View style={tw('flex flex-row')}>
    -  <View style={tw('w-[80px]')}>
    -    <Typography styles={[tw('text-[8px] leading-[1.45rem]')]} weight="bold">
    -      Checked at
    -    </Typography>
    -  </View>
    -  <View style={tw('w-[400px]')}>
    -    <ValueOrNone value={checkDate ? new Date(checkDate).toISOString() : undefined} />
    -  </View>
    -</View>
    +<AttributeRow label="Checked at" value={formatDate(checkDate)} />
     
    Error handling
    Add error handling in the isValid method to manage exceptions gracefully.

    The isValid method should handle potential exceptions thrown by
    TitlePageSchema.parse(data) to prevent the application from crashing due to unhandled
    exceptions.

    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/registry-page.pdf.tsx [54-56]

     isValid(data: TRegistryInformationData) {
    -  TitlePageSchema.parse(data);
    +  try {
    +    TitlePageSchema.parse(data);
    +  } catch (error) {
    +    console.error('Data validation failed:', error);
    +    throw new Error('Invalid data provided for PDF generation.');
    +  }
     }
     
    Improve error handling in the render method to handle invalid data cases more effectively.

    The render method should handle the case where pdfData is invalid more gracefully, perhaps
    by logging an error or displaying a message, instead of potentially rendering an empty or
    incorrect page.

    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/registry-page.pdf.tsx [13-19]

     async render(): Promise<JSX.Element> {
       const pdfData = await this.getData();
    -  this.isValid(pdfData);
    +  if (!this.isValid(pdfData)) {
    +    console.error('Invalid PDF data:', pdfData);
    +    return <ErrorPage message="Invalid data provided for PDF rendering." />;
    +  }
       if (this.isEmpty(pdfData)) return <EmptyRegistryInformationPage data={pdfData} />;
       return <RegistryInformationPage data={pdfData} />;
     }
     
    Performance
    Improve rendering performance by memoizing the CaseInformationPageHeader component.

    Consider using a memoization technique for the CaseInformationPageHeader component to
    prevent unnecessary re-renders when the parent component re-renders but the props
    companyLogo and companyName haven't changed.

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/CompanySanctionsPage/CompanySanctionsPage.tsx [23]

    -<CaseInformationPageHeader companyLogo={logoUrl} companyName={companyName} />
    +<CaseInformationPageHeader companyLogo={logoUrl} companyName={companyName} memoized />
     

    ✨ Improve tool usage guide:

    Overview:
    The improve tool scans the PR code changes, and automatically generates suggestions for improving the PR code. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on a PR.

    • When commenting, to edit configurations related to the improve tool (pr_code_suggestions section), use the following template:
    /improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=...
    
    [pr_code_suggestions]
    some_config1=...
    some_config2=...
    

    See the improve usage page for a comprehensive guide on using this tool.

    Copy link
    Contributor

    github-actions bot commented May 1, 2024

    PR Code Suggestions

    CategorySuggestions                                                                                                                                                       
    Bug
    Ensure the canvas is properly managed in the DOM.

    Ensure that the canvas element is appended to the document body before removing it to
    avoid errors.

    apps/backoffice-v2/src/common/utils/svg-to-png/svg-to-png.ts [16]

    +document.body.appendChild(canvas);
     document.body.removeChild(canvas);
     
    Correct the PDF name to match the actual PDF being rendered.

    The static variable PDF_NAME is misleadingly set to 'titlePage' which might be a
    copy-paste error from another renderer. It should reflect the actual PDF being rendered,
    which is the 'RegistryPage'.

    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/registry-page.pdf.tsx [11]

    -static PDF_NAME = 'titlePage';
    +static PDF_NAME = 'registryPage';
     
    Use the correct schema for data validation in the isValid method.

    The isValid method uses TitlePageSchema to validate pdfData which might not be appropriate
    for RegistryPagePDF. Ensure that the correct schema is used for validation to prevent
    runtime errors.

    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/registry-page.pdf.tsx [55]

    -TitlePageSchema.parse(data);
    +RegistryPageSchema.parse(data);
     
    Add a check to ensure sources is an array before filtering to prevent runtime errors.

    To ensure that the isValidUrl function is only called with valid inputs, add a check to
    ensure that sources is an array of strings before filtering. This prevents potential
    runtime errors if sources is not in the expected format.

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/CompanySanctionsPage/CompanySanctionsPage.tsx [63]

    -sources={item.sources.filter(source => isValidUrl(source))}
    +sources={Array.isArray(item.sources) ? item.sources.filter(source => isValidUrl(source)) : []}
     
    Enhancement
    Add error handling for unsupported 2D context.

    Add error handling for the case when getContext('2d') returns null to prevent runtime
    errors.

    apps/backoffice-v2/src/common/utils/svg-to-png/svg-to-png.ts [7]

     const context = canvas.getContext('2d');
    +if (!context) {
    +  reject(new Error('2D context not supported'));
    +  return;
    +}
     
    Refine the condition in isEmpty method to handle non-string falsy values appropriately.

    The method isEmpty checks if all values are falsy or empty arrays, but does not handle
    cases where values might be non-string falsy values like 0 or false which might be valid
    in some contexts. Consider refining the condition to handle such cases or document the
    expected data types and values.

    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/registry-page.pdf.tsx [70-76]

     if (
       values.every(value => {
         if (Array.isArray(value) && !value.length) return true;
    -    return !value;
    +    return value === null || value === undefined || value === '';
       })
     ) {
       return true;
     }
     
    Simplify conditional rendering with a utility component for status.

    Replace inline conditional rendering with a more concise and readable utility function
    that handles the rendering logic based on the status.

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/IdentityVerificationsPage/components/IdentityItem/IdentityItem.tsx [41-57]

    -{status === 'approved' && (
    -  <Typography
    -    styles={[tw('text-[8px] leading-[1.45rem] text-[#00BD59]')]}
    -    weight="bold"
    -  >
    -    Approved
    -  </Typography>
    -)}
    -{status === 'rejected' && (
    -  <Typography
    -    styles={[tw('text-[8px] leading-[1.45rem] text-[#DF2222]')]}
    -    weight="bold"
    -  >
    -    Rejected
    -  </Typography>
    -)}
    -{!status && <ValueOrNone value={status} />}
    +<StatusTypography status={status} />
     
    Performance
    Optimize memory usage by managing blob URLs.

    Use URL.createObjectURL and URL.revokeObjectURL for handling image URLs to manage memory
    more efficiently.

    apps/backoffice-v2/src/common/utils/svg-to-png/svg-to-png.ts [21]

    -img.src = imageUrl;
    +const blob = new Blob([imageUrl], { type: 'image/svg+xml' });
    +img.src = URL.createObjectURL(blob);
    +img.onload = () => {
    +  URL.revokeObjectURL(img.src);
    +  // existing onload code
    +};
     
    Improve performance by memoizing the date string calculation.

    Consider using memoization for the new Date().toISOString() call in the subtitle of
    CaseInformationPageSectionHeader to avoid recalculating the date string on every render,
    which can improve performance in cases where the component re-renders frequently.

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/CompanySanctionsPage/CompanySanctionsPage.tsx [31]

    -subtitle={`Check conducted at: ${new Date().toISOString()}`}
    +subtitle={`Check conducted at: ${useMemo(() => new Date().toISOString(), [])}`}
     
    Maintainability
    Use constants instead of hardcoded strings.

    Replace the 'Anonymous' string with a constant to avoid hardcoding and improve
    maintainability.

    apps/backoffice-v2/src/common/utils/svg-to-png/svg-to-png.ts [4]

    -img.crossOrigin = 'Anonymous';
    +const ANONYMOUS = 'Anonymous';
    +img.crossOrigin = ANONYMOUS;
     
    Abstract repetitive get operations into a helper function for cleaner and more maintainable code.

    The method getData uses multiple get calls with default values that could be simplified or
    abstracted to reduce redundancy and improve maintainability. Consider creating a helper
    function to handle these get operations.

    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/registry-page.pdf.tsx [23-51]

    -const pdfData: TRegistryInformationData = {
    -  companyName: get(this.workflow.context, 'entity.data.companyName', ''),
    -  creationDate: new Date(),
    -  logoUrl: await this.getLogoUrl(),
    -  registrationNumber: get(this.workflow.context, 'entity.data.registrationNumber', ''),
    -  incorporationDate: get(
    -    this.workflow.context,
    -    'entity.data.additionalInfo.dateOfEstablishment',
    -    null,
    -  ),
    -  companyType: get(this.workflow.context, 'entity.data.businessType', ''),
    -  companyStatus: get(this.workflow.context, 'entity.data.status', ''),
    -  registrationAddress: [
    -    get(this.workflow.context, 'entity.data.headquarters.street', ''),
    -    get(this.workflow.context, 'entity.data.headquarters.streetNumber', ''),
    -    get(this.workflow.context, 'entity.data.headquarters.city', ''),
    -    get(this.workflow.context, 'entity.data.headquarters.country', ''),
    -    get(this.workflow.context, 'entity.data.headquarters.postalCode', ''),
    -  ]
    -    .filter(Boolean)
    -    .join(', '),
    -  registryPage: get(this.workflow.context, 'entity.data.registryPage', ''),
    -  lastUpdate: new Date(),
    -  registeredAt: get(this.workflow.context, 'entity.data.registeredAt', ''),
    -};
    +const pdfData: TRegistryInformationData = this.createPDFData();
     
    Extract inline styles into a separate style object for better maintainability.

    To enhance code readability and maintainability, consider extracting the inline styles
    used in the View components into a separate style object or file. This approach helps in
    managing styles more efficiently and makes the JSX cleaner.

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/CompanySanctionsPage/CompanySanctionsPage.tsx [22]

    -<View style={tw('mb-3')}>
    +<View style={styles.marginBottom}>
     
    Use a dedicated date formatting function to improve code maintainability and error handling.

    Consider using a utility function to format dates instead of inline new
    Date().toISOString() to handle potential exceptions and ensure consistent date formatting
    across your application.

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/IdentityVerificationsPage/components/IdentityItem/IdentityItem.tsx [31-97]

    -<ValueOrNone value={checkDate ? new Date(checkDate).toISOString() : undefined} />
    -<ValueOrNone value={dateOfBirth ? new Date(dateOfBirth).toISOString() : undefined} />
    +<ValueOrNone value={formatDate(checkDate)} />
    +<ValueOrNone value={formatDate(dateOfBirth)} />
     
    Refactor repetitive field rendering into a reusable sub-component.

    To improve readability and reduce redundancy, consider creating a sub-component for
    rendering each field row, passing field name and value as props.

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/IdentityVerificationsPage/components/IdentityItem/IdentityItem.tsx [24-32]

    -<View style={tw('flex flex-row')}>
    -  <View style={tw('w-[80px]')}>
    -    <Typography styles={[tw('text-[8px] leading-[1.45rem]')]} weight="bold">
    -      Checked at
    -    </Typography>
    -  </View>
    -  <View style={tw('w-[400px]')}>
    -    <ValueOrNone value={checkDate ? new Date(checkDate).toISOString() : undefined} />
    -  </View>
    -</View>
    +<FieldRow label="Checked at" value={checkDate ? new Date(checkDate).toISOString() : undefined} />
     
    Security
    Validate input image format before processing.

    Add MIME type checks for the input imageUrl to ensure it's a valid SVG before processing.

    apps/backoffice-v2/src/common/utils/svg-to-png/svg-to-png.ts [21]

    +if (!imageUrl.endsWith('.svg')) {
    +  reject(new Error('Invalid SVG format'));
    +  return;
    +}
     img.src = imageUrl;
     
    Best practice
    Enhance type safety and readability in the isEmpty method using TypeScript's utility types.

    The method isEmpty could be improved by using TypeScript's utility types for better type
    safety and readability. Consider using Partial or similar to ensure type safety.

    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/registry-page.pdf.tsx [58-81]

    -private isEmpty(data: TRegistryInformationData) {
    -  const values = [
    -    data.registrationNumber,
    -    data.incorporationDate,
    -    data.companyType,
    -    data.companyStatus,
    -    data.registrationAddress,
    -    data.registryPage,
    -    data.lastUpdate,
    -    data.registeredAt,
    -  ];
    -  if (
    -    values.every(value => {
    -      if (Array.isArray(value) && !value.length) return true;
    -      return !value;
    -    })
    -  ) {
    -    return true;
    -  }
    -  return false;
    +private isEmpty(data: Partial<TRegistryInformationData>) {
    +  const values = Object.values(data);
    +  return values.every(value => !value || (Array.isArray(value) && !value.length));
     }
     
    Use a more robust key for list items to prevent potential issues with duplicate names.

    Consider using a more descriptive key than item.name in the list rendering of
    CompanySanctionsMatchSection. Using a combination of name and index or a unique identifier
    would be more robust, especially if names can be duplicated.

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/CompanySanctionsPage/CompanySanctionsPage.tsx [57]

    -key={item.name}
    +key={`${item.name}-${index}`}
     
    Define a constant for repeated style properties to enhance maintainability.

    Use a constant for repeated style values to ensure consistency and ease future
    modifications.

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/IdentityVerificationsPage/components/IdentityItem/IdentityItem.tsx [26-72]

    -<Typography styles={[tw('text-[8px] leading-[1.45rem]')]} weight="bold">
    +<Typography styles={[tw(STANDARD_TEXT_STYLE)]} weight="bold">
     
    Use descriptive prop names to improve code clarity.

    Consider using a more descriptive prop name than item to enhance code readability and
    maintainability.

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/IdentityVerificationsPage/components/IdentityItem/IdentityItem.tsx [11]

    -export const IdentityItem: FunctionComponent<IIdentityItemProps> = ({ item }) => {
    +export const IdentityItem: FunctionComponent<IIdentityItemProps> = ({ identityVerification }) => {
     
    Possible issue
    Add safe navigation to handle potential undefined values in the sanctions array.

    It's a good practice to handle potential errors or exceptions when working with dynamic
    data. Consider adding error handling for the case where sanctions might be undefined or
    not an array, which could lead to runtime errors.

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/CompanySanctionsPage/CompanySanctionsPage.tsx [55]

    -{sanctions.map((item, index) => (
    +{sanctions?.map((item, index) => (
     

    ✨ Improve tool usage guide:

    Overview:
    The improve tool scans the PR code changes, and automatically generates suggestions for improving the PR code. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on a PR.

    • When commenting, to edit configurations related to the improve tool (pr_code_suggestions section), use the following template:
    /improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=...
    
    [pr_code_suggestions]
    some_config1=...
    some_config2=...
    

    See the improve usage page for a comprehensive guide on using this tool.

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

    Out of diff range and nitpick comments (6)
    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/TitlePage/title-page.schema.ts (1)

    4-4: Consider adding a comment explaining the purpose of extending BaseCaseInformationPdfSchema with an empty object, especially if future properties are expected to be added.

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/CompanySanctionsPage/empty-company-sanctions.schema.ts (1)

    4-4: Consider adding a comment explaining the purpose of extending BaseCaseInformationPdfSchema with an empty object, especially if future properties are expected to be added.

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/CompanyOwnershipPage/empty-company-ownership-page.schema.ts (1)

    4-4: Consider adding a comment explaining the purpose of extending BaseCaseInformationPdfSchema with an empty object, especially if future properties are expected to be added.

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/IdentityVerificationsPage/empty-identity-verfications.schema.ts (1)

    4-4: Consider adding a comment explaining the purpose of extending BaseCaseInformationPdfSchema with an empty object, especially if future properties are expected to be added.

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/IndividualSanctionsPage/components/IndividualSanctionsItem/ValueOrNone.tsx (1)

    27-27: Ensure type safety by explicitly handling the type conversion of valueOrNone(value).

    Consider using TypeScript's type assertion or a type guard to ensure the type of valueOrNone(value) matches AnyChildren.

    apps/backoffice-v2/src/lib/blocks/hooks/useUbosRegistryProvidedBlock/useUbosRegistryProvidedBlock.tsx (1)

    5-5: Consider adding JSDoc comments to the useUbosRegistryProvidedBlock hook to improve code documentation and developer understanding.

    Add JSDoc comments explaining the parameters and the return type of the useUbosRegistryProvidedBlock hook.

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

    Outside diff range and nitpick comments (1)
    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/useCaseOptionsLogic.tsx (1)

    33-64: Consider using React Query for state management in asynchronous operations.

    Given the complexity of state management in asynchronous operations, consider using React Query. It provides built-in mechanisms for loading states, caching, and error handling, which could simplify the implementation of useCaseOptionsLogic.

    Review Details

    Configuration used: CodeRabbit UI
    Review profile: CHILL

    Commits Files that changed from the base of the PR and between d904642 and 368be9d.
    Files selected for processing (8)
    • apps/backoffice-v2/src/main.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/company-ownership-page.pdf.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/company-sanctions-page.pdf.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/identity-verifications-page.pdf.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/individual-sanctions-page.pdf.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/registry-page.pdf.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/useCaseOptionsLogic.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/components/CaseInformationPageContainer/CaseInformationPageContainer.tsx (1 hunks)
    Additional comments not posted (2)
    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/components/CaseInformationPageContainer/CaseInformationPageContainer.tsx (1)

    5-9: The implementation of CaseInformationPageContainer looks clean and well-integrated with the PDF toolkit.

    apps/backoffice-v2/src/main.tsx (1)

    10-11: The integration of registerFont for PDF rendering looks correct. Ensure that the font registration is tested across different environments.

    Also applies to: 17-17

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

    Review Details

    Configuration used: CodeRabbit UI
    Review profile: CHILL

    Commits Files that changed from the base of the PR and between d904642 and 4399427.
    Files ignored due to path filters (1)
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/assets/title-page-ballerine-logo.png is excluded by !**/*.png
    Files selected for processing (21)
    • apps/backoffice-v2/src/main.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/company-ownership-page.pdf.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/company-sanctions-page.pdf.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/identity-verifications-page.pdf.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/individual-sanctions-page.pdf.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/registry-page.pdf.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/useCaseOptionsLogic.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/components/CaseInformationPageContainer/CaseInformationPageContainer.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/components/CaseInformationPageSection/CaseInformationPageSection.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/CompanyOwnershipPage/empty-company-ownership-page.schema.ts (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/CompanySanctionsPage/EmptyCompanySanctionsPage.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/CompanySanctionsPage/empty-company-sanctions.schema.ts (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/IdentityVerificationsPage/empty-identity-verfications.schema.ts (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/IndividualSanctionsPage/EmptyIndividualSanctionsPage.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/IndividualSanctionsPage/IndividualSanctionsPage.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/IndividualSanctionsPage/empty-individual-sanctions.schema.ts (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/RegistryInformationPage/RegistryInformationPage.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/RegistryInformationPage/empty-registry-information-page.schema.ts (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/RegistryInformationPage/registry-information.schema.ts (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/RegistryInformationPage/utils/create-registry-items.ts (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/TitlePage/title-page.schema.ts (1 hunks)
    Files skipped from review due to trivial changes (6)
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/CompanyOwnershipPage/empty-company-ownership-page.schema.ts
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/CompanySanctionsPage/empty-company-sanctions.schema.ts
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/IdentityVerificationsPage/empty-identity-verfications.schema.ts
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/IndividualSanctionsPage/empty-individual-sanctions.schema.ts
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/RegistryInformationPage/empty-registry-information-page.schema.ts
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/TitlePage/title-page.schema.ts
    Additional comments not posted (11)
    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/components/CaseInformationPageSection/CaseInformationPageSection.tsx (1)

    5-6: LGTM! The component is well-structured and follows best practices for React components.

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/components/CaseInformationPageContainer/CaseInformationPageContainer.tsx (1)

    5-8: LGTM! The component is well-structured and follows best practices for React components.

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/RegistryInformationPage/registry-information.schema.ts (1)

    16-16: The type export is correctly implemented and follows TypeScript best practices.

    apps/backoffice-v2/src/main.tsx (1)

    17-17: The font registration for PDF rendering is correctly implemented.

    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/company-ownership-page.pdf.tsx (1)

    11-45: The implementation of the PDF rendering class is robust and follows best practices for asynchronous data handling and rendering in React.

    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/company-sanctions-page.pdf.tsx (1)

    11-50: The implementation of the PDF rendering class is robust and follows best practices for asynchronous data handling and rendering in React.

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/RegistryInformationPage/utils/create-registry-items.ts (1)

    4-71: The implementation of registryItemsAdapter effectively handles potential undefined values and maps the data correctly.

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/IndividualSanctionsPage/EmptyIndividualSanctionsPage.tsx (1)

    16-43: The EmptyIndividualSanctionsPage component is well-structured and follows React best practices for component composition and styling.

    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/identity-verifications-page.pdf.tsx (1)

    12-67: The IdentityVerificationsPagePDF class is well-implemented with proper data handling and transformation logic.

    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/useCaseOptionsLogic.tsx (1)

    24-59: The useCaseOptionsLogic hook is correctly implemented with proper use of React hooks and handles asynchronous operations effectively.

    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/registry-page.pdf.tsx (1)

    10-76: The RegistryPagePDF class is well-implemented with robust data handling and conditional rendering logic.

    @chesterkmr chesterkmr requested a review from Omri-Levy May 22, 2024 11:09
    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

    Review Details

    Configuration used: CodeRabbit UI
    Review profile: CHILL

    Commits Files that changed from the base of the PR and between 4399427 and 649e021.
    Files ignored due to path filters (1)
    • pnpm-lock.yaml is excluded by !pnpm-lock.yaml
    Files selected for processing (12)
    • apps/backoffice-v2/package.json (2 hunks)
    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/company-ownership-page.pdf.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/company-sanctions-page.pdf.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/identity-verifications-page.pdf.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/individual-sanctions-page.pdf.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/registry-page.pdf.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/title-page.pdf.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/CompanyOwnershipPage/EmptyCompanyOwnershipPage.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/CompanySanctionsPage/CompanySanctionsPage.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/CompanySanctionsPage/EmptyCompanySanctionsPage.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/RegistryInformationPage/EmptyRegistryInformationPage.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/RegistryInformationPage/RegistryInformationPage.tsx (1 hunks)
    Files skipped from review as they are similar to previous changes (7)
    • apps/backoffice-v2/package.json
    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/company-ownership-page.pdf.tsx
    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/company-sanctions-page.pdf.tsx
    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/identity-verifications-page.pdf.tsx
    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/registry-page.pdf.tsx
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/CompanySanctionsPage/EmptyCompanySanctionsPage.tsx
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/RegistryInformationPage/RegistryInformationPage.tsx
    Additional comments not posted (9)
    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/title-page.pdf.tsx (3)

    11-15: The render method implementation is clean and follows good async practices.


    18-25: The getData method is well-implemented, handling potential null values effectively.


    28-30: Good use of schema validation to ensure data integrity in isValid.

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/CompanyOwnershipPage/EmptyCompanyOwnershipPage.tsx (1)

    16-46: The implementation of EmptyCompanyOwnershipPage is clear and uses consistent styling and structure.

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/RegistryInformationPage/EmptyRegistryInformationPage.tsx (1)

    16-46: The EmptyRegistryInformationPage component is well-structured and follows the established pattern of other similar components.

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/CompanySanctionsPage/CompanySanctionsPage.tsx (1)

    18-76: The CompanySanctionsPage component is implemented effectively, with clear separation of concerns and dynamic data handling.

    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/individual-sanctions-page.pdf.tsx (3)

    15-21: The render method in IndividualSanctionsPagePDF is well-structured, handling different rendering scenarios based on the data state.


    106-108: Proper use of schema validation in isValid ensures the integrity of the data being rendered.


    110-112: The isEmpty method is effectively implemented to determine the rendering path based on the presence of data.

    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

    Outside diff range and nitpick comments (1)
    apps/backoffice-v2/src/pages/Entity/components/Case/Case.Actions.tsx (1)

    Line range hint 44-54: The integration of CaseOptions within the Actions component is well done. However, consider simplifying the use of template literals where dynamic expressions are not used.

    - <div className={`mb-8 flex flex-row justify-between space-x-3.5`}>
    + <div className="mb-8 flex flex-row justify-between space-x-3.5">
    Review Details

    Configuration used: CodeRabbit UI
    Review profile: CHILL

    Commits Files that changed from the base of the PR and between 649e021 and 907985e.
    Files ignored due to path filters (1)
    • pnpm-lock.yaml is excluded by !pnpm-lock.yaml
    Files selected for processing (4)
    • apps/backoffice-v2/package.json (2 hunks)
    • apps/backoffice-v2/src/domains/workflows/fetchers.ts (5 hunks)
    • apps/backoffice-v2/src/pages/Entity/components/Case/Case.Actions.tsx (3 hunks)
    • services/workflows-service/prisma/data-migrations (1 hunks)
    Files skipped from review as they are similar to previous changes (2)
    • apps/backoffice-v2/package.json
    • services/workflows-service/prisma/data-migrations
    Additional Context Used
    Biome (11)
    apps/backoffice-v2/src/domains/workflows/fetchers.ts (1)

    12-13: All these imports are only used as types.

    apps/backoffice-v2/src/pages/Entity/components/Case/Case.Actions.tsx (10)

    43-43: Do not use template literals if interpolation and special-character handling are not needed.


    44-44: Do not use template literals if interpolation and special-character handling are not needed.


    56-56: Do not use template literals if interpolation and special-character handling are not needed.


    57-57: Do not use template literals if interpolation and special-character handling are not needed.


    59-59: Do not use template literals if interpolation and special-character handling are not needed.


    67-67: Do not use template literals if interpolation and special-character handling are not needed.


    68-68: Do not use template literals if interpolation and special-character handling are not needed.


    71-71: Do not use template literals if interpolation and special-character handling are not needed.


    2-3: All these imports are only used as types.


    10-11: All these imports are only used as types.

    Additional comments not posted (3)
    apps/backoffice-v2/src/pages/Entity/components/Case/Case.Actions.tsx (1)

    6-6: The import of CaseOptions is correctly placed and follows the project's aliasing conventions.

    apps/backoffice-v2/src/domains/workflows/fetchers.ts (2)

    95-95: The addition of childWorkflows to BaseWorkflowByIdSchema is noted. Ensure that the schema for childWorkflows aligns with existing schemas if applicable, as suggested by a previous comment.

    Verification successful

    The search results indicate multiple references to childWorkflows across various files, but none of them define a specific schema for childWorkflows. Instead, they seem to use it in different contexts, often as part of other objects or arrays.

    Given this, it appears that there is no existing schema specifically for childWorkflows that could be used in place of z.any().optional(). Therefore, the current implementation using z.any().optional() is consistent with the rest of the codebase.

    • : The addition of childWorkflows: z.any().optional() to the BaseWorkflowByIdSchema is consistent with the current usage and definitions in the codebase. No specific schema for childWorkflows exists that should be used instead.
    Scripts Executed

    The following scripts were executed for the analysis:


    Script:

    #!/bin/bash
    # Description: Verify if `childWorkflows` uses an existing schema.
    ast-grep --lang typescript --pattern $'z.object({
      $$$
      childWorkflows: $_,
      $$$
    })'
    

    Length of output: 2824



    Script:

    #!/bin/bash
    # Description: Search for any existing schema definitions related to `childWorkflows`.
    rg 'childWorkflows' --type ts
    

    Length of output: 7438


    Line range hint 109-121: The definition of TWorkflowById and the update to fetchWorkflowById are consistent with the schema changes. Ensure that the transformation logic in fetchWorkflowById is thoroughly tested, especially the handling of pluginsOutput.

    Verification successful

    The definition of TWorkflowById and the update to fetchWorkflowById are consistent with the schema changes. The transformation logic in fetchWorkflowById appears to handle pluginsOutput correctly by using deepCamelKeys on website_monitoring.data.

    • fetchWorkflowById is defined in apps/backoffice-v2/src/domains/workflows/fetchers.ts.
    • The function is used in apps/backoffice-v2/src/domains/workflows/query-keys.ts.

    Ensure that the transformation logic, especially the handling of pluginsOutput, is thoroughly tested.

    Scripts Executed

    The following scripts were executed for the analysis:


    Script:

    #!/bin/bash
    # Description: Verify the transformation logic in `fetchWorkflowById`.
    rg --type typescript $'fetchWorkflowById'
    

    Length of output: 75



    Script:

    #!/bin/bash
    # Description: Verify the transformation logic in `fetchWorkflowById`.
    rg --type ts 'fetchWorkflowById'
    

    Length of output: 365



    Script:

    #!/bin/bash
    # Description: Extract the implementation of `fetchWorkflowById` from `fetchers.ts`.
    rg --type ts --context 20 'fetchWorkflowById' apps/backoffice-v2/src/domains/workflows/fetchers.ts
    

    Length of output: 1472

    @chesterkmr chesterkmr requested a review from Omri-Levy May 28, 2024 13:35
    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

    Review Details

    Configuration used: CodeRabbit UI
    Review profile: CHILL

    Commits Files that changed from the base of the PR and between 907985e and c053a45.
    Files selected for processing (7)
    • apps/backoffice-v2/public/locales/en/toast.json (1 hunks)
    • apps/backoffice-v2/src/domains/workflows/fetchers.ts (2 hunks)
    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/CaseOptions.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/registry-page.pdf.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/useCaseOptionsLogic.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/TitlePage/TitlePage.tsx (1 hunks)
    • services/workflows-service/prisma/data-migrations (1 hunks)
    Files skipped from review due to trivial changes (1)
    • apps/backoffice-v2/public/locales/en/toast.json
    Files skipped from review as they are similar to previous changes (1)
    • services/workflows-service/prisma/data-migrations
    Additional Context Used
    Biome (6)
    apps/backoffice-v2/src/domains/workflows/fetchers.ts (1)

    12-13: All these imports are only used as types.

    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/registry-page.pdf.tsx (1)

    5-6: All these imports are only used as types.

    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/useCaseOptionsLogic.tsx (2)

    1-1: All these imports are only used as types.


    2-3: All these imports are only used as types.

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/TitlePage/TitlePage.tsx (2)

    1-1: All these imports are only used as types.


    3-4: All these imports are only used as types.

    Additional comments not posted (5)
    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/CaseOptions.tsx (1)

    8-27: The implementation of the CaseOptions component looks solid and well-integrated with the dropdown functionality for PDF generation.

    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/registry-page.pdf.tsx (1)

    9-69: The RegistryPagePDF class is well-implemented with clear separation of concerns and robust data handling.

    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/useCaseOptionsLogic.tsx (1)

    25-60: The useCaseOptionsLogic hook is efficiently implemented with proper error handling and state management for PDF generation.

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/TitlePage/TitlePage.tsx (1)

    11-89: The TitlePage component is well-designed with a clear layout and appropriate use of styling and data handling.

    apps/backoffice-v2/src/domains/workflows/fetchers.ts (1)

    Line range hint 1-122: The updates to fetchers.ts are well-implemented with robust data fetching and error handling mechanisms.

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

    Outside diff range and nitpick comments (1)
    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/registry-page.pdf.tsx (1)

    10-10: Consider renaming PDF_NAME to REGISTRY_PAGE_PDF for clarity.

    This would make the purpose of the PDF more explicit in the codebase.

    Review details

    Configuration used: CodeRabbit UI
    Review profile: CHILL

    Commits

    Files that changed from the base of the PR and between c053a45 and 742e281.

    Files selected for processing (30)
    • apps/backoffice-v2/public/locales/en/toast.json (1 hunks)
    • apps/backoffice-v2/src/common/utils/svg-to-png/svg-to-png.ts (1 hunks)
    • apps/backoffice-v2/src/common/utils/value-or-none/value-or-none.ts (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/CaseOptions.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/mutations/useGeneratePDFMutation/useGeneratePDFMutation.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/company-ownership-page.pdf.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/company-sanctions-page.pdf.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/identity-verifications-page.pdf.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/individual-sanctions-page.pdf.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/pdf-renderer.abstract.ts (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/registry-page.pdf.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/title-page.pdf.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/useCaseOptionsLogic.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/CompanyOwnershipPage/CompanyOwnershipPage.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/CompanyOwnershipPage/EmptyCompanyOwnershipPage.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/CompanySanctionsPage/CompanySanctionsPage.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/CompanySanctionsPage/EmptyCompanySanctionsPage.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/IdentityVerificationsPage/EmptyIdentityVerificationsPage.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/IdentityVerificationsPage/IdentityVerificationsPage.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/IdentityVerificationsPage/components/IdentityItem/IdentityItem.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/IndividualSanctionsPage/EmptyIndividualSanctionsPage.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/IndividualSanctionsPage/IndividualSanctionsPage.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/IndividualSanctionsPage/components/IndividualSanctionsItem/IndividualSanctionsItem.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/IndividualSanctionsPage/components/IndividualSanctionsItem/ValueOrNone.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/RegistryInformationPage/EmptyRegistryInformationPage.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/RegistryInformationPage/RegistryInformationPage.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/RegistryInformationPage/registry-information.schema.ts (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/TitlePage/TitlePage.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/TitlePage/index.ts (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/schemas/base-case-information-pdf.schema.ts (1 hunks)
    Files skipped from review due to trivial changes (2)
    • apps/backoffice-v2/public/locales/en/toast.json
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/TitlePage/index.ts
    Additional context used
    Biome
    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/IdentityVerificationsPage/IdentityVerificationsPage.tsx

    [error] 29-29: Avoid using the index of an array as key property in an element. (lint/suspicious/noArrayIndexKey)

    This is the source of the key value.

    The order of the items may change, and this also affects performances and component state.
    Check the React documentation.

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/IndividualSanctionsPage/IndividualSanctionsPage.tsx

    [error] 29-29: Avoid using the index of an array as key property in an element. (lint/suspicious/noArrayIndexKey)

    This is the source of the key value.

    The order of the items may change, and this also affects performances and component state.
    Check the React documentation.

    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/identity-verifications-page.pdf.tsx

    [error] 27-45: The call chain .map().flat() can be replaced with a single .flatMap() call. (lint/complexity/useFlatMap)

    Safe fix: Replace the chain with .flatMap().

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/RegistryInformationPage/RegistryInformationPage.tsx

    [error] 45-50: JSX elements without children should be marked as self-closing. In JSX, it is valid for any element to be self-closing. (lint/style/useSelfClosingElements)

    Unsafe fix: Use a SelfClosingElement instead

    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/individual-sanctions-page.pdf.tsx

    [error] 40-50: The call chain .map().flat() can be replaced with a single .flatMap() call. (lint/complexity/useFlatMap)

    Safe fix: Replace the chain with .flatMap().


    [error] 52-62: The call chain .map().flat() can be replaced with a single .flatMap() call. (lint/complexity/useFlatMap)

    Safe fix: Replace the chain with .flatMap().


    [error] 64-74: The call chain .map().flat() can be replaced with a single .flatMap() call. (lint/complexity/useFlatMap)

    Safe fix: Replace the chain with .flatMap().


    [error] 76-86: The call chain .map().flat() can be replaced with a single .flatMap() call. (lint/complexity/useFlatMap)

    Safe fix: Replace the chain with .flatMap().


    [error] 97-101: The call chain .map().flat() can be replaced with a single .flatMap() call. (lint/complexity/useFlatMap)

    Safe fix: Replace the chain with .flatMap().

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/IndividualSanctionsPage/components/IndividualSanctionsItem/IndividualSanctionsItem.tsx

    [error] 76-76: Avoid using the index of an array as key property in an element. (lint/suspicious/noArrayIndexKey)

    This is the source of the key value.

    The order of the items may change, and this also affects performances and component state.
    Check the React documentation.


    [error] 97-97: Avoid using the index of an array as key property in an element. (lint/suspicious/noArrayIndexKey)

    This is the source of the key value.

    The order of the items may change, and this also affects performances and component state.
    Check the React documentation.


    [error] 118-118: Avoid using the index of an array as key property in an element. (lint/suspicious/noArrayIndexKey)

    This is the source of the key value.

    The order of the items may change, and this also affects performances and component state.
    Check the React documentation.


    [error] 139-139: Avoid using the index of an array as key property in an element. (lint/suspicious/noArrayIndexKey)

    This is the source of the key value.

    The order of the items may change, and this also affects performances and component state.
    Check the React documentation.

    Additional comments not posted (25)
    apps/backoffice-v2/src/common/utils/value-or-none/value-or-none.ts (1)

    1-3: LGTM! Ensure that valueOrFallback is robustly tested since it's critical to the functionality of valueOrNone.

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/schemas/base-case-information-pdf.schema.ts (1)

    1-9: LGTM! Verify the consistent usage of companyName, creationDate, and logoUrl across the application to ensure data integrity.

    Verification successful

    The fields companyName, creationDate, and logoUrl are used consistently across the application, as evidenced by the extensive search results.

    • services/workflows-service/src/workflow/workflow.service.ts
    • services/workflows-service/src/workflow/hook-callback-handler.service.ts
    • services/workflows-service/src/workflow/utils/toPrismaOrderBy.ts
    • services/workflows-service/src/workflow/cron/ongoing-monitoring.cron.ts
    • services/workflows-service/src/workflow/types/index.ts
    • services/workflows-service/src/workflow/dtos/find-workflows-list.dto.ts
    • services/workflows-service/src/webhooks/webhooks.service.ts
    • packages/workflow-core/src/lib/plugins/external-plugin/api-plugin.test.ts
    • services/workflows-service/src/business/schemas.ts
    • services/workflows-service/src/case-management/controllers/case-management.controller.ts
    • services/workflows-service/src/business/dtos/business-select.ts
    • services/workflows-service/src/business/dtos/business.update.ts
    • services/workflows-service/src/business/dtos/business-create.ts
    • services/workflows-service/src/swagger/swagger.ts
    • services/workflows-service/src/transaction/transaction.mapper.ts
    • services/workflows-service/src/transaction/transaction.controller.external.ts
    • services/workflows-service/src/transaction/transaction.controller.external.intg.test.ts
    • services/workflows-service/src/transaction/test-utils/transaction-factory.ts
    • services/workflows-service/src/business/business.repository.intg.test.ts
    • services/workflows-service/src/business/business.model.ts
    • services/workflows-service/src/business/business.controller.ts
    • services/workflows-service/src/business/business.controller.external.ts
    • services/workflows-service/src/end-user/end-user.controller.external.ts
    • services/workflows-service/src/end-user/end-user.service.ts
    • services/workflows-service/src/filter/dtos/temp-zod-schemas.ts
    • services/workflows-service/src/end-user/dtos/end-user-create-with-business.ts
    • services/workflows-service/src/collection-flow/workflow-adapters/kyb_parent_kyc_session_example/kyb_parent_kyc_session_example.workflow-adapter.ts
    • services/workflows-service/src/collection-flow/dto/update-flow-input.dto.ts
    • services/workflows-service/src/alert/types.ts
    • services/workflows-service/src/alert/alert.service.intg.test.ts
    • services/workflows-service/src/alert/alert.controller.external.ts
    • services/workflows-service/scripts/seed.ts
    • services/workflows-service/scripts/filters/index.ts
    • services/workflows-service/scripts/generate-end-user.ts
    • services/workflows-service/scripts/workflows/e2e-dynamic-url-example.ts
    • services/workflows-service/scripts/workflows/dynamic-ui-workflow.ts
    • services/workflows-service/scripts/workflows/workflow-runtime.ts
    • services/workflows-service/scripts/workflows/parent-kyb-kyc-session-workflow.ts
    • services/workflows-service/scripts/workflows/ui-definition/kyb-parent-dynamic-example/pages/2-company-info-page.ts
    • services/workflows-service/scripts/workflows/ui-definition/kyb-with-associated-companies/definition/compose-kyb-with-associated-companies-definition.ts
    • services/workflows-service/scripts/workflows/ui-definition/kyb-with-associated-companies/ui-definition/associated-company-ui-def/associated-ui-definition.ts
    • services/workflows-service/scripts/workflows/ui-definition/kyb-with-associated-companies/ui-definition/kyb-with-associated-company-ui-def/6-company-ownership-with-associated.ts
    • services/workflows-service/scripts/workflows/kyb-kyc-workflow-definition.ts
    • services/workflows-service/scripts/workflows/kyc-email-process-example.ts
    • services/workflows-service/scripts/workflows/index.ts
    • packages/react-pdf-toolkit/src/components/layouts/Footer/types.ts
    • packages/react-pdf-toolkit/src/components/layouts/Footer/Footer.tsx
    • examples/report-generation-example/src/example-data.ts
    • examples/headless-example/src/services/ballerine-backoffice.service.ts
    • apps/kyb-app/src/components/organisms/UIRenderer/elements/JSONForm/components/RelationshipDropdown/RelationshipDropdown.tsx
    • apps/kyb-app/src/components/organisms/UIRenderer/elements/JSONForm/JSONForm.tsx
    • apps/kyb-app/src/pages/CollectionFlow/components/pages/Success/Success.tsx
    • apps/kyb-app/src/domains/collection-flow/types/index.ts
    • apps/kyb-app/src/components/layouts/AppShell/Navigation.tsx
    • apps/kyb-app/src/pages/CollectionFlow/components/pages/Approved/Approved.tsx
    • apps/kyb-app/src/pages/CollectionFlow/components/pages/Rejected/Rejected.tsx
    • apps/kyb-app/src/pages/CollectionFlow/CollectionFlow.tsx
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/TitlePage/TitlePage.tsx
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/components/CaseInformationPageHeader/CaseInformationPageHeader.tsx
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/schemas/base-case-information-pdf.schema.ts
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/RegistryInformationPage/registry-information.schema.ts
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/RegistryInformationPage/utils/create-registry-items.ts
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/RegistryInformationPage/RegistryInformationPage.tsx
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/RegistryInformationPage/EmptyRegistryInformationPage.tsx
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/IndividualSanctionsPage/IndividualSanctionsPage.tsx
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/CompanySanctionsPage/EmptyCompanySanctionsPage.tsx
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/IdentityVerificationsPage/IdentityVerificationsPage.tsx
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/IndividualSanctionsPage/EmptyIndividualSanctionsPage.tsx
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/CompanySanctionsPage/CompanySanctionsPage.tsx
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/IdentityVerificationsPage/EmptyIdentityVerificationsPage.tsx
    • apps/backoffice-v2/src/pages/Entity/hooks/useEntityLogic/mock-workflow-with-children.ts
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/CompanyOwnershipPage/company-ownership.schema.ts
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/CompanyOwnershipPage/EmptyCompanyOwnershipPage.tsx
    • apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/CompanyOwnershipPage/CompanyOwnershipPage.tsx
    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/company-ownership-page.pdf.tsx
    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/title-page.pdf.tsx
    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/registry-page.pdf.tsx
    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/individual-sanctions-page.pdf.tsx
    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/identity-verifications-page.pdf.tsx
    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/company-sanctions-page.pdf.tsx
    • apps/backoffice-v2/src/pages/Entities/components/Cases/hooks/useCases/useCases.tsx
    • apps/backoffice-v2/src/lib/blocks/variants/KybExampleBlocks/hooks/useKybExampleBlocksLogic/useKybExampleBlocksLogic.tsx
    • apps/backoffice-v2/src/lib/blocks/hooks/useAssosciatedCompaniesBlock/useAssociatedCompaniesBlock.tsx
    • apps/backoffice-v2/src/lib/blocks/hooks/useAssosciatedCompaniesBlock/useAssociatedCompaniesBlock.stories.tsx
    • apps/backoffice-v2/src/lib/blocks/variants/DefaultBlocks/hooks/useDefaultBlocksLogic/useDefaultBlocksLogic.tsx
    • apps/backoffice-v2/src/lib/blocks/hooks/useAssosciatedCompaniesBlock/associated-company-adapter.ts
    • apps/backoffice-v2/src/lib/blocks/components/KycBlock/hooks/useKycBlock/child-contexts.ts
    • apps/backoffice-v2/src/common/hooks/useSearchParamsByEntity/validation-schemas.ts
    • apps/backoffice-v2/src/domains/transactions/fetchers.ts
    Scripts executed

    The following scripts were executed for the analysis:


    Script:

    #!/bin/bash
    # Description: Verify consistent usage of schema fields across the application.
    
    # Test: Search for the fields usage. Expect: Consistent usage across different modules.
    rg --type ts $'companyName|creationDate|logoUrl'
    

    Length of output: 30498

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/RegistryInformationPage/registry-information.schema.ts (1)

    1-16: LGTM! Verify the usage and validation of fields like registrationNumber and companyStatus in the application to ensure they meet business requirements.

    apps/backoffice-v2/src/common/utils/svg-to-png/svg-to-png.ts (1)

    1-26: LGTM! Consider adding a cleanup mechanism for the canvas element to prevent memory leaks.
    [REFACTOR_SUGGESTion]

    +      canvas.remove();
    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/useCaseOptionsLogic.tsx (1)

    5-22: The hook useCaseOptionsLogic is well-structured and follows best practices for asynchronous operations using React Query.

    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/pdf-renderer.abstract.ts (2)

    6-26: The abstract class IPDFRenderer is well-designed, encapsulating the common functionalities needed for PDF rendering. The error handling in getLogoUrl is robust.


    1-4: Check the import paths and ensure that the poweredByLogo path is correct relative to this file.

    Verification successful

    The import paths and the image path in pdf-renderer.abstract.ts are correct.

    • svg-to-png/svg-to-png exists.
    • fetchers files exist.
    • title-page-ballerine-logo.png exists.
    Scripts executed

    The following scripts were executed for the analysis:


    Script:

    #!/bin/bash
    # Description: Verify the import paths and the image path.
    
    # Test: Search for the import paths and the image path. Expect: Paths should exist.
    fd 'svg-to-png/svg-to-png' && fd 'fetchers' && fd 'title-page-ballerine-logo.png'
    

    Length of output: 823

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/IndividualSanctionsPage/components/IndividualSanctionsItem/ValueOrNone.tsx (1)

    1-3: Ensure the imported utility functions are correctly implemented and used.

    Verification successful

    The utility functions valueOrFallback and valueOrNone are correctly implemented and imported in the ValueOrNone.tsx file.

    • valueOrFallback is defined in apps/backoffice-v2/src/common/utils/value-or-fallback/value-or-fallback.ts.
    • valueOrNone is defined in apps/backoffice-v2/src/common/utils/value-or-none/value-or-none.ts and utilizes valueOrFallback.
    Scripts executed

    The following scripts were executed for the analysis:


    Script:

    #!/bin/bash
    # Description: Verify the utility functions.
    
    # Test: Search for the utility function implementations. Expect: Functions should be implemented correctly.
    ast-grep --lang javascript --pattern $'export const valueOrFallback($_, $_)'
    ast-grep --lang javascript --pattern $'export const valueOrNone($_)'
    

    Length of output: 1057



    Script:

    #!/bin/bash
    # Description: Verify the utility functions.
    
    # Test: Search for the utility function implementations. Expect: Functions should be implemented correctly.
    ast-grep --lang javascript --pattern 'export const valueOrFallback = $_'
    ast-grep --lang javascript --pattern 'export const valueOrNone = $_'
    

    Length of output: 145



    Script:

    #!/bin/bash
    # Description: Verify the utility functions.
    
    # Test: Search for the utility function implementations. Expect: Functions should be implemented correctly.
    rg 'export const valueOrFallback'
    rg 'export const valueOrNone'
    

    Length of output: 314

    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/title-page.pdf.tsx (2)

    8-31: The TitlePagePDF class is well-implemented, adhering to the structure defined by IPDFRenderer. The data fetching and validation logic are clear and concise.


    1-6: Verify the import paths to ensure they are correct and the files exist.

    Verification successful

    The import paths in title-page.pdf.tsx are correct and the files exist in the expected locations.

    • pdf-renderer.abstract.ts exists.
    • TitlePage.tsx exists.
    • base-case-information-pdf.schema.ts exists.
    Scripts executed

    The following scripts were executed for the analysis:


    Script:

    #!/bin/bash
    # Description: Verify the import paths.
    
    # Test: Search for the import paths. Expect: Paths should exist.
    fd 'pdf-renderer.abstract' && fd 'TitlePage' && fd 'base-case-information-pdf.schema'
    

    Length of output: 480

    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/CaseOptions.tsx (3)

    6-6: Ensure useCaseOptionsLogic is properly imported with the correct path.

    Verification successful

    The import path for useCaseOptionsLogic in CaseOptions.tsx is correct and matches the file structure in the project.

    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/CaseOptions.tsx: The import statement is correctly pointing to useCaseOptionsLogic in the hooks directory.
    Scripts executed

    The following scripts were executed for the analysis:


    Script:

    #!/bin/bash
    # Description: Verify the correct import path for `useCaseOptionsLogic`.
    
    # Test: Search for the import statement in the project. Expect: Only one correct path.
    rg --type typescript "useCaseOptionsLogic"
    

    Length of output: 77



    Script:

    #!/bin/bash
    # Description: Verify the correct import path for `useCaseOptionsLogic`.
    
    # Test: Search for the import statement in the project. Expect: Only one correct path.
    rg --type ts "useCaseOptionsLogic"
    

    Length of output: 4520


    18-18: Ensure the onClick handler generateAndOpenPDFInNewTab is implemented with error handling.


    9-9: Check the destructuring of useCaseOptionsLogic for consistency with its definition.

    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/company-ownership-page.pdf.tsx (1)

    42-42: Ensure the isEmpty method correctly handles edge cases for data validation.

    Verification successful

    The isEmpty methods in the relevant files handle edge cases by checking if the items array or other relevant fields are empty or undefined. Here are the specific implementations:

    • company-ownership-page.pdf.tsx:

      private isEmpty(data: TCompanyOwnershipData) {
        return !data.items?.length;
      }
    • registry-page.pdf.tsx:

      private isEmpty(data: TRegistryInformationData) {
        const values = [
          data.registrationNumber,
          data.incorporationDate,
          data.companyType,
          data.companyStatus,
          data.registrationAddress,
          data.registryPage,
          data.lastUpdate,
          data.registeredAt,
        ];
      
        return values.every(value => {
          return (Array.isArray(value) && !value.length) || !value;
        });
      }
    • individual-sanctions-page.pdf.tsx:

      private isEmpty(data: TIndividualSanctionsData) {
        return !data.items?.length;
      }
    • identity-verifications-page.pdf.tsx:

      private isEmpty(data: TIdentityVerificationsData) {
        return !data.items?.length;
      }
    • company-sanctions-page.pdf.tsx:

      private isEmpty(data: TCompanySanctionsData) {
        return !data.sanctions?.length;
      }

    These implementations ensure that the isEmpty method correctly handles edge cases by checking for the presence and length of arrays or other relevant fields.

    Scripts executed

    The following scripts were executed for the analysis:


    Script:

    #!/bin/bash
    # Description: Verify the `isEmpty` method handles all necessary edge cases.
    
    # Test: Search for the method implementation and check for comprehensive condition checks.
    ast-grep --lang typescript --pattern $'private isEmpty($_) {
      return !$_?.items?.length;
    }'
    

    Length of output: 568



    Script:

    #!/bin/bash
    # Description: Verify the `isEmpty` method handles all necessary edge cases.
    
    # Test: Search for the method implementation and check for comprehensive condition checks.
    ast-grep --lang typescript --pattern $'private isEmpty($_) {
      return !$_?.items?.length;
    }'
    

    Length of output: 568


    Script:

    #!/bin/bash
    # Description: Verify the `isEmpty` method handles all necessary edge cases.
    
    # Test: Search for the method implementation and check for comprehensive condition checks.
    ast-grep --lang typescript --pattern $'private isEmpty($_) {
      return !$_.items?.length;
    }'
    

    Length of output: 566


    Script:

    #!/bin/bash
    # Description: Verify the `isEmpty` method handles all necessary edge cases.
    
    # Test: Search for the method implementation and check for comprehensive condition checks.
    ast-grep --lang typescript --pattern $'private isEmpty($_) {
      return !$_?.items.length;
    }'
    

    Length of output: 566


    Script:

    #!/bin/bash
    # Description: Verify the `isEmpty` method handles all necessary edge cases.
    
    # Test: Search for the method implementation and check for comprehensive condition checks.
    ast-grep --lang typescript --pattern $'private isEmpty($_) {
      return !$_?.items?.length;
    }'
    

    Length of output: 568



    Script:

    #!/bin/bash
    # Description: Verify the `isEmpty` method handles all necessary edge cases.
    
    # Test: Search for the method name and inspect the implementation manually.
    rg 'isEmpty' --type ts
    

    Length of output: 4327



    Script:

    #!/bin/bash
    # Description: Extract the `isEmpty` method implementations from the relevant files.
    
    # Extract the `isEmpty` method implementation from company-ownership-page.pdf.tsx
    ast-grep --lang typescript --pattern 'private isEmpty($_) { $$$ }' apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/company-ownership-page.pdf.tsx
    
    # Extract the `isEmpty` method implementation from registry-page.pdf.tsx
    ast-grep --lang typescript --pattern 'private isEmpty($_) { $$$ }' apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/registry-page.pdf.tsx
    
    # Extract the `isEmpty` method implementation from individual-sanctions-page.pdf.tsx
    ast-grep --lang typescript --pattern 'private isEmpty($_) { $$$ }' apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/individual-sanctions-page.pdf.tsx
    
    # Extract the `isEmpty` method implementation from identity-verifications-page.pdf.tsx
    ast-grep --lang typescript --pattern 'private isEmpty($_) { $$$ }' apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/identity-verifications-page.pdf.tsx
    
    # Extract the `isEmpty` method implementation from company-sanctions-page.pdf.tsx
    ast-grep --lang typescript --pattern 'private isEmpty($_) { $$$ }' apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/company-sanctions-page.pdf.tsx
    

    Length of output: 3303



    Script:

    #!/bin/bash
    # Description: Display the contents of the relevant files for manual inspection of the `isEmpty` method implementations.
    
    # Display the contents of company-ownership-page.pdf.tsx
    cat apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/company-ownership-page.pdf.tsx
    
    # Display the contents of registry-page.pdf.tsx
    cat apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/registry-page.pdf.tsx
    
    # Display the contents of individual-sanctions-page.pdf.tsx
    cat apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/individual-sanctions-page.pdf.tsx
    
    # Display the contents of identity-verifications-page.pdf.tsx
    cat apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/identity-verifications-page.pdf.tsx
    
    # Display the contents of company-sanctions-page.pdf.tsx
    cat apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/company-sanctions-page.pdf.tsx
    

    Length of output: 12570

    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/company-sanctions-page.pdf.tsx (1)

    46-46: Validate the isEmpty method to ensure it accurately determines when there are no sanctions.

    Verification successful

    The rg search results indicate multiple isEmpty method implementations in the codebase. Specifically, the relevant implementation for the company-sanctions-page.pdf.tsx file is found in the same file:

    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/company-sanctions-page.pdf.tsx:  private isEmpty(data: TCompanySanctionsData) {

    To verify the accuracy of this method, we need to inspect its implementation directly. Let's extract the implementation of the isEmpty method from the company-sanctions-page.pdf.tsx file.


    The ast-grep command failed again due to a pattern syntax error. To ensure we accurately verify the isEmpty method, we should use a simpler approach by directly extracting the relevant lines from the file using sed.


    The extracted implementation of the isEmpty method is as follows:

    private isEmpty(data: TCompanySanctionsData) {
      return !data.sanctions?.length;
    }

    This method checks if the sanctions array in the data object is either undefined or has a length of zero, which seems to be a valid way to determine if there are no sanctions.

    • The method uses optional chaining (?.) to safely access the sanctions property.
    • It returns true if sanctions is either undefined or an empty array.

    Based on this implementation, the isEmpty method accurately determines when there are no sanctions.

    Scripts executed

    The following scripts were executed for the analysis:


    Script:

    #!/bin/bash
    # Description: Verify the `isEmpty` method accurately checks for empty sanctions.
    
    # Test: Search for the method implementation and check for comprehensive condition checks.
    ast-grep --lang typescript --pattern $'private isEmpty($_) {
      return !$_?.sanctions?.length;
    }'
    

    Length of output: 576



    Script:

    #!/bin/bash
    # Description: Verify the `isEmpty` method accurately checks for empty sanctions.
    
    # Test: Search for the method implementation and check for comprehensive condition checks.
    ast-grep --lang typescript --pattern $'private isEmpty($_) {
      return !$_?.sanctions?.length;
    }'
    

    Length of output: 576



    Script:

    #!/bin/bash
    # Description: Verify the `isEmpty` method accurately checks for empty sanctions.
    
    # Test: Search for the method implementation and check for comprehensive condition checks.
    ast-grep --lang typescript --pattern $'function isEmpty($_) {
      return !$_?.sanctions?.length;
    }'
    

    Length of output: 98



    Script:

    #!/bin/bash
    # Description: Verify the `isEmpty` method accurately checks for empty sanctions.
    
    # Test: Search for the method name in the codebase to locate its implementation.
    rg 'isEmpty'
    

    Length of output: 4317



    Script:

    #!/bin/bash
    # Description: Extract the implementation of the `isEmpty` method from the company-sanctions-page.pdf.tsx file.
    
    # Extract the method implementation
    ast-grep --lang typescript --pattern $'private isEmpty(data: TCompanySanctionsData) {
      $$$
    }' apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/company-sanctions-page.pdf.tsx
    

    Length of output: 714



    Script:

    #!/bin/bash
    # Description: Extract the implementation of the `isEmpty` method from the company-sanctions-page.pdf.tsx file.
    
    # Extract the method implementation using sed
    sed -n '/private isEmpty(data: TCompanySanctionsData)/,/^}/p' apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/company-sanctions-page.pdf.tsx
    

    Length of output: 296

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/IdentityVerificationsPage/EmptyIdentityVerificationsPage.tsx (1)

    11-36: Ensure the layout and styling of EmptyIdentityVerificationsPage are consistent with the application's design system.

    Verification successful

    The EmptyIdentityVerificationsPage component is used within the IdentityVerificationsPagePDF class's render method. The component is conditionally rendered when pdfData is empty. The imports and the render method indicate that the component is integrated correctly.

    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/identity-verifications-page.pdf.tsx
    Scripts executed

    The following scripts were executed for the analysis:


    Script:

    #!/bin/bash
    # Description: Verify the consistency of layout and styling with the application's design system.
    
    # Test: Search for the component usage and check for consistent styling.
    rg --type typescript "EmptyIdentityVerificationsPage"
    

    Length of output: 88



    Script:

    #!/bin/bash
    # Description: Verify the consistency of layout and styling with the application's design system.
    
    # Test: Search for the component usage and check for consistent styling.
    rg --type ts "EmptyIdentityVerificationsPage"
    

    Length of output: 827



    Script:

    #!/bin/bash
    # Description: Extract the relevant code from `identity-verifications-page.pdf.tsx` to verify the layout and styling consistency.
    
    # Extract the lines where `EmptyIdentityVerificationsPage` is used.
    rg --type ts --context 10 "EmptyIdentityVerificationsPage" apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/identity-verifications-page.pdf.tsx
    

    Length of output: 1206

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/IndividualSanctionsPage/EmptyIndividualSanctionsPage.tsx (1)

    12-37: The structure and imports in EmptyIndividualSanctionsPage are correctly implemented.

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/CompanyOwnershipPage/EmptyCompanyOwnershipPage.tsx (1)

    12-40: The dynamic generation of the subtitle using dayjs in EmptyCompanyOwnershipPage is a good practice for displaying real-time data.

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/RegistryInformationPage/EmptyRegistryInformationPage.tsx (1)

    12-40: The consistent use of components and styles in EmptyRegistryInformationPage ensures a uniform look across different PDF pages.

    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/mutations/useGeneratePDFMutation/useGeneratePDFMutation.tsx (1)

    49-50: Ensure proper error handling and user feedback for PDF generation failures.

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/CompanySanctionsPage/EmptyCompanySanctionsPage.tsx (1)

    12-56: Ensure consistent use of React hooks for data manipulation and rendering logic.

    apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/registry-page.pdf.tsx (1)

    49-51: Good use of schema validation in isValid.

    This ensures that the data conforms to the expected structure before proceeding with rendering.

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/TitlePage/TitlePage.tsx (1)

    7-86: The implementation of the TitlePage component is well-structured and adheres to the requirements specified for displaying various sections of the title page in a PDF document. The use of tw for styling and the structured layout using View and Typography components from @react-pdf/renderer and @ballerine/react-pdf-toolkit respectively, ensures a consistent and clean design. The dynamic rendering of the creationDate and companyName using JavaScript's Date methods and the handling of the logoUrl are correctly implemented.

    One minor suggestion is to consider externalizing the inline styles for better maintainability and potential reuse across other components. This is not a blocker but could enhance the maintainability of the codebase.

    Overall, the component meets the functional requirements and follows good React component practices.

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/CompanyOwnershipPage/CompanyOwnershipPage.tsx (1)

    12-85: The CompanyOwnershipPage component is well implemented with clear separation of concerns and modular code structure. The use of various sub-components like CaseInformationPageHeader, CaseInformationPageSection, and CaseInformationDisclaimer enhances the readability and reusability of the code.

    The dynamic rendering of the company ownership data with the map function and the ValueOrNone component to handle potentially undefined values are correctly used. The layout and styling using tw utility function from @ballerine/react-pdf-toolkit are consistent and appropriate for the PDF rendering context.

    Consider addressing the previous comment about creating a reusable table component. This could further improve the modularity and reusability of your code, especially if similar table layouts are used across different PDF pages.

    apps/backoffice-v2/src/pages/Entity/pdfs/case-information/pages/IdentityVerificationsPage/components/IdentityItem/IdentityItem.tsx (1)

    7-136: The IdentityItem component is implemented with a clear structure and proper use of the ValueOrNone component to handle optional data fields effectively. The layout is consistent, and the use of tw for styling within the @react-pdf/renderer context is appropriate.

    However, consider passing props directly as suggested in the previous review comments to reduce redundancy and improve the clarity of the component's API. This could make the component easier to maintain and integrate in different contexts where the identity verification data structure might vary.

    Comment on lines +1 to +3
    import { useCustomerQuery } from '@/domains/customer/hook/queries/useCustomerQuery/userCustomerQuery';
    import { useCurrentCaseQuery } from '@/pages/Entity/hooks/useCurrentCaseQuery/useCurrentCaseQuery';
    import { useGeneratePDFMutation } from '@/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/mutations/useGeneratePDFMutation/useGeneratePDFMutation';
    Copy link
    Contributor

    Choose a reason for hiding this comment

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

    Tip

    Codebase Verification

    Ensure the imported paths are correct and consistent.

    • The file useCustomerQuery.ts is located at apps/kyb-app/src/hooks/useCustomerQuery/useCustomerQuery.ts, which does not match the import path in the code.
    • The files useCurrentCaseQuery.tsx and useGeneratePDFMutation.tsx are correctly located as per their import paths.
    Analysis chain

    Ensure the imported paths are correct and consistent.

    Scripts executed

    The following scripts were executed for the analysis:


    Script:

    #!/bin/bash
    # Description: Verify the import paths are correct.
    
    # Test: Search for the import paths. Expect: Paths should exist.
    fd 'useCustomerQuery/userCustomerQuery' && fd 'useCurrentCaseQuery/useCurrentCaseQuery' && fd 'useGeneratePDFMutation/useGeneratePDFMutation'
    

    Length of output: 135



    Script:

    #!/bin/bash
    # Description: Verify the existence of the base filenames for the imports.
    
    # Test: Search for the base filenames. Expect: Filenames should exist.
    fd 'useCustomerQuery.ts' && fd 'useCurrentCaseQuery.ts' && fd 'useGeneratePDFMutation.ts'
    

    Length of output: 390

    Comment on lines +11 to +30
    const NONE_TEXT_HEX_COLOR = '#999999';
    const valueOrNoneTextColor = valueOrFallback(NONE_TEXT_HEX_COLOR, { checkFalsy: true });

    export const ValueOrNone: FunctionComponent<IValueOrNoneProps> = ({ value }) => {
    return (
    <Typography
    styles={[
    tw(
    `text-[8px] leading-[1.45rem] ${
    valueOrNoneTextColor(value) === NONE_TEXT_HEX_COLOR
    ? `text-[${valueOrNoneTextColor(value)}]`
    : ''
    }`,
    ),
    ]}
    >
    {valueOrNone(value) as AnyChildren}
    </Typography>
    );
    };
    Copy link
    Contributor

    Choose a reason for hiding this comment

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

    The ValueOrNone component is correctly using the valueOrFallback utility to handle potentially undefined values. Consider using React.memo for optimization if this component is frequently re-rendered with the same props.

    - export const ValueOrNone: FunctionComponent<IValueOrNoneProps> = ({ value }) => {
    + export const ValueOrNone: FunctionComponent<IValueOrNoneProps> = React.memo(({ value }) => {
    Committable suggestion

    ‼️ IMPORTANT
    Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

    Suggested change
    const NONE_TEXT_HEX_COLOR = '#999999';
    const valueOrNoneTextColor = valueOrFallback(NONE_TEXT_HEX_COLOR, { checkFalsy: true });
    export const ValueOrNone: FunctionComponent<IValueOrNoneProps> = ({ value }) => {
    return (
    <Typography
    styles={[
    tw(
    `text-[8px] leading-[1.45rem] ${
    valueOrNoneTextColor(value) === NONE_TEXT_HEX_COLOR
    ? `text-[${valueOrNoneTextColor(value)}]`
    : ''
    }`,
    ),
    ]}
    >
    {valueOrNone(value) as AnyChildren}
    </Typography>
    );
    };
    export const ValueOrNone: FunctionComponent<IValueOrNoneProps> = React.memo(({ value }) => {
    return (
    <Typography
    styles={[
    tw(
    `text-[8px] leading-[1.45rem] ${
    valueOrNoneTextColor(value) === NONE_TEXT_HEX_COLOR
    ? `text-[${valueOrNoneTextColor(value)}]`
    : ''
    }`,
    ),
    ]}
    >
    {valueOrNone(value) as AnyChildren}
    </Typography>
    );
    });

    Comment on lines +28 to +30
    {items.map((item, index) => (
    <IdentityItem key={index} {...item} />
    ))}
    Copy link
    Contributor

    Choose a reason for hiding this comment

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

    Avoid using array indices as keys in React components to prevent issues with rendering performance and component state.

    - {items.map((item, index) => (
    -   <IdentityItem key={index} {...item} />
    - ))}
    + {items.map((item) => (
    +   <IdentityItem key={item.id} {...item} />
    + ))}
    Committable suggestion

    ‼️ IMPORTANT
    Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

    Suggested change
    {items.map((item, index) => (
    <IdentityItem key={index} {...item} />
    ))}
    {items.map((item) => (
    <IdentityItem key={item.id} {...item} />
    ))}
    Tools
    Biome

    [error] 29-29: Avoid using the index of an array as key property in an element. (lint/suspicious/noArrayIndexKey)

    This is the source of the key value.

    The order of the items may change, and this also affects performances and component state.
    Check the React documentation.

    Comment on lines +7 to +153
    </View>
    </View>
    <View style={tw('flex flex-row')}>
    <View style={tw('w-[80px]')}>
    <Typography styles={[tw('text-[8px] leading-[1.45rem]')]} weight="bold">
    Names
    </Typography>
    </View>
    <View style={tw('w-[400px]')}>
    <ValueOrNone value={names?.join(', ')} />
    </View>
    </View>
    <View style={tw('flex flex-row')}>
    <View style={tw('w-[80px]')}>
    <Typography styles={[tw('text-[8px] leading-[1.45rem]')]} weight="bold">
    Warnings
    </Typography>
    </View>
    <View style={tw('w-[400px] flex flex-row flex-wrap gap-2')}>
    {warnings.length ? (
    warnings.map((warning, index) => (
    <Link
    key={index}
    href={warning.sourceUrl}
    url={warning.name}
    styles={[tw('text-[#007AFF] no-underline')]}
    />
    ))
    ) : (
    <ValueOrNone value={undefined} />
    )}
    </View>
    </View>
    <View style={tw('flex flex-row')}>
    <View style={tw('w-[80px]')}>
    <Typography styles={[tw('text-[8px] leading-[1.45rem]')]} weight="bold">
    Sanctions
    </Typography>
    </View>
    <View style={tw('w-[400px] flex flex-row gap-2 flex-wrap')}>
    {sanctions.length ? (
    sanctions.map((sanction, index) => (
    <Link
    key={index}
    href={sanction.sourceUrl}
    url={sanction.name}
    styles={[tw('text-[#007AFF] no-underline')]}
    />
    ))
    ) : (
    <ValueOrNone value={undefined} />
    )}
    </View>
    </View>
    <View style={tw('flex flex-row')}>
    <View style={tw('w-[80px]')}>
    <Typography styles={[tw('text-[8px] leading-[1.45rem]')]} weight="bold">
    PEP
    </Typography>
    </View>
    <View style={tw('w-[400px] flex flex-row gap-2 flex-wrap')}>
    {PEP.length ? (
    PEP.map((PEP, index) => (
    <Link
    key={index}
    href={PEP.sourceUrl}
    url={PEP.name}
    styles={[tw('text-[#007AFF] no-underline')]}
    />
    ))
    ) : (
    <ValueOrNone value={undefined} />
    )}
    </View>
    </View>
    <View style={tw('flex flex-row')}>
    <View style={tw('w-[80px]')}>
    <Typography styles={[tw('text-[8px] leading-[1.45rem]')]} weight="bold">
    Adverse Media
    </Typography>
    </View>
    <View style={tw('w-[400px] flex flex-row gap-2 flex-wrap')}>
    {adverseMedia.length ? (
    adverseMedia.map((adverseMedia, index) => (
    <Link
    key={index}
    href={adverseMedia.sourceUrl}
    url={adverseMedia.name}
    styles={[tw('text-[#007AFF] no-underline')]}
    />
    ))
    ) : (
    <ValueOrNone value={undefined} />
    )}
    </View>
    </View>
    </View>
    </View>
    );
    };
    Copy link
    Contributor

    Choose a reason for hiding this comment

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

    The IndividualSanctionsItem component is robust in handling various data fields and dynamically rendering content based on the data's presence. The use of conditional rendering and the ValueOrNone component for handling optional or absent data is well implemented.

    However, the static analysis tool has flagged the use of array indices as keys in the map function calls. This is a valid concern as using indices as keys can lead to performance issues and bugs in React components when the order of items changes.

    Here's a suggested fix:

    - <Link key={index} href={warning.sourceUrl} url={warning.name} styles={[tw('text-[#007AFF] no-underline')]} />
    + <Link key={warning.sourceUrl} href={warning.sourceUrl} url={warning.name} styles={[tw('text-[#007AFF] no-underline')]} />

    Apply this change to all instances where key={index} is used. This will ensure that the keys are unique and tied to the content, not the array position.

    Committable suggestion was skipped due to low confidence.

    Tools
    Biome

    [error] 76-76: Avoid using the index of an array as key property in an element. (lint/suspicious/noArrayIndexKey)

    This is the source of the key value.

    The order of the items may change, and this also affects performances and component state.
    Check the React documentation.


    [error] 97-97: Avoid using the index of an array as key property in an element. (lint/suspicious/noArrayIndexKey)

    This is the source of the key value.

    The order of the items may change, and this also affects performances and component state.
    Check the React documentation.


    [error] 118-118: Avoid using the index of an array as key property in an element. (lint/suspicious/noArrayIndexKey)

    This is the source of the key value.

    The order of the items may change, and this also affects performances and component state.
    Check the React documentation.


    [error] 139-139: Avoid using the index of an array as key property in an element. (lint/suspicious/noArrayIndexKey)

    This is the source of the key value.

    The order of the items may change, and this also affects performances and component state.
    Check the React documentation.

    <CaseInformationPageSectionHeader title="Individual PEP/Sanctions" />
    <View style={tw('flex flex-col gap-6')}>
    {items.map((item, index) => (
    <IndividualSanctionsItem key={index} {...item} />
    Copy link
    Contributor

    Choose a reason for hiding this comment

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

    Replace array index with unique identifier as key in list rendering.

    - <IndividualSanctionsItem key={index} {...item} />
    + <IndividualSanctionsItem key={item.id} {...item} />
    Committable suggestion

    ‼️ IMPORTANT
    Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

    Suggested change
    <IndividualSanctionsItem key={index} {...item} />
    <IndividualSanctionsItem key={item.id} {...item} />
    Tools
    Biome

    [error] 29-29: Avoid using the index of an array as key property in an element. (lint/suspicious/noArrayIndexKey)

    This is the source of the key value.

    The order of the items may change, and this also affects performances and component state.
    Check the React documentation.

    Comment on lines +14 to +73
    export const CompanySanctionsPage: FunctionComponent<TCompanySanctionsData> = ({
    sanctions,
    companyName,
    logoUrl,
    }) => {
    return (
    <CaseInformationPageContainer>
    <View style={tw('mb-3')}>
    <CaseInformationPageHeader companyLogo={logoUrl} companyName={companyName} />
    </View>
    <View style={tw('flex flex-col gap-5')}>
    <CaseInformationPageSection>
    <View style={tw('flex flex-col gap-4 py-3')}>
    {/* Company Sanctions section --- start */}
    <CaseInformationPageSectionHeader
    title="Company Sanctions"
    subtitle={`Check conducted at: ${dayjs().format('D MMM YYYY HH:mm')}`}
    />
    <View style={tw('flex flex-col gap-2')}>
    <View style={tw('flex flex-row')}>
    <View style={tw('w-[72px]')}>
    <Typography styles={[tw('text-[8px]')]} weight="bold">
    Scan Status
    </Typography>
    </View>
    <Typography>Completed</Typography>
    </View>
    <View style={tw('flex flex-row')}>
    <View style={tw('w-[72px]')}>
    <Typography styles={[tw('text-[8px]')]} weight="bold">
    Total Matches
    </Typography>
    </View>
    <Typography styles={[tw('text-[#EA4335]')]} weight="bold">
    {sanctions.length}
    {' matches'}
    </Typography>
    </View>
    </View>
    <View style={tw('flex flex-col gap-4')}>
    {sanctions.map((item, index) => (
    <CompanySanctionsMatchSection
    key={item.name}
    primaryName={item.name}
    labels={item.labels}
    matchNumber={index + 1}
    lastReviewedDate={item.reviewDate ? new Date(item.reviewDate) : undefined}
    matchReasons={item.matchReasons}
    sources={item.sources.filter(source => isValidUrl(source))}
    addresses={item.addresses}
    />
    ))}
    </View>
    {/* Company Sanctions section --- end */}
    </View>
    </CaseInformationPageSection>
    <CaseInformationDisclaimer />
    </View>
    </CaseInformationPageContainer>
    );
    Copy link
    Contributor

    Choose a reason for hiding this comment

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

    Ensure consistent date formatting in CompanySanctionsPage.

    The subtitle in the CaseInformationPageSectionHeader uses dayjs().format('D MMM YYYY HH:mm') directly. It's recommended to define this date format in a constant or utility function for reuse and consistency across the application.

    Comment on lines +27 to +45
    items: childWorkflowSessions
    .map(childWorkflowSession => {
    return Object.values(childWorkflowSession || {}).map(
    (session: any): TIdentityVerificationsData['items'][number] => ({
    firstName: session.result?.childEntity?.firstName || '',
    lastName: session.result?.childEntity?.lastName || '',
    dateOfBirth: session.result?.entity?.data?.dateOfBirth || null,
    status:
    session.result?.vendorResult?.decision?.status || ('' as 'approved' | 'rejected'),
    checkDate: session.result?.vendorResult?.aml?.createdAt || null,
    id: session.result?.vendorResult?.metadata?.id || '',
    gender: session.result?.vendorResult?.entity?.data?.additionalInfo?.gender || '',
    nationality:
    session.result?.vendorResult?.entity?.data?.additionalInfo?.nationality || '',
    reason: session.result.vendorResult.decision.reason || '',
    }),
    );
    })
    .flat(),
    Copy link
    Contributor

    Choose a reason for hiding this comment

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

    Simplify data transformation using .flatMap() instead of .map().flat().

    - .map().flat()
    + .flatMap()
    Committable suggestion

    ‼️ IMPORTANT
    Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

    Suggested change
    items: childWorkflowSessions
    .map(childWorkflowSession => {
    return Object.values(childWorkflowSession || {}).map(
    (session: any): TIdentityVerificationsData['items'][number] => ({
    firstName: session.result?.childEntity?.firstName || '',
    lastName: session.result?.childEntity?.lastName || '',
    dateOfBirth: session.result?.entity?.data?.dateOfBirth || null,
    status:
    session.result?.vendorResult?.decision?.status || ('' as 'approved' | 'rejected'),
    checkDate: session.result?.vendorResult?.aml?.createdAt || null,
    id: session.result?.vendorResult?.metadata?.id || '',
    gender: session.result?.vendorResult?.entity?.data?.additionalInfo?.gender || '',
    nationality:
    session.result?.vendorResult?.entity?.data?.additionalInfo?.nationality || '',
    reason: session.result.vendorResult.decision.reason || '',
    }),
    );
    })
    .flat(),
    items: childWorkflowSessions
    .flatMap(childWorkflowSession => {
    return Object.values(childWorkflowSession || {}).map(
    (session: any): TIdentityVerificationsData['items'][number] => ({
    firstName: session.result?.childEntity?.firstName || '',
    lastName: session.result?.childEntity?.lastName || '',
    dateOfBirth: session.result?.entity?.data?.dateOfBirth || null,
    status:
    session.result?.vendorResult?.decision?.status || ('' as 'approved' | 'rejected'),
    checkDate: session.result?.vendorResult?.aml?.createdAt || null,
    id: session.result?.vendorResult?.metadata?.id || '',
    gender: session.result?.vendorResult?.entity?.data?.additionalInfo?.gender || '',
    nationality:
    session.result?.vendorResult?.entity?.data?.additionalInfo?.nationality || '',
    reason: session.result.vendorResult.decision.reason || '',
    }),
    );
    }),
    Tools
    Biome

    [error] 27-45: The call chain .map().flat() can be replaced with a single .flatMap() call. (lint/complexity/useFlatMap)

    Safe fix: Replace the chain with .flatMap().

    Comment on lines +24 to +92
    async getData() {
    const pdfData: TIndividualSanctionsData = {
    companyName: this.workflow.context?.entity?.data?.companyName || '',
    creationDate: new Date(),
    logoUrl: await this.getLogoUrl(),
    items: this.extractAmlSessions().map(session => {
    const rawAml = session.result?.vendorResult?.aml || {};
    const amlData = amlAdapter(rawAml);

    return {
    checkDate: amlData.dateOfCheck ?? undefined,
    fullName: `${session.result?.childEntity?.firstName || ''} ${
    session.result?.childEntity?.lastName || ''
    }`,
    matchesCount: amlData.totalMatches,
    names: amlData.matches.map(match => match.aka).flat(0),
    warnings: amlData.matches
    .map(match =>
    match.warnings.map(
    warning =>
    ({
    sourceUrl: warning.source,
    name: warning.warning,
    } as { sourceUrl: string; name: string }),
    ),
    )
    .flat(1)
    .filter(warning => warning.name && warning.sourceUrl),
    sanctions: amlData.matches
    .map(match =>
    match.sanctions.map(
    sanction =>
    ({
    sourceUrl: sanction.source,
    name: sanction.sanction,
    } as { sourceUrl: string; name: string }),
    ),
    )
    .flat(1)
    .filter(sanction => sanction.name && sanction.sourceUrl),
    PEP: amlData.matches
    .map(match =>
    match.pep.map(
    pep =>
    ({ sourceUrl: pep.source, name: pep.person } as {
    sourceUrl: string;
    name: string;
    }),
    ),
    )
    .flat(1)
    .filter(pep => pep.name && pep.sourceUrl),
    adverseMedia: amlData.matches
    .map(match =>
    match.adverseMedia.map(
    adverseMedia =>
    ({
    sourceUrl: adverseMedia.source,
    name: adverseMedia.entry,
    } as { sourceUrl: string; name: string }),
    ),
    )
    .flat(1)
    .filter(adverseMedia => adverseMedia.name && adverseMedia.sourceUrl),
    };
    }),
    };

    return pdfData;
    Copy link
    Contributor

    Choose a reason for hiding this comment

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

    Refactor getData to use .flatMap() for better performance.

    Replace the .map().flat() chains with .flatMap() to simplify and optimize the data transformation logic.

    - .map().flat()
    + .flatMap()
    Committable suggestion

    ‼️ IMPORTANT
    Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

    Suggested change
    async getData() {
    const pdfData: TIndividualSanctionsData = {
    companyName: this.workflow.context?.entity?.data?.companyName || '',
    creationDate: new Date(),
    logoUrl: await this.getLogoUrl(),
    items: this.extractAmlSessions().map(session => {
    const rawAml = session.result?.vendorResult?.aml || {};
    const amlData = amlAdapter(rawAml);
    return {
    checkDate: amlData.dateOfCheck ?? undefined,
    fullName: `${session.result?.childEntity?.firstName || ''} ${
    session.result?.childEntity?.lastName || ''
    }`,
    matchesCount: amlData.totalMatches,
    names: amlData.matches.map(match => match.aka).flat(0),
    warnings: amlData.matches
    .map(match =>
    match.warnings.map(
    warning =>
    ({
    sourceUrl: warning.source,
    name: warning.warning,
    } as { sourceUrl: string; name: string }),
    ),
    )
    .flat(1)
    .filter(warning => warning.name && warning.sourceUrl),
    sanctions: amlData.matches
    .map(match =>
    match.sanctions.map(
    sanction =>
    ({
    sourceUrl: sanction.source,
    name: sanction.sanction,
    } as { sourceUrl: string; name: string }),
    ),
    )
    .flat(1)
    .filter(sanction => sanction.name && sanction.sourceUrl),
    PEP: amlData.matches
    .map(match =>
    match.pep.map(
    pep =>
    ({ sourceUrl: pep.source, name: pep.person } as {
    sourceUrl: string;
    name: string;
    }),
    ),
    )
    .flat(1)
    .filter(pep => pep.name && pep.sourceUrl),
    adverseMedia: amlData.matches
    .map(match =>
    match.adverseMedia.map(
    adverseMedia =>
    ({
    sourceUrl: adverseMedia.source,
    name: adverseMedia.entry,
    } as { sourceUrl: string; name: string }),
    ),
    )
    .flat(1)
    .filter(adverseMedia => adverseMedia.name && adverseMedia.sourceUrl),
    };
    }),
    };
    return pdfData;
    async getData() {
    const pdfData: TIndividualSanctionsData = {
    companyName: this.workflow.context?.entity?.data?.companyName || '',
    creationDate: new Date(),
    logoUrl: await this.getLogoUrl(),
    items: this.extractAmlSessions().map(session => {
    const rawAml = session.result?.vendorResult?.aml || {};
    const amlData = amlAdapter(rawAml);
    return {
    checkDate: amlData.dateOfCheck ?? undefined,
    fullName: `${session.result?.childEntity?.firstName || ''} ${
    session.result?.childEntity?.lastName || ''
    }`,
    matchesCount: amlData.totalMatches,
    names: amlData.matches.flatMap(match => match.aka),
    warnings: amlData.matches
    .flatMap(match =>
    match.warnings.map(
    warning =>
    ({
    sourceUrl: warning.source,
    name: warning.warning,
    } as { sourceUrl: string; name: string }),
    ),
    )
    .filter(warning => warning.name && warning.sourceUrl),
    sanctions: amlData.matches
    .flatMap(match =>
    match.sanctions.map(
    sanction =>
    ({
    sourceUrl: sanction.source,
    name: sanction.sanction,
    } as { sourceUrl: string; name: string }),
    ),
    )
    .filter(sanction => sanction.name && sanction.sourceUrl),
    PEP: amlData.matches
    .flatMap(match =>
    match.pep.map(
    pep =>
    ({ sourceUrl: pep.source, name: pep.person } as {
    sourceUrl: string;
    name: string;
    }),
    ),
    )
    .filter(pep => pep.name && pep.sourceUrl),
    adverseMedia: amlData.matches
    .flatMap(match =>
    match.adverseMedia.map(
    adverseMedia =>
    ({
    sourceUrl: adverseMedia.source,
    name: adverseMedia.entry,
    } as { sourceUrl: string; name: string }),
    ),
    )
    .filter(adverseMedia => adverseMedia.name && adverseMedia.sourceUrl),
    };
    }),
    };
    return pdfData;
    Tools
    Biome

    [error] 40-50: The call chain .map().flat() can be replaced with a single .flatMap() call. (lint/complexity/useFlatMap)

    Safe fix: Replace the chain with .flatMap().


    [error] 52-62: The call chain .map().flat() can be replaced with a single .flatMap() call. (lint/complexity/useFlatMap)

    Safe fix: Replace the chain with .flatMap().


    [error] 64-74: The call chain .map().flat() can be replaced with a single .flatMap() call. (lint/complexity/useFlatMap)

    Safe fix: Replace the chain with .flatMap().


    [error] 76-86: The call chain .map().flat() can be replaced with a single .flatMap() call. (lint/complexity/useFlatMap)

    Safe fix: Replace the chain with .flatMap().

    Comment on lines +26 to +31
    items: (this.workflow?.context?.pluginsOutput?.ubo?.data?.uboGraph || []).map((ubo: any) => ({
    companyName: ubo?.name,
    companyType: ubo?.type,
    ownershipPercentage: ubo?.shareHolders?.[0]?.sharePercentage,
    level: ubo?.level,
    })),
    Copy link
    Contributor

    Choose a reason for hiding this comment

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

    Optimize the mapping logic to ensure type safety and reduce complexity.

    - items: (this.workflow?.context?.pluginsOutput?.ubo?.data?.uboGraph || []).map((ubo: any) => ({
    + items: (this.workflow?.context?.pluginsOutput?.ubo?.data?.uboGraph || []).map((ubo: TCompanyOwnershipData) => ({
        companyName: ubo?.name,
        companyType: ubo?.type,
        ownershipPercentage: ubo?.shareHolders?.[0]?.sharePercentage,
        level: ubo?.level,
      })),
    Committable suggestion

    ‼️ IMPORTANT
    Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

    Suggested change
    items: (this.workflow?.context?.pluginsOutput?.ubo?.data?.uboGraph || []).map((ubo: any) => ({
    companyName: ubo?.name,
    companyType: ubo?.type,
    ownershipPercentage: ubo?.shareHolders?.[0]?.sharePercentage,
    level: ubo?.level,
    })),
    items: (this.workflow?.context?.pluginsOutput?.ubo?.data?.uboGraph || []).map((ubo: TCompanyOwnershipData) => ({
    companyName: ubo?.name,
    companyType: ubo?.type,
    ownershipPercentage: ubo?.shareHolders?.[0]?.sharePercentage,
    level: ubo?.level,
    })),

    Comment on lines +26 to +34
    sanctions: (this.workflow?.context?.pluginsOutput?.companySanctions?.data || []).map(
    (sanction: any) => ({
    name: sanction.entity.name,
    reviewDate: sanction.entity.lastReviewed,
    labels: sanction.entity.categories,
    sources: sanction.entity.sources.map((source: { url: string }) => source.url),
    addresses: sanction.entity.places,
    matchReasons: sanction.matchedFields,
    }),
    Copy link
    Contributor

    Choose a reason for hiding this comment

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

    Refactor the mapping logic to improve readability and performance.

    - sanctions: (this.workflow?.context?.pluginsOutput?.companySanctions?.data || []).map(
    + sanctions: (this.workflow?.context?.pluginsOutput?.companySanctions?.data || []).map((sanction: TCompanySanctionsData) => ({
        name: sanction.entity.name,
        reviewDate: sanction.entity.lastReviewed,
        labels: sanction.entity.categories,
        sources: sanction.entity.sources.map((source: { url: string }) => source.url),
        addresses: sanction.entity.places,
        matchReasons: sanction.matchedFields,
      })),
    Committable suggestion

    ‼️ IMPORTANT
    Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

    Suggested change
    sanctions: (this.workflow?.context?.pluginsOutput?.companySanctions?.data || []).map(
    (sanction: any) => ({
    name: sanction.entity.name,
    reviewDate: sanction.entity.lastReviewed,
    labels: sanction.entity.categories,
    sources: sanction.entity.sources.map((source: { url: string }) => source.url),
    addresses: sanction.entity.places,
    matchReasons: sanction.matchedFields,
    }),
    sanctions: (this.workflow?.context?.pluginsOutput?.companySanctions?.data || []).map((sanction: TCompanySanctionsData) => ({
    name: sanction.entity.name,
    reviewDate: sanction.entity.lastReviewed,
    labels: sanction.entity.categories,
    sources: sanction.entity.sources.map((source: { url: string }) => source.url),
    addresses: sanction.entity.places,
    matchReasons: sanction.matchedFields,
    })),

    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

    Review details

    Configuration used: CodeRabbit UI
    Review profile: CHILL

    Commits

    Files that changed from the base of the PR and between 742e281 and c4f941c.

    Files selected for processing (2)
    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/CaseOptions.tsx (1 hunks)
    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/useCaseOptionsLogic.tsx (1 hunks)
    Files skipped from review as they are similar to previous changes (2)
    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/CaseOptions.tsx
    • apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/useCaseOptionsLogic.tsx

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

    Successfully merging this pull request may close these issues.

    None yet

    2 participants