-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Include totalSaleAmount in commission webhook #2775
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 partner.aggregate field totalSaleAmount to commission webhook schema and sample event JSON. Updates two customer UI tables to format total values via nFormatter and switch to truthiness checks, showing a placeholder when totals are 0 or falsy. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant UI as Customer*Table Footer
participant Util as nFormatter
User->>UI: View table
alt total is truthy
UI->>Util: format(total, { full: true })
Util-->>UI: "1,234" (example)
UI-->>User: Render formatted total
else total is falsy (0/null/undefined)
UI-->>User: Render loading placeholder
end
note over UI: Applies to totalSales and totalCommissions
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
✨ 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: 2
🧹 Nitpick comments (1)
apps/web/lib/zod/schemas/commissions.ts (1)
60-60: Constrain and document totalSaleAmount to prevent invalid values.As an aggregate of monetary amounts in cents, this should never be negative. Consider enforcing that and adding a brief description for consumers/tools.
Apply this diff:
- totalSaleAmount: z.number(), + // Sum of all sale amounts for the partner, in cents (minor units). + totalSaleAmount: z.number().min(0),
📜 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/lib/webhook/sample-events/commission-created.json(1 hunks)apps/web/lib/zod/schemas/commissions.ts(1 hunks)apps/web/ui/customers/customer-partner-earnings-table.tsx(2 hunks)apps/web/ui/customers/customer-sales-table.tsx(2 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/lib/webhook/sample-events/commission-created.json (1)
25-25: Addition of totalSaleAmount in sample event looks good; confirm units are minor (cents).The value 100000 aligns with other amount fields that appear to be in cents. Please ensure docs for the webhook explicitly note that totalSaleAmount is in minor units and matches the program currency, and update any API docs or changelogs accordingly.
Would you like me to open a quick docs PR to add this field to the webhook reference and changelog?
apps/web/lib/zod/schemas/commissions.ts (1)
45-66: ✅ Commission Webhook payload already includestotalSaleAmount
I’ve confirmed that inapps/web/lib/partners/create-partner-commission.tsthe call tosendWorkspaceWebhook({ …, data: CommissionWebhookSchema.parse({ …commission, partner: { …programEnrollment.partner, totalClicks: stats.totalClicks, totalLeads: stats.totalLeads, totalConversions: stats.totalConversions, totalSales: stats.totalSales, totalSaleAmount: stats.totalSaleAmount, totalCommissions: stats.totalCommissions, }, … }), })uses the aggregated partner stats (from
aggregate-partner-links-stats.ts) which includetotalSaleAmount. The sample event underlib/webhook/sample-events/commission-created.jsonalready lists"totalSaleAmount".Next step: Update your public webhook documentation (and version/history notes) to call out the new
totalSaleAmountfield so consumers know to expect it.apps/web/ui/customers/customer-sales-table.tsx (1)
3-3: Import of nFormatter is fine.apps/web/ui/customers/customer-partner-earnings-table.tsx (1)
3-3: Import of nFormatter is fine.
| {totalCommissions ? ( | ||
| nFormatter(totalCommissions, { full: true }) | ||
| ) : ( | ||
| <div className="size-3 animate-pulse rounded-md bg-neutral-100" /> |
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.
Bug: Truthiness check hides valid 0 totals (shows loader instead of “0”).
Same issue here—0 commissions should render “0”, not the loading placeholder.
Apply this diff:
- {totalCommissions ? (
+ {totalCommissions != null ? (
nFormatter(totalCommissions, { full: true })
) : (
<div className="size-3 animate-pulse rounded-md bg-neutral-100" />
)}{" "}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| {totalCommissions ? ( | |
| nFormatter(totalCommissions, { full: true }) | |
| ) : ( | |
| <div className="size-3 animate-pulse rounded-md bg-neutral-100" /> | |
| {totalCommissions != null ? ( | |
| nFormatter(totalCommissions, { full: true }) | |
| ) : ( | |
| <div className="size-3 animate-pulse rounded-md bg-neutral-100" /> | |
| )}{" "} |
🤖 Prompt for AI Agents
In apps/web/ui/customers/customer-partner-earnings-table.tsx around lines
127-130, the current truthiness check treats 0 as falsy and shows the loading
placeholder; change the condition to explicitly check for null/undefined so zero
renders correctly — e.g. replace "totalCommissions ? ( ... ) : ( loader )" with
a nullish check like "totalCommissions != null ? (nFormatter(totalCommissions, {
full: true })) : (loader)" (or use "totalCommissions !== null &&
totalCommissions !== undefined") so 0 will display as "0" instead of the loader.
| {totalSales ? ( | ||
| nFormatter(totalSales, { full: true }) | ||
| ) : ( | ||
| <div className="size-3 animate-pulse rounded-md bg-neutral-100" /> |
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.
Bug: Truthiness check hides valid 0 totals (shows loader instead of “0”).
0 is a valid total; use a null/undefined check instead of a truthy check.
Apply this diff:
- {totalSales ? (
+ {totalSales != null ? (
nFormatter(totalSales, { full: true })
) : (
<div className="size-3 animate-pulse rounded-md bg-neutral-100" />
)}{" "}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| {totalSales ? ( | |
| nFormatter(totalSales, { full: true }) | |
| ) : ( | |
| <div className="size-3 animate-pulse rounded-md bg-neutral-100" /> | |
| {totalSales != null ? ( | |
| nFormatter(totalSales, { full: true }) | |
| ) : ( | |
| <div className="size-3 animate-pulse rounded-md bg-neutral-100" /> | |
| )}{" "} |
🤖 Prompt for AI Agents
In apps/web/ui/customers/customer-sales-table.tsx around lines 146 to 149, the
current truthy check hides valid zero totals and renders the loader for 0;
change the condition to explicitly check for null/undefined (e.g., totalSales !=
null) so 0 is treated as a valid value and rendered via nFormatter, while the
loader is shown only when totalSales is null or undefined.
Summary by CodeRabbit
New Features
Refactor