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: userflow #161

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

fix: userflow #161

wants to merge 2 commits into from

Conversation

evgongora
Copy link
Collaborator

@evgongora evgongora commented Mar 5, 2025

Summary by CodeRabbit

  • New Features

    • Enhanced the interactive test experience with updated answer selection visuals and disabled repeated submissions during processing.
    • Streamlined the registration process by removing unnecessary permission prompts, ensuring smoother onboarding.
    • Introduced a new API route to fetch user information based on wallet address.
    • Improved user data retrieval logic on the welcome page for better error handling and state management.
    • Updated the verification modal text for clearer user guidance.
  • Bug Fixes

    • Simplified logic for displaying the verification modal to ensure consistent visibility for unverified users.
  • Chores

    • Replaced the toggle switch with a dummy component in the settings page to indicate future functionality.

Copy link

vercel bot commented Mar 5, 2025

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

Name Status Preview Comments Updated (UTC)
miniapp-monorepo-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 5, 2025 7:17am

Copy link
Contributor

coderabbitai bot commented Mar 5, 2025

Walkthrough

This pull request introduces state management enhancements in the Ideology Test component to manage answer selection and processing delays. It also removes dependencies on notification permissions in the registration component. The changes include new state variables and modifications to the answer handling logic in the Ideology Test, as well as commenting out unused code and simplifying permission requests in the registration page. Additionally, it enhances user data fetching in the Welcome component and modifies modal management across various components.

Changes

File(s) Change Summary
apps/web/src/app/ideology-test/page.tsx Added selectedAnswer and isProcessingAnswer state variables; updated handleAnswer to prevent multiple submissions; implemented an 800ms delay before transitioning and reset process; updated UI button state based on answer processing.
apps/web/src/app/register/page.tsx Commented out import statements for RequestPermissionPayload and Permission; commented out the requestPermission implementation and replaced it with a resolved promise to bypass permission handling; added session verification logic.
apps/web/src/app/welcome/page.tsx Removed useAuth hook; enhanced fetchUserData function for improved error handling; simplified user data fetching logic; ensured loading state management is effective.
apps/web/src/app/api/user/by-wallet/route.ts Introduced a new API route for fetching user information by wallet address; added error handling and response structure for user data retrieval.
apps/web/src/app/(home)/page.tsx Simplified logic for displaying the verification modal; updated conditions for showing the modal to ensure it appears for unverified users.
apps/web/src/app/insights/page.tsx Introduced a combined useEffect for modal state management; modified modal closing logic for better user experience.
apps/web/src/app/settings/page.tsx Introduced a DummyToggleSwitch component as a placeholder for the toggle functionality; commented out the unused ToggleSwitch.
apps/web/src/components/layout/LayoutContent.tsx Modified share modal state handling to introduce a delay before closing to prevent flickering.
apps/web/src/components/ui/navigation/BannerTop.tsx Removed error handling related to verification; updated rendering logic based on verification state.
apps/web/src/components/ui/overlays/VerifyModal.tsx Modified text content within the modal for clarity on the verification process.
apps/web/src/hooks/useAuth.ts Added logic to handle users who have just completed registration to prevent unnecessary redirection.
apps/web/src/middleware.ts Added new public paths and specific handling for the /welcome path based on registration status.

Possibly related PRs

Suggested reviewers

  • bitfalt

Poem

I'm a bunny in the code field, hopping with delight,
Adding states and delays to make our flow just right.
With careful clicks and checks, we guard each line,
A playful dance in our code design!
Hooray for fixes and features that shine bright!
🐰✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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 generate docstrings to generate docstrings for this 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

netlify bot commented Mar 5, 2025

Deploy Preview for lucent-florentine-971919 ready!

Name Link
🔨 Latest commit 1407a84
🔍 Latest deploy log https://app.netlify.com/sites/lucent-florentine-971919/deploys/67c7f9b8de8fa50008cc9615
😎 Deploy Preview https://deploy-preview-161--lucent-florentine-971919.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

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

🧹 Nitpick comments (3)
apps/web/src/app/register/page.tsx (2)

55-79: Streamlined permission handling improves user flow.

The notification permission request has been simplified to return a resolved promise rather than requesting actual permissions from the user. This change:

  1. Removes a potential friction point in the registration process
  2. Simplifies the user flow by eliminating permission requests
  3. Maintains the function interface while making it a no-op

