Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@steven-tey
Copy link
Collaborator

@steven-tey steven-tey commented Jul 3, 2025

Summary by CodeRabbit

  • New Features

    • Added the ability to edit the partner's email address in the profile form, with conditional restrictions based on payout status.
    • Enhanced user warnings and confirmation dialogs when changing sensitive fields (email, country, or profile type) that may impact Stripe payouts.
    • Unified disabling logic and tooltips for email, country, and profile type fields when payouts have been completed.
  • Bug Fixes

    • Improved error messages and validation when attempting to update restricted profile fields after payouts have been received.

@vercel
Copy link
Contributor

vercel bot commented Jul 3, 2025

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

Name Status Preview Updated (UTC)
dub ✅ Ready (Inspect) Visit Preview Jul 3, 2025 0:51am

@steven-tey
Copy link
Collaborator Author

@CodeRabbit final review pls

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 3, 2025

Walkthrough

The changes add support for editing a partner's email address in the profile form, with conditional disabling and tooltips if payouts have been completed. The backend schema and update logic are updated to require and validate the email field, and to restrict email changes if payouts exist, aligning with existing restrictions on other sensitive fields.

Changes

File(s) Change Summary
apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/page-client.tsx Added email editing to profile form; updated form types and defaults; added conditional disabling and tooltips for email, country, and profile type fields based on payout status; enhanced save logic with confirmation dialog for Stripe accounts.
apps/web/lib/actions/partners/update-partner-profile.ts Required and validated email in schema; updated action to process and restrict email changes if payouts exist; updated error messaging; ensured email is updated in the partner record.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ProfileForm
    participant ConfirmationDialog
    participant BackendAction

    User->>ProfileForm: Edit email/country/profile type
    ProfileForm->>User: Disable fields or show tooltip if payouts exist
    User->>ProfileForm: Click "Save changes"
    alt Stripe Connect ID present
        ProfileForm->>ConfirmationDialog: Show warning about resetting Stripe
        ConfirmationDialog->>User: Prompt for confirmation
        User->>ConfirmationDialog: Confirm/Cancel
        alt User cancels
            ConfirmationDialog->>ProfileForm: Abort submission
        else User confirms
            ProfileForm->>BackendAction: Submit updated profile data
        end
    else
        ProfileForm->>BackendAction: Submit updated profile data
    end
    BackendAction->>ProfileForm: Success/Error response
Loading

Poem

A bunny with code on its mind,
Hopped in and made email refined.
With tooltips and checks for payouts past,
Now changes to profiles are safe and steadfast.
Stripe and forms in harmony dwell—
The dashboard’s improved, and all is well!
🐇✨

✨ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 3, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Read the partner profile page client component
cat "apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/page-client.tsx"

Length of output: 15350


🏁 Script executed:

#!/bin/bash
# Read the update partner profile action
cat "apps/web/lib/actions/partners/update-partner-profile.ts"

Length of output: 4139


🏁 Script executed:

#!/bin/bash
# Check git diff to see what specific changes were made
git diff HEAD~1 HEAD -- "apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/page-client.tsx" "apps/web/lib/actions/partners/update-partner-profile.ts"

Length of output: 182


🏁 Script executed:

#!/bin/bash
# Look for any related types or interfaces that might be relevant
fd -e ts -e tsx -x grep -l "PartnerProfile\|updatePartnerProfile" {} \;

Length of output: 3209


🏁 Script executed:

#!/bin/bash
# Check for any validation schemas or types related to partner profile
rg "PartnerProfile" -A 5 -B 5 --type ts --type tsx

Length of output: 78


🏁 Script executed:

#!/bin/bash
# Check for PartnerProfile types and schemas with correct file extensions
rg "PartnerProfile" -A 5 -B 5 --type ts

Length of output: 104574


🏁 Script executed:

#!/bin/bash
# Look at the partner profile schema
cat "apps/web/lib/zod/schemas/partner-profile.ts"

Length of output: 3253


🏁 Script executed:

#!/bin/bash
# Check the types file for PartnerProps definition
cat "apps/web/lib/types.ts" | grep -A 20 -B 5 "PartnerProps"

