-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add 1 to discount.maxDuration #2760
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughAdded 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
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)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
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 unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this 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 sentenceThe 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 optionMinor 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 claritySince 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 valueConsider 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.
📒 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) — LGTMChanging 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 — LGTMComment 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 themaxDurationcolumn were found in any.sqlmigration files. Inserting a value of1will succeed at the database layer.apps/web/lib/zod/schemas/misc.ts (1)
6-6: Validation list now includes 1 month — LGTMAdding 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]; |
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
📒 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.
Summary by CodeRabbit
New Features
Style
Documentation