Consider fully removing the commented code for better maintainability rather than keeping it commented out. If needed in the future, the code can be retrieved from version control.

-  // Function to request notification permission - commented out
  const requestPermission = async () => {
-    // Notification permission request is now commented out
-    // This allows registration to proceed without requiring notification permissions
-    /*
-    const requestPermissionPayload: RequestPermissionPayload = {
-      permission: Permission.Notifications,
-    };
-    try {
-      const payload = await MiniKit.commandsAsync.requestPermission(
-        requestPermissionPayload,
-      );
-      return payload;
-    } catch (error) {
-      console.error("Permission request failed:", error);
-      if (error instanceof Error) {
-        setErrorCode(error.message as NotificationErrorCode);
-      }
-      return null;
-    }
-    */
-    
-    // Return a resolved promise to maintain function signature
    return Promise.resolve(null);
  };

172-173: Consider updating the comment to reflect the changed behavior.

Since the requestPermission function no longer actually requests notification permissions, the comment should be updated to reflect the current behavior.

-      // Request notification permission after successful registration
+      // Previously requested notification permission, now simplified to improve user flow
       await requestPermission();
apps/web/src/app/ideology-test/page.tsx (1)

279-287: Good implementation of delayed navigation with visual feedback.

Adding a delay before moving to the next question provides valuable visual feedback to users, showing them which answer they've selected before proceeding.

Consider extracting the delay duration to a named constant at the top of the file for better maintainability:

// Add near the top of the file with other constants
+const ANSWER_FEEDBACK_DELAY_MS = 800;

// Then in the setTimeout
-      }, 800); // 800ms delay to show the selected answer
+      }, ANSWER_FEEDBACK_DELAY_MS);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1bf6ea0 and 272c77e.

📒 Files selected for processing (2)
  • apps/web/src/app/ideology-test/page.tsx (8 hunks)
  • apps/web/src/app/register/page.tsx (3 hunks)
🔇 Additional comments (9)
apps/web/src/app/register/page.tsx (1)

8-9: Simplified import declarations improve code clarity.

Commenting out these imports is appropriate since the associated functionality is no longer being used.

apps/web/src/app/ideology-test/page.tsx (8)

32-33: Good addition of state variables for improved UX.

Adding these state variables improves the user experience by:

  1. Tracking the currently selected answer for visual feedback
  2. Preventing multiple submissions while an answer is being processed

240-246: Enhanced answer handling with visual feedback.

The improved handleAnswer function now provides better user feedback by:

  1. Preventing multiple clicks/answers while processing
  2. Visually indicating the selected answer before proceeding

288-291: Good error handling with state reset.

The error handling logic now properly resets both the processing state and selected answer state, ensuring the UI remains responsive even if an error occurs.


409-412: Improved button selection logic.

The enhanced selection logic now considers both current and saved selections, providing appropriate visual feedback to users.


423-425: Appropriate button disabling during processing.

Disabling the answer buttons while processing prevents users from submitting multiple answers quickly, which improves both UX and data integrity.


438-442: Consistent UI state management for navigation buttons.

The Previous button is now correctly disabled while an answer is being processed, maintaining UI consistency.


454-458: Proper End Test button state management.

The End Test button is appropriately disabled during answer processing, preventing accidental submissions.


467-471: Consistent Next button state handling.

The Next button is properly disabled during answer processing, ensuring a smooth user experience.

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

🧹 Nitpick comments (6)
apps/web/src/middleware.ts (1)

17-17: Note potential redundancy in welcome page handling.

The welcome page is now both in the publicPaths array and has a special handling case (lines 73-80). While this works, it creates some redundancy in the code. Consider removing it from publicPaths if the special case is meant to be the only way to access this page.

apps/web/src/app/insights/page.tsx (1)

175-178: Consider refactoring for better modal transition management.

Using setTimeout for UI transitions can lead to inconsistent behavior across different devices with varying performance. Consider using a state machine or a dedicated library for managing modal transitions.

