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

Fix modal interaction for email verification flow #4878

Merged
merged 1 commit into from
Nov 27, 2024

Conversation

kkatusic
Copy link
Collaborator

@kkatusic kkatusic commented Nov 27, 2024

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced tooltips for email verification guidance in English, Catalan, and Spanish.
    • Added a VerifyEmailBanner to prompt users to verify their email addresses in the user profile view.
  • Improvements

    • Enhanced user interface with new styled components for better visual feedback and interaction.
    • Updated translations for clarity and consistency across various user interface elements.
  • Bug Fixes

    • Removed the previous email verification banner to streamline user experience.

@kkatusic kkatusic self-assigned this Nov 27, 2024
Copy link

vercel bot commented Nov 27, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
giveth-dapps-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 27, 2024 0:34am

Copy link
Contributor

coderabbitai bot commented Nov 27, 2024

Walkthrough

The changes in this pull request involve updates to various language files to include new tooltip entries related to email verification in Catalan, English, and Spanish. Additionally, the VerifyEmailBanner component has been added to the UserProfileView, while the existing VerifyEmailBanner component has been modified to include conditional routing logic. The EditUserModal component has been updated to incorporate routing functionality, and the ProjectGIVbackToast component has been enhanced with new tooltip features.

Changes

File Change Summary
lang/ca.json Added entry: "label.email_tooltip": "Edita el teu perfil des de \"El meu compte\" i verifica la teva adreça de correu electrònic per continuar"
lang/en.json Added entry: "label.email_tooltip": "Edit your profile from \"My Account\" and verify your email address to continue"; various updates for clarity and consistency.
lang/es.json Added entry: "label.email_tooltip": "Edita tu perfil desde \"Mi cuenta\" y verifica tu dirección de correo electrónico para continuar"; comprehensive updates to Spanish translations.
pages/account.tsx Removed VerifyEmailBanner component from AccountRoute.
src/components/modals/EditUserModal.tsx Added routing functionality to reset query parameters after user update; included new import for useRouter.
src/components/views/project/ProjectGIVbackToast.tsx Added TooltipWrapper and ContentWrapper styled components; modified rendering logic to include tooltips.
src/components/views/userProfile/UserProfile.view.tsx Added VerifyEmailBanner component, conditionally rendered based on user's email verification status.
src/components/views/userProfile/VerifyEmailBanner.tsx Updated method signature to accept setShowModal prop; modified routing logic based on current route and query parameters.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant AccountRoute
    participant UserProfileView
    participant EditUserModal
    participant ProjectGIVbackToast

    User->>AccountRoute: Access Account Page
    AccountRoute-->>User: Render Account Page (without VerifyEmailBanner)
    
    User->>UserProfileView: Access User Profile
    UserProfileView-->>User: Render User Profile (with VerifyEmailBanner if email not verified)

    User->>EditUserModal: Update User Information
    EditUserModal-->>User: Reset Query Parameters and Show Success Message

    User->>ProjectGIVbackToast: Hover for Tooltip
    ProjectGIVbackToast-->>User: Show Tooltip with Email Verification Info
Loading

Possibly related PRs

Suggested labels

Code Review

Suggested reviewers

  • CarlosQ96
  • MohammadPCh
  • mateodaza

Poem

🐰 In the land where emails roam,
A tooltip guides you safely home.
Verify with just a click,
Your profile's ready, oh so quick!
With banners bright and messages clear,
Your journey's smooth, have no fear! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

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

Documentation and Community

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

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 (4)
src/components/views/userProfile/VerifyEmailBanner.tsx (1)

23-37: Consider improving the routing logic implementation

A few suggestions to enhance the code:

  1. Use a boolean comparison instead of string
  2. Extract the navigation logic
  3. Add error handling for router.push

Consider this refactoring:

