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

Skip to content

Conversation

@TWilson023
Copy link
Collaborator

@TWilson023 TWilson023 commented Aug 15, 2025

Summary by CodeRabbit

  • New Features

    • Duplicate the default group’s discount or reward into other groups via a “Duplicate default group” button (shown only for non-default groups).
    • Discount and reward sheets accept external default values to prefill forms for faster setup.
  • Improvements

    • Prevent accidental openings by ignoring item clicks originating from interactive child controls.
    • Improved reward item responsiveness and layout on small screens.
    • Skeletons now show when loading or when group data is not yet available.

@vercel
Copy link
Contributor

vercel bot commented Aug 15, 2025

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

Project Deployment Preview Updated (UTC)
dub Ready Ready Preview Aug 15, 2025 9:35pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 15, 2025

Walkthrough

Adds "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 DiscountItem signature to accept a group prop.

Changes

Cohort / File(s) Summary
Dashboard group pages (discounts & rewards)
apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/discount/group-discount.tsx, apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/rewards/group-rewards.tsx
Add "Duplicate default group" / "Copy default" buttons for non-default groups; fetch default group (slug "default") and open sheets with prefilled default*Values; show skeleton when loading OR group missing; guard item clicks with isClickOnInteractiveChild; responsive layout tweaks; DiscountItem now requires group prop.
Discount sheet component
apps/web/ui/partners/add-edit-discount-sheet.tsx
Add optional defaultDiscountValues?: DiscountProps to DiscountSheetProps; DiscountSheetContent accepts defaultDiscountValues and initializes form defaults from `discount
Reward sheet component
apps/web/ui/partners/rewards/add-edit-reward-sheet.tsx
Add optional defaultRewardValues?: RewardProps to RewardSheetProps; RewardSheetContent accepts defaultRewardValues and initializes form defaults from `reward

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
Loading
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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • steven-tey

Poem

I’m a rabbit with a little hop and grin,
I copy defaults and tuck them in.
Sheets pop open, values take their place,
Clicks behave, no accidental race.
Hooray for shortcuts—start with a happy hop! 🐇✨

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 duplicate-default-rewards

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.

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

🔭 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 amount at 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.

defaultValuesSource correctly unifies edit vs. duplicate flows. However, the initial isRecurring state and the radio toggle reuse discount?.maxDuration and ignore defaultDiscountValues, 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 (or amount is 0-like), dividing undefined will yield NaN. 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.

📥 Commits

Reviewing files that changed from the base of the PR and between b53961b and 59a3a26.

📒 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?: DiscountProps is 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.

  • defaultRewardValues and defaultValuesSource mirror the discount pattern cleanly.
  • Correct type-aware scaling of amount and modifiers for flat vs. percentage.
  • Properly treating maxDuration: null as Infinity and 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 !group prevents a flash of empty state and aligns with the rewards page behavior.


56-59: Guard against interactive-child clicks is correct.

Using isClickOnInteractiveChild prevents 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.

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 (5)
apps/web/ui/partners/add-edit-discount-sheet.tsx (4)

60-66: Preserve duplicated maxDuration when toggling Recurring

When duplicating from default group, toggling the “Discount Type” back to Recurring resets maxDuration to Infinity because the code references discount?.maxDuration and ignores defaultDiscountValues. Use defaultValuesSource to 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 missing

Guard against undefined amounts to prevent NaN in 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: 100 blocks 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 == null doesn’t catch NaN. 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 presses

The 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.

📥 Commits

Reviewing files that changed from the base of the PR and between 63f2c13 and 6955bd9.

📒 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 addition

Introducing defaultDiscountValues?: DiscountProps is a clean way to support duplication/prefill without complicating the existing discount prop.


50-54: Signature update reads well

Accepting defaultDiscountValues here 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 good

Typed imports and the DEFAULT_PARTNER_GROUP constant are used correctly below.


16-16: Interactive-child click guard is a solid UX improvement

Using isClickOnInteractiveChild avoids accidental sheet opens from nested buttons/links.


27-31: Broadened skeleton condition is appropriate

Rendering the skeleton when loading || !group avoids undefined access and smooths hydration.


36-43: Passing group into DiscountItem

Extending DiscountItem with group is clean and is used for default-vs-non-default decisions. Types align (DiscountProps | null).


52-59: Clickable container + guard is consistent

Adding cursor-pointer on the container and guarding with isClickOnInteractiveChild is consistent and avoids double sheet opens.


97-122: “Duplicate default group” flow is well-wired

  • Fetches the default group by slug.
  • Prefills DiscountSheet via defaultDiscountValues.
  • Stops propagation to avoid parent click handling.

Looks good, and isolates this path without impacting the primary sheet.

@steven-tey steven-tey merged commit 33200eb into main Aug 15, 2025
8 checks passed
@steven-tey steven-tey deleted the duplicate-default-rewards branch August 15, 2025 22:20
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