-    setTimeout(() => {
-      setIsModalOpen(false);
-    }, 50);
+    // Using a more declarative approach
+    const transitionToShareModal = () => {
+      setIsShareModalOpen(true);
+      // Use requestAnimationFrame for smoother transitions
+      requestAnimationFrame(() => {
+        requestAnimationFrame(() => {
+          setIsModalOpen(false);
+        });
+      });
+    };
+    
+    transitionToShareModal();
apps/web/src/app/api/user/by-wallet/route.ts (1)

54-58: Provide more context in error responses.

Returning a generic "Failed to fetch user data" message is fine for production, but consider logging or including additional troubleshooting details when in development mode, to expedite debugging.

apps/web/src/app/welcome/page.tsx (3)

21-24: Limit excessive console logging.

Repeated logs can clutter the console, especially in production. If you need detailed logs, consider a debug mode or a logging library that can be filtered by severity level.


50-74: Consolidate repeated fetch logic.

You perform a second fetch from /api/auth/session if the first call fails to retrieve a name. Consider extracting both fetch attempts into a small helper function or a single consolidated endpoint to reduce repetition and improve maintainability.


84-86: Refine fallback logic.

Your multi-stage fallback to sessionStorage and finally "User" makes sense, but you might want to provide a user notice or an error state if no name is found. Else, they may be labeled "User" unexpectedly.

Also applies to: 88-98

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 272c77e and 1407a84.

📒 Files selected for processing (11)
  • apps/web/src/app/(home)/page.tsx (2 hunks)
  • apps/web/src/app/api/user/by-wallet/route.ts (1 hunks)
  • apps/web/src/app/insights/page.tsx (2 hunks)
  • apps/web/src/app/register/page.tsx (4 hunks)
  • apps/web/src/app/settings/page.tsx (3 hunks)
  • apps/web/src/app/welcome/page.tsx (2 hunks)
  • apps/web/src/components/layout/LayoutContent.tsx (1 hunks)
  • apps/web/src/components/ui/navigation/BannerTop.tsx (1 hunks)
  • apps/web/src/components/ui/overlays/VerifyModal.tsx (1 hunks)
  • apps/web/src/hooks/useAuth.ts (1 hunks)
  • apps/web/src/middleware.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/web/src/app/register/page.tsx
🔇 Additional comments (13)
apps/web/src/components/ui/navigation/BannerTop.tsx (1)

7-7:

❓ Verification inconclusive

Error handling has been removed from the verification process.

You've removed the error variable from the destructured return value of useVerification(). This means the component no longer has a way to inform users if verification fails. Consider whether error handling should be implemented elsewhere or if users should still be notified of verification failures.


🏁 Script executed:

#!/bin/bash
# Check if error handling is implemented elsewhere in the codebase

# Look for references to verification error handling in other components
echo "Searching for verification error handling in other components..."
rg -l "error.*useVerification|useVerification.*error" --type=tsx

# Check the implementation of useVerification hook to see if errors are handled elsewhere
echo "Checking the implementation of useVerification hook..."
rg -l "function useVerification" --type=ts

Length of output: 435


Attention: Missing User-Facing Error Handling in Verification

It appears that the error field has been removed from the destructured return of useVerification() in the BannerTop.tsx component, which means that any failures during the verification process won’t be communicated to the user. The search for error-specific handling in the codebase (and the hook’s implementation) hasn’t revealed any alternative error notification mechanism.

  • Location to review:
    • apps/web/src/components/ui/navigation/BannerTop.tsx – currently only destructures isVerifying, isVerified, isLoading, and handleVerify.
    • apps/web/src/hooks/useVerification.ts – verify if it still handles error logic internally that might be propagated elsewhere.

Recommendation:
Please confirm whether error handling is addressed at a higher level (for example, by a global error boundary or separate notification system). If not, consider reintroducing error handling in this component (or via a dedicated mechanism) to ensure users are informed of verification failures as needed.

apps/web/src/components/layout/LayoutContent.tsx (1)

73-82: Good UX improvement to prevent navigation flickering during modal transitions.

Adding the delay before hiding the navigation when closing the share modal is a useful improvement that prevents flickering during transitions. The code is well-commented and clearly explains the purpose of the timeout.

apps/web/src/middleware.ts (2)

11-12: LGTM: New public API endpoint added.

Adding the /api/user/by-wallet path to the public paths is appropriate if you need to retrieve user information based on wallet address without authentication.


