@antelopejs/dms-saas 0.5.0 → 0.6.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.
Files changed (100) hide show
  1. package/README.md +12 -1
  2. package/dist/billing-state/recovery.js +2 -2
  3. package/dist/billing-state/recovery.js.map +1 -1
  4. package/dist/pages/platform/credit-notes.js +1 -1
  5. package/dist/pages/platform/credit-notes.js.map +1 -1
  6. package/dist/pages/platform/features.js +3 -1
  7. package/dist/pages/platform/features.js.map +1 -1
  8. package/dist/pages/platform/invoices.js +2 -2
  9. package/dist/pages/platform/invoices.js.map +1 -1
  10. package/dist/pages/platform/plans/index.js +15 -9
  11. package/dist/pages/platform/plans/index.js.map +1 -1
  12. package/dist/pages/platform/plans/migrations.js +2 -2
  13. package/dist/pages/platform/plans/migrations.js.map +1 -1
  14. package/dist/pages/platform/segments/index.js +1 -1
  15. package/dist/pages/platform/segments/index.js.map +1 -1
  16. package/dist/pages/platform/users/detail.js +11 -3
  17. package/dist/pages/platform/users/detail.js.map +1 -1
  18. package/dist/pages/platform/users/index.js +1 -1
  19. package/dist/pages/platform/users/index.js.map +1 -1
  20. package/dist/pages/platform/workspaces/detail.js +1 -1
  21. package/dist/pages/platform/workspaces/detail.js.map +1 -1
  22. package/dist/pages/platform/workspaces/index.js +2 -2
  23. package/dist/pages/platform/workspaces/index.js.map +1 -1
  24. package/dist/pages/tenant/billing.js +2 -2
  25. package/dist/pages/tenant/billing.js.map +1 -1
  26. package/dist/stripe/client.d.ts +3 -0
  27. package/dist/stripe/client.js +16 -1
  28. package/dist/stripe/client.js.map +1 -1
  29. package/dist/stripe/customer-billing.js +1 -1
  30. package/dist/stripe/customer-billing.js.map +1 -1
  31. package/dist/stripe/subscription-cancellation.js +1 -1
  32. package/dist/stripe/subscription-cancellation.js.map +1 -1
  33. package/dist/stripe/upcoming-invoice.js +3 -3
  34. package/dist/stripe/upcoming-invoice.js.map +1 -1
  35. package/dist/types/config.d.ts +2 -0
  36. package/dist/types/config.js.map +1 -1
  37. package/frontend-vue/app/build/PayInvoicePanel.vue +4 -8
  38. package/frontend-vue/app/build/PlanChangeReview.vue +3 -6
  39. package/frontend-vue/app/build/public/RegistrationCardField.vue +6 -3
  40. package/frontend-vue/app/build/segments/useSegmentCatalog.ts +7 -12
  41. package/frontend-vue/app/build/useWorkspaceName.ts +1 -2
  42. package/frontend-vue/app/build/users/useUserDetail.ts +8 -10
  43. package/frontend-vue/app/build/workspace-detail/ComplimentaryDialog.vue +5 -3
  44. package/frontend-vue/app/build/workspace-detail/CreditDialog.vue +5 -3
  45. package/frontend-vue/app/build/workspace-detail/UpgradeDialog.vue +14 -7
  46. package/frontend-vue/app/build/workspace-detail/useWorkspaceActions.ts +11 -10
  47. package/frontend-vue/app/build/workspace-detail/useWorkspaceOverview.ts +16 -30
  48. package/frontend-vue/app/components/CustomerPortalButton.vue +6 -4
  49. package/frontend-vue/app/components/DataExport.vue +34 -54
  50. package/frontend-vue/app/components/DataExportHistory.vue +2 -7
  51. package/frontend-vue/app/components/IssueCreditNoteModal.vue +5 -4
  52. package/frontend-vue/app/components/MigrationStripeCheck.vue +11 -8
  53. package/frontend-vue/app/components/PastDueAlert.vue +8 -6
  54. package/frontend-vue/app/components/PastDueBanner.vue +4 -4
  55. package/frontend-vue/app/components/PaymentMethodCard.vue +7 -12
  56. package/frontend-vue/app/components/PlanAccessEditor.vue +31 -30
  57. package/frontend-vue/app/components/PlanCard.vue +2 -3
  58. package/frontend-vue/app/components/PlanEditorPreview.vue +27 -36
  59. package/frontend-vue/app/components/PlanUpgradeModal.vue +1 -1
  60. package/frontend-vue/app/components/PlatformNotes.vue +27 -28
  61. package/frontend-vue/app/components/Pricing.vue +16 -23
  62. package/frontend-vue/app/components/RefundButton.vue +62 -46
  63. package/frontend-vue/app/components/RetirePlanModal.vue +13 -7
  64. package/frontend-vue/app/components/SeatQuotaBanner.vue +9 -10
  65. package/frontend-vue/app/components/SegmentConditionsBuilder.vue +0 -1
  66. package/frontend-vue/app/components/SegmentRulesText.vue +1 -3
  67. package/frontend-vue/app/components/TenantBillingForm.vue +14 -19
  68. package/frontend-vue/app/components/TenantPlanCard.vue +19 -22
  69. package/frontend-vue/app/components/TrialEndingBanner.vue +5 -10
  70. package/frontend-vue/app/components/UserPlatformRoleCard.vue +8 -9
  71. package/frontend-vue/app/components/UserSegmentMatches.vue +8 -16
  72. package/frontend-vue/app/components/UserSummaryCard.vue +2 -4
  73. package/frontend-vue/app/components/WorkspaceAdminCreateModal.vue +13 -5
  74. package/frontend-vue/app/components/WorkspaceCreateModal.vue +5 -1
  75. package/frontend-vue/app/components/WorkspaceDangerZone.vue +8 -7
  76. package/frontend-vue/app/components/WorkspaceDetailHeader.vue +14 -4
  77. package/frontend-vue/app/components/WorkspaceSuspended.vue +27 -32
  78. package/frontend-vue/app/components/WorkspaceSwitcherWidget.vue +5 -16
  79. package/frontend-vue/app/composables/useBillingIdentity.ts +9 -5
  80. package/frontend-vue/app/composables/useBillingStatus.ts +8 -7
  81. package/frontend-vue/app/composables/useCurrentWorkspace.ts +6 -8
  82. package/frontend-vue/app/composables/useExportHistory.ts +67 -78
  83. package/frontend-vue/app/composables/useMountedData.ts +27 -0
  84. package/frontend-vue/app/composables/useMyWorkspaces.ts +24 -27
  85. package/frontend-vue/app/composables/useNextInvoice.ts +7 -6
  86. package/frontend-vue/app/composables/useOnDemandRead.ts +49 -0
  87. package/frontend-vue/app/composables/usePendingCheckout.ts +2 -1
  88. package/frontend-vue/app/composables/usePlanCatalog.ts +3 -9
  89. package/frontend-vue/app/composables/usePublicPricing.ts +24 -0
  90. package/frontend-vue/app/composables/useSaasRegistration.ts +2 -0
  91. package/frontend-vue/app/composables/useSeatQuota.ts +2 -6
  92. package/frontend-vue/app/composables/useTenantPlan.ts +26 -9
  93. package/frontend-vue/app/composables/useWorkspaceOverview.ts +2 -6
  94. package/frontend-vue/i18n/locales/saas-public-en-GB.json +1 -0
  95. package/frontend-vue/i18n/locales/saas-public-fr-FR.json +1 -0
  96. package/frontend-vue/package.json +1 -1
  97. package/package.json +4 -4
  98. package/frontend-vue/app/composables/useServerConfirm.ts +0 -44
  99. package/frontend-vue/app/composables/useSharedRequest.ts +0 -54
  100. package/frontend-vue/app/composables/useWorkspaceAccessCache.ts +0 -52
