Repository navigation
Add manual credit granting to the dashboard - #15420
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
1 issue found and verified against the latest diff
Confidence score: 3/5
useMeterCreditOptions.tsonly 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
| }) | ||
| const { data: subscriptions } = useSubscriptions(organizationId, { | ||
| customer_id: customer.id, | ||
| active: true, |
There was a problem hiding this comment.
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>
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
7d218cb to
bdd5a12
Compare
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Automations to automatically generate PRs for you. |
416de49 to
fda0f64
Compare
| if (result.error) return | ||
| const queryClient = getQueryClient() | ||
| queryClient.invalidateQueries({ queryKey: ['events'] }) | ||
| void waitForCreditedUnitsChange( |
There was a problem hiding this comment.
Implemented polling here until the credit is applied.
Another option could be to add a sse event to the existing connection the dashboard has.
There was a problem hiding this comment.
😬 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?
There was a problem hiding this comment.
We probably could!
|
|
||
| if ( | ||
| !canManageCustomers || | ||
| !organization.feature_settings?.config_as_code_enabled |
There was a problem hiding this comment.
Blocking this on the dashboard for now just to be safe. But can just roll it out directly too?
There was a problem hiding this comment.
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
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>
e3739af to
0169da5
Compare
There was a problem hiding this comment.
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
Stacked on #15405, which adds the endpoint this calls.
Lets a merchant add credits to a customer's meter from the dashboard.