@streamoid/settings 0.16.0 → 0.17.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/dist/index.d.mts +36 -4
- package/dist/index.d.ts +36 -4
- package/dist/index.js +163 -38
- package/dist/index.mjs +192 -67
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -108,6 +108,7 @@ __export(index_exports, {
|
|
|
108
108
|
formatPoolSplit: () => formatPoolSplit,
|
|
109
109
|
groupWorkspaceList: () => groupWorkspaceList,
|
|
110
110
|
hasPaidFeatures: () => hasPaidFeatures,
|
|
111
|
+
inviteUpdate: () => inviteUpdate,
|
|
111
112
|
isLimitBelowUsage: () => isLimitBelowUsage,
|
|
112
113
|
isPaidPlan: () => isPaidPlan,
|
|
113
114
|
isSponsoredEntitlement: () => isSponsoredEntitlement,
|
|
@@ -3291,6 +3292,7 @@ function InviteUpdateModal({
|
|
|
3291
3292
|
stores = [],
|
|
3292
3293
|
hiddenApps = [],
|
|
3293
3294
|
allowSubmitWithoutChanges = false,
|
|
3295
|
+
subject = "member",
|
|
3294
3296
|
initialPermissions,
|
|
3295
3297
|
onClose,
|
|
3296
3298
|
onSave,
|
|
@@ -3305,7 +3307,19 @@ function InviteUpdateModal({
|
|
|
3305
3307
|
onInvite,
|
|
3306
3308
|
onInviteMany
|
|
3307
3309
|
}) {
|
|
3308
|
-
|
|
3310
|
+
const pendingInvite = (0, import_react9.useRef)(false);
|
|
3311
|
+
const inviteGeneration = (0, import_react9.useRef)(0);
|
|
3312
|
+
const requestClose = () => {
|
|
3313
|
+
if (!pendingInvite.current) onClose();
|
|
3314
|
+
};
|
|
3315
|
+
useOverlayOpen(open, requestClose);
|
|
3316
|
+
(0, import_react9.useEffect)(() => {
|
|
3317
|
+
setSubmitting(false);
|
|
3318
|
+
return () => {
|
|
3319
|
+
inviteGeneration.current += 1;
|
|
3320
|
+
pendingInvite.current = false;
|
|
3321
|
+
};
|
|
3322
|
+
}, [open, mode, userEmail]);
|
|
3309
3323
|
const [emailValue, setEmailValue] = (0, import_react9.useState)("");
|
|
3310
3324
|
const [hasChanges, setHasChanges] = (0, import_react9.useState)(false);
|
|
3311
3325
|
const [role, setRole] = (0, import_react9.useState)("member");
|
|
@@ -3384,7 +3398,8 @@ function InviteUpdateModal({
|
|
|
3384
3398
|
const notLastShown = (key) => shownApps[shownApps.length - 1] !== key;
|
|
3385
3399
|
const appValue = (key) => role === "admin" || showsApp(key) ? appToggles[key] : false;
|
|
3386
3400
|
const grantsNoApp = role === "member" && shownApps.length > 0 && !shownApps.some((key) => appToggles[key]);
|
|
3387
|
-
const
|
|
3401
|
+
const editsInvite = !isInvite && subject === "invite";
|
|
3402
|
+
const isSubmitDisabled = isInvite ? !hasEmail || grantsNoApp || submitting : editsInvite ? !hasChanges || grantsNoApp : !(allowSubmitWithoutChanges || hasChanges);
|
|
3388
3403
|
function toggleStore(storeId) {
|
|
3389
3404
|
setSelectedStores((prev) => {
|
|
3390
3405
|
const next = new Set(prev);
|
|
@@ -3400,7 +3415,7 @@ function InviteUpdateModal({
|
|
|
3400
3415
|
className: "fixed inset-0 z-50 flex items-center justify-center",
|
|
3401
3416
|
style: { backgroundColor: "rgba(0, 0, 0, 0.6)" },
|
|
3402
3417
|
onClick: (e) => {
|
|
3403
|
-
if (e.target === e.currentTarget)
|
|
3418
|
+
if (e.target === e.currentTarget) requestClose();
|
|
3404
3419
|
},
|
|
3405
3420
|
children: /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
|
|
3406
3421
|
"div",
|
|
@@ -3440,10 +3455,10 @@ function InviteUpdateModal({
|
|
|
3440
3455
|
fontWeight: 600,
|
|
3441
3456
|
lineHeight: T6.lhLg
|
|
3442
3457
|
},
|
|
3443
|
-
children: isInvite ? "Invite" : "Update user"
|
|
3458
|
+
children: isInvite ? "Invite" : editsInvite ? "Edit invitation" : "Update user"
|
|
3444
3459
|
}
|
|
3445
3460
|
),
|
|
3446
|
-
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("
|
|
3461
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("button", { type: "button", "aria-label": "Close invite dialog", disabled: submitting, className: "shrink-0 cursor-pointer disabled:cursor-wait", onClick: requestClose, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_icons5.SiconClose, { className: "w-6 h-6", color: T6.primary }) })
|
|
3447
3462
|
]
|
|
3448
3463
|
}
|
|
3449
3464
|
) })
|
|
@@ -4546,7 +4561,7 @@ function InviteUpdateModal({
|
|
|
4546
4561
|
!isInvite && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
4547
4562
|
import_ui4.ScButton,
|
|
4548
4563
|
{
|
|
4549
|
-
text: "Remove user",
|
|
4564
|
+
text: editsInvite ? "Cancel invitation" : "Remove user",
|
|
4550
4565
|
variant: "error",
|
|
4551
4566
|
size: "md",
|
|
4552
4567
|
state: canRemove ? "default" : "disabled",
|
|
@@ -4556,7 +4571,7 @@ function InviteUpdateModal({
|
|
|
4556
4571
|
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
4557
4572
|
import_ui4.ScButton,
|
|
4558
4573
|
{
|
|
4559
|
-
text: isInvite ? "Invite User" : allowSubmitWithoutChanges ? "Resend invite" : "Save changes",
|
|
4574
|
+
text: isInvite ? "Invite User" : !editsInvite && allowSubmitWithoutChanges ? "Resend invite" : "Save changes",
|
|
4560
4575
|
variant: "primary",
|
|
4561
4576
|
size: "md",
|
|
4562
4577
|
state: isSubmitDisabled ? "disabled" : "default",
|
|
@@ -4578,14 +4593,20 @@ function InviteUpdateModal({
|
|
|
4578
4593
|
};
|
|
4579
4594
|
const standing = showOrganizationStanding ? orgStanding : void 0;
|
|
4580
4595
|
if (isInvite && onInviteMany) {
|
|
4596
|
+
if (pendingInvite.current) return;
|
|
4597
|
+
pendingInvite.current = true;
|
|
4598
|
+
const generation = ++inviteGeneration.current;
|
|
4599
|
+
const current = () => inviteGeneration.current === generation;
|
|
4581
4600
|
setSubmitting(true);
|
|
4582
|
-
Promise.resolve(
|
|
4583
|
-
|
|
4584
|
-
).then((result) => {
|
|
4585
|
-
if (result && result.failed.length > 0) {
|
|
4601
|
+
Promise.resolve().then(() => current() ? onInviteMany(perms, parsedEmails.emails, standing) : void 0).then((result) => {
|
|
4602
|
+
if (current() && result && result.failed.length > 0) {
|
|
4586
4603
|
setEmailValue(result.failed.join(", "));
|
|
4587
4604
|
}
|
|
4588
|
-
}).
|
|
4605
|
+
}).catch(() => void 0).finally(() => {
|
|
4606
|
+
if (!current()) return;
|
|
4607
|
+
pendingInvite.current = false;
|
|
4608
|
+
setSubmitting(false);
|
|
4609
|
+
});
|
|
4589
4610
|
} else if (isInvite && onInvite) {
|
|
4590
4611
|
for (const email of parsedEmails.emails) {
|
|
4591
4612
|
onInvite(perms, email, standing);
|
|
@@ -4868,6 +4889,17 @@ function memberRoleUpdate(current, permissions, services) {
|
|
|
4868
4889
|
storeIds: permissions.catalogixStores || []
|
|
4869
4890
|
};
|
|
4870
4891
|
}
|
|
4892
|
+
function inviteUpdate(invitationId, permissions, services) {
|
|
4893
|
+
const isAdmin = permissions.role === "admin";
|
|
4894
|
+
return {
|
|
4895
|
+
invitationId,
|
|
4896
|
+
role: permissions.role,
|
|
4897
|
+
creditAccess: permissions.canUseCredits,
|
|
4898
|
+
inviteAccess: permissions.canInviteUser,
|
|
4899
|
+
serviceIds: isAdmin ? [] : permissionServiceIds(services, permissions),
|
|
4900
|
+
storeIds: isAdmin ? [] : permissions.catalogixStores || []
|
|
4901
|
+
};
|
|
4902
|
+
}
|
|
4871
4903
|
function uniqueNonEmpty(values) {
|
|
4872
4904
|
return Array.from(new Set(values.map((v) => v.trim()).filter(Boolean)));
|
|
4873
4905
|
}
|
|
@@ -5317,12 +5349,17 @@ function TeamsContent({
|
|
|
5317
5349
|
isReady: permissionsReady,
|
|
5318
5350
|
failed: permissionData?.failed
|
|
5319
5351
|
});
|
|
5352
|
+
const modalSession = (0, import_react10.useRef)(0);
|
|
5320
5353
|
const [modal, setModal] = (0, import_react10.useState)({
|
|
5321
5354
|
open: false,
|
|
5322
5355
|
mode: "invite"
|
|
5323
5356
|
});
|
|
5324
5357
|
(0, import_react10.useEffect)(() => {
|
|
5358
|
+
modalSession.current += 1;
|
|
5325
5359
|
setModal({ open: false, mode: "invite" });
|
|
5360
|
+
return () => {
|
|
5361
|
+
modalSession.current += 1;
|
|
5362
|
+
};
|
|
5326
5363
|
}, [permissionScope, api]);
|
|
5327
5364
|
const MOCK_ACTIVE = [
|
|
5328
5365
|
{
|
|
@@ -5471,7 +5508,10 @@ function TeamsContent({
|
|
|
5471
5508
|
fetchGeneration.current += 1;
|
|
5472
5509
|
};
|
|
5473
5510
|
}, [fetchData]);
|
|
5474
|
-
const openInviteModal = () =>
|
|
5511
|
+
const openInviteModal = () => {
|
|
5512
|
+
modalSession.current += 1;
|
|
5513
|
+
setModal({ open: true, mode: "invite" });
|
|
5514
|
+
};
|
|
5475
5515
|
(0, import_react10.useEffect)(() => {
|
|
5476
5516
|
if ((onInviteOpen || inviteRequested) && permissionsReady && !permissionData?.failed) {
|
|
5477
5517
|
if (viewerCanInvite) openInviteModal();
|
|
@@ -5483,6 +5523,7 @@ function TeamsContent({
|
|
|
5483
5523
|
onCanInviteChange?.(viewerCanInvite);
|
|
5484
5524
|
}, [viewerCanInvite, onCanInviteChange]);
|
|
5485
5525
|
const openUpdateModal = async (member) => {
|
|
5526
|
+
modalSession.current += 1;
|
|
5486
5527
|
setModal({
|
|
5487
5528
|
open: true,
|
|
5488
5529
|
mode: "update",
|
|
@@ -5502,8 +5543,12 @@ function TeamsContent({
|
|
|
5502
5543
|
} catch {
|
|
5503
5544
|
}
|
|
5504
5545
|
};
|
|
5505
|
-
const closeModal = () =>
|
|
5546
|
+
const closeModal = () => {
|
|
5547
|
+
modalSession.current += 1;
|
|
5548
|
+
setModal({ open: false, mode: "invite" });
|
|
5549
|
+
};
|
|
5506
5550
|
const currentMemberPermissions = modal.target?.permissions;
|
|
5551
|
+
const canEditInvites = highestRole === "admin" && api.updateInvite !== void 0 && allServices.length > 0;
|
|
5507
5552
|
const handleSave = async (permissions) => {
|
|
5508
5553
|
if (!modal.target) {
|
|
5509
5554
|
closeModal();
|
|
@@ -5514,16 +5559,22 @@ function TeamsContent({
|
|
|
5514
5559
|
closeModal();
|
|
5515
5560
|
return;
|
|
5516
5561
|
}
|
|
5517
|
-
if (modal.target.kind === "invite"
|
|
5562
|
+
if (modal.target.kind === "invite") {
|
|
5563
|
+
if (!modal.target.invitationId || !api.updateInvite) {
|
|
5564
|
+
closeModal();
|
|
5565
|
+
return;
|
|
5566
|
+
}
|
|
5518
5567
|
try {
|
|
5519
|
-
await api.
|
|
5520
|
-
|
|
5521
|
-
|
|
5568
|
+
await api.updateInvite(
|
|
5569
|
+
inviteUpdate(modal.target.invitationId, permissions, allServices)
|
|
5570
|
+
);
|
|
5571
|
+
toast.success("Invitation updated");
|
|
5522
5572
|
} catch (err) {
|
|
5523
|
-
|
|
5524
|
-
|
|
5573
|
+
toast.error(errorMessage(err, { method: "PUT" }));
|
|
5574
|
+
return;
|
|
5525
5575
|
}
|
|
5526
5576
|
closeModal();
|
|
5577
|
+
await fetchData();
|
|
5527
5578
|
return;
|
|
5528
5579
|
}
|
|
5529
5580
|
if (modal.target.kind !== "member" || !modal.target.userId) {
|
|
@@ -5648,6 +5699,9 @@ function TeamsContent({
|
|
|
5648
5699
|
}
|
|
5649
5700
|
};
|
|
5650
5701
|
const handleInviteMany = async (permissions, emails, organizationStanding) => {
|
|
5702
|
+
const session = modalSession.current;
|
|
5703
|
+
const isCurrent = () => fetchMounted.current && modalSession.current === session && latestFetchScope.current.scope === permissionScope && latestFetchScope.current.api === api;
|
|
5704
|
+
if (!isCurrent()) return { failed: emails };
|
|
5651
5705
|
if (!viewerCanInvite || permissions.role === "admin" && highestRole !== "admin") {
|
|
5652
5706
|
toast.error("You do not have permission to invite users");
|
|
5653
5707
|
closeModal();
|
|
@@ -5657,6 +5711,7 @@ function TeamsContent({
|
|
|
5657
5711
|
const sent = [];
|
|
5658
5712
|
const failed = [];
|
|
5659
5713
|
for (const email of emails) {
|
|
5714
|
+
if (!isCurrent()) return { failed: emails.filter((address) => !sent.includes(address)) };
|
|
5660
5715
|
try {
|
|
5661
5716
|
await api.inviteMember({
|
|
5662
5717
|
email,
|
|
@@ -5676,6 +5731,7 @@ function TeamsContent({
|
|
|
5676
5731
|
failed.push({ email, message: errorMessage(err, { method: "POST" }) });
|
|
5677
5732
|
}
|
|
5678
5733
|
}
|
|
5734
|
+
if (!isCurrent()) return { failed: failed.map((f) => f.email) };
|
|
5679
5735
|
if (sent.length === 1) toast.success(`Invitation sent to ${sent[0]}`);
|
|
5680
5736
|
else if (sent.length > 1)
|
|
5681
5737
|
toast.success(`Invitations sent to ${sent.length} people`);
|
|
@@ -5689,7 +5745,7 @@ function TeamsContent({
|
|
|
5689
5745
|
);
|
|
5690
5746
|
}
|
|
5691
5747
|
if (sent.length > 0) await fetchData();
|
|
5692
|
-
if (failed.length === 0) closeModal();
|
|
5748
|
+
if (isCurrent() && failed.length === 0) closeModal();
|
|
5693
5749
|
return { failed: failed.map((f) => f.email) };
|
|
5694
5750
|
};
|
|
5695
5751
|
const filteredActive = activeMembers.filter((m) => {
|
|
@@ -5778,7 +5834,7 @@ function TeamsContent({
|
|
|
5778
5834
|
{
|
|
5779
5835
|
member,
|
|
5780
5836
|
variant: activeTab,
|
|
5781
|
-
onClick: activeTab === "active" ? () => openUpdateModal(member) : void 0,
|
|
5837
|
+
onClick: activeTab === "active" || canEditInvites ? () => openUpdateModal(member) : void 0,
|
|
5782
5838
|
onCancelInvite: () => void handleCancelPendingInvite(member),
|
|
5783
5839
|
onResendInvite: () => void handleResendPendingInvite(member)
|
|
5784
5840
|
},
|
|
@@ -5796,7 +5852,7 @@ function TeamsContent({
|
|
|
5796
5852
|
userEmail: modal.target?.userEmail,
|
|
5797
5853
|
stores: allStores,
|
|
5798
5854
|
hiddenApps,
|
|
5799
|
-
|
|
5855
|
+
subject: modal.target?.kind === "invite" ? "invite" : "member",
|
|
5800
5856
|
initialPermissions: currentMemberPermissions,
|
|
5801
5857
|
onClose: closeModal,
|
|
5802
5858
|
onSave: handleSave,
|
|
@@ -7915,6 +7971,35 @@ function OrganizationListContent() {
|
|
|
7915
7971
|
] });
|
|
7916
7972
|
}
|
|
7917
7973
|
|
|
7974
|
+
// src/billing-request-gate.ts
|
|
7975
|
+
function createBillingRequestGate(initialScope) {
|
|
7976
|
+
let scope = initialScope;
|
|
7977
|
+
let generation = 0;
|
|
7978
|
+
return {
|
|
7979
|
+
setScope(next) {
|
|
7980
|
+
if (next !== scope) {
|
|
7981
|
+
scope = next;
|
|
7982
|
+
generation++;
|
|
7983
|
+
}
|
|
7984
|
+
},
|
|
7985
|
+
invalidate() {
|
|
7986
|
+
generation++;
|
|
7987
|
+
},
|
|
7988
|
+
begin(requestScope) {
|
|
7989
|
+
if (requestScope !== scope) return null;
|
|
7990
|
+
const id = ++generation;
|
|
7991
|
+
return () => id === generation && requestScope === scope;
|
|
7992
|
+
}
|
|
7993
|
+
};
|
|
7994
|
+
}
|
|
7995
|
+
|
|
7996
|
+
// src/plan-card-state.ts
|
|
7997
|
+
function planCardState(loaded, loading, failed, hasSubscription) {
|
|
7998
|
+
if (!loaded || loading) return "loading";
|
|
7999
|
+
if (failed) return "error";
|
|
8000
|
+
return hasSubscription ? "ready" : "empty";
|
|
8001
|
+
}
|
|
8002
|
+
|
|
7918
8003
|
// src/billing-errors.ts
|
|
7919
8004
|
function isBillingWorkspaceMissing(failure) {
|
|
7920
8005
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -10866,12 +10951,23 @@ async function loadCurrentPlan(fetchCurrentPlan) {
|
|
|
10866
10951
|
response = await fetchCurrentPlan();
|
|
10867
10952
|
} catch (failure) {
|
|
10868
10953
|
const entitlement2 = entitlementFromFailure(failure);
|
|
10869
|
-
if (!entitlement2)
|
|
10954
|
+
if (!entitlement2) {
|
|
10955
|
+
const error = failure;
|
|
10956
|
+
if (error?.status === 404 || error?.response?.status === 404) {
|
|
10957
|
+
return { subscription: null, entitlement: null, paid: false, noSubscriptionConfirmed: true };
|
|
10958
|
+
}
|
|
10959
|
+
throw failure;
|
|
10960
|
+
}
|
|
10870
10961
|
return { subscription: null, entitlement: entitlement2, paid: entitlement2.paid };
|
|
10871
10962
|
}
|
|
10872
10963
|
const subscription = response?.data ?? null;
|
|
10873
10964
|
const entitlement = entitlementFromBody(response);
|
|
10874
|
-
return {
|
|
10965
|
+
return {
|
|
10966
|
+
subscription,
|
|
10967
|
+
entitlement,
|
|
10968
|
+
paid: hasPaidFeatures({ entitlement, subscription }),
|
|
10969
|
+
...response?.noSubscription === true ? { noSubscriptionConfirmed: true } : {}
|
|
10970
|
+
};
|
|
10875
10971
|
}
|
|
10876
10972
|
|
|
10877
10973
|
// src/billing-layout.ts
|
|
@@ -12399,6 +12495,10 @@ function BillingContent({
|
|
|
12399
12495
|
);
|
|
12400
12496
|
const [buyCreditsInFlight, setBuyCreditsInFlight] = (0, import_react23.useState)(false);
|
|
12401
12497
|
const [loadingBilling, setLoadingBilling] = (0, import_react23.useState)(false);
|
|
12498
|
+
const [planLoadFailed, setPlanLoadFailed] = (0, import_react23.useState)(false);
|
|
12499
|
+
const billingRequestGate = (0, import_react23.useRef)(createBillingRequestGate(workspaceId));
|
|
12500
|
+
billingRequestGate.current.setScope(workspaceId);
|
|
12501
|
+
(0, import_react23.useEffect)(() => () => billingRequestGate.current.invalidate(), []);
|
|
12402
12502
|
const [billingOverviewLoaded, setBillingOverviewLoaded] = (0, import_react23.useState)(false);
|
|
12403
12503
|
const [loadingTable, setLoadingTable] = (0, import_react23.useState)(false);
|
|
12404
12504
|
const [showInitialLoader, setShowInitialLoader] = (0, import_react23.useState)(true);
|
|
@@ -12423,6 +12523,8 @@ function BillingContent({
|
|
|
12423
12523
|
}
|
|
12424
12524
|
}, [api]);
|
|
12425
12525
|
const fetchBillingOverview = (0, import_react23.useCallback)(async () => {
|
|
12526
|
+
const isCurrent = billingRequestGate.current.begin(workspaceId);
|
|
12527
|
+
if (!isCurrent) return;
|
|
12426
12528
|
setLoadingBilling(true);
|
|
12427
12529
|
setBillingOverviewLoaded(false);
|
|
12428
12530
|
try {
|
|
@@ -12435,8 +12537,13 @@ function BillingContent({
|
|
|
12435
12537
|
api.fetchPlans().catch(() => null),
|
|
12436
12538
|
api.getCustomCreditInfo?.().catch(() => null) ?? Promise.resolve(null)
|
|
12437
12539
|
]);
|
|
12438
|
-
if (
|
|
12439
|
-
|
|
12540
|
+
if (!isCurrent()) return;
|
|
12541
|
+
const knownPlan = subRes && (subRes.subscription || subRes.entitlement || subRes.noSubscriptionConfirmed);
|
|
12542
|
+
setPlanLoadFailed(!knownPlan);
|
|
12543
|
+
if (knownPlan) {
|
|
12544
|
+
setSubscription(subRes.subscription);
|
|
12545
|
+
setEntitlement(subRes.entitlement);
|
|
12546
|
+
}
|
|
12440
12547
|
if (creditsRes?.availableCredits != null)
|
|
12441
12548
|
setAvailableCredits(creditsRes.availableCredits);
|
|
12442
12549
|
setSharedPool(creditsRes?.sharedPool ?? null);
|
|
@@ -12445,11 +12552,14 @@ function BillingContent({
|
|
|
12445
12552
|
setCustomPlanCredits(customRes.data.credits);
|
|
12446
12553
|
}
|
|
12447
12554
|
} catch {
|
|
12555
|
+
if (isCurrent()) setPlanLoadFailed(true);
|
|
12448
12556
|
} finally {
|
|
12449
|
-
|
|
12450
|
-
|
|
12557
|
+
if (isCurrent()) {
|
|
12558
|
+
setLoadingBilling(false);
|
|
12559
|
+
setBillingOverviewLoaded(true);
|
|
12560
|
+
}
|
|
12451
12561
|
}
|
|
12452
|
-
}, [api]);
|
|
12562
|
+
}, [api, workspaceId]);
|
|
12453
12563
|
const fetchUserMap = (0, import_react23.useCallback)(async () => {
|
|
12454
12564
|
try {
|
|
12455
12565
|
const members = await api.fetchMembers();
|
|
@@ -12645,8 +12755,10 @@ function BillingContent({
|
|
|
12645
12755
|
setInitialFetchTriggered(false);
|
|
12646
12756
|
setBillingOverviewLoaded(false);
|
|
12647
12757
|
setSubscription(null);
|
|
12758
|
+
setPlanLoadFailed(false);
|
|
12648
12759
|
setEntitlement(null);
|
|
12649
12760
|
setAvailableCredits(null);
|
|
12761
|
+
setSharedPool(null);
|
|
12650
12762
|
setProducts([]);
|
|
12651
12763
|
setTotalCredits(null);
|
|
12652
12764
|
setCustomPlanCredits(null);
|
|
@@ -12707,15 +12819,17 @@ function BillingContent({
|
|
|
12707
12819
|
);
|
|
12708
12820
|
const scheduledDowngradeText = subscription?.downgradeScheduled && subscription.plan?.name ? `Downgrades to ${subscription.plan.name}${scheduledDowngradeDateLabel ? ` ${scheduledDowngradeDateLabel}` : ""}` : void 0;
|
|
12709
12821
|
const sponsored = isSponsoredEntitlement(entitlement);
|
|
12710
|
-
const
|
|
12711
|
-
const
|
|
12822
|
+
const planState = planCardState(billingOverviewLoaded, loadingBilling, planLoadFailed, subscription != null);
|
|
12823
|
+
const withoutPlan = planState === "empty";
|
|
12824
|
+
const sponsoredWithoutPlan = sponsored && withoutPlan;
|
|
12825
|
+
const isPlanDetailsLoading = planState === "loading";
|
|
12712
12826
|
const paidFeatures = hasPaidFeatures({ entitlement, subscription });
|
|
12713
12827
|
const onEntitlementChangeRef = (0, import_react23.useRef)(onEntitlementChange);
|
|
12714
12828
|
onEntitlementChangeRef.current = onEntitlementChange;
|
|
12715
12829
|
(0, import_react23.useEffect)(() => {
|
|
12716
|
-
if (!billingOverviewLoaded) return;
|
|
12830
|
+
if (!billingOverviewLoaded || loadingBilling || planLoadFailed) return;
|
|
12717
12831
|
onEntitlementChangeRef.current?.({ entitlement, paid: paidFeatures });
|
|
12718
|
-
}, [billingOverviewLoaded, entitlement, paidFeatures]);
|
|
12832
|
+
}, [billingOverviewLoaded, loadingBilling, planLoadFailed, entitlement, paidFeatures]);
|
|
12719
12833
|
const {
|
|
12720
12834
|
used: usedCredits,
|
|
12721
12835
|
remaining: remainingCredits,
|
|
@@ -12985,20 +13099,27 @@ function BillingContent({
|
|
|
12985
13099
|
className: "flex items-start shrink-0 w-full",
|
|
12986
13100
|
style: { gap: 12 },
|
|
12987
13101
|
children: [
|
|
12988
|
-
/* @__PURE__ */ (0, import_jsx_runtime29.
|
|
13102
|
+
planState === "error" ? /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)("div", { role: "alert", className: "flex-1 min-w-0", style: { padding: 16 }, children: [
|
|
13103
|
+
/* @__PURE__ */ (0, import_jsx_runtime29.jsx)("p", { children: "Plan details could not be loaded." }),
|
|
13104
|
+
/* @__PURE__ */ (0, import_jsx_runtime29.jsx)(import_ui17.ScButton, { text: "Retry plan details", variant: "outline", size: "sm", onClick: () => void fetchBillingOverview() })
|
|
13105
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
|
|
12989
13106
|
import_ui17.ScPlanDetailsCard,
|
|
12990
13107
|
{
|
|
12991
|
-
planName:
|
|
13108
|
+
planName: withoutPlan ? "Free" : planName || "Current plan",
|
|
12992
13109
|
planCredits: sponsoredWithoutPlan ? "Shared credits" : planCreditsText,
|
|
12993
|
-
planPrice:
|
|
13110
|
+
planPrice: withoutPlan ? "No paid subscription" : planAmount,
|
|
12994
13111
|
badgeText: "Active",
|
|
12995
13112
|
badgeSubText: scheduledDowngradeText,
|
|
12996
13113
|
currentPlanLabel: "Current plan",
|
|
12997
|
-
upgradeButtonText: subscription?.downgradeScheduled ? "Cancel downgrade" : "Manage Plan",
|
|
13114
|
+
upgradeButtonText: withoutPlan ? "See plans" : navigation.manageBilling ? "Manage Plan" : subscription?.downgradeScheduled ? "Cancel downgrade" : "Manage Plan",
|
|
12998
13115
|
isLoading: isPlanDetailsLoading,
|
|
12999
13116
|
className: "flex-1 min-w-0",
|
|
13000
13117
|
style: { padding: 16, gap: 8 },
|
|
13001
13118
|
onUpgrade: () => {
|
|
13119
|
+
if (navigation.manageBilling) {
|
|
13120
|
+
navigation.manageBilling();
|
|
13121
|
+
return;
|
|
13122
|
+
}
|
|
13002
13123
|
void logBillingEvent("billing_plans_opened", "Plans opened", {
|
|
13003
13124
|
action: "open_plans"
|
|
13004
13125
|
});
|
|
@@ -13023,6 +13144,10 @@ function BillingContent({
|
|
|
13023
13144
|
className: "flex-1 min-w-0",
|
|
13024
13145
|
style: { padding: 16, gap: 8 },
|
|
13025
13146
|
onBuyClick: () => {
|
|
13147
|
+
if (navigation.manageBilling) {
|
|
13148
|
+
navigation.manageBilling();
|
|
13149
|
+
return;
|
|
13150
|
+
}
|
|
13026
13151
|
void logBillingEvent(
|
|
13027
13152
|
"billing_buy_credits_clicked",
|
|
13028
13153
|
"Buy credits clicked",
|