Length of output: 2309


🏁 Script executed:

#!/bin/bash
# Check for any recent commits on these files to understand the changes
git log --oneline -10 -- "apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/page-client.tsx" "apps/web/lib/actions/partners/update-partner-profile.ts"

Length of output: 0


🏁 Script executed:

#!/bin/bash
# Check for any validation or error handling patterns
rg "completedPayoutsCount" -A 3 -B 3 --type ts

Length of output: 9128


@steven-tey Looking at your partner profile update implementation, this is a well-structured feature with solid business logic and security considerations. Here's my final review:

Strengths

Security & Validation:

  • Proper server-side validation matching client-side restrictions
  • Authentication with authPartnerActionClient
  • Input sanitization and file upload restrictions (2MB limit)
  • Protection against unauthorized profile changes

Business Logic:

  • Excellent handling of payout restrictions - partners with completed payouts can't change critical fields
  • Smart Stripe account cleanup when restricted fields are modified
  • Proper error messages explaining restrictions to users

User Experience:

  • Great accessibility with tooltips explaining disabled fields
  • Responsive form with proper loading states
  • Clear visual feedback for restricted actions
  • Smooth animations for conditional company name field

Code Quality:

  • Good TypeScript usage with proper type definitions
  • Effective use of React Hook Form for form management
  • Proper separation of concerns between client and server code
  • Clean error handling with user-friendly messages

🔧 Minor Suggestions

Component Organization:
The ProfileForm component is quite large (~200 lines). Consider extracting smaller components:

// Extract field components
<EmailField completedPayoutsCount={completedPayoutsCount} />
<CountryField completedPayoutsCount={completedPayoutsCount} />
<ProfileTypeField completedPayoutsCount={completedPayoutsCount} />

Code Duplication:
The completedPayoutsCount > 0 checks could be extracted to a custom hook:

const useFieldRestrictions = (completedPayoutsCount: number) => ({
  isRestricted: completedPayoutsCount > 0,
  getTooltip: (fieldName: string) => `Since you've already received payouts...`,
  getFieldProps: (fieldName: string) => ({ disabled: completedPayoutsCount > 0 })
});

📋 Technical Notes

Image Handling: The conditional image upload logic is clean:

image: imageChanged ? data.image : null

Form Validation: The Zod schema properly handles the company name requirement:

.refine((data) => data.profileType === "company" ? !!data.companyName : true)

Cache Invalidation: Good use of qstash for invalidating partner caches when image/name changes.

🎯 Overall Assessment

This is production-ready code that demonstrates solid understanding of:

  • Complex form handling with business rules
  • Security best practices
  • User experience considerations
  • Integration with external services (Stripe)

The implementation properly balances user flexibility with business requirements around payout restrictions. The code is maintainable and follows React/Next.js best practices.

Approved ✅ - This feature is ready for deployment with excellent attention to security, UX, and business logic requirements.

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

🧹 Nitpick comments (3)
apps/web/lib/actions/partners/update-partner-profile.ts (1)

81-82: Update the comment to include email.

The comment should reflect that email is now also restricted along with country, profile type, and company name.

-      // Partner is not able to update their country, profile type, or company name
+      // Partner is not able to update their email, country, profile type, or company name
apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/page-client.tsx (2)

143-155: Enhance confirmation dialog to be more specific about changed fields.

The current confirmation dialog shows a generic message regardless of which specific fields have changed. Consider making it more precise to improve user experience.

-        onClick={() => {
-          if (partner?.stripeConnectId) {
-            const confirmed = window.confirm(
-              "Updating your email, country, or profile type will reset your Stripe account, which will require you to restart the payouts connection process. Are you sure you want to continue?",
-            );
-
-            if (!confirmed) {
-              return;
-            }
-          }
-
-          formRef.current?.requestSubmit();
-        }}
+        onClick={() => {
+          if (partner?.stripeConnectId) {
+            const form = formRef.current;
+            if (form) {
+              const formData = new FormData(form);
+              const changedFields = [];
+              
+              if (formData.get('email') !== partner.email) changedFields.push('email');
+              if (formData.get('country') !== partner.country) changedFields.push('country');
+              if (formData.get('profileType') !== partner.profileType) changedFields.push('profile type');
+              
+              if (changedFields.length > 0) {
+                const confirmed = window.confirm(
+                  `Updating your ${changedFields.join(', ')} will reset your Stripe account, which will require you to restart the payouts connection process. Are you sure you want to continue?`,
+                );
+
+                if (!confirmed) {
+                  return;
+                }
+              }
+            }
+          }
+
+          formRef.current?.requestSubmit();
+        }}

