@meterbox/react 0.1.15 → 0.1.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meterbox/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.17",
|
|
4
4
|
"description": "Embeddable React components for Meterbox: pricing tables, subscription preview, credit balance and usage charts. Presentational by default, with data fetched by your backend via @meterbox/node.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://meterbox.ai",
|
|
@@ -10,6 +10,10 @@
|
|
|
10
10
|
"README.md",
|
|
11
11
|
"LICENSE"
|
|
12
12
|
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"format": "prettier --write .",
|
|
15
|
+
"format:check": "prettier --check ."
|
|
16
|
+
},
|
|
13
17
|
"engines": {
|
|
14
18
|
"node": ">=18"
|
|
15
19
|
},
|
|
@@ -17,12 +21,15 @@
|
|
|
17
21
|
"access": "public"
|
|
18
22
|
},
|
|
19
23
|
"dependencies": {
|
|
20
|
-
"@meterbox/node": "0.1.
|
|
24
|
+
"@meterbox/node": "0.1.4"
|
|
21
25
|
},
|
|
22
26
|
"peerDependencies": {
|
|
23
27
|
"react": ">=17",
|
|
24
28
|
"react-dom": ">=17"
|
|
25
29
|
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"prettier": "^3.9.10"
|
|
32
|
+
},
|
|
26
33
|
"keywords": [
|
|
27
34
|
"meterbox",
|
|
28
35
|
"react",
|
package/src/CreditGrantsTable.js
CHANGED
|
@@ -40,7 +40,13 @@ const styles = {
|
|
|
40
40
|
title: { fontSize: 14, fontWeight: 700 },
|
|
41
41
|
balance: { fontSize: 13, opacity: 0.7 },
|
|
42
42
|
table: { width: "100%", borderCollapse: "collapse", fontSize: 13 },
|
|
43
|
-
th: {
|
|
43
|
+
th: {
|
|
44
|
+
textAlign: "left",
|
|
45
|
+
padding: "6px 8px",
|
|
46
|
+
borderBottom: "1px solid #e5e7eb",
|
|
47
|
+
opacity: 0.6,
|
|
48
|
+
fontWeight: 600,
|
|
49
|
+
},
|
|
44
50
|
td: { padding: "6px 8px", borderBottom: "1px solid #f3f4f6" },
|
|
45
51
|
pill: {
|
|
46
52
|
display: "inline-block",
|
|
@@ -187,7 +193,11 @@ function CreditGrantsTable({
|
|
|
187
193
|
React.createElement(
|
|
188
194
|
"tr",
|
|
189
195
|
{ key: g.id },
|
|
190
|
-
React.createElement(
|
|
196
|
+
React.createElement(
|
|
197
|
+
"td",
|
|
198
|
+
{ style: styles.td },
|
|
199
|
+
g.reason || g.source || g.type || "—",
|
|
200
|
+
),
|
|
191
201
|
React.createElement("td", { style: styles.td }, money(g.amount_usd)),
|
|
192
202
|
React.createElement("td", { style: styles.td }, money(remaining(g))),
|
|
193
203
|
React.createElement("td", { style: styles.td }, date(g.expires_at)),
|
package/src/CreditUtilization.js
CHANGED
|
@@ -151,7 +151,9 @@ function CreditUtilization({
|
|
|
151
151
|
const y = 100 - (v / max) * 100;
|
|
152
152
|
return [x, y];
|
|
153
153
|
});
|
|
154
|
-
const linePath = coords
|
|
154
|
+
const linePath = coords
|
|
155
|
+
.map(([x, y], i) => `${i === 0 ? "M" : "L"}${x.toFixed(2)},${y.toFixed(2)}`)
|
|
156
|
+
.join(" ");
|
|
155
157
|
const areaPath = `${linePath} L100,100 L0,100 Z`;
|
|
156
158
|
return React.createElement(
|
|
157
159
|
"div",
|
package/src/InvoiceHistory.js
CHANGED
|
@@ -69,7 +69,13 @@ async function fetchInvoices({ baseUrl, customerId, customerToken, fetchImpl })
|
|
|
69
69
|
return json.invoices || [];
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
function InvoiceHistory({
|
|
72
|
+
function InvoiceHistory({
|
|
73
|
+
invoices,
|
|
74
|
+
baseUrl: baseUrlProp,
|
|
75
|
+
customerId,
|
|
76
|
+
customerToken,
|
|
77
|
+
fetch: fetchImpl,
|
|
78
|
+
}) {
|
|
73
79
|
const baseUrl = useBaseUrl(baseUrlProp);
|
|
74
80
|
const selfFetch = !invoices && customerId && customerToken;
|
|
75
81
|
const [fetched, setFetched] = React.useState(null);
|
package/src/PlanChangeCard.js
CHANGED
|
@@ -156,15 +156,21 @@ function PlanChangeCard({
|
|
|
156
156
|
const [scheduled, setScheduled] = React.useState(scheduledChange || null);
|
|
157
157
|
// "now" or "period_end" while the customer is asked to confirm it.
|
|
158
158
|
const [asking, setAsking] = React.useState(null);
|
|
159
|
+
// Another plan picked while asking: ask again for that one. Reset as it
|
|
160
|
+
// renders, not in an effect: React runs a render's pending effects before
|
|
161
|
+
// it handles a click, so one that reset this on mount could undo a click on
|
|
162
|
+
// "Change now" that came first.
|
|
163
|
+
const [askedFor, setAskedFor] = React.useState(planId);
|
|
164
|
+
if (askedFor !== planId) {
|
|
165
|
+
setAskedFor(planId);
|
|
166
|
+
setAsking(null);
|
|
167
|
+
}
|
|
159
168
|
const { t, date, money } = useI18n();
|
|
160
169
|
|
|
161
170
|
React.useEffect(() => {
|
|
162
171
|
setScheduled(scheduledChange || null);
|
|
163
172
|
}, [scheduledChange]);
|
|
164
173
|
|
|
165
|
-
// Another plan picked while asking: ask again for that one.
|
|
166
|
-
React.useEffect(() => setAsking(null), [planId]);
|
|
167
|
-
|
|
168
174
|
// The buttons asked about are gone, so focus moves to the safe answer.
|
|
169
175
|
const keepRef = React.useRef(null);
|
|
170
176
|
React.useEffect(() => {
|
|
@@ -186,7 +192,14 @@ function PlanChangeCard({
|
|
|
186
192
|
const result = onConfirm
|
|
187
193
|
? await onConfirm(effective)
|
|
188
194
|
: canSelfFetch
|
|
189
|
-
? await postChange({
|
|
195
|
+
? await postChange({
|
|
196
|
+
baseUrl,
|
|
197
|
+
customerId,
|
|
198
|
+
customerToken,
|
|
199
|
+
planId,
|
|
200
|
+
effective,
|
|
201
|
+
fetchImpl: fetcher,
|
|
202
|
+
})
|
|
190
203
|
: null;
|
|
191
204
|
if (result?.scheduled) {
|
|
192
205
|
setScheduled(result.scheduled_change);
|
|
@@ -50,7 +50,14 @@ const styles = {
|
|
|
50
50
|
delta: { fontSize: 13, fontWeight: 600 },
|
|
51
51
|
};
|
|
52
52
|
|
|
53
|
-
async function fetchPreview({
|
|
53
|
+
async function fetchPreview({
|
|
54
|
+
baseUrl,
|
|
55
|
+
customerId,
|
|
56
|
+
customerToken,
|
|
57
|
+
planId,
|
|
58
|
+
planVersion,
|
|
59
|
+
fetchImpl,
|
|
60
|
+
}) {
|
|
54
61
|
const url = `${String(baseUrl).replace(/\/+$/, "")}/v1/customer-portal/${encodeURIComponent(
|
|
55
62
|
customerId,
|
|
56
63
|
)}/subscription/preview`;
|
package/src/UsageChart.js
CHANGED
|
@@ -72,7 +72,11 @@ function UsageChart({ series, valueKey = "amount_usd", height = 120, label }) {
|
|
|
72
72
|
return React.createElement(
|
|
73
73
|
"div",
|
|
74
74
|
{ className: "meterbox-usage-chart", style: styles.wrap },
|
|
75
|
-
React.createElement(
|
|
75
|
+
React.createElement(
|
|
76
|
+
"div",
|
|
77
|
+
{ style: styles.label },
|
|
78
|
+
label || VALUE_LABELS[valueKey] || valueKey,
|
|
79
|
+
),
|
|
76
80
|
React.createElement("div", { style: styles.total }, formatValue(valueKey, total)),
|
|
77
81
|
React.createElement(
|
|
78
82
|
"svg",
|