-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Duplicate default rewards + discounts #2752
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
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughAdds "duplicate from default group" actions for non-default groups (discounts and rewards), lets sheets accept external default values to prefill forms, broadens skeleton rendering when group data is missing, refines item click handling to ignore interactive-child clicks, updates responsive layout, and changes Changes
Sequence Diagram(s)sequenceDiagram
participant U as User
participant PG as Group Page (Discounts/Rewards)
participant DG as useGroup("default")
participant S as Sheet (Discount/Reward)
participant API as Backend API
U->>PG: Click "Duplicate default group"
PG->>DG: Fetch default group data
DG-->>PG: Return default discount/reward
PG->>S: Open sheet with default*Values
U->>S: Edit and submit
S->>API: Create/Update group discount/reward
API-->>S: Success
S-->>PG: Close and refresh list
sequenceDiagram
participant U as User
participant Item as Discount/Reward Item
participant Sheet as Sheet
U->>Item: Click on item
Item->>Item: isClickOnInteractiveChild?
alt Click on interactive child
Item-->>U: Ignore open action
else
Item->>Sheet: Open sheet for edit/create
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
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 (
|
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
🔭 Outside diff range comments (1)
apps/web/ui/partners/add-edit-discount-sheet.tsx (1)
367-374: Flat-amount discounts improperly capped at 100.Validation unconditionally caps
amountat 100, which is correct for percentages but blocks flat USD discounts over $100.Use a type-aware max like in the rewards sheet:
{...register("amount", { valueAsNumber: true, min: 0, - max: 100, + max: type === "percentage" ? 100 : undefined, onChange: handleMoneyInputChange, required: true, })}
🧹 Nitpick comments (4)
apps/web/ui/partners/add-edit-discount-sheet.tsx (2)
50-54: Defaults plumbing is solid; align isRecurring and toggle behavior to respect defaultDiscountValues.
defaultValuesSourcecorrectly unifies edit vs. duplicate flows. However, the initialisRecurringstate and the radio toggle reusediscount?.maxDurationand ignoredefaultDiscountValues, which can hide the "Duration" UI or set an unexpected duration when duplicating defaults.Apply these changes:
@@ - const [isRecurring, setIsRecurring] = useState( - discount ? discount.maxDuration !== 0 : false, - ); + // Respect defaults when duplicating + const [isRecurring, setIsRecurring] = useState( + (discount?.maxDuration ?? defaultDiscountValues?.maxDuration ?? 0) !== 0, + ); @@ - setValue( - "maxDuration", - recurring - ? discount?.maxDuration || - Infinity - : 0, - ); + setValue( + "maxDuration", + recurring + ? (discount?.maxDuration ?? + defaultDiscountValues?.maxDuration ?? + Infinity) + : 0, + );Also applies to: 69-70, 78-90
80-83: Prevent potential NaN when default amount is absent.If a flat default is provided without an
amount(oramountis 0-like), dividingundefinedwill yieldNaN. Safer to null-coalesce before scaling.- defaultValuesSource?.type === "flat" - ? defaultValuesSource.amount / 100 - : defaultValuesSource?.amount, + defaultValuesSource?.type === "flat" + ? (defaultValuesSource?.amount ?? 0) / 100 + : defaultValuesSource?.amount ?? undefined,apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/discount/group-discount.tsx (1)
97-103: Use the DEFAULT_PARTNER_GROUP slug constant for consistency.Avoid hardcoding "default" to reduce drift if the slug ever changes.
-const CopyDefaultDiscountButton = () => { - const { group: defaultGroup } = useGroup({ slug: "default" }); +const CopyDefaultDiscountButton = () => { + const { group: defaultGroup } = useGroup({ slug: DEFAULT_PARTNER_GROUP.slug });apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/rewards/group-rewards.tsx (1)
213-218: Use the DEFAULT_PARTNER_GROUP slug constant for parity with the discounts file.Small consistency tweak.
-const CopyDefaultRewardButton = ({ event }: { event: EventType }) => { - const { group: defaultGroup } = useGroup({ slug: "default" }); +const CopyDefaultRewardButton = ({ event }: { event: EventType }) => { + const { group: defaultGroup } = useGroup({ slug: DEFAULT_PARTNER_GROUP.slug });
📜 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 (4)
apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/discount/group-discount.tsx(5 hunks)apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/rewards/group-rewards.tsx(3 hunks)apps/web/ui/partners/add-edit-discount-sheet.tsx(4 hunks)apps/web/ui/partners/rewards/add-edit-reward-sheet.tsx(2 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-07-30T15:29:54.131Z
Learnt from: TWilson023
PR: dubinc/dub#2673
File: apps/web/ui/partners/rewards/rewards-logic.tsx:268-275
Timestamp: 2025-07-30T15:29:54.131Z
Learning: In apps/web/ui/partners/rewards/rewards-logic.tsx, when setting the entity field in a reward condition, dependent fields (attribute, operator, value) should be reset rather than preserved because different entities (customer vs sale) have different available attributes. Maintaining existing fields when the entity changes would create invalid state combinations and confusing UX.
Applied to files:
apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/rewards/group-rewards.tsx
📚 Learning: 2025-07-30T15:25:13.936Z
Learnt from: TWilson023
PR: dubinc/dub#2673
File: apps/web/ui/partners/rewards/add-edit-reward-sheet.tsx:56-66
Timestamp: 2025-07-30T15:25:13.936Z
Learning: In apps/web/ui/partners/rewards/add-edit-reward-sheet.tsx, the form schema uses partial condition objects to allow users to add empty/unconfigured condition fields without type errors, while submission validation uses strict schemas to ensure data integrity. This two-stage validation pattern improves UX by allowing progressive completion of complex forms.
Applied to files:
apps/web/ui/partners/rewards/add-edit-reward-sheet.tsx
🧬 Code Graph Analysis (4)
apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/rewards/group-rewards.tsx (4)
packages/ui/src/icons/index.tsx (1)
Icon(79-79)apps/web/lib/zod/schemas/groups.ts (1)
DEFAULT_PARTNER_GROUP(9-13)apps/web/lib/swr/use-group.ts (1)
useGroup(7-30)apps/web/ui/partners/rewards/add-edit-reward-sheet.tsx (2)
useRewardSheet(504-515)RewardSheet(482-502)
apps/web/ui/partners/add-edit-discount-sheet.tsx (1)
apps/web/lib/types.ts (1)
DiscountProps(410-410)
apps/web/ui/partners/rewards/add-edit-reward-sheet.tsx (3)
apps/web/lib/types.ts (1)
RewardProps(474-474)apps/web/lib/swr/use-group.ts (1)
useGroup(7-30)apps/web/lib/swr/use-workspace.ts (1)
useWorkspace(6-45)
apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/discount/group-discount.tsx (4)
apps/web/lib/types.ts (2)
DiscountProps(410-410)GroupProps(509-509)apps/web/lib/zod/schemas/groups.ts (1)
DEFAULT_PARTNER_GROUP(9-13)apps/web/lib/swr/use-group.ts (1)
useGroup(7-30)apps/web/ui/partners/add-edit-discount-sheet.tsx (2)
useDiscountSheet(495-506)DiscountSheet(480-493)
⏰ 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 (7)
apps/web/ui/partners/add-edit-discount-sheet.tsx (1)
32-33: Prop addition looks good and keeps the public surface backward-compatible.Adding
defaultDiscountValues?: DiscountPropsis a clean extension that enables prefilled creation without breaking existing callers.apps/web/ui/partners/rewards/add-edit-reward-sheet.tsx (1)
59-60: Well-implemented defaultValue source and scaling.
defaultRewardValuesanddefaultValuesSourcemirror the discount pattern cleanly.- Correct type-aware scaling of
amountandmodifiersfor flat vs. percentage.- Properly treating
maxDuration: nullasInfinityand converting back on submit.No issues from a correctness or UX standpoint.
Also applies to: 77-82, 88-110
apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/discount/group-discount.tsx (3)
27-31: Skeleton condition broadened appropriately.Rendering the skeleton when either loading or
!groupprevents a flash of empty state and aligns with the rewards page behavior.
56-59: Guard against interactive-child clicks is correct.Using
isClickOnInteractiveChildprevents opening the sheet when clicking inner controls (e.g., Duplicate button). Good UX safeguard.
77-91: Nice composition: adds “Duplicate default group” affordance without altering the primary action.The two-button layout is responsive and avoids accidental open of the main sheet by stopping propagation on the duplicate button.
apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/rewards/group-rewards.tsx (2)
149-156: Responsive layout refinements improve small-screen readability.Switching to column on small screens with a non-shrinking icon prevents text squish and aligns actions cleanly on md+.
Also applies to: 159-159
191-205: Create flow plus “Duplicate default group” action is a solid UX improvement.The composition mirrors discounts, includes proper event scoping, and correctly prevents link navigation via
preventDefault/stopPropagation.
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 (5)
apps/web/ui/partners/add-edit-discount-sheet.tsx (4)
60-66: Preserve duplicated maxDuration when toggling RecurringWhen duplicating from default group, toggling the “Discount Type” back to Recurring resets
maxDurationtoInfinitybecause the code referencesdiscount?.maxDurationand ignoresdefaultDiscountValues. UsedefaultValuesSourceto preserve the prefilled value.Apply this diff:
- const defaultValuesSource = discount || defaultDiscountValues; + const defaultValuesSource = discount || defaultDiscountValues; @@ - setValue( - "maxDuration", - recurring - ? discount?.maxDuration || - Infinity - : 0, - ); + setValue( + "maxDuration", + recurring + ? (defaultValuesSource?.maxDuration ?? + Infinity) + : 0, + );Also applies to: 254-260
80-83: Avoid NaN defaults for amount when source amount is missingGuard against
undefinedamounts to preventNaNin the input when prefilled data is incomplete/unexpected.- amount: - defaultValuesSource?.type === "flat" - ? defaultValuesSource.amount / 100 - : defaultValuesSource?.amount, + amount: + defaultValuesSource?.type === "flat" + ? (defaultValuesSource?.amount != null + ? defaultValuesSource.amount / 100 + : 0) + : (defaultValuesSource?.amount ?? 0),
368-373: Cap 100 only for percentage; allow flat USD > 100
max: 100blocks flat amounts above $100. Make the 100-cap percentage-only via a custom validator.- {...register("amount", { - valueAsNumber: true, - min: 0, - max: 100, - onChange: handleMoneyInputChange, - required: true, - })} + {...register("amount", { + valueAsNumber: true, + min: 0, + validate: (v) => + type === "percentage" + ? v <= 100 || "Percentage must be <= 100" + : true, + onChange: handleMoneyInputChange, + required: true, + })}
469-471: Disable submit on NaN amount
amount == nulldoesn’t catchNaN. Ensure the button disables when the value can’t be parsed.- disabled={ - amount == null || isDeleting || isCreating || isUpdating - } + disabled={ + amount == null || + Number.isNaN(amount) || + isDeleting || + isCreating || + isUpdating + }apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/discount/group-discount.tsx (1)
77-90: Prevent parent click handler from ever firing on button pressesThe parent has a guard, but adding
stopPropagation()here makes this robust if the guard changes in the future.<Button text={discount ? "Edit" : "Create"} variant={discount ? "secondary" : "primary"} className="h-9 w-full rounded-lg md:w-fit" onClick={(e) => { e.preventDefault(); + e.stopPropagation(); setIsOpen(true); }} />
📜 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/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/discount/group-discount.tsx(5 hunks)apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/rewards/group-rewards.tsx(3 hunks)apps/web/ui/partners/add-edit-discount-sheet.tsx(3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/rewards/group-rewards.tsx
🧰 Additional context used
🧬 Code Graph Analysis (2)
apps/web/ui/partners/add-edit-discount-sheet.tsx (3)
apps/web/lib/types.ts (1)
DiscountProps(410-410)apps/web/lib/swr/use-workspace.ts (1)
useWorkspace(6-45)apps/web/lib/swr/use-group.ts (1)
useGroup(7-30)
apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/discount/group-discount.tsx (4)
apps/web/lib/types.ts (2)
DiscountProps(410-410)GroupProps(509-509)apps/web/lib/zod/schemas/groups.ts (1)
DEFAULT_PARTNER_GROUP(9-13)apps/web/lib/swr/use-group.ts (1)
useGroup(7-30)apps/web/ui/partners/add-edit-discount-sheet.tsx (2)
useDiscountSheet(495-506)DiscountSheet(480-493)
⏰ 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 (8)
apps/web/ui/partners/add-edit-discount-sheet.tsx (2)
32-33: Prop to prefill discount forms — good additionIntroducing
defaultDiscountValues?: DiscountPropsis a clean way to support duplication/prefill without complicating the existingdiscountprop.
50-54: Signature update reads wellAccepting
defaultDiscountValueshere keeps the public API minimal and centralizes defaulting logic in one place. No concerns.apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/discount/group-discount.tsx (6)
4-6: Imports for types and default group look goodTyped imports and the
DEFAULT_PARTNER_GROUPconstant are used correctly below.
16-16: Interactive-child click guard is a solid UX improvementUsing
isClickOnInteractiveChildavoids accidental sheet opens from nested buttons/links.
27-31: Broadened skeleton condition is appropriateRendering the skeleton when
loading || !groupavoids undefined access and smooths hydration.
36-43: Passing group into DiscountItemExtending
DiscountItemwithgroupis clean and is used for default-vs-non-default decisions. Types align (DiscountProps | null).
52-59: Clickable container + guard is consistentAdding
cursor-pointeron the container and guarding withisClickOnInteractiveChildis consistent and avoids double sheet opens.
97-122: “Duplicate default group” flow is well-wired
- Fetches the default group by slug.
- Prefills
DiscountSheetviadefaultDiscountValues.- Stops propagation to avoid parent click handling.
Looks good, and isolates this path without impacting the primary sheet.
Summary by CodeRabbit
New Features
Improvements