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

Skip to content

Conversation

@devkiran
Copy link
Collaborator

@devkiran devkiran commented Jun 9, 2025

Summary by CodeRabbit

  • New Features

    • Introduced support for multiple default rewards per program by event type (click, lead, sale) for finer reward management.
    • Added separate UI components for default and additional rewards grouped by event type.
    • Enabled partner filtering and grouping by individual reward types (click, lead, sale).
  • Improvements

    • Simplified reward assignment and partner enrollment with explicit default reward marking.
    • Enhanced partner and reward displays with accurate counts and loading states.
    • Refined discount and reward descriptions for clarity.
    • Optimized reward data fetching, sorting, and API queries for distinct reward types.
    • Streamlined partner invitation flows to include default reward context.
    • Improved validation and error handling during reward creation and updates.
    • Removed legacy partner type selection UI and simplified reward forms.
    • Added cache invalidation for updated reward-related data.
  • Bug Fixes

    • Fixed reward assignment inconsistencies across multiple reward types.
    • Corrected partner count and reward filtering accuracy.
  • Chores

    • Migrated internal reward data structures and schema to support new default reward logic.
    • Removed deprecated code and obsolete reward handling logic.
    • Added data migration scripts for rewards and enrollments.

@vercel
Copy link
Contributor

vercel bot commented Jun 9, 2025

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

Name Status Preview Updated (UTC)
dub ✅ Ready (Inspect) Visit Preview Jun 14, 2025 10:56pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 9, 2025

Warning

Rate limit exceeded

@steven-tey has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 16 minutes and 56 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 831766c and 202eb4b.

📒 Files selected for processing (1)
  • apps/web/lib/partners/create-partner-commission.ts (1 hunks)

Walkthrough

This update introduces a comprehensive refactor of the reward system, transitioning from a model with a single default reward per program to one supporting multiple default rewards categorized by event types ("click", "lead", "sale"). The changes affect database schemas, backend logic, API endpoints, frontend components, and validation schemas to consistently support event-based default rewards and partner-specific reward associations.

Changes

