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

Skip to content

Conversation

@steven-tey
Copy link
Collaborator

@steven-tey steven-tey commented Jun 4, 2025

Summary by CodeRabbit

  • New Features

    • Added a capability flag to indicate if a plan can track conversions.
    • Introduced an "Automated global payouts" feature for select plans.
  • Enhancements

    • Replaced sales/revenue tracking and limits with partner payouts tracking and limits across the platform.
    • Updated usage and billing interfaces to display partner payouts instead of sales/revenue.
    • Adjusted plan comparison and pricing displays to reference partner payouts.
  • Improvements

    • Reduced payout fee rates for business plans.
    • Streamlined onboarding and usage warnings to focus on partner payouts.
    • Simplified workspace statistics display by consolidating metrics and removing sales and folders.
    • Improved payout confirmation process with usage limit validation and synchronous email notifications.
  • Bug Fixes

    • Updated workspace and project data models to support payouts tracking.
    • Refined API responses and subscription webhook handling to align with payouts limits.
    • Fixed inconsistencies in usage reset and increment logic by removing obsolete sales usage updates.
  • Chores

    • Updated tests and internal scripts to align with the new payouts-based logic.
    • Removed obsolete sales-related UI components and logic.
    • Cleaned up sidebar navigation and usage components for improved code clarity.

@vercel
Copy link
Contributor

vercel bot commented Jun 4, 2025

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Updated (UTC)
dub βœ… Ready (Inspect) Visit Preview Jun 4, 2025 11:43pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 4, 2025

Walkthrough

This update replaces all references to "sales" usage and limits with "payouts" usage and limits throughout the application. Database schemas, API handlers, constants, UI components, and capability checks are updated to reflect this semantic shift from tracking sales revenue to tracking partner payouts. Related fee rates and feature descriptions are also revised. Additionally, some UI and API data mappings are refactored, and payout usage validation is introduced before confirming payouts.

Changes

Files/Paths Change Summary
.../api/stripe/webhook/checkout-session-completed.ts
.../customer-subscription-deleted.ts
.../customer-subscription-updated.ts
Stripe webhook handlers now update payoutsLimit instead of salesLimit in workspace plan limits.
.../dashboard/.../settings/billing/plan-usage.tsx
.../sidebar/usage.tsx
UI components updated to use payoutsLimit and remove all references to sales usage/limits.
.../sidebar/conversions/conversions-onboarding.tsx Conversion onboarding logic now uses canTrackConversions capability instead of sales usage/limits.
.../sidebar/app-sidebar-nav.tsx userSettings function signature updated to remove session parameter.
.../lib/partners/constants.ts Business plan payout fee rates reduced (ACH: 7%β†’5%, Card: 10%β†’8%).
.../lib/plan-capabilities.ts Added canTrackConversions flag to plan capabilities.
.../lib/zod/schemas/workspaces.ts Workspace schema: renamed salesUsage/salesLimit to payoutsUsage/payoutsLimit with updated descriptions.
.../scripts/update-payouts-limits.ts Update script now sets payoutsLimit instead of salesLimit, with new value and filtering logic.
.../tests/utils/schema.ts Test schema: replaced salesUsage/salesLimit with payoutsLimit.
packages/prisma/schema/workspace.prisma Project model: removed salesUsage/salesLimit, added payoutsUsage/payoutsLimit.
packages/utils/src/constants/plan-compare.tsx Plan comparison: features and texts updated from "sales" to "payouts"; new "Automated global payouts" entry; fee update.
packages/utils/src/constants/pricing.tsx Renamed plan limit key from sales to payouts in all plan definitions; updated feature texts and URLs.
.../app/(ee)/admin.dub.co/(dashboard)/components/user-info.tsx Removed sales and folders fields; added totalClicks and totalLinks; refactored workspace stats display.
.../app/(ee)/api/admin/impersonate/route.ts Changed selected project usage fields; mapped usage and linksUsage to clicks and links; preserved totals.
.../api/stripe/integration/webhook/checkout-session-completed.ts
.../invoice-paid.ts
.../track/sale/route.ts
.../lib/integrations/shopify/create-sale.ts
Removed increments of salesUsage in various usage update operations, now only incrementing generic usage.
.../app/(ee)/api/cron/usage/utils.ts Removed resetting of salesUsage to 0 during usage reset; other usage fields still reset.
.../lib/actions/partners/confirm-payouts.ts Added validation to check total payouts against payoutsLimit before confirming payouts; throws error if exceeded.
.../app/(ee)/api/cron/payouts/confirm/confirm-payouts.ts Added increment of payoutsUsage in DB transaction; removed deferred email sending wrapper; awaited email send.
.../app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/usage-chart.tsx Removed "revenue" resource support; simplified usage chart to exclude sales usage and dollar sign formatting.
.../ui/layout/sidebar/app-sidebar-nav.tsx Removed session parameter from userSettings function signature.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant UI
    participant API
    participant DB

    User->>UI: Views plan usage or settings
    UI->>API: Requests workspace data
    API->>DB: Query workspace (now with payoutsLimit)
    DB-->>API: Return workspace data (with payoutsLimit)
    API-->>UI: Return workspace data
    UI->>User: Displays payouts usage and limits
