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

Skip to content

Conversation

@steven-tey
Copy link
Collaborator

@steven-tey steven-tey commented Aug 19, 2025

Summary by CodeRabbit

  • New Features

    • Added support for a 1-month recurring discount duration; validation now accepts 1 month alongside existing options.
  • Style

    • Improved discount messaging: introduced explicit "for their first purchase" for one-time (0) discounts; "for their first month" remains for 1-month recurring; lifetime wording fixed.
  • Documentation

    • Clarified duration values and meanings in internal schema comments (one-time vs. lifetime vs. monthly).

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 19, 2025

Walkthrough

Added 1 month to allowed recurring durations and updated validation; introduced explicit handling for maxDuration === 0 (render "first purchase") and fixed a typo; clarified Prisma comment that 0 means a one-time purchase and listed valid month values. No API or structural logic changes.

Changes

Cohort / File(s) Summary
Validation schema (durations)
apps/web/lib/zod/schemas/misc.ts
Expanded RECURRING_MAX_DURATIONS from [0,3,6,12,18,24,36] to [0,1,3,6,12,18,24,36], updating the maxDurationSchema includes-check and its error message.
UI: discount formatting & program reward rendering
apps/web/ui/partners/format-discount-description.ts, apps/web/ui/partners/program-reward-description.tsx
Fixed typo ("for the their lifetime" → "for their lifetime"); added explicit maxDuration === 0 branch rendering "for their first purchase"; reordered checks so 0 is evaluated before 1; flattened JSX in program-reward-description.tsx to handle null/0/1/>1 cases explicitly.
Prisma schema documentation
packages/prisma/schema/discount.prisma
Updated inline comment for Discount.maxDuration: 0 denotes a one-time (first) purchase; enumerated valid recurring month values (1, 3, 6, 12, 18, 24, 36); null remains lifetime.

Sequence Diagram(s)

sequenceDiagram
  participant UI as ProgramRewardDescription
  participant Validator as ValidationSchema
  participant DB as PrismaSchemaComment

  UI->>UI: read maxDuration value (null, 0, 1, >1)
  alt null
    UI->>UI: render "for their lifetime"
  else 0
    UI->>UI: render "for their first purchase"
  else 1
    UI->>UI: render "for their first month"
  else >1
    UI->>UI: render "for {N} months"
  end

  Note over Validator,UI: Validator now accepts 1 in allowed durations
  Note over DB: Comment updated to document semantics (0 = one-time, null = lifetime)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Updated logic #2582 — Modifies program-reward-description.tsx logic for maxDuration branches; likely touches the same rendering changes.
  • Fix discount maxDuration #2682 — Adjusts handling of discount maxDuration and allowed values across UI/form code; related to the validation and UI updates here.
  • Reward modifier display #2734 — Edits the same ProgramRewardDescription component; may overlap with JSX/branching changes in this PR.

Poem

I'm a rabbit in code with a twitchy delight,
One month hops in and the schema is right.
"First purchase" I whisper, typo tucked away,
Prisma nods kindly, comments now say:
Little hops, bright fixes — a carrot-coded day. 🥕

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch discount-duration

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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

@vercel
Copy link
Contributor

vercel bot commented Aug 19, 2025

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

Project Deployment Preview Updated (UTC)
dub Ready Ready Preview Aug 19, 2025 4:33am

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: 2

🧹 Nitpick comments (4)
apps/web/ui/partners/format-discount-description.ts (1)

20-21: Eliminate double spaces in assembled sentence

The first fragment includes a trailing space and you also join with " ", which can result in double spaces in the final string. Drop the trailing space for consistency.

Apply this diff:

-  parts.push(`New users get ${discountAmount} off `);
+  parts.push(`New users get ${discountAmount} off`);

Also applies to: 32-33

apps/web/lib/zod/schemas/misc.ts (3)

56-61: Improve error message to mention lifetime option

Minor UX tweak: explicitly mention that null is allowed for lifetime to reduce confusion when validation fails.

Apply this diff:

-  .refine((val) => RECURRING_MAX_DURATIONS.includes(val), {
-    message: `Max duration must be ${RECURRING_MAX_DURATIONS.join(", ")}`,
-  })
+  .refine((val) => RECURRING_MAX_DURATIONS.includes(val), {
+    message: `Max duration must be one of: ${RECURRING_MAX_DURATIONS.join(", ")} (or null for lifetime)`,
+  })

6-6: Optional: rename constant for clarity

Since the list includes 0 (not recurring), consider a more neutral name like ALLOWED_MAX_DURATIONS or MAX_DURATION_OPTIONS to avoid implying all entries are “recurring.”


