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/Email verification bugs #4872

Merged
merged 1 commit into from
Nov 25, 2024
Merged

Fix/Email verification bugs #4872

merged 1 commit into from
Nov 25, 2024

Conversation

kkatusic
Copy link
Collaborator

@kkatusic kkatusic commented Nov 25, 2024

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced email verification prompts for clarity across multiple languages (Catalan, English, Spanish).
    • Updated InputUserEmailVerify component to improve email verification status handling.
    • Added state management in EditUserModal to ensure users cannot save profile changes without verified email.
    • Refined visibility conditions for the VerifyEmailBanner to target admin users specifically.
  • Bug Fixes

    • Corrected terminology from "Resend Verification Link!" to "Resend Verification Code!" for better accuracy.

Copy link

vercel bot commented Nov 25, 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 25, 2024 1:48pm

@kkatusic kkatusic requested a review from CarlosQ96 November 25, 2024 13:41
@kkatusic kkatusic self-assigned this Nov 25, 2024
Copy link
Contributor

coderabbitai bot commented Nov 25, 2024

Walkthrough

The changes in this pull request involve modifications to language translation files (lang/ca.json, lang/en.json, lang/es.json) to improve the clarity of email verification prompts. Additionally, the InputUserEmailVerify component has been updated to include a new callback for email verification status, and the EditUserModal now tracks whether the user's email is verified, affecting the save button's state. The ProjectIndex component's logic for displaying the VerifyEmailBanner has also been refined to show the banner only to unverified admin users.

Changes

File Change Summary
lang/ca.json, lang/en.json, lang/es.json Updated string for email verification prompts to clarify the action of resending verification codes.
src/components/InputUserEmailVerify.tsx Enhanced InputType to include an optional verifiedSaveButton property for email verification status.
src/components/modals/EditUserModal.tsx Added verified state to track email verification status; updated email input to accept verifiedSaveButton.
src/components/views/project/ProjectIndex.tsx Updated condition for displaying VerifyEmailBanner to show only for unverified admin users.

Possibly related PRs

Suggested labels

Code Review

Suggested reviewers

  • Meriem-BM
  • MohammadPCh
  • RamRamez

Poem

🐰 In the land of code where bunnies play,
Clarity blooms in a bright new way.
With emails verified, the path is clear,
Resend the code, have no fear!
Hopping along, we make it right,
For every user, a joyful sight! 🌼


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

🧹 Outside diff range and nitpick comments (5)
src/components/modals/EditUserModal.tsx (2)

195-197: Consider improving type safety for the email input props

While the implementation works, consider:

  1. Adding proper TypeScript interface for the new prop
  2. Using a more descriptive name like onVerificationStatusChange instead of verifiedSaveButton
+ interface IEmailInputProps extends InputProps {
+   onVerificationStatusChange?: (verified: boolean) => void;
+ }

  {
-   ...(field.type === 'email' && {
-     verifiedSaveButton: setVerified,
-   })}
+   ...(field.type === 'email' && {
+     onVerificationStatusChange: setVerified,
+   })}

206-206: Consider adding user feedback for disabled save button

While the button disabling logic is correct, users might not understand why the button is disabled. Consider adding a tooltip or helper text explaining that email verification is required to save changes.

  <ButtonEditSave
    buttonType='secondary'
    label={formatMessage({
      id: 'label.save',
    })}
    disabled={isLoading || !verified}
+   title={!verified ? formatMessage({ id: 'label.verify_email_to_save' }) : ''}
    type='submit'
  />
src/components/views/project/ProjectIndex.tsx (1)

139-139: LGTM! Consider extracting the condition for better readability.

The change correctly ensures that the email verification banner is only shown to admin users who haven't verified their email. This is a good improvement that aligns with fixing the email verification bugs.

Consider extracting the condition to a descriptive variable for better readability:

