@streamoid/settings 0.21.0 → 0.22.0
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 +133 -12
- package/dist/index.d.ts +133 -12
- package/dist/index.js +318 -29
- package/dist/index.mjs +318 -29
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -10058,6 +10058,32 @@ function validatePoolText(raw, max) {
|
|
|
10058
10058
|
if (value.length > max) return { ok: false, reason: `At most ${max} characters` };
|
|
10059
10059
|
return { ok: true, value };
|
|
10060
10060
|
}
|
|
10061
|
+
var round2 = (value) => Math.round(value * 100) / 100;
|
|
10062
|
+
function poolAllocatedPercent(pool, exclude) {
|
|
10063
|
+
if (!pool) return 0;
|
|
10064
|
+
if (exclude === void 0 && typeof pool.allocatedPercent === "number") return round2(pool.allocatedPercent);
|
|
10065
|
+
let total = 0;
|
|
10066
|
+
if (exclude !== "self" && pool.self?.mode === "percent") total += pool.self.value;
|
|
10067
|
+
for (const member of pool.members ?? []) {
|
|
10068
|
+
if (member._id !== exclude && member.mode === "percent") total += member.value;
|
|
10069
|
+
}
|
|
10070
|
+
return round2(total);
|
|
10071
|
+
}
|
|
10072
|
+
function poolUnallocatedPercent(pool, exclude) {
|
|
10073
|
+
return Math.max(0, round2(100 - poolAllocatedPercent(pool, exclude)));
|
|
10074
|
+
}
|
|
10075
|
+
function checkPoolPercentTotal(split, unallocatedPercent) {
|
|
10076
|
+
if (split.mode !== "percent" || round2(split.value) <= round2(unallocatedPercent)) return { ok: true };
|
|
10077
|
+
const left = formatCredits(Math.max(0, unallocatedPercent));
|
|
10078
|
+
return {
|
|
10079
|
+
ok: false,
|
|
10080
|
+
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."
|
|
10081
|
+
};
|
|
10082
|
+
}
|
|
10083
|
+
function poolAllocationText(pool) {
|
|
10084
|
+
const allocated = poolAllocatedPercent(pool);
|
|
10085
|
+
return `Allocated ${formatCredits(allocated)}% \xB7 Unallocated ${formatCredits(Math.max(0, round2(100 - allocated)))}%`;
|
|
10086
|
+
}
|
|
10061
10087
|
var credits = (value) => `${formatCredits(value)} ${value === 1 ? "credit" : "credits"}`;
|
|
10062
10088
|
function formatPoolSplit(split) {
|
|
10063
10089
|
if (split.mode === "percent") return `${formatCredits(split.value)}%`;
|
|
@@ -10144,6 +10170,16 @@ function sharedPoolBannerText(pool) {
|
|
|
10144
10170
|
const sponsor = pool.sponsorName?.trim() || "another workspace";
|
|
10145
10171
|
return `Credits shared by ${sponsor}: ${formatCredits(pool.remaining)} of ${formatCredits(pool.allowance)} left this cycle`;
|
|
10146
10172
|
}
|
|
10173
|
+
function sponsorShareSpentText() {
|
|
10174
|
+
return "This workspace has used its share of the credits for this cycle.";
|
|
10175
|
+
}
|
|
10176
|
+
function sponsorShareBannerText(share) {
|
|
10177
|
+
if (share.remaining <= 0) return sponsorShareSpentText();
|
|
10178
|
+
return `This workspace's share: ${formatCredits(share.remaining)} of ${credits(share.allowance)} left this cycle`;
|
|
10179
|
+
}
|
|
10180
|
+
function sponsorShareDetailText() {
|
|
10181
|
+
return "The rest of this workspace's credits are kept for the workspaces it shares them with. Organization admins change this in Shared credits.";
|
|
10182
|
+
}
|
|
10147
10183
|
function pausedOwnCreditsText(_pool) {
|
|
10148
10184
|
return ownCreditsFirstText();
|
|
10149
10185
|
}
|
|
@@ -10153,8 +10189,16 @@ function ownCreditsFirstText() {
|
|
|
10153
10189
|
function creditsMeter({
|
|
10154
10190
|
availableCredits,
|
|
10155
10191
|
totalCredits,
|
|
10156
|
-
sharedPool
|
|
10192
|
+
sharedPool,
|
|
10193
|
+
sponsorShare = null
|
|
10157
10194
|
}) {
|
|
10195
|
+
if (sponsorShare && !sharedPool) {
|
|
10196
|
+
const used2 = Math.max(0, sponsorShare.used);
|
|
10197
|
+
const left = Math.max(0, sponsorShare.remaining);
|
|
10198
|
+
const remaining = availableCredits != null ? Math.min(left, Math.max(0, availableCredits)) : left;
|
|
10199
|
+
const progressPct2 = sponsorShare.allowance > 0 ? Math.min(100, Math.round(used2 / sponsorShare.allowance * 100)) : 100;
|
|
10200
|
+
return { used: used2, remaining, progressPct: progressPct2, remainingPct: 100 - progressPct2 };
|
|
10201
|
+
}
|
|
10158
10202
|
if (sharedPool && availableCredits != null && totalCredits != null) {
|
|
10159
10203
|
const total = Math.max(0, totalCredits) + Math.max(0, sharedPool.allowance);
|
|
10160
10204
|
const used2 = Math.max(0, total - availableCredits);
|
|
@@ -10365,18 +10409,31 @@ var EXPIRY_OPTIONS = [
|
|
|
10365
10409
|
];
|
|
10366
10410
|
var isExpiryKind = (id) => EXPIRY_OPTIONS.some((o) => o.id === id);
|
|
10367
10411
|
var endsText = (member) => member.endsAt ? `, until ${formatPoolEndsAt(member.endsAt)}` : "";
|
|
10368
|
-
function endsAtHelp(kind, endsAt) {
|
|
10369
|
-
if (kind === "never")
|
|
10412
|
+
function endsAtHelp(kind, endsAt, self) {
|
|
10413
|
+
if (kind === "never") {
|
|
10414
|
+
return self ? "Applies every billing cycle until it is removed." : "Shares every billing cycle until it is removed.";
|
|
10415
|
+
}
|
|
10416
|
+
if (self) {
|
|
10417
|
+
const stop2 = "After that, this workspace may spend all its credits again.";
|
|
10418
|
+
return endsAt ? `The share ends on ${formatPoolEndsAt(endsAt)}. ${stop2}` : stop2;
|
|
10419
|
+
}
|
|
10370
10420
|
const stop = "After that, the other workspace spends only its own credits.";
|
|
10371
10421
|
return endsAt ? `Sharing stops on ${formatPoolEndsAt(endsAt)}. ${stop}` : stop;
|
|
10372
10422
|
}
|
|
10423
|
+
function valueHelp(kind, mode) {
|
|
10424
|
+
if (kind === "self") {
|
|
10425
|
+
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%.";
|
|
10426
|
+
}
|
|
10427
|
+
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.";
|
|
10428
|
+
}
|
|
10373
10429
|
function CreditPoolMemberModal(props) {
|
|
10374
10430
|
const { toast } = useSettingsAdapters();
|
|
10375
|
-
const editing = props.kind === "edit" ? props.member : null;
|
|
10431
|
+
const editing = props.kind === "edit" ? props.member : props.kind === "self" ? props.self : null;
|
|
10432
|
+
const initialNote = props.kind === "self" ? props.self?.note ?? "" : "";
|
|
10376
10433
|
const [memberId, setMemberId] = useState19("");
|
|
10377
10434
|
const [mode, setMode] = useState19(editing?.mode ?? "percent");
|
|
10378
10435
|
const [raw, setRaw] = useState19(editing ? String(editing.value) : "");
|
|
10379
|
-
const [note, setNote] = useState19(
|
|
10436
|
+
const [note, setNote] = useState19(initialNote);
|
|
10380
10437
|
const [touched, setTouched] = useState19(false);
|
|
10381
10438
|
const [saving, setSaving] = useState19(false);
|
|
10382
10439
|
const [serverError, setServerError] = useState19(null);
|
|
@@ -10393,10 +10450,13 @@ function CreditPoolMemberModal(props) {
|
|
|
10393
10450
|
const endsAtUnchanged = Boolean(editing) && expiry.kind === initialExpiry.kind && (expiry.kind !== "date" || initialExpiry.kind === "date" && expiry.date === initialExpiry.date);
|
|
10394
10451
|
const endsAt = endsAtUnchanged ? null : poolEndsAtFrom(expiry);
|
|
10395
10452
|
const splitChanged = !editing || mode !== editing.mode || !value.ok || value.value !== editing.value;
|
|
10396
|
-
const
|
|
10397
|
-
const
|
|
10453
|
+
const noteChanged = props.kind === "self" && note.trim() !== initialNote.trim();
|
|
10454
|
+
const changed = splitChanged || !endsAtUnchanged || noteChanged;
|
|
10455
|
+
const percentTotal = value.ok && props.unallocatedPercent !== void 0 ? checkPoolPercentTotal({ mode, value: value.value }, props.unallocatedPercent) : null;
|
|
10456
|
+
const valid = value.ok && (percentTotal === null || percentTotal.ok) && (endsAt === null || endsAt.ok) && (props.kind === "edit" || (props.kind === "self" || Boolean(memberId)) && noteCheck.ok);
|
|
10398
10457
|
const canSave = !saving && changed && valid;
|
|
10399
|
-
const valueHint = touched && !value.ok ? value.reason : null;
|
|
10458
|
+
const valueHint = touched && !value.ok ? value.reason : percentTotal && !percentTotal.ok ? percentTotal.reason : null;
|
|
10459
|
+
const unallocatedHint = mode === "percent" && props.unallocatedPercent !== void 0 ? ` ${formatCredits(Math.max(0, props.unallocatedPercent))}% is unallocated.` : "";
|
|
10400
10460
|
const expiryHint = endsAt && !endsAt.ok && !(expiry.kind === "date" && !expiry.date) ? endsAt.reason : null;
|
|
10401
10461
|
const handleSave = async () => {
|
|
10402
10462
|
if (!canSave || !value.ok) return;
|
|
@@ -10413,6 +10473,17 @@ function CreditPoolMemberModal(props) {
|
|
|
10413
10473
|
...sendEndsAt?.value ? { endsAt: sendEndsAt.value } : {}
|
|
10414
10474
|
});
|
|
10415
10475
|
toast.success(`Credits shared. ${describeAllowance(added)}${endsText(added)}.`);
|
|
10476
|
+
} else if (props.kind === "self") {
|
|
10477
|
+
const nextEndsAt = sendEndsAt ? sendEndsAt.value : props.self?.endsAt ?? null;
|
|
10478
|
+
await props.onSave({
|
|
10479
|
+
mode,
|
|
10480
|
+
value: value.value,
|
|
10481
|
+
note: noteCheck.ok ? noteCheck.value : "",
|
|
10482
|
+
endsAt: nextEndsAt
|
|
10483
|
+
});
|
|
10484
|
+
toast.success(
|
|
10485
|
+
`This workspace's share is ${formatPoolSplit({ mode, value: value.value })} each billing cycle${endsText({ endsAt: nextEndsAt })}.`
|
|
10486
|
+
);
|
|
10416
10487
|
} else {
|
|
10417
10488
|
const updated = await props.onSave({
|
|
10418
10489
|
mode,
|
|
@@ -10426,7 +10497,10 @@ function CreditPoolMemberModal(props) {
|
|
|
10426
10497
|
} catch (err) {
|
|
10427
10498
|
const message = poolErrorMessage(err);
|
|
10428
10499
|
if (message) setServerError(message);
|
|
10429
|
-
else
|
|
10500
|
+
else {
|
|
10501
|
+
const method = props.kind === "add" ? "POST" : props.kind === "self" ? "PUT" : "PATCH";
|
|
10502
|
+
toast.error(errorMessage(err, { method }));
|
|
10503
|
+
}
|
|
10430
10504
|
setSaving(false);
|
|
10431
10505
|
}
|
|
10432
10506
|
};
|
|
@@ -10434,7 +10508,7 @@ function CreditPoolMemberModal(props) {
|
|
|
10434
10508
|
return /* @__PURE__ */ jsxs24(
|
|
10435
10509
|
PoolModalShell,
|
|
10436
10510
|
{
|
|
10437
|
-
title: props.kind === "add" ? "Share credits" : "Edit shared credits",
|
|
10511
|
+
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
10512
|
busy: saving,
|
|
10439
10513
|
onClose: props.onClose,
|
|
10440
10514
|
footer: /* @__PURE__ */ jsxs24(Fragment10, { children: [
|
|
@@ -10461,7 +10535,7 @@ function CreditPoolMemberModal(props) {
|
|
|
10461
10535
|
] }),
|
|
10462
10536
|
children: [
|
|
10463
10537
|
/* @__PURE__ */ jsxs24("div", { className: "flex flex-col w-full", style: { gap: T17.spXs }, children: [
|
|
10464
|
-
/* @__PURE__ */ jsx27("span", { style: fieldLabel, children: "Share with" }),
|
|
10538
|
+
/* @__PURE__ */ jsx27("span", { style: fieldLabel, children: props.kind === "self" ? "Workspace" : "Share with" }),
|
|
10465
10539
|
props.kind === "add" ? candidateOptions.length ? /* @__PURE__ */ jsx27(
|
|
10466
10540
|
ScSelect,
|
|
10467
10541
|
{
|
|
@@ -10471,7 +10545,7 @@ function CreditPoolMemberModal(props) {
|
|
|
10471
10545
|
placeholder: "Choose a workspace",
|
|
10472
10546
|
disabled: saving
|
|
10473
10547
|
}
|
|
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 })
|
|
10548
|
+
) : /* @__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
10549
|
] }),
|
|
10476
10550
|
/* @__PURE__ */ jsxs24("div", { className: "flex flex-col w-full", style: { gap: T17.spMd }, children: [
|
|
10477
10551
|
/* @__PURE__ */ jsx27("span", { style: fieldLabel, children: "How much, each billing cycle" }),
|
|
@@ -10530,7 +10604,8 @@ function CreditPoolMemberModal(props) {
|
|
|
10530
10604
|
}
|
|
10531
10605
|
),
|
|
10532
10606
|
valueHint ? /* @__PURE__ */ jsx27("span", { role: "alert", style: { ...modalBodyText, color: T17.error }, children: valueHint }) : /* @__PURE__ */ jsxs24("span", { style: { ...modalBodyText, color: T17.tertiary }, children: [
|
|
10533
|
-
|
|
10607
|
+
valueHelp(props.kind, mode),
|
|
10608
|
+
unallocatedHint,
|
|
10534
10609
|
editing ? " Applies immediately." : ""
|
|
10535
10610
|
] })
|
|
10536
10611
|
] }),
|
|
@@ -10598,16 +10673,20 @@ function CreditPoolMemberModal(props) {
|
|
|
10598
10673
|
)
|
|
10599
10674
|
}
|
|
10600
10675
|
),
|
|
10601
|
-
expiryHint ? /* @__PURE__ */ jsx27("span", { role: "alert", style: { ...modalBodyText, color: T17.error }, children: expiryHint }) : /* @__PURE__ */ jsx27("span", { style: { ...modalBodyText, color: T17.tertiary }, children: endsAtHelp(
|
|
10676
|
+
expiryHint ? /* @__PURE__ */ jsx27("span", { role: "alert", style: { ...modalBodyText, color: T17.error }, children: expiryHint }) : /* @__PURE__ */ jsx27("span", { style: { ...modalBodyText, color: T17.tertiary }, children: endsAtHelp(
|
|
10677
|
+
expiryKind,
|
|
10678
|
+
endsAtUnchanged ? editing?.endsAt ?? null : endsAt?.ok ? endsAt.value : null,
|
|
10679
|
+
props.kind === "self"
|
|
10680
|
+
) })
|
|
10602
10681
|
] }),
|
|
10603
|
-
props.kind
|
|
10682
|
+
props.kind !== "edit" && /* @__PURE__ */ jsxs24("div", { className: "flex flex-col w-full", style: { gap: T17.spXs }, children: [
|
|
10604
10683
|
/* @__PURE__ */ jsx27("span", { style: fieldLabel, children: "Note" }),
|
|
10605
10684
|
/* @__PURE__ */ jsx27(
|
|
10606
10685
|
ScTextArea,
|
|
10607
10686
|
{
|
|
10608
10687
|
value: note,
|
|
10609
10688
|
maxLength: POOL_NOTE_MAX_LENGTH,
|
|
10610
|
-
placeholder: "Why are these credits being shared?",
|
|
10689
|
+
placeholder: props.kind === "self" ? "Why does this workspace keep only this share?" : "Why are these credits being shared?",
|
|
10611
10690
|
disabled: saving,
|
|
10612
10691
|
onChange: (e) => setNote(e.target.value),
|
|
10613
10692
|
rows: 3,
|
|
@@ -10720,6 +10799,73 @@ function RemovePoolMemberModal({
|
|
|
10720
10799
|
}
|
|
10721
10800
|
);
|
|
10722
10801
|
}
|
|
10802
|
+
function RemoveSelfShareModal({
|
|
10803
|
+
self,
|
|
10804
|
+
workspaceName,
|
|
10805
|
+
onRemove,
|
|
10806
|
+
onClose,
|
|
10807
|
+
onRemoved
|
|
10808
|
+
}) {
|
|
10809
|
+
const { toast } = useSettingsAdapters();
|
|
10810
|
+
const [saving, setSaving] = useState20(false);
|
|
10811
|
+
const handleConfirm = async () => {
|
|
10812
|
+
if (saving) return;
|
|
10813
|
+
setSaving(true);
|
|
10814
|
+
try {
|
|
10815
|
+
await onRemove();
|
|
10816
|
+
toast.success(`${workspaceName} can spend all its credits again`);
|
|
10817
|
+
onRemoved();
|
|
10818
|
+
onClose();
|
|
10819
|
+
} catch (err) {
|
|
10820
|
+
toast.error(errorMessage(err, { method: "DELETE" }));
|
|
10821
|
+
setSaving(false);
|
|
10822
|
+
}
|
|
10823
|
+
};
|
|
10824
|
+
return /* @__PURE__ */ jsxs25(
|
|
10825
|
+
PoolModalShell,
|
|
10826
|
+
{
|
|
10827
|
+
title: "Remove this workspace's share",
|
|
10828
|
+
busy: saving,
|
|
10829
|
+
onClose,
|
|
10830
|
+
footer: /* @__PURE__ */ jsxs25(Fragment11, { children: [
|
|
10831
|
+
/* @__PURE__ */ jsx28(
|
|
10832
|
+
ScButton13,
|
|
10833
|
+
{
|
|
10834
|
+
text: "Keep share",
|
|
10835
|
+
variant: "secondary",
|
|
10836
|
+
size: "md",
|
|
10837
|
+
state: saving ? "disabled" : "default",
|
|
10838
|
+
onClick: saving ? void 0 : onClose
|
|
10839
|
+
}
|
|
10840
|
+
),
|
|
10841
|
+
/* @__PURE__ */ jsx28(
|
|
10842
|
+
ScButton13,
|
|
10843
|
+
{
|
|
10844
|
+
text: "Remove share",
|
|
10845
|
+
variant: "error",
|
|
10846
|
+
size: "md",
|
|
10847
|
+
state: saving ? "disabled" : "default",
|
|
10848
|
+
onClick: saving ? void 0 : () => void handleConfirm()
|
|
10849
|
+
}
|
|
10850
|
+
)
|
|
10851
|
+
] }),
|
|
10852
|
+
children: [
|
|
10853
|
+
/* @__PURE__ */ jsxs25("span", { style: { ...modalBodyText, color: MODAL_T.primary }, children: [
|
|
10854
|
+
workspaceName,
|
|
10855
|
+
" may spend its whole balance again, starting now."
|
|
10856
|
+
] }),
|
|
10857
|
+
/* @__PURE__ */ jsxs25("span", { style: { ...modalBodyText, color: MODAL_T.tertiary }, children: [
|
|
10858
|
+
"It kept ",
|
|
10859
|
+
describeAllowance(self),
|
|
10860
|
+
" and has used ",
|
|
10861
|
+
formatCredits(self.used),
|
|
10862
|
+
".",
|
|
10863
|
+
self.mode === "percent" ? ` Its ${formatPoolSplit(self)} goes back to unallocated, so other workspaces can be given more.` : ""
|
|
10864
|
+
] })
|
|
10865
|
+
]
|
|
10866
|
+
}
|
|
10867
|
+
);
|
|
10868
|
+
}
|
|
10723
10869
|
|
|
10724
10870
|
// src/shared-credits-view.tsx
|
|
10725
10871
|
import { jsx as jsx29, jsxs as jsxs26 } from "react/jsx-runtime";
|
|
@@ -10802,10 +10948,49 @@ function MemberRow2({
|
|
|
10802
10948
|
}
|
|
10803
10949
|
);
|
|
10804
10950
|
}
|
|
10951
|
+
function SelfShareRow({
|
|
10952
|
+
self,
|
|
10953
|
+
onSet,
|
|
10954
|
+
onRemove
|
|
10955
|
+
}) {
|
|
10956
|
+
const spent = Boolean(self) && self.remaining <= 0;
|
|
10957
|
+
return /* @__PURE__ */ jsxs26(
|
|
10958
|
+
"div",
|
|
10959
|
+
{
|
|
10960
|
+
style: {
|
|
10961
|
+
borderBottom: `1px solid ${T18.borderSubtle}`,
|
|
10962
|
+
display: "grid",
|
|
10963
|
+
gridTemplateColumns: MEMBER_COLUMNS2,
|
|
10964
|
+
alignItems: "center",
|
|
10965
|
+
padding: `10px ${T18.sp3xl}`,
|
|
10966
|
+
gap: MEMBER_GAP,
|
|
10967
|
+
backgroundColor: T18.fillPlus
|
|
10968
|
+
},
|
|
10969
|
+
children: [
|
|
10970
|
+
/* @__PURE__ */ jsxs26("div", { className: "flex flex-col min-w-0", style: { gap: 2 }, children: [
|
|
10971
|
+
/* @__PURE__ */ jsx29("span", { className: "truncate", style: { ...cellText3, fontWeight: 500 }, children: "This workspace" }),
|
|
10972
|
+
self?.note && /* @__PURE__ */ jsx29("span", { className: "truncate", title: self.note, style: { ...cellText3, color: T18.tertiary }, children: self.note })
|
|
10973
|
+
] }),
|
|
10974
|
+
self ? /* @__PURE__ */ jsxs26("div", { className: "flex flex-col min-w-0", style: { gap: 2 }, children: [
|
|
10975
|
+
/* @__PURE__ */ jsx29("span", { style: cellText3, children: formatPoolSplit({ mode: "fixed", value: self.allowance }) }),
|
|
10976
|
+
/* @__PURE__ */ jsx29("span", { style: { ...cellText3, color: T18.tertiary }, children: self.mode === "percent" ? `${formatPoolSplit(self)} \xB7 this cycle` : "this cycle" })
|
|
10977
|
+
] }) : /* @__PURE__ */ jsx29("span", { style: { ...cellText3, color: T18.muted }, children: "All its credits" }),
|
|
10978
|
+
/* @__PURE__ */ jsx29("span", { style: { ...cellText3, color: self ? T18.primary : T18.muted }, children: self ? formatCredits(self.used) : "\u2014" }),
|
|
10979
|
+
/* @__PURE__ */ jsx29("span", { style: { ...cellText3, color: !self ? T18.muted : spent ? T18.warning : T18.primary }, children: self ? formatCredits(self.remaining) : "\u2014" }),
|
|
10980
|
+
/* @__PURE__ */ jsx29("span", { style: { ...cellText3, color: self?.endsAt ? T18.primary : T18.muted }, children: self ? formatPoolEndsAt(self.endsAt) : "\u2014" }),
|
|
10981
|
+
/* @__PURE__ */ jsxs26("div", { className: "flex items-center whitespace-nowrap", style: { gap: 8 }, children: [
|
|
10982
|
+
onSet && /* @__PURE__ */ jsx29(ScButton14, { text: self ? "Edit" : "Set share", variant: "secondary", size: "sm", onClick: onSet }),
|
|
10983
|
+
self && onRemove && /* @__PURE__ */ jsx29(ScButton14, { text: "Remove", variant: "secondary", size: "sm", onClick: onRemove })
|
|
10984
|
+
] })
|
|
10985
|
+
]
|
|
10986
|
+
}
|
|
10987
|
+
);
|
|
10988
|
+
}
|
|
10805
10989
|
function SharedCreditsView() {
|
|
10806
10990
|
const { api, workspace, toast } = useSettingsAdapters();
|
|
10807
10991
|
const workspaceId = workspace.current?.id ?? null;
|
|
10808
10992
|
const workspaceName = workspace.current?.name?.trim() || "this workspace";
|
|
10993
|
+
const selfName = workspace.current?.name?.trim() || "This workspace";
|
|
10809
10994
|
const [data, setData] = useState21(null);
|
|
10810
10995
|
const [loading, setLoading] = useState21(true);
|
|
10811
10996
|
const [failed, setFailed] = useState21(false);
|
|
@@ -10813,6 +10998,8 @@ function SharedCreditsView() {
|
|
|
10813
10998
|
const [adding, setAdding] = useState21(false);
|
|
10814
10999
|
const [editing, setEditing] = useState21(null);
|
|
10815
11000
|
const [removing, setRemoving] = useState21(null);
|
|
11001
|
+
const [settingSelf, setSettingSelf] = useState21(false);
|
|
11002
|
+
const [removingSelf, setRemovingSelf] = useState21(false);
|
|
10816
11003
|
const latestLoad = useRef11(0);
|
|
10817
11004
|
const load = useCallback8(
|
|
10818
11005
|
async ({ refresh = false } = {}) => {
|
|
@@ -10841,6 +11028,8 @@ function SharedCreditsView() {
|
|
|
10841
11028
|
setAdding(false);
|
|
10842
11029
|
setEditing(null);
|
|
10843
11030
|
setRemoving(null);
|
|
11031
|
+
setSettingSelf(false);
|
|
11032
|
+
setRemovingSelf(false);
|
|
10844
11033
|
void load();
|
|
10845
11034
|
}, [workspaceId]);
|
|
10846
11035
|
useEffect18(
|
|
@@ -10888,6 +11077,8 @@ function SharedCreditsView() {
|
|
|
10888
11077
|
);
|
|
10889
11078
|
}
|
|
10890
11079
|
const members = data?.members ?? [];
|
|
11080
|
+
const self = data?.self ?? null;
|
|
11081
|
+
const showSelf = !failed && Boolean(data) && (Boolean(api.setCreditPoolSelfShare) || Boolean(self));
|
|
10891
11082
|
return /* @__PURE__ */ jsxs26("div", { className: "flex flex-col flex-1 min-h-0 w-full overflow-y-auto", style: { gap: 16 }, children: [
|
|
10892
11083
|
/* @__PURE__ */ jsxs26("div", { className: "flex items-start justify-between shrink-0 w-full", style: { gap: 12 }, children: [
|
|
10893
11084
|
/* @__PURE__ */ jsxs26("div", { className: "flex flex-col min-w-0", style: { gap: 4 }, children: [
|
|
@@ -10932,25 +11123,46 @@ function SharedCreditsView() {
|
|
|
10932
11123
|
}
|
|
10933
11124
|
),
|
|
10934
11125
|
!sponsor && /* @__PURE__ */ jsxs26("div", { className: "flex flex-col shrink-0 w-full", style: { gap: 8 }, children: [
|
|
10935
|
-
/* @__PURE__ */
|
|
10936
|
-
|
|
11126
|
+
/* @__PURE__ */ jsxs26("div", { className: "flex items-baseline justify-between w-full", style: { gap: 12 }, children: [
|
|
11127
|
+
/* @__PURE__ */ jsx29("span", { style: { ...cellText3, fontWeight: 500 }, children: "Shared with" }),
|
|
11128
|
+
!failed && data && /* @__PURE__ */ jsx29(
|
|
11129
|
+
"span",
|
|
11130
|
+
{
|
|
11131
|
+
style: { ...cellText3, color: T18.muted },
|
|
11132
|
+
title: "Percentage shares, this workspace's included, total at most 100%. Fixed-credit shares aren't counted.",
|
|
11133
|
+
children: poolAllocationText(data)
|
|
11134
|
+
}
|
|
11135
|
+
)
|
|
11136
|
+
] }),
|
|
11137
|
+
/* @__PURE__ */ jsxs26(
|
|
10937
11138
|
MemberListFrame,
|
|
10938
11139
|
{
|
|
10939
11140
|
grow: "cap",
|
|
10940
11141
|
maxHeight: 420,
|
|
10941
11142
|
contentMinWidth: MEMBER_MIN_WIDTH,
|
|
10942
11143
|
header: tableHeader(MEMBER_COLUMNS2, ["Workspace", "Allowance", "Used", "Remaining", "Ends", "Actions"]),
|
|
10943
|
-
isEmpty: failed || members.length === 0,
|
|
11144
|
+
isEmpty: failed || members.length === 0 && !showSelf,
|
|
10944
11145
|
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
|
-
|
|
11146
|
+
children: [
|
|
11147
|
+
showSelf && /* @__PURE__ */ jsx29(
|
|
11148
|
+
SelfShareRow,
|
|
11149
|
+
{
|
|
11150
|
+
self,
|
|
11151
|
+
onSet: canManage && api.setCreditPoolSelfShare ? () => setSettingSelf(true) : void 0,
|
|
11152
|
+
onRemove: canManage && api.removeCreditPoolSelfShare ? () => setRemovingSelf(true) : void 0
|
|
11153
|
+
}
|
|
11154
|
+
),
|
|
11155
|
+
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." }),
|
|
11156
|
+
members.map((member) => /* @__PURE__ */ jsx29(
|
|
11157
|
+
MemberRow2,
|
|
11158
|
+
{
|
|
11159
|
+
member,
|
|
11160
|
+
onEdit: canManage && api.updateCreditPoolMember ? () => setEditing(member) : void 0,
|
|
11161
|
+
onRemove: canManage && api.removeCreditPoolMember ? () => setRemoving(member) : void 0
|
|
11162
|
+
},
|
|
11163
|
+
member._id
|
|
11164
|
+
))
|
|
11165
|
+
]
|
|
10954
11166
|
}
|
|
10955
11167
|
)
|
|
10956
11168
|
] }),
|
|
@@ -10959,6 +11171,7 @@ function SharedCreditsView() {
|
|
|
10959
11171
|
{
|
|
10960
11172
|
kind: "add",
|
|
10961
11173
|
candidates,
|
|
11174
|
+
unallocatedPercent: poolUnallocatedPercent(data),
|
|
10962
11175
|
onSave: (input) => api.addCreditPoolMember(input),
|
|
10963
11176
|
onClose: () => setAdding(false),
|
|
10964
11177
|
onSaved: () => void load({ refresh: true })
|
|
@@ -10970,11 +11183,34 @@ function SharedCreditsView() {
|
|
|
10970
11183
|
kind: "edit",
|
|
10971
11184
|
member: editing,
|
|
10972
11185
|
memberName: poolWorkspaceName(editing.memberWorkspaceName),
|
|
11186
|
+
unallocatedPercent: poolUnallocatedPercent(data, editing._id),
|
|
10973
11187
|
onSave: (patch) => api.updateCreditPoolMember(editing._id, patch),
|
|
10974
11188
|
onClose: () => setEditing(null),
|
|
10975
11189
|
onSaved: () => void load({ refresh: true })
|
|
10976
11190
|
}
|
|
10977
11191
|
),
|
|
11192
|
+
settingSelf && api.setCreditPoolSelfShare && /* @__PURE__ */ jsx29(
|
|
11193
|
+
CreditPoolMemberModal,
|
|
11194
|
+
{
|
|
11195
|
+
kind: "self",
|
|
11196
|
+
self,
|
|
11197
|
+
workspaceName: selfName,
|
|
11198
|
+
unallocatedPercent: poolUnallocatedPercent(data, "self"),
|
|
11199
|
+
onSave: (input) => api.setCreditPoolSelfShare(input),
|
|
11200
|
+
onClose: () => setSettingSelf(false),
|
|
11201
|
+
onSaved: () => void load({ refresh: true })
|
|
11202
|
+
}
|
|
11203
|
+
),
|
|
11204
|
+
removingSelf && self && api.removeCreditPoolSelfShare && /* @__PURE__ */ jsx29(
|
|
11205
|
+
RemoveSelfShareModal,
|
|
11206
|
+
{
|
|
11207
|
+
self,
|
|
11208
|
+
workspaceName: selfName,
|
|
11209
|
+
onRemove: () => api.removeCreditPoolSelfShare(),
|
|
11210
|
+
onClose: () => setRemovingSelf(false),
|
|
11211
|
+
onRemoved: () => void load({ refresh: true })
|
|
11212
|
+
}
|
|
11213
|
+
),
|
|
10978
11214
|
removing && api.removeCreditPoolMember && /* @__PURE__ */ jsx29(
|
|
10979
11215
|
RemovePoolMemberModal,
|
|
10980
11216
|
{
|
|
@@ -12552,6 +12788,7 @@ function BillingContent({
|
|
|
12552
12788
|
);
|
|
12553
12789
|
const [availableCredits, setAvailableCredits] = useState22(null);
|
|
12554
12790
|
const [sharedPool, setSharedPool] = useState22(null);
|
|
12791
|
+
const [sponsorShare, setSponsorShare] = useState22(null);
|
|
12555
12792
|
const [usedByNames, setUsedByNames] = useState22({});
|
|
12556
12793
|
const [allProducts, setProducts] = useState22([]);
|
|
12557
12794
|
const workspaceCountry = workspace.current?.country;
|
|
@@ -12642,6 +12879,7 @@ function BillingContent({
|
|
|
12642
12879
|
if (creditsRes?.availableCredits != null)
|
|
12643
12880
|
setAvailableCredits(creditsRes.availableCredits);
|
|
12644
12881
|
setSharedPool(creditsRes?.sharedPool ?? null);
|
|
12882
|
+
setSponsorShare(creditsRes?.sponsorShare ?? null);
|
|
12645
12883
|
if (productsRes?.data) setProducts(productsRes.data);
|
|
12646
12884
|
if (customRes?.data?.credits != null) {
|
|
12647
12885
|
setCustomPlanCredits(customRes.data.credits);
|
|
@@ -12930,7 +13168,7 @@ function BillingContent({
|
|
|
12930
13168
|
remaining: remainingCredits,
|
|
12931
13169
|
progressPct,
|
|
12932
13170
|
remainingPct
|
|
12933
|
-
} = creditsMeter({ availableCredits, totalCredits, sharedPool });
|
|
13171
|
+
} = creditsMeter({ availableCredits, totalCredits, sharedPool, sponsorShare });
|
|
12934
13172
|
const usageText = usedCredits != null ? formatCredits2(usedCredits) : remainingCredits != null ? `${formatCredits2(remainingCredits)} available` : customPlanCredits != null ? `${formatCredits2(customPlanCredits)} credits` : "\u2014";
|
|
12935
13173
|
const handleExport = async (startDate, endDate) => {
|
|
12936
13174
|
const end = new Date(endDate);
|
|
@@ -13343,6 +13581,49 @@ function BillingContent({
|
|
|
13343
13581
|
]
|
|
13344
13582
|
}
|
|
13345
13583
|
)
|
|
13584
|
+
) : sponsorShare ? (
|
|
13585
|
+
// A sponsor keeping only a share of its credits: what is left of it.
|
|
13586
|
+
/* @__PURE__ */ jsxs27(
|
|
13587
|
+
"div",
|
|
13588
|
+
{
|
|
13589
|
+
role: "status",
|
|
13590
|
+
className: "flex flex-col shrink-0 w-full",
|
|
13591
|
+
style: {
|
|
13592
|
+
gap: 4,
|
|
13593
|
+
padding: 16,
|
|
13594
|
+
backgroundColor: "var(--alias-surface-base)",
|
|
13595
|
+
border: "1px solid var(--alias-border-subtle)",
|
|
13596
|
+
borderRadius: "var(--radius-3xl)"
|
|
13597
|
+
},
|
|
13598
|
+
children: [
|
|
13599
|
+
/* @__PURE__ */ jsx30(
|
|
13600
|
+
"span",
|
|
13601
|
+
{
|
|
13602
|
+
style: {
|
|
13603
|
+
fontFamily: "var(--font-family-font-family-body)",
|
|
13604
|
+
fontSize: "var(--font-size-font-size-sm)",
|
|
13605
|
+
fontWeight: 500,
|
|
13606
|
+
lineHeight: "var(--line-height-line-height-sm)",
|
|
13607
|
+
color: sponsorShare.remaining <= 0 ? "var(--alias-text---icons-warning)" : "var(--alias-text---icons-primary)"
|
|
13608
|
+
},
|
|
13609
|
+
children: sponsorShareBannerText(sponsorShare)
|
|
13610
|
+
}
|
|
13611
|
+
),
|
|
13612
|
+
/* @__PURE__ */ jsx30(
|
|
13613
|
+
"span",
|
|
13614
|
+
{
|
|
13615
|
+
style: {
|
|
13616
|
+
fontFamily: "var(--font-family-font-family-body)",
|
|
13617
|
+
fontSize: "var(--font-size-font-size-sm)",
|
|
13618
|
+
lineHeight: "var(--line-height-line-height-sm)",
|
|
13619
|
+
color: "var(--alias-text---icons-muted)"
|
|
13620
|
+
},
|
|
13621
|
+
children: sponsorShareDetailText()
|
|
13622
|
+
}
|
|
13623
|
+
)
|
|
13624
|
+
]
|
|
13625
|
+
}
|
|
13626
|
+
)
|
|
13346
13627
|
) : null,
|
|
13347
13628
|
usage ? /* @__PURE__ */ jsxs27(
|
|
13348
13629
|
"div",
|
|
@@ -18408,6 +18689,7 @@ export {
|
|
|
18408
18689
|
ReferralHistoryView,
|
|
18409
18690
|
ReferralTab,
|
|
18410
18691
|
RemovePoolMemberModal,
|
|
18692
|
+
RemoveSelfShareModal,
|
|
18411
18693
|
SCOPE_LABELS,
|
|
18412
18694
|
ScopeHeader,
|
|
18413
18695
|
SettingsAdaptersProvider,
|
|
@@ -18441,6 +18723,7 @@ export {
|
|
|
18441
18723
|
belowUsageReason,
|
|
18442
18724
|
canManageOnlyWorkspaceCreditLimit,
|
|
18443
18725
|
canShowSharedCredits,
|
|
18726
|
+
checkPoolPercentTotal,
|
|
18444
18727
|
cleanCreditLimitInput,
|
|
18445
18728
|
cleanPoolValueInput,
|
|
18446
18729
|
countLabel,
|
|
@@ -18486,9 +18769,12 @@ export {
|
|
|
18486
18769
|
parseBillingEntitlement,
|
|
18487
18770
|
parseInviteEmails,
|
|
18488
18771
|
pausedOwnCreditsText,
|
|
18772
|
+
poolAllocatedPercent,
|
|
18773
|
+
poolAllocationText,
|
|
18489
18774
|
poolEndsAtFrom,
|
|
18490
18775
|
poolErrorMessage,
|
|
18491
18776
|
poolRenewsAtCycleEnd,
|
|
18777
|
+
poolUnallocatedPercent,
|
|
18492
18778
|
poolWorkspaceName,
|
|
18493
18779
|
productsForCountry,
|
|
18494
18780
|
readSettingsCaller,
|
|
@@ -18504,6 +18790,9 @@ export {
|
|
|
18504
18790
|
sharedPoolEndsText,
|
|
18505
18791
|
sliceUsageLogsPage,
|
|
18506
18792
|
sortReferredUsers,
|
|
18793
|
+
sponsorShareBannerText,
|
|
18794
|
+
sponsorShareDetailText,
|
|
18795
|
+
sponsorShareSpentText,
|
|
18507
18796
|
sponsoredCreditsText,
|
|
18508
18797
|
ssoLabel,
|
|
18509
18798
|
toCsv,
|