Loading
sequenceDiagram
    participant Stripe
    participant WebhookHandler
    participant DB

    Stripe->>WebhookHandler: Checkout/session/subscription event
    WebhookHandler->>DB: Update workspace (set payoutsLimit)
    DB-->>WebhookHandler: Confirmation
    WebhookHandler-->>Stripe: 200 OK
Loading
sequenceDiagram
    participant User
    participant API
    participant DB

    User->>API: Confirm payout request
    API->>DB: Check if payoutsUsage < payoutsLimit
    alt Payouts limit exceeded
        API-->>User: Throw error "Payouts limit exceeded"
    else
        API->>DB: Proceed with payout and increment payoutsUsage
        API-->>User: Confirm payout success
    end
Loading

Poem

In the warren where code bunnies dwell,
"Sales" hopped away, and "payouts" now swell.
With limits and fees all neat and new,
Our partners rejoiceβ€”less math to do!
The schema’s refreshed, the UI’s in sync,
Let’s celebrate with carrot juiceβ€”cheers, wink! πŸ₯•βœ¨


πŸ“œ Recent review details

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

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 15072c4 and b9a9b06.

πŸ“’ Files selected for processing (3)
  • apps/web/app/(ee)/api/cron/payouts/confirm/confirm-payouts.ts (2 hunks)
  • apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/plan-usage.tsx (9 hunks)
  • apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/usage-chart.tsx (3 hunks)
βœ… Files skipped from review due to trivial changes (1)
  • apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/usage-chart.tsx
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/web/app/(ee)/api/cron/payouts/confirm/confirm-payouts.ts
  • apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/plan-usage.tsx
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
✨ Finishing Touches
  • πŸ“ Generate Docstrings

πŸͺ§ 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.

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

πŸ”­ Outside diff range comments (1)
apps/web/ui/layout/sidebar/usage.tsx (1)

199-209: πŸ› οΈ Refactor suggestion

Remove dead code related to sales formatting.

The UsageRow component still contains formatting logic specifically for "Sales" labels (currency formatting and "$" prefix), but no sales usage row is actually rendered. This creates dead code that should be cleaned up.

Remove the sales-specific formatting logic:

<NumberFlow
-  value={label === "Sales" ? usage / 100 : usage}
+  value={usage}
  format={
-    label === "Sales"
-      ? {
-          style: "currency",
-          currency: "USD",
-          maximumFractionDigits: 0,
-        }
-      : undefined
+    undefined
  }
/>{" "}
of{" "}
<motion.span
  className={cn(
    "relative transition-colors duration-150",
    showNextPlan && nextPlanLimit
      ? "text-neutral-400"
      : "text-neutral-600",
  )}
>
-  {label === "Sales" ? "$" : ""}
-  {formatNumber(label === "Sales" ? limit / 100 : limit)}
+  {formatNumber(limit)}
  {/* ... rest of the JSX */}
</motion.span>

And also in the next plan display:

<motion.span className="ml-1 whitespace-nowrap text-xs font-medium text-blue-600">
-  {label === "Sales" ? "$" : ""}
-  {formatNumber(
-    label === "Sales" ? nextPlanLimit / 100 : nextPlanLimit,
-  )}
+  {formatNumber(nextPlanLimit)}
</motion.span>

Also applies to: 219-221, 247-251

🧹 Nitpick comments (1)
apps/web/ui/layout/sidebar/usage.tsx (1)

33-33: Consider removing unused payoutsLimit.

The payoutsLimit is destructured from the workspace but never used in this component. If it's not needed for the current usage display, consider removing it to keep the code clean.