73-80: Good implementation of registration flow.

The special case for the welcome page correctly handles users who have just completed registration by checking for the registration_status cookie. This implementation works well with the changes in the useAuth hook to create a smooth registration flow.

apps/web/src/app/settings/page.tsx (3)

12-12: Clean approach to commented-out imports.

The comment clearly explains why the import is commented out rather than removed completely, which is good practice for temporary changes.


30-54: Good implementation of placeholder toggle component.

The DummyToggleSwitch component correctly implements the visual aspects of a toggle with proper accessibility attributes while making it clear it's a placeholder without actual theme-changing functionality.

Some positive aspects:

  • Includes proper ARIA attributes (role="switch", aria-checked)
  • Maintains internal state for UI interactions
  • Uses conditional classes for visual feedback
  • Clear naming that indicates its temporary nature

251-252: Clear usage with explanatory comment.

The comment clearly explains this is a placeholder for the dark theme toggle functionality, which is helpful for other developers.

apps/web/src/app/insights/page.tsx (1)

59-66: Effective consolidation of modal state management.

The combined effect is a good approach to ensure the bottom navigation stays hidden when either modal is open, reducing redundancy and potential inconsistencies.

apps/web/src/components/ui/overlays/VerifyModal.tsx (1)

42-48: Improved user guidance for verification process.

The updated text provides clearer instructions that focus on using the World ID app rather than finding a physical Orb, making the verification process more accessible to users. The step-by-step guidance is also more direct and actionable.

apps/web/src/app/(home)/page.tsx (2)

28-29: Good code maintenance with explanatory comments.

Keeping the function with a clear explanation of why it's retained despite not being needed for the current implementation shows good code maintenance practices.


72-76: Simplified verification modal display logic.

The removal of the sessionStorage check means the modal will appear consistently for unverified users. This is a more assertive approach to user verification.

The comment correctly explains the change, which helps other developers understand the intent behind the modification.

apps/web/src/app/api/user/by-wallet/route.ts (2)

5-17: Well-defined response interface – minimal improvements needed.

The UserResponse interface is consistent with the returned data structure. If you're certain the database fields are always strings, you can streamline by removing unnecessary .toString() calls. Otherwise, this looks good.


21-29: Consider validating or sanitizing wallet addresses.

Currently, there's no validation for walletAddress. Depending on your application's needs, you might want to ensure it's properly formatted or sanitized to avoid potential edge cases or database attacks.

Comment on lines +36 to +43
// Check if registration was just completed
const registrationComplete = sessionStorage.getItem("registration_complete");
if (registrationComplete && pathname === "/welcome") {
// If we're on the welcome page and registration was just completed,
// skip auth check to prevent redirection
setAuthState((prev) => ({ ...prev, loading: false }));
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Ensure session storage key is cleared after use.

This new code properly handles users who have just completed registration by allowing them to access the welcome page. However, there's no code to clear the registration_complete item from sessionStorage after it's been used, which might lead to unwanted behavior if the user navigates back to the welcome page later.

// Check if registration was just completed
const registrationComplete = sessionStorage.getItem("registration_complete");
if (registrationComplete && pathname === "/welcome") {
  // If we're on the welcome page and registration was just completed,
  // skip auth check to prevent redirection
  setAuthState((prev) => ({ ...prev, loading: false }));
+ // Clear the flag to prevent future bypassing of auth checks
+ sessionStorage.removeItem("registration_complete");
  return;
}
📝 Committable suggestion

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

Suggested change
// Check if registration was just completed
const registrationComplete = sessionStorage.getItem("registration_complete");
if (registrationComplete && pathname === "/welcome") {
// If we're on the welcome page and registration was just completed,
// skip auth check to prevent redirection
setAuthState((prev) => ({ ...prev, loading: false }));
return;
}
// Check if registration was just completed
const registrationComplete = sessionStorage.getItem("registration_complete");
if (registrationComplete && pathname === "/welcome") {
// If we're on the welcome page and registration was just completed,
// skip auth check to prevent redirection
setAuthState((prev) => ({ ...prev, loading: false }));
// Clear the flag to prevent future bypassing of auth checks
sessionStorage.removeItem("registration_complete");
return;
}

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

Successfully merging this pull request may close these issues.

1 participant