+const VERIFY_EMAIL_QUERY = 'opencheck';
+
+const navigateToEmailVerification = (router: NextRouter) => {
+  return router.push(
+    {
+      pathname: Routes.MyAccount,
+      query: { [VERIFY_EMAIL_QUERY]: true },
+    },
+    undefined,
+    { shallow: true },
+  ).catch(error => {
+    console.error('Failed to navigate:', error);
+  });
+};
+
 onClick={() => {
   if (
     router.pathname === Routes.MyAccount &&
-    router.query.opencheck === 'true'
+    router.query[VERIFY_EMAIL_QUERY] === 'true'
   ) {
     setShowModal?.(true);
   } else {
-    router.push(
-      {
-        pathname: Routes.MyAccount,
-        query: { opencheck: 'true' },
-      },
-      undefined,
-      { shallow: true },
-    );
+    navigateToEmailVerification(router);
   }
 }}
src/components/views/project/ProjectGIVbackToast.tsx (3)

Line range hint 356-392: Consider enhancing tooltip accessibility and mobile UX

The tooltip implementation could be improved in the following areas:

  1. Accessibility: Add ARIA attributes for screen readers
  2. Mobile UX: Add touch support since hover doesn't work well on mobile devices

Consider applying these improvements:

 <ContentWrapper>
   <Wrapper $isverified={isAdminEmailVerified}>
     {/* ... */}
   </Wrapper>
   {!isAdminEmailVerified && (
-    <TooltipWrapper>
+    <TooltipWrapper
+      role="tooltip"
+      aria-label={formatMessage({ id: 'label.email_tooltip' })}
+      tabIndex={0}
+    >
       {formatMessage({ id: 'label.email_tooltip' })}
     </TooltipWrapper>
   )}
 </ContentWrapper>

438-462: Align tooltip styles with design system

The tooltip styling could be improved for better maintainability and consistency:

  1. Use design system color tokens instead of hardcoded values
  2. Add z-index to prevent overlay issues

Consider these styling improvements:

 const TooltipWrapper = styled.div`
   position: absolute;
   bottom: 100%;
   left: 50%;
   transform: translateX(-50%);
-  background: #1a1a1a;
-  color: #fff;
+  background: ${neutralColors.gray[900]};
+  color: ${neutralColors.gray[100]};
   padding: 8px 12px;
   border-radius: 4px;
   font-size: 12px;
   white-space: nowrap;
   opacity: 0;
   visibility: hidden;
+  z-index: 1;
   transition:
     opacity 0.2s ease-in-out,
     visibility 0.2s ease-in-out;
 `;

476-477: Follow React boolean prop naming convention

The $isverified prop doesn't follow React's convention for boolean props. Consider using isVerified (without $ prefix) to align with React's naming patterns.

-const Wrapper = styled(Flex)<{ $isverified: boolean }>`
+const Wrapper = styled(Flex)<{ isVerified: boolean }>`
   /* ... */
