@streamoid/settings 0.21.0 → 0.22.1
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 +8 -0
- package/dist/index.d.mts +151 -12
- package/dist/index.d.ts +151 -12
- package/dist/index.js +353 -42
- package/dist/index.mjs +353 -42
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -7950,6 +7950,17 @@ function findBillingError(failure, codes) {
|
|
|
7950
7950
|
return visit(failure, 0);
|
|
7951
7951
|
}
|
|
7952
7952
|
|
|
7953
|
+
// src/invoice-download.ts
|
|
7954
|
+
function invoiceDownloadKind(item) {
|
|
7955
|
+
const id = item.transactionId;
|
|
7956
|
+
if (!id) return null;
|
|
7957
|
+
if (id.startsWith("in_")) return "invoice";
|
|
7958
|
+
if (id.startsWith("pi_")) return "receipt";
|
|
7959
|
+
return null;
|
|
7960
|
+
}
|
|
7961
|
+
var INVOICE_NOT_AVAILABLE_MESSAGE = "There's no invoice for this order. Rolled-over, bonus and manually added credits don't have one.";
|
|
7962
|
+
var INVOICE_DOWNLOAD_FAILED_MESSAGE = "Couldn't download this invoice.";
|
|
7963
|
+
|
|
7953
7964
|
// src/billing-content.tsx
|
|
7954
7965
|
import {
|
|
7955
7966
|
useState as useState22,
|
|
@@ -10058,6 +10069,32 @@ function validatePoolText(raw, max) {
|
|
|
10058
10069
|
if (value.length > max) return { ok: false, reason: `At most ${max} characters` };
|
|
10059
10070
|
return { ok: true, value };
|
|
10060
10071
|
}
|
|
10072
|
+
var round2 = (value) => Math.round(value * 100) / 100;
|
|
10073
|
+
function poolAllocatedPercent(pool, exclude) {
|
|
10074
|
+
if (!pool) return 0;
|
|
10075
|
+
if (exclude === void 0 && typeof pool.allocatedPercent === "number") return round2(pool.allocatedPercent);
|
|
10076
|
+
let total = 0;
|
|
10077
|
+
if (exclude !== "self" && pool.self?.mode === "percent") total += pool.self.value;
|
|
10078
|
+
for (const member of pool.members ?? []) {
|
|
10079
|
+
if (member._id !== exclude && member.mode === "percent") total += member.value;
|
|
10080
|
+
}
|
|
10081
|
+
return round2(total);
|
|
10082
|
+
}
|
|
10083
|
+
function poolUnallocatedPercent(pool, exclude) {
|
|
10084
|
+
return Math.max(0, round2(100 - poolAllocatedPercent(pool, exclude)));
|
|
10085
|
+
}
|
|
10086
|
+
function checkPoolPercentTotal(split, unallocatedPercent) {
|
|
10087
|
+
if (split.mode !== "percent" || round2(split.value) <= round2(unallocatedPercent)) return { ok: true };
|
|
10088
|
+
const left = formatCredits(Math.max(0, unallocatedPercent));
|
|
10089
|
+
return {
|
|
10090
|
+
ok: false,
|
|
10091
|
+
reason: unallocatedPercent > 0 ? `Only ${left}% is unallocated. Percentage shares, this workspace's included, can total at most 100%.` : "All 100% is allocated. Lower another percentage share first, or share fixed credits."
|
|
10092
|
+
};
|
|
10093
|
+
}
|
|
10094
|
+
function poolAllocationText(pool) {
|
|
10095
|
+
const allocated = poolAllocatedPercent(pool);
|
|
10096
|
+
return `Allocated ${formatCredits(allocated)}% \xB7 Unallocated ${formatCredits(Math.max(0, round2(100 - allocated)))}%`;
|
|
10097
|
+
}
|
|
10061
10098
|
var credits = (value) => `${formatCredits(value)} ${value === 1 ? "credit" : "credits"}`;
|
|
10062
10099
|
function formatPoolSplit(split) {
|
|
10063
10100
|
if (split.mode === "percent") return `${formatCredits(split.value)}%`;
|
|
@@ -10144,6 +10181,16 @@ function sharedPoolBannerText(pool) {
|
|
|
10144
10181
|
const sponsor = pool.sponsorName?.trim() || "another workspace";
|
|
10145
10182
|
return `Credits shared by ${sponsor}: ${formatCredits(pool.remaining)} of ${formatCredits(pool.allowance)} left this cycle`;
|
|
10146
10183
|
}
|
|
10184
|
+
function sponsorShareSpentText() {
|
|
10185
|
+
return "This workspace has used its share of the credits for this cycle.";
|
|
10186
|
+
}
|
|
10187
|
+
function sponsorShareBannerText(share) {
|
|
10188
|
+
if (share.remaining <= 0) return sponsorShareSpentText();
|
|
10189
|
+
return `This workspace's share: ${formatCredits(share.remaining)} of ${credits(share.allowance)} left this cycle`;
|
|
10190
|
+
}
|
|
10191
|
+
function sponsorShareDetailText() {
|
|
10192
|
+
return "The rest of this workspace's credits are kept for the workspaces it shares them with. Organization admins change this in Shared credits.";
|
|
10193
|
+
}
|
|
10147
10194
|
function pausedOwnCreditsText(_pool) {
|
|
10148
10195
|
return ownCreditsFirstText();
|
|
10149
10196
|
}
|
|
@@ -10153,8 +10200,16 @@ function ownCreditsFirstText() {
|
|
|
10153
10200
|
function creditsMeter({
|
|
10154
10201
|
availableCredits,
|
|
10155
10202
|
totalCredits,
|
|
10156
|
-
sharedPool
|
|
10203
|
+
sharedPool,
|
|
10204
|
+
sponsorShare = null
|
|
10157
10205
|
}) {
|
|
10206
|
+
if (sponsorShare && !sharedPool) {
|
|
10207
|
+
const used2 = Math.max(0, sponsorShare.used);
|
|
10208
|
+
const left = Math.max(0, sponsorShare.remaining);
|
|
10209
|
+
const remaining = availableCredits != null ? Math.min(left, Math.max(0, availableCredits)) : left;
|
|
10210
|
+
const progressPct2 = sponsorShare.allowance > 0 ? Math.min(100, Math.round(used2 / sponsorShare.allowance * 100)) : 100;
|
|
10211
|
+
return { used: used2, remaining, progressPct: progressPct2, remainingPct: 100 - progressPct2 };
|
|
10212
|
+
}
|
|
10158
10213
|
if (sharedPool && availableCredits != null && totalCredits != null) {
|
|
10159
10214
|
const total = Math.max(0, totalCredits) + Math.max(0, sharedPool.allowance);
|
|
10160
10215
|
const used2 = Math.max(0, total - availableCredits);
|
|
@@ -10365,18 +10420,31 @@ var EXPIRY_OPTIONS = [
|
|
|
10365
10420
|
];
|
|
10366
10421
|
var isExpiryKind = (id) => EXPIRY_OPTIONS.some((o) => o.id === id);
|
|
10367
10422
|
var endsText = (member) => member.endsAt ? `, until ${formatPoolEndsAt(member.endsAt)}` : "";
|
|
10368
|
-
function endsAtHelp(kind, endsAt) {
|
|
10369
|
-
if (kind === "never")
|
|
10423
|
+
function endsAtHelp(kind, endsAt, self) {
|
|
10424
|
+
if (kind === "never") {
|
|
10425
|
+
return self ? "Applies every billing cycle until it is removed." : "Shares every billing cycle until it is removed.";
|
|
10426
|
+
}
|
|
10427
|
+
if (self) {
|
|
10428
|
+
const stop2 = "After that, this workspace may spend all its credits again.";
|
|
10429
|
+
return endsAt ? `The share ends on ${formatPoolEndsAt(endsAt)}. ${stop2}` : stop2;
|
|
10430
|
+
}
|
|
10370
10431
|
const stop = "After that, the other workspace spends only its own credits.";
|
|
10371
10432
|
return endsAt ? `Sharing stops on ${formatPoolEndsAt(endsAt)}. ${stop}` : stop;
|
|
10372
10433
|
}
|
|
10434
|
+
function valueHelp(kind, mode) {
|
|
10435
|
+
if (kind === "self") {
|
|
10436
|
+
return mode === "percent" ? "The most this workspace may spend of its own plan credits each billing cycle. It counts toward the same 100% as the shares other workspaces get." : "The most credits this workspace may spend itself each billing cycle. Fixed credits don't count toward the 100%.";
|
|
10437
|
+
}
|
|
10438
|
+
return mode === "percent" ? "A share of this workspace's plan credits for each billing cycle. Credits stay with this workspace; the other workspace spends them up to this share, after its own credits." : "Credits the other workspace may spend each billing cycle, after its own credits. Credits stay with this workspace until spent.";
|
|
10439
|
+
}
|
|
10373
10440
|
function CreditPoolMemberModal(props) {
|
|
10374
10441
|
const { toast } = useSettingsAdapters();
|
|
10375
|
-
const editing = props.kind === "edit" ? props.member : null;
|
|
10442
|
+
const editing = props.kind === "edit" ? props.member : props.kind === "self" ? props.self : null;
|
|
10443
|
+
const initialNote = props.kind === "self" ? props.self?.note ?? "" : "";
|
|
10376
10444
|
const [memberId, setMemberId] = useState19("");
|
|
10377
10445
|
const [mode, setMode] = useState19(editing?.mode ?? "percent");
|
|
10378
10446
|
const [raw, setRaw] = useState19(editing ? String(editing.value) : "");
|
|
10379
|
-
const [note, setNote] = useState19(
|
|
10447
|
+
const [note, setNote] = useState19(initialNote);
|
|
10380
10448
|
const [touched, setTouched] = useState19(false);
|
|
10381
10449
|
const [saving, setSaving] = useState19(false);
|
|
10382
10450
|
const [serverError, setServerError] = useState19(null);
|
|
@@ -10393,10 +10461,13 @@ function CreditPoolMemberModal(props) {
|
|
|
10393
10461
|
const endsAtUnchanged = Boolean(editing) && expiry.kind === initialExpiry.kind && (expiry.kind !== "date" || initialExpiry.kind === "date" && expiry.date === initialExpiry.date);
|
|
10394
10462
|
const endsAt = endsAtUnchanged ? null : poolEndsAtFrom(expiry);
|
|
10395
10463
|
const splitChanged = !editing || mode !== editing.mode || !value.ok || value.value !== editing.value;
|
|
10396
|
-
const
|
|
10397
|
-
const
|
|
10464
|
+
const noteChanged = props.kind === "self" && note.trim() !== initialNote.trim();
|
|
10465
|
+
const changed = splitChanged || !endsAtUnchanged || noteChanged;
|
|
10466
|
+
const percentTotal = value.ok && props.unallocatedPercent !== void 0 ? checkPoolPercentTotal({ mode, value: value.value }, props.unallocatedPercent) : null;
|
|
10467
|
+
const valid = value.ok && (percentTotal === null || percentTotal.ok) && (endsAt === null || endsAt.ok) && (props.kind === "edit" || (props.kind === "self" || Boolean(memberId)) && noteCheck.ok);
|
|
10398
10468
|
const canSave = !saving && changed && valid;
|
|
10399
|
-
const valueHint = touched && !value.ok ? value.reason : null;
|
|
10469
|
+
const valueHint = touched && !value.ok ? value.reason : percentTotal && !percentTotal.ok ? percentTotal.reason : null;
|
|
10470
|
+
const unallocatedHint = mode === "percent" && props.unallocatedPercent !== void 0 ? ` ${formatCredits(Math.max(0, props.unallocatedPercent))}% is unallocated.` : "";
|
|
10400
10471
|
const expiryHint = endsAt && !endsAt.ok && !(expiry.kind === "date" && !expiry.date) ? endsAt.reason : null;
|
|
10401
10472
|
const handleSave = async () => {
|
|
10402
10473
|
if (!canSave || !value.ok) return;
|
|
@@ -10413,6 +10484,17 @@ function CreditPoolMemberModal(props) {
|
|
|
10413
10484
|
...sendEndsAt?.value ? { endsAt: sendEndsAt.value } : {}
|
|
10414
10485
|
});
|
|
10415
10486
|
toast.success(`Credits shared. ${describeAllowance(added)}${endsText(added)}.`);
|
|
10487
|
+
} else if (props.kind === "self") {
|
|
10488
|
+
const nextEndsAt = sendEndsAt ? sendEndsAt.value : props.self?.endsAt ?? null;
|
|
10489
|
+
await props.onSave({
|
|
10490
|
+
mode,
|
|
10491
|
+
value: value.value,
|
|
10492
|
+
note: noteCheck.ok ? noteCheck.value : "",
|
|
10493
|
+
endsAt: nextEndsAt
|
|
10494
|
+
});
|
|
10495
|
+
toast.success(
|
|
10496
|
+
`This workspace's share is ${formatPoolSplit({ mode, value: value.value })} each billing cycle${endsText({ endsAt: nextEndsAt })}.`
|
|
10497
|
+
);
|
|
10416
10498
|
} else {
|
|
10417
10499
|
const updated = await props.onSave({
|
|
10418
10500
|
mode,
|
|
@@ -10426,7 +10508,10 @@ function CreditPoolMemberModal(props) {
|
|
|
10426
10508
|
} catch (err) {
|
|
10427
10509
|
const message = poolErrorMessage(err);
|
|
10428
10510
|
if (message) setServerError(message);
|
|
10429
|
-
else
|
|
10511
|
+
else {
|
|
10512
|
+
const method = props.kind === "add" ? "POST" : props.kind === "self" ? "PUT" : "PATCH";
|
|
10513
|
+
toast.error(errorMessage(err, { method }));
|
|
10514
|
+
}
|
|
10430
10515
|
setSaving(false);
|
|
10431
10516
|
}
|
|
10432
10517
|
};
|
|
@@ -10434,7 +10519,7 @@ function CreditPoolMemberModal(props) {
|
|
|
10434
10519
|
return /* @__PURE__ */ jsxs24(
|
|
10435
10520
|
PoolModalShell,
|
|
10436
10521
|
{
|
|
10437
|
-
title: props.kind === "add" ? "Share credits" : "Edit shared credits",
|
|
10522
|
+
title: props.kind === "add" ? "Share credits" : props.kind === "edit" ? "Edit shared credits" : props.self ? "Edit this workspace's share" : "Set this workspace's share",
|
|
10438
10523
|
busy: saving,
|
|
10439
10524
|
onClose: props.onClose,
|
|
10440
10525
|
footer: /* @__PURE__ */ jsxs24(Fragment10, { children: [
|
|
@@ -10461,7 +10546,7 @@ function CreditPoolMemberModal(props) {
|
|
|
10461
10546
|
] }),
|
|
10462
10547
|
children: [
|
|
10463
10548
|
/* @__PURE__ */ jsxs24("div", { className: "flex flex-col w-full", style: { gap: T17.spXs }, children: [
|
|
10464
|
-
/* @__PURE__ */ jsx27("span", { style: fieldLabel, children: "Share with" }),
|
|
10549
|
+
/* @__PURE__ */ jsx27("span", { style: fieldLabel, children: props.kind === "self" ? "Workspace" : "Share with" }),
|
|
10465
10550
|
props.kind === "add" ? candidateOptions.length ? /* @__PURE__ */ jsx27(
|
|
10466
10551
|
ScSelect,
|
|
10467
10552
|
{
|
|
@@ -10471,7 +10556,7 @@ function CreditPoolMemberModal(props) {
|
|
|
10471
10556
|
placeholder: "Choose a workspace",
|
|
10472
10557
|
disabled: saving
|
|
10473
10558
|
}
|
|
10474
|
-
) : /* @__PURE__ */ jsx27("span", { style: { ...modalBodyText, color: T17.muted }, children: "There are no other workspaces in this organization to share credits with." }) : /* @__PURE__ */ jsx27("span", { style: { ...modalBodyText, color: T17.primary }, children: props.memberName })
|
|
10559
|
+
) : /* @__PURE__ */ jsx27("span", { style: { ...modalBodyText, color: T17.muted }, children: "There are no other workspaces in this organization to share credits with." }) : /* @__PURE__ */ jsx27("span", { style: { ...modalBodyText, color: T17.primary }, children: props.kind === "self" ? props.workspaceName : props.memberName })
|
|
10475
10560
|
] }),
|
|
10476
10561
|
/* @__PURE__ */ jsxs24("div", { className: "flex flex-col w-full", style: { gap: T17.spMd }, children: [
|
|
10477
10562
|
/* @__PURE__ */ jsx27("span", { style: fieldLabel, children: "How much, each billing cycle" }),
|
|
@@ -10530,7 +10615,8 @@ function CreditPoolMemberModal(props) {
|
|
|
10530
10615
|
}
|
|
10531
10616
|
),
|
|
10532
10617
|
valueHint ? /* @__PURE__ */ jsx27("span", { role: "alert", style: { ...modalBodyText, color: T17.error }, children: valueHint }) : /* @__PURE__ */ jsxs24("span", { style: { ...modalBodyText, color: T17.tertiary }, children: [
|
|
10533
|
-
|
|
10618
|
+
valueHelp(props.kind, mode),
|
|
10619
|
+
unallocatedHint,
|
|
10534
10620
|
editing ? " Applies immediately." : ""
|
|
10535
10621
|
] })
|
|
10536
10622
|
] }),
|
|
@@ -10598,16 +10684,20 @@ function CreditPoolMemberModal(props) {
|
|
|
10598
10684
|
)
|
|
10599
10685
|
}
|
|
10600
10686
|
),
|
|
10601
|
-
expiryHint ? /* @__PURE__ */ jsx27("span", { role: "alert", style: { ...modalBodyText, color: T17.error }, children: expiryHint }) : /* @__PURE__ */ jsx27("span", { style: { ...modalBodyText, color: T17.tertiary }, children: endsAtHelp(
|
|
10687
|
+
expiryHint ? /* @__PURE__ */ jsx27("span", { role: "alert", style: { ...modalBodyText, color: T17.error }, children: expiryHint }) : /* @__PURE__ */ jsx27("span", { style: { ...modalBodyText, color: T17.tertiary }, children: endsAtHelp(
|
|
10688
|
+
expiryKind,
|
|
10689
|
+
endsAtUnchanged ? editing?.endsAt ?? null : endsAt?.ok ? endsAt.value : null,
|
|
10690
|
+
props.kind === "self"
|
|
10691
|
+
) })
|
|
10602
10692
|
] }),
|
|
10603
|
-
props.kind
|
|
10693
|
+
props.kind !== "edit" && /* @__PURE__ */ jsxs24("div", { className: "flex flex-col w-full", style: { gap: T17.spXs }, children: [
|
|
10604
10694
|
/* @__PURE__ */ jsx27("span", { style: fieldLabel, children: "Note" }),
|
|
10605
10695
|
/* @__PURE__ */ jsx27(
|
|
10606
10696
|
ScTextArea,
|
|
10607
10697
|
{
|
|
10608
10698
|
value: note,
|
|
10609
10699
|
maxLength: POOL_NOTE_MAX_LENGTH,
|
|
10610
|
-
placeholder: "Why are these credits being shared?",
|
|
10700
|
+
placeholder: props.kind === "self" ? "Why does this workspace keep only this share?" : "Why are these credits being shared?",
|
|
10611
10701
|
disabled: saving,
|
|
10612
10702
|
onChange: (e) => setNote(e.target.value),
|
|
10613
10703
|
rows: 3,
|
|
@@ -10720,6 +10810,73 @@ function RemovePoolMemberModal({
|
|
|
10720
10810
|
}
|
|
10721
10811
|
);
|
|
10722
10812
|
}
|
|
10813
|
+
function RemoveSelfShareModal({
|
|
10814
|
+
self,
|
|
10815
|
+
workspaceName,
|
|
10816
|
+
onRemove,
|
|
10817
|
+
onClose,
|
|
10818
|
+
onRemoved
|
|
10819
|
+
}) {
|
|
10820
|
+
const { toast } = useSettingsAdapters();
|
|
10821
|
+
const [saving, setSaving] = useState20(false);
|
|
10822
|
+
const handleConfirm = async () => {
|
|
10823
|
+
if (saving) return;
|
|
10824
|
+
setSaving(true);
|
|
10825
|
+
try {
|
|
10826
|
+
await onRemove();
|
|
10827
|
+
toast.success(`${workspaceName} can spend all its credits again`);
|
|
10828
|
+
onRemoved();
|
|
10829
|
+
onClose();
|
|
10830
|
+
} catch (err) {
|
|
10831
|
+
toast.error(errorMessage(err, { method: "DELETE" }));
|
|
10832
|
+
setSaving(false);
|
|
10833
|
+
}
|
|
10834
|
+
};
|
|
10835
|
+
return /* @__PURE__ */ jsxs25(
|
|
10836
|
+
PoolModalShell,
|
|
10837
|
+
{
|
|
10838
|
+
title: "Remove this workspace's share",
|
|
10839
|
+
busy: saving,
|
|
10840
|
+
onClose,
|
|
10841
|
+
footer: /* @__PURE__ */ jsxs25(Fragment11, { children: [
|
|
10842
|
+
/* @__PURE__ */ jsx28(
|
|
10843
|
+
ScButton13,
|
|
10844
|
+
{
|
|
10845
|
+
text: "Keep share",
|
|
10846
|
+
variant: "secondary",
|
|
10847
|
+
size: "md",
|
|
10848
|
+
state: saving ? "disabled" : "default",
|
|
10849
|
+
onClick: saving ? void 0 : onClose
|
|
10850
|
+
}
|
|
10851
|
+
),
|
|
10852
|
+
/* @__PURE__ */ jsx28(
|
|
10853
|
+
ScButton13,
|
|
10854
|
+
{
|
|
10855
|
+
text: "Remove share",
|
|
10856
|
+
variant: "error",
|
|
10857
|
+
size: "md",
|
|
10858
|
+
state: saving ? "disabled" : "default",
|
|
10859
|
+
onClick: saving ? void 0 : () => void handleConfirm()
|
|
10860
|
+
}
|
|
10861
|
+
)
|
|
10862
|
+
] }),
|
|
10863
|
+
children: [
|
|
10864
|
+
/* @__PURE__ */ jsxs25("span", { style: { ...modalBodyText, color: MODAL_T.primary }, children: [
|
|
10865
|
+
workspaceName,
|
|
10866
|
+
" may spend its whole balance again, starting now."
|
|
10867
|
+
] }),
|
|
10868
|
+
/* @__PURE__ */ jsxs25("span", { style: { ...modalBodyText, color: MODAL_T.tertiary }, children: [
|
|
10869
|
+
"It kept ",
|
|
10870
|
+
describeAllowance(self),
|
|
10871
|
+
" and has used ",
|
|
10872
|
+
formatCredits(self.used),
|
|
10873
|
+
".",
|
|
10874
|
+
self.mode === "percent" ? ` Its ${formatPoolSplit(self)} goes back to unallocated, so other workspaces can be given more.` : ""
|
|
10875
|
+
] })
|
|
10876
|
+
]
|
|
10877
|
+
}
|
|
10878
|
+
);
|
|
10879
|
+
}
|
|
10723
10880
|
|
|
10724
10881
|
// src/shared-credits-view.tsx
|
|
10725
10882
|
import { jsx as jsx29, jsxs as jsxs26 } from "react/jsx-runtime";
|
|
@@ -10802,10 +10959,49 @@ function MemberRow2({
|
|
|
10802
10959
|
}
|
|
10803
10960
|
);
|
|
10804
10961
|
}
|
|
10962
|
+
function SelfShareRow({
|
|
10963
|
+
self,
|
|
10964
|
+
onSet,
|
|
10965
|
+
onRemove
|
|
10966
|
+
}) {
|
|
10967
|
+
const spent = Boolean(self) && self.remaining <= 0;
|
|
10968
|
+
return /* @__PURE__ */ jsxs26(
|
|
10969
|
+
"div",
|
|
10970
|
+
{
|
|
10971
|
+
style: {
|
|
10972
|
+
borderBottom: `1px solid ${T18.borderSubtle}`,
|
|
10973
|
+
display: "grid",
|
|
10974
|
+
gridTemplateColumns: MEMBER_COLUMNS2,
|
|
10975
|
+
alignItems: "center",
|
|
10976
|
+
padding: `10px ${T18.sp3xl}`,
|
|
10977
|
+
gap: MEMBER_GAP,
|
|
10978
|
+
backgroundColor: T18.fillPlus
|
|
10979
|
+
},
|
|
10980
|
+
children: [
|
|
10981
|
+
/* @__PURE__ */ jsxs26("div", { className: "flex flex-col min-w-0", style: { gap: 2 }, children: [
|
|
10982
|
+
/* @__PURE__ */ jsx29("span", { className: "truncate", style: { ...cellText3, fontWeight: 500 }, children: "This workspace" }),
|
|
10983
|
+
self?.note && /* @__PURE__ */ jsx29("span", { className: "truncate", title: self.note, style: { ...cellText3, color: T18.tertiary }, children: self.note })
|
|
10984
|
+
] }),
|
|
10985
|
+
self ? /* @__PURE__ */ jsxs26("div", { className: "flex flex-col min-w-0", style: { gap: 2 }, children: [
|
|
10986
|
+
/* @__PURE__ */ jsx29("span", { style: cellText3, children: formatPoolSplit({ mode: "fixed", value: self.allowance }) }),
|
|
10987
|
+
/* @__PURE__ */ jsx29("span", { style: { ...cellText3, color: T18.tertiary }, children: self.mode === "percent" ? `${formatPoolSplit(self)} \xB7 this cycle` : "this cycle" })
|
|
10988
|
+
] }) : /* @__PURE__ */ jsx29("span", { style: { ...cellText3, color: T18.muted }, children: "All its credits" }),
|
|
10989
|
+
/* @__PURE__ */ jsx29("span", { style: { ...cellText3, color: self ? T18.primary : T18.muted }, children: self ? formatCredits(self.used) : "\u2014" }),
|
|
10990
|
+
/* @__PURE__ */ jsx29("span", { style: { ...cellText3, color: !self ? T18.muted : spent ? T18.warning : T18.primary }, children: self ? formatCredits(self.remaining) : "\u2014" }),
|
|
10991
|
+
/* @__PURE__ */ jsx29("span", { style: { ...cellText3, color: self?.endsAt ? T18.primary : T18.muted }, children: self ? formatPoolEndsAt(self.endsAt) : "\u2014" }),
|
|
10992
|
+
/* @__PURE__ */ jsxs26("div", { className: "flex items-center whitespace-nowrap", style: { gap: 8 }, children: [
|
|
10993
|
+
onSet && /* @__PURE__ */ jsx29(ScButton14, { text: self ? "Edit" : "Set share", variant: "secondary", size: "sm", onClick: onSet }),
|
|
10994
|
+
self && onRemove && /* @__PURE__ */ jsx29(ScButton14, { text: "Remove", variant: "secondary", size: "sm", onClick: onRemove })
|
|
10995
|
+
] })
|
|
10996
|
+
]
|
|
10997
|
+
}
|
|
10998
|
+
);
|
|
10999
|
+
}
|
|
10805
11000
|
function SharedCreditsView() {
|
|
10806
11001
|
const { api, workspace, toast } = useSettingsAdapters();
|
|
10807
11002
|
const workspaceId = workspace.current?.id ?? null;
|
|
10808
11003
|
const workspaceName = workspace.current?.name?.trim() || "this workspace";
|
|
11004
|
+
const selfName = workspace.current?.name?.trim() || "This workspace";
|
|
10809
11005
|
const [data, setData] = useState21(null);
|
|
10810
11006
|
const [loading, setLoading] = useState21(true);
|
|
10811
11007
|
const [failed, setFailed] = useState21(false);
|
|
@@ -10813,6 +11009,8 @@ function SharedCreditsView() {
|
|
|
10813
11009
|
const [adding, setAdding] = useState21(false);
|
|
10814
11010
|
const [editing, setEditing] = useState21(null);
|
|
10815
11011
|
const [removing, setRemoving] = useState21(null);
|
|
11012
|
+
const [settingSelf, setSettingSelf] = useState21(false);
|
|
11013
|
+
const [removingSelf, setRemovingSelf] = useState21(false);
|
|
10816
11014
|
const latestLoad = useRef11(0);
|
|
10817
11015
|
const load = useCallback8(
|
|
10818
11016
|
async ({ refresh = false } = {}) => {
|
|
@@ -10841,6 +11039,8 @@ function SharedCreditsView() {
|
|
|
10841
11039
|
setAdding(false);
|
|
10842
11040
|
setEditing(null);
|
|
10843
11041
|
setRemoving(null);
|
|
11042
|
+
setSettingSelf(false);
|
|
11043
|
+
setRemovingSelf(false);
|
|
10844
11044
|
void load();
|
|
10845
11045
|
}, [workspaceId]);
|
|
10846
11046
|
useEffect18(
|
|
@@ -10888,6 +11088,8 @@ function SharedCreditsView() {
|
|
|
10888
11088
|
);
|
|
10889
11089
|
}
|
|
10890
11090
|
const members = data?.members ?? [];
|
|
11091
|
+
const self = data?.self ?? null;
|
|
11092
|
+
const showSelf = !failed && Boolean(data) && (Boolean(api.setCreditPoolSelfShare) || Boolean(self));
|
|
10891
11093
|
return /* @__PURE__ */ jsxs26("div", { className: "flex flex-col flex-1 min-h-0 w-full overflow-y-auto", style: { gap: 16 }, children: [
|
|
10892
11094
|
/* @__PURE__ */ jsxs26("div", { className: "flex items-start justify-between shrink-0 w-full", style: { gap: 12 }, children: [
|
|
10893
11095
|
/* @__PURE__ */ jsxs26("div", { className: "flex flex-col min-w-0", style: { gap: 4 }, children: [
|
|
@@ -10932,25 +11134,46 @@ function SharedCreditsView() {
|
|
|
10932
11134
|
}
|
|
10933
11135
|
),
|
|
10934
11136
|
!sponsor && /* @__PURE__ */ jsxs26("div", { className: "flex flex-col shrink-0 w-full", style: { gap: 8 }, children: [
|
|
10935
|
-
/* @__PURE__ */
|
|
10936
|
-
|
|
11137
|
+
/* @__PURE__ */ jsxs26("div", { className: "flex items-baseline justify-between w-full", style: { gap: 12 }, children: [
|
|
11138
|
+
/* @__PURE__ */ jsx29("span", { style: { ...cellText3, fontWeight: 500 }, children: "Shared with" }),
|
|
11139
|
+
!failed && data && /* @__PURE__ */ jsx29(
|
|
11140
|
+
"span",
|
|
11141
|
+
{
|
|
11142
|
+
style: { ...cellText3, color: T18.muted },
|
|
11143
|
+
title: "Percentage shares, this workspace's included, total at most 100%. Fixed-credit shares aren't counted.",
|
|
11144
|
+
children: poolAllocationText(data)
|
|
11145
|
+
}
|
|
11146
|
+
)
|
|
11147
|
+
] }),
|
|
11148
|
+
/* @__PURE__ */ jsxs26(
|
|
10937
11149
|
MemberListFrame,
|
|
10938
11150
|
{
|
|
10939
11151
|
grow: "cap",
|
|
10940
11152
|
maxHeight: 420,
|
|
10941
11153
|
contentMinWidth: MEMBER_MIN_WIDTH,
|
|
10942
11154
|
header: tableHeader(MEMBER_COLUMNS2, ["Workspace", "Allowance", "Used", "Remaining", "Ends", "Actions"]),
|
|
10943
|
-
isEmpty: failed || members.length === 0,
|
|
11155
|
+
isEmpty: failed || members.length === 0 && !showSelf,
|
|
10944
11156
|
emptyText: failed ? "Couldn't load shared credits. Try again later." : "This workspace doesn't share its credits with any other workspace.",
|
|
10945
|
-
children:
|
|
10946
|
-
|
|
10947
|
-
|
|
10948
|
-
|
|
10949
|
-
|
|
10950
|
-
|
|
10951
|
-
|
|
10952
|
-
|
|
10953
|
-
|
|
11157
|
+
children: [
|
|
11158
|
+
showSelf && /* @__PURE__ */ jsx29(
|
|
11159
|
+
SelfShareRow,
|
|
11160
|
+
{
|
|
11161
|
+
self,
|
|
11162
|
+
onSet: canManage && api.setCreditPoolSelfShare ? () => setSettingSelf(true) : void 0,
|
|
11163
|
+
onRemove: canManage && api.removeCreditPoolSelfShare ? () => setRemovingSelf(true) : void 0
|
|
11164
|
+
}
|
|
11165
|
+
),
|
|
11166
|
+
showSelf && members.length === 0 && /* @__PURE__ */ jsx29("div", { style: { ...cellText3, color: T18.muted, padding: `12px ${T18.sp3xl}` }, children: "This workspace doesn't share its credits with any other workspace." }),
|
|
11167
|
+
members.map((member) => /* @__PURE__ */ jsx29(
|
|
11168
|
+
MemberRow2,
|
|
11169
|
+
{
|
|
11170
|
+
member,
|
|
11171
|
+
onEdit: canManage && api.updateCreditPoolMember ? () => setEditing(member) : void 0,
|
|
11172
|
+
onRemove: canManage && api.removeCreditPoolMember ? () => setRemoving(member) : void 0
|
|
11173
|
+
},
|
|
11174
|
+
member._id
|
|
11175
|
+
))
|
|
11176
|
+
]
|
|
10954
11177
|
}
|
|
10955
11178
|
)
|
|
10956
11179
|
] }),
|
|
@@ -10959,6 +11182,7 @@ function SharedCreditsView() {
|
|
|
10959
11182
|
{
|
|
10960
11183
|
kind: "add",
|
|
10961
11184
|
candidates,
|
|
11185
|
+
unallocatedPercent: poolUnallocatedPercent(data),
|
|
10962
11186
|
onSave: (input) => api.addCreditPoolMember(input),
|
|
10963
11187
|
onClose: () => setAdding(false),
|
|
10964
11188
|
onSaved: () => void load({ refresh: true })
|
|
@@ -10970,11 +11194,34 @@ function SharedCreditsView() {
|
|
|
10970
11194
|
kind: "edit",
|
|
10971
11195
|
member: editing,
|
|
10972
11196
|
memberName: poolWorkspaceName(editing.memberWorkspaceName),
|
|
11197
|
+
unallocatedPercent: poolUnallocatedPercent(data, editing._id),
|
|
10973
11198
|
onSave: (patch) => api.updateCreditPoolMember(editing._id, patch),
|
|
10974
11199
|
onClose: () => setEditing(null),
|
|
10975
11200
|
onSaved: () => void load({ refresh: true })
|
|
10976
11201
|
}
|
|
10977
11202
|
),
|
|
11203
|
+
settingSelf && api.setCreditPoolSelfShare && /* @__PURE__ */ jsx29(
|
|
11204
|
+
CreditPoolMemberModal,
|
|
11205
|
+
{
|
|
11206
|
+
kind: "self",
|
|
11207
|
+
self,
|
|
11208
|
+
workspaceName: selfName,
|
|
11209
|
+
unallocatedPercent: poolUnallocatedPercent(data, "self"),
|
|
11210
|
+
onSave: (input) => api.setCreditPoolSelfShare(input),
|
|
11211
|
+
onClose: () => setSettingSelf(false),
|
|
11212
|
+
onSaved: () => void load({ refresh: true })
|
|
11213
|
+
}
|
|
11214
|
+
),
|
|
11215
|
+
removingSelf && self && api.removeCreditPoolSelfShare && /* @__PURE__ */ jsx29(
|
|
11216
|
+
RemoveSelfShareModal,
|
|
11217
|
+
{
|
|
11218
|
+
self,
|
|
11219
|
+
workspaceName: selfName,
|
|
11220
|
+
onRemove: () => api.removeCreditPoolSelfShare(),
|
|
11221
|
+
onClose: () => setRemovingSelf(false),
|
|
11222
|
+
onRemoved: () => void load({ refresh: true })
|
|
11223
|
+
}
|
|
11224
|
+
),
|
|
10978
11225
|
removing && api.removeCreditPoolMember && /* @__PURE__ */ jsx29(
|
|
10979
11226
|
RemovePoolMemberModal,
|
|
10980
11227
|
{
|
|
@@ -12045,19 +12292,20 @@ function InvoiceHistoryTable({
|
|
|
12045
12292
|
const currencySymbol = getCurrencySymbolByCountry(workspaceCountry);
|
|
12046
12293
|
const handleDownload = async (item) => {
|
|
12047
12294
|
const orderId = item.transactionId;
|
|
12048
|
-
|
|
12049
|
-
|
|
12295
|
+
const kind = invoiceDownloadKind(item);
|
|
12296
|
+
if (!orderId || !kind) {
|
|
12297
|
+
toast.info?.(INVOICE_NOT_AVAILABLE_MESSAGE);
|
|
12050
12298
|
return;
|
|
12051
12299
|
}
|
|
12052
12300
|
try {
|
|
12053
12301
|
const res = await api.downloadInvoice(orderId);
|
|
12054
|
-
const
|
|
12055
|
-
|
|
12056
|
-
|
|
12057
|
-
window.open(
|
|
12058
|
-
} else if (
|
|
12059
|
-
const
|
|
12060
|
-
|
|
12302
|
+
const invoicePdfUrl = res?.data?.invoiceData?.invoice_pdf;
|
|
12303
|
+
const receiptPdfUrl = res?.data?.receiptPdfUrl;
|
|
12304
|
+
if (kind === "invoice" && invoicePdfUrl) {
|
|
12305
|
+
window.open(invoicePdfUrl, "_blank");
|
|
12306
|
+
} else if (kind === "receipt" && receiptPdfUrl) {
|
|
12307
|
+
const response = await fetch(receiptPdfUrl);
|
|
12308
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
12061
12309
|
const blob = await response.blob();
|
|
12062
12310
|
const url = window.URL.createObjectURL(blob);
|
|
12063
12311
|
const a = document.createElement("a");
|
|
@@ -12068,10 +12316,14 @@ function InvoiceHistoryTable({
|
|
|
12068
12316
|
a.remove();
|
|
12069
12317
|
window.URL.revokeObjectURL(url);
|
|
12070
12318
|
} else {
|
|
12071
|
-
toast.info?.(
|
|
12319
|
+
toast.info?.(
|
|
12320
|
+
kind === "receipt" ? "The receipt for this payment isn't ready yet. Try again in a few minutes." : "The PDF for this invoice isn't available yet. Try again in a few minutes."
|
|
12321
|
+
);
|
|
12072
12322
|
}
|
|
12073
|
-
} catch {
|
|
12074
|
-
toast.error(
|
|
12323
|
+
} catch (err) {
|
|
12324
|
+
toast.error(
|
|
12325
|
+
`${INVOICE_DOWNLOAD_FAILED_MESSAGE} ${errorMessage(err, { method: "GET" })}`
|
|
12326
|
+
);
|
|
12075
12327
|
}
|
|
12076
12328
|
};
|
|
12077
12329
|
const handleRowClick = (e, invoiceNumber) => {
|
|
@@ -12149,6 +12401,9 @@ function InvoiceHistoryTable({
|
|
|
12149
12401
|
amount: inv.amountPaid != null ? `${currencySymbol}${inv.amountPaid.toFixed(2)}` : `${currencySymbol}${(inv.amount / 100).toFixed(2)}`,
|
|
12150
12402
|
date: formatDate3(inv.createdAt),
|
|
12151
12403
|
downloadLabel: "Download invoice",
|
|
12404
|
+
downloadable: invoiceDownloadKind(inv) !== null,
|
|
12405
|
+
unavailableLabel: "No invoice",
|
|
12406
|
+
title: invoiceDownloadKind(inv) === null ? INVOICE_NOT_AVAILABLE_MESSAGE : void 0,
|
|
12152
12407
|
onClick: (e) => handleRowClick(e, inv)
|
|
12153
12408
|
},
|
|
12154
12409
|
inv._id
|
|
@@ -12552,6 +12807,7 @@ function BillingContent({
|
|
|
12552
12807
|
);
|
|
12553
12808
|
const [availableCredits, setAvailableCredits] = useState22(null);
|
|
12554
12809
|
const [sharedPool, setSharedPool] = useState22(null);
|
|
12810
|
+
const [sponsorShare, setSponsorShare] = useState22(null);
|
|
12555
12811
|
const [usedByNames, setUsedByNames] = useState22({});
|
|
12556
12812
|
const [allProducts, setProducts] = useState22([]);
|
|
12557
12813
|
const workspaceCountry = workspace.current?.country;
|
|
@@ -12642,6 +12898,7 @@ function BillingContent({
|
|
|
12642
12898
|
if (creditsRes?.availableCredits != null)
|
|
12643
12899
|
setAvailableCredits(creditsRes.availableCredits);
|
|
12644
12900
|
setSharedPool(creditsRes?.sharedPool ?? null);
|
|
12901
|
+
setSponsorShare(creditsRes?.sponsorShare ?? null);
|
|
12645
12902
|
if (productsRes?.data) setProducts(productsRes.data);
|
|
12646
12903
|
if (customRes?.data?.credits != null) {
|
|
12647
12904
|
setCustomPlanCredits(customRes.data.credits);
|
|
@@ -12930,7 +13187,7 @@ function BillingContent({
|
|
|
12930
13187
|
remaining: remainingCredits,
|
|
12931
13188
|
progressPct,
|
|
12932
13189
|
remainingPct
|
|
12933
|
-
} = creditsMeter({ availableCredits, totalCredits, sharedPool });
|
|
13190
|
+
} = creditsMeter({ availableCredits, totalCredits, sharedPool, sponsorShare });
|
|
12934
13191
|
const usageText = usedCredits != null ? formatCredits2(usedCredits) : remainingCredits != null ? `${formatCredits2(remainingCredits)} available` : customPlanCredits != null ? `${formatCredits2(customPlanCredits)} credits` : "\u2014";
|
|
12935
13192
|
const handleExport = async (startDate, endDate) => {
|
|
12936
13193
|
const end = new Date(endDate);
|
|
@@ -12938,7 +13195,7 @@ function BillingContent({
|
|
|
12938
13195
|
if (activeTab === "invoice") {
|
|
12939
13196
|
const filtered = invoices.filter((inv) => {
|
|
12940
13197
|
const d = new Date(inv.createdAt);
|
|
12941
|
-
return d >= startDate && d <= end;
|
|
13198
|
+
return d >= startDate && d <= end && invoiceDownloadKind(inv) === "invoice";
|
|
12942
13199
|
});
|
|
12943
13200
|
if (filtered.length === 0) {
|
|
12944
13201
|
toast.info?.("No invoices found in the selected date range.");
|
|
@@ -13343,6 +13600,49 @@ function BillingContent({
|
|
|
13343
13600
|
]
|
|
13344
13601
|
}
|
|
13345
13602
|
)
|
|
13603
|
+
) : sponsorShare ? (
|
|
13604
|
+
// A sponsor keeping only a share of its credits: what is left of it.
|
|
13605
|
+
/* @__PURE__ */ jsxs27(
|
|
13606
|
+
"div",
|
|
13607
|
+
{
|
|
13608
|
+
role: "status",
|
|
13609
|
+
className: "flex flex-col shrink-0 w-full",
|
|
13610
|
+
style: {
|
|
13611
|
+
gap: 4,
|
|
13612
|
+
padding: 16,
|
|
13613
|
+
backgroundColor: "var(--alias-surface-base)",
|
|
13614
|
+
border: "1px solid var(--alias-border-subtle)",
|
|
13615
|
+
borderRadius: "var(--radius-3xl)"
|
|
13616
|
+
},
|
|
13617
|
+
children: [
|
|
13618
|
+
/* @__PURE__ */ jsx30(
|
|
13619
|
+
"span",
|
|
13620
|
+
{
|
|
13621
|
+
style: {
|
|
13622
|
+
fontFamily: "var(--font-family-font-family-body)",
|
|
13623
|
+
fontSize: "var(--font-size-font-size-sm)",
|
|
13624
|
+
fontWeight: 500,
|
|
13625
|
+
lineHeight: "var(--line-height-line-height-sm)",
|
|
13626
|
+
color: sponsorShare.remaining <= 0 ? "var(--alias-text---icons-warning)" : "var(--alias-text---icons-primary)"
|
|
13627
|
+
},
|
|
13628
|
+
children: sponsorShareBannerText(sponsorShare)
|
|
13629
|
+
}
|
|
13630
|
+
),
|
|
13631
|
+
/* @__PURE__ */ jsx30(
|
|
13632
|
+
"span",
|
|
13633
|
+
{
|
|
13634
|
+
style: {
|
|
13635
|
+
fontFamily: "var(--font-family-font-family-body)",
|
|
13636
|
+
fontSize: "var(--font-size-font-size-sm)",
|
|
13637
|
+
lineHeight: "var(--line-height-line-height-sm)",
|
|
13638
|
+
color: "var(--alias-text---icons-muted)"
|
|
13639
|
+
},
|
|
13640
|
+
children: sponsorShareDetailText()
|
|
13641
|
+
}
|
|
13642
|
+
)
|
|
13643
|
+
]
|
|
13644
|
+
}
|
|
13645
|
+
)
|
|
13346
13646
|
) : null,
|
|
13347
13647
|
usage ? /* @__PURE__ */ jsxs27(
|
|
13348
13648
|
"div",
|
|
@@ -18387,6 +18687,8 @@ export {
|
|
|
18387
18687
|
EMPTY_USAGE_LOGS_PAGE,
|
|
18388
18688
|
ExportDateModal,
|
|
18389
18689
|
INITIAL_USAGE_LOGS_STATE,
|
|
18690
|
+
INVOICE_DOWNLOAD_FAILED_MESSAGE,
|
|
18691
|
+
INVOICE_NOT_AVAILABLE_MESSAGE,
|
|
18390
18692
|
InviteUpdateModal,
|
|
18391
18693
|
MOCK_REFERRED_USERS,
|
|
18392
18694
|
MemberCreditLimitModal,
|
|
@@ -18408,6 +18710,7 @@ export {
|
|
|
18408
18710
|
ReferralHistoryView,
|
|
18409
18711
|
ReferralTab,
|
|
18410
18712
|
RemovePoolMemberModal,
|
|
18713
|
+
RemoveSelfShareModal,
|
|
18411
18714
|
SCOPE_LABELS,
|
|
18412
18715
|
ScopeHeader,
|
|
18413
18716
|
SettingsAdaptersProvider,
|
|
@@ -18441,6 +18744,7 @@ export {
|
|
|
18441
18744
|
belowUsageReason,
|
|
18442
18745
|
canManageOnlyWorkspaceCreditLimit,
|
|
18443
18746
|
canShowSharedCredits,
|
|
18747
|
+
checkPoolPercentTotal,
|
|
18444
18748
|
cleanCreditLimitInput,
|
|
18445
18749
|
cleanPoolValueInput,
|
|
18446
18750
|
countLabel,
|
|
@@ -18465,6 +18769,7 @@ export {
|
|
|
18465
18769
|
groupWorkspaceList,
|
|
18466
18770
|
hasPaidFeatures,
|
|
18467
18771
|
inviteUpdate,
|
|
18772
|
+
invoiceDownloadKind,
|
|
18468
18773
|
isLimitAboveTotal,
|
|
18469
18774
|
isLimitBelowUsage,
|
|
18470
18775
|
isPaidPlan,
|
|
@@ -18486,9 +18791,12 @@ export {
|
|
|
18486
18791
|
parseBillingEntitlement,
|
|
18487
18792
|
parseInviteEmails,
|
|
18488
18793
|
pausedOwnCreditsText,
|
|
18794
|
+
poolAllocatedPercent,
|
|
18795
|
+
poolAllocationText,
|
|
18489
18796
|
poolEndsAtFrom,
|
|
18490
18797
|
poolErrorMessage,
|
|
18491
18798
|
poolRenewsAtCycleEnd,
|
|
18799
|
+
poolUnallocatedPercent,
|
|
18492
18800
|
poolWorkspaceName,
|
|
18493
18801
|
productsForCountry,
|
|
18494
18802
|
readSettingsCaller,
|
|
@@ -18504,6 +18812,9 @@ export {
|
|
|
18504
18812
|
sharedPoolEndsText,
|
|
18505
18813
|
sliceUsageLogsPage,
|
|
18506
18814
|
sortReferredUsers,
|
|
18815
|
+
sponsorShareBannerText,
|
|
18816
|
+
sponsorShareDetailText,
|
|
18817
|
+
sponsorShareSpentText,
|
|
18507
18818
|
sponsoredCreditsText,
|
|
18508
18819
|
ssoLabel,
|
|
18509
18820
|
toCsv,
|