@streamoid/settings 0.16.0 → 0.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -721,6 +721,9 @@ interface BillingEntitlement {
721
721
  }
722
722
  interface SubscriptionResponse {
723
723
  data: BillingSubscription | null;
724
+ /** Set only after a successful lookup confirms there is no subscription.
725
+ * Legacy adapters may return data:null on failure, so null alone is unknown. */
726
+ noSubscription?: boolean;
724
727
  /**
725
728
  * Billing's top-level `entitlement` (beside `data`), passed through.
726
729
  * Absent on servers from before it, and from hosts that drop it: then the
@@ -1161,6 +1164,8 @@ interface SettingsApiAdapter {
1161
1164
  fetchReferrals?: () => Promise<unknown[]>;
1162
1165
  }
1163
1166
  interface SettingsNavigationAdapter {
1167
+ /** Read-only hosts can hand billing actions to their central dashboard. */
1168
+ manageBilling?: () => void;
1164
1169
  /**
1165
1170
  * Resolve a fully-qualified URL the host wants Stripe checkout to redirect
1166
1171
  * back to after success / cancel. Both flows typically land on the billing
@@ -2559,13 +2564,15 @@ interface CurrentPlanState {
2559
2564
  entitlement: BillingEntitlement | null;
2560
2565
  /** Gate features on this; see `hasPaidFeatures`. */
2561
2566
  paid: boolean;
2567
+ /** Explicit no-subscription evidence for display; legacy null stays compatible. */
2568
+ noSubscriptionConfirmed?: boolean;
2562
2569
  }
2563
2570
  /**
2564
2571
  * Read the current plan and its entitlement through the host's
2565
2572
  * `fetchCurrentPlan`. A failure that carries an entitlement — billing's 404
2566
2573
  * for a sponsored workspace with no subscription of its own — is not an
2567
- * error: it answers no subscription with that entitlement. Any other failure
2568
- * is thrown, as before.
2574
+ * error: it answers no subscription with that entitlement. A plain 404 also
2575
+ * means no subscription. Authorization, network and server errors still throw.
2569
2576
  */
2570
2577
  declare function loadCurrentPlan(fetchCurrentPlan: () => Promise<SubscriptionResponse>): Promise<CurrentPlanState>;
2571
2578
 
package/dist/index.d.ts CHANGED
@@ -721,6 +721,9 @@ interface BillingEntitlement {
721
721
  }
722
722
  interface SubscriptionResponse {
723
723
  data: BillingSubscription | null;
724
+ /** Set only after a successful lookup confirms there is no subscription.
725
+ * Legacy adapters may return data:null on failure, so null alone is unknown. */
726
+ noSubscription?: boolean;
724
727
  /**
725
728
  * Billing's top-level `entitlement` (beside `data`), passed through.
726
729
  * Absent on servers from before it, and from hosts that drop it: then the
@@ -1161,6 +1164,8 @@ interface SettingsApiAdapter {
1161
1164
  fetchReferrals?: () => Promise<unknown[]>;
1162
1165
  }
1163
1166
  interface SettingsNavigationAdapter {
1167
+ /** Read-only hosts can hand billing actions to their central dashboard. */
1168
+ manageBilling?: () => void;
1164
1169
  /**
1165
1170
  * Resolve a fully-qualified URL the host wants Stripe checkout to redirect
1166
1171
  * back to after success / cancel. Both flows typically land on the billing
@@ -2559,13 +2564,15 @@ interface CurrentPlanState {
2559
2564
  entitlement: BillingEntitlement | null;
2560
2565
  /** Gate features on this; see `hasPaidFeatures`. */
2561
2566
  paid: boolean;
2567
+ /** Explicit no-subscription evidence for display; legacy null stays compatible. */
2568
+ noSubscriptionConfirmed?: boolean;
2562
2569
  }
2563
2570
  /**
2564
2571
  * Read the current plan and its entitlement through the host's
2565
2572
  * `fetchCurrentPlan`. A failure that carries an entitlement — billing's 404
2566
2573
  * for a sponsored workspace with no subscription of its own — is not an
2567
- * error: it answers no subscription with that entitlement. Any other failure
2568
- * is thrown, as before.
2574
+ * error: it answers no subscription with that entitlement. A plain 404 also
2575
+ * means no subscription. Authorization, network and server errors still throw.
2569
2576
  */
2570
2577
  declare function loadCurrentPlan(fetchCurrentPlan: () => Promise<SubscriptionResponse>): Promise<CurrentPlanState>;
2571
2578
 