Files/Paths Change Summary
packages/prisma/schema/program.prisma, packages/prisma/schema/reward.prisma Database schema updated: removed single default reward relation, added event-specific reward fields and relations, set up indexes, and added default flag to rewards.
apps/web/scripts/migrate-rewards.ts New migration script to transform existing reward data to new structure, marking program-wide rewards as default and updating enrollments.
apps/web/scripts/migrate-rewards-remainder.ts New script added to find program enrollments missing all event-specific reward IDs.
apps/web/lib/zod/schemas/rewards.ts Added default and isDefault fields to schemas, introduced REWARD_EVENT_COLUMN_MAPPING for mapping event types to enrollment fields.
apps/web/lib/zod/schemas/partners.ts Replaced single rewardId filter with clickRewardId, leadRewardId, saleRewardId in schemas.
apps/web/lib/zod/schemas/programs.ts Removed defaultRewardId from ProgramSchema.
apps/web/lib/partners/sort-rewards-by-event-order.ts Added function to sort rewards by event order.
apps/web/lib/partners/determine-partner-reward.ts Refactored to fetch reward by event type directly from program enrollment.
apps/web/lib/partners/determine-partner-rewards.ts, apps/web/lib/partners/reorder-top-program-rewards.ts, apps/web/lib/fetchers/get-reward.ts Deleted obsolete reward utility functions.
apps/web/lib/api/partners/create-and-enroll-partner.ts, apps/web/lib/rewardful/import-affiliates.ts Partner enrollment now associates rewards by event type using mapped fields, not via partner-reward join table.
apps/web/lib/api/partners/get-partners.ts, apps/web/lib/api/partners/get-reward-or-throw.ts Updated reward filtering to event-specific fields; simplified reward fetching logic.
apps/web/lib/api/programs/get-program-enrollment-or-throw.ts Added optional inclusion of all rewards for an enrollment.
apps/web/lib/api/programs/get-program-or-throw.ts, apps/web/lib/fetchers/get-program.ts Refactored to fetch only default rewards by event; unified reward sorting logic.
apps/web/lib/planetscale/get-program-via-edge.ts, apps/web/lib/planetscale/types.ts Deleted file and interface related to edge API returning single reward fields; replaced by array-based reward handling.
apps/web/lib/actions/partners/create-program.ts, apps/web/lib/actions/partners/invite-partner.ts Program creation/invitation passes default reward context using event-based rewards.
apps/web/lib/actions/partners/create-reward.ts, apps/web/lib/actions/partners/update-reward.ts, apps/web/lib/actions/partners/delete-reward.ts Reward actions refactored for event-based default/partner-specific rewards, updating enrollments and validation.
apps/web/lib/rewardful/import-campaign.ts Campaign import logic updated to handle event-based default rewards.
apps/web/lib/swr/use-partners-count.ts Added loading flag to partners count hook.
apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/use-partner-filters.tsx Partner filters now support separate event-based reward filters.
apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/rewards/rewards.tsx UI refactored to display and manage default/additional rewards by event type.
apps/web/ui/partners/add-edit-reward-sheet.tsx Removed partner type selection; simplified default reward logic and validation.
apps/web/ui/partners/lander/blocks/earnings-calculator-block.tsx Earnings calculator now finds default sale reward by event flag.
apps/web/ui/partners/program-invite-card.tsx Simplified reward selection logic for invite card.
apps/web/app/(ee)/api/cron/aggregate-clicks/route.ts Refactored click reward processing to use new enrollment structure.
apps/web/app/(ee)/api/partner-profile/programs/[programId]/route.ts, apps/web/app/(ee)/api/partner-profile/programs/route.ts Partner profile APIs now retrieve rewards directly from enrollments.
apps/web/app/(ee)/api/partners/count/route.ts Partner counting/grouping logic updated for event-based reward fields.
apps/web/app/(ee)/api/programs/[programId]/rewards/partners/route.ts, apps/web/app/(ee)/api/programs/[programId]/rewards/route.ts APIs updated to fetch partners/rewards using event-based fields, removed partner count from rewards API.
apps/web/app/(ee)/api/programs/[programId]/route.ts Changed reward inclusion option to single unified flag.
apps/web/app/(ee)/app.dub.co/embed/referrals/utils.ts Refactored to fetch and sort rewards by event order.
apps/web/app/(ee)/partners.dub.co/(apply)/[programSlug]/apply/page.tsx, apps/web/app/(ee)/partners.dub.co/(apply)/[programSlug]/page.tsx, apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/apply/page.tsx Updated to request "defaultRewards" instead of "rewards" when fetching programs.
apps/web/app/(ee)/partners.dub.co/(apply)/[programSlug]/layout.tsx Metadata logic updated for event-based default rewards, removed unused reward fetch.
apps/web/app/(ee)/partners.dub.co/(auth)/(default)/login/page.tsx, apps/web/app/(ee)/partners.dub.co/(auth)/(default)/register/page.tsx Refactored function parameter destructuring for clarity.
apps/web/app/api/og/program/route.tsx Program OG image API now uses sorted rewards by event order.
apps/web/app/api/tokens/embed/referrals/route.ts Removed unused defaultRewardId field from program selection.
apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/discounts/page-client.tsx UI text updates for discount sections.
apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/invite-partner-sheet.tsx Added padding styles and default label in reward select options.
apps/web/lib/actions/partners/approve-partner.ts Enrich enrollment update with default rewards by event during partner approval.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Frontend
    participant API
    participant DB

    User->>Frontend: Request program details
    Frontend->>API: GET /programs/[programId]
    API->>DB: Query Program (include default rewards by event)
    DB-->>API: Return Program with rewards [{event, type, amount, default}]
    API-->>Frontend: Return Program + rewards[]
    Frontend->>User: Display default rewards for click, lead, sale

    User->>Frontend: Create new reward (for event type)
    Frontend->>API: POST /rewards (with isDefault, event)
    API->>DB: Validate uniqueness, create reward, update enrollments
    DB-->>API: Confirmation
    API-->>Frontend: Reward created

    User->>Frontend: Enroll partner with reward
    Frontend->>API: POST /enroll-partner (with reward for event)
    API->>DB: Upsert ProgramEnrollment, set event-specific rewardId
    DB-->>API: Enrollment confirmation
    API-->>Frontend: Enrollment success
Loading

Poem