-			{!isAdminEmailVerified && isAdmin && <VerifyEmailBanner />}
+			{const shouldShowVerificationBanner = !isAdminEmailVerified && isAdmin;
+			{shouldShowVerificationBanner && <VerifyEmailBanner />}
src/components/InputUserEmailVerify.tsx (2)

296-296: Use optional chaining for consistency

For consistency with other callback invocations, use optional chaining.

- props.verifiedSaveButton && props.verifiedSaveButton(true);
+ props.verifiedSaveButton?.(true);
🧰 Tools
🪛 Biome (1.9.4)

[error] 296-296: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


Line range hint 262-310: Improve error handling in verification process

The error handling in the verification process could be enhanced:

  1. Remove console.log statements from catch blocks
  2. Consider adding specific error handling for different error types
  3. Add retry logic for network failures
 } catch (error) {
-  if (error instanceof Error) {
-    showToastError(error.message);
-  }
-  console.log(error);
+  if (error instanceof Error) {
+    const errorMessage = error.message;
+    showToastError(errorMessage);
+    setValidationCodeStatus(EInputValidation.ERROR);
+    // Consider adding retry logic here
+  } else {
+    showToastError('An unexpected error occurred');
+  }
 }
🧰 Tools
🪛 Biome (1.9.4)

[error] 296-296: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 606ca16 and e8eaac8.

📒 Files selected for processing (6)
  • lang/ca.json (1 hunks)
  • lang/en.json (1 hunks)
  • lang/es.json (1 hunks)
  • src/components/InputUserEmailVerify.tsx (3 hunks)
  • src/components/modals/EditUserModal.tsx (3 hunks)
  • src/components/views/project/ProjectIndex.tsx (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • lang/ca.json
🧰 Additional context used
🪛 Biome (1.9.4)
src/components/InputUserEmailVerify.tsx

[error] 215-215: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 218-218: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 221-221: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 296-296: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (5)
src/components/modals/EditUserModal.tsx (2)

61-61: LGTM: State management for email verification

The state initialization is well-implemented, using the user's current email verification status.


Line range hint 15-15: Verify InputUserEmailVerify component implementation

Let's ensure the imported component properly implements the verification callback.

✅ Verification successful

InputUserEmailVerify component implementation is complete and functional

The component properly implements email verification functionality with:

  • Email input validation and verification state management
  • Verification code sending and validation
  • Proper callback handling through verifiedSaveButton prop
  • Complete error handling and user feedback
  • Email verification status persistence
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check implementation of InputUserEmailVerify component
ast-grep --pattern 'const InputUserEmailVerify = $_' -f 'src/components/InputUserEmailVerify.tsx'

Length of output: 275


Script:

#!/bin/bash
# Search for InputUserEmailVerify component file
fd "InputUserEmailVerify" --type f

# Search for InputUserEmailVerify component implementation
ast-grep --pattern 'const InputUserEmailVerify = $$$'

Length of output: 25951

src/components/InputUserEmailVerify.tsx (1)

99-106: LGTM: Type definition changes are well-structured

The addition of the verifiedSaveButton callback to both variants of the InputType union maintains backward compatibility while adding new functionality.

lang/en.json (1)

393-393: LGTM! Good security improvement.

The change from "Verification Link" to "Verification Code" reflects a more secure approach to email verification.

Let's verify this change is consistent across the codebase:

✅ Verification successful

Change is consistent across language files and verification system

The verification shows that:

  • The change from "link" to "code" is consistently implemented across all language files (English, Spanish, Catalan)
  • All related email verification strings use "code" terminology
  • No legacy "verification link" references remain in the JSON files
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining instances of "verification link" that might need updating
rg -i "verification link" --type-add 'web:*.{js,jsx,ts,tsx}' -t web

# Search for related email verification code handling
ast-grep --pattern 'email_get_resend'

Length of output: 107


Script:

#!/bin/bash
# Let's try a broader search for verification-related strings in all files
rg -i "verification (link|code)" --type json

# Also search for email verification related keys in language files
rg "email.*verification" --type json

# Search for the specific key in all JSON files
rg "label\.email_get_resend" --type json

Length of output: 875

lang/es.json (1)

393-393: LGTM! Translation update improves clarity

The change from "enlace de verificación" to "código de verificación" more accurately reflects that a verification code (not a link) is being resent.

src/components/InputUserEmailVerify.tsx Show resolved Hide resolved
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.

Thanks Kechy

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