package/dist/index.js CHANGED
@@ -3305,7 +3305,19 @@ function InviteUpdateModal({
3305
3305
  onInvite,
3306
3306
  onInviteMany
3307
3307
  }) {
3308
- useOverlayOpen(open, onClose);
3308
+ const pendingInvite = (0, import_react9.useRef)(false);
3309
+ const inviteGeneration = (0, import_react9.useRef)(0);
3310
+ const requestClose = () => {
3311
+ if (!pendingInvite.current) onClose();
3312
+ };
3313
+ useOverlayOpen(open, requestClose);
3314
+ (0, import_react9.useEffect)(() => {
3315
+ setSubmitting(false);
3316
+ return () => {
3317
+ inviteGeneration.current += 1;
3318
+ pendingInvite.current = false;
3319
+ };
3320
+ }, [open, mode, userEmail]);
3309
3321
  const [emailValue, setEmailValue] = (0, import_react9.useState)("");
3310
3322
  const [hasChanges, setHasChanges] = (0, import_react9.useState)(false);
3311
3323
  const [role, setRole] = (0, import_react9.useState)("member");
@@ -3400,7 +3412,7 @@ function InviteUpdateModal({
3400
3412
  className: "fixed inset-0 z-50 flex items-center justify-center",
3401
3413
  style: { backgroundColor: "rgba(0, 0, 0, 0.6)" },
3402
3414
  onClick: (e) => {
3403
- if (e.target === e.currentTarget) onClose();
3415
+ if (e.target === e.currentTarget) requestClose();
3404
3416
  },
3405
3417
  children: /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
3406
3418
  "div",
@@ -3443,7 +3455,7 @@ function InviteUpdateModal({
3443
3455
  children: isInvite ? "Invite" : "Update user"
3444
3456
  }
3445
3457
  ),
3446
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: "shrink-0 cursor-pointer", onClick: onClose, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_icons5.SiconClose, { className: "w-6 h-6", color: T6.primary }) })
3458
+ /* @__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
3459
  ]
3448
3460
  }
3449
3461
  ) })
@@ -4578,14 +4590,20 @@ function InviteUpdateModal({
4578
4590
  };
4579
4591
  const standing = showOrganizationStanding ? orgStanding : void 0;
4580
4592
  if (isInvite && onInviteMany) {
4593
+ if (pendingInvite.current) return;
4594
+ pendingInvite.current = true;
4595
+ const generation = ++inviteGeneration.current;
4596
+ const current = () => inviteGeneration.current === generation;
4581
4597
  setSubmitting(true);
4582
- Promise.resolve(
4583
- onInviteMany(perms, parsedEmails.emails, standing)
4584
- ).then((result) => {
4585
- if (result && result.failed.length > 0) {
4598
+ Promise.resolve().then(() => current() ? onInviteMany(perms, parsedEmails.emails, standing) : void 0).then((result) => {
4599
+ if (current() && result && result.failed.length > 0) {
4586
4600
  setEmailValue(result.failed.join(", "));
4587
4601
  }
4588
- }).finally(() => setSubmitting(false));
4602
+ }).catch(() => void 0).finally(() => {
4603
+ if (!current()) return;
4604
+ pendingInvite.current = false;
4605
+ setSubmitting(false);
4606
+ });
4589
4607
  } else if (isInvite && onInvite) {
4590
4608
  for (const email of parsedEmails.emails) {
4591
4609
  onInvite(perms, email, standing);
@@ -5317,12 +5335,17 @@ function TeamsContent({
5317
5335
  isReady: permissionsReady,
5318
5336
  failed: permissionData?.failed
5319
5337
  });
5338
+ const modalSession = (0, import_react10.useRef)(0);
5320
5339
  const [modal, setModal] = (0, import_react10.useState)({
5321
5340
  open: false,
5322
5341
  mode: "invite"
5323
5342
  });
5324
5343
  (0, import_react10.useEffect)(() => {
5344
+ modalSession.current += 1;
5325
5345
  setModal({ open: false, mode: "invite" });
5346
+ return () => {
5347
+ modalSession.current += 1;
5348
+ };
5326
5349
  }, [permissionScope, api]);
5327
5350
  const MOCK_ACTIVE = [
5328
5351
  {
@@ -5471,7 +5494,10 @@ function TeamsContent({
5471
5494
  fetchGeneration.current += 1;
5472
5495
  };
5473
5496
  }, [fetchData]);
5474
- const openInviteModal = () => setModal({ open: true, mode: "invite" });
5497
+ const openInviteModal = () => {
5498
+ modalSession.current += 1;
5499
+ setModal({ open: true, mode: "invite" });
5500
+ };
5475
5501
  (0, import_react10.useEffect)(() => {
5476
5502
  if ((onInviteOpen || inviteRequested) && permissionsReady && !permissionData?.failed) {
5477
5503
  if (viewerCanInvite) openInviteModal();
@@ -5483,6 +5509,7 @@ function TeamsContent({
5483
5509
  onCanInviteChange?.(viewerCanInvite);
5484
5510
  }, [viewerCanInvite, onCanInviteChange]);
5485
5511
  const openUpdateModal = async (member) => {
5512
+ modalSession.current += 1;
5486
5513
  setModal({
5487
5514
  open: true,
5488
5515
  mode: "update",
@@ -5502,7 +5529,10 @@ function TeamsContent({
5502
5529
  } catch {
5503
5530
  }
5504
5531
  };
5505
- const closeModal = () => setModal({ open: false, mode: "invite" });
5532
+ const closeModal = () => {
5533
+ modalSession.current += 1;
5534
+ setModal({ open: false, mode: "invite" });
5535
+ };
5506
5536
  const currentMemberPermissions = modal.target?.permissions;
5507
5537
  const handleSave = async (permissions) => {
5508
5538
  if (!modal.target) {
@@ -5648,6 +5678,9 @@ function TeamsContent({
5648
5678
  }
5649
5679
  };
5650
5680
  const handleInviteMany = async (permissions, emails, organizationStanding) => {
5681
+ const session = modalSession.current;
5682
+ const isCurrent = () => fetchMounted.current && modalSession.current === session && latestFetchScope.current.scope === permissionScope && latestFetchScope.current.api === api;
5683
+ if (!isCurrent()) return { failed: emails };
5651
5684
  if (!viewerCanInvite || permissions.role === "admin" && highestRole !== "admin") {
5652
5685
  toast.error("You do not have permission to invite users");
5653
5686
  closeModal();
@@ -5657,6 +5690,7 @@ function TeamsContent({
5657
5690
  const sent = [];
5658
5691
  const failed = [];
5659
5692
  for (const email of emails) {
5693
+ if (!isCurrent()) return { failed: emails.filter((address) => !sent.includes(address)) };
5660
5694
  try {
5661
5695
  await api.inviteMember({
5662
5696
  email,
@@ -5676,6 +5710,7 @@ function TeamsContent({
5676
5710
  failed.push({ email, message: errorMessage(err, { method: "POST" }) });
5677
5711
  }
5678
5712
  }
5713
+ if (!isCurrent()) return { failed: failed.map((f) => f.email) };
5679
5714
  if (sent.length === 1) toast.success(`Invitation sent to ${sent[0]}`);
5680
5715
  else if (sent.length > 1)
5681
5716
  toast.success(`Invitations sent to ${sent.length} people`);
@@ -5689,7 +5724,7 @@ function TeamsContent({
5689
5724
  );
5690
5725
  }
5691
5726
  if (sent.length > 0) await fetchData();
5692
- if (failed.length === 0) closeModal();
5727
+ if (isCurrent() && failed.length === 0) closeModal();
5693
5728
  return { failed: failed.map((f) => f.email) };
5694
5729
  };
5695
5730
  const filteredActive = activeMembers.filter((m) => {
@@ -7915,6 +7950,35 @@ function OrganizationListContent() {
7915
7950
  ] });
7916
7951
  }
7917
7952
 
7953
+ // src/billing-request-gate.ts
7954
+ function createBillingRequestGate(initialScope) {
7955
+ let scope = initialScope;
7956
+ let generation = 0;
7957
+ return {
7958
+ setScope(next) {
7959
+ if (next !== scope) {
7960
+ scope = next;
7961
+ generation++;
7962
+ }
7963
+ },
7964
+ invalidate() {
7965
+ generation++;
7966
+ },
7967
+ begin(requestScope) {
7968
+ if (requestScope !== scope) return null;
7969
+ const id = ++generation;
7970
+ return () => id === generation && requestScope === scope;
7971
+ }
7972
+ };
7973
+ }
7974
+
7975
+ // src/plan-card-state.ts
7976
+ function planCardState(loaded, loading, failed, hasSubscription) {
7977
+ if (!loaded || loading) return "loading";
7978
+ if (failed) return "error";
7979
+ return hasSubscription ? "ready" : "empty";
7980
+ }
7981
+
7918
7982
  // src/billing-errors.ts
7919
7983
  function isBillingWorkspaceMissing(failure) {
7920
7984
  const seen = /* @__PURE__ */ new Set();