56-61: Offer tests for the new allowed value

Consider adding unit tests to ensure:

  • Accepts: 0, 1, 3, 6, 12, 18, 24, 36, null/undefined
  • Rejects: 2, 4, 5, -1, "foo"

I can draft zod tests (parse/parseAsync) covering these cases if helpful.

📜 Review details

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

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 7544810 and 197abbd.

📒 Files selected for processing (3)
  • apps/web/lib/zod/schemas/misc.ts (1 hunks)
  • apps/web/ui/partners/format-discount-description.ts (1 hunks)
  • packages/prisma/schema/discount.prisma (1 hunks)
⏰ 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 (4)
apps/web/ui/partners/format-discount-description.ts (1)

25-26: Copy update aligns semantics (0 => first purchase) — LGTM

Changing the 0-branch to “for their first purchase” correctly reflects one-time discounts.

packages/prisma/schema/discount.prisma (2)

6-6: Comment clarification is accurate — LGTM

Comment now clearly documents 0 = one-time purchase, valid month values include 1, and null = lifetime.


6-6: DB‐level constraint scan passed – maxDuration accepts 1
No CHECK constraints or triggers referencing the maxDuration column were found in any .sql migration files. Inserting a value of 1 will succeed at the database layer.

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

6-6: Validation list now includes 1 month — LGTM

Adding 1 to RECURRING_MAX_DURATIONS aligns with the new semantics and keeps validation consistent.

import { fileTypeFromBuffer } from "file-type";

export const RECURRING_MAX_DURATIONS = [0, 3, 6, 12, 18, 24, 36];
export const RECURRING_MAX_DURATIONS = [0, 1, 3, 6, 12, 18, 24, 36];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Check for stale UI copy referring to “first month”

To avoid inconsistent messaging across the app, scan for any remaining “first month” phrasing and update to “first purchase” where it refers to maxDuration = 0.


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Searching for 'first month' vs 'first purchase' copy:"
rg -n -S -C2 'first month|first purchase'

echo
echo "Searching for logic branches specifically handling maxDuration === 0:"
rg -n -C3 -P '\bmaxDuration\s*===\s*0\b'

Length of output: 7598


Update stale “first month” copy to “first purchase” for one-time offers

Please replace instances of “first month” with “first purchase” wherever maxDuration === 0 to keep messaging consistent:

• apps/web/ui/partners/program-reward-list.tsx (line 94):
Change
<>for their first month</>
to
<>for their first purchase</>

• apps/web/ui/partners/program-reward-description.tsx (line 98):
Change
" for their first month"
to
" for their first purchase"

🤖 Prompt for AI Agents
In apps/web/ui/partners/program-reward-list.tsx (around line 94) and
apps/web/ui/partners/program-reward-description.tsx (around line 98), update the
copy for one-time offers where maxDuration === 0: replace "for their first
month" with "for their first purchase" in program-reward-list.tsx, and replace "
for their first month" with " for their first purchase" in
program-reward-description.tsx so messaging is consistent for maxDuration === 0.

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: 0

🧹 Nitpick comments (2)
apps/web/ui/partners/program-reward-description.tsx (2)

99-103: Prefer explicit numeric check over truthiness for >1 months branch.

This reads clearer and avoids relying on JS truthiness.

-          ) : discount.maxDuration && discount.maxDuration > 1 ? (
+          ) : typeof discount.maxDuration === "number" && discount.maxDuration > 1 ? (
             <strong className={cn("font-semibold", periodClassName)}>
               for {discount.maxDuration} months
             </strong>
           ) : null}

92-94: Minor copy tweak: “off their first purchase” reads more naturally.

Given the preceding “off ” text, dropping “for” here is more idiomatic.

-            <strong className={cn("font-semibold", periodClassName)}>
-              for their first purchase
-            </strong>
+            <strong className={cn("font-semibold", periodClassName)}>
+              their first purchase
+            </strong>
📜 Review details

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

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 197abbd and d63bcb0.

📒 Files selected for processing (2)
  • apps/web/ui/partners/format-discount-description.ts (1 hunks)
  • apps/web/ui/partners/program-reward-description.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/web/ui/partners/format-discount-description.ts
⏰ 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 (1)
apps/web/ui/partners/program-reward-description.tsx (1)

87-103: Explicit 0/1/null duration handling looks correct and matches validation.

Good addition of the 0- and 1-month branches and clearer null handling. This aligns with the updated allowed durations and improves clarity.

@steven-tey steven-tey merged commit e6f25d1 into main Aug 19, 2025
7 of 8 checks passed
@steven-tey steven-tey deleted the discount-duration branch August 19, 2025 04:36
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