@@ -4,7 +4,7 @@
4
4
  * billing answers a visitor needs before signing up. Every plan leads to
5
5
  * Register with the plan chosen.
6
6
  */
7
- import { computed, onMounted, ref, watch } from 'vue'
7
+ import { computed, ref, watch } from 'vue'
8
8
  import PricingComparison from '../build/public/PricingComparison.vue'
9
9
  import PricingFaq from '../build/public/PricingFaq.vue'
10
10
  import {
@@ -20,26 +20,30 @@ import {
20
20
  LOGIN_PATH,
21
21
  registerPathFor,
22
22
  } from '../build/public/routes'
23
- import {
24
- onPublicLocaleChange,
25
- usePublicFetch,
26
- } from '../build/public/usePublicFetch'
27
23
  import type { PlanInterval } from '../composables/usePlanIntervalLabel'
28
24
 
29
- const PRICING_ENDPOINT = '/api/saas/pricing'
30
25
  const SKELETON_CARDS = 3
31
26
 
32
27
  const { t } = useI18n()
33
- const publicFetch = usePublicFetch()
34
28
  const { resolveApiError } = useApiErrorMessage()
35
29
  const config = useDmsRuntimeConfig()
36
30
  const saasConfig = config.public.dmsSaas as
37
31
  | DmsSaasPublicRuntimeConfig
38
32
  | undefined
39
33
 
40
- const pricing = ref<PublicPricing | null>(null)
41
- const isLoading = ref(true)
42
- const loadError = ref<string | null>(null)
34
+ const pricingRead = usePublicPricing()
35
+ const pricing = computed<PublicPricing | null>(() => pricingRead.data.value)
36
+ // A retry shows the skeleton again, not the failure it replaces.
37
+ const isLoading = computed(
38
+ () =>
39
+ !pricing.value &&
40
+ (pricingRead.status.value === 'pending' || !pricingRead.error.value),
41
+ )
42
+ const loadError = computed(() =>
43
+ pricingRead.error.value
44
+ ? resolveApiError(pricingRead.error.value, 'saas.public.pricing.load_error')
45
+ : null,
46
+ )
43
47
  const interval = ref<PlanInterval>('month')
44
48
 
45
49
  const canRegister = isSelfRegistrationOpen(saasConfig)
@@ -99,20 +103,9 @@ watch(intervals, (available) => {
99
103
  }
100
104
  })