-  pointer-events: ${({ $isverified }) => ($isverified ? 'auto' : 'none')};
-  opacity: ${({ $isverified }) => ($isverified ? '1' : '0.75')};
+  pointer-events: ${({ isVerified }) => (isVerified ? 'auto' : 'none')};
+  opacity: ${({ isVerified }) => (isVerified ? '1' : '0.75')};
 `;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 5dc388c and 603dcab.

📒 Files selected for processing (8)
  • lang/ca.json (1 hunks)
  • lang/en.json (1 hunks)
  • lang/es.json (1 hunks)
  • pages/account.tsx (0 hunks)
  • src/components/modals/EditUserModal.tsx (3 hunks)
  • src/components/views/project/ProjectGIVbackToast.tsx (4 hunks)
  • src/components/views/userProfile/UserProfile.view.tsx (2 hunks)
  • src/components/views/userProfile/VerifyEmailBanner.tsx (2 hunks)
💤 Files with no reviewable changes (1)
  • pages/account.tsx
✅ Files skipped from review due to trivial changes (2)
  • lang/ca.json
  • lang/es.json
🔇 Additional comments (10)
src/components/views/userProfile/VerifyEmailBanner.tsx (3)

7-11: LGTM: Clean prop interface definition

The TypeScript interface for the optional setShowModal prop is well-defined and follows best practices.


7-11: Verify integration with UserProfileView

According to the PR summary, this component is integrated into UserProfileView. Let's ensure the integration is properly implemented.

✅ Verification successful

Integration with UserProfileView is properly implemented

The verification shows that:

  1. VerifyEmailBanner is correctly imported in UserProfileView
  2. The component is used with the setShowModal prop being passed from UserProfileView's state
  3. The integration matches the component's interface
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check the UserProfileView integration
ast-grep --pattern 'import { VerifyEmailBanner } from $_'
ast-grep --pattern 'const UserProfileView = $_'

Length of output: 109


Script:

#!/bin/bash
# Let's try a broader search to find the integration
rg -l "VerifyEmailBanner" --type tsx
rg "UserProfileView" --type tsx -A 5

Length of output: 129


Script:

#!/bin/bash
# Search without file type restriction since tsx isn't recognized
rg -l "VerifyEmailBanner"
rg "UserProfileView" -A 5

Length of output: 13251


Script:

#!/bin/bash
# Let's check how VerifyEmailBanner is used in UserProfile.view.tsx
rg -A 10 "VerifyEmailBanner" src/components/views/userProfile/UserProfile.view.tsx

Length of output: 794


23-37: Verify the impact of shallow routing

The use of shallow routing might affect SEO and analytics tracking. Please ensure this aligns with your requirements.

src/components/modals/EditUserModal.tsx (3)

5-5: LGTM: Clean import addition

The Next.js router import is properly placed and follows standard patterns.


47-47: LGTM: Proper hook initialization

The router hook is correctly initialized at the component level, following React hooks rules.


111-120: 🛠️ Refactor suggestion

Verify impact on query parameters and error handling

While the routing logic is correctly implemented, there are a few concerns to address:

  1. Consider moving the router.push inside the try-catch block to handle potential routing errors
  2. Verify that clearing all query parameters doesn't affect other features

Let's check for other query parameter usage in the codebase:

Consider wrapping the router.push in the try-catch and preserving necessary query parameters:

 if (data.updateUser) {
   address && dispatch(fetchUserByAddress(address));
   gToast('Profile information updated.', {
     type: ToastType.SUCCESS,
     title: 'Success',
   });
-  closeModal();
-
-  // Reset router query
-  router.push(
-    {
-      pathname: router.pathname,
-      query: {},
-    },
-    undefined,
-    { shallow: true },
-  );
+  try {
+    await closeModal();
+    // Reset only specific query parameters if needed
+    const { verifyEmail, ...restQuery } = router.query;
+    await router.push(
+      {
+        pathname: router.pathname,
+        query: restQuery,
+      },
+      undefined,
+      { shallow: true },
+    );
+  } catch (error) {
+    console.error('Navigation error:', error);
+  }
 } else {
   throw 'Update User Failed.';
 }
✅ Verification successful

Let me gather more information about the router usage in EditUserModal.tsx and its surrounding context.


Let me check the VerifyEmailModal and related components to understand if there's any connection with EditUserModal's query parameters.


Based on the gathered information, I can now provide the final response:

Router query clearing in EditUserModal is safe to proceed

The current implementation of clearing query parameters in EditUserModal is safe because:

  1. The modal operates independently of email verification flow (no direct connection found between EditUserModal and VerifyEmailModal)
  2. Other modals manage their own query parameters independently
  3. The shallow routing ensures minimal impact on the application state

The suggested try-catch block would be a good practice, but it's not critical as the router operation is simple and contained.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for router.query usage to understand potential impacts
rg "router\.(query|push)" -A 3 --type typescript

# Search for email verification related query parameters
ast-grep --pattern 'const { $_ } = router.query'

Length of output: 1177


Script:

#!/bin/bash
# Check EditUserModal.tsx content for router usage and query parameters
rg -A 5 "router\." src/components/modals/EditUserModal.tsx

# Look for any email verification related code in EditUserModal
rg "verifyEmail|email.*verif" src/components/modals/EditUserModal.tsx

# Check if there are any other modal components that handle query parameters
fd -e tsx -e ts modal --exec rg -l "router\.(query|push)"

Length of output: 796


Script:

#!/bin/bash
# Check VerifyEmailModal implementation
rg -A 10 "router\." src/components/modals/VerifyEmailModal.tsx

# Look for any connections between EditUserModal and email verification
rg -A 5 "EditUserModal" src/components/modals/VerifyEmailModal.tsx
rg -A 5 "VerifyEmailModal" src/components/modals/EditUserModal.tsx

# Check if there are any shared query parameters between these modals
ast-grep --pattern 'router.push({
  $$$
  query: $_,
  $$$
})'

Length of output: 3950

src/components/views/userProfile/UserProfile.view.tsx (2)

46-46: Verify the VerifyEmailBanner component exists

The import path suggests the component is in the same directory. Let's verify its existence and implementation.

✅ Verification successful

Import path for VerifyEmailBanner component is correct

The component exists in the expected location and is properly implemented as a React functional component. It accepts the required setShowModal prop and includes the email verification banner functionality.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if VerifyEmailBanner component exists and verify its implementation
fd "VerifyEmailBanner.tsx" src/components/views/userProfile/

Length of output: 115


Script:

#!/bin/bash
# Let's verify the implementation of VerifyEmailBanner component
ast-grep --pattern $'const VerifyEmailBanner = ({ $$ }) => {
  $$$
}'

Length of output: 70


Script:

#!/bin/bash
# Let's check the content of the VerifyEmailBanner component file
cat src/components/views/userProfile/VerifyEmailBanner.tsx

Length of output: 1588


127-129: LGTM! Verify the complete email verification flow

The integration looks correct. The banner is properly conditionally rendered and connected to the modal system via setShowModal.

Let's verify the complete email verification flow:

✅ Verification successful

LGTM! Email verification flow is properly implemented

The verification confirms that:

  • VerifyEmailBanner is correctly rendered based on !user?.isEmailVerified condition
  • The banner passes setShowModal to open EditUserModal for email verification
  • EditUserModal properly tracks email verification state and handles the verification process
  • The integration between components maintains proper state management for email verification
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the email verification flow implementation

# Check VerifyEmailBanner's usage of setShowModal
ast-grep --pattern 'const VerifyEmailBanner = ({ setShowModal }: { setShowModal: $_}) => {
  $$$
}'

# Check EditUserModal's email verification handling
ast-grep --pattern 'const EditUserModal = ({ setShowModal, user, $$ }: { setShowModal: $_; user: $_; $$ }) => {
  $$$
}'

Length of output: 224


Script:

#!/bin/bash
# Let's try a different approach to verify the email verification flow

# Search for VerifyEmailBanner component
rg -A 10 "const VerifyEmailBanner" --type typescript

# Search for EditUserModal component
rg -A 10 "const EditUserModal" --type typescript

# Search for email verification related state or handlers
rg "isEmailVerified|setShowModal|verifyEmail" --type typescript

Length of output: 276


Script:

#!/bin/bash
# Let's try without specifying the file type

# Search for VerifyEmailBanner component
rg -A 10 "const VerifyEmailBanner"

# Search for EditUserModal component
rg -A 10 "const EditUserModal"

# Search for email verification related state or handlers
rg "isEmailVerified|setShowModal|verifyEmail"

# Also search for the files containing these components
fd "VerifyEmailBanner|EditUserModal"

Length of output: 33635

src/components/views/project/ProjectGIVbackToast.tsx (1)

Line range hint 356-477: Implementation aligns well with PR objectives

The changes effectively address the email verification flow by:

  1. Adding clear visual feedback about verification status
  2. Preventing interactions when email is not verified
  3. Providing user guidance through tooltips
lang/en.json (1)

403-403: LGTM! The new email tooltip text is clear and properly formatted.

The added tooltip provides clear instructions for email verification while maintaining consistent style with other tooltips in the file.

Copy link
Collaborator

@CarlosQ96 CarlosQ96 left a comment

Choose a reason for hiding this comment

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

LGTM!

@kkatusic kkatusic merged commit 3376e29 into develop Nov 27, 2024
3 checks passed
@kkatusic kkatusic deleted the fix/email_verification branch November 27, 2024 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: QA
Development

Successfully merging this pull request may close these issues.

2 participants