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

Skip to content

Conversation

@devkiran
Copy link
Collaborator

@devkiran devkiran commented Jul 24, 2025

Summary by CodeRabbit

  • New Features

    • Improved handling and normalization of the "amount" field in forms, especially for flat reward or discount types.
    • Default discount type is now set to "percentage" when adding or editing discounts.
  • Bug Fixes

    • Fixed inconsistent default durations for recurring discounts, now defaulting to a lifetime duration when not specified.

@vercel
Copy link
Contributor

vercel bot commented Jul 24, 2025

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

Name Status Preview Updated (UTC)
dub ✅ Ready (Inspect) Visit Preview Jul 24, 2025 6:40pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 24, 2025

Walkthrough

The changes update the logic for initializing form default values related to monetary "amount" fields in both program onboarding and discount forms. The updates normalize "flat" type amounts by dividing by 100, adjust default types and fallback values, and simplify assignment logic for cleaner initialization.

Changes

File(s) Change Summary
apps/web/app/(ee)/app.dub.co/(new-program)/form-wrapper.tsx Updated default value logic for amount: divides by 100 for "flat" type, otherwise assigns as before.
apps/web/ui/partners/add-edit-discount-sheet.tsx Simplified form default value assignment; normalizes "flat" amount, changes default type to "percentage", and adjusts fallback for recurring discount duration.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant FormComponent
    participant DataSource

    User->>FormComponent: Open form (Program or Discount)
    FormComponent->>DataSource: Fetch onboarding/discount data
    DataSource-->>FormComponent: Return data
    alt type is "flat" and amount exists
        FormComponent->>FormComponent: Set amount = amount / 100
    else
        FormComponent->>FormComponent: Set amount = amount
    end
    FormComponent->>User: Render form with normalized default values
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested reviewers

  • steven-tey

Poem

A nibble here, a tweak just so,
Amounts now scale, as forms will show.
Flat or not, the math is neat,
Divided by 100, a tidy feat!
Rabbits cheer as numbers align—
Default values, simply divine!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 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 4453a7f and 519514f.

📒 Files selected for processing (2)
  • apps/web/app/(ee)/app.dub.co/(new-program)/form-wrapper.tsx (1 hunks)
  • apps/web/ui/partners/add-edit-discount-sheet.tsx (2 hunks)
🧰 Additional context used
🧠 Learnings (2)
apps/web/ui/partners/add-edit-discount-sheet.tsx (1)

Learnt from: TWilson023
PR: #2614
File: apps/web/ui/partners/design/previews/lander-preview.tsx:181-181
Timestamp: 2025-07-09T20:52:56.592Z
Learning: In apps/web/ui/partners/design/previews/lander-preview.tsx, the ellipsis wave animation delay calculation 3 - i * -0.15 is intentionally designed to create negative delays that offset each dot's animation cycle. This pattern works correctly for the intended ellipsis effect and should not be changed to positive incremental delays.

apps/web/app/(ee)/app.dub.co/(new-program)/form-wrapper.tsx (1)

Learnt from: TWilson023
PR: #2614
File: apps/web/ui/partners/design/previews/lander-preview.tsx:181-181
Timestamp: 2025-07-09T20:52:56.592Z
Learning: In apps/web/ui/partners/design/previews/lander-preview.tsx, the ellipsis wave animation delay calculation 3 - i * -0.15 is intentionally designed to create negative delays that offset each dot's animation cycle. This pattern works correctly for the intended ellipsis effect and should not be changed to positive incremental delays.

⏰ 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 (3)
apps/web/app/(ee)/app.dub.co/(new-program)/form-wrapper.tsx (1)

28-31: LGTM! Amount normalization logic is correct.

The conditional logic properly normalizes flat amounts (likely stored in cents) to dollar amounts for form display. The dual condition check prevents division of null/undefined values.

apps/web/ui/partners/add-edit-discount-sheet.tsx (2)

78-84: LGTM! Form initialization improvements are well-structured.

The changes improve form initialization by:

  • Consistent amount normalization for "flat" types (dividing by 100)
  • Better default type selection ("percentage" vs "flat")
  • Cleaner assignment logic with optional chaining
  • Proper handling of maxDuration null values as Infinity

284-285: Verify business impact of default recurring discount duration change

The fallback for discount?.maxDuration was updated from 3 (months) to Infinity (lifetime). This is a breaking change in default behavior—ensure it’s aligned with product requirements:

  • No existing tests assert a 3-month default.
  • No documentation references “3 months” as the standard limit.
  • Confirm with stakeholders that a lifetime default is acceptable for recurring discounts.
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-reward

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 generate unit tests to generate unit tests for 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
Copy link
Collaborator

@CodeRabbit final review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 24, 2025

Tip

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

@steven-tey Here's my final review of this PR:

Overall Assessment: APPROVED

This PR successfully addresses discount and reward amount normalization issues with clean, consistent implementation.

🔍 Key Improvements

1. Amount Normalization

  • Both files now properly handle "flat" type amounts by dividing by 100
  • Prevents display of cent values (e.g., showing $10 instead of 1000)
  • Consistent logic across program onboarding and discount forms

2. Form Initialization

  • Cleaner default value assignment using optional chaining
  • Better handling of null/undefined values
  • Improved default type selection ("percentage" over "flat")

3. Code Quality

  • Simplified conditional logic
  • More readable and maintainable code structure

⚠️ Important Business Logic Change

The default recurring discount duration changed from 3 months to Infinity (lifetime). This is a significant behavioral change that should be confirmed with stakeholders before deployment.

🎯 Final Recommendations

  1. Verify the maxDuration change - Confirm that lifetime defaults for recurring discounts align with business requirements
  2. Test edge cases - Ensure null/undefined amounts are handled gracefully
  3. Consider documentation - Update any relevant docs about default discount behaviors

The code implementation is solid and addresses the core issues effectively. The main consideration is ensuring the business logic changes are intentional and approved.

(\   /)

( .. )
o
(")(")
Thoughtful review complete!


🧠 Learnings used
Learnt from: TWilson023
PR: dubinc/dub#2614
File: apps/web/ui/partners/design/previews/lander-preview.tsx:181-181
Timestamp: 2025-07-09T20:52:56.592Z
Learning: In apps/web/ui/partners/design/previews/lander-preview.tsx, the ellipsis wave animation delay calculation `3 - i * -0.15` is intentionally designed to create negative delays that offset each dot's animation cycle. This pattern works correctly for the intended ellipsis effect and should not be changed to positive incremental delays.

@steven-tey steven-tey merged commit 01ea8e2 into main Jul 24, 2025
8 checks passed
@steven-tey steven-tey deleted the fix-reward branch July 24, 2025 19:58
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