315-315: Simplify boolean expression.

The ternary operator is unnecessary when the result is already a boolean.

-                  error={errors.country ? true : false}
+                  error={!!errors.country}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between eb3e244 and e405ed7.

📒 Files selected for processing (2)
  • apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/page-client.tsx (9 hunks)
  • apps/web/lib/actions/partners/update-partner-profile.ts (5 hunks)
🧰 Additional context used
🧠 Learnings (1)
apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/page-client.tsx (2)
Learnt from: devkiran
PR: dubinc/dub#2448
File: packages/email/src/templates/partner-program-summary.tsx:0-0
Timestamp: 2025-05-29T04:45:18.504Z
Learning: In the PartnerProgramSummary email template (packages/email/src/templates/partner-program-summary.tsx), the stat titles are hardcoded constants ("Clicks", "Leads", "Sales", "Earnings") that will always match the ICONS object keys after toLowerCase() conversion, so icon lookup failures are not possible.
Learnt from: TWilson023
PR: dubinc/dub#2471
File: apps/web/ui/auth/reset-password-form.tsx:52-65
Timestamp: 2025-06-04T15:09:51.562Z
Learning: In the Dub codebase, server-side validation errors for password fields are handled via toast notifications rather than using react-hook-form's setError method to display field-specific errors. This architectural pattern separates client-side validation feedback (inline) from server-side error handling (toast).
🧬 Code Graph Analysis (1)
apps/web/lib/actions/partners/update-partner-profile.ts (1)
apps/web/lib/stripe/index.ts (1)
  • stripe (3-9)
🪛 Biome (1.9.4)
apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/page-client.tsx

[error] 315-315: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build

@steven-tey
Copy link
Collaborator Author

@CodeRabbit final review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 3, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Read the main files involved in this PR to understand the implementation
echo "=== Frontend Profile Form Component ==="
cat "apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/page-client.tsx"

echo -e "\n=== Backend Update Action ==="
cat "apps/web/lib/actions/partners/update-partner-profile.ts"

echo -e "\n=== Check for any validation schemas ==="
find apps/web/lib -name "*.ts" -exec grep -l "updatePartnerProfile\|PartnerProfile" {} \; | head -5

Length of output: 20203


@steven-tey Looking at your partner profile update implementation, this is a well-structured feature with solid business logic and security considerations. Here's my final review:

Strengths

Security & Validation:

  • Proper server-side validation matching client-side restrictions
  • Authentication with authPartnerActionClient
  • Input sanitization and file upload restrictions (2MB limit)
  • Protection against unauthorized profile changes

Business Logic:

  • Excellent handling of payout restrictions - partners with completed payouts can't change critical fields
  • Smart Stripe account cleanup when restricted fields are modified
  • Proper error messages explaining restrictions to users

User Experience:

  • Great accessibility with tooltips explaining disabled fields
  • Responsive form with proper loading states
  • Clear visual feedback for restricted actions
  • Smooth animations for conditional company name field

Code Quality:

  • Good TypeScript usage with proper type definitions
  • Effective use of React Hook Form for form management
  • Proper separation of concerns between client and server code
  • Clean error handling with user-friendly messages

🔧 Minor Suggestions

Component Organization:
The ProfileForm component is quite large (~200 lines). Consider extracting smaller components:

// Extract field components
<EmailField completedPayoutsCount={completedPayoutsCount} />
<CountryField completedPayoutsCount={completedPayoutsCount} />
<ProfileTypeField completedPayoutsCount={completedPayoutsCount} />

Code Duplication:
The completedPayoutsCount > 0 checks could be extracted to a custom hook:

