Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: reworked back to portal button logic #2375

Merged
merged 3 commits into from
May 19, 2024
Merged

feat: reworked back to portal button logic #2375

merged 3 commits into from
May 19, 2024

Conversation

chesterkmr
Copy link
Collaborator

@chesterkmr chesterkmr commented May 14, 2024

User description

Description

Reworked Back to portal rendering logic.

Back to portal button will be rendered:

  • If config.kybOnExitAction is set to send-event
  • if config.kybOnExitAction is set to redirect-to-customer-portal and websiteUrl is exists in customer.

PR Type

enhancement


Description

  • Enhanced the exit logic across multiple components to use destructured exit and isExitAvailable from useAppExit.
  • Added new logic to determine the availability of the exit action based on configuration and customer details.
  • Implemented conditional rendering for the back to portal button based on the new exit availability logic.

Changes walkthrough 📝

Relevant files
Enhancement
Navigation.tsx
Enhance exit logic and conditional rendering in Navigation

apps/kyb-app/src/components/layouts/AppShell/Navigation.tsx

  • Replaced exitFromApp with destructured exit and isExitAvailable from
    useAppExit.
  • Added condition to return null if it is the first step and exit is not
    available.
  • +5/-3     
    useAppExit.ts
    Extend useAppExit hook to include exit availability logic

    apps/kyb-app/src/hooks/useAppExit/useAppExit.ts

  • Modified return object to include isExitAvailable, determining
    availability based on kybOnExitAction and customer.websiteUrl.
  • +5/-1     
    Approved.tsx
    Update exit logic in Approved page                                             

    apps/kyb-app/src/pages/CollectionFlow/components/pages/Approved/Approved.tsx

  • Updated to use destructured exit and isExitAvailable from useAppExit.
  • Conditionally render the back to portal button based on
    isExitAvailable.
  • +3/-3     
    Success.tsx
    Update exit logic in Success page                                               

    apps/kyb-app/src/pages/CollectionFlow/components/pages/Success/Success.tsx

  • Updated to use destructured exit and isExitAvailable from useAppExit.
  • Conditionally render the back to portal button based on
    isExitAvailable.
  • +3/-3     

    💡 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 isExitAvailable to conditionally display an exit button based on availability.
    • Improved Functionality

      • Enhanced the app exit logic across various components (Navigation, Approved, and Success) for a more consistent user experience.

    @chesterkmr chesterkmr requested a review from Omri-Levy May 14, 2024 11:22
    Copy link

    changeset-bot bot commented May 14, 2024

    ⚠️ No Changeset found

    Latest commit: de5b646

    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 14, 2024

    Walkthrough

    The recent updates focus on enhancing the app's exit functionality by integrating a new isExitAvailable check. This change affects various components, including Navigation.tsx, Approved.tsx, and Success.tsx, where the exit logic is now more robust and conditional. The useAppExit hook has been modified to return an object containing both exit and isExitAvailable, ensuring consistent and improved exit handling across the application.

    Changes

    File Path Change Summary
    apps/kyb-app/src/components/layouts/AppShell/Navigation.tsx Integrated isExitAvailable check alongside exit using useAppExit hook.
    apps/kyb-app/src/hooks/useAppExit/useAppExit.ts Updated to return an object with exit and isExitAvailable properties.
    apps/kyb-app/src/pages/CollectionFlow/components/pages/... Updated Approved.tsx and Success.tsx to utilize isExitAvailable and adjust exit logic accordingly.

    In code we trust, with changes bright,
    A rabbit hops through lines of light. 🐇✨
    Exit paths now clear and true,
    With checks in place, for me and you.
    Apps flow smoother, day and night,
    Thanks to tweaks that feel just right. 🌟


    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.

    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 a review. This is useful when automatic reviews are disabled for the repository.
    • @coderabbitai resolve resolve all the CodeRabbit review comments.
    • @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 14, 2024
    Copy link
    Contributor

    PR Description updated to latest commit (be3bb1a)

    1 similar comment
    Copy link
    Contributor

    PR Description updated to latest commit (be3bb1a)

    Copy link
    Contributor

    github-actions bot commented May 14, 2024

    PR Review 🔍

    (Review updated until commit be3bb1a)

    ⏱️ Estimated effort to review [1-5]

    2, because the changes are localized to specific components and hooks with a clear focus on enhancing exit logic and conditional rendering. The logic is straightforward and the modifications are not extensive, making it easier to review.

    🧪 Relevant tests

    No

    ⚡ Possible issues

    Possible Bug: The condition uiSchema?.config?.kybOnExitAction === 'send-event' ? true : !!customer?.websiteUrl in useAppExit.ts might not correctly handle all exit scenarios. Specifically, the condition does not account for the redirect-to-customer-portal action unless websiteUrl is present, which might not be the intended logic if other conditions are supposed to trigger an exit.

    🔒 Security concerns

    No

    Code feedback:
    relevant fileapps/kyb-app/src/hooks/useAppExit/useAppExit.ts
    suggestion      

    Consider refining the exit availability logic to explicitly handle both 'send-event' and 'redirect-to-customer-portal' as separate cases. This change ensures that the logic is clear and maintainable, especially if additional exit actions are introduced in the future. [important]

    relevant lineuiSchema?.config?.kybOnExitAction === 'send-event' ? true : !!customer?.websiteUrl,

    Copy link
    Contributor

    Persistent review updated to latest commit be3bb1a

    Copy link
    Contributor

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Possible bug
    Add a conditional check to ensure safe usage of the exit function

    Ensure that the exit function is only called when isExitAvailable is true to prevent
    unintended behavior or errors. This can be achieved by adding a conditional check before
    calling exit().

    apps/kyb-app/src/components/layouts/AppShell/Navigation.tsx [29]

    -exit();
    +if (isExitAvailable) {
    +  exit();
    +}
     
    Suggestion importance[1-10]: 9

    Why: This is a crucial suggestion as it prevents the exit function from being called when isExitAvailable is false, which could lead to unintended behavior or errors.

    9
    Add a check for undefined currentPage to prevent errors

    Consider handling the case where currentPage might be undefined before accessing
    currentPage.number. This can prevent potential runtime errors if currentPage is not set.

    apps/kyb-app/src/components/layouts/AppShell/Navigation.tsx [20]

    -const isFirstStep = currentPage?.number === 1;
    +const isFirstStep = currentPage ? currentPage.number === 1 : false;
     
    Suggestion importance[1-10]: 6

    Why: This suggestion correctly addresses a potential issue where currentPage might be undefined, preventing runtime errors. However, the existing code already handles this with optional chaining, making the suggestion less critical.

    6
    Maintainability
    Simplify the conditional logic for better readability

    Consider simplifying the conditional logic for isExitAvailable to improve readability and
    maintainability. Instead of using a ternary operator followed by a logical OR, you can use
    a single logical OR if the conditions are mutually exclusive or can be combined logically.

    apps/kyb-app/src/hooks/useAppExit/useAppExit.ts [30-31]

    -isExitAvailable:
    -  uiSchema?.config?.kybOnExitAction === 'send-event' ? true : !!customer?.websiteUrl,
    +isExitAvailable: uiSchema?.config?.kybOnExitAction === 'send-event' || !!customer?.websiteUrl,
     
    Suggestion importance[1-10]: 8

    Why: The suggestion correctly identifies a more efficient way to handle the conditional logic for isExitAvailable, which improves readability and maintainability.

    8
    Enhancement
    Update the dependency array of the useEffect hook for correct reactivity

    Add isExitAvailable to the dependency array of the useEffect hook to ensure that the
    effect correctly responds to changes in the availability of the exit action.

    apps/kyb-app/src/components/layouts/AppShell/Navigation.tsx [31]

    -}, [stateApi, exit]);
    +}, [stateApi, exit, isExitAvailable]);
     
    Suggestion importance[1-10]: 7

    Why: Adding isExitAvailable to the dependency array is a good practice to ensure the useEffect hook reacts correctly to its changes, enhancing the robustness of the component.

    7

    Copy link
    Contributor

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Possible bug
    Ensure the useEffect hook responds to all relevant data changes

    Add isExitAvailable to the dependency array of the useEffect hook to ensure that the
    effect correctly responds to changes in this variable.

    apps/kyb-app/src/components/layouts/AppShell/Navigation.tsx [31]

    -}, [stateApi, exit]);
    +}, [stateApi, exit, isExitAvailable]);
     
    Suggestion importance[1-10]: 9

    Why: This suggestion correctly identifies a potential bug where changes in isExitAvailable would not trigger the useEffect, which could lead to inconsistent UI states.

    9
    Maintainability
    Simplify the conditional expression for better readability

    Consider simplifying the expression for isExitAvailable by using a more concise
    conditional operator. This will improve readability and maintainability.

    apps/kyb-app/src/hooks/useAppExit/useAppExit.ts [30-31]

    -isExitAvailable:
    -  uiSchema?.config?.kybOnExitAction === 'send-event' ? true : !!customer?.websiteUrl,
    +isExitAvailable: uiSchema?.config?.kybOnExitAction === 'send-event' || !!customer?.websiteUrl,
     
    Suggestion importance[1-10]: 8

    Why: The suggested improvement to the conditional expression simplifies the code and enhances readability without altering functionality, addressing a key maintainability aspect.

    8

    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 f645eb0 and be3bb1a.
    Files selected for processing (4)
    • apps/kyb-app/src/components/layouts/AppShell/Navigation.tsx (2 hunks)
    • apps/kyb-app/src/hooks/useAppExit/useAppExit.ts (1 hunks)
    • apps/kyb-app/src/pages/CollectionFlow/components/pages/Approved/Approved.tsx (2 hunks)
    • apps/kyb-app/src/pages/CollectionFlow/components/pages/Success/Success.tsx (2 hunks)
    Additional comments not posted (4)
    apps/kyb-app/src/pages/CollectionFlow/components/pages/Success/Success.tsx (1)

    32-34: Ensure proper conditional rendering.

    The conditional rendering of the button based on isExitAvailable and customer?.displayName is correct and ensures the button is only shown when appropriate.

    apps/kyb-app/src/pages/CollectionFlow/components/pages/Approved/Approved.tsx (1)

    32-34: Ensure proper conditional rendering.

    The conditional rendering of the button based on isExitAvailable and customer is correct and ensures the button is only shown when appropriate.

    apps/kyb-app/src/components/layouts/AppShell/Navigation.tsx (2)

    29-31: Ensure proper function call.

    The exit function is correctly called when the onPrevious function is triggered, ensuring the appropriate exit action is taken.


    33-33: Ensure proper conditional rendering.

    The conditional rendering of the button based on isExitAvailable and isFirstStep is correct and ensures the button is only shown when appropriate.

    @alonp99 alonp99 enabled auto-merge (squash) May 16, 2024 09:42
    @alonp99 alonp99 merged commit c575956 into dev May 19, 2024
    9 checks passed
    @alonp99 alonp99 deleted the bal-1933 branch May 19, 2024 08:28
    @Omri-Levy Omri-Levy mentioned this pull request Nov 4, 2024
    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.

    2 participants