@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.mjs
CHANGED
|
@@ -599,7 +599,7 @@ import {
|
|
|
599
599
|
Fragment as Fragment15,
|
|
600
600
|
useState as useState25,
|
|
601
601
|
useEffect as useEffect20,
|
|
602
|
-
useRef as
|
|
602
|
+
useRef as useRef12,
|
|
603
603
|
useCallback as useCallback10,
|
|
604
604
|
useMemo as useMemo5
|
|
605
605
|
} from "react";
|
|
@@ -3000,7 +3000,7 @@ var APP_ACCESS_MARKS = {
|
|
|
3000
3000
|
};
|
|
3001
3001
|
|
|
3002
3002
|
// src/teams-content.tsx
|
|
3003
|
-
import { useState as useState8, useEffect as useEffect8, useCallback as useCallback2, useRef as
|
|
3003
|
+
import { useState as useState8, useEffect as useEffect8, useCallback as useCallback2, useRef as useRef6 } from "react";
|
|
3004
3004
|
import { ScPendingAction } from "@streamoid/ui";
|
|
3005
3005
|
import { ScButton as ScButton4 } from "@streamoid/ui";
|
|
3006
3006
|
import {
|
|
@@ -3008,7 +3008,7 @@ import {
|
|
|
3008
3008
|
} from "@streamoid/icons";
|
|
3009
3009
|
|
|
3010
3010
|
// src/invite-update-modal.tsx
|
|
3011
|
-
import { useState as useState7, useEffect as useEffect7 } from "react";
|
|
3011
|
+
import { useState as useState7, useEffect as useEffect7, useRef as useRef5 } from "react";
|
|
3012
3012
|
import { ScButton as ScButton3 } from "@streamoid/ui";
|
|
3013
3013
|
import {
|
|
3014
3014
|
SiconClose as SiconClose2,
|
|
@@ -3176,6 +3176,7 @@ function InviteUpdateModal({
|
|
|
3176
3176
|
stores = [],
|
|
3177
3177
|
hiddenApps = [],
|
|
3178
3178
|
allowSubmitWithoutChanges = false,
|
|
3179
|
+
subject = "member",
|
|
3179
3180
|
initialPermissions,
|
|
3180
3181
|
onClose,
|
|
3181
3182
|
onSave,
|
|
@@ -3190,7 +3191,19 @@ function InviteUpdateModal({
|
|
|
3190
3191
|
onInvite,
|
|
3191
3192
|
onInviteMany
|
|
3192
3193
|
}) {
|
|
3193
|
-
|
|
3194
|
+
const pendingInvite = useRef5(false);
|
|
3195
|
+
const inviteGeneration = useRef5(0);
|
|
3196
|
+
const requestClose = () => {
|
|
3197
|
+
if (!pendingInvite.current) onClose();
|
|
3198
|
+
};
|
|
3199
|
+
useOverlayOpen(open, requestClose);
|
|
3200
|
+
useEffect7(() => {
|
|
3201
|
+
setSubmitting(false);
|
|
3202
|
+
return () => {
|
|
3203
|
+
inviteGeneration.current += 1;
|
|
3204
|
+
pendingInvite.current = false;
|
|
3205
|
+
};
|
|
3206
|
+
}, [open, mode, userEmail]);
|
|
3194
3207
|
const [emailValue, setEmailValue] = useState7("");
|
|
3195
3208
|
const [hasChanges, setHasChanges] = useState7(false);
|
|
3196
3209
|
const [role, setRole] = useState7("member");
|
|
@@ -3269,7 +3282,8 @@ function InviteUpdateModal({
|
|
|
3269
3282
|
const notLastShown = (key) => shownApps[shownApps.length - 1] !== key;
|
|
3270
3283
|
const appValue = (key) => role === "admin" || showsApp(key) ? appToggles[key] : false;
|
|
3271
3284
|
const grantsNoApp = role === "member" && shownApps.length > 0 && !shownApps.some((key) => appToggles[key]);
|
|
3272
|
-
const
|
|
3285
|
+
const editsInvite = !isInvite && subject === "invite";
|
|
3286
|
+
const isSubmitDisabled = isInvite ? !hasEmail || grantsNoApp || submitting : editsInvite ? !hasChanges || grantsNoApp : !(allowSubmitWithoutChanges || hasChanges);
|
|
3273
3287
|
function toggleStore(storeId) {
|
|
3274
3288
|
setSelectedStores((prev) => {
|
|
3275
3289
|
const next = new Set(prev);
|
|
@@ -3285,7 +3299,7 @@ function InviteUpdateModal({
|
|
|
3285
3299
|
className: "fixed inset-0 z-50 flex items-center justify-center",
|
|
3286
3300
|
style: { backgroundColor: "rgba(0, 0, 0, 0.6)" },
|
|
3287
3301
|
onClick: (e) => {
|
|
3288
|
-
if (e.target === e.currentTarget)
|
|
3302
|
+
if (e.target === e.currentTarget) requestClose();
|
|
3289
3303
|
},
|
|
3290
3304
|
children: /* @__PURE__ */ jsxs11(
|
|
3291
3305
|
"div",
|
|
@@ -3325,10 +3339,10 @@ function InviteUpdateModal({
|
|
|
3325
3339
|
fontWeight: 600,
|
|
3326
3340
|
lineHeight: T6.lhLg
|
|
3327
3341
|
},
|
|
3328
|
-
children: isInvite ? "Invite" : "Update user"
|
|
3342
|
+
children: isInvite ? "Invite" : editsInvite ? "Edit invitation" : "Update user"
|
|
3329
3343
|
}
|
|
3330
3344
|
),
|
|
3331
|
-
/* @__PURE__ */ jsx14("
|
|
3345
|
+
/* @__PURE__ */ jsx14("button", { type: "button", "aria-label": "Close invite dialog", disabled: submitting, className: "shrink-0 cursor-pointer disabled:cursor-wait", onClick: requestClose, children: /* @__PURE__ */ jsx14(SiconClose2, { className: "w-6 h-6", color: T6.primary }) })
|
|
3332
3346
|
]
|
|
3333
3347
|
}
|
|
3334
3348
|
) })
|
|
@@ -4431,7 +4445,7 @@ function InviteUpdateModal({
|
|
|
4431
4445
|
!isInvite && /* @__PURE__ */ jsx14(
|
|
4432
4446
|
ScButton3,
|
|
4433
4447
|
{
|
|
4434
|
-
text: "Remove user",
|
|
4448
|
+
text: editsInvite ? "Cancel invitation" : "Remove user",
|
|
4435
4449
|
variant: "error",
|
|
4436
4450
|
size: "md",
|
|
4437
4451
|
state: canRemove ? "default" : "disabled",
|
|
@@ -4441,7 +4455,7 @@ function InviteUpdateModal({
|
|
|
4441
4455
|
/* @__PURE__ */ jsx14(
|
|
4442
4456
|
ScButton3,
|
|
4443
4457
|
{
|
|
4444
|
-
text: isInvite ? "Invite User" : allowSubmitWithoutChanges ? "Resend invite" : "Save changes",
|
|
4458
|
+
text: isInvite ? "Invite User" : !editsInvite && allowSubmitWithoutChanges ? "Resend invite" : "Save changes",
|
|
4445
4459
|
variant: "primary",
|
|
4446
4460
|
size: "md",
|
|
4447
4461
|
state: isSubmitDisabled ? "disabled" : "default",
|
|
@@ -4463,14 +4477,20 @@ function InviteUpdateModal({
|
|
|
4463
4477
|
};
|
|
4464
4478
|
const standing = showOrganizationStanding ? orgStanding : void 0;
|
|
4465
4479
|
if (isInvite && onInviteMany) {
|
|
4480
|
+
if (pendingInvite.current) return;
|
|
4481
|
+
pendingInvite.current = true;
|
|
4482
|
+
const generation = ++inviteGeneration.current;
|
|
4483
|
+
const current = () => inviteGeneration.current === generation;
|
|
4466
4484
|
setSubmitting(true);
|
|
4467
|
-
Promise.resolve(
|
|
4468
|
-
|
|
4469
|
-
).then((result) => {
|
|
4470
|
-
if (result && result.failed.length > 0) {
|
|
4485
|
+
Promise.resolve().then(() => current() ? onInviteMany(perms, parsedEmails.emails, standing) : void 0).then((result) => {
|
|
4486
|
+
if (current() && result && result.failed.length > 0) {
|
|
4471
4487
|
setEmailValue(result.failed.join(", "));
|
|
4472
4488
|
}
|
|
4473
|
-
}).
|
|
4489
|
+
}).catch(() => void 0).finally(() => {
|
|
4490
|
+
if (!current()) return;
|
|
4491
|
+
pendingInvite.current = false;
|
|
4492
|
+
setSubmitting(false);
|
|
4493
|
+
});
|
|
4474
4494
|
} else if (isInvite && onInvite) {
|
|
4475
4495
|
for (const email of parsedEmails.emails) {
|
|
4476
4496
|
onInvite(perms, email, standing);
|
|
@@ -4753,6 +4773,17 @@ function memberRoleUpdate(current, permissions, services) {
|
|
|
4753
4773
|
storeIds: permissions.catalogixStores || []
|
|
4754
4774
|
};
|
|
4755
4775
|
}
|
|
4776
|
+
function inviteUpdate(invitationId, permissions, services) {
|
|
4777
|
+
const isAdmin = permissions.role === "admin";
|
|
4778
|
+
return {
|
|
4779
|
+
invitationId,
|
|
4780
|
+
role: permissions.role,
|
|
4781
|
+
creditAccess: permissions.canUseCredits,
|
|
4782
|
+
inviteAccess: permissions.canInviteUser,
|
|
4783
|
+
serviceIds: isAdmin ? [] : permissionServiceIds(services, permissions),
|
|
4784
|
+
storeIds: isAdmin ? [] : permissions.catalogixStores || []
|
|
4785
|
+
};
|
|
4786
|
+
}
|
|
4756
4787
|
function uniqueNonEmpty(values) {
|
|
4757
4788
|
return Array.from(new Set(values.map((v) => v.trim()).filter(Boolean)));
|
|
4758
4789
|
}
|
|
@@ -5183,9 +5214,9 @@ function TeamsContent({
|
|
|
5183
5214
|
const currentRoster = roster?.scope === permissionScope && roster.api === api ? roster : null;
|
|
5184
5215
|
const activeMembers = currentRoster?.active ?? [];
|
|
5185
5216
|
const pendingMembers = currentRoster?.pending ?? [];
|
|
5186
|
-
const fetchGeneration =
|
|
5187
|
-
const fetchMounted =
|
|
5188
|
-
const latestFetchScope =
|
|
5217
|
+
const fetchGeneration = useRef6(0);
|
|
5218
|
+
const fetchMounted = useRef6(false);
|
|
5219
|
+
const latestFetchScope = useRef6({ scope: permissionScope, api });
|
|
5189
5220
|
latestFetchScope.current = { scope: permissionScope, api };
|
|
5190
5221
|
const [permissionData, setPermissionData] = useState8(null);
|
|
5191
5222
|
const [searchQuery, setSearchQuery] = useState8("");
|
|
@@ -5202,12 +5233,17 @@ function TeamsContent({
|
|
|
5202
5233
|
isReady: permissionsReady,
|
|
5203
5234
|
failed: permissionData?.failed
|
|
5204
5235
|
});
|
|
5236
|
+
const modalSession = useRef6(0);
|
|
5205
5237
|
const [modal, setModal] = useState8({
|
|
5206
5238
|
open: false,
|
|
5207
5239
|
mode: "invite"
|
|
5208
5240
|
});
|
|
5209
5241
|
useEffect8(() => {
|
|
5242
|
+
modalSession.current += 1;
|
|
5210
5243
|
setModal({ open: false, mode: "invite" });
|
|
5244
|
+
return () => {
|
|
5245
|
+
modalSession.current += 1;
|
|
5246
|
+
};
|
|
5211
5247
|
}, [permissionScope, api]);
|
|
5212
5248
|
const MOCK_ACTIVE = [
|
|
5213
5249
|
{
|
|
@@ -5356,7 +5392,10 @@ function TeamsContent({
|
|
|
5356
5392
|
fetchGeneration.current += 1;
|
|
5357
5393
|
};
|
|
5358
5394
|
}, [fetchData]);
|
|
5359
|
-
const openInviteModal = () =>
|
|
5395
|
+
const openInviteModal = () => {
|
|
5396
|
+
modalSession.current += 1;
|
|
5397
|
+
setModal({ open: true, mode: "invite" });
|
|
5398
|
+
};
|
|
5360
5399
|
useEffect8(() => {
|
|
5361
5400
|
if ((onInviteOpen || inviteRequested) && permissionsReady && !permissionData?.failed) {
|
|
5362
5401
|
if (viewerCanInvite) openInviteModal();
|
|
@@ -5368,6 +5407,7 @@ function TeamsContent({
|
|
|
5368
5407
|
onCanInviteChange?.(viewerCanInvite);
|
|
5369
5408
|
}, [viewerCanInvite, onCanInviteChange]);
|
|
5370
5409
|
const openUpdateModal = async (member) => {
|
|
5410
|
+
modalSession.current += 1;
|
|
5371
5411
|
setModal({
|
|
5372
5412
|
open: true,
|
|
5373
5413
|
mode: "update",
|
|
@@ -5387,8 +5427,12 @@ function TeamsContent({
|
|
|
5387
5427
|
} catch {
|
|
5388
5428
|
}
|
|
5389
5429
|
};
|
|
5390
|
-
const closeModal = () =>
|
|
5430
|
+
const closeModal = () => {
|
|
5431
|
+
modalSession.current += 1;
|
|
5432
|
+
setModal({ open: false, mode: "invite" });
|
|
5433
|
+
};
|
|
5391
5434
|
const currentMemberPermissions = modal.target?.permissions;
|
|
5435
|
+
const canEditInvites = highestRole === "admin" && api.updateInvite !== void 0 && allServices.length > 0;
|
|
5392
5436
|
const handleSave = async (permissions) => {
|
|
5393
5437
|
if (!modal.target) {
|
|
5394
5438
|
closeModal();
|
|
@@ -5399,16 +5443,22 @@ function TeamsContent({
|
|
|
5399
5443
|
closeModal();
|
|
5400
5444
|
return;
|
|
5401
5445
|
}
|
|
5402
|
-
if (modal.target.kind === "invite"
|
|
5446
|
+
if (modal.target.kind === "invite") {
|
|
5447
|
+
if (!modal.target.invitationId || !api.updateInvite) {
|
|
5448
|
+
closeModal();
|
|
5449
|
+
return;
|
|
5450
|
+
}
|
|
5403
5451
|
try {
|
|
5404
|
-
await api.
|
|
5405
|
-
|
|
5406
|
-
|
|
5452
|
+
await api.updateInvite(
|
|
5453
|
+
inviteUpdate(modal.target.invitationId, permissions, allServices)
|
|
5454
|
+
);
|
|
5455
|
+
toast.success("Invitation updated");
|
|
5407
5456
|
} catch (err) {
|
|
5408
|
-
|
|
5409
|
-
|
|
5457
|
+
toast.error(errorMessage(err, { method: "PUT" }));
|
|
5458
|
+
return;
|
|
5410
5459
|
}
|
|
5411
5460
|
closeModal();
|
|
5461
|
+
await fetchData();
|
|
5412
5462
|
return;
|
|
5413
5463
|
}
|
|
5414
5464
|
if (modal.target.kind !== "member" || !modal.target.userId) {
|
|
@@ -5533,6 +5583,9 @@ function TeamsContent({
|
|
|
5533
5583
|
}
|
|
5534
5584
|
};
|
|
5535
5585
|
const handleInviteMany = async (permissions, emails, organizationStanding) => {
|
|
5586
|
+
const session = modalSession.current;
|
|
5587
|
+
const isCurrent = () => fetchMounted.current && modalSession.current === session && latestFetchScope.current.scope === permissionScope && latestFetchScope.current.api === api;
|
|
5588
|
+
if (!isCurrent()) return { failed: emails };
|
|
5536
5589
|
if (!viewerCanInvite || permissions.role === "admin" && highestRole !== "admin") {
|
|
5537
5590
|
toast.error("You do not have permission to invite users");
|
|
5538
5591
|
closeModal();
|
|
@@ -5542,6 +5595,7 @@ function TeamsContent({
|
|
|
5542
5595
|
const sent = [];
|
|
5543
5596
|
const failed = [];
|
|
5544
5597
|
for (const email of emails) {
|
|
5598
|
+
if (!isCurrent()) return { failed: emails.filter((address) => !sent.includes(address)) };
|
|
5545
5599
|
try {
|
|
5546
5600
|
await api.inviteMember({
|
|
5547
5601
|
email,
|
|
@@ -5561,6 +5615,7 @@ function TeamsContent({
|
|
|
5561
5615
|
failed.push({ email, message: errorMessage(err, { method: "POST" }) });
|
|
5562
5616
|
}
|
|
5563
5617
|
}
|
|
5618
|
+
if (!isCurrent()) return { failed: failed.map((f) => f.email) };
|
|
5564
5619
|
if (sent.length === 1) toast.success(`Invitation sent to ${sent[0]}`);
|
|
5565
5620
|
else if (sent.length > 1)
|
|
5566
5621
|
toast.success(`Invitations sent to ${sent.length} people`);
|
|
@@ -5574,7 +5629,7 @@ function TeamsContent({
|
|
|
5574
5629
|
);
|
|
5575
5630
|
}
|
|
5576
5631
|
if (sent.length > 0) await fetchData();
|
|
5577
|
-
if (failed.length === 0) closeModal();
|
|
5632
|
+
if (isCurrent() && failed.length === 0) closeModal();
|
|
5578
5633
|
return { failed: failed.map((f) => f.email) };
|
|
5579
5634
|
};
|
|
5580
5635
|
const filteredActive = activeMembers.filter((m) => {
|
|
@@ -5663,7 +5718,7 @@ function TeamsContent({
|
|
|
5663
5718
|
{
|
|
5664
5719
|
member,
|
|
5665
5720
|
variant: activeTab,
|
|
5666
|
-
onClick: activeTab === "active" ? () => openUpdateModal(member) : void 0,
|
|
5721
|
+
onClick: activeTab === "active" || canEditInvites ? () => openUpdateModal(member) : void 0,
|
|
5667
5722
|
onCancelInvite: () => void handleCancelPendingInvite(member),
|
|
5668
5723
|
onResendInvite: () => void handleResendPendingInvite(member)
|
|
5669
5724
|
},
|
|
@@ -5681,7 +5736,7 @@ function TeamsContent({
|
|
|
5681
5736
|
userEmail: modal.target?.userEmail,
|
|
5682
5737
|
stores: allStores,
|
|
5683
5738
|
hiddenApps,
|
|
5684
|
-
|
|
5739
|
+
subject: modal.target?.kind === "invite" ? "invite" : "member",
|
|
5685
5740
|
initialPermissions: currentMemberPermissions,
|
|
5686
5741
|
onClose: closeModal,
|
|
5687
5742
|
onSave: handleSave,
|
|
@@ -6119,7 +6174,7 @@ function OrganizationMemberModal({
|
|
|
6119
6174
|
}
|
|
6120
6175
|
|
|
6121
6176
|
// src/organization-modal.tsx
|
|
6122
|
-
import { useState as useState10, useRef as
|
|
6177
|
+
import { useState as useState10, useRef as useRef7, useEffect as useEffect10 } from "react";
|
|
6123
6178
|
import { Fragment as Fragment7, jsx as jsx18, jsxs as jsxs15 } from "react/jsx-runtime";
|
|
6124
6179
|
var T10 = {
|
|
6125
6180
|
primary: "var(--alias-text---icons-primary)",
|
|
@@ -6192,7 +6247,7 @@ function OrganizationModal({
|
|
|
6192
6247
|
);
|
|
6193
6248
|
const [submitting, setSubmitting] = useState10(false);
|
|
6194
6249
|
const [canDelete, setCanDelete] = useState10(false);
|
|
6195
|
-
const fileInputRef =
|
|
6250
|
+
const fileInputRef = useRef7(null);
|
|
6196
6251
|
const { organization: organizationAdapter } = useSettingsAdapters();
|
|
6197
6252
|
useEffect10(() => {
|
|
6198
6253
|
if (open) {
|
|
@@ -7512,7 +7567,7 @@ function OrganizationContent({
|
|
|
7512
7567
|
}
|
|
7513
7568
|
|
|
7514
7569
|
// src/organization-list-content.tsx
|
|
7515
|
-
import { useCallback as useCallback4, useEffect as useEffect12, useRef as
|
|
7570
|
+
import { useCallback as useCallback4, useEffect as useEffect12, useRef as useRef8, useState as useState12 } from "react";
|
|
7516
7571
|
import { ScButton as ScButton7 } from "@streamoid/ui";
|
|
7517
7572
|
import { jsx as jsx20, jsxs as jsxs17 } from "react/jsx-runtime";
|
|
7518
7573
|
var T12 = {
|
|
@@ -7550,7 +7605,7 @@ function OrganizationListContent() {
|
|
|
7550
7605
|
const [openingId, setOpeningId] = useState12(null);
|
|
7551
7606
|
const [joinable, setJoinable] = useState12([]);
|
|
7552
7607
|
const [joiningId, setJoiningId] = useState12(null);
|
|
7553
|
-
const organizationRef =
|
|
7608
|
+
const organizationRef = useRef8(organization);
|
|
7554
7609
|
organizationRef.current = organization;
|
|
7555
7610
|
const load = useCallback4(async () => {
|
|
7556
7611
|
setLoading(true);
|
|
@@ -7800,6 +7855,35 @@ function OrganizationListContent() {
|
|
|
7800
7855
|
] });
|
|
7801
7856
|
}
|
|
7802
7857
|
|
|
7858
|
+
// src/billing-request-gate.ts
|
|
7859
|
+
function createBillingRequestGate(initialScope) {
|
|
7860
|
+
let scope = initialScope;
|
|
7861
|
+
let generation = 0;
|
|
7862
|
+
return {
|
|
7863
|
+
setScope(next) {
|
|
7864
|
+
if (next !== scope) {
|
|
7865
|
+
scope = next;
|
|
7866
|
+
generation++;
|
|
7867
|
+
}
|
|
7868
|
+
},
|
|
7869
|
+
invalidate() {
|
|
7870
|
+
generation++;
|
|
7871
|
+
},
|
|
7872
|
+
begin(requestScope) {
|
|
7873
|
+
if (requestScope !== scope) return null;
|
|
7874
|
+
const id = ++generation;
|
|
7875
|
+
return () => id === generation && requestScope === scope;
|
|
7876
|
+
}
|
|
7877
|
+
};
|
|
7878
|
+
}
|
|
7879
|
+
|
|
7880
|
+
// src/plan-card-state.ts
|
|
7881
|
+
function planCardState(loaded, loading, failed, hasSubscription) {
|
|
7882
|
+
if (!loaded || loading) return "loading";
|
|
7883
|
+
if (failed) return "error";
|
|
7884
|
+
return hasSubscription ? "ready" : "empty";
|
|
7885
|
+
}
|
|
7886
|
+
|
|
7803
7887
|
// src/billing-errors.ts
|
|
7804
7888
|
function isBillingWorkspaceMissing(failure) {
|
|
7805
7889
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -7848,7 +7932,7 @@ import {
|
|
|
7848
7932
|
useCallback as useCallback8,
|
|
7849
7933
|
useMemo as useMemo4,
|
|
7850
7934
|
useReducer,
|
|
7851
|
-
useRef as
|
|
7935
|
+
useRef as useRef11
|
|
7852
7936
|
} from "react";
|
|
7853
7937
|
import {
|
|
7854
7938
|
ScPlanDetailsCard,
|
|
@@ -8792,7 +8876,7 @@ function BuyCreditsModal({
|
|
|
8792
8876
|
}
|
|
8793
8877
|
|
|
8794
8878
|
// src/per-user-limits-view.tsx
|
|
8795
|
-
import { useCallback as useCallback6, useEffect as useEffect14, useMemo as useMemo3, useRef as
|
|
8879
|
+
import { useCallback as useCallback6, useEffect as useEffect14, useMemo as useMemo3, useRef as useRef9, useState as useState16 } from "react";
|
|
8796
8880
|
import { ScButton as ScButton9 } from "@streamoid/ui";
|
|
8797
8881
|
|
|
8798
8882
|
// src/member-credit-limit-modal.tsx
|
|
@@ -9299,7 +9383,7 @@ function PerUserLimitsView() {
|
|
|
9299
9383
|
const [searchQuery, setSearchQuery] = useState16("");
|
|
9300
9384
|
const [editing, setEditing] = useState16(null);
|
|
9301
9385
|
const [editingDefault, setEditingDefault] = useState16(false);
|
|
9302
|
-
const latestLoad =
|
|
9386
|
+
const latestLoad = useRef9(0);
|
|
9303
9387
|
const load = useCallback6(async ({ refresh = false } = {}) => {
|
|
9304
9388
|
const loadId = ++latestLoad.current;
|
|
9305
9389
|
if (!api.fetchMemberCreditLimits) {
|
|
@@ -9505,7 +9589,7 @@ function PerUserLimitsView() {
|
|
|
9505
9589
|
}
|
|
9506
9590
|
|
|
9507
9591
|
// src/shared-credits-view.tsx
|
|
9508
|
-
import { useCallback as useCallback7, useEffect as useEffect17, useRef as
|
|
9592
|
+
import { useCallback as useCallback7, useEffect as useEffect17, useRef as useRef10, useState as useState20 } from "react";
|
|
9509
9593
|
import { ScButton as ScButton13 } from "@streamoid/ui";
|
|
9510
9594
|
|
|
9511
9595
|
// src/connected-apps-shared.tsx
|
|
@@ -10541,7 +10625,7 @@ function SharedCreditsView() {
|
|
|
10541
10625
|
const [adding, setAdding] = useState20(false);
|
|
10542
10626
|
const [editing, setEditing] = useState20(null);
|
|
10543
10627
|
const [removing, setRemoving] = useState20(null);
|
|
10544
|
-
const latestLoad =
|
|
10628
|
+
const latestLoad = useRef10(0);
|
|
10545
10629
|
const load = useCallback7(
|
|
10546
10630
|
async ({ refresh = false } = {}) => {
|
|
10547
10631
|
const loadId = ++latestLoad.current;
|
|
@@ -10774,12 +10858,23 @@ async function loadCurrentPlan(fetchCurrentPlan) {
|
|
|
10774
10858
|
response = await fetchCurrentPlan();
|
|
10775
10859
|
} catch (failure) {
|
|
10776
10860
|
const entitlement2 = entitlementFromFailure(failure);
|
|
10777
|
-
if (!entitlement2)
|
|
10861
|
+
if (!entitlement2) {
|
|
10862
|
+
const error = failure;
|
|
10863
|
+
if (error?.status === 404 || error?.response?.status === 404) {
|
|
10864
|
+
return { subscription: null, entitlement: null, paid: false, noSubscriptionConfirmed: true };
|
|
10865
|
+
}
|
|
10866
|
+
throw failure;
|
|
10867
|
+
}
|
|
10778
10868
|
return { subscription: null, entitlement: entitlement2, paid: entitlement2.paid };
|
|
10779
10869
|
}
|
|
10780
10870
|
const subscription = response?.data ?? null;
|
|
10781
10871
|
const entitlement = entitlementFromBody(response);
|
|
10782
|
-
return {
|
|
10872
|
+
return {
|
|
10873
|
+
subscription,
|
|
10874
|
+
entitlement,
|
|
10875
|
+
paid: hasPaidFeatures({ entitlement, subscription }),
|
|
10876
|
+
...response?.noSubscription === true ? { noSubscriptionConfirmed: true } : {}
|
|
10877
|
+
};
|
|
10783
10878
|
}
|
|
10784
10879
|
|
|
10785
10880
|
// src/billing-layout.ts
|
|
@@ -11457,7 +11552,7 @@ function PlansView({
|
|
|
11457
11552
|
selectedMiddlePlan && actionInFlight === selectedMiddlePlan.key
|
|
11458
11553
|
);
|
|
11459
11554
|
const [isPlanSelectorOpen, setIsPlanSelectorOpen] = useState21(false);
|
|
11460
|
-
const planDropdownRef =
|
|
11555
|
+
const planDropdownRef = useRef11(null);
|
|
11461
11556
|
useEffect18(() => {
|
|
11462
11557
|
if (!isPlanSelectorOpen) return;
|
|
11463
11558
|
const handleClickOutside = (event) => {
|
|
@@ -12261,7 +12356,7 @@ function BillingContent({
|
|
|
12261
12356
|
const [showExportModal, setShowExportModal] = useState21(false);
|
|
12262
12357
|
const [exportProgress, setExportProgress] = useState21(null);
|
|
12263
12358
|
const [exportNotice, setExportNotice] = useState21(null);
|
|
12264
|
-
const exportAbortRef =
|
|
12359
|
+
const exportAbortRef = useRef11(null);
|
|
12265
12360
|
const [showBuyCreditsModal, setShowBuyCreditsModal] = useState21(false);
|
|
12266
12361
|
const [subscription, setSubscription] = useState21(null);
|
|
12267
12362
|
const [entitlement, setEntitlement] = useState21(
|
|
@@ -12287,12 +12382,12 @@ function BillingContent({
|
|
|
12287
12382
|
loading: loadingUsageLogs,
|
|
12288
12383
|
error: usageLogsError
|
|
12289
12384
|
} = usageLogsState;
|
|
12290
|
-
const usageLogsRequestRef =
|
|
12291
|
-
const usageLogsStateRef =
|
|
12385
|
+
const usageLogsRequestRef = useRef11(0);
|
|
12386
|
+
const usageLogsStateRef = useRef11(usageLogsState);
|
|
12292
12387
|
usageLogsStateRef.current = usageLogsState;
|
|
12293
|
-
const workspaceIdRef =
|
|
12388
|
+
const workspaceIdRef = useRef11(workspaceId);
|
|
12294
12389
|
workspaceIdRef.current = workspaceId;
|
|
12295
|
-
const loadUsedByNamesRef =
|
|
12390
|
+
const loadUsedByNamesRef = useRef11(null);
|
|
12296
12391
|
loadUsedByNamesRef.current ??= createUsedByNamesLoader((forWorkspace, names) => {
|
|
12297
12392
|
if (forWorkspace !== workspaceIdRef.current) return false;
|
|
12298
12393
|
setUsedByNames(names);
|
|
@@ -12307,6 +12402,10 @@ function BillingContent({
|
|
|
12307
12402
|
);
|
|
12308
12403
|
const [buyCreditsInFlight, setBuyCreditsInFlight] = useState21(false);
|
|
12309
12404
|
const [loadingBilling, setLoadingBilling] = useState21(false);
|
|
12405
|
+
const [planLoadFailed, setPlanLoadFailed] = useState21(false);
|
|
12406
|
+
const billingRequestGate = useRef11(createBillingRequestGate(workspaceId));
|
|
12407
|
+
billingRequestGate.current.setScope(workspaceId);
|
|
12408
|
+
useEffect18(() => () => billingRequestGate.current.invalidate(), []);
|
|
12310
12409
|
const [billingOverviewLoaded, setBillingOverviewLoaded] = useState21(false);
|
|
12311
12410
|
const [loadingTable, setLoadingTable] = useState21(false);
|
|
12312
12411
|
const [showInitialLoader, setShowInitialLoader] = useState21(true);
|
|
@@ -12331,6 +12430,8 @@ function BillingContent({
|
|
|
12331
12430
|
}
|
|
12332
12431
|
}, [api]);
|
|
12333
12432
|
const fetchBillingOverview = useCallback8(async () => {
|
|
12433
|
+
const isCurrent = billingRequestGate.current.begin(workspaceId);
|
|
12434
|
+
if (!isCurrent) return;
|
|
12334
12435
|
setLoadingBilling(true);
|
|
12335
12436
|
setBillingOverviewLoaded(false);
|
|
12336
12437
|
try {
|
|
@@ -12343,8 +12444,13 @@ function BillingContent({
|
|
|
12343
12444
|
api.fetchPlans().catch(() => null),
|
|
12344
12445
|
api.getCustomCreditInfo?.().catch(() => null) ?? Promise.resolve(null)
|
|
12345
12446
|
]);
|
|
12346
|
-
if (
|
|
12347
|
-
|
|
12447
|
+
if (!isCurrent()) return;
|
|
12448
|
+
const knownPlan = subRes && (subRes.subscription || subRes.entitlement || subRes.noSubscriptionConfirmed);
|
|
12449
|
+
setPlanLoadFailed(!knownPlan);
|
|
12450
|
+
if (knownPlan) {
|
|
12451
|
+
setSubscription(subRes.subscription);
|
|
12452
|
+
setEntitlement(subRes.entitlement);
|
|
12453
|
+
}
|
|
12348
12454
|
if (creditsRes?.availableCredits != null)
|
|
12349
12455
|
setAvailableCredits(creditsRes.availableCredits);
|
|
12350
12456
|
setSharedPool(creditsRes?.sharedPool ?? null);
|
|
@@ -12353,11 +12459,14 @@ function BillingContent({
|
|
|
12353
12459
|
setCustomPlanCredits(customRes.data.credits);
|
|
12354
12460
|
}
|
|
12355
12461
|
} catch {
|
|
12462
|
+
if (isCurrent()) setPlanLoadFailed(true);
|
|
12356
12463
|
} finally {
|
|
12357
|
-
|
|
12358
|
-
|
|
12464
|
+
if (isCurrent()) {
|
|
12465
|
+
setLoadingBilling(false);
|
|
12466
|
+
setBillingOverviewLoaded(true);
|
|
12467
|
+
}
|
|
12359
12468
|
}
|
|
12360
|
-
}, [api]);
|
|
12469
|
+
}, [api, workspaceId]);
|
|
12361
12470
|
const fetchUserMap = useCallback8(async () => {
|
|
12362
12471
|
try {
|
|
12363
12472
|
const members = await api.fetchMembers();
|
|
@@ -12553,8 +12662,10 @@ function BillingContent({
|
|
|
12553
12662
|
setInitialFetchTriggered(false);
|
|
12554
12663
|
setBillingOverviewLoaded(false);
|
|
12555
12664
|
setSubscription(null);
|
|
12665
|
+
setPlanLoadFailed(false);
|
|
12556
12666
|
setEntitlement(null);
|
|
12557
12667
|
setAvailableCredits(null);
|
|
12668
|
+
setSharedPool(null);
|
|
12558
12669
|
setProducts([]);
|
|
12559
12670
|
setTotalCredits(null);
|
|
12560
12671
|
setCustomPlanCredits(null);
|
|
@@ -12615,15 +12726,17 @@ function BillingContent({
|
|
|
12615
12726
|
);
|
|
12616
12727
|
const scheduledDowngradeText = subscription?.downgradeScheduled && subscription.plan?.name ? `Downgrades to ${subscription.plan.name}${scheduledDowngradeDateLabel ? ` ${scheduledDowngradeDateLabel}` : ""}` : void 0;
|
|
12617
12728
|
const sponsored = isSponsoredEntitlement(entitlement);
|
|
12618
|
-
const
|
|
12619
|
-
const
|
|
12729
|
+
const planState = planCardState(billingOverviewLoaded, loadingBilling, planLoadFailed, subscription != null);
|
|
12730
|
+
const withoutPlan = planState === "empty";
|
|
12731
|
+
const sponsoredWithoutPlan = sponsored && withoutPlan;
|
|
12732
|
+
const isPlanDetailsLoading = planState === "loading";
|
|
12620
12733
|
const paidFeatures = hasPaidFeatures({ entitlement, subscription });
|
|
12621
|
-
const onEntitlementChangeRef =
|
|
12734
|
+
const onEntitlementChangeRef = useRef11(onEntitlementChange);
|
|
12622
12735
|
onEntitlementChangeRef.current = onEntitlementChange;
|
|
12623
12736
|
useEffect18(() => {
|
|
12624
|
-
if (!billingOverviewLoaded) return;
|
|
12737
|
+
if (!billingOverviewLoaded || loadingBilling || planLoadFailed) return;
|
|
12625
12738
|
onEntitlementChangeRef.current?.({ entitlement, paid: paidFeatures });
|
|
12626
|
-
}, [billingOverviewLoaded, entitlement, paidFeatures]);
|
|
12739
|
+
}, [billingOverviewLoaded, loadingBilling, planLoadFailed, entitlement, paidFeatures]);
|
|
12627
12740
|
const {
|
|
12628
12741
|
used: usedCredits,
|
|
12629
12742
|
remaining: remainingCredits,
|
|
@@ -12893,20 +13006,27 @@ function BillingContent({
|
|
|
12893
13006
|
className: "flex items-start shrink-0 w-full",
|
|
12894
13007
|
style: { gap: 12 },
|
|
12895
13008
|
children: [
|
|
12896
|
-
/* @__PURE__ */
|
|
13009
|
+
planState === "error" ? /* @__PURE__ */ jsxs26("div", { role: "alert", className: "flex-1 min-w-0", style: { padding: 16 }, children: [
|
|
13010
|
+
/* @__PURE__ */ jsx29("p", { children: "Plan details could not be loaded." }),
|
|
13011
|
+
/* @__PURE__ */ jsx29(ScButton14, { text: "Retry plan details", variant: "outline", size: "sm", onClick: () => void fetchBillingOverview() })
|
|
13012
|
+
] }) : /* @__PURE__ */ jsx29(
|
|
12897
13013
|
ScPlanDetailsCard,
|
|
12898
13014
|
{
|
|
12899
|
-
planName:
|
|
13015
|
+
planName: withoutPlan ? "Free" : planName || "Current plan",
|
|
12900
13016
|
planCredits: sponsoredWithoutPlan ? "Shared credits" : planCreditsText,
|
|
12901
|
-
planPrice:
|
|
13017
|
+
planPrice: withoutPlan ? "No paid subscription" : planAmount,
|
|
12902
13018
|
badgeText: "Active",
|
|
12903
13019
|
badgeSubText: scheduledDowngradeText,
|
|
12904
13020
|
currentPlanLabel: "Current plan",
|
|
12905
|
-
upgradeButtonText: subscription?.downgradeScheduled ? "Cancel downgrade" : "Manage Plan",
|
|
13021
|
+
upgradeButtonText: withoutPlan ? "See plans" : navigation.manageBilling ? "Manage Plan" : subscription?.downgradeScheduled ? "Cancel downgrade" : "Manage Plan",
|
|
12906
13022
|
isLoading: isPlanDetailsLoading,
|
|
12907
13023
|
className: "flex-1 min-w-0",
|
|
12908
13024
|
style: { padding: 16, gap: 8 },
|
|
12909
13025
|
onUpgrade: () => {
|
|
13026
|
+
if (navigation.manageBilling) {
|
|
13027
|
+
navigation.manageBilling();
|
|
13028
|
+
return;
|
|
13029
|
+
}
|
|
12910
13030
|
void logBillingEvent("billing_plans_opened", "Plans opened", {
|
|
12911
13031
|
action: "open_plans"
|
|
12912
13032
|
});
|
|
@@ -12931,6 +13051,10 @@ function BillingContent({
|
|
|
12931
13051
|
className: "flex-1 min-w-0",
|
|
12932
13052
|
style: { padding: 16, gap: 8 },
|
|
12933
13053
|
onBuyClick: () => {
|
|
13054
|
+
if (navigation.manageBilling) {
|
|
13055
|
+
navigation.manageBilling();
|
|
13056
|
+
return;
|
|
13057
|
+
}
|
|
12934
13058
|
void logBillingEvent(
|
|
12935
13059
|
"billing_buy_credits_clicked",
|
|
12936
13060
|
"Buy credits clicked",
|
|
@@ -14776,7 +14900,7 @@ function SpecializationDropdown({
|
|
|
14776
14900
|
}) {
|
|
14777
14901
|
const { auth } = useSettingsAdapters();
|
|
14778
14902
|
const [open, setOpen] = useState25(false);
|
|
14779
|
-
const containerRef =
|
|
14903
|
+
const containerRef = useRef12(null);
|
|
14780
14904
|
const [options, setOptions] = useState25([]);
|
|
14781
14905
|
useEffect20(() => {
|
|
14782
14906
|
if (!auth.getSpecializations) return;
|
|
@@ -14914,7 +15038,7 @@ function LanguageDropdown({
|
|
|
14914
15038
|
disabled
|
|
14915
15039
|
}) {
|
|
14916
15040
|
const [open, setOpen] = useState25(false);
|
|
14917
|
-
const containerRef =
|
|
15041
|
+
const containerRef = useRef12(null);
|
|
14918
15042
|
useEffect20(() => {
|
|
14919
15043
|
if (!open) return;
|
|
14920
15044
|
function handleMouseDown(e) {
|
|
@@ -15041,7 +15165,7 @@ function ProfileTab() {
|
|
|
15041
15165
|
const [imagePreview, setImagePreview] = useState25(
|
|
15042
15166
|
void 0
|
|
15043
15167
|
);
|
|
15044
|
-
const fileInputRef =
|
|
15168
|
+
const fileInputRef = useRef12(null);
|
|
15045
15169
|
const profileDisplayName = fullName || user?.email || "User";
|
|
15046
15170
|
const profileImage = imagePreview ?? getUserProfileImage(user);
|
|
15047
15171
|
const profileInitial = profileDisplayName.charAt(0).toUpperCase();
|
|
@@ -15491,13 +15615,13 @@ function WorkspaceListTab({
|
|
|
15491
15615
|
const pageWorkspaces = pageRows.map((row) => row.ws);
|
|
15492
15616
|
const listLoading = loading || serverMode && !serverPage;
|
|
15493
15617
|
const [plans, setPlans] = useState25({});
|
|
15494
|
-
const requestedPlans =
|
|
15618
|
+
const requestedPlans = useRef12(/* @__PURE__ */ new Set());
|
|
15495
15619
|
const visibleIds = [
|
|
15496
15620
|
...currentWorkspace ? [currentWorkspace._id] : [],
|
|
15497
15621
|
...pageWorkspaces.map((ws) => ws._id)
|
|
15498
15622
|
];
|
|
15499
15623
|
const visibleKey = visibleIds.join(",");
|
|
15500
|
-
const mounted =
|
|
15624
|
+
const mounted = useRef12(true);
|
|
15501
15625
|
useEffect20(() => {
|
|
15502
15626
|
mounted.current = true;
|
|
15503
15627
|
return () => {
|
|
@@ -17433,9 +17557,9 @@ function OrganizationPicker({
|
|
|
17433
17557
|
}
|
|
17434
17558
|
|
|
17435
17559
|
// src/use-billing-entitlement.ts
|
|
17436
|
-
import { useEffect as useEffect22, useRef as
|
|
17560
|
+
import { useEffect as useEffect22, useRef as useRef13, useState as useState28 } from "react";
|
|
17437
17561
|
function useBillingEntitlement(fetchCurrentPlan, key) {
|
|
17438
|
-
const fetchRef =
|
|
17562
|
+
const fetchRef = useRef13(fetchCurrentPlan);
|
|
17439
17563
|
fetchRef.current = fetchCurrentPlan;
|
|
17440
17564
|
const [state, setState] = useState28(null);
|
|
17441
17565
|
const [loading, setLoading] = useState28(false);
|
|
@@ -17676,6 +17800,7 @@ export {
|
|
|
17676
17800
|
formatPoolSplit,
|
|
17677
17801
|
groupWorkspaceList,
|
|
17678
17802
|
hasPaidFeatures,
|
|
17803
|
+
inviteUpdate,
|
|
17679
17804
|
isLimitBelowUsage,
|
|
17680
17805
|
isPaidPlan,
|
|
17681
17806
|
isSponsoredEntitlement,
|