Skip to content

Add custom duration input for group discount codes#3897

Open
pepeladeira wants to merge 4 commits into
mainfrom
custom-discount-duration
Open

Add custom duration input for group discount codes#3897
pepeladeira wants to merge 4 commits into
mainfrom
custom-discount-duration

Conversation

@pepeladeira
Copy link
Copy Markdown
Collaborator

@pepeladeira pepeladeira commented May 13, 2026

Summary by CodeRabbit

  • New Features

    • Discount durations now support custom month values, in addition to preset options.
  • Improvements

    • Preset duration choices trimmed to a shorter set for simpler selection.
    • Popover menus can remain open for multi-step selections and now autofocus input lists for smoother keyboard use.
  • Bug Fixes

    • Duration input validation tightened: values must be integer, non-negative, and capped with clearer error messages.

Review Change Stack

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 13, 2026

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

Project Deployment Actions Updated (UTC)
dub Ready Ready Preview May 13, 2026 9:27pm

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 13, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 31560431-e572-48c8-98fd-278c5178bf6c

📥 Commits

Reviewing files that changed from the base of the PR and between 8b88b14 and 05cbd80.

📒 Files selected for processing (2)
  • apps/web/lib/zod/schemas/misc.ts
  • apps/web/ui/partners/discounts/add-edit-discount-sheet.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/web/ui/partners/discounts/add-edit-discount-sheet.tsx

📝 Walkthrough

Walkthrough

This PR enables selecting custom discount durations (integer 0–9999 months). It relaxes the Zod schema to accept integer non-negative values up to 9999, adds a preventClose flag and focus/ref handling to the inline popover, and integrates a DurationPopoverContent UI into the discount sheet to enter and persist custom durations.

Changes

Custom Duration Selection for Discounts

Layer / File(s) Summary
Validation schema for custom durations
apps/web/lib/zod/schemas/misc.ts
RECURRING_MAX_DURATIONS reduced to [0,1,3,6,12,24]. maxDurationSchema now enforces integer, non-negative, and max-9999 constraints with explicit error messages, replacing the prior allowlist refine.
Popover component enhancements
apps/web/ui/shared/inline-badge-popover.tsx
InlineBadgePopoverMenu adds an optional preventClose flag on items, introduces Command and list refs for focus management, wires useScrollProgress to the list ref, auto-focuses the Command container on mount when search is disabled, and Command accepts a forwarded ref; selection respects preventClose.
Discount sheet custom duration UI
apps/web/ui/partners/discounts/add-edit-discount-sheet.tsx
Discount sheet adds DurationPopoverContent, seeds customDurationInput from existing values, replaces the preset-only menu with the popover content that shows presets or a numeric input, clamps/sets maxDuration via setValue, and handles Enter/Escape/Backspace and popover close behaviors.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 A popover opens, numbers hop in tune,
Custom months now counted beneath the moon,
Schemas count integers up to nine-nine-nine-nine,
Preventing a close keeps the input in line,
Discounts and rabbits cheer — durations align.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding a custom duration input feature for group discount codes, which is reflected across all three modified files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch custom-discount-duration

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

apps/web/lib/zod/schemas/misc.ts

Parsing error: The keyword 'import' is reserved

apps/web/ui/partners/discounts/add-edit-discount-sheet.tsx

Parsing error: The keyword 'import' is reserved


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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
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

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/web/ui/partners/discounts/add-edit-discount-sheet.tsx`:
- Around line 633-648: The custom duration input disallows zero via min="1" and
the onChange guard (parsed > 0) even though the schema and presets allow 0;
change the input attribute to min="0", clamp parsed using
Math.max(Math.min(parsed, 9999), 0) (or equivalent) and update the onChange
condition to accept parsed >= 0 so setValue("maxDuration", clamped, {
shouldDirty: true }) and setCustomDurationInput(display) will allow and persist
zero; update references in the component handling customDurationInput and the
onChange handler accordingly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2db62fa1-25b0-45a3-9bac-e2c072c27508

📥 Commits

Reviewing files that changed from the base of the PR and between 8a42da7 and 43488b6.

📒 Files selected for processing (3)
  • apps/web/lib/zod/schemas/misc.ts
  • apps/web/ui/partners/discounts/add-edit-discount-sheet.tsx
  • apps/web/ui/shared/inline-badge-popover.tsx

Comment thread apps/web/ui/partners/discounts/add-edit-discount-sheet.tsx Outdated
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.

1 participant