@@ -10866,12 +10930,23 @@ async function loadCurrentPlan(fetchCurrentPlan) {
10866
10930
  response = await fetchCurrentPlan();
10867
10931
  } catch (failure) {
10868
10932
  const entitlement2 = entitlementFromFailure(failure);
10869
- if (!entitlement2) throw failure;
10933
+ if (!entitlement2) {
10934
+ const error = failure;
10935
+ if (error?.status === 404 || error?.response?.status === 404) {
10936
+ return { subscription: null, entitlement: null, paid: false, noSubscriptionConfirmed: true };
10937
+ }
10938
+ throw failure;
10939
+ }
10870
10940
  return { subscription: null, entitlement: entitlement2, paid: entitlement2.paid };
10871
10941
  }
10872
10942
  const subscription = response?.data ?? null;
10873
10943
  const entitlement = entitlementFromBody(response);
10874
- return { subscription, entitlement, paid: hasPaidFeatures({ entitlement, subscription }) };
10944
+ return {
10945
+ subscription,
10946
+ entitlement,
10947
+ paid: hasPaidFeatures({ entitlement, subscription }),
10948
+ ...response?.noSubscription === true ? { noSubscriptionConfirmed: true } : {}
10949
+ };
10875
10950
  }
10876
10951
 
10877
10952
  // src/billing-layout.ts
@@ -12399,6 +12474,10 @@ function BillingContent({
12399
12474
  );
12400
12475
  const [buyCreditsInFlight, setBuyCreditsInFlight] = (0, import_react23.useState)(false);
12401
12476
  const [loadingBilling, setLoadingBilling] = (0, import_react23.useState)(false);
12477
+ const [planLoadFailed, setPlanLoadFailed] = (0, import_react23.useState)(false);
12478
+ const billingRequestGate = (0, import_react23.useRef)(createBillingRequestGate(workspaceId));
12479
+ billingRequestGate.current.setScope(workspaceId);
12480
+ (0, import_react23.useEffect)(() => () => billingRequestGate.current.invalidate(), []);
12402
12481
  const [billingOverviewLoaded, setBillingOverviewLoaded] = (0, import_react23.useState)(false);
12403
12482
  const [loadingTable, setLoadingTable] = (0, import_react23.useState)(false);
12404
12483
  const [showInitialLoader, setShowInitialLoader] = (0, import_react23.useState)(true);
@@ -12423,6 +12502,8 @@ function BillingContent({
12423
12502
  }
12424
12503
  }, [api]);
