@meterbox/react 0.1.6 → 0.1.8
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 +18 -0
- package/package.json +1 -1
- package/src/BillingDetailsButton.js +4 -2
- 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 +101 -51
- package/src/SubscriptionPreview.js +17 -24
- package/src/i18n.js +694 -0
- package/src/index.js +7 -0
package/src/PricingTable.js
CHANGED
|
@@ -35,6 +35,13 @@
|
|
|
35
35
|
* each plan's button is its call-to-action link (`customerEmail` fills
|
|
36
36
|
* {CUSTOMER_EMAIL} in it).
|
|
37
37
|
*
|
|
38
|
+
* A plan's list is its `bullets` (the snapshot and the customer portal's plan
|
|
39
|
+
* list: the tenant's own bullets, else its features' labels), else its
|
|
40
|
+
* `display_features`, else its feature ids made readable; its included
|
|
41
|
+
* credits come first ("1,500 Bits a month"). A snapshot plan's `promotion`
|
|
42
|
+
* shows its monthly price with the regular one struck through, and how to
|
|
43
|
+
* get it ("Save 50% with code LAUNCH50 for 3 months").
|
|
44
|
+
*
|
|
38
45
|
* Pure presentational + inline styles — no CSS pipeline required from the
|
|
39
46
|
* tenant.
|
|
40
47
|
*/
|
|
@@ -42,6 +49,7 @@
|
|
|
42
49
|
const React = require("react");
|
|
43
50
|
const theme = require("./theme");
|
|
44
51
|
const { brandingVars } = require("./branding");
|
|
52
|
+
const { useI18n } = require("./i18n");
|
|
45
53
|
|
|
46
54
|
/**
|
|
47
55
|
* Total charged for one year prepaid upfront, or null when the plan
|
|
@@ -114,6 +122,8 @@ const styles = {
|
|
|
114
122
|
cursor: "default",
|
|
115
123
|
},
|
|
116
124
|
trial: { fontSize: 13, fontWeight: 600 },
|
|
125
|
+
wasPrice: { fontSize: 16, opacity: 0.5, marginRight: 6 },
|
|
126
|
+
promo: { fontSize: 12, fontWeight: 600, color: theme.accent },
|
|
117
127
|
usage: {
|
|
118
128
|
display: "grid",
|
|
119
129
|
gap: 4,
|
|
@@ -132,74 +142,103 @@ const styles = {
|
|
|
132
142
|
},
|
|
133
143
|
};
|
|
134
144
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
currency,
|
|
141
|
-
maximumFractionDigits: amount % 1 === 0 ? 0 : 2,
|
|
142
|
-
}).format(amount);
|
|
143
|
-
} catch (_) {
|
|
144
|
-
return `${currency} ${amount}`;
|
|
145
|
-
}
|
|
145
|
+
/** What a plan lists: its bullets, else its own display text, else its feature ids. */
|
|
146
|
+
function planBullets(plan) {
|
|
147
|
+
if (Array.isArray(plan.bullets)) return plan.bullets;
|
|
148
|
+
if (plan.display_features?.length) return plan.display_features;
|
|
149
|
+
return (plan.features || []).map((f) => f.replace(/_/g, " "));
|
|
146
150
|
}
|
|
147
151
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
function compact(n) {
|
|
155
|
-
return new Intl.NumberFormat("en", { notation: "compact" }).format(n);
|
|
152
|
+
/** "1,500 Bits a month", or "$15 of credit a month" without a credit unit. */
|
|
153
|
+
function creditsText({ t, number, money }, c) {
|
|
154
|
+
return c.credit_units != null && c.credit_unit_name
|
|
155
|
+
? t("pricing.credits.units", { n: number(c.credit_units), unit: c.credit_unit_name })
|
|
156
|
+
: t("pricing.credits.usd", { amount: money(c.amount_usd) });
|
|
156
157
|
}
|
|
157
158
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
159
|
+
/** "Save 50% with code LAUNCH50 for 3 months" */
|
|
160
|
+
function promoText({ t, money }, c) {
|
|
161
|
+
const save =
|
|
162
|
+
c.percent_off != null
|
|
163
|
+
? t("pricing.promo.percent", { pct: c.percent_off })
|
|
164
|
+
: t("pricing.promo.amount", { amount: money(c.amount_off_usd) });
|
|
165
|
+
const offer = t("pricing.promo.code", { save, code: c.code });
|
|
166
|
+
if (c.duration === "once") return t("pricing.promo.once", { offer });
|
|
167
|
+
if (c.duration === "repeating" && c.duration_in_months) {
|
|
168
|
+
return t("pricing.promo.months", { offer, count: c.duration_in_months });
|
|
169
|
+
}
|
|
170
|
+
return offer;
|
|
161
171
|
}
|
|
162
172
|
|
|
163
173
|
/** "$3.00 to 10M then $2.50" — a tier ladder priced per 1,000 units × `scale`. */
|
|
164
|
-
function ladderText(tiers, scale) {
|
|
174
|
+
function ladderText({ t, money, number }, tiers, scale) {
|
|
175
|
+
const rate = (perUnit) => {
|
|
176
|
+
const v = Math.round(perUnit * 1e6) / 1e6;
|
|
177
|
+
return money(
|
|
178
|
+
v,
|
|
179
|
+
"USD",
|
|
180
|
+
v > 0 && v < 0.01
|
|
181
|
+
? { minimumSignificantDigits: 2, maximumSignificantDigits: 2 }
|
|
182
|
+
: { minimumFractionDigits: 2, maximumFractionDigits: 2 },
|
|
183
|
+
);
|
|
184
|
+
};
|
|
165
185
|
return tiers
|
|
166
|
-
.map((
|
|
167
|
-
|
|
186
|
+
.map((tier) => {
|
|
187
|
+
const price = rate(tier.per_1k * scale);
|
|
188
|
+
if (tier.up_to == null) return price;
|
|
189
|
+
return t("pricing.upTo", { rate: price, n: number(tier.up_to, { notation: "compact" }) });
|
|
190
|
+
})
|
|
191
|
+
.join(` ${t("pricing.then")} `);
|
|
168
192
|
}
|
|
169
193
|
|
|
170
194
|
/** Included amounts, what happens past them, and the models' rates. */
|
|
171
195
|
function PlanUsage({ usage }) {
|
|
196
|
+
const i18n = useI18n();
|
|
197
|
+
const { t, number } = i18n;
|
|
172
198
|
const { included, overage, models, api_call_overage_tiers: callTiers } = usage;
|
|
173
199
|
const parts = [
|
|
174
|
-
[included.input_tokens, "
|
|
175
|
-
[included.output_tokens, "
|
|
176
|
-
[included.api_calls, "
|
|
200
|
+
[included.input_tokens, "pricing.inputTokens"],
|
|
201
|
+
[included.output_tokens, "pricing.outputTokens"],
|
|
202
|
+
[included.api_calls, "pricing.apiCalls"],
|
|
177
203
|
]
|
|
178
204
|
.filter(([n]) => n > 0)
|
|
179
|
-
.map(([n,
|
|
205
|
+
.map(([n, key]) => t(key, { n: number(n, { notation: "compact" }) }));
|
|
180
206
|
const billed = overage === "billed";
|
|
181
207
|
return React.createElement(
|
|
182
208
|
"div",
|
|
183
209
|
{ className: "meterbox-plan-usage", style: styles.usage },
|
|
184
|
-
parts.length > 0 &&
|
|
210
|
+
parts.length > 0 &&
|
|
211
|
+
React.createElement("div", null, t("pricing.includes", { parts: parts.join(", ") })),
|
|
185
212
|
React.createElement(
|
|
186
213
|
"div",
|
|
187
214
|
{ style: { opacity: 0.75 } },
|
|
188
|
-
billed && parts.length === 0 ? "
|
|
215
|
+
billed && parts.length === 0 ? t("pricing.per1M") : t(`pricing.past.${overage}`, null, ""),
|
|
189
216
|
),
|
|
190
217
|
billed
|
|
191
218
|
? models.map((m) =>
|
|
192
219
|
React.createElement(
|
|
193
220
|
"div",
|
|
194
221
|
{ key: m.id },
|
|
195
|
-
|
|
222
|
+
t("pricing.modelRates", {
|
|
223
|
+
model: m.name,
|
|
224
|
+
input: ladderText(i18n, m.input_tiers, 1000),
|
|
225
|
+
output: ladderText(i18n, m.output_tiers, 1000),
|
|
226
|
+
}),
|
|
196
227
|
),
|
|
197
228
|
)
|
|
198
229
|
: models.length > 0 &&
|
|
199
|
-
React.createElement(
|
|
230
|
+
React.createElement(
|
|
231
|
+
"div",
|
|
232
|
+
null,
|
|
233
|
+
t("pricing.models", { names: models.map((m) => m.name).join(", ") }),
|
|
234
|
+
),
|
|
200
235
|
billed &&
|
|
201
236
|
callTiers &&
|
|
202
|
-
React.createElement(
|
|
237
|
+
React.createElement(
|
|
238
|
+
"div",
|
|
239
|
+
null,
|
|
240
|
+
t("pricing.apiCallRates", { ladder: ladderText(i18n, callTiers, 1) }),
|
|
241
|
+
),
|
|
203
242
|
);
|
|
204
243
|
}
|
|
205
244
|
|
|
@@ -223,6 +262,9 @@ function fromSnapshot(p) {
|
|
|
223
262
|
name: p.name,
|
|
224
263
|
description: p.description || null,
|
|
225
264
|
features: p.features || [],
|
|
265
|
+
bullets: p.bullets || null,
|
|
266
|
+
included_credits: p.included_credits || null,
|
|
267
|
+
promotion: p.promotion || null,
|
|
226
268
|
stripe_price_monthly_usd: p.price ? p.price.monthly_usd : 0,
|
|
227
269
|
annual_free_months: p.annual_free_months == null ? null : p.annual_free_months,
|
|
228
270
|
localized_prices: p.localized_prices || [],
|
|
@@ -258,6 +300,8 @@ function PricingTable({
|
|
|
258
300
|
const selfFetch = !Array.isArray(plans) && !!baseUrl && !!publishableKey;
|
|
259
301
|
const [fetched, setFetched] = React.useState(null);
|
|
260
302
|
const [billingInterval, setBillingInterval] = React.useState("monthly");
|
|
303
|
+
const i18n = useI18n();
|
|
304
|
+
const { t, money } = i18n;
|
|
261
305
|
|
|
262
306
|
React.useEffect(() => {
|
|
263
307
|
if (!selfFetch) return undefined;
|
|
@@ -282,7 +326,7 @@ function PricingTable({
|
|
|
282
326
|
return React.createElement(
|
|
283
327
|
"div",
|
|
284
328
|
{ style: { opacity: 0.6, fontFamily: styles.grid.fontFamily } },
|
|
285
|
-
selfFetch && list == null ? "
|
|
329
|
+
selfFetch && list == null ? t("pricing.loading") : t("pricing.empty"),
|
|
286
330
|
);
|
|
287
331
|
}
|
|
288
332
|
|
|
@@ -308,7 +352,7 @@ function PricingTable({
|
|
|
308
352
|
"aria-pressed": billingInterval === interval,
|
|
309
353
|
onClick: () => setBillingInterval(interval),
|
|
310
354
|
},
|
|
311
|
-
interval
|
|
355
|
+
t(`pricing.${interval}`),
|
|
312
356
|
),
|
|
313
357
|
),
|
|
314
358
|
),
|
|
@@ -327,6 +371,12 @@ function PricingTable({
|
|
|
327
371
|
// toggle above is set to "Annual" for its siblings.
|
|
328
372
|
const annual = billingInterval === "annual" ? annualPriceUsd(plan) : null;
|
|
329
373
|
const link = !onSelect && !isCurrent ? ctaLink(plan, customerEmail) : null;
|
|
374
|
+
// A promotion is on the monthly USD price.
|
|
375
|
+
const promo = annual == null && displayCurrency === "USD" ? plan.promotion : null;
|
|
376
|
+
const bullets = [
|
|
377
|
+
...(plan.included_credits ? [creditsText(i18n, plan.included_credits)] : []),
|
|
378
|
+
...planBullets(plan),
|
|
379
|
+
];
|
|
330
380
|
return React.createElement(
|
|
331
381
|
"div",
|
|
332
382
|
{
|
|
@@ -334,7 +384,7 @@ function PricingTable({
|
|
|
334
384
|
style:
|
|
335
385
|
isCurrent || plan.highlight ? { ...styles.card, ...styles.cardCurrent } : styles.card,
|
|
336
386
|
},
|
|
337
|
-
isCurrent && React.createElement("span", { style: styles.badge }, "
|
|
387
|
+
isCurrent && React.createElement("span", { style: styles.badge }, t("pricing.current")),
|
|
338
388
|
!isCurrent &&
|
|
339
389
|
plan.badge &&
|
|
340
390
|
React.createElement("span", { style: styles.badge }, plan.badge),
|
|
@@ -348,33 +398,33 @@ function PricingTable({
|
|
|
348
398
|
React.createElement(
|
|
349
399
|
"div",
|
|
350
400
|
null,
|
|
401
|
+
promo && React.createElement("s", { style: styles.wasPrice }, money(monthlyAmount)),
|
|
351
402
|
React.createElement(
|
|
352
403
|
"span",
|
|
353
404
|
{ style: styles.price },
|
|
354
|
-
|
|
355
|
-
?
|
|
356
|
-
|
|
405
|
+
money(
|
|
406
|
+
promo ? promo.monthly_usd : annual != null ? annual : monthlyAmount,
|
|
407
|
+
displayCurrency,
|
|
408
|
+
),
|
|
357
409
|
),
|
|
358
410
|
React.createElement(
|
|
359
411
|
"span",
|
|
360
412
|
{ style: styles.perMonth },
|
|
361
|
-
annual != null ? "
|
|
413
|
+
annual != null ? t("pricing.billedAnnually") : t("pricing.perMonth"),
|
|
362
414
|
),
|
|
363
415
|
),
|
|
416
|
+
promo && React.createElement("div", { style: styles.promo }, promoText(i18n, promo)),
|
|
364
417
|
plan.trial_days > 0 &&
|
|
365
418
|
React.createElement(
|
|
366
419
|
"div",
|
|
367
420
|
{ style: styles.trial },
|
|
368
|
-
|
|
421
|
+
t("pricing.trial", { days: plan.trial_days }),
|
|
369
422
|
),
|
|
370
|
-
|
|
371
|
-
plan.features.length > 0 &&
|
|
423
|
+
bullets.length > 0 &&
|
|
372
424
|
React.createElement(
|
|
373
425
|
"ul",
|
|
374
426
|
{ style: styles.features },
|
|
375
|
-
|
|
376
|
-
React.createElement("li", { key: f }, `• ${f.replace(/_/g, " ")}`),
|
|
377
|
-
),
|
|
427
|
+
bullets.map((b, i) => React.createElement("li", { key: `${i}:${b}` }, `• ${b}`)),
|
|
378
428
|
),
|
|
379
429
|
plan.usage && React.createElement(PlanUsage, { usage: plan.usage }),
|
|
380
430
|
link
|
|
@@ -393,11 +443,11 @@ function PricingTable({
|
|
|
393
443
|
style: isCurrent ? { ...styles.cta, ...styles.ctaCurrent } : styles.cta,
|
|
394
444
|
disabled: isCurrent,
|
|
395
445
|
onClick: () => (onSelect ? onSelect(plan, billingInterval) : undefined),
|
|
396
|
-
"aria-label": isCurrent
|
|
397
|
-
|
|
398
|
-
|
|
446
|
+
"aria-label": t(isCurrent ? "pricing.currentlyOn" : "pricing.choose", {
|
|
447
|
+
plan: plan.name || plan.id,
|
|
448
|
+
}),
|
|
399
449
|
},
|
|
400
|
-
isCurrent ? "
|
|
450
|
+
isCurrent ? t("pricing.currentPlan") : t("pricing.choosePlan"),
|
|
401
451
|
),
|
|
402
452
|
);
|
|
403
453
|
}),
|
|
@@ -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
|
}
|