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 40 commits into
base: dev
Choose a base branch
from
Open

Bal 1641 #2331

wants to merge 40 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

      • Added PDF generation and download functionality in the Case component.
      • Introduced a dropdown menu for PDF certificate options within the Case component.
    • Improvements

      • Enhanced workflow fetching with updated schemas and better handling of child workflows.
    • Bug Fixes

      • Added error message for failed PDF certificate downloads.
    • Dependencies

      • Added new dependencies: @ballerine/react-pdf-toolkit, @react-pdf/renderer, lodash, and @types/lodash.
    • Documentation

      • Updated localizations with a new error message for PDF certificate downloads.

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

    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 changes introduce new dependencies for PDF handling and lodash utilities, update workflow schemas, and add PDF generation functionalities to the back office application. Specifically, new components and hooks are implemented to support the creation and downloading of PDF certificates. Additionally, there are updates to the workflow fetching logic and the inclusion of new error messages.

    Changes

    Files Change Summary
    apps/backoffice-v2/package.json Added dependencies: @ballerine/react-pdf-toolkit, @react-pdf/renderer, lodash, @types/lodash.
    .../fetchers.ts Reordered imports, added new imports, restructured schemas, and modified fetchWorkflowById function.
    .../Case.Actions.tsx Added import for CaseOptions and included <CaseOptions /> component in Actions component.
    .../locales/en/toast.json Added a new error message key "pdf_certificate" with the value "Failed to download PDF certificate.".
    .../CaseOptions/CaseOptions.tsx Introduced CaseOptions component for dropdown menu with PDF download option.
    .../CaseOptions/hooks/useCaseOptionsLogic/renderers/registry-page.pdf.tsx Added RegistryPagePDF class for rendering registry information pages in PDFs.
    .../CaseOptions/hooks/useCaseOptionsLogic/useCaseOptionsLogic.tsx Introduced useCaseOptionsLogic hook for managing PDF generation and download.
    .../case-information/pages/TitlePage/TitlePage.tsx Defined TitlePage component to render a title page for documents.
    services/workflows-service/prisma/data-migrations Updated subproject commit hash.

    In the land of code, where PDFs now bloom,
    New tools and hooks bring workflows to room.
    With schemas restructured and options to choose,
    Download certificates, no chance to lose.
    A rabbit's delight in each byte and line,
    Back office enhanced, oh how divine!


    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 full the 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: 0

    Review Details

    Configuration used: CodeRabbit UI
    Review profile: CHILL

    Commits Files that changed from the base of the PR and between d8a0a9d and d904642.
    Files selected for processing (1)
    • apps/backoffice-v2/src/domains/workflows/fetchers.ts (6 hunks)
    Additional comments not posted (4)
    apps/backoffice-v2/src/domains/workflows/fetchers.ts (4)

    121-121: Ensure the TypeScript version upgrade plan is in place to simplify this transformation logic as noted in the TODO comment.


    238-238: The selective use of BaseWorkflowByIdSchema for the context field is appropriate here.


    1-1: The file maintains a consistent structure and error handling approach, which is good for maintainability.

    Also applies to: 6-6, 12-12, 109-109


    95-95: Please verify if the existing schema for childWorkflows can be used here as suggested in the previous review.

    Verification successful

    The search results indicate that there are no existing schemas specifically for childWorkflows other than the one defined as z.any().optional() in fetchers.ts. The only other related schema found is childWorkflowsRuntimeData defined as z.boolean().optional() in temp-zod-schemas.ts, which does not seem to be directly applicable here.

    • services/workflows-service/src/filter/dtos/temp-zod-schemas.ts: childWorkflowsRuntimeData: z.boolean().optional()
    • apps/backoffice-v2/src/domains/workflows/fetchers.ts: childWorkflows: z.any().optional()

    Given this context, it appears that there is no existing schema for childWorkflows that can be reused.

    Scripts Executed

    The following scripts were executed for the analysis:


    Script:

    #!/bin/bash
    # Description: Search for existing `childWorkflows` schema in the project.
    rg --type typescript "childWorkflows" --files-with-matches
    

    Length of output: 93



    Script:

    #!/bin/bash
    # Description: Search for existing `childWorkflows` schema in the project.
    rg "childWorkflows" --glob "*.ts"
    

    Length of output: 3877



    Script:

    #!/bin/bash
    # Description: Search for schema definitions related to `childWorkflows` in the project.
    rg "childWorkflows.*z\." --glob "*.ts"
    

    Length of output: 249

    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.

    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