101
105
 
102
- async function loadPricing(): Promise<void> {
103
- isLoading.value = true
104
- loadError.value = null
105
- try {
106
- pricing.value = await publicFetch<PublicPricing>(PRICING_ENDPOINT)
107
- } catch (error) {
108
- loadError.value = resolveApiError(error, 'saas.public.pricing.load_error')
109
- } finally {
110
- isLoading.value = false
111
- }
106
+ function loadPricing(): void {
107
+ void pricingRead.refresh()
112
108
  }
113
-
114
- onMounted(loadPricing)
115
- onPublicLocaleChange(loadPricing)
116
109
  </script>
117
110
 
118
111
  <template>
@@ -1,5 +1,5 @@
1
1
  <script setup lang="ts">
2
- import { computed, onMounted, ref } from 'vue'
2
+ import { computed } from 'vue'
3
3
 
4
4
  /** `GET /api/saas/billing/refund-eligibility`. */
5
5
  interface RefundEligibility {
@@ -17,6 +17,25 @@ interface RefundEligibility {
17
17
 
18
18
  type GuaranteeState = 'open' | 'ended' | 'refunded' | 'not_started' | 'blocked'
19
19
 
20
+ /** `GET /api/saas/billing/access`, as far as the card reads it. */
21
+ interface WorkspaceAccess {
22
+ blocked: boolean
23
+ isTenantOwner: boolean
24
+ }
25
+
26
+ /** What the card shows, read in one go: the eligibility is the owner's. */
27
+ interface RefundGuarantee {
28
+ isOwner: boolean
29
+ isBlocked: boolean
30
+ eligibility: RefundEligibility | null
31
+ /** Days the data is kept once the subscription stops. */
32
+ retentionDays: number
33
+ /** The owner's eligibility could not be read. */
34
+ hasFailed: boolean
35
+ }
36
+
37
+ const ACCESS_ENDPOINT = '/api/saas/billing/access'
38
+ const CURRENT_WORKSPACE_ENDPOINT = '/api/saas/workspaces/current'
20
39
  const ELIGIBILITY_ENDPOINT = '/api/saas/billing/refund-eligibility'
21
40
  const REFUND_ENDPOINT = '/api/saas/billing/refund-self'
22
41
  const KEY_PREFIX = 'saas.tenant_billing.money_back'
@@ -42,13 +61,43 @@ const { resolveApiError } = useApiErrorMessage()
42
61
  const { formatMinorUnits } = useMoneyFormat()
43
62
  const billingStatus = useBillingStatus()
44
63
  const tenantPlan = useTenantPlan()
45
- const { workspace, load: loadWorkspace } = useCurrentWorkspace()
46
64
 
47
- const eligibility = ref<RefundEligibility | null>(null)
48
- const isOwner = ref(false)
49
- const isBlocked = ref(false)
50
- const isLoading = ref(true)
51
- const loadFailed = ref(false)
65
+ /**
66
+ * The eligibility read is owner-only; it stays open while the access gate
67
+ * blocks the workspace, so a refunded guarantee is still told apart. A failed
68
+ * access read fails open, as the backend gate still denies every surface.
69
+ */
70
+ const guarantee = useApiData<RefundGuarantee>(
71
+ 'saas-refund-guarantee',
72
+ async ({ $authFetch, signal }) => {
73
+ const access = await $authFetch<WorkspaceAccess>(ACCESS_ENDPOINT, {
74
+ signal,
75
+ }).catch(() => null)
76
+ const isOwner = !!access?.isTenantOwner
77
+ const read: RefundGuarantee = {
78
+ isOwner,
79
+ isBlocked: !!access?.blocked,
80
+ eligibility: null,
81
+ retentionDays: 0,
82
+ hasFailed: false,
83
+ }
84
+ if (!isOwner) return read
85
+ try {
86
+ const [eligibility, workspace] = await Promise.all([
87
+ $authFetch<RefundEligibility>(ELIGIBILITY_ENDPOINT, { signal }),
88
+ $authFetch<CurrentWorkspace>(CURRENT_WORKSPACE_ENDPOINT, { signal }),
89
+ ])
90
+ return { ...read, eligibility, retentionDays: workspace.retentionDays }
91
+ } catch {
92
+ return { ...read, hasFailed: true }
93
+ }
94
+ },
95
+ )
96
+ const eligibility = computed(() => guarantee.data.value?.eligibility ?? null)
97
+ const isOwner = computed(() => !!guarantee.data.value?.isOwner)
98
+ const isBlocked = computed(() => !!guarantee.data.value?.isBlocked)
99
+ const isLoading = computed(() => guarantee.pending.value)
100
+ const loadFailed = computed(() => !!guarantee.data.value?.hasFailed)
52
101
 
53
102
  // A refund blocks the workspace (it cancels the subscription): a refunded
54
103
  // guarantee says so before the access gate is mentioned.
@@ -102,7 +151,7 @@ const params = computed(() => ({
102
151
  window: eligibility.value?.windowDays ?? 0,
103
152
  days: daysLeft.value,
104
153
  day: dayOfWindow.value,
105
- retention: workspace.value?.retentionDays ?? 0,
154
+ retention: guarantee.data.value?.retentionDays ?? 0,
106
155
  }))
107
156
 
108
157
  const pill = computed(() => {
@@ -121,34 +170,6 @@ const pill = computed(() => {
121
170
  return null
122
171
  })
123
172
 
124
- async function loadEligibility(): Promise<void> {
125
- isLoading.value = true
126
- loadFailed.value = false
127
- try {
128
- eligibility.value =
129
- await $authFetch<RefundEligibility>(ELIGIBILITY_ENDPOINT)
130
- } catch {
131
- loadFailed.value = true
132
- } finally {
133
- isLoading.value = false
134
- }
135
- }
136
-
137
- /** The eligibility read is owner-only; it stays open while the access gate
138
- * blocks the workspace, so a refunded guarantee is still told apart. */
139
- async function loadIfOffered(): Promise<void> {
140
- const access = await loadWorkspaceAccess()
141
- isOwner.value = !!access?.isTenantOwner
142
- isBlocked.value = !!access?.blocked
143
- if (!isOwner.value) {
144
- isLoading.value = false
145
- return
146
- }
147
- void loadWorkspace().catch(() => undefined)
148
- void tenantPlan.load()
149
- await loadEligibility()
150
- }
151
-
152
173
  async function submitRefund(): Promise<void> {
153
174
  await $authFetch(REFUND_ENDPOINT, { method: 'POST' })
154
175
  toast.add({
@@ -156,16 +177,12 @@ async function submitRefund(): Promise<void> {
156
177
  color: 'success',
157
178
  icon: 'i-ph-check-circle',
158
179
  })
159
- await Promise.all([
160
- loadEligibility(),
161
- tenantPlan.refresh(),
162
- billingStatus.refresh(),
163
- ])
164
- refreshPageBlocks()
180
+ // The dialog closes once the page shows the refund.
181
+ await refreshPageBlocks()
165
182
  }
166
183
 
167
184
  async function requestRefund(): Promise<void> {
168
- await billingStatus.load()
185
+ await billingStatus
169
186
  const card = billingStatus.data.value?.paymentMethod
170
187
  const members = tenantPlan.data.value?.seats.members ?? 0
171
188
  await confirm({
@@ -211,13 +228,12 @@ async function requestRefund(): Promise<void> {
211
228
  },
212
229
  })
213
230
  }
214
-
215
- onMounted(loadIfOffered)
216
231
  </script>
217
232
 
218
233
  <template>
219
234
  <DmsCard
220
235
  v-if="isOwner && (isLoading || loadFailed || state)"
236
+ class="grow"
221
237
  :title="$t(`${KEY_PREFIX}.title`)"
222
238
  >
223
239
  <template v-if="pill" #actions>
@@ -233,7 +249,7 @@ onMounted(loadIfOffered)
233
249
  <DmsSaasLoadFailure
234
250
  v-else-if="loadFailed"
235
251
  :title="$t(`${KEY_PREFIX}.load_failed`)"
236
- @retry="loadEligibility"
252
+ @retry="guarantee.refresh()"
237
253
  />
238
254
 
239
255
  <div v-else-if="state === 'open'" class="flex flex-col gap-4">
@@ -78,6 +78,14 @@ const prepareError = ref<string | null>(null)
78
78
  const notifyOwners = ref(true)
79
79
  const typed = ref('')
80
80
  const isSubmitting = ref(false)
81
+ const impactRead = useOnDemandRead<RetireImpact>(() =>
82
+ planId.value ? `${RETIRE_ENDPOINT}/${planId.value}/impact` : null,
83
+ )
84
+ const preparationRead = useOnDemandRead<RetirePreparation>(() =>
85
+ planId.value && targetPlanId.value
86
+ ? `${RETIRE_ENDPOINT}/${planId.value}/prepare/${targetPlanId.value}`
87
+ : null,
88
+ )
81
89
  const submitError = ref<string | null>(null)
82
90
  const typedError = ref<string | null>(null)
83
91
 
@@ -187,12 +195,12 @@ async function loadImpact(): Promise<void> {
187
195
  isLoading.value = true
188
196
  loadError.value = null
189
197
  try {
190
- const [loaded, catalog] = await Promise.all([
191
- $authFetch<RetireImpact>(`${RETIRE_ENDPOINT}/${planId.value}/impact`),
192
- planCatalog.load(),
198
+ const [loaded] = await Promise.all([
199
+ impactRead.read(),
200
+ planCatalog,
193
201
  ])
194
202
  impact.value = loaded
195
- features.value = catalog?.features ?? []
203
+ features.value = planCatalog.data.value?.features ?? []
196
204
  } catch (error) {
197
205
  loadError.value = processApiMessage(readError(error))
198
206
  } finally {
@@ -209,9 +217,7 @@ async function prepare(): Promise<void> {
209
217
  isPreparing.value = true
210
218
  prepareError.value = null
211
219
  try {
212
- preparation.value = await $authFetch<RetirePreparation>(
213
- `${RETIRE_ENDPOINT}/${planId.value}/prepare/${targetPlanId.value}`,
214
- )
220
+ preparation.value = await preparationRead.read()
215
221
  } catch (error) {
216
222
  preparation.value = null
217
223
  prepareError.value = processApiMessage(readError(error))
@@ -1,5 +1,5 @@
1
1
  <script setup lang="ts">
2
- import { computed, onMounted } from 'vue'
2
+ import { computed } from 'vue'
3
3
  import {
4
4
  BILLING_PATH,
5
5
  INVITES_PATH,
@@ -14,7 +14,7 @@ const ERROR_AT_PERCENT = 100
14
14
  /** Where the seats stand against the plan's cap. */
15
15
  type SeatState = 'unlimited' | 'room' | 'full' | 'over'
16
16
 
17
- const { data: quota, error, refresh } = useSeatQuota()
17
+ const { data: quota, status, refresh } = useSeatQuota()
18
18
  const { t } = useI18n()
19
19
 
20
20
  const seatState = computed<SeatState>(() => {
@@ -99,11 +99,6 @@ const overDescription = computed(() => {
99
99
  excess: t(`${KEYS}.seats_count`, excess),
100
100
  })
101
101
  })
102
-
103
- // Refetch rather than serve the shared cache: adding a member or an invite
104
- // lands back on this page, and a stale count would contradict the table right
105
- // under the block.
106
- onMounted(refresh)
107
102
  </script>
108
103
 
109
104
  <template>
@@ -112,15 +107,19 @@ onMounted(refresh)
112
107
  :description="$t(`${KEYS}.description`)"
113
108
  >
114
109
  <div class="p-4.5 flex flex-col gap-4">
115
- <div v-if="!quota && !error" class="grid gap-1.5" aria-busy="true">
110
+ <div
111
+ v-if="!quota && status !== 'error'"
112
+ class="grid gap-1.5"
113
+ aria-busy="true"
114
+ >
116
115
  <USkeleton class="h-4 w-1/3" />
117
116
  <USkeleton class="h-1.5 w-full rounded-full" />
118
117
  <USkeleton class="h-3 w-40" />
119
118
  </div>
120
119
  <DmsSaasLoadFailure
121
- v-else-if="error && !quota"
120
+ v-else-if="status === 'error' && !quota"
122
121
  :title="$t(`${KEYS}.load_failed`)"
123
- @retry="refresh"
122
+ @retry="refresh()"
124
123
  />
125
124
  <template v-else-if="quota">
126
125
  <DmsMeter
@@ -52,7 +52,6 @@ watch(
52
52
 
53
53
  onMounted(() => {
54
54
  draft.conditions.value = state.value
55
- void catalog.load()
56
55
  })
57
56
 
58
57
  onBeforeUnmount(() => {
@@ -1,5 +1,5 @@
1
1
  <script setup lang="ts">
2
- import { computed, onMounted } from 'vue'
2
+ import { computed } from 'vue'
3
3
  import { hasSegmentConditions, parseSegmentGroup } from '../build/segments/tree'
4
4
  import { useSegmentCatalog } from '../build/segments/useSegmentCatalog'
5
5
  import {
@@ -22,8 +22,6 @@ const words = useSegmentWords(catalog)
22
22
 
23
23
  const group = computed(() => parseSegmentGroup(props.conditions))
24
24
  const parts = computed(() => words.groupParts(group.value, 'user', props.mode))
25
-
26
- onMounted(() => void catalog.load())
27
25
  </script>
28
26
 
29
27
  <template>
@@ -1,5 +1,5 @@
1
1
  <script setup lang="ts">
2
- import { computed, onMounted, ref } from 'vue'
2
+ import { computed, ref, watch } from 'vue'
3
3
 
4
4
  const KEY_PREFIX = 'saas.tenant_billing.billing_info'
5
5
  const DAY_FORMAT: Intl.DateTimeFormatOptions = {
@@ -22,7 +22,8 @@ const toast = useToast()
22
22
  const { t, locale } = useI18n()
23
23
  const { resolveApiError } = useApiErrorMessage()
24
24
  const identity = useBillingIdentity()
25
- const { data: billingStatus, load: loadBillingStatus } = useBillingStatus()
25
+ const info = useBillingInfo()
26
+ const { data: billingStatus } = useBillingStatus()
26
27
 
27
28
  /** Saving is owner-only server-side; a member gets the form read-only
28
29
  * instead of a save button that can only end in a 403 toast. */
@@ -39,8 +40,8 @@ const hasTriedSubmit = ref(false)
39
40
  const invalidFields = computed<BillingIdentityField[]>(() =>
40
41
  hasTriedSubmit.value ? findMissingBillingFields(draft.value) : [],
41
42
  )
42
- const isLoading = ref(true)
43
- const loadFailed = ref(false)
43
+ const isLoading = computed(() => info.pending.value && !info.data.value)
44
+ const loadFailed = computed(() => !!info.error.value && !info.data.value)
44
45
  const isSaving = ref(false)
45
46
 
46
47
  /** The badge reflects what is stored, not what is being typed. */
@@ -64,16 +65,8 @@ function apply(info: BillingInfoResponse): void {
64
65
  hasTriedSubmit.value = false
65
66
  }
66
67
 
67
- async function load(): Promise<void> {
68
- isLoading.value = true
69
- loadFailed.value = false
70
- try {
71
- apply(await identity.load())
72
- } catch {
73
- loadFailed.value = true
74
- } finally {
75
- isLoading.value = false
76
- }
68
+ function load(): Promise<void> {
69
+ return info.refresh()
77
70
  }
78
71
 
79
72
  function discard(): void {
@@ -93,7 +86,7 @@ async function save(): Promise<void> {
93
86
  }
94
87
  isSaving.value = true
95
88
  try {
96
- apply(await identity.save(draft.value))
89
+ info.data.value = await identity.save(draft.value)
97
90
  toast.add({
98
91
  title: t(`${KEY_PREFIX}.saved`),
99
92
  color: 'success',
@@ -110,10 +103,12 @@ async function save(): Promise<void> {
110
103
  }
111
104
  }
112
105
 
113
- onMounted(() => {
114
- void loadBillingStatus()
115
- return load()
116
- })
106
+ // The fields are copies of the stored identity, edited in place: copied once
107
+ // it is read (awaited, so the server renders them filled in), then each time
108
+ // it is read or saved again.
109
+ watch(info.data, (stored) => stored && apply(stored))
110
+ await info
111
+ if (info.data.value) apply(info.data.value)
117
112
  </script>
118
113
 
119
114
  <template>
@@ -24,6 +24,7 @@ const { confirm } = useConfirm()
24
24
  const { resolveApiError } = useApiErrorMessage()
25
25
  const tenantPlan = useTenantPlan()
26
26
  const { data, error: loadError } = tenantPlan
27
+ const planChanges = useTenantPlanChanges()
27
28
  const billingStatus = useBillingStatus()
28
29
  const nextInvoice = useNextInvoice()
29
30
  const { formatMajorUnits, formatMinorUnits } = useMoneyFormat()
@@ -35,11 +36,13 @@ const { consumeCancelledCheckout } = usePendingCheckout()
35
36
  const { workspace, load: loadWorkspace } = useCurrentWorkspace()
36
37
  const planIntervalLabel = usePlanIntervalLabel('saas.workspace.plan.interval')
37
38
  const workspaceName = useWorkspaceName()
38
- const myWorkspaces = useMyWorkspaces()
39
39
  const route = useDmsRoute()
40
40
  const router = useDmsRouter()
41
41
 
42
- const isLoading = ref(true)
42
+ // The card waits for both reads before it offers an action.
43
+ const isLoading = computed(
44
+ () => tenantPlan.pending.value || billingStatus.pending.value,
45
+ )
43
46
  const isWorking = ref(false)
44
47
  const isUpgradeOpen = ref(false)
45
48
  const upgradeTarget = ref<OfferedPlanView | null>(null)
@@ -249,15 +252,10 @@ function openUpgrade(plan: OfferedPlanView): void {
249
252
  isUpgradeOpen.value = true
250
253
  }
251
254
 
252
- // The page's stock blocks (the complimentary banner, the next invoice) and
253
- // the sidebar switcher, which names the plan, read it too: they read their
254
- // routes again once it changed.
255
- async function refresh(): Promise<void> {
256
- isLoading.value = true
257
- void nextInvoice.refresh()
258
- void myWorkspaces.refresh().catch(() => undefined)
259
- await Promise.all([tenantPlan.refresh(), billingStatus.refresh()])
260
- isLoading.value = false
255
+ // The page's refresh reads the plan again, with what shows it elsewhere: the
256
+ // page's stock blocks (the complimentary banner, the next invoice) and the
257
+ // sidebar switcher, which names the plan.
258
+ function refresh(): void {
261
259
  refreshPageBlocks()
262
260
  }
263
261
 
@@ -273,7 +271,7 @@ async function runAction(
273
271
  color: 'success',
274
272
  icon: 'i-ph-check-circle',
275
273
  })
276
- await refresh()
274
+ refresh()
277
275
  } catch (error) {
278
276
  toast.add({
279
277
  title: resolveApiError(error, 'saas.workspace.plan.change_error'),
@@ -287,14 +285,14 @@ async function runAction(
287
285
 
288
286
  function cancelDowngrade(): Promise<void> {
289
287
  return runAction(
290
- tenantPlan.cancelPendingChange,
288
+ planChanges.cancelPendingChange,
291
289
  `${KEY_PREFIX}.downgrade_cancelled`,
292
290
  )
293
291
  }
294
292
 
295
293
  function keepSubscription(): Promise<void> {
296
294
  return runAction(
297
- tenantPlan.keepSubscription,
295
+ planChanges.keepSubscription,
298
296
  `${KEY_PREFIX}.subscription_kept`,
299
297
  )
300
298
  }
@@ -335,7 +333,7 @@ async function cancelSubscription(): Promise<void> {
335
333
  body: () => t(`${KEY_PREFIX}.cancel_note`),
336
334
  onConfirm: async () => {
337
335
  try {
338
- await tenantPlan.cancelSubscription()
336
+ await planChanges.cancelSubscription()
339
337
  } catch (error) {
340
338
  throw new Error(
341
339
  resolveApiError(error, 'saas.workspace.plan.change_error'),
@@ -346,17 +344,18 @@ async function cancelSubscription(): Promise<void> {
346
344
  color: 'success',
347
345
  icon: 'i-ph-check-circle',
348
346
  })
349
- await refresh()
347
+ refresh()
350
348
  },
351
349
  })
352
350
  }
353
351
 
354
- /** Back from Stripe's cancel link: the checkout left behind is released
355
- * before the card loads, so the plan buttons work straight away. */
352
+ /** Back from Stripe's cancel link: the checkout left behind is released, and
353
+ * the card read again, so the plan buttons work straight away. */
356
354
  async function releaseCancelledCheckout(): Promise<void> {
357
355
  try {
358
356
  const { released } = await consumeCancelledCheckout()
359
357
  if (!released) return
358
+ refresh()
360
359
  toast.add({
361
360
  title: t('saas.workspace.plan.checkout_pending.cancelled'),
362
361
  color: 'info',
@@ -421,9 +420,7 @@ async function consumeChoosePlanParam(): Promise<void> {
421
420
 
422
421
  onMounted(async () => {
423
422
  await releaseCancelledCheckout()
424
- void nextInvoice.load()
425
- await Promise.all([tenantPlan.load(), billingStatus.load()])
426
- isLoading.value = false
423
+ await Promise.all([tenantPlan, billingStatus])
427
424
  await consumeUpgradeParam()
428
425
  await consumeChoosePlanParam()
429
426
  })
@@ -439,7 +436,7 @@ watch(
439
436
  </script>
440
437
 
441
438
  <template>
442
- <DmsCard :title="$t(`${KEY_PREFIX}.title`)">
439
+ <DmsCard class="grow" :title="$t(`${KEY_PREFIX}.title`)">
443
440
  <template v-if="canChangePlan && current" #actions>
444
441
  <UButton
445
442
  v-if="canResubscribe"
@@ -1,5 +1,5 @@
1
1
  <script setup lang="ts">
2
- import { computed, onMounted } from 'vue'
2
+ import { computed } from 'vue'
3
3
 
4
4
  // Content of the trial-ending layout strip (see registerTrialEndingBanners),
5
5
  // shown to the workspace owner 7, 3 and 1 day before the trial ends.
@@ -10,12 +10,12 @@ const DAY_FORMAT: Intl.DateTimeFormatOptions = {
10
10
  month: 'short',
11
11
  }
12
12
 
13
- const { data: plan, load: loadPlan } = useTenantPlan()
14
- const { data: billingStatus, load: loadBillingStatus } = useBillingStatus()
13
+ const { data: plan } = useTenantPlan()
14
+ const billingStatus = useMountedData(useBillingStatus({ server: false }).data)
15
15
  const { formatMinorUnits } = useMoneyFormat()
16
16
  const { t, locale } = useI18n()
17
17
  const planIntervalLabel = usePlanIntervalLabel('saas.workspace.plan.interval')
18
- const { data: nextInvoice, load: loadNextInvoice } = useNextInvoice()
18
+ const nextInvoice = useMountedData(useNextInvoice({ server: false }).data)
19
19
 
20
20
  const trialEndsAt = computed(() => plan.value?.currentPeriodEnd ?? null)
21
21
  const daysLeft = computed(() =>
@@ -50,12 +50,6 @@ const charge = computed(() => {
50
50
  })
51
51
  : t(`${KEY_PREFIX}.charge`, params)
52
52
  })
53
-
54
- onMounted(() => {
55
- void loadPlan()
56
- void loadBillingStatus()
57
- void loadNextInvoice()
58
- })
59
53
  </script>
60
54
 
61
55
  <template>
@@ -69,6 +63,7 @@ onMounted(() => {
69
63
  </UButton>
70
64
  <DmsSaasCustomerPortalButton
71
65
  label-key="saas.tenant_billing.past_due.update_card"
66
+ is-deferred
72
67
  icon="i-ph-credit-card"
73
68
  size="xs"
74
69
  />
@@ -1,5 +1,5 @@
1
1
  <script setup lang="ts">
2
- import { computed, onMounted, ref } from 'vue'
2
+ import { computed, ref } from 'vue'
3
3
  import { useUserDetail } from '../build/users/useUserDetail'
4
4
 
5
5
  const props = defineProps<{ routeParams?: Record<string, string> }>()
@@ -11,7 +11,7 @@ type RoleChange = 'promote' | 'demote'
11
11
 
12
12
  const { t } = useI18n()
13
13
  const { $authFetch } = useAuthFetch()
14
- const { confirmFrom } = useServerConfirm()
14
+ const { confirmFrom } = useConfirmFrom()
15
15
  const toast = useToast()
16
16
  const { resolveApiError } = useApiErrorMessage()
17
17
  const detail = useUserDetail(() => props.routeParams)
@@ -25,16 +25,17 @@ const change = computed<RoleChange>(() =>
25
25
  async function runChange(kind: RoleChange): Promise<void> {
26
26
  await $authFetch(`${API}/${detail.userId.value}/${kind}`, { method: 'POST' })
27
27
  toast.add({ color: 'success', title: t(`${I18N}.${kind}d`) })
28
- await detail.refresh()
28
+ // The dialog closes once the card shows the new role.
29
+ await refreshPageBlocks()
29
30
  }
30
31
 
31
32
  async function openConfirm(): Promise<void> {
32
33
  const kind = change.value
33
34
  isOpening.value = true
34
35
  try {
35
- await confirmFrom(`${API}/${detail.userId.value}/${kind}-confirm`, () =>
36
- runChange(kind),
37
- )
36
+ await confirmFrom(`${API}/${detail.userId.value}/${kind}-confirm`, {
37
+ onConfirm: () => runChange(kind),
38
+ })
38
39
  } catch (error) {
39
40
  toast.add({
40
41
  color: 'error',
@@ -44,14 +45,12 @@ async function openConfirm(): Promise<void> {
44
45
  isOpening.value = false
45
46
  }
46
47
  }
47
-
48
- onMounted(() => void detail.load())
49
48
  </script>
50
49
 
51
50
  <template>
52
51
  <DmsCard :title="$t(`${I18N}.title`)">
53
52
  <DmsSaasLoadFailure
54
- v-if="detail.error.value && !user"
53
+ v-if="detail.status.value === 'error' && !user"
55
54
  @retry="detail.refresh()"
56
55
  />
57
56
  <div v-else-if="!user" class="flex flex-col gap-2">