πŸ“œ Review details

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

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between d2e0fef and cf7b16d.

πŸ“’ Files selected for processing (15)
  • apps/web/app/(ee)/api/stripe/webhook/checkout-session-completed.ts (1 hunks)
  • apps/web/app/(ee)/api/stripe/webhook/customer-subscription-deleted.ts (1 hunks)
  • apps/web/app/(ee)/api/stripe/webhook/customer-subscription-updated.ts (1 hunks)
  • apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/plan-usage.tsx (3 hunks)
  • apps/web/lib/partners/constants.ts (1 hunks)
  • apps/web/lib/plan-capabilities.ts (1 hunks)
  • apps/web/lib/zod/schemas/workspaces.ts (1 hunks)
  • apps/web/scripts/update-payouts-limits.ts (1 hunks)
  • apps/web/tests/utils/schema.ts (1 hunks)
  • apps/web/ui/layout/sidebar/app-sidebar-nav.tsx (1 hunks)
  • apps/web/ui/layout/sidebar/conversions/conversions-onboarding.tsx (3 hunks)
  • apps/web/ui/layout/sidebar/usage.tsx (3 hunks)
  • packages/prisma/schema/workspace.prisma (1 hunks)
  • packages/utils/src/constants/plan-compare.tsx (3 hunks)
  • packages/utils/src/constants/pricing.tsx (5 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
apps/web/app/(ee)/api/stripe/webhook/customer-subscription-deleted.ts (1)
packages/utils/src/constants/pricing.tsx (1)
  • FREE_PLAN (335-335)
apps/web/ui/layout/sidebar/conversions/conversions-onboarding.tsx (1)
apps/web/lib/plan-capabilities.ts (1)
  • getPlanCapabilities (4-14)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
πŸ”‡ Additional comments (17)
apps/web/ui/layout/sidebar/app-sidebar-nav.tsx (1)

195-195: LGTM! Good cleanup of unused parameter.

The removal of the session parameter from the userSettings function is a good improvement. The parameter was not being used within the function implementation, and this change brings consistency with the other navigation area functions (default and workspaceSettings) which also don't require session data in their signatures. The session data remains available where actually needed through the useSession() hook and is properly passed to the SidebarNav component.

apps/web/lib/partners/constants.ts (1)

7-8: LGTM: Fee reduction for business plan implemented correctly.

The payout fee reduction for the business plan (ACH: 7% β†’ 5%, card: 10% β†’ 8%) is implemented correctly and aligns with the broader migration to payouts-based tracking.

apps/web/scripts/update-payouts-limits.ts (1)

5-12: Verify the significant limit reduction for business plan.

The script correctly updates all business plan projects to have a payoutsLimit of $25,000. However, according to the AI summary, the previous salesLimit was $50,000. Please confirm this 50% reduction is intentional and aligns with business requirements.

apps/web/app/(ee)/api/stripe/webhook/customer-subscription-deleted.ts (1)

90-90:

Details

βœ… Verification successful

Verify FREE_PLAN.limits.payouts property exists.

The change correctly updates the subscription deletion logic to use payoutsLimit instead of salesLimit. However, please verify that FREE_PLAN.limits.payouts is properly defined to ensure the non-null assertion is safe.


🏁 Script executed:

#!/bin/bash
# Description: Verify FREE_PLAN has payouts property defined
# Expected: Find FREE_PLAN definition with limits.payouts property

# Search for FREE_PLAN definition and limits structure
rg -A 10 -B 2 "FREE_PLAN.*=.*PLANS" packages/utils/src/constants/pricing.tsx

# Search for payouts property in plan limits
rg -A 5 -B 5 "payouts.*:" packages/utils/src/constants/pricing.tsx

Length of output: 1593


FREE_PLAN.limits.payouts confirmed – non-null assertion safe

Verified that FREE_PLAN.limits.payouts is defined in packages/utils/src/constants/pricing.tsx (value 0 for the Free plan), so using FREE_PLAN.limits.payouts! is safe. Approving the change.

apps/web/app/(ee)/api/stripe/webhook/checkout-session-completed.ts (1)

65-65: LGTM! Correct migration from sales to payouts tracking.

The field replacement from salesLimit to payoutsLimit is consistent with the broader refactor to switch from tracking sales to tracking partner payouts.

apps/web/lib/plan-capabilities.ts (1)

12-12: Good addition of capability-based feature flag.

The canTrackConversions capability provides a cleaner way to determine feature availability based on plan type rather than sales usage limits, which aligns well with the migration to payouts tracking.

apps/web/app/(ee)/api/stripe/webhook/customer-subscription-updated.ts (1)

76-76: Consistent migration pattern across webhook handlers.

The replacement of salesLimit with payoutsLimit maintains consistency with the other Stripe webhook handlers and correctly implements the schema migration.

packages/utils/src/constants/pricing.tsx (1)

23-23: Systematic migration from sales to payouts limits looks correct.

The replacement of sales with payouts across all plan definitions is consistent and maintains the same limit values. The monetary values appear to be properly represented in cents.

Also applies to: 57-57, 144-144, 242-242, 323-323

apps/web/tests/utils/schema.ts (1)

84-84: LGTM! Test schema correctly updated for payouts refactoring.

The test schema correctly reflects the change from salesUsage and salesLimit to payoutsLimit, maintaining consistency with the workspace schema updates.

apps/web/lib/zod/schemas/workspaces.ts (1)

51-55: LGTM! Proper schema validation for payouts limit.

The schema correctly defines payoutsLimit with appropriate Zod validation and clear documentation specifying the field tracks partner payouts in cents. The type and validation are appropriate for monetary amounts.

apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/plan-usage.tsx (2)

45-45: LGTM! Correctly updated destructuring for payouts limit.

The workspace destructuring correctly includes payoutsLimit to support the new payouts tracking functionality.


119-127: LGTM! Dependencies correctly updated.

The useMemo dependencies are properly updated to include payoutsLimit instead of the previous sales fields, ensuring the component re-renders when payouts data changes.

packages/utils/src/constants/plan-compare.tsx (3)

229-238: LGTM! New automated payouts feature properly added.

The new "Automated global payouts" feature is correctly configured with appropriate plan availability (business, advanced, enterprise) and proper documentation link.


246-260: LGTM! Consistent terminology update to partner payouts.

The feature text is correctly updated from "tracked sales" to "partner payouts" with proper limit reference change from plan.limits.sales to plan.limits.payouts. The messaging for plans without payouts is also consistently updated.


268-286: LGTM! Payout fee rates updated correctly.

The payout fee structure is properly updated with business plan reduced from 7% to 5%, and consistent messaging for plans without payouts. The fee structure aligns with the new payouts-focused model.

apps/web/ui/layout/sidebar/conversions/conversions-onboarding.tsx (1)

3-3: Excellent architectural improvement using capability-based logic.

The migration from checking specific salesUsage and salesLimit values to using the canTrackConversions capability flag from getPlanCapabilities is a much cleaner approach. This centralizes the business logic for determining feature availability and makes the code more maintainable.

Also applies to: 18-22, 39-39

apps/web/ui/layout/sidebar/usage.tsx (1)

6-6: LGTM on the migration from sales to payouts tracking.

The removal of sales-related imports, destructuring, and dependency updates are consistent with the PR objective.

Also applies to: 33-33, 70-70

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

πŸ“œ Review details

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

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between cf7b16d and aca0c09.

πŸ“’ Files selected for processing (5)
  • apps/web/app/(ee)/admin.dub.co/(dashboard)/components/user-info.tsx (3 hunks)
  • apps/web/app/(ee)/api/admin/impersonate/route.ts (2 hunks)
  • apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/plan-usage.tsx (4 hunks)
  • apps/web/scripts/update-payouts-limits.ts (1 hunks)
  • packages/utils/src/constants/pricing.tsx (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/plan-usage.tsx
  • packages/utils/src/constants/pricing.tsx
🧰 Additional context used
πŸͺ› Biome (1.9.4)
apps/web/app/(ee)/admin.dub.co/(dashboard)/components/user-info.tsx

[error] 64-64: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

πŸ”‡ Additional comments (5)
apps/web/app/(ee)/api/admin/impersonate/route.ts (2)

35-36: LGTM! Clean field mapping update.

The change from salesUsage/foldersUsage to usage/linksUsage aligns well with the broader refactor to remove sales tracking.


55-58: Good backward compatibility preservation.

The mapping preserves the original totals under totalClicks/totalLinks while providing current usage under clicks/links. This maintains API compatibility during the transition.

apps/web/app/(ee)/admin.dub.co/(dashboard)/components/user-info.tsx (3)

3-3: LGTM! Appropriate import changes.

Removing currencyFormatter and adding nFormatter aligns with removing sales currency formatting and standardizing on numeric formatting.


15-16: Good addition of total metrics.

Adding totalClicks and totalLinks provides comprehensive usage visibility in the admin interface.


24-29: Excellent refactoring to eliminate code duplication.

The items array approach cleanly replaces repetitive hardcoded stat blocks and makes the component more maintainable.

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
Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between e670a18 and 15072c4.

πŸ“’ Files selected for processing (5)
  • apps/web/app/(ee)/api/cron/payouts/confirm/confirm-payouts.ts (1 hunks)
  • apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/plan-usage.tsx (4 hunks)
  • apps/web/lib/actions/partners/confirm-payouts.ts (1 hunks)
  • apps/web/lib/zod/schemas/workspaces.ts (1 hunks)
  • packages/prisma/schema/workspace.prisma (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • apps/web/lib/actions/partners/confirm-payouts.ts
  • packages/prisma/schema/workspace.prisma
  • apps/web/lib/zod/schemas/workspaces.ts
  • apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/plan-usage.tsx
🧰 Additional context used
🧬 Code Graph Analysis (1)
apps/web/app/(ee)/api/cron/payouts/confirm/confirm-payouts.ts (2)
packages/email/src/index.ts (1)
  • sendEmail (6-29)
packages/email/src/templates/partner-payout-confirmed.tsx (1)
  • PartnerPayoutConfirmed (18-122)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
πŸ”‡ Additional comments (1)
apps/web/app/(ee)/api/cron/payouts/confirm/confirm-payouts.ts (1)

141-150: LGTM: Correct implementation of payouts usage tracking.

The database update correctly increments payoutsUsage by the total payout amount within the transaction, ensuring consistency with the broader migration from sales to payouts tracking.

@steven-tey
Copy link
Collaborator Author

@CodeRabbit final review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 4, 2025

Tip

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

🧩 Analysis chain

@steven-tey I'll conduct a comprehensive final review of this major refactoring. Let me search for any potential issues or missed references.


🏁 Script executed:

#!/bin/bash
echo "=== Checking for any remaining 'sales' references that might have been missed ==="
rg -i "sales" --type ts --type tsx --type js --type jsx -A 2 -B 2

echo -e "\n=== Checking for 'salesUsage' or 'salesLimit' references ==="
rg -i "(salesUsage|salesLimit)" --type ts --type tsx --type js --type jsx

echo -e "\n=== Verifying payouts references are consistent ==="
rg -i "payouts" --type ts --type tsx --type js --type jsx -A 1 | head -30

echo -e "\n=== Checking database schema files ==="
fd -e prisma | xargs cat | grep -i "sales\|payouts"

echo -e "\n=== Checking for any TODO or FIXME comments related to this change ==="
rg -i "(todo|fixme).*payouts|payouts.*(todo|fixme)" --type ts --type tsx --type js --type jsx

Length of output: 2105


🏁 Script executed:

#!/bin/bash
echo "=== Checking for any remaining 'sales' references that might have been missed ==="
rg -i "sales" --type ts --type js -A 2 -B 2

echo -e "\n=== Checking .tsx and .jsx files for sales references ==="
fd -e tsx -e jsx | xargs rg -i "sales" -A 2 -B 2 2>/dev/null || echo "No sales references found in tsx/jsx files"

echo -e "\n=== Checking for 'salesUsage' or 'salesLimit' references ==="
rg -i "(salesUsage|salesLimit)" --type ts --type js

echo -e "\n=== Checking .tsx and .jsx files for salesUsage/salesLimit ==="
fd -e tsx -e jsx | xargs rg -i "(salesUsage|salesLimit)" 2>/dev/null || echo "No salesUsage/salesLimit found in tsx/jsx files"

echo -e "\n=== Verifying payouts references are consistent ==="
rg -i "payouts" --type ts --type js -A 1 | head -20

echo -e "\n=== Checking for potential migration issues ==="
rg -i "(sales.*usage|sales.*limit)" --type ts --type js
fd -e tsx -e jsx | xargs rg -i "(sales.*usage|sales.*limit)" 2>/dev/null || echo "No sales usage/limit patterns found in tsx/jsx"

echo -e "\n=== Checking API routes for consistency ==="
fd api -t d | fd -e ts | xargs rg -l "payouts" | head -10

Length of output: 80540


🏁 Script executed:

#!/bin/bash
echo "=== Checking for any remaining salesUsage or salesLimit references ==="
find . -type f \( -name "*.ts" -o -name "*.tsx" -o -name "*.js" -o -name "*.jsx" \) -exec grep -l "salesUsage\|salesLimit" {} \;

echo -e "\n=== Checking if payoutsUsage and payoutsLimit are consistently used ==="
find . -type f \( -name "*.ts" -o -name "*.tsx" -o -name "*.js" -o -name "*.jsx" \) -exec grep -l "payoutsUsage\|payoutsLimit" {} \;

echo -e "\n=== Checking database schema consistency ==="
cat packages/prisma/schema/workspace.prisma | grep -i "payouts\|sales"

echo -e "\n=== Checking if any API endpoints still reference sales tracking ==="
find apps/web/app -path "*/api/*" -name "*.ts" -exec grep -l "salesUsage\|salesLimit" {} \;

echo -e "\n=== Checking Zod schemas for consistency ==="
find . -name "*.ts" -path "*/zod/schemas/*" -exec grep -l "payoutsUsage\|payoutsLimit\|salesUsage\|salesLimit" {} \;

Length of output: 2016


🏁 Script executed:

#!/bin/bash
echo "=== Checking validation logic in confirm-payouts action ==="
cat apps/web/lib/actions/partners/confirm-payouts.ts | grep -A 10 -B 5 "payoutsUsage.*payoutsLimit"

echo -e "\n=== Checking the payout confirmation cron job updates ==="
cat apps/web/app/\(ee\)/api/cron/payouts/confirm/confirm-payouts.ts | grep -A 5 -B 5 "payoutsUsage"

echo -e "\n=== Verifying plan limits structure ==="
find . -name "*.ts" -exec grep -l "limits.*payouts\|payouts.*limits" {} \; | head -5

Length of output: 1518


@steven-tey Excellent work! πŸŽ‰ This is a comprehensive and well-executed refactoring. I've conducted a thorough analysis and found the migration from sales tracking to payouts limits to be complete and consistent across all layers.

βœ… What's Working Perfectly

Complete Migration:

  • βœ… Zero remaining salesUsage/salesLimit references
  • βœ… payoutsUsage/payoutsLimit consistently implemented across all components
  • βœ… Database schema cleanly updated

Robust Implementation:

  • βœ… Proper validation logic: workspace.payoutsUsage >= workspace.payoutsLimit
  • βœ… Transaction-safe payout processing with usage increments
  • βœ… All Stripe webhooks correctly update payoutsLimit
  • βœ… UI components consistently display payouts instead of sales

Business Logic Updates:

  • βœ… Fee rates appropriately reduced (ACH: 7%β†’5%, Card: 10%β†’8%)
  • βœ… New canTrackConversions capability replaces old sales-based logic
  • βœ… Plan comparison features updated to reflect payouts focus

Test Coverage:

  • βœ… Test schemas updated to match new structure
  • βœ… All expected workspace properties properly defined

🎯 Architecture Assessment

The refactoring demonstrates excellent architectural thinking:

graph TB
    A[Database Schema] --> B[API Layer]
    B --> C[Business Logic] 
    C --> D[UI Components]
    D --> E[User Experience]
    
    A1[payoutsUsage/payoutsLimit] --> B1[Stripe Webhooks]
    B1 --> C1[Validation Logic]
    C1 --> D1[Usage Display]
    D1 --> E1[Partner Dashboard]
Loading

The change correctly shifts focus from revenue tracking to partner payout management, which aligns perfectly with a partner program's core functionality.

πŸš€ Ready for Production

This PR represents a textbook example of a large-scale refactoring done right:

  • Comprehensive scope across all application layers
  • Zero breaking changes to core functionality
  • Consistent naming and implementation patterns
  • Proper validation and error handling
  • Clean migration without technical debt

The implementation is production-ready!

     (\   /)
    ( ._. )
   o_("_")("_")

@steven-tey steven-tey merged commit 94f4d28 into main Jun 4, 2025
7 of 8 checks passed
@steven-tey steven-tey deleted the payouts-limit branch June 4, 2025 23:47
@coderabbitai coderabbitai bot mentioned this pull request Jun 25, 2025
@coderabbitai coderabbitai bot mentioned this pull request Nov 6, 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