12425
12504
  const fetchBillingOverview = (0, import_react23.useCallback)(async () => {
12505
+ const isCurrent = billingRequestGate.current.begin(workspaceId);
12506
+ if (!isCurrent) return;
12426
12507
  setLoadingBilling(true);
12427
12508
  setBillingOverviewLoaded(false);
12428
12509
  try {
@@ -12435,8 +12516,13 @@ function BillingContent({
12435
12516
  api.fetchPlans().catch(() => null),
12436
12517
  api.getCustomCreditInfo?.().catch(() => null) ?? Promise.resolve(null)
12437
12518
  ]);
12438
- if (subRes?.subscription) setSubscription(subRes.subscription);
12439
- if (subRes) setEntitlement(subRes.entitlement);
12519
+ if (!isCurrent()) return;
12520
+ const knownPlan = subRes && (subRes.subscription || subRes.entitlement || subRes.noSubscriptionConfirmed);
12521
+ setPlanLoadFailed(!knownPlan);
12522
+ if (knownPlan) {
12523
+ setSubscription(subRes.subscription);
12524
+ setEntitlement(subRes.entitlement);
12525
+ }
12440
12526
  if (creditsRes?.availableCredits != null)
12441
12527
  setAvailableCredits(creditsRes.availableCredits);
12442
12528
  setSharedPool(creditsRes?.sharedPool ?? null);
@@ -12445,11 +12531,14 @@ function BillingContent({
12445
12531
  setCustomPlanCredits(customRes.data.credits);
12446
12532
  }
12447
12533
  } catch {
12534
+ if (isCurrent()) setPlanLoadFailed(true);
12448
12535
  } finally {
12449
- setLoadingBilling(false);
12450
- setBillingOverviewLoaded(true);
12536
+ if (isCurrent()) {
12537
+ setLoadingBilling(false);
12538
+ setBillingOverviewLoaded(true);
12539
+ }
12451
12540
  }
12452
- }, [api]);
12541
+ }, [api, workspaceId]);
12453
12542
  const fetchUserMap = (0, import_react23.useCallback)(async () => {
12454
12543
  try {
12455
12544
  const members = await api.fetchMembers();
@@ -12645,8 +12734,10 @@ function BillingContent({
12645
12734
  setInitialFetchTriggered(false);
12646
12735
  setBillingOverviewLoaded(false);
12647
12736
  setSubscription(null);
12737
+ setPlanLoadFailed(false);
12648
12738
  setEntitlement(null);
12649
12739
  setAvailableCredits(null);
12740
+ setSharedPool(null);
12650
12741
  setProducts([]);
12651
12742
  setTotalCredits(null);
12652
12743
  setCustomPlanCredits(null);
@@ -12707,15 +12798,17 @@ function BillingContent({
12707
12798
  );
12708
12799
  const scheduledDowngradeText = subscription?.downgradeScheduled && subscription.plan?.name ? `Downgrades to ${subscription.plan.name}${scheduledDowngradeDateLabel ? ` ${scheduledDowngradeDateLabel}` : ""}` : void 0;
12709
12800
  const sponsored = isSponsoredEntitlement(entitlement);
12710
- const sponsoredWithoutPlan = sponsored && billingOverviewLoaded && !loadingBilling && subscription == null;
12711
- const isPlanDetailsLoading = sponsoredWithoutPlan ? false : !billingOverviewLoaded || loadingBilling || subscription?.plan == null || !planName || planName === "-" || !planAmount || currentPlanCredits == null;
12801
+ const planState = planCardState(billingOverviewLoaded, loadingBilling, planLoadFailed, subscription != null);
12802
+ const withoutPlan = planState === "empty";
12803
+ const sponsoredWithoutPlan = sponsored && withoutPlan;
12804
+ const isPlanDetailsLoading = planState === "loading";
12712
12805
  const paidFeatures = hasPaidFeatures({ entitlement, subscription });
12713
12806
  const onEntitlementChangeRef = (0, import_react23.useRef)(onEntitlementChange);
12714
12807
  onEntitlementChangeRef.current = onEntitlementChange;
12715
12808
  (0, import_react23.useEffect)(() => {
12716
- if (!billingOverviewLoaded) return;
12809
+ if (!billingOverviewLoaded || loadingBilling || planLoadFailed) return;
12717
12810
  onEntitlementChangeRef.current?.({ entitlement, paid: paidFeatures });
12718
- }, [billingOverviewLoaded, entitlement, paidFeatures]);
12811
+ }, [billingOverviewLoaded, loadingBilling, planLoadFailed, entitlement, paidFeatures]);
12719
12812
  const {
12720
12813
  used: usedCredits,
12721
12814
  remaining: remainingCredits,
@@ -12985,20 +13078,27 @@ function BillingContent({
12985
13078
  className: "flex items-start shrink-0 w-full",
12986
13079
  style: { gap: 12 },
12987
13080
  children: [
12988
- /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
13081
+ planState === "error" ? /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)("div", { role: "alert", className: "flex-1 min-w-0", style: { padding: 16 }, children: [
13082
+ /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("p", { children: "Plan details could not be loaded." }),
13083
+ /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(import_ui17.ScButton, { text: "Retry plan details", variant: "outline", size: "sm", onClick: () => void fetchBillingOverview() })
13084
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
12989
13085
  import_ui17.ScPlanDetailsCard,
12990
13086
  {
12991
- planName: sponsoredWithoutPlan ? "Free" : planName,
13087
+ planName: withoutPlan ? "Free" : planName || "Current plan",
12992
13088
  planCredits: sponsoredWithoutPlan ? "Shared credits" : planCreditsText,
12993
- planPrice: sponsoredWithoutPlan ? `${workspace.current?.country?.trim().toUpperCase() === "IN" ? "\u20B9" : "$"}0.00 / month` : planAmount,
13089
+ planPrice: withoutPlan ? "No paid subscription" : planAmount,
12994
13090
  badgeText: "Active",
12995
13091
  badgeSubText: scheduledDowngradeText,
12996
13092
  currentPlanLabel: "Current plan",
12997
- upgradeButtonText: subscription?.downgradeScheduled ? "Cancel downgrade" : "Manage Plan",
13093
+ upgradeButtonText: withoutPlan ? "See plans" : navigation.manageBilling ? "Manage Plan" : subscription?.downgradeScheduled ? "Cancel downgrade" : "Manage Plan",
12998
13094
  isLoading: isPlanDetailsLoading,
12999
13095
  className: "flex-1 min-w-0",
13000
13096
  style: { padding: 16, gap: 8 },
13001
13097
  onUpgrade: () => {
13098
+ if (navigation.manageBilling) {
13099
+ navigation.manageBilling();
13100
+ return;
13101
+ }
13002
13102
  void logBillingEvent("billing_plans_opened", "Plans opened", {
13003
13103
  action: "open_plans"
13004
13104
  });
@@ -13023,6 +13123,10 @@ function BillingContent({
13023
13123
  className: "flex-1 min-w-0",
13024
13124
  style: { padding: 16, gap: 8 },
13025
13125
  onBuyClick: () => {
13126
+ if (navigation.manageBilling) {
13127
+ navigation.manageBilling();
13128
+ return;
13129
+ }
13026
13130
  void logBillingEvent(
13027
13131
  "billing_buy_credits_clicked",
13028
13132
  "Buy credits clicked",
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 useRef11,
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 useRef5 } from "react";
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,
@@ -3190,7 +3190,19 @@ function InviteUpdateModal({
3190
3190
  onInvite,
3191
3191
  onInviteMany
3192
3192
  }) {
3193
- useOverlayOpen(open, onClose);
3193
+ const pendingInvite = useRef5(false);
3194
+ const inviteGeneration = useRef5(0);
3195
+ const requestClose = () => {
3196
+ if (!pendingInvite.current) onClose();
3197
+ };
3198
+ useOverlayOpen(open, requestClose);
3199
+ useEffect7(() => {
3200
+ setSubmitting(false);
3201
+ return () => {
3202
+ inviteGeneration.current += 1;
3203
+ pendingInvite.current = false;
3204
+ };
3205
+ }, [open, mode, userEmail]);
3194
3206
  const [emailValue, setEmailValue] = useState7("");
3195
3207
  const [hasChanges, setHasChanges] = useState7(false);
3196
3208
  const [role, setRole] = useState7("member");
@@ -3285,7 +3297,7 @@ function InviteUpdateModal({
3285
3297
  className: "fixed inset-0 z-50 flex items-center justify-center",
3286
3298
  style: { backgroundColor: "rgba(0, 0, 0, 0.6)" },
3287
3299
  onClick: (e) => {
3288
- if (e.target === e.currentTarget) onClose();
3300
+ if (e.target === e.currentTarget) requestClose();
3289
3301
  },
3290
3302
  children: /* @__PURE__ */ jsxs11(
3291
3303
  "div",
@@ -3328,7 +3340,7 @@ function InviteUpdateModal({
3328
3340
  children: isInvite ? "Invite" : "Update user"
3329
3341
  }
3330
3342
  ),
3331
- /* @__PURE__ */ jsx14("div", { className: "shrink-0 cursor-pointer", onClick: onClose, children: /* @__PURE__ */ jsx14(SiconClose2, { className: "w-6 h-6", color: T6.primary }) })
3343
+ /* @__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
3344
  ]
3333
3345
  }
3334
3346
  ) })
@@ -4463,14 +4475,20 @@ function InviteUpdateModal({
4463
4475
  };
4464
4476
  const standing = showOrganizationStanding ? orgStanding : void 0;
4465
4477
  if (isInvite && onInviteMany) {
4478
+ if (pendingInvite.current) return;
4479
+ pendingInvite.current = true;
4480
+ const generation = ++inviteGeneration.current;
4481
+ const current = () => inviteGeneration.current === generation;
4466
4482
  setSubmitting(true);
4467
- Promise.resolve(
4468
- onInviteMany(perms, parsedEmails.emails, standing)
4469
- ).then((result) => {
4470
- if (result && result.failed.length > 0) {
4483
+ Promise.resolve().then(() => current() ? onInviteMany(perms, parsedEmails.emails, standing) : void 0).then((result) => {
4484
+ if (current() && result && result.failed.length > 0) {
4471
4485
  setEmailValue(result.failed.join(", "));
4472
4486
  }
4473
- }).finally(() => setSubmitting(false));
4487
+ }).catch(() => void 0).finally(() => {
4488
+ if (!current()) return;
4489
+ pendingInvite.current = false;
4490
+ setSubmitting(false);
4491
+ });
4474
4492
  } else if (isInvite && onInvite) {
4475
4493
  for (const email of parsedEmails.emails) {
4476
4494
  onInvite(perms, email, standing);
@@ -5183,9 +5201,9 @@ function TeamsContent({
5183
5201
  const currentRoster = roster?.scope === permissionScope && roster.api === api ? roster : null;
5184
5202
  const activeMembers = currentRoster?.active ?? [];
5185
5203
  const pendingMembers = currentRoster?.pending ?? [];
5186
- const fetchGeneration = useRef5(0);
5187
- const fetchMounted = useRef5(false);
5188
- const latestFetchScope = useRef5({ scope: permissionScope, api });
5204
+ const fetchGeneration = useRef6(0);
5205
+ const fetchMounted = useRef6(false);
5206
+ const latestFetchScope = useRef6({ scope: permissionScope, api });
5189
5207
  latestFetchScope.current = { scope: permissionScope, api };
5190
5208
  const [permissionData, setPermissionData] = useState8(null);
5191
5209
  const [searchQuery, setSearchQuery] = useState8("");
@@ -5202,12 +5220,17 @@ function TeamsContent({
5202
5220
  isReady: permissionsReady,
5203
5221
  failed: permissionData?.failed
5204
5222
  });
5223
+ const modalSession = useRef6(0);
5205
5224
  const [modal, setModal] = useState8({
5206
5225
  open: false,
5207
5226
  mode: "invite"
5208
5227
  });
5209
5228
  useEffect8(() => {
5229
+ modalSession.current += 1;
5210
5230
  setModal({ open: false, mode: "invite" });
5231
+ return () => {
5232
+ modalSession.current += 1;
5233
+ };
5211
5234
  }, [permissionScope, api]);
5212
5235
  const MOCK_ACTIVE = [
5213
5236
  {
@@ -5356,7 +5379,10 @@ function TeamsContent({
5356
5379
  fetchGeneration.current += 1;
5357
5380
  };
5358
5381
  }, [fetchData]);
5359
- const openInviteModal = () => setModal({ open: true, mode: "invite" });
5382
+ const openInviteModal = () => {
5383
+ modalSession.current += 1;
5384
+ setModal({ open: true, mode: "invite" });
5385
+ };
5360
5386
  useEffect8(() => {
5361
5387
  if ((onInviteOpen || inviteRequested) && permissionsReady && !permissionData?.failed) {
5362
5388
  if (viewerCanInvite) openInviteModal();
@@ -5368,6 +5394,7 @@ function TeamsContent({
5368
5394
  onCanInviteChange?.(viewerCanInvite);
5369
5395
  }, [viewerCanInvite, onCanInviteChange]);
5370
5396
  const openUpdateModal = async (member) => {
5397
+ modalSession.current += 1;
5371
5398
  setModal({
5372
5399
  open: true,
5373
5400
  mode: "update",
@@ -5387,7 +5414,10 @@ function TeamsContent({
5387
5414
  } catch {
5388
5415
  }
5389
5416
  };
5390
- const closeModal = () => setModal({ open: false, mode: "invite" });
5417
+ const closeModal = () => {
5418
+ modalSession.current += 1;
5419
+ setModal({ open: false, mode: "invite" });
5420
+ };
5391
5421
  const currentMemberPermissions = modal.target?.permissions;
5392
5422
  const handleSave = async (permissions) => {
5393
5423
  if (!modal.target) {
@@ -5533,6 +5563,9 @@ function TeamsContent({
5533
5563
  }
5534
5564
  };
5535
5565
  const handleInviteMany = async (permissions, emails, organizationStanding) => {
5566
+ const session = modalSession.current;
5567
+ const isCurrent = () => fetchMounted.current && modalSession.current === session && latestFetchScope.current.scope === permissionScope && latestFetchScope.current.api === api;
5568
+ if (!isCurrent()) return { failed: emails };
5536
5569
  if (!viewerCanInvite || permissions.role === "admin" && highestRole !== "admin") {
5537
5570
  toast.error("You do not have permission to invite users");
5538
5571
  closeModal();
@@ -5542,6 +5575,7 @@ function TeamsContent({
5542
5575
  const sent = [];
5543
5576
  const failed = [];
5544
5577
  for (const email of emails) {
5578
+ if (!isCurrent()) return { failed: emails.filter((address) => !sent.includes(address)) };
5545
5579
  try {
5546
5580
  await api.inviteMember({
5547
5581
  email,
@@ -5561,6 +5595,7 @@ function TeamsContent({
5561
5595
  failed.push({ email, message: errorMessage(err, { method: "POST" }) });
5562
5596
  }
5563
5597
  }
5598
+ if (!isCurrent()) return { failed: failed.map((f) => f.email) };
5564
5599
  if (sent.length === 1) toast.success(`Invitation sent to ${sent[0]}`);
5565
5600
  else if (sent.length > 1)
5566
5601
  toast.success(`Invitations sent to ${sent.length} people`);
@@ -5574,7 +5609,7 @@ function TeamsContent({
5574
5609
  );
5575
5610
  }
5576
5611
  if (sent.length > 0) await fetchData();
5577
- if (failed.length === 0) closeModal();
5612
+ if (isCurrent() && failed.length === 0) closeModal();
5578
5613
  return { failed: failed.map((f) => f.email) };
5579
5614
  };
5580
5615
  const filteredActive = activeMembers.filter((m) => {
@@ -6119,7 +6154,7 @@ function OrganizationMemberModal({
6119
6154
  }
6120
6155
 
6121
6156
  // src/organization-modal.tsx
6122
- import { useState as useState10, useRef as useRef6, useEffect as useEffect10 } from "react";
6157
+ import { useState as useState10, useRef as useRef7, useEffect as useEffect10 } from "react";
6123
6158
  import { Fragment as Fragment7, jsx as jsx18, jsxs as jsxs15 } from "react/jsx-runtime";
6124
6159
  var T10 = {
6125
6160
  primary: "var(--alias-text---icons-primary)",
@@ -6192,7 +6227,7 @@ function OrganizationModal({
6192
6227
  );
6193
6228
  const [submitting, setSubmitting] = useState10(false);
6194
6229
  const [canDelete, setCanDelete] = useState10(false);
6195
- const fileInputRef = useRef6(null);
6230
+ const fileInputRef = useRef7(null);
6196
6231
  const { organization: organizationAdapter } = useSettingsAdapters();
6197
6232
  useEffect10(() => {
6198
6233
  if (open) {
@@ -7512,7 +7547,7 @@ function OrganizationContent({
7512
7547
  }
7513
7548
 
7514
7549
  // src/organization-list-content.tsx
7515
- import { useCallback as useCallback4, useEffect as useEffect12, useRef as useRef7, useState as useState12 } from "react";
7550
+ import { useCallback as useCallback4, useEffect as useEffect12, useRef as useRef8, useState as useState12 } from "react";
7516
7551
  import { ScButton as ScButton7 } from "@streamoid/ui";
7517
7552
  import { jsx as jsx20, jsxs as jsxs17 } from "react/jsx-runtime";
7518
7553
  var T12 = {
@@ -7550,7 +7585,7 @@ function OrganizationListContent() {
7550
7585
  const [openingId, setOpeningId] = useState12(null);
7551
7586
  const [joinable, setJoinable] = useState12([]);
7552
7587
  const [joiningId, setJoiningId] = useState12(null);
7553
- const organizationRef = useRef7(organization);
7588
+ const organizationRef = useRef8(organization);
7554
7589
  organizationRef.current = organization;
7555
7590
  const load = useCallback4(async () => {
7556
7591
  setLoading(true);
@@ -7800,6 +7835,35 @@ function OrganizationListContent() {
7800
7835
  ] });
7801
7836
  }
7802
7837
 
7838
+ // src/billing-request-gate.ts
7839
+ function createBillingRequestGate(initialScope) {
7840
+ let scope = initialScope;
7841
+ let generation = 0;
7842
+ return {
7843
+ setScope(next) {
7844
+ if (next !== scope) {
7845
+ scope = next;
7846
+ generation++;
7847
+ }
7848
+ },
7849
+ invalidate() {
7850
+ generation++;
7851
+ },
7852
+ begin(requestScope) {
7853
+ if (requestScope !== scope) return null;
7854
+ const id = ++generation;
7855
+ return () => id === generation && requestScope === scope;
7856
+ }
7857
+ };
7858
+ }
7859
+
7860
+ // src/plan-card-state.ts
7861
+ function planCardState(loaded, loading, failed, hasSubscription) {
7862
+ if (!loaded || loading) return "loading";
7863
+ if (failed) return "error";
7864
+ return hasSubscription ? "ready" : "empty";
7865
+ }
7866
+
7803
7867
  // src/billing-errors.ts
7804
7868
  function isBillingWorkspaceMissing(failure) {
7805
7869
  const seen = /* @__PURE__ */ new Set();
@@ -7848,7 +7912,7 @@ import {
7848
7912
  useCallback as useCallback8,
7849
7913
  useMemo as useMemo4,
7850
7914
  useReducer,
7851
- useRef as useRef10
7915
+ useRef as useRef11
7852
7916
  } from "react";
7853
7917
  import {
7854
7918
  ScPlanDetailsCard,
@@ -8792,7 +8856,7 @@ function BuyCreditsModal({
8792
8856
  }
8793
8857
 
8794
8858
  // src/per-user-limits-view.tsx
8795
- import { useCallback as useCallback6, useEffect as useEffect14, useMemo as useMemo3, useRef as useRef8, useState as useState16 } from "react";
8859
+ import { useCallback as useCallback6, useEffect as useEffect14, useMemo as useMemo3, useRef as useRef9, useState as useState16 } from "react";
8796
8860
  import { ScButton as ScButton9 } from "@streamoid/ui";
8797
8861
 
8798
8862
  // src/member-credit-limit-modal.tsx
@@ -9299,7 +9363,7 @@ function PerUserLimitsView() {
9299
9363
  const [searchQuery, setSearchQuery] = useState16("");
9300
9364
  const [editing, setEditing] = useState16(null);
9301
9365
  const [editingDefault, setEditingDefault] = useState16(false);
9302
- const latestLoad = useRef8(0);
9366
+ const latestLoad = useRef9(0);
9303
9367
  const load = useCallback6(async ({ refresh = false } = {}) => {
9304
9368
  const loadId = ++latestLoad.current;
9305
9369
  if (!api.fetchMemberCreditLimits) {
@@ -9505,7 +9569,7 @@ function PerUserLimitsView() {
9505
9569
  }
9506
9570
 
9507
9571
  // src/shared-credits-view.tsx
9508
- import { useCallback as useCallback7, useEffect as useEffect17, useRef as useRef9, useState as useState20 } from "react";
9572
+ import { useCallback as useCallback7, useEffect as useEffect17, useRef as useRef10, useState as useState20 } from "react";
9509
9573
  import { ScButton as ScButton13 } from "@streamoid/ui";
9510
9574
 
9511
9575
  // src/connected-apps-shared.tsx
@@ -10541,7 +10605,7 @@ function SharedCreditsView() {
10541
10605
  const [adding, setAdding] = useState20(false);
10542
10606
  const [editing, setEditing] = useState20(null);
10543
10607
  const [removing, setRemoving] = useState20(null);
10544
- const latestLoad = useRef9(0);
10608
+ const latestLoad = useRef10(0);
10545
10609
  const load = useCallback7(
10546
10610
  async ({ refresh = false } = {}) => {
10547
10611
  const loadId = ++latestLoad.current;
@@ -10774,12 +10838,23 @@ async function loadCurrentPlan(fetchCurrentPlan) {
10774
10838
  response = await fetchCurrentPlan();
10775
10839
  } catch (failure) {
10776
10840
  const entitlement2 = entitlementFromFailure(failure);
10777
- if (!entitlement2) throw failure;
10841
+ if (!entitlement2) {
10842
+ const error = failure;
10843
+ if (error?.status === 404 || error?.response?.status === 404) {
10844
+ return { subscription: null, entitlement: null, paid: false, noSubscriptionConfirmed: true };
10845
+ }
10846
+ throw failure;
10847
+ }
10778
10848
  return { subscription: null, entitlement: entitlement2, paid: entitlement2.paid };
10779
10849
  }
10780
10850
  const subscription = response?.data ?? null;
10781
10851
  const entitlement = entitlementFromBody(response);
10782
- return { subscription, entitlement, paid: hasPaidFeatures({ entitlement, subscription }) };
10852
+ return {
10853
+ subscription,
10854
+ entitlement,
10855
+ paid: hasPaidFeatures({ entitlement, subscription }),
10856
+ ...response?.noSubscription === true ? { noSubscriptionConfirmed: true } : {}
10857
+ };
10783
10858
  }
10784
10859
 
10785
10860
  // src/billing-layout.ts
@@ -11457,7 +11532,7 @@ function PlansView({
11457
11532
  selectedMiddlePlan && actionInFlight === selectedMiddlePlan.key
11458
11533
  );
11459
11534
  const [isPlanSelectorOpen, setIsPlanSelectorOpen] = useState21(false);
11460
- const planDropdownRef = useRef10(null);
11535
+ const planDropdownRef = useRef11(null);
11461
11536
  useEffect18(() => {
11462
11537
  if (!isPlanSelectorOpen) return;
11463
11538
  const handleClickOutside = (event) => {
@@ -12261,7 +12336,7 @@ function BillingContent({
12261
12336
  const [showExportModal, setShowExportModal] = useState21(false);
12262
12337
  const [exportProgress, setExportProgress] = useState21(null);
12263
12338
  const [exportNotice, setExportNotice] = useState21(null);
12264
- const exportAbortRef = useRef10(null);
12339
+ const exportAbortRef = useRef11(null);
12265
12340
  const [showBuyCreditsModal, setShowBuyCreditsModal] = useState21(false);
12266
12341
  const [subscription, setSubscription] = useState21(null);
12267
12342
  const [entitlement, setEntitlement] = useState21(
@@ -12287,12 +12362,12 @@ function BillingContent({
12287
12362
  loading: loadingUsageLogs,
12288
12363
  error: usageLogsError
12289
12364
  } = usageLogsState;
12290
- const usageLogsRequestRef = useRef10(0);
12291
- const usageLogsStateRef = useRef10(usageLogsState);
12365
+ const usageLogsRequestRef = useRef11(0);
12366
+ const usageLogsStateRef = useRef11(usageLogsState);
12292
12367
  usageLogsStateRef.current = usageLogsState;
12293
- const workspaceIdRef = useRef10(workspaceId);
12368
+ const workspaceIdRef = useRef11(workspaceId);
12294
12369
  workspaceIdRef.current = workspaceId;
12295
- const loadUsedByNamesRef = useRef10(null);
12370
+ const loadUsedByNamesRef = useRef11(null);
12296
12371
  loadUsedByNamesRef.current ??= createUsedByNamesLoader((forWorkspace, names) => {
12297
12372
  if (forWorkspace !== workspaceIdRef.current) return false;
12298
12373
  setUsedByNames(names);
@@ -12307,6 +12382,10 @@ function BillingContent({
12307
12382
  );
12308
12383
  const [buyCreditsInFlight, setBuyCreditsInFlight] = useState21(false);
12309
12384
  const [loadingBilling, setLoadingBilling] = useState21(false);
12385
+ const [planLoadFailed, setPlanLoadFailed] = useState21(false);
12386
+ const billingRequestGate = useRef11(createBillingRequestGate(workspaceId));
12387
+ billingRequestGate.current.setScope(workspaceId);
12388
+ useEffect18(() => () => billingRequestGate.current.invalidate(), []);
12310
12389
  const [billingOverviewLoaded, setBillingOverviewLoaded] = useState21(false);
12311
12390
  const [loadingTable, setLoadingTable] = useState21(false);
12312
12391
  const [showInitialLoader, setShowInitialLoader] = useState21(true);
@@ -12331,6 +12410,8 @@ function BillingContent({
12331
12410
  }
12332
12411
  }, [api]);
12333
12412
  const fetchBillingOverview = useCallback8(async () => {
12413
+ const isCurrent = billingRequestGate.current.begin(workspaceId);
12414
+ if (!isCurrent) return;
12334
12415
  setLoadingBilling(true);
12335
12416
  setBillingOverviewLoaded(false);
12336
12417
  try {
@@ -12343,8 +12424,13 @@ function BillingContent({
12343
12424
  api.fetchPlans().catch(() => null),
12344
12425
  api.getCustomCreditInfo?.().catch(() => null) ?? Promise.resolve(null)
12345
12426
  ]);
12346
- if (subRes?.subscription) setSubscription(subRes.subscription);
12347
- if (subRes) setEntitlement(subRes.entitlement);
12427
+ if (!isCurrent()) return;
12428
+ const knownPlan = subRes && (subRes.subscription || subRes.entitlement || subRes.noSubscriptionConfirmed);
12429
+ setPlanLoadFailed(!knownPlan);
12430
+ if (knownPlan) {
12431
+ setSubscription(subRes.subscription);
12432
+ setEntitlement(subRes.entitlement);
12433
+ }
12348
12434
  if (creditsRes?.availableCredits != null)
12349
12435
  setAvailableCredits(creditsRes.availableCredits);
12350
12436
  setSharedPool(creditsRes?.sharedPool ?? null);
@@ -12353,11 +12439,14 @@ function BillingContent({
12353
12439
  setCustomPlanCredits(customRes.data.credits);
12354
12440
  }
12355
12441
  } catch {
12442
+ if (isCurrent()) setPlanLoadFailed(true);
12356
12443
  } finally {
12357
- setLoadingBilling(false);
12358
- setBillingOverviewLoaded(true);
12444
+ if (isCurrent()) {
12445
+ setLoadingBilling(false);
12446
+ setBillingOverviewLoaded(true);
12447
+ }
12359
12448
  }
12360
- }, [api]);
12449
+ }, [api, workspaceId]);
12361
12450
  const fetchUserMap = useCallback8(async () => {
12362
12451
  try {
12363
12452
  const members = await api.fetchMembers();
@@ -12553,8 +12642,10 @@ function BillingContent({
12553
12642
  setInitialFetchTriggered(false);
12554
12643
  setBillingOverviewLoaded(false);
12555
12644
  setSubscription(null);
12645
+ setPlanLoadFailed(false);
12556
12646
  setEntitlement(null);
12557
12647
  setAvailableCredits(null);
12648
+ setSharedPool(null);
12558
12649
  setProducts([]);
12559
12650
  setTotalCredits(null);
12560
12651
  setCustomPlanCredits(null);
@@ -12615,15 +12706,17 @@ function BillingContent({
12615
12706
  );
12616
12707
  const scheduledDowngradeText = subscription?.downgradeScheduled && subscription.plan?.name ? `Downgrades to ${subscription.plan.name}${scheduledDowngradeDateLabel ? ` ${scheduledDowngradeDateLabel}` : ""}` : void 0;
12617
12708
  const sponsored = isSponsoredEntitlement(entitlement);
12618
- const sponsoredWithoutPlan = sponsored && billingOverviewLoaded && !loadingBilling && subscription == null;
12619
- const isPlanDetailsLoading = sponsoredWithoutPlan ? false : !billingOverviewLoaded || loadingBilling || subscription?.plan == null || !planName || planName === "-" || !planAmount || currentPlanCredits == null;
12709
+ const planState = planCardState(billingOverviewLoaded, loadingBilling, planLoadFailed, subscription != null);
12710
+ const withoutPlan = planState === "empty";
12711
+ const sponsoredWithoutPlan = sponsored && withoutPlan;
12712
+ const isPlanDetailsLoading = planState === "loading";
12620
12713
  const paidFeatures = hasPaidFeatures({ entitlement, subscription });
12621
- const onEntitlementChangeRef = useRef10(onEntitlementChange);
12714
+ const onEntitlementChangeRef = useRef11(onEntitlementChange);
12622
12715
  onEntitlementChangeRef.current = onEntitlementChange;
12623
12716
  useEffect18(() => {
12624
- if (!billingOverviewLoaded) return;
12717
+ if (!billingOverviewLoaded || loadingBilling || planLoadFailed) return;
12625
12718
  onEntitlementChangeRef.current?.({ entitlement, paid: paidFeatures });
12626
- }, [billingOverviewLoaded, entitlement, paidFeatures]);
12719
+ }, [billingOverviewLoaded, loadingBilling, planLoadFailed, entitlement, paidFeatures]);
12627
12720
  const {
12628
12721
  used: usedCredits,
12629
12722
  remaining: remainingCredits,
@@ -12893,20 +12986,27 @@ function BillingContent({
12893
12986
  className: "flex items-start shrink-0 w-full",
12894
12987
  style: { gap: 12 },
12895
12988
  children: [
12896
- /* @__PURE__ */ jsx29(
12989
+ planState === "error" ? /* @__PURE__ */ jsxs26("div", { role: "alert", className: "flex-1 min-w-0", style: { padding: 16 }, children: [
12990
+ /* @__PURE__ */ jsx29("p", { children: "Plan details could not be loaded." }),
12991
+ /* @__PURE__ */ jsx29(ScButton14, { text: "Retry plan details", variant: "outline", size: "sm", onClick: () => void fetchBillingOverview() })
12992
+ ] }) : /* @__PURE__ */ jsx29(
12897
12993
  ScPlanDetailsCard,
12898
12994
  {
12899
- planName: sponsoredWithoutPlan ? "Free" : planName,
12995
+ planName: withoutPlan ? "Free" : planName || "Current plan",
12900
12996
  planCredits: sponsoredWithoutPlan ? "Shared credits" : planCreditsText,
12901
- planPrice: sponsoredWithoutPlan ? `${workspace.current?.country?.trim().toUpperCase() === "IN" ? "\u20B9" : "$"}0.00 / month` : planAmount,
12997
+ planPrice: withoutPlan ? "No paid subscription" : planAmount,
12902
12998
  badgeText: "Active",
12903
12999
  badgeSubText: scheduledDowngradeText,
12904
13000
  currentPlanLabel: "Current plan",
12905
- upgradeButtonText: subscription?.downgradeScheduled ? "Cancel downgrade" : "Manage Plan",
13001
+ upgradeButtonText: withoutPlan ? "See plans" : navigation.manageBilling ? "Manage Plan" : subscription?.downgradeScheduled ? "Cancel downgrade" : "Manage Plan",
12906
13002
  isLoading: isPlanDetailsLoading,
12907
13003
  className: "flex-1 min-w-0",
12908
13004
  style: { padding: 16, gap: 8 },
12909
13005
  onUpgrade: () => {
13006
+ if (navigation.manageBilling) {
13007
+ navigation.manageBilling();
13008
+ return;
13009
+ }
12910
13010
  void logBillingEvent("billing_plans_opened", "Plans opened", {
12911
13011
  action: "open_plans"
12912
13012
  });
@@ -12931,6 +13031,10 @@ function BillingContent({
12931
13031
  className: "flex-1 min-w-0",
12932
13032
  style: { padding: 16, gap: 8 },
12933
13033
  onBuyClick: () => {
13034
+ if (navigation.manageBilling) {
13035
+ navigation.manageBilling();
13036
+ return;
13037
+ }
12934
13038
  void logBillingEvent(
12935
13039
  "billing_buy_credits_clicked",
12936
13040
  "Buy credits clicked",
@@ -14776,7 +14880,7 @@ function SpecializationDropdown({
14776
14880
  }) {
14777
14881
  const { auth } = useSettingsAdapters();
14778
14882
  const [open, setOpen] = useState25(false);
14779
- const containerRef = useRef11(null);
14883
+ const containerRef = useRef12(null);
14780
14884
  const [options, setOptions] = useState25([]);
14781
14885
  useEffect20(() => {
14782
14886
  if (!auth.getSpecializations) return;
@@ -14914,7 +15018,7 @@ function LanguageDropdown({
14914
15018
  disabled
14915
15019
  }) {
14916
15020
  const [open, setOpen] = useState25(false);
14917
- const containerRef = useRef11(null);
15021
+ const containerRef = useRef12(null);
14918
15022
  useEffect20(() => {
14919
15023
  if (!open) return;
14920
15024
  function handleMouseDown(e) {
@@ -15041,7 +15145,7 @@ function ProfileTab() {
15041
15145
  const [imagePreview, setImagePreview] = useState25(
15042
15146
  void 0
15043
15147
  );
15044
- const fileInputRef = useRef11(null);
15148
+ const fileInputRef = useRef12(null);
15045
15149
  const profileDisplayName = fullName || user?.email || "User";
15046
15150
  const profileImage = imagePreview ?? getUserProfileImage(user);
15047
15151
  const profileInitial = profileDisplayName.charAt(0).toUpperCase();
@@ -15491,13 +15595,13 @@ function WorkspaceListTab({
15491
15595
  const pageWorkspaces = pageRows.map((row) => row.ws);
15492
15596
  const listLoading = loading || serverMode && !serverPage;
15493
15597
  const [plans, setPlans] = useState25({});
15494
- const requestedPlans = useRef11(/* @__PURE__ */ new Set());
15598
+ const requestedPlans = useRef12(/* @__PURE__ */ new Set());
15495
15599
  const visibleIds = [
15496
15600
  ...currentWorkspace ? [currentWorkspace._id] : [],
15497
15601
  ...pageWorkspaces.map((ws) => ws._id)
15498
15602
  ];
15499
15603
  const visibleKey = visibleIds.join(",");
15500
- const mounted = useRef11(true);
15604
+ const mounted = useRef12(true);
15501
15605
  useEffect20(() => {
15502
15606
  mounted.current = true;
15503
15607
  return () => {
@@ -17433,9 +17537,9 @@ function OrganizationPicker({
17433
17537
  }
17434
17538
 
17435
17539
  // src/use-billing-entitlement.ts
17436
- import { useEffect as useEffect22, useRef as useRef12, useState as useState28 } from "react";
17540
+ import { useEffect as useEffect22, useRef as useRef13, useState as useState28 } from "react";
17437
17541
  function useBillingEntitlement(fetchCurrentPlan, key) {
17438
- const fetchRef = useRef12(fetchCurrentPlan);
17542
+ const fetchRef = useRef13(fetchCurrentPlan);
17439
17543
  fetchRef.current = fetchCurrentPlan;
17440
17544
  const [state, setState] = useState28(null);
17441
17545
  const [loading, setLoading] = useState28(false);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamoid/settings",
3
- "version": "0.16.0",
3
+ "version": "0.16.1",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",