Skip to content

Skip click/lead/sale commissions for non-active program enrollments#4018

Merged
steven-tey merged 5 commits into
mainfrom
skip-commissions-for-non-active-partners
Jun 10, 2026
Merged

Skip click/lead/sale commissions for non-active program enrollments#4018
steven-tey merged 5 commits into
mainfrom
skip-commissions-for-non-active-partners

Conversation

@pepeladeira

@pepeladeira pepeladeira commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Bug Fixes

    • Click aggregation now only processes clicks for commission-eligible enrollments (including "invited"), reducing incorrect payouts.
    • Commission creation workflow skips and logs ineligible click, lead, and sale events to prevent incorrect allocations.
  • New Features

    • "Create commission" action (button, menu item, and keyboard shortcut) is disabled when the partner enrollment is not eligible.

@vercel

vercel Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
dub Ready Ready Preview Jun 10, 2026 6:30pm

Request Review

@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0620e15b-0333-4240-b00d-b161d85f49b5

📥 Commits

Reviewing files that changed from the base of the PR and between 0c452dc and 4df1c89.

📒 Files selected for processing (4)
  • apps/web/app/(ee)/api/cron/aggregate-clicks/route.ts
  • apps/web/app/(ee)/api/workflows/create-partner-commission/route.ts
  • apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/[partnerId]/layout.tsx
  • apps/web/lib/zod/schemas/partners.ts
✅ Files skipped from review due to trivial changes (1)
  • apps/web/lib/zod/schemas/partners.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/web/app/(ee)/api/workflows/create-partner-commission/route.ts

📝 Walkthrough

Walkthrough

This PR adds COMMISSION_ELIGIBLE_ENROLLMENT_STATUSES and uses it to gate click aggregation, gate workflow commission creation (skip for ineligible enrollment statuses), and disable the “Create commission” UI when a partner is not eligible.

Changes

Commission eligibility by enrollment status

Layer / File(s) Summary
Commission eligibility constant
apps/web/lib/zod/schemas/partners.ts
Adds exported COMMISSION_ELIGIBLE_ENROLLMENT_STATUSES as ACTIVE_ENROLLMENT_STATUSES plus ProgramEnrollmentStatus.invited.
Backend: aggregation and workflow guards
apps/web/app/(ee)/api/cron/aggregate-clicks/route.ts, apps/web/app/(ee)/api/workflows/create-partner-commission/route.ts
Cron aggregation imports the new constant and filters Prisma link.findMany by programEnrollment.status in that set; the commission workflow imports it and early-returns commission: null (with a log message) for click/lead/sale events when the enrollment status is not in the allowed set.
Frontend: disable Create commission when ineligible
apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/[partnerId]/layout.tsx
Computes canCreateCommission from partner.statusCOMMISSION_ELIGIBLE_ENROLLMENT_STATUSES, conditionally opens the commission sheet on “c” shortcut, and passes a disabledTooltip to primary and mobile “Create commission” controls when ineligible.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • dubinc/dub#3961: Prior work on the stepCreateCommission/commission-creation path that this change builds on.

Suggested reviewers

  • steven-tey
  • devkiran

Poem

A rabbit checks the partner scroll tonight,
Only eligible hops make the ledger bright,
Invited friends get a polite little nod,
Others wait while the carrots stay untrod,
Hooray — fair hops keep the payouts right 🐇✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding commission eligibility checks based on enrollment status across the codebase.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch skip-commissions-for-non-active-partners

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@steven-tey

Copy link
Copy Markdown
Collaborator

@coderabbitai final review, any breaking changes?

@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Tip

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

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Read the new constant definition
cat apps/web/lib/zod/schemas/partners.ts | grep -A 10 "COMMISSION_ELIGIBLE\|ACTIVE_ENROLLMENT"

echo "=== aggregate-clicks route ==="
cat "apps/web/app/(ee)/api/cron/aggregate-clicks/route.ts"

echo "=== create-partner-commission workflow ==="
cat "apps/web/app/(ee)/api/workflows/create-partner-commission/route.ts"

echo "=== partner layout ==="
cat "apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/[partnerId]/layout.tsx"

echo "=== partners schema ==="
cat apps/web/lib/zod/schemas/partners.ts

Length of output: 73103



@steven-tey: No breaking changes — here's the full breakdown:


✅ No breaking changes

Area Status
API contracts / endpoints Unchanged
DB schema / migrations None required
Public/exported interfaces Only a new export added (COMMISSION_ELIGIBLE_ENROLLMENT_STATUSES)
Existing commission records Unaffected (only new creation is gated)

Behavioral changes (intentional)

  • banned / deactivated / rejected partners will no longer receive auto-created commissions for click, lead, or sale events — both via the cron job and the workflow. This is the whole point of the PR.
  • invited partners remain eligible (COMMISSION_ELIGIBLE_ENROLLMENT_STATUSES = approved + archived + invited), which makes sense so invite-link conversions aren't missed before a partner signs up.

One minor inconsistency to be aware of

The eligibility guard in the workflow only covers click, lead, sale — the custom event type intentionally bypasses it, allowing manual custom commissions regardless of status. However, the UI disables the "Create commission" button for all types (not just click/lead/sale) when a partner is ineligible. This means:

  • A banned partner can still receive a custom commission via the API/workflow directly
  • But the UI button to do so manually is disabled

This is likely intentional (custom commissions are a manual override path), but worth confirming with @pepeladeira if the UX should also allow custom commissions for ineligible partners via the UI.

@steven-tey steven-tey merged commit 98c42a7 into main Jun 10, 2026
11 of 12 checks passed
@steven-tey steven-tey deleted the skip-commissions-for-non-active-partners branch June 10, 2026 19:01
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.

3 participants