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

Skip to content

Conversation

@steven-tey
Copy link
Collaborator

@steven-tey steven-tey commented Aug 26, 2025

Summary by CodeRabbit

  • New Features

    • Added support for a “Total Sale Amount” metric in commission data to enable richer aggregates across partner and sales views.
  • Refactor

    • Improved totals display in customer sales and partner earnings tables: non-zero values now use human-readable number formatting; zero/undefined values show a loading placeholder for a cleaner experience.

@vercel
Copy link
Contributor

vercel bot commented Aug 26, 2025

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

Project Deployment Preview Updated (UTC)
dub Ready Ready Preview Aug 26, 2025 2:26am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 26, 2025

Walkthrough

Adds 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

Cohort / File(s) Summary
Webhook sample event
apps/web/lib/webhook/sample-events/commission-created.json
Inserted partner.totalSaleAmount: 100000 between totalSales and totalCommissions.
Zod commission schema
apps/web/lib/zod/schemas/commissions.ts
Added totalSaleAmount: z.number() to partner aggregate in CommissionWebhookSchema.
UI totals formatting (customers)
apps/web/ui/customers/customer-partner-earnings-table.tsx, apps/web/ui/customers/customer-sales-table.tsx
Imported nFormatter and changed rendering: show formatted totals only when truthy; otherwise show loading placeholder. Affects totalCommissions and totalSales footers.

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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • devkiran

Poem

A hop and a skip through totals we go,
New sums in our pouch, formatted just so.
When zero appears, we patiently wait—
A placeholder blink, then numbers look great.
Carrot-calculations? Crunchy and neat.
Thump-thump approved—this update’s complete! 🥕✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch commission-webhook-followup

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

📥 Commits

Reviewing files that changed from the base of the PR and between 65379f6 and 0ae8e1d.

📒 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 includes totalSaleAmount
I’ve confirmed that in apps/web/lib/partners/create-partner-commission.ts the call to

sendWorkspaceWebhook({,
  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 include totalSaleAmount. The sample event under lib/webhook/sample-events/commission-created.json already lists "totalSaleAmount".

Next step: Update your public webhook documentation (and version/history notes) to call out the new totalSaleAmount field 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.

Comment on lines +127 to 130
{totalCommissions ? (
nFormatter(totalCommissions, { full: true })
) : (
<div className="size-3 animate-pulse rounded-md bg-neutral-100" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

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.

Suggested change
{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.

Comment on lines +146 to 149
{totalSales ? (
nFormatter(totalSales, { full: true })
) : (
<div className="size-3 animate-pulse rounded-md bg-neutral-100" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

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.

Suggested change
{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.

@steven-tey steven-tey merged commit f4d9477 into main Aug 26, 2025
8 of 9 checks passed
@steven-tey steven-tey deleted the commission-webhook-followup branch August 26, 2025 02:33
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.

2 participants