In the warren of code, rewards now bloom,
Each event with its own, no more single-room!
"Click", "lead", and "sale"—a trio to cheer,
Partners and programs, the logic is clear.
The bunny hops on, with schemas anew,
And celebrates progress with carrots (and you)! 🥕✨

✨ 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.

@bug0-qa-agent
Copy link

bug0-qa-agent bot commented Jun 9, 2025

🤖 Bug0 QA Agent

Here are the results of the automated tests for PR #2504:

To re-run the tests, please comment /bug0 run or push a new commit to this PR.

@bug0-qa-agent
Copy link

bug0-qa-agent bot commented Jun 9, 2025

🤖 Bug0 QA Agent

Here are the results of the automated tests for PR #2504:

To re-run the tests, please comment /bug0 run or push a new commit to this PR.

@bug0-qa-agent
Copy link

bug0-qa-agent bot commented Jun 9, 2025

🤖 Bug0 QA Agent

Here are the results of the automated tests for PR #2504:

To re-run the tests, please comment /bug0 run or push a new commit to this PR.

… retrieval logic in partner profile components.
@bug0-qa-agent
Copy link

bug0-qa-agent bot commented Jun 9, 2025

🤖 Bug0 QA Agent

Here are the results of the automated tests for PR #2504:

To re-run the tests, please comment /bug0 run or push a new commit to this PR.

@bug0-qa-agent
Copy link

bug0-qa-agent bot commented Jun 9, 2025

🤖 Bug0 QA Agent

Here are the results of the automated tests for PR #2504:

To re-run the tests, please comment /bug0 run or push a new commit to this PR.

@bug0-qa-agent
Copy link

bug0-qa-agent bot commented Jun 9, 2025

🤖 Bug0 QA Agent

Here are the results of the automated tests for PR #2504:

To re-run the tests, please comment /bug0 run or push a new commit to this PR.

@bug0-qa-agent
Copy link

bug0-qa-agent bot commented Jun 10, 2025

🤖 Bug0 QA Agent

Here are the results of the automated tests for PR #2504:

To re-run the tests, please comment /bug0 run or push a new commit to this PR.

devkiran added 3 commits June 10, 2025 11:22
- Introduced `sortRewardsByEvent` function to organize rewards by event type.
- Updated `getProgramViaEdge` to fetch rewards more efficiently and return them in a structured format.
- Modified the API response in `route.tsx` to utilize the new rewards sorting logic.
- Adjusted the rendering logic to display the first reward based on the sorted list.
- Renamed parameters for clarity, changing `includeDefaultReward` and `includeRewards` to `includeDefaultRewards`.
- Updated the logic in `getProgramOrThrow` to utilize the new `sortRewardsByEvent` function for sorting rewards.
- Adjusted API response handling in `route.ts` to reflect the updated reward inclusion logic.
@bug0-qa-agent
Copy link

bug0-qa-agent bot commented Jun 14, 2025

🤖 Bug0 QA Agent

Here are the results of the automated tests for PR #2504:

To re-run the tests, please comment /bug0 run or push a new commit to this PR.

@bug0-qa-agent
Copy link

bug0-qa-agent bot commented Jun 14, 2025

🤖 Bug0 QA Agent

Here are the results of the automated tests for PR #2504:

To re-run the tests, please comment /bug0 run or push a new commit to this PR.

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 (3)
packages/prisma/schema/reward.prisma (3)

22-24: Avoid using SQL reserved keyword for field name
Naming the Boolean column default may conflict with SQL’s DEFAULT keyword. Consider renaming it to something like isDefault or defaultReward to prevent quoting issues in migrations.


32-33: Evaluate need for separate single-column index on event
You already have a composite @@index([programId, event]). If the only use case for filtering by event is within a specific program, the composite index suffices. Otherwise, the standalone @@index(event) makes sense for cross-program queries (e.g. the cron job).


36-36: Plan removal of deprecated PartnerReward table
This TODO notes the table’s eventual drop. Confirm that you’ll include a Prisma migration to drop PartnerReward and clean up related code once consumers have migrated.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c8b6d65 and 831766c.

📒 Files selected for processing (5)
  • apps/web/app/api/og/program/route.tsx (4 hunks)
  • apps/web/lib/planetscale/get-program-via-edge.ts (0 hunks)
  • apps/web/lib/planetscale/types.ts (0 hunks)
  • apps/web/lib/rewardful/import-campaign.ts (3 hunks)
  • packages/prisma/schema/reward.prisma (2 hunks)
💤 Files with no reviewable changes (2)
  • apps/web/lib/planetscale/types.ts
  • apps/web/lib/planetscale/get-program-via-edge.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/web/lib/rewardful/import-campaign.ts
  • apps/web/app/api/og/program/route.tsx
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (2)
packages/prisma/schema/reward.prisma (2)

13-14: Field definitions for id and programId look correct
The primary key and foreign key scalar fields are properly declared.


26-30: Verify relation consistency for event-based enrollments
Ensure that in ProgramEnrollment you have matching relation fields (e.g. clickReward, leadReward, saleReward) with the same @relation("ClickRewardEnrollments"), etc., so Prisma can link both sides correctly.

@bug0-qa-agent
Copy link

bug0-qa-agent bot commented Jun 14, 2025

🤖 Bug0 QA Agent

Here are the results of the automated tests for PR #2504:

To re-run the tests, please comment /bug0 run or push a new commit to this PR.

@bug0-qa-agent
Copy link

bug0-qa-agent bot commented Jun 14, 2025

🤖 Bug0 QA Agent

Here are the results of the automated tests for PR #2504:

To re-run the tests, please comment /bug0 run or push a new commit to this PR.

@steven-tey
Copy link
Collaborator

@CodeRabbit final review please

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 14, 2025

Tip

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

@steven-tey

Final Review: PR #2504 - Improve Reward UI/UX

This is a comprehensive and well-architected refactor that successfully modernizes the reward system from a single-default model to an event-based multi-reward structure. Here's my final assessment:

Strengths

Architectural Consistency

  • Clean separation of rewards by event type (click/lead/sale) throughout all layers
  • Consistent API patterns with the new clickRewardId/leadRewardId/saleRewardId paradigm
  • Proper database normalization with appropriate indexes and relations

Migration Strategy

  • Comprehensive migration script (migrate-rewards.ts) handles data transformation safely
  • Legacy stub columns preserved with clear TODO comments for cleanup
  • Gradual deprecation approach minimizes immediate breakage

Code Quality

  • Well-structured TypeScript with proper type safety
  • Consistent error handling and validation
  • Clean component refactoring with consolidated RewardItem logic

⚠️ Key Considerations

Deployment Sequence

  1. Deploy schema changes first
  2. Run migrate-rewards.ts to backfill data
  3. Deploy application code
  4. Update any external consumers
  5. Clean up legacy columns in future PR

Performance Impact

  • New composite index [programId, event] should improve query performance
  • Multiple reward lookups per enrollment may increase DB load slightly
  • Consider monitoring query performance post-deployment

API Versioning

  • Breaking changes are well-documented but immediate
  • Consider API versioning strategy for external consumers
  • The embed/edge functions changes affect public-facing endpoints

🚀 Recommendations

  1. Pre-deployment: Verify the migration script on a staging environment with production-like data
  2. Monitoring: Set up alerts for the new reward-related queries and endpoints
  3. Documentation: Update API documentation to reflect the new multi-reward structure
  4. Rollback Plan: Ensure database rollback procedures are tested
  5. External Communication: Notify any external API consumers about the breaking changes

Overall Assessment: ✅ APPROVED

This is a high-quality refactor that successfully modernizes the reward system architecture. The breaking changes are justified by the improved flexibility and maintainability. The comprehensive migration strategy and consistent implementation across all layers demonstrate excellent engineering practices.

The PR is ready for deployment with the recommended migration sequence.

@bug0-qa-agent
Copy link

bug0-qa-agent bot commented Jun 14, 2025

🤖 Bug0 QA Agent

Here are the results of the automated tests for PR #2504:

To re-run the tests, please comment /bug0 run or push a new commit to this PR.

@bug0-qa-agent
Copy link

bug0-qa-agent bot commented Jun 14, 2025

🤖 Bug0 QA Agent

Here are the results of the automated tests for PR #2504:

To re-run the tests, please comment /bug0 run or push a new commit to this PR.

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