Skip to content

Add manual credit granting to the dashboard - #15420

Merged
strandhvilliam merged 18 commits into
mainfrom
villiam/manual-credit-granting-dashboard
Oct 15, 2026
Merged

strandhvilliam merged 18 commits into
mainfrom
villiam/manual-credit-granting-dashboard

Conversation

@strandhvilliam

@strandhvilliam strandhvilliam commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #15405, which adds the endpoint this calls.

Lets a merchant add credits to a customer's meter from the dashboard.

Screenshots
Modal
Screenshot 2026-10-13 at 22 59 24
Button on each customer meter rows
Screenshot 2026-10-13 at 22 58 27
Customer Meter page -- Add credit button
Screenshot 2026-10-13 at 22 58 14

@vercel

vercel Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
orbit Ready Ready Preview Oct 15, 2026 9:10am UTC
polar-test Ready Ready Preview Oct 15, 2026 9:10am UTC

Request Review

@strandhvilliam strandhvilliam changed the title villiam/manual credit granting dashboard Add manual credit granting to the dashboard Oct 13, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

1 issue found and verified against the latest diff

Confidence score: 3/5

  • useMeterCreditOptions.ts only loads the first 10 subscriptions, so a meter tied to a later active subscription can miss its overage preview. Request the maximum page size and paginate when needed.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="clients/apps/web/src/components/Customer/AddCredits/useMeterCreditOptions.ts">

<violation number="1" location="clients/apps/web/src/components/Customer/AddCredits/useMeterCreditOptions.ts:25">
P2: This query returns only the first page, defaulting to 10 subscriptions; a meter priced by a later active subscription then has no overage preview. Request the maximum page size and paginate when necessary.</violation>
</file>

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread clients/apps/web/src/hooks/queries/customerMeters.ts
Comment thread clients/apps/web/src/components/Customer/AddCredits/useMeterCreditOptions.ts Outdated
})
const { data: subscriptions } = useSubscriptions(organizationId, {
customer_id: customer.id,
active: true,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2: This query returns only the first page, defaulting to 10 subscriptions; a meter priced by a later active subscription then has no overage preview. Request the maximum page size and paginate when necessary.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At clients/apps/web/src/components/Customer/AddCredits/useMeterCreditOptions.ts, line 25:

<comment>This query returns only the first page, defaulting to 10 subscriptions; a meter priced by a later active subscription then has no overage preview. Request the maximum page size and paginate when necessary.</comment>

<file context>
@@ -0,0 +1,54 @@
+    })
+  const { data: subscriptions } = useSubscriptions(organizationId, {
+    customer_id: customer.id,
+    active: true,
+  })
+
</file context>

Comment thread clients/apps/web/src/components/Customer/AddCredits/useMeterCreditOptions.ts Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 10 files

Requires human review: Auto-approval blocked because this review re-detected 3 unresolved issues already reported by Cubic.

View guided diff | Turn on auto-fix | Re-trigger cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

0 issues found across 3 files (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Requires human review: Auto-approval blocked by 2 unresolved issues from previous reviews.

View guided diff | Turn on auto-fix | Re-trigger cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

0 issues found across 2 files (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Requires human review: Auto-approval blocked by 1 unresolved issue from previous reviews.

View guided diff | Turn on auto-fix | Re-trigger cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

0 issues found across 1 file (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Requires human review: Auto-approval blocked by 1 unresolved issue from previous reviews.

View guided diff | Turn on auto-fix | Re-trigger cubic

Base automatically changed from villiam/manual-credit-granting to main October 14, 2026 11:57
@mintlify

mintlify Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
Polar 🟢 Ready View Preview Oct 15, 2026, 9:09 AM

💡 Tip: Enable Automations to automatically generate PRs for you.

if (result.error) return
const queryClient = getQueryClient()
queryClient.invalidateQueries({ queryKey: ['events'] })
void waitForCreditedUnitsChange(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Implemented polling here until the credit is applied.

Another option could be to add a sse event to the existing connection the dashboard has.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

😬 yeah, I understand why, but I'm not sure… Can we get away with a "It may take a while until granted credits show up" for now?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We probably could!


if (
!canManageCustomers ||
!organization.feature_settings?.config_as_code_enabled

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Blocking this on the dashboard for now just to be safe. But can just roll it out directly too?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

yolo buddy

@strandhvilliam
strandhvilliam marked this pull request as ready for review October 14, 2026 13:37

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 5 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread server/polar/customer_meter/service.py Outdated
strandhvilliam and others added 18 commits October 15, 2026 11:08
Adds an "Add credits" side panel that grants credits on a customer meter
through POST /v1/customer-meters/credits. It opens from the customer-meter
page with that meter preselected, and from the customer menu with no meter
selected. The panel previews the new balance and, for billed meters, how
much of the current overage the credits cover.

Credits always roll over and can't be removed. The entry points only show
for organizations with config as code enabled and members who can manage
customers.
Each meter row on the customer Usage tab gets an "Add credits" button
that opens the panel with that meter preselected. Column widths give the
meter name more room so the extra column fits on narrower screens.
- The panel checks the customers:manage permission itself and shows the
  restricted view, like the other customer modals; callers use useModal
  and InlineModal directly and only check the config as code flag.
- The amount is a number input with form rules instead of a custom parser.
- Reuse FormattedUnits and formatCurrency in the summary.
- Drop the intro copy, the unit suffix and the schema-name discriminators.
- Explain an external_id conflict as a possibly already added grant
  instead of showing the raw API message.
- Inline the panel header in both views, like the other customer modals.
- Keep the overage cost helper local to getCreditPreview.
- Build balance and subscription lookups by meter before mapping options.
Buttons follow the form instead of pinning to the drawer bottom, the
amount is a numeric text field validated as you type, the credits field
is focused when a meter is preselected, labels pluralize, and the entry
points are hidden without customers:manage.
…llback

On mobile, Add credits sits on the title row.
The base branch renamed CustomerMeterCreditsCustomerIDCreate to
CustomerMeterCreditsIDCreate and requires meter_id on that schema.

Co-authored-by: Villiam Strandh <villiam.strandh@outlook.com>
Recompute the customer meter balance in the credit request instead of
waiting for the debounced customer_meter.update_customer job, so the
dashboard sees the new balance right after granting credits. If a
worker holds the customer meter lock, fall back to activating the meter
and let the debounced job pick up the credit.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…eter

When a worker holds the customer meter lock, it computed the balance
from events read before the credit was committed, and create_event
never enqueues customer_meter.update_customer. Enqueue it in the
fallback so the credit is reflected once the request commits.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

0 issues found across 2 files (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Requires human review: Auto-approval blocked by 1 unresolved issue from previous reviews.

View guided diff | Turn on auto-fix | Re-trigger cubic

@strandhvilliam
strandhvilliam added this pull request to the merge queue Oct 15, 2026
Merged via the queue into main with commit 3afef32 Oct 15, 2026
32 checks passed
@strandhvilliam
strandhvilliam deleted the villiam/manual-credit-granting-dashboard branch October 15, 2026 09:21

This branch was successfully deployed

3 active deployments
Preview – polar-test — 0169da59 Deployed Oct 15, 2026 by vercel[bot]
Preview – orbit — 0169da59 Deployed Oct 15, 2026 by vercel[bot]
staging - docs — 0169da59 Deployed Oct 15, 2026 by mintlify[bot]
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.

4 participants