const useFieldRestrictions = (completedPayoutsCount: number) => ({
  isRestricted: completedPayoutsCount > 0,
  getTooltip: (fieldName: string) => `Since you've already received payouts...`,
  getFieldProps: (fieldName: string) => ({ disabled: completedPayoutsCount > 0 })
});

📋 Technical Notes

Image Handling: The conditional image upload logic is clean:

image: imageChanged ? data.image : null

Form Validation: The Zod schema properly handles the company name requirement:

.refine((data) => data.profileType === "company" ? !!data.companyName : true)

Cache Invalidation: Good use of qstash for invalidating partner caches when image/name changes.

🎯 Overall Assessment

This is production-ready code that demonstrates solid understanding of:

  • Complex form handling with business rules
  • Security best practices
  • User experience considerations
  • Integration with external services (Stripe)

The implementation properly balances user flexibility with business requirements around payout restrictions. The code is maintainable and follows React/Next.js best practices.

Approved ✅ - This feature is ready for deployment with excellent attention to security, UX, and business logic requirements.

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 (2)
apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/page-client.tsx (2)

143-155: Consider including company name in the confirmation dialog.

The confirmation message mentions "email, country, or profile type" but based on the backend restrictions, company name changes also reset the Stripe account. Consider updating the message for completeness.

-              "Updating your email, country, or profile type will reset your Stripe account, which will require you to restart the payouts connection process. Are you sure you want to continue?",
+              "Updating your email, country, profile type, or company name will reset your Stripe account, which will require you to restart the payouts connection process. Are you sure you want to continue?",

314-314: Simplify boolean expression.

The ternary operator with boolean literals is unnecessary and can be simplified for better readability.

-                  error={errors.country ? true : false}
+                  error={!!errors.country}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e405ed7 and 2aa48e2.

📒 Files selected for processing (1)
  • apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/page-client.tsx (8 hunks)
🧰 Additional context used
🧠 Learnings (1)
apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/page-client.tsx (2)
Learnt from: devkiran
PR: dubinc/dub#2448
File: packages/email/src/templates/partner-program-summary.tsx:0-0
Timestamp: 2025-05-29T04:45:18.504Z
Learning: In the PartnerProgramSummary email template (packages/email/src/templates/partner-program-summary.tsx), the stat titles are hardcoded constants ("Clicks", "Leads", "Sales", "Earnings") that will always match the ICONS object keys after toLowerCase() conversion, so icon lookup failures are not possible.
Learnt from: TWilson023
PR: dubinc/dub#2471
File: apps/web/ui/auth/reset-password-form.tsx:52-65
Timestamp: 2025-06-04T15:09:51.562Z
Learning: In the Dub codebase, server-side validation errors for password fields are handled via toast notifications rather than using react-hook-form's setError method to display field-specific errors. This architectural pattern separates client-side validation feedback (inline) from server-side error handling (toast).
🪛 Biome (1.9.4)
apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/page-client.tsx

[error] 314-314: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (4)
apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/page-client.tsx (4)

93-93: LGTM: Email field properly added to form data type.

The email field addition aligns with the PR objective to enable partner email updates.


108-108: LGTM: Proper email initialization with fallback.

The form correctly initializes with the partner's current email and provides an empty string fallback for null values.


272-301: LGTM: Well-implemented email field with proper restrictions.

The email input field correctly:

  • Uses proper validation with errors.email reference
  • Implements conditional disabling based on completed payouts
  • Provides informative tooltip explaining restrictions
  • Applies appropriate styling for disabled state

Great implementation that follows the established patterns in the codebase.


350-392: LGTM: Consistent tooltip implementation for profile type field.

The profile type field correctly implements the same conditional disabling pattern as other restricted fields, with appropriate tooltip messaging and visual feedback for disabled state.

@steven-tey steven-tey merged commit 24b14b3 into main Jul 3, 2025
5 of 7 checks passed
@steven-tey steven-tey deleted the update-partner-email branch July 3, 2025 00:30
@coderabbitai coderabbitai bot mentioned this pull request Sep 24, 2025
@coderabbitai coderabbitai bot mentioned this pull request Oct 26, 2025
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.

2 participants