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

Skip to content

Conversation

@devkiran
Copy link
Collaborator

@devkiran devkiran commented Jul 9, 2025

Summary by CodeRabbit

  • New Features

    • Added support for displaying and managing event-specific reward assignments for partners, including visual indicators when a partner is already assigned to a different reward for the selected event.
    • Expanded partner enrollment data and schemas to include additional reward and discount identifiers.
  • Improvements

    • Enhanced error messages for invalid partner IDs during reward creation to clarify enrollment requirements.
    • Adjusted table column widths for improved layout and readability.

@vercel
Copy link
Contributor

vercel bot commented Jul 9, 2025

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

Name Status Preview Updated (UTC)
dub ✅ Ready (Inspect) Visit Preview Jul 9, 2025 5:34am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 9, 2025

Walkthrough

The changes expand partner reward management by adding support for multiple event-specific reward IDs—clickRewardId, leadRewardId, saleRewardId, and discountId—across the backend, schema, and UI. The UI now visually warns when a partner is already assigned to a different reward for the same event, and error messages clarify partner enrollment requirements.

Changes

File(s) Change Summary
apps/web/lib/actions/partners/create-reward.ts Updated error message for invalid partner IDs to clarify enrollment requirement.
apps/web/lib/api/partners/get-partners.ts Extended partner query and filtering to include clickRewardId, leadRewardId, saleRewardId, and discountId.
apps/web/lib/zod/schemas/partners.ts Added four optional nullable string fields for reward/discount IDs to EnrolledPartnerSchemaExtended.
apps/web/ui/partners/add-edit-reward-sheet.tsx Passed new event and rewardId props to RewardPartnersTable component.
apps/web/ui/partners/reward-partners-table.tsx Enhanced table to handle event-specific reward IDs, added warning icon for partners already linked to another reward, updated props.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant RewardSheet as Add/Edit Reward Sheet
  participant PartnersTable as RewardPartnersTable
  participant Backend

  User->>RewardSheet: Opens Add/Edit Reward Sheet
  RewardSheet->>PartnersTable: Renders with event and rewardId props
  PartnersTable->>Backend: Fetch partners with event-specific reward IDs
  Backend-->>PartnersTable: Returns partners with click/lead/sale/discount IDs
  PartnersTable->>User: Displays partners, warns if assigned to other reward for event
  User->>RewardSheet: Submits reward changes
  RewardSheet->>Backend: Creates/updates reward, validates partner enrollment
  Backend-->>RewardSheet: Returns success or error (with clarified message)
Loading

Possibly related PRs

  • Improve reward UI/UX #2504: Refactored partner reward logic to support multiple reward ID fields (clickRewardId, leadRewardId, saleRewardId) in the same files as this PR, indicating a shared evolution of partner-reward assignment functionality.

Suggested reviewers

  • steven-tey

Poem

In the garden of code, rewards now bloom,
With click, lead, sale, and discounts in the room.
Partners checked twice, warnings in sight,
Assignments are clear, everything’s right.
A bunny hops by, with a carrot to share—
“Event rewards sorted! Hop on if you dare!” 🥕


📜 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 77ba5b1 and 478bfd6.

📒 Files selected for processing (5)
  • apps/web/lib/actions/partners/create-reward.ts (1 hunks)
  • apps/web/lib/api/partners/get-partners.ts (1 hunks)
  • apps/web/lib/zod/schemas/partners.ts (1 hunks)
  • apps/web/ui/partners/add-edit-reward-sheet.tsx (1 hunks)
  • apps/web/ui/partners/reward-partners-table.tsx (6 hunks)
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
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.
apps/web/lib/actions/partners/create-reward.ts (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: devkiran
PR: dubinc/dub#2177
File: apps/web/lib/api/links/bulk-create-links.ts:66-84
Timestamp: 2025-06-06T07:59:03.120Z
Learning: In apps/web/lib/api/links/bulk-create-links.ts, the team accepts the risk of potential undefined results from links.find() operations when building invalidLinks arrays, because existing links are fetched from the database based on the input links, so matches are expected to always exist.
apps/web/lib/zod/schemas/partners.ts (1)
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.
apps/web/ui/partners/reward-partners-table.tsx (1)
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.
🧬 Code Graph Analysis (1)
apps/web/ui/partners/reward-partners-table.tsx (3)
apps/web/lib/types.ts (1)
  • EnrolledPartnerProps (402-404)
packages/utils/src/constants/misc.ts (1)
  • OG_AVATAR_URL (29-29)
packages/ui/src/tooltip.tsx (1)
  • Tooltip (32-88)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (11)
apps/web/ui/partners/add-edit-reward-sheet.tsx (1)

435-436: LGTM! Props correctly passed for event-specific reward warnings.

The addition of event={selectedEvent} and rewardId={reward?.id} props enables the RewardPartnersTable to display warnings when partners are assigned to different rewards for the same event type.

apps/web/lib/actions/partners/create-reward.ts (1)

72-72: LGTM! Improved error message clarity.

The updated error message clearly explains why partner IDs are invalid, improving the user experience by specifying that partners must be enrolled in the program.

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

297-300: LGTM! Schema correctly extended with new reward ID fields.

The addition of clickRewardId, leadRewardId, saleRewardId, and discountId as optional nullable string fields properly supports the event-specific reward assignment feature.

apps/web/lib/api/partners/get-partners.ts (2)

61-64: LGTM! SQL query correctly extended with new reward ID fields.

The addition of the new reward and discount ID fields to the SELECT clause properly supports the enhanced partner enrollment data requirements.


114-116: LGTM! Filtering conditions correctly implemented.

The filtering conditions for clickRewardId, leadRewardId, and saleRewardId follow the same pattern as existing filters and properly support event-specific partner queries.

apps/web/ui/partners/reward-partners-table.tsx (6)

5-13: LGTM! Imports correctly added for new functionality.

The new imports (EventType, CircleWarning, Tooltip) are necessary for the warning UI implementation and properly support the enhanced functionality.


26-27: LGTM! Props correctly added for event-specific reward handling.

The addition of event and rewardId props enables the component to determine when partners are assigned to different rewards for the same event type.

Also applies to: 37-38


43-53: LGTM! State properly extended with reward ID fields.

The selectedPartners state now includes the necessary reward ID fields (clickRewardId, leadRewardId, saleRewardId) to support the warning logic.


76-78: LGTM! Partners map correctly updated with reward ID fields.

The partnersMap now includes the new reward ID fields, ensuring consistent data structure across the component.


162-193: LGTM! Warning UI implementation is well-designed.

The warning logic correctly identifies when a partner is assigned to a different reward for the same event:

  • Uses dynamic property access row.original[${event}RewardId] which is type-safe given the EventType constraint
  • Properly checks if the existing reward ID differs from the current one
  • Provides clear visual feedback with a warning icon and tooltip
  • The tooltip message clearly explains what will happen ("will be updated to this one")

190-203: LGTM! Column width adjustments accommodate new UI elements.

The width adjustments (Partner column increased to 180px, Email column decreased to 160px) properly accommodate the new warning icon while maintaining good layout proportions.

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

@steven-tey steven-tey merged commit 6915bf9 into main Jul 9, 2025
8 checks passed
@steven-tey steven-tey deleted the reward-discount-warning branch July 9, 2025 05:38
@coderabbitai coderabbitai bot mentioned this pull request Jul 30, 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.

3 participants