@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.js
CHANGED
|
@@ -61,6 +61,7 @@ __export(index_exports, {
|
|
|
61
61
|
ReferralHistoryView: () => ReferralHistoryView,
|
|
62
62
|
ReferralTab: () => ReferralTab,
|
|
63
63
|
RemovePoolMemberModal: () => RemovePoolMemberModal,
|
|
64
|
+
RemoveSelfShareModal: () => RemoveSelfShareModal,
|
|
64
65
|
SCOPE_LABELS: () => SCOPE_LABELS,
|
|
65
66
|
ScopeHeader: () => ScopeHeader,
|
|
66
67
|
SettingsAdaptersProvider: () => SettingsAdaptersProvider,
|
|
@@ -94,6 +95,7 @@ __export(index_exports, {
|
|
|
94
95
|
belowUsageReason: () => belowUsageReason,
|
|
95
96
|
canManageOnlyWorkspaceCreditLimit: () => canManageOnlyWorkspaceCreditLimit,
|
|
96
97
|
canShowSharedCredits: () => canShowSharedCredits,
|
|
98
|
+
checkPoolPercentTotal: () => checkPoolPercentTotal,
|
|
97
99
|
cleanCreditLimitInput: () => cleanCreditLimitInput,
|
|
98
100
|
cleanPoolValueInput: () => cleanPoolValueInput,
|
|
99
101
|
countLabel: () => countLabel,
|
|
@@ -139,9 +141,12 @@ __export(index_exports, {
|
|
|
139
141
|
parseBillingEntitlement: () => parseBillingEntitlement,
|
|
140
142
|
parseInviteEmails: () => parseInviteEmails,
|
|
141
143
|
pausedOwnCreditsText: () => pausedOwnCreditsText,
|
|
144
|
+
poolAllocatedPercent: () => poolAllocatedPercent,
|
|
145
|
+
poolAllocationText: () => poolAllocationText,
|
|
142
146
|
poolEndsAtFrom: () => poolEndsAtFrom,
|
|
143
147
|
poolErrorMessage: () => poolErrorMessage,
|
|
144
148
|
poolRenewsAtCycleEnd: () => poolRenewsAtCycleEnd,
|
|
149
|
+
poolUnallocatedPercent: () => poolUnallocatedPercent,
|
|
145
150
|
poolWorkspaceName: () => poolWorkspaceName,
|
|
146
151
|
productsForCountry: () => productsForCountry,
|
|
147
152
|
readSettingsCaller: () => readSettingsCaller,
|
|
@@ -157,6 +162,9 @@ __export(index_exports, {
|
|
|
157
162
|
sharedPoolEndsText: () => sharedPoolEndsText,
|
|
158
163
|
sliceUsageLogsPage: () => sliceUsageLogsPage,
|
|
159
164
|
sortReferredUsers: () => sortReferredUsers,
|
|
165
|
+
sponsorShareBannerText: () => sponsorShareBannerText,
|
|
166
|
+
sponsorShareDetailText: () => sponsorShareDetailText,
|
|
167
|
+
sponsorShareSpentText: () => sponsorShareSpentText,
|
|
160
168
|
sponsoredCreditsText: () => sponsoredCreditsText,
|
|
161
169
|
ssoLabel: () => ssoLabel,
|
|
162
170
|
toCsv: () => toCsv,
|
|
@@ -10169,6 +10177,32 @@ function validatePoolText(raw, max) {
|
|
|
10169
10177
|
if (value.length > max) return { ok: false, reason: `At most ${max} characters` };
|
|
10170
10178
|
return { ok: true, value };
|
|
10171
10179
|
}
|
|
10180
|
+
var round2 = (value) => Math.round(value * 100) / 100;
|
|
10181
|
+
function poolAllocatedPercent(pool, exclude) {
|
|
10182
|
+
if (!pool) return 0;
|
|
10183
|
+
if (exclude === void 0 && typeof pool.allocatedPercent === "number") return round2(pool.allocatedPercent);
|
|
10184
|
+
let total = 0;
|
|
10185
|
+
if (exclude !== "self" && pool.self?.mode === "percent") total += pool.self.value;
|
|
10186
|
+
for (const member of pool.members ?? []) {
|
|
10187
|
+
if (member._id !== exclude && member.mode === "percent") total += member.value;
|
|
10188
|
+
}
|
|
10189
|
+
return round2(total);
|
|
10190
|
+
}
|
|
10191
|
+
function poolUnallocatedPercent(pool, exclude) {
|
|
10192
|
+
return Math.max(0, round2(100 - poolAllocatedPercent(pool, exclude)));
|
|
10193
|
+
}
|
|
10194
|
+
function checkPoolPercentTotal(split, unallocatedPercent) {
|
|
10195
|
+
if (split.mode !== "percent" || round2(split.value) <= round2(unallocatedPercent)) return { ok: true };
|
|
10196
|
+
const left = formatCredits(Math.max(0, unallocatedPercent));
|
|
10197
|
+
return {
|
|
10198
|
+
ok: false,
|
|
10199
|
+
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."
|
|
10200
|
+
};
|
|
10201
|
+
}
|
|
10202
|
+
function poolAllocationText(pool) {
|
|
10203
|
+
const allocated = poolAllocatedPercent(pool);
|
|
10204
|
+
return `Allocated ${formatCredits(allocated)}% \xB7 Unallocated ${formatCredits(Math.max(0, round2(100 - allocated)))}%`;
|
|
10205
|
+
}
|
|
10172
10206
|
var credits = (value) => `${formatCredits(value)} ${value === 1 ? "credit" : "credits"}`;
|
|
10173
10207
|
function formatPoolSplit(split) {
|
|
10174
10208
|
if (split.mode === "percent") return `${formatCredits(split.value)}%`;
|
|
@@ -10255,6 +10289,16 @@ function sharedPoolBannerText(pool) {
|
|
|
10255
10289
|
const sponsor = pool.sponsorName?.trim() || "another workspace";
|
|
10256
10290
|
return `Credits shared by ${sponsor}: ${formatCredits(pool.remaining)} of ${formatCredits(pool.allowance)} left this cycle`;
|
|
10257
10291
|
}
|
|
10292
|
+
function sponsorShareSpentText() {
|
|
10293
|
+
return "This workspace has used its share of the credits for this cycle.";
|
|
10294
|
+
}
|
|
10295
|
+
function sponsorShareBannerText(share) {
|
|
10296
|
+
if (share.remaining <= 0) return sponsorShareSpentText();
|
|
10297
|
+
return `This workspace's share: ${formatCredits(share.remaining)} of ${credits(share.allowance)} left this cycle`;
|
|
10298
|
+
}
|
|
10299
|
+
function sponsorShareDetailText() {
|
|
10300
|
+
return "The rest of this workspace's credits are kept for the workspaces it shares them with. Organization admins change this in Shared credits.";
|
|
10301
|
+
}
|
|
10258
10302
|
function pausedOwnCreditsText(_pool) {
|
|
10259
10303
|
return ownCreditsFirstText();
|
|
10260
10304
|
}
|
|
@@ -10264,8 +10308,16 @@ function ownCreditsFirstText() {
|
|
|
10264
10308
|
function creditsMeter({
|
|
10265
10309
|
availableCredits,
|
|
10266
10310
|
totalCredits,
|
|
10267
|
-
sharedPool
|
|
10311
|
+
sharedPool,
|
|
10312
|
+
sponsorShare = null
|
|
10268
10313
|
}) {
|
|
10314
|
+
if (sponsorShare && !sharedPool) {
|
|
10315
|
+
const used2 = Math.max(0, sponsorShare.used);
|
|
10316
|
+
const left = Math.max(0, sponsorShare.remaining);
|
|
10317
|
+
const remaining = availableCredits != null ? Math.min(left, Math.max(0, availableCredits)) : left;
|
|
10318
|
+
const progressPct2 = sponsorShare.allowance > 0 ? Math.min(100, Math.round(used2 / sponsorShare.allowance * 100)) : 100;
|
|
10319
|
+
return { used: used2, remaining, progressPct: progressPct2, remainingPct: 100 - progressPct2 };
|
|
10320
|
+
}
|
|
10269
10321
|
if (sharedPool && availableCredits != null && totalCredits != null) {
|
|
10270
10322
|
const total = Math.max(0, totalCredits) + Math.max(0, sharedPool.allowance);
|
|
10271
10323
|
const used2 = Math.max(0, total - availableCredits);
|
|
@@ -10476,18 +10528,31 @@ var EXPIRY_OPTIONS = [
|
|
|
10476
10528
|
];
|
|
10477
10529
|
var isExpiryKind = (id) => EXPIRY_OPTIONS.some((o) => o.id === id);
|
|
10478
10530
|
var endsText = (member) => member.endsAt ? `, until ${formatPoolEndsAt(member.endsAt)}` : "";
|
|
10479
|
-
function endsAtHelp(kind, endsAt) {
|
|
10480
|
-
if (kind === "never")
|
|
10531
|
+
function endsAtHelp(kind, endsAt, self) {
|
|
10532
|
+
if (kind === "never") {
|
|
10533
|
+
return self ? "Applies every billing cycle until it is removed." : "Shares every billing cycle until it is removed.";
|
|
10534
|
+
}
|
|
10535
|
+
if (self) {
|
|
10536
|
+
const stop2 = "After that, this workspace may spend all its credits again.";
|
|
10537
|
+
return endsAt ? `The share ends on ${formatPoolEndsAt(endsAt)}. ${stop2}` : stop2;
|
|
10538
|
+
}
|
|
10481
10539
|
const stop = "After that, the other workspace spends only its own credits.";
|
|
10482
10540
|
return endsAt ? `Sharing stops on ${formatPoolEndsAt(endsAt)}. ${stop}` : stop;
|
|
10483
10541
|
}
|
|
10542
|
+
function valueHelp(kind, mode) {
|
|
10543
|
+
if (kind === "self") {
|
|
10544
|
+
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%.";
|
|
10545
|
+
}
|
|
10546
|
+
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.";
|
|
10547
|
+
}
|
|
10484
10548
|
function CreditPoolMemberModal(props) {
|
|
10485
10549
|
const { toast } = useSettingsAdapters();
|
|
10486
|
-
const editing = props.kind === "edit" ? props.member : null;
|
|
10550
|
+
const editing = props.kind === "edit" ? props.member : props.kind === "self" ? props.self : null;
|
|
10551
|
+
const initialNote = props.kind === "self" ? props.self?.note ?? "" : "";
|
|
10487
10552
|
const [memberId, setMemberId] = (0, import_react21.useState)("");
|
|
10488
10553
|
const [mode, setMode] = (0, import_react21.useState)(editing?.mode ?? "percent");
|
|
10489
10554
|
const [raw, setRaw] = (0, import_react21.useState)(editing ? String(editing.value) : "");
|
|
10490
|
-
const [note, setNote] = (0, import_react21.useState)(
|
|
10555
|
+
const [note, setNote] = (0, import_react21.useState)(initialNote);
|
|
10491
10556
|
const [touched, setTouched] = (0, import_react21.useState)(false);
|
|
10492
10557
|
const [saving, setSaving] = (0, import_react21.useState)(false);
|
|
10493
10558
|
const [serverError, setServerError] = (0, import_react21.useState)(null);
|
|
@@ -10504,10 +10569,13 @@ function CreditPoolMemberModal(props) {
|
|
|
10504
10569
|
const endsAtUnchanged = Boolean(editing) && expiry.kind === initialExpiry.kind && (expiry.kind !== "date" || initialExpiry.kind === "date" && expiry.date === initialExpiry.date);
|
|
10505
10570
|
const endsAt = endsAtUnchanged ? null : poolEndsAtFrom(expiry);
|
|
10506
10571
|
const splitChanged = !editing || mode !== editing.mode || !value.ok || value.value !== editing.value;
|
|
10507
|
-
const
|
|
10508
|
-
const
|
|
10572
|
+
const noteChanged = props.kind === "self" && note.trim() !== initialNote.trim();
|
|
10573
|
+
const changed = splitChanged || !endsAtUnchanged || noteChanged;
|
|
10574
|
+
const percentTotal = value.ok && props.unallocatedPercent !== void 0 ? checkPoolPercentTotal({ mode, value: value.value }, props.unallocatedPercent) : null;
|
|
10575
|
+
const valid = value.ok && (percentTotal === null || percentTotal.ok) && (endsAt === null || endsAt.ok) && (props.kind === "edit" || (props.kind === "self" || Boolean(memberId)) && noteCheck.ok);
|
|
10509
10576
|
const canSave = !saving && changed && valid;
|
|
10510
|
-
const valueHint = touched && !value.ok ? value.reason : null;
|
|
10577
|
+
const valueHint = touched && !value.ok ? value.reason : percentTotal && !percentTotal.ok ? percentTotal.reason : null;
|
|
10578
|
+
const unallocatedHint = mode === "percent" && props.unallocatedPercent !== void 0 ? ` ${formatCredits(Math.max(0, props.unallocatedPercent))}% is unallocated.` : "";
|
|
10511
10579
|
const expiryHint = endsAt && !endsAt.ok && !(expiry.kind === "date" && !expiry.date) ? endsAt.reason : null;
|
|
10512
10580
|
const handleSave = async () => {
|
|
10513
10581
|
if (!canSave || !value.ok) return;
|
|
@@ -10524,6 +10592,17 @@ function CreditPoolMemberModal(props) {
|
|
|
10524
10592
|
...sendEndsAt?.value ? { endsAt: sendEndsAt.value } : {}
|
|
10525
10593
|
});
|
|
10526
10594
|
toast.success(`Credits shared. ${describeAllowance(added)}${endsText(added)}.`);
|
|
10595
|
+
} else if (props.kind === "self") {
|
|
10596
|
+
const nextEndsAt = sendEndsAt ? sendEndsAt.value : props.self?.endsAt ?? null;
|
|
10597
|
+
await props.onSave({
|
|
10598
|
+
mode,
|
|
10599
|
+
value: value.value,
|
|
10600
|
+
note: noteCheck.ok ? noteCheck.value : "",
|
|
10601
|
+
endsAt: nextEndsAt
|
|
10602
|
+
});
|
|
10603
|
+
toast.success(
|
|
10604
|
+
`This workspace's share is ${formatPoolSplit({ mode, value: value.value })} each billing cycle${endsText({ endsAt: nextEndsAt })}.`
|
|
10605
|
+
);
|
|
10527
10606
|
} else {
|
|
10528
10607
|
const updated = await props.onSave({
|
|
10529
10608
|
mode,
|
|
@@ -10537,7 +10616,10 @@ function CreditPoolMemberModal(props) {
|
|
|
10537
10616
|
} catch (err) {
|
|
10538
10617
|
const message = poolErrorMessage(err);
|
|
10539
10618
|
if (message) setServerError(message);
|
|
10540
|
-
else
|
|
10619
|
+
else {
|
|
10620
|
+
const method = props.kind === "add" ? "POST" : props.kind === "self" ? "PUT" : "PATCH";
|
|
10621
|
+
toast.error(errorMessage(err, { method }));
|
|
10622
|
+
}
|
|
10541
10623
|
setSaving(false);
|
|
10542
10624
|
}
|
|
10543
10625
|
};
|
|
@@ -10545,7 +10627,7 @@ function CreditPoolMemberModal(props) {
|
|
|
10545
10627
|
return /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)(
|
|
10546
10628
|
PoolModalShell,
|
|
10547
10629
|
{
|
|
10548
|
-
title: props.kind === "add" ? "Share credits" : "Edit shared credits",
|
|
10630
|
+
title: props.kind === "add" ? "Share credits" : props.kind === "edit" ? "Edit shared credits" : props.self ? "Edit this workspace's share" : "Set this workspace's share",
|
|
10549
10631
|
busy: saving,
|
|
10550
10632
|
onClose: props.onClose,
|
|
10551
10633
|
footer: /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)(import_jsx_runtime27.Fragment, { children: [
|
|
@@ -10572,7 +10654,7 @@ function CreditPoolMemberModal(props) {
|
|
|
10572
10654
|
] }),
|
|
10573
10655
|
children: [
|
|
10574
10656
|
/* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("div", { className: "flex flex-col w-full", style: { gap: T17.spXs }, children: [
|
|
10575
|
-
/* @__PURE__ */ (0, import_jsx_runtime27.jsx)("span", { style: fieldLabel, children: "Share with" }),
|
|
10657
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsx)("span", { style: fieldLabel, children: props.kind === "self" ? "Workspace" : "Share with" }),
|
|
10576
10658
|
props.kind === "add" ? candidateOptions.length ? /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
|
|
10577
10659
|
import_ui15.ScSelect,
|
|
10578
10660
|
{
|
|
@@ -10582,7 +10664,7 @@ function CreditPoolMemberModal(props) {
|
|
|
10582
10664
|
placeholder: "Choose a workspace",
|
|
10583
10665
|
disabled: saving
|
|
10584
10666
|
}
|
|
10585
|
-
) : /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("span", { style: { ...modalBodyText, color: T17.muted }, children: "There are no other workspaces in this organization to share credits with." }) : /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("span", { style: { ...modalBodyText, color: T17.primary }, children: props.memberName })
|
|
10667
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("span", { style: { ...modalBodyText, color: T17.muted }, children: "There are no other workspaces in this organization to share credits with." }) : /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("span", { style: { ...modalBodyText, color: T17.primary }, children: props.kind === "self" ? props.workspaceName : props.memberName })
|
|
10586
10668
|
] }),
|
|
10587
10669
|
/* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("div", { className: "flex flex-col w-full", style: { gap: T17.spMd }, children: [
|
|
10588
10670
|
/* @__PURE__ */ (0, import_jsx_runtime27.jsx)("span", { style: fieldLabel, children: "How much, each billing cycle" }),
|
|
@@ -10641,7 +10723,8 @@ function CreditPoolMemberModal(props) {
|
|
|
10641
10723
|
}
|
|
10642
10724
|
),
|
|
10643
10725
|
valueHint ? /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("span", { role: "alert", style: { ...modalBodyText, color: T17.error }, children: valueHint }) : /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("span", { style: { ...modalBodyText, color: T17.tertiary }, children: [
|
|
10644
|
-
|
|
10726
|
+
valueHelp(props.kind, mode),
|
|
10727
|
+
unallocatedHint,
|
|
10645
10728
|
editing ? " Applies immediately." : ""
|
|
10646
10729
|
] })
|
|
10647
10730
|
] }),
|
|
@@ -10709,16 +10792,20 @@ function CreditPoolMemberModal(props) {
|
|
|
10709
10792
|
)
|
|
10710
10793
|
}
|
|
10711
10794
|
),
|
|
10712
|
-
expiryHint ? /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("span", { role: "alert", style: { ...modalBodyText, color: T17.error }, children: expiryHint }) : /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("span", { style: { ...modalBodyText, color: T17.tertiary }, children: endsAtHelp(
|
|
10795
|
+
expiryHint ? /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("span", { role: "alert", style: { ...modalBodyText, color: T17.error }, children: expiryHint }) : /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("span", { style: { ...modalBodyText, color: T17.tertiary }, children: endsAtHelp(
|
|
10796
|
+
expiryKind,
|
|
10797
|
+
endsAtUnchanged ? editing?.endsAt ?? null : endsAt?.ok ? endsAt.value : null,
|
|
10798
|
+
props.kind === "self"
|
|
10799
|
+
) })
|
|
10713
10800
|
] }),
|
|
10714
|
-
props.kind
|
|
10801
|
+
props.kind !== "edit" && /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("div", { className: "flex flex-col w-full", style: { gap: T17.spXs }, children: [
|
|
10715
10802
|
/* @__PURE__ */ (0, import_jsx_runtime27.jsx)("span", { style: fieldLabel, children: "Note" }),
|
|
10716
10803
|
/* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
|
|
10717
10804
|
import_ui15.ScTextArea,
|
|
10718
10805
|
{
|
|
10719
10806
|
value: note,
|
|
10720
10807
|
maxLength: POOL_NOTE_MAX_LENGTH,
|
|
10721
|
-
placeholder: "Why are these credits being shared?",
|
|
10808
|
+
placeholder: props.kind === "self" ? "Why does this workspace keep only this share?" : "Why are these credits being shared?",
|
|
10722
10809
|
disabled: saving,
|
|
10723
10810
|
onChange: (e) => setNote(e.target.value),
|
|
10724
10811
|
rows: 3,
|
|
@@ -10831,6 +10918,73 @@ function RemovePoolMemberModal({
|
|
|
10831
10918
|
}
|
|
10832
10919
|
);
|
|
10833
10920
|
}
|
|
10921
|
+
function RemoveSelfShareModal({
|
|
10922
|
+
self,
|
|
10923
|
+
workspaceName,
|
|
10924
|
+
onRemove,
|
|
10925
|
+
onClose,
|
|
10926
|
+
onRemoved
|
|
10927
|
+
}) {
|
|
10928
|
+
const { toast } = useSettingsAdapters();
|
|
10929
|
+
const [saving, setSaving] = (0, import_react22.useState)(false);
|
|
10930
|
+
const handleConfirm = async () => {
|
|
10931
|
+
if (saving) return;
|
|
10932
|
+
setSaving(true);
|
|
10933
|
+
try {
|
|
10934
|
+
await onRemove();
|
|
10935
|
+
toast.success(`${workspaceName} can spend all its credits again`);
|
|
10936
|
+
onRemoved();
|
|
10937
|
+
onClose();
|
|
10938
|
+
} catch (err) {
|
|
10939
|
+
toast.error(errorMessage(err, { method: "DELETE" }));
|
|
10940
|
+
setSaving(false);
|
|
10941
|
+
}
|
|
10942
|
+
};
|
|
10943
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)(
|
|
10944
|
+
PoolModalShell,
|
|
10945
|
+
{
|
|
10946
|
+
title: "Remove this workspace's share",
|
|
10947
|
+
busy: saving,
|
|
10948
|
+
onClose,
|
|
10949
|
+
footer: /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)(import_jsx_runtime28.Fragment, { children: [
|
|
10950
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
|
|
10951
|
+
import_ui16.ScButton,
|
|
10952
|
+
{
|
|
10953
|
+
text: "Keep share",
|
|
10954
|
+
variant: "secondary",
|
|
10955
|
+
size: "md",
|
|
10956
|
+
state: saving ? "disabled" : "default",
|
|
10957
|
+
onClick: saving ? void 0 : onClose
|
|
10958
|
+
}
|
|
10959
|
+
),
|
|
10960
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
|
|
10961
|
+
import_ui16.ScButton,
|
|
10962
|
+
{
|
|
10963
|
+
text: "Remove share",
|
|
10964
|
+
variant: "error",
|
|
10965
|
+
size: "md",
|
|
10966
|
+
state: saving ? "disabled" : "default",
|
|
10967
|
+
onClick: saving ? void 0 : () => void handleConfirm()
|
|
10968
|
+
}
|
|
10969
|
+
)
|
|
10970
|
+
] }),
|
|
10971
|
+
children: [
|
|
10972
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("span", { style: { ...modalBodyText, color: MODAL_T.primary }, children: [
|
|
10973
|
+
workspaceName,
|
|
10974
|
+
" may spend its whole balance again, starting now."
|
|
10975
|
+
] }),
|
|
10976
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("span", { style: { ...modalBodyText, color: MODAL_T.tertiary }, children: [
|
|
10977
|
+
"It kept ",
|
|
10978
|
+
describeAllowance(self),
|
|
10979
|
+
" and has used ",
|
|
10980
|
+
formatCredits(self.used),
|
|
10981
|
+
".",
|
|
10982
|
+
self.mode === "percent" ? ` Its ${formatPoolSplit(self)} goes back to unallocated, so other workspaces can be given more.` : ""
|
|
10983
|
+
] })
|
|
10984
|
+
]
|
|
10985
|
+
}
|
|
10986
|
+
);
|
|
10987
|
+
}
|
|
10834
10988
|
|
|
10835
10989
|
// src/shared-credits-view.tsx
|
|
10836
10990
|
var import_jsx_runtime29 = require("react/jsx-runtime");
|
|
@@ -10913,10 +11067,49 @@ function MemberRow2({
|
|
|
10913
11067
|
}
|
|
10914
11068
|
);
|
|
10915
11069
|
}
|
|
11070
|
+
function SelfShareRow({
|
|
11071
|
+
self,
|
|
11072
|
+
onSet,
|
|
11073
|
+
onRemove
|
|
11074
|
+
}) {
|
|
11075
|
+
const spent = Boolean(self) && self.remaining <= 0;
|
|
11076
|
+
return /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)(
|
|
11077
|
+
"div",
|
|
11078
|
+
{
|
|
11079
|
+
style: {
|
|
11080
|
+
borderBottom: `1px solid ${T18.borderSubtle}`,
|
|
11081
|
+
display: "grid",
|
|
11082
|
+
gridTemplateColumns: MEMBER_COLUMNS2,
|
|
11083
|
+
alignItems: "center",
|
|
11084
|
+
padding: `10px ${T18.sp3xl}`,
|
|
11085
|
+
gap: MEMBER_GAP,
|
|
11086
|
+
backgroundColor: T18.fillPlus
|
|
11087
|
+
},
|
|
11088
|
+
children: [
|
|
11089
|
+
/* @__PURE__ */ (0, import_jsx_runtime29.jsxs)("div", { className: "flex flex-col min-w-0", style: { gap: 2 }, children: [
|
|
11090
|
+
/* @__PURE__ */ (0, import_jsx_runtime29.jsx)("span", { className: "truncate", style: { ...cellText3, fontWeight: 500 }, children: "This workspace" }),
|
|
11091
|
+
self?.note && /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("span", { className: "truncate", title: self.note, style: { ...cellText3, color: T18.tertiary }, children: self.note })
|
|
11092
|
+
] }),
|
|
11093
|
+
self ? /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)("div", { className: "flex flex-col min-w-0", style: { gap: 2 }, children: [
|
|
11094
|
+
/* @__PURE__ */ (0, import_jsx_runtime29.jsx)("span", { style: cellText3, children: formatPoolSplit({ mode: "fixed", value: self.allowance }) }),
|
|
11095
|
+
/* @__PURE__ */ (0, import_jsx_runtime29.jsx)("span", { style: { ...cellText3, color: T18.tertiary }, children: self.mode === "percent" ? `${formatPoolSplit(self)} \xB7 this cycle` : "this cycle" })
|
|
11096
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("span", { style: { ...cellText3, color: T18.muted }, children: "All its credits" }),
|
|
11097
|
+
/* @__PURE__ */ (0, import_jsx_runtime29.jsx)("span", { style: { ...cellText3, color: self ? T18.primary : T18.muted }, children: self ? formatCredits(self.used) : "\u2014" }),
|
|
11098
|
+
/* @__PURE__ */ (0, import_jsx_runtime29.jsx)("span", { style: { ...cellText3, color: !self ? T18.muted : spent ? T18.warning : T18.primary }, children: self ? formatCredits(self.remaining) : "\u2014" }),
|
|
11099
|
+
/* @__PURE__ */ (0, import_jsx_runtime29.jsx)("span", { style: { ...cellText3, color: self?.endsAt ? T18.primary : T18.muted }, children: self ? formatPoolEndsAt(self.endsAt) : "\u2014" }),
|
|
11100
|
+
/* @__PURE__ */ (0, import_jsx_runtime29.jsxs)("div", { className: "flex items-center whitespace-nowrap", style: { gap: 8 }, children: [
|
|
11101
|
+
onSet && /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(import_ui17.ScButton, { text: self ? "Edit" : "Set share", variant: "secondary", size: "sm", onClick: onSet }),
|
|
11102
|
+
self && onRemove && /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(import_ui17.ScButton, { text: "Remove", variant: "secondary", size: "sm", onClick: onRemove })
|
|
11103
|
+
] })
|
|
11104
|
+
]
|
|
11105
|
+
}
|
|
11106
|
+
);
|
|
11107
|
+
}
|
|
10916
11108
|
function SharedCreditsView() {
|
|
10917
11109
|
const { api, workspace, toast } = useSettingsAdapters();
|
|
10918
11110
|
const workspaceId = workspace.current?.id ?? null;
|
|
10919
11111
|
const workspaceName = workspace.current?.name?.trim() || "this workspace";
|
|
11112
|
+
const selfName = workspace.current?.name?.trim() || "This workspace";
|
|
10920
11113
|
const [data, setData] = (0, import_react23.useState)(null);
|
|
10921
11114
|
const [loading, setLoading] = (0, import_react23.useState)(true);
|
|
10922
11115
|
const [failed, setFailed] = (0, import_react23.useState)(false);
|
|
@@ -10924,6 +11117,8 @@ function SharedCreditsView() {
|
|
|
10924
11117
|
const [adding, setAdding] = (0, import_react23.useState)(false);
|
|
10925
11118
|
const [editing, setEditing] = (0, import_react23.useState)(null);
|
|
10926
11119
|
const [removing, setRemoving] = (0, import_react23.useState)(null);
|
|
11120
|
+
const [settingSelf, setSettingSelf] = (0, import_react23.useState)(false);
|
|
11121
|
+
const [removingSelf, setRemovingSelf] = (0, import_react23.useState)(false);
|
|
10927
11122
|
const latestLoad = (0, import_react23.useRef)(0);
|
|
10928
11123
|
const load = (0, import_react23.useCallback)(
|
|
10929
11124
|
async ({ refresh = false } = {}) => {
|
|
@@ -10952,6 +11147,8 @@ function SharedCreditsView() {
|
|
|
10952
11147
|
setAdding(false);
|
|
10953
11148
|
setEditing(null);
|
|
10954
11149
|
setRemoving(null);
|
|
11150
|
+
setSettingSelf(false);
|
|
11151
|
+
setRemovingSelf(false);
|
|
10955
11152
|
void load();
|
|
10956
11153
|
}, [workspaceId]);
|
|
10957
11154
|
(0, import_react23.useEffect)(
|
|
@@ -10999,6 +11196,8 @@ function SharedCreditsView() {
|
|
|
10999
11196
|
);
|
|
11000
11197
|
}
|
|
11001
11198
|
const members = data?.members ?? [];
|
|
11199
|
+
const self = data?.self ?? null;
|
|
11200
|
+
const showSelf = !failed && Boolean(data) && (Boolean(api.setCreditPoolSelfShare) || Boolean(self));
|
|
11002
11201
|
return /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)("div", { className: "flex flex-col flex-1 min-h-0 w-full overflow-y-auto", style: { gap: 16 }, children: [
|
|
11003
11202
|
/* @__PURE__ */ (0, import_jsx_runtime29.jsxs)("div", { className: "flex items-start justify-between shrink-0 w-full", style: { gap: 12 }, children: [
|
|
11004
11203
|
/* @__PURE__ */ (0, import_jsx_runtime29.jsxs)("div", { className: "flex flex-col min-w-0", style: { gap: 4 }, children: [
|
|
@@ -11043,25 +11242,46 @@ function SharedCreditsView() {
|
|
|
11043
11242
|
}
|
|
11044
11243
|
),
|
|
11045
11244
|
!sponsor && /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)("div", { className: "flex flex-col shrink-0 w-full", style: { gap: 8 }, children: [
|
|
11046
|
-
/* @__PURE__ */ (0, import_jsx_runtime29.
|
|
11047
|
-
|
|
11245
|
+
/* @__PURE__ */ (0, import_jsx_runtime29.jsxs)("div", { className: "flex items-baseline justify-between w-full", style: { gap: 12 }, children: [
|
|
11246
|
+
/* @__PURE__ */ (0, import_jsx_runtime29.jsx)("span", { style: { ...cellText3, fontWeight: 500 }, children: "Shared with" }),
|
|
11247
|
+
!failed && data && /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
|
|
11248
|
+
"span",
|
|
11249
|
+
{
|
|
11250
|
+
style: { ...cellText3, color: T18.muted },
|
|
11251
|
+
title: "Percentage shares, this workspace's included, total at most 100%. Fixed-credit shares aren't counted.",
|
|
11252
|
+
children: poolAllocationText(data)
|
|
11253
|
+
}
|
|
11254
|
+
)
|
|
11255
|
+
] }),
|
|
11256
|
+
/* @__PURE__ */ (0, import_jsx_runtime29.jsxs)(
|
|
11048
11257
|
MemberListFrame,
|
|
11049
11258
|
{
|
|
11050
11259
|
grow: "cap",
|
|
11051
11260
|
maxHeight: 420,
|
|
11052
11261
|
contentMinWidth: MEMBER_MIN_WIDTH,
|
|
11053
11262
|
header: tableHeader(MEMBER_COLUMNS2, ["Workspace", "Allowance", "Used", "Remaining", "Ends", "Actions"]),
|
|
11054
|
-
isEmpty: failed || members.length === 0,
|
|
11263
|
+
isEmpty: failed || members.length === 0 && !showSelf,
|
|
11055
11264
|
emptyText: failed ? "Couldn't load shared credits. Try again later." : "This workspace doesn't share its credits with any other workspace.",
|
|
11056
|
-
children:
|
|
11057
|
-
|
|
11058
|
-
|
|
11059
|
-
|
|
11060
|
-
|
|
11061
|
-
|
|
11062
|
-
|
|
11063
|
-
|
|
11064
|
-
|
|
11265
|
+
children: [
|
|
11266
|
+
showSelf && /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
|
|
11267
|
+
SelfShareRow,
|
|
11268
|
+
{
|
|
11269
|
+
self,
|
|
11270
|
+
onSet: canManage && api.setCreditPoolSelfShare ? () => setSettingSelf(true) : void 0,
|
|
11271
|
+
onRemove: canManage && api.removeCreditPoolSelfShare ? () => setRemovingSelf(true) : void 0
|
|
11272
|
+
}
|
|
11273
|
+
),
|
|
11274
|
+
showSelf && members.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("div", { style: { ...cellText3, color: T18.muted, padding: `12px ${T18.sp3xl}` }, children: "This workspace doesn't share its credits with any other workspace." }),
|
|
11275
|
+
members.map((member) => /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
|
|
11276
|
+
MemberRow2,
|
|
11277
|
+
{
|
|
11278
|
+
member,
|
|
11279
|
+
onEdit: canManage && api.updateCreditPoolMember ? () => setEditing(member) : void 0,
|
|
11280
|
+
onRemove: canManage && api.removeCreditPoolMember ? () => setRemoving(member) : void 0
|
|
11281
|
+
},
|
|
11282
|
+
member._id
|
|
11283
|
+
))
|
|
11284
|
+
]
|
|
11065
11285
|
}
|
|
11066
11286
|
)
|
|
11067
11287
|
] }),
|
|
@@ -11070,6 +11290,7 @@ function SharedCreditsView() {
|
|
|
11070
11290
|
{
|
|
11071
11291
|
kind: "add",
|
|
11072
11292
|
candidates,
|
|
11293
|
+
unallocatedPercent: poolUnallocatedPercent(data),
|
|
11073
11294
|
onSave: (input) => api.addCreditPoolMember(input),
|
|
11074
11295
|
onClose: () => setAdding(false),
|
|
11075
11296
|
onSaved: () => void load({ refresh: true })
|
|
@@ -11081,11 +11302,34 @@ function SharedCreditsView() {
|
|
|
11081
11302
|
kind: "edit",
|
|
11082
11303
|
member: editing,
|
|
11083
11304
|
memberName: poolWorkspaceName(editing.memberWorkspaceName),
|
|
11305
|
+
unallocatedPercent: poolUnallocatedPercent(data, editing._id),
|
|
11084
11306
|
onSave: (patch) => api.updateCreditPoolMember(editing._id, patch),
|
|
11085
11307
|
onClose: () => setEditing(null),
|
|
11086
11308
|
onSaved: () => void load({ refresh: true })
|
|
11087
11309
|
}
|
|
11088
11310
|
),
|
|
11311
|
+
settingSelf && api.setCreditPoolSelfShare && /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
|
|
11312
|
+
CreditPoolMemberModal,
|
|
11313
|
+
{
|
|
11314
|
+
kind: "self",
|
|
11315
|
+
self,
|
|
11316
|
+
workspaceName: selfName,
|
|
11317
|
+
unallocatedPercent: poolUnallocatedPercent(data, "self"),
|
|
11318
|
+
onSave: (input) => api.setCreditPoolSelfShare(input),
|
|
11319
|
+
onClose: () => setSettingSelf(false),
|
|
11320
|
+
onSaved: () => void load({ refresh: true })
|
|
11321
|
+
}
|
|
11322
|
+
),
|
|
11323
|
+
removingSelf && self && api.removeCreditPoolSelfShare && /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
|
|
11324
|
+
RemoveSelfShareModal,
|
|
11325
|
+
{
|
|
11326
|
+
self,
|
|
11327
|
+
workspaceName: selfName,
|
|
11328
|
+
onRemove: () => api.removeCreditPoolSelfShare(),
|
|
11329
|
+
onClose: () => setRemovingSelf(false),
|
|
11330
|
+
onRemoved: () => void load({ refresh: true })
|
|
11331
|
+
}
|
|
11332
|
+
),
|
|
11089
11333
|
removing && api.removeCreditPoolMember && /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
|
|
11090
11334
|
RemovePoolMemberModal,
|
|
11091
11335
|
{
|
|
@@ -12663,6 +12907,7 @@ function BillingContent({
|
|
|
12663
12907
|
);
|
|
12664
12908
|
const [availableCredits, setAvailableCredits] = (0, import_react24.useState)(null);
|
|
12665
12909
|
const [sharedPool, setSharedPool] = (0, import_react24.useState)(null);
|
|
12910
|
+
const [sponsorShare, setSponsorShare] = (0, import_react24.useState)(null);
|
|
12666
12911
|
const [usedByNames, setUsedByNames] = (0, import_react24.useState)({});
|
|
12667
12912
|
const [allProducts, setProducts] = (0, import_react24.useState)([]);
|
|
12668
12913
|
const workspaceCountry = workspace.current?.country;
|
|
@@ -12753,6 +12998,7 @@ function BillingContent({
|
|
|
12753
12998
|
if (creditsRes?.availableCredits != null)
|
|
12754
12999
|
setAvailableCredits(creditsRes.availableCredits);
|
|
12755
13000
|
setSharedPool(creditsRes?.sharedPool ?? null);
|
|
13001
|
+
setSponsorShare(creditsRes?.sponsorShare ?? null);
|
|
12756
13002
|
if (productsRes?.data) setProducts(productsRes.data);
|
|
12757
13003
|
if (customRes?.data?.credits != null) {
|
|
12758
13004
|
setCustomPlanCredits(customRes.data.credits);
|
|
@@ -13041,7 +13287,7 @@ function BillingContent({
|
|
|
13041
13287
|
remaining: remainingCredits,
|
|
13042
13288
|
progressPct,
|
|
13043
13289
|
remainingPct
|
|
13044
|
-
} = creditsMeter({ availableCredits, totalCredits, sharedPool });
|
|
13290
|
+
} = creditsMeter({ availableCredits, totalCredits, sharedPool, sponsorShare });
|
|
13045
13291
|
const usageText = usedCredits != null ? formatCredits2(usedCredits) : remainingCredits != null ? `${formatCredits2(remainingCredits)} available` : customPlanCredits != null ? `${formatCredits2(customPlanCredits)} credits` : "\u2014";
|
|
13046
13292
|
const handleExport = async (startDate, endDate) => {
|
|
13047
13293
|
const end = new Date(endDate);
|
|
@@ -13454,6 +13700,49 @@ function BillingContent({
|
|
|
13454
13700
|
]
|
|
13455
13701
|
}
|
|
13456
13702
|
)
|
|
13703
|
+
) : sponsorShare ? (
|
|
13704
|
+
// A sponsor keeping only a share of its credits: what is left of it.
|
|
13705
|
+
/* @__PURE__ */ (0, import_jsx_runtime30.jsxs)(
|
|
13706
|
+
"div",
|
|
13707
|
+
{
|
|
13708
|
+
role: "status",
|
|
13709
|
+
className: "flex flex-col shrink-0 w-full",
|
|
13710
|
+
style: {
|
|
13711
|
+
gap: 4,
|
|
13712
|
+
padding: 16,
|
|
13713
|
+
backgroundColor: "var(--alias-surface-base)",
|
|
13714
|
+
border: "1px solid var(--alias-border-subtle)",
|
|
13715
|
+
borderRadius: "var(--radius-3xl)"
|
|
13716
|
+
},
|
|
13717
|
+
children: [
|
|
13718
|
+
/* @__PURE__ */ (0, import_jsx_runtime30.jsx)(
|
|
13719
|
+
"span",
|
|
13720
|
+
{
|
|
13721
|
+
style: {
|
|
13722
|
+
fontFamily: "var(--font-family-font-family-body)",
|
|
13723
|
+
fontSize: "var(--font-size-font-size-sm)",
|
|
13724
|
+
fontWeight: 500,
|
|
13725
|
+
lineHeight: "var(--line-height-line-height-sm)",
|
|
13726
|
+
color: sponsorShare.remaining <= 0 ? "var(--alias-text---icons-warning)" : "var(--alias-text---icons-primary)"
|
|
13727
|
+
},
|
|
13728
|
+
children: sponsorShareBannerText(sponsorShare)
|
|
13729
|
+
}
|
|
13730
|
+
),
|
|
13731
|
+
/* @__PURE__ */ (0, import_jsx_runtime30.jsx)(
|
|
13732
|
+
"span",
|
|
13733
|
+
{
|
|
13734
|
+
style: {
|
|
13735
|
+
fontFamily: "var(--font-family-font-family-body)",
|
|
13736
|
+
fontSize: "var(--font-size-font-size-sm)",
|
|
13737
|
+
lineHeight: "var(--line-height-line-height-sm)",
|
|
13738
|
+
color: "var(--alias-text---icons-muted)"
|
|
13739
|
+
},
|
|
13740
|
+
children: sponsorShareDetailText()
|
|
13741
|
+
}
|
|
13742
|
+
)
|
|
13743
|
+
]
|
|
13744
|
+
}
|
|
13745
|
+
)
|
|
13457
13746
|
) : null,
|
|
13458
13747
|
usage ? /* @__PURE__ */ (0, import_jsx_runtime30.jsxs)(
|
|
13459
13748
|
"div",
|