@meterbox/react 0.1.5 → 0.1.7
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/README.md +25 -0
- package/package.json +1 -1
- package/src/BillingDetailsButton.js +98 -0
- package/src/CreditBalance.js +9 -12
- package/src/CreditGrantsTable.js +26 -27
- package/src/CreditUtilization.js +8 -11
- package/src/InvoiceHistory.js +28 -16
- package/src/PlanChangeCard.js +18 -13
- package/src/PricingTable.js +53 -52
- package/src/SubscriptionPreview.js +17 -24
- package/src/i18n.js +662 -0
- package/src/index.js +9 -0
package/src/PricingTable.js
CHANGED
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
const React = require("react");
|
|
43
43
|
const theme = require("./theme");
|
|
44
44
|
const { brandingVars } = require("./branding");
|
|
45
|
+
const { useI18n } = require("./i18n");
|
|
45
46
|
|
|
46
47
|
/**
|
|
47
48
|
* Total charged for one year prepaid upfront, or null when the plan
|
|
@@ -132,74 +133,75 @@ const styles = {
|
|
|
132
133
|
},
|
|
133
134
|
};
|
|
134
135
|
|
|
135
|
-
function formatPrice(amount, currency = "USD") {
|
|
136
|
-
if (amount == null) return "—";
|
|
137
|
-
try {
|
|
138
|
-
return new Intl.NumberFormat(undefined, {
|
|
139
|
-
style: "currency",
|
|
140
|
-
currency,
|
|
141
|
-
maximumFractionDigits: amount % 1 === 0 ? 0 : 2,
|
|
142
|
-
}).format(amount);
|
|
143
|
-
} catch (_) {
|
|
144
|
-
return `${currency} ${amount}`;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
const PAST_INCLUDED = {
|
|
149
|
-
billed: "Past that, per 1M tokens:",
|
|
150
|
-
blocked: "Usage stops there until next month.",
|
|
151
|
-
upgrade: "Past that, your plan is upgraded automatically.",
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
function compact(n) {
|
|
155
|
-
return new Intl.NumberFormat("en", { notation: "compact" }).format(n);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
function rate(perUnit) {
|
|
159
|
-
const v = Math.round(perUnit * 1e6) / 1e6;
|
|
160
|
-
return `$${v > 0 && v < 0.01 ? v.toPrecision(2) : v.toFixed(2)}`;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
136
|
/** "$3.00 to 10M then $2.50" — a tier ladder priced per 1,000 units × `scale`. */
|
|
164
|
-
function ladderText(tiers, scale) {
|
|
137
|
+
function ladderText({ t, money, number }, tiers, scale) {
|
|
138
|
+
const rate = (perUnit) => {
|
|
139
|
+
const v = Math.round(perUnit * 1e6) / 1e6;
|
|
140
|
+
return money(
|
|
141
|
+
v,
|
|
142
|
+
"USD",
|
|
143
|
+
v > 0 && v < 0.01
|
|
144
|
+
? { minimumSignificantDigits: 2, maximumSignificantDigits: 2 }
|
|
145
|
+
: { minimumFractionDigits: 2, maximumFractionDigits: 2 },
|
|
146
|
+
);
|
|
147
|
+
};
|
|
165
148
|
return tiers
|
|
166
|
-
.map((
|
|
167
|
-
|
|
149
|
+
.map((tier) => {
|
|
150
|
+
const price = rate(tier.per_1k * scale);
|
|
151
|
+
if (tier.up_to == null) return price;
|
|
152
|
+
return t("pricing.upTo", { rate: price, n: number(tier.up_to, { notation: "compact" }) });
|
|
153
|
+
})
|
|
154
|
+
.join(` ${t("pricing.then")} `);
|
|
168
155
|
}
|
|
169
156
|
|
|
170
157
|
/** Included amounts, what happens past them, and the models' rates. */
|
|
171
158
|
function PlanUsage({ usage }) {
|
|
159
|
+
const i18n = useI18n();
|
|
160
|
+
const { t, number } = i18n;
|
|
172
161
|
const { included, overage, models, api_call_overage_tiers: callTiers } = usage;
|
|
173
162
|
const parts = [
|
|
174
|
-
[included.input_tokens, "
|
|
175
|
-
[included.output_tokens, "
|
|
176
|
-
[included.api_calls, "
|
|
163
|
+
[included.input_tokens, "pricing.inputTokens"],
|
|
164
|
+
[included.output_tokens, "pricing.outputTokens"],
|
|
165
|
+
[included.api_calls, "pricing.apiCalls"],
|
|
177
166
|
]
|
|
178
167
|
.filter(([n]) => n > 0)
|
|
179
|
-
.map(([n,
|
|
168
|
+
.map(([n, key]) => t(key, { n: number(n, { notation: "compact" }) }));
|
|
180
169
|
const billed = overage === "billed";
|
|
181
170
|
return React.createElement(
|
|
182
171
|
"div",
|
|
183
172
|
{ className: "meterbox-plan-usage", style: styles.usage },
|
|
184
|
-
parts.length > 0 &&
|
|
173
|
+
parts.length > 0 &&
|
|
174
|
+
React.createElement("div", null, t("pricing.includes", { parts: parts.join(", ") })),
|
|
185
175
|
React.createElement(
|
|
186
176
|
"div",
|
|
187
177
|
{ style: { opacity: 0.75 } },
|
|
188
|
-
billed && parts.length === 0 ? "
|
|
178
|
+
billed && parts.length === 0 ? t("pricing.per1M") : t(`pricing.past.${overage}`, null, ""),
|
|
189
179
|
),
|
|
190
180
|
billed
|
|
191
181
|
? models.map((m) =>
|
|
192
182
|
React.createElement(
|
|
193
183
|
"div",
|
|
194
184
|
{ key: m.id },
|
|
195
|
-
|
|
185
|
+
t("pricing.modelRates", {
|
|
186
|
+
model: m.name,
|
|
187
|
+
input: ladderText(i18n, m.input_tiers, 1000),
|
|
188
|
+
output: ladderText(i18n, m.output_tiers, 1000),
|
|
189
|
+
}),
|
|
196
190
|
),
|
|
197
191
|
)
|
|
198
192
|
: models.length > 0 &&
|
|
199
|
-
React.createElement(
|
|
193
|
+
React.createElement(
|
|
194
|
+
"div",
|
|
195
|
+
null,
|
|
196
|
+
t("pricing.models", { names: models.map((m) => m.name).join(", ") }),
|
|
197
|
+
),
|
|
200
198
|
billed &&
|
|
201
199
|
callTiers &&
|
|
202
|
-
React.createElement(
|
|
200
|
+
React.createElement(
|
|
201
|
+
"div",
|
|
202
|
+
null,
|
|
203
|
+
t("pricing.apiCallRates", { ladder: ladderText(i18n, callTiers, 1) }),
|
|
204
|
+
),
|
|
203
205
|
);
|
|
204
206
|
}
|
|
205
207
|
|
|
@@ -258,6 +260,7 @@ function PricingTable({
|
|
|
258
260
|
const selfFetch = !Array.isArray(plans) && !!baseUrl && !!publishableKey;
|
|
259
261
|
const [fetched, setFetched] = React.useState(null);
|
|
260
262
|
const [billingInterval, setBillingInterval] = React.useState("monthly");
|
|
263
|
+
const { t, money } = useI18n();
|
|
261
264
|
|
|
262
265
|
React.useEffect(() => {
|
|
263
266
|
if (!selfFetch) return undefined;
|
|
@@ -282,7 +285,7 @@ function PricingTable({
|
|
|
282
285
|
return React.createElement(
|
|
283
286
|
"div",
|
|
284
287
|
{ style: { opacity: 0.6, fontFamily: styles.grid.fontFamily } },
|
|
285
|
-
selfFetch && list == null ? "
|
|
288
|
+
selfFetch && list == null ? t("pricing.loading") : t("pricing.empty"),
|
|
286
289
|
);
|
|
287
290
|
}
|
|
288
291
|
|
|
@@ -308,7 +311,7 @@ function PricingTable({
|
|
|
308
311
|
"aria-pressed": billingInterval === interval,
|
|
309
312
|
onClick: () => setBillingInterval(interval),
|
|
310
313
|
},
|
|
311
|
-
interval
|
|
314
|
+
t(`pricing.${interval}`),
|
|
312
315
|
),
|
|
313
316
|
),
|
|
314
317
|
),
|
|
@@ -334,7 +337,7 @@ function PricingTable({
|
|
|
334
337
|
style:
|
|
335
338
|
isCurrent || plan.highlight ? { ...styles.card, ...styles.cardCurrent } : styles.card,
|
|
336
339
|
},
|
|
337
|
-
isCurrent && React.createElement("span", { style: styles.badge }, "
|
|
340
|
+
isCurrent && React.createElement("span", { style: styles.badge }, t("pricing.current")),
|
|
338
341
|
!isCurrent &&
|
|
339
342
|
plan.badge &&
|
|
340
343
|
React.createElement("span", { style: styles.badge }, plan.badge),
|
|
@@ -351,21 +354,19 @@ function PricingTable({
|
|
|
351
354
|
React.createElement(
|
|
352
355
|
"span",
|
|
353
356
|
{ style: styles.price },
|
|
354
|
-
annual != null
|
|
355
|
-
? formatPrice(annual, displayCurrency)
|
|
356
|
-
: formatPrice(monthlyAmount, displayCurrency),
|
|
357
|
+
money(annual != null ? annual : monthlyAmount, displayCurrency),
|
|
357
358
|
),
|
|
358
359
|
React.createElement(
|
|
359
360
|
"span",
|
|
360
361
|
{ style: styles.perMonth },
|
|
361
|
-
annual != null ? "
|
|
362
|
+
annual != null ? t("pricing.billedAnnually") : t("pricing.perMonth"),
|
|
362
363
|
),
|
|
363
364
|
),
|
|
364
365
|
plan.trial_days > 0 &&
|
|
365
366
|
React.createElement(
|
|
366
367
|
"div",
|
|
367
368
|
{ style: styles.trial },
|
|
368
|
-
|
|
369
|
+
t("pricing.trial", { days: plan.trial_days }),
|
|
369
370
|
),
|
|
370
371
|
Array.isArray(plan.features) &&
|
|
371
372
|
plan.features.length > 0 &&
|
|
@@ -393,11 +394,11 @@ function PricingTable({
|
|
|
393
394
|
style: isCurrent ? { ...styles.cta, ...styles.ctaCurrent } : styles.cta,
|
|
394
395
|
disabled: isCurrent,
|
|
395
396
|
onClick: () => (onSelect ? onSelect(plan, billingInterval) : undefined),
|
|
396
|
-
"aria-label": isCurrent
|
|
397
|
-
|
|
398
|
-
|
|
397
|
+
"aria-label": t(isCurrent ? "pricing.currentlyOn" : "pricing.choose", {
|
|
398
|
+
plan: plan.name || plan.id,
|
|
399
|
+
}),
|
|
399
400
|
},
|
|
400
|
-
isCurrent ? "
|
|
401
|
+
isCurrent ? t("pricing.currentPlan") : t("pricing.choosePlan"),
|
|
401
402
|
),
|
|
402
403
|
);
|
|
403
404
|
}),
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
|
|
23
23
|
const React = require("react");
|
|
24
24
|
const theme = require("./theme");
|
|
25
|
+
const { useI18n } = require("./i18n");
|
|
25
26
|
|
|
26
27
|
const styles = {
|
|
27
28
|
panel: {
|
|
@@ -51,11 +52,6 @@ const styles = {
|
|
|
51
52
|
negative: { color: "#dc2626" },
|
|
52
53
|
};
|
|
53
54
|
|
|
54
|
-
function dollars(n) {
|
|
55
|
-
if (n == null) return "—";
|
|
56
|
-
return `$${Number(n).toLocaleString(undefined, { maximumFractionDigits: 2 })}`;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
55
|
async function fetchPreview({ baseUrl, customerId, customerToken, planId, planVersion, fetchImpl }) {
|
|
60
56
|
const url = `${String(baseUrl).replace(/\/+$/, "")}/v1/customer-portal/${encodeURIComponent(
|
|
61
57
|
customerId,
|
|
@@ -91,6 +87,7 @@ function SubscriptionPreview({
|
|
|
91
87
|
const [fetched, setFetched] = React.useState(null);
|
|
92
88
|
const [error, setError] = React.useState(null);
|
|
93
89
|
const [loading, setLoading] = React.useState(false);
|
|
90
|
+
const { t, money, date } = useI18n();
|
|
94
91
|
|
|
95
92
|
React.useEffect(() => {
|
|
96
93
|
if (!selfFetch) return undefined;
|
|
@@ -113,7 +110,7 @@ function SubscriptionPreview({
|
|
|
113
110
|
})
|
|
114
111
|
.catch((err) => {
|
|
115
112
|
if (!cancelled) {
|
|
116
|
-
setError(err.message || "
|
|
113
|
+
setError(err.message || t("preview.error"));
|
|
117
114
|
setLoading(false);
|
|
118
115
|
}
|
|
119
116
|
});
|
|
@@ -128,7 +125,7 @@ function SubscriptionPreview({
|
|
|
128
125
|
return React.createElement(
|
|
129
126
|
"div",
|
|
130
127
|
{ style: { opacity: 0.6, fontFamily: styles.panel.fontFamily } },
|
|
131
|
-
"
|
|
128
|
+
t("preview.loading"),
|
|
132
129
|
);
|
|
133
130
|
}
|
|
134
131
|
if (error) {
|
|
@@ -142,7 +139,7 @@ function SubscriptionPreview({
|
|
|
142
139
|
return React.createElement(
|
|
143
140
|
"div",
|
|
144
141
|
{ style: { opacity: 0.6, fontFamily: styles.panel.fontFamily } },
|
|
145
|
-
"
|
|
142
|
+
t("preview.empty"),
|
|
146
143
|
);
|
|
147
144
|
}
|
|
148
145
|
// Render the canonical API shape from
|
|
@@ -162,18 +159,14 @@ function SubscriptionPreview({
|
|
|
162
159
|
React.createElement(
|
|
163
160
|
"div",
|
|
164
161
|
{ style: styles.row },
|
|
165
|
-
React.createElement("span", { style: styles.label }, "
|
|
166
|
-
React.createElement(
|
|
167
|
-
"span",
|
|
168
|
-
{ style: styles.value },
|
|
169
|
-
current.name || current.plan_id,
|
|
170
|
-
),
|
|
162
|
+
React.createElement("span", { style: styles.label }, t("preview.from")),
|
|
163
|
+
React.createElement("span", { style: styles.value }, current.name || current.plan_id),
|
|
171
164
|
),
|
|
172
165
|
target &&
|
|
173
166
|
React.createElement(
|
|
174
167
|
"div",
|
|
175
168
|
{ style: styles.row },
|
|
176
|
-
React.createElement("span", { style: styles.label }, "
|
|
169
|
+
React.createElement("span", { style: styles.label }, t("preview.to")),
|
|
177
170
|
React.createElement("span", { style: styles.value }, target.name || target.plan_id),
|
|
178
171
|
),
|
|
179
172
|
period &&
|
|
@@ -181,25 +174,25 @@ function SubscriptionPreview({
|
|
|
181
174
|
React.createElement(
|
|
182
175
|
"div",
|
|
183
176
|
{ style: styles.row },
|
|
184
|
-
React.createElement("span", { style: styles.label }, "
|
|
185
|
-
React.createElement("span", { style: styles.value }, period.start),
|
|
177
|
+
React.createElement("span", { style: styles.label }, t("preview.effective")),
|
|
178
|
+
React.createElement("span", { style: styles.value }, date(period.start)),
|
|
186
179
|
),
|
|
187
180
|
prevMrr != null &&
|
|
188
181
|
React.createElement(
|
|
189
182
|
"div",
|
|
190
183
|
{ style: styles.row },
|
|
191
|
-
React.createElement("span", { style: styles.label }, "
|
|
192
|
-
React.createElement("span", { style: styles.value },
|
|
184
|
+
React.createElement("span", { style: styles.label }, t("preview.mrrNow")),
|
|
185
|
+
React.createElement("span", { style: styles.value }, money(prevMrr)),
|
|
193
186
|
),
|
|
194
187
|
newMrr != null &&
|
|
195
188
|
React.createElement(
|
|
196
189
|
"div",
|
|
197
190
|
{ style: styles.row },
|
|
198
|
-
React.createElement("span", { style: styles.label }, "
|
|
191
|
+
React.createElement("span", { style: styles.label }, t("preview.mrrAfter")),
|
|
199
192
|
React.createElement(
|
|
200
193
|
"span",
|
|
201
194
|
{ style: styles.value },
|
|
202
|
-
|
|
195
|
+
money(newMrr),
|
|
203
196
|
mrrDelta != null &&
|
|
204
197
|
React.createElement(
|
|
205
198
|
"span",
|
|
@@ -210,7 +203,7 @@ function SubscriptionPreview({
|
|
|
210
203
|
marginLeft: 8,
|
|
211
204
|
},
|
|
212
205
|
},
|
|
213
|
-
`(${mrrDelta >= 0 ? "+" : ""}${
|
|
206
|
+
`(${mrrDelta >= 0 ? "+" : ""}${money(mrrDelta)})`,
|
|
214
207
|
),
|
|
215
208
|
),
|
|
216
209
|
),
|
|
@@ -218,8 +211,8 @@ function SubscriptionPreview({
|
|
|
218
211
|
React.createElement(
|
|
219
212
|
"div",
|
|
220
213
|
{ style: styles.total },
|
|
221
|
-
React.createElement("span", null, "
|
|
222
|
-
React.createElement("span", null,
|
|
214
|
+
React.createElement("span", null, t("preview.dueToday")),
|
|
215
|
+
React.createElement("span", null, money(amountDue)),
|
|
223
216
|
),
|
|
224
217
|
);
|
|
225
218
|
}
|