@antelopejs/dms-saas 0.5.1 → 0.6.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.
Files changed (86) hide show
  1. package/README.md +61 -1003
  2. package/dist/billing-state/recovery.js +2 -2
  3. package/dist/billing-state/recovery.js.map +1 -1
  4. package/dist/operator-actions/db/lifecycle-delivery.model.d.ts +1 -0
  5. package/dist/operator-actions/db/operator-action.model.d.ts +1 -0
  6. package/dist/pages/tenant/general.js +1 -0
  7. package/dist/pages/tenant/general.js.map +1 -1
  8. package/dist/stripe/client.d.ts +3 -0
  9. package/dist/stripe/client.js +16 -1
  10. package/dist/stripe/client.js.map +1 -1
  11. package/dist/stripe/customer-billing.js +1 -1
  12. package/dist/stripe/customer-billing.js.map +1 -1
  13. package/dist/stripe/subscription-cancellation.js +1 -1
  14. package/dist/stripe/subscription-cancellation.js.map +1 -1
  15. package/dist/stripe/upcoming-invoice.js +3 -3
  16. package/dist/stripe/upcoming-invoice.js.map +1 -1
  17. package/dist/types/config.d.ts +2 -0
  18. package/dist/types/config.js.map +1 -1
  19. package/dist/upcoming-invoice/db/preview-cache.model.d.ts +1 -0
  20. package/dist/workspaces/db/provisioning-attempt.model.d.ts +1 -0
  21. package/dist/workspaces/db/trial-identity.model.d.ts +1 -0
  22. package/frontend-vue/app/build/PayInvoicePanel.vue +4 -8
  23. package/frontend-vue/app/build/PlanChangeReview.vue +3 -6
  24. package/frontend-vue/app/build/segments/useSegmentCatalog.ts +7 -12
  25. package/frontend-vue/app/build/useWorkspaceName.ts +1 -2
  26. package/frontend-vue/app/build/users/useUserDetail.ts +8 -10
  27. package/frontend-vue/app/build/workspace-detail/ComplimentaryDialog.vue +5 -3
  28. package/frontend-vue/app/build/workspace-detail/CreditDialog.vue +5 -3
  29. package/frontend-vue/app/build/workspace-detail/UpgradeDialog.vue +14 -7
  30. package/frontend-vue/app/build/workspace-detail/useWorkspaceActions.ts +11 -10
  31. package/frontend-vue/app/build/workspace-detail/useWorkspaceOverview.ts +16 -30
  32. package/frontend-vue/app/components/CustomerPortalButton.vue +6 -4
  33. package/frontend-vue/app/components/DataExport.vue +34 -54
  34. package/frontend-vue/app/components/DataExportHistory.vue +2 -7
  35. package/frontend-vue/app/components/IssueCreditNoteModal.vue +5 -4
  36. package/frontend-vue/app/components/MigrationStripeCheck.vue +11 -8
  37. package/frontend-vue/app/components/PastDueAlert.vue +8 -6
  38. package/frontend-vue/app/components/PastDueBanner.vue +4 -4
  39. package/frontend-vue/app/components/PaymentMethodCard.vue +6 -11
  40. package/frontend-vue/app/components/PlanAccessEditor.vue +31 -30
  41. package/frontend-vue/app/components/PlanCard.vue +2 -3
  42. package/frontend-vue/app/components/PlanEditorPreview.vue +27 -36
  43. package/frontend-vue/app/components/PlanUpgradeModal.vue +1 -1
  44. package/frontend-vue/app/components/PlatformNotes.vue +27 -28
  45. package/frontend-vue/app/components/Pricing.vue +16 -23
  46. package/frontend-vue/app/components/RefundButton.vue +61 -46
  47. package/frontend-vue/app/components/RetirePlanModal.vue +13 -7
  48. package/frontend-vue/app/components/SeatQuotaBanner.vue +9 -10
  49. package/frontend-vue/app/components/SegmentConditionsBuilder.vue +0 -1
  50. package/frontend-vue/app/components/SegmentRulesText.vue +1 -3
  51. package/frontend-vue/app/components/TenantBillingForm.vue +14 -19
  52. package/frontend-vue/app/components/TenantPlanCard.vue +18 -21
  53. package/frontend-vue/app/components/TrialEndingBanner.vue +5 -10
  54. package/frontend-vue/app/components/UserPlatformRoleCard.vue +8 -9
  55. package/frontend-vue/app/components/UserSegmentMatches.vue +8 -16
  56. package/frontend-vue/app/components/UserSummaryCard.vue +2 -4
  57. package/frontend-vue/app/components/WorkspaceAdminCreateModal.vue +13 -5
  58. package/frontend-vue/app/components/WorkspaceCreateModal.vue +5 -1
  59. package/frontend-vue/app/components/WorkspaceDangerZone.vue +10 -9
  60. package/frontend-vue/app/components/WorkspaceDetailHeader.vue +14 -4
  61. package/frontend-vue/app/components/WorkspaceSuspended.vue +27 -32
  62. package/frontend-vue/app/components/WorkspaceSwitcherWidget.vue +5 -18
  63. package/frontend-vue/app/composables/useBillingIdentity.ts +9 -5
  64. package/frontend-vue/app/composables/useBillingStatus.ts +8 -7
  65. package/frontend-vue/app/composables/useCurrentWorkspace.ts +6 -8
  66. package/frontend-vue/app/composables/useExportHistory.ts +67 -78
  67. package/frontend-vue/app/composables/useMountedData.ts +27 -0
  68. package/frontend-vue/app/composables/useMyWorkspaces.ts +26 -28
  69. package/frontend-vue/app/composables/useNextInvoice.ts +7 -6
  70. package/frontend-vue/app/composables/useOnDemandRead.ts +49 -0
  71. package/frontend-vue/app/composables/usePendingCheckout.ts +2 -1
  72. package/frontend-vue/app/composables/usePlanCatalog.ts +3 -9
  73. package/frontend-vue/app/composables/usePublicPricing.ts +24 -0
  74. package/frontend-vue/app/composables/useSaasRegistration.ts +2 -0
  75. package/frontend-vue/app/composables/useSeatQuota.ts +2 -6
  76. package/frontend-vue/app/composables/useTenantPlan.ts +26 -9
  77. package/frontend-vue/app/composables/useWorkspaceOverview.ts +2 -6
  78. package/frontend-vue/app/custom-pages/auth/no-workspace.vue +3 -1
  79. package/frontend-vue/dms.server.ts +22 -0
  80. package/frontend-vue/package.json +1 -1
  81. package/package.json +36 -18
  82. package/skills/dms-saas/SKILL.md +56 -0
  83. package/frontend-vue/app/composables/useServerConfirm.ts +0 -44
  84. package/frontend-vue/app/composables/useSharedRequest.ts +0 -54
  85. package/frontend-vue/app/composables/useWorkspaceAccessCache.ts +0 -52
  86. package/frontend-vue/app/composables/useWorkspaceRenamed.ts +0 -33
@@ -1,44 +1,30 @@
1
- import { onBeforeUnmount, onMounted, ref, type Ref } from 'vue'
1
+ import { computed, type ComputedRef, type Ref } from 'vue'
2
2
  import type { WorkspaceOverview } from './types'
3
3
 
4
4
  /** The workspace an operator looks at, refreshed after each action on it. */
5
5
  export interface WorkspaceOverviewState {
6
6
  overview: Ref<WorkspaceOverview | null>
7
- isLoading: Ref<boolean>
8
- hasError: Ref<boolean>
7
+ isLoading: ComputedRef<boolean>
8
+ hasError: ComputedRef<boolean>
9
9
  load: () => Promise<void>
10
10
  }
11
11
 
12
12
  /**
13
13
  * Reads the header of a workspace's detail page, again each time the page
14
- * refreshes its blocks after an operator action.
14
+ * refreshes its blocks after an operator action (as every `useApiData` read
15
+ * of the page does). The header, the operator card and the suspend button
16
+ * share one read.
15
17
  */
16
18
  export function useWorkspaceOverview(tenantId: string): WorkspaceOverviewState {
17
- const { $authFetch } = useAuthFetch()
18
- const overview = ref<WorkspaceOverview | null>(null)
19
- const isLoading = ref(true)
20
- const hasError = ref(false)
21
-
22
- async function load(): Promise<void> {
23
- if (!tenantId) return
24
- isLoading.value = true
25
- try {
26
- overview.value = await $authFetch<WorkspaceOverview>(
27
- `/api/saas/workspaces/${tenantId}/overview`,
28
- )
29
- hasError.value = false
30
- } catch {
31
- hasError.value = true
32
- } finally {
33
- isLoading.value = false
34
- }
19
+ const { data, status, refresh } = useApiData<WorkspaceOverview>(
20
+ tenantId ? `/api/saas/workspaces/${tenantId}/overview` : null,
21
+ )
22
+ return {
23
+ overview: data,
24
+ isLoading: computed(
25
+ () => status.value === 'pending' || status.value === 'idle',
26
+ ),
27
+ hasError: computed(() => status.value === 'error'),
28
+ load: () => refresh(),
35
29
  }
36
-
37
- let stopRefresh: (() => void) | undefined
38
- onMounted(() => {
39
- void load()
40
- stopRefresh = onPageBlocksRefresh(() => void load())
41
- })
42
- onBeforeUnmount(() => stopRefresh?.())
43
- return { overview, isLoading, hasError, load }
44
30
  }
@@ -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 type { ButtonProps } from '@nuxt/ui'
4
4
 
5
5
  const props = withDefaults(
@@ -10,6 +10,8 @@ const props = withDefaults(
10
10
  variant?: ButtonProps['variant']
11
11
  size?: ButtonProps['size']
12
12
  icon?: string
13
+ /** Read the billing status in the browser, as a layout strip does. */
14
+ isDeferred?: boolean
13
15
  }>(),
14
16
  {
15
17
  labelKey: 'saas.tenant_billing.portal.open',
@@ -17,6 +19,7 @@ const props = withDefaults(
17
19
  variant: 'subtle',
18
20
  size: 'md',
19
21
  icon: 'i-ph-arrow-square-out',
22
+ isDeferred: false,
20
23
  },
21
24
  )
22
25
 
@@ -28,7 +31,8 @@ interface PortalSession {
28
31
 
29
32
  const { $authFetch } = useAuthFetch()
30
33
  const { resolveApiError } = useApiErrorMessage()
31
- const { data, load } = useBillingStatus()
34
+ const billingStatus = useBillingStatus({ server: !props.isDeferred }).data
35
+ const data = props.isDeferred ? useMountedData(billingStatus) : billingStatus
32
36
  const isLoading = ref(false)
33
37
  const failure = ref<string | null>(null)
34
38
 
@@ -52,8 +56,6 @@ async function openCustomerPortal(): Promise<void> {
52
56
  isLoading.value = false
53
57
  }
54
58
  }
55
-
56
- onMounted(load)
57
59
  </script>
58
60
 
59
61
  <template>
@@ -1,5 +1,5 @@
1
1
  <script setup lang="ts">
2
- import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
2
+ import { computed, onMounted, ref, watch } from 'vue'
3
3
  import { SENTENCE_DAY_FORMAT } from '../build/day-formats'
4
4
 
5
5
  /** Query parameter a delivered export link carries, set by the DMS. */
@@ -20,19 +20,34 @@ const { resolveApiError } = useApiErrorMessage()
20
20
  const route = useDmsRoute()
21
21
  const router = useDmsRouter()
22
22
  const toast = useToast()
23
- const { state, running, load, refresh, start, readStatus, download } =
24
- useExportHistory()
23
+ const { state, running, load, start, download } = useExportHistory()
25
24
 
26
25
  /** The export this visit watched finish, shown until the page is left. */
27
26
  const finished = ref<ExportHistoryEntry | null>(null)
28
27
  /** The e-mailed link this visit came from, once the server said it is gone. */
29
28
  const expiredLinkJobId = ref<string | null>(null)
30
29
  const isDownloading = ref(false)
31
- let pollTimer: ReturnType<typeof setInterval> | null = null
30
+ // The export being built is read again every interval, in the browser, until
31
+ // it is done; a tick waits for a slow answer instead of piling up requests.
32
+ const runningStatus = useApiData<ExportJobStatus>(
33
+ () =>
34
+ running.value
35
+ ? `${EXPORT_STATUS_ENDPOINT}/${encodeURIComponent(running.value.jobId)}`
36
+ : null,
37
+ { server: false, refreshInterval: POLL_INTERVAL_MS, refreshOnPageRefresh: false },
38
+ )
32
39
 
33
40
  const email = computed(() => user.value?.email ?? '')
34
41
  const progress = computed(() =>
35
- Math.min(FULL_PROGRESS, Math.round(running.value?.progress ?? 0)),
42
+ Math.min(
43
+ FULL_PROGRESS,
44
+ Math.round(
45
+ (runningStatus.placeholder.value ? null : runningStatus.data.value)
46
+ ?.progress ??
47
+ running.value?.progress ??
48
+ 0,
49
+ ),
50
+ ),
36
51
  )
37
52
  const isFinishedPartial = computed(() => !!finished.value?.result?.partial)
38
53
 
@@ -79,48 +94,17 @@ async function downloadFinished(): Promise<void> {
79
94
  })
80
95
  }
81
96
 
82
- // A tick is skipped while the previous read is still out: a slow status
83
- // route would otherwise pile up requests every interval, until the browser's
84
- // few connections per host are all held and the rest of the app stalls.
85
- let isReadingStatus = false
86
-
87
- async function readRunningStatus(
88
- jobId: string,
89
- ): Promise<ExportJobStatus | null> {
90
- if (isReadingStatus) return null
91
- isReadingStatus = true
92
- try {
93
- return await readStatus(jobId).catch(() => null)
94
- } finally {
95
- isReadingStatus = false
96
- }
97
- }
98
-
99
- async function pollRunning(): Promise<void> {
100
- const entry = running.value
101
- if (!entry) return
102
- const status = await readRunningStatus(entry.jobId)
103
- if (!status) return
104
- if (status.status === EXPORT_STATUS.pending) {
105
- entry.progress = status.progress
106
- return
107
- }
108
- finished.value = { ...entry, ...status }
109
- await load()
110
- }
111
-
112
- function stopPolling(): void {
113
- if (pollTimer) clearInterval(pollTimer)
114
- pollTimer = null
115
- }
116
-
117
- /** One timer at most, following the export being built, if any. */
118
- function syncPolling(): void {
119
- stopPolling()
120
- if (running.value) pollTimer = setInterval(pollRunning, POLL_INTERVAL_MS)
121
- }
122
-
123
- watch(() => running.value?.jobId, syncPolling)
97
+ watch(
98
+ () => runningStatus.data.value,
99
+ async (status) => {
100
+ const entry = running.value
101
+ if (!status || !entry || runningStatus.placeholder.value) return
102
+ if (status.status === EXPORT_STATUS.pending) return
103
+ if (finished.value?.jobId === entry.jobId) return
104
+ finished.value = { ...entry, ...status }
105
+ await load()
106
+ },
107
+ )
124
108
 
125
109
  async function clearDeliveredLink(): Promise<void> {
126
110
  const { [EXPORT_JOB_QUERY_PARAM]: _consumed, ...query } = route.query
@@ -149,13 +133,9 @@ async function consumeDeliveredLink(): Promise<void> {
149
133
  }
150
134
  }
151
135
 
152
- onMounted(async () => {
153
- await refresh()
154
- syncPolling()
155
- await consumeDeliveredLink()
156
- })
157
-
158
- onBeforeUnmount(stopPolling)
136
+ // The history is read with the page, on the server too: the browser polls
137
+ // the export it shows running, and downloads the archive a link names.
138
+ onMounted(consumeDeliveredLink)
159
139
  </script>
160
140
 
161
141
  <template>
@@ -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
 
4
4
  const KEYS = 'saas.workspace.data_export.history'
5
5
  const SKELETON_ROWS = 3
@@ -30,8 +30,7 @@ const ROW_TONES: Record<ExportRowState, Tone> = {
30
30
  const { t, locale } = useI18n()
31
31
  const { resolveApiError } = useApiErrorMessage()
32
32
  const toast = useToast()
33
- const { state, running, load, refresh, goToPage, start, download } =
34
- useExportHistory()
33
+ const { state, running, load, goToPage, start, download } = useExportHistory()
35
34
 
36
35
  const downloadingJobId = ref<string | null>(null)
37
36
 
@@ -106,10 +105,6 @@ function requestAnother(): Promise<void> {
106
105
  notifyError(error, 'saas.workspace.data_export.error.start'),
107
106
  )
108
107
  }
109
-
110
- onMounted(() => {
111
- void refresh()
112
- })
113
108
  </script>
114
109
 
115
110
  <template>
@@ -50,14 +50,15 @@ const texts = useCreditNoteTexts({
50
50
  creditedAfter: draft.creditedAfter,
51
51
  })
52
52
 
53
+ const previewRead = useOnDemandRead<CreditNotePreview>(
54
+ () => `${PREVIEW_ENDPOINT}/${encodeURIComponent(props.rowData?._id ?? '')}`,
55
+ )
56
+
53
57
  async function load(): Promise<void> {
54
- const invoiceId = props.rowData?._id
55
58
  isLoading.value = true
56
59
  loadError.value = null
57
60
  try {
58
- preview.value = await $authFetch<CreditNotePreview>(
59
- `${PREVIEW_ENDPOINT}/${encodeURIComponent(invoiceId ?? '')}`,
60
- )
61
+ preview.value = await previewRead.read()
61
62
  draft.reset(preview.value)
62
63
  } catch (error) {
63
64
  loadError.value = resolveApiError(error, `${TEXT}.load_failed`)
@@ -34,7 +34,7 @@ const props = defineProps<{ rowData?: MigrationWorkspaceRow }>()
34
34
  const KeyValueListBlock = resolveDmsComponent('dms-key-value-list-block')
35
35
  const { $authFetch } = useAuthFetch()
36
36
  const { t } = useI18n()
37
- const { confirmFrom } = useServerConfirm()
37
+ const { confirmFrom } = useConfirmFrom()
38
38
  const toast = useToast()
39
39
  const { resolveApiError } = useApiErrorMessage()
40
40
 
@@ -52,13 +52,15 @@ const resolution = computed(() =>
52
52
  isSettled.value ? null : (reading.value?.resolution ?? null),
53
53
  )
54
54
 
55
+ const stripeRead = useOnDemandRead<StripeReading>(() =>
56
+ workspaceApi.value ? `${workspaceApi.value}/stripe` : null,
57
+ )
58
+
55
59
  async function load(): Promise<void> {
56
60
  if (!workspaceApi.value) return
57
61
  loadFailed.value = false
58
62
  try {
59
- reading.value = await $authFetch<StripeReading>(
60
- `${workspaceApi.value}/stripe`,
61
- )
63
+ reading.value = await stripeRead.read()
62
64
  } catch {
63
65
  loadFailed.value = true
64
66
  }
@@ -71,14 +73,15 @@ async function settle(kind: UncertainResolution): Promise<void> {
71
73
  })
72
74
  isSettled.value = true
73
75
  toast.add({ color: 'success', title: t(`${DETAIL}.${kind}_done`) })
74
- refreshPageBlocks()
76
+ // The dialog closes once the page shows the settlement.
77
+ await refreshPageBlocks()
75
78
  }
76
79
 
77
80
  async function openSettlement(kind: UncertainResolution): Promise<void> {
78
81
  try {
79
- await confirmFrom(`${workspaceApi.value}/dialogs/${kind}`, () =>
80
- settle(kind),
81
- )
82
+ await confirmFrom(`${workspaceApi.value}/dialogs/${kind}`, {
83
+ onConfirm: () => settle(kind),
84
+ })
82
85
  } catch (error) {
83
86
  toast.add({
84
87
  color: 'error',
@@ -1,8 +1,12 @@
1
1
  <script setup lang="ts">
2
- import { computed, onMounted } from 'vue'
2
+ import { computed } from 'vue'
3
3
  import PayInvoiceDialog from '../build/PayInvoiceDialog.vue'
4
4
  import { LABEL_DAY_FORMAT, SENTENCE_DAY_FORMAT } from '../build/day-formats'
5
5
 
6
+ // Drawn as two roots (the alert, then the payment dialog): the page's block
7
+ // attributes have no single element to land on.
8
+ defineOptions({ inheritAttrs: false })
9
+
6
10
  interface TimelineStep {
7
11
  key: string
8
12
  date: string
@@ -14,7 +18,7 @@ const SUSPENDED_STATUS = 'suspended'
14
18
  const UNPAID_STATUSES = new Set(['past_due', SUSPENDED_STATUS])
15
19
  const KEY_PREFIX = 'saas.tenant_billing.past_due'
16
20
 
17
- const { data, error, load, refresh } = useBillingStatus()
21
+ const { data, status: readStatus, refresh } = useBillingStatus()
18
22
  const { formatMinorUnits } = useMoneyFormat()
19
23
  const { open: openPayment } = usePayInvoice()
20
24
  const { t, locale } = useI18n()
@@ -126,15 +130,13 @@ const DOT_CLASSES: Record<TimelineStep['tone'], string> = {
126
130
  function payInvoice(): void {
127
131
  if (invoice.value) openPayment(invoice.value)
128
132
  }
129
-
130
- onMounted(load)
131
133
  </script>
132
134
 
133
135
  <template>
134
136
  <DmsSaasLoadFailure
135
- v-if="error && !data"
137
+ v-if="readStatus === 'error' && !data"
136
138
  :title="$t(`${KEY_PREFIX}.load_failed`)"
137
- @retry="refresh"
139
+ @retry="refresh()"
138
140
  />
139
141
 
140
142
  <DmsBanner
@@ -1,5 +1,5 @@
1
1
  <script setup lang="ts">
2
- import { computed, onMounted } from 'vue'
2
+ import { computed } from 'vue'
3
3
  import PayInvoiceDialog from '../build/PayInvoiceDialog.vue'
4
4
  import { useWorkspaceName } from '../build/useWorkspaceName'
5
5
 
@@ -17,7 +17,8 @@ const DEADLINE_FORMAT: Intl.DateTimeFormatOptions = {
17
17
  month: 'long',
18
18
  }
19
19
 
20
- const { data, load } = useBillingStatus()
20
+ const { data: billingStatus } = useBillingStatus({ server: false })
21
+ const data = useMountedData(billingStatus)
21
22
  const workspaceName = useWorkspaceName()
22
23
  const { formatMinorUnits } = useMoneyFormat()
23
24
  const { open: openPayment } = usePayInvoice()
@@ -63,8 +64,6 @@ const ownerMailto = computed(() =>
63
64
  function payInvoice(): void {
64
65
  if (invoice.value) openPayment(invoice.value)
65
66
  }
66
-
67
- onMounted(load)
68
67
  </script>
69
68
 
70
69
  <template>
@@ -78,6 +77,7 @@ onMounted(load)
78
77
  <template v-if="isOwnerStrip">
79
78
  <DmsSaasCustomerPortalButton
80
79
  label-key="saas.tenant_billing.past_due.update_card"
80
+ is-deferred
81
81
  icon="i-ph-credit-card"
82
82
  variant="ghost"
83
83
  size="xs"
@@ -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
  const UNPAID_STATUSES = new Set(['past_due', 'suspended'])
5
5
  const KEY_PREFIX = 'saas.tenant_billing.payment_method'
@@ -8,8 +8,8 @@ const DAY_FORMAT: Intl.DateTimeFormatOptions = {
8
8
  month: 'short',
9
9
  }
10
10
 
11
- const { data, error, load, refresh } = useBillingStatus()
12
- const { data: plan, load: loadPlan } = useTenantPlan()
11
+ const { data, status: readStatus, refresh } = useBillingStatus()
12
+ const { data: plan } = useTenantPlan()
13
13
  const { open: openPlanComparison } = usePlanComparison()
14
14
  const { open: openPayment } = usePayInvoice()
15
15
  const { locale } = useI18n()
@@ -46,11 +46,6 @@ function payWithAnotherCard(): void {
46
46
  hostedInvoiceUrl: unpaid.hostedInvoiceUrl,
47
47
  })
48
48
  }
49
-
50
- onMounted(() => {
51
- void loadPlan()
52
- return load()
53
- })
54
49
  </script>
55
50
 
56
51
  <template>
@@ -66,15 +61,15 @@ onMounted(() => {
66
61
  />
67
62
  </template>
68
63
 
69
- <div v-if="!data && !error" class="flex flex-col gap-3">
64
+ <div v-if="!data && readStatus !== 'error'" class="flex flex-col gap-3">
70
65
  <USkeleton class="h-14 w-full" />
71
66
  <USkeleton class="h-4 w-2/3" />
72
67
  </div>
73
68
 
74
69
  <DmsSaasLoadFailure
75
- v-else-if="error && !data"
70
+ v-else-if="readStatus === 'error' && !data"
76
71
  :title="$t(`${KEY_PREFIX}.load_failed`)"
77
- @retry="refresh"
72
+ @retry="refresh()"
78
73
  />
79
74
 
80
75
  <p v-else-if="!isTenantOwner" class="text-muted text-sm">
@@ -28,21 +28,26 @@ const props = defineProps<{
28
28
 
29
29
  const emit = defineEmits<{ 'update:modelValue': [value: PlanAccess] }>()
30
30
 
31
- const { $authFetch } = useAuthFetch()
31
+ const EMPTY_CATALOG: PlanCatalog = {
32
+ plans: [],
33
+ features: [],
34
+ newPlanPermissions: [],
35
+ }
36
+
32
37
  const planCatalog = usePlanCatalog()
38
+ const permissionsTree = useApiData<PermissionNode[]>(
39
+ props.permissionsTreeUrl ?? '/api/saas/plans/permissions-tree',
40
+ )
33
41
  const route = useDmsRoute()
34
42
  const { t } = useI18n()
35
43
  const { processI18n } = useTranslation()
36
44
  const { formatFeatureValue } = usePlanFeatureFormat()
37
45
 
38
- const catalog = ref<PlanCatalog>({
39
- plans: [],
40
- features: [],
41
- newPlanPermissions: [],
42
- })
43
- const tree = ref<PermissionNode[]>([])
44
- const isLoading = ref(true)
45
- const hasError = ref(false)
46
+ const catalog = computed(() => planCatalog.data.value ?? EMPTY_CATALOG)
47
+ const tree = computed(() => permissionsTree.data.value ?? [])
48
+ const hasError = computed(() =>
49
+ [planCatalog, permissionsTree].some((read) => read.status.value === 'error'),
50
+ )
46
51
  const isPickerOpen = ref(false)
47
52
 
48
53
  // A new plan starts with no value: no parent, nothing of its own.
@@ -184,34 +189,30 @@ function isBlank(value: PlanAccess): boolean {
184
189
 
185
190
  // A new plan starts with every permission checked, as the seeded plans hold
186
191
  // them, for the operator to uncheck; a duplicate keeps the plan it copies.
192
+ // The form's value changes from the browser: until then a new plan shows the
193
+ // placeholder, on the server as in the browser's first render.
194
+ const isNewBlankPlan = !currentPlanId.value && !route.query.duplicate
195
+ const isSeeding = ref(isNewBlankPlan)
196
+ const isLoading = computed(
197
+ () =>
198
+ !hasError.value &&
199
+ (isSeeding.value || !planCatalog.data.value || !permissionsTree.data.value),
200
+ )
201
+
187
202
  function startNewPlanWithEveryPermission(): void {
188
- if (currentPlanId.value || route.query.duplicate) return
189
- if (!isBlank(access.value)) return
203
+ if (!isNewBlankPlan || !isBlank(access.value)) return
190
204
  update({ extraPermissions: catalog.value.newPlanPermissions })
191
205
  }
192
206
 
193
207
  async function load(): Promise<void> {
194
- isLoading.value = true
195
- hasError.value = false
196
- try {
197
- const [loadedCatalog, loadedTree] = await Promise.all([
198
- planCatalog.refresh(),
199
- $authFetch<PermissionNode[]>(
200
- props.permissionsTreeUrl ?? '/api/saas/plans/permissions-tree',
201
- ),
202
- ])
203
- if (!loadedCatalog) throw new Error('catalog unavailable')
204
- catalog.value = loadedCatalog
205
- tree.value = loadedTree
206
- startNewPlanWithEveryPermission()
207
- } catch {
208
- hasError.value = true
209
- } finally {
210
- isLoading.value = false
211
- }
208
+ await Promise.all([planCatalog.refresh(), permissionsTree.refresh()])
212
209
  }
213
210
 
214
- onMounted(load)
211
+ onMounted(async () => {
212
+ await Promise.all([planCatalog, permissionsTree])
213
+ if (planCatalog.data.value) startNewPlanWithEveryPermission()
214
+ isSeeding.value = false
215
+ })
215
216
  </script>
216
217
 
217
218
  <template>
@@ -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
  type CatalogFeature,
5
5
  type CatalogPlanRow,
@@ -199,7 +199,6 @@ function toggleSale(): void {
199
199
  }
200
200
 
201
201
  // Every card asks as it mounts: the cards of a page share the one request.
202
- onMounted(catalog.refresh)
203
202
  </script>
204
203
 
205
204
  <template>
@@ -321,7 +320,7 @@ onMounted(catalog.refresh)
321
320
  </div>
322
321
 
323
322
  <p
324
- v-if="catalog.error.value"
323
+ v-if="catalog.status.value === 'error'"
325
324
  class="text-muted flex items-center gap-1.5 text-xs"
326
325
  >
327
326
  <UIcon name="i-ph-warning" class="text-warning size-4" />
@@ -1,5 +1,5 @@
1
1
  <script setup lang="ts">
2
- import { computed, onMounted, type Ref, ref } from 'vue'
2
+ import { computed, type Ref } from 'vue'
3
3
  import { useLiveFormValues } from '../build/composables/useLiveFormValues'
4
4
  import {
5
5
  cardFeatures,
@@ -60,22 +60,26 @@ const props = defineProps<{
60
60
  formKey?: string
61
61
  }>()
62
62
 
63
- const { $authFetch } = useAuthFetch()
64
- const { t, locale } = useI18n()
65
- const planDescription = usePlanDescription()
66
- const { formatFeatureValue } = usePlanFeatureFormat()
67
-
68
- const saved = ref<PlanDraft | null>(null)
69
- const context = ref<EditorContext | null>(null)
70
- const catalog = ref<PlanCatalog>({
63
+ const EMPTY_CATALOG: PlanCatalog = {
71
64
  plans: [],
72
65
  features: [],
73
66
  newPlanPermissions: [],
74
- })
75
- const isLoading = ref(true)
76
- const hasError = ref(false)
67
+ }
68
+
69
+ const { t, locale } = useI18n()
70
+ const planDescription = usePlanDescription()
71
+ const { formatFeatureValue } = usePlanFeatureFormat()
77
72
 
78
73
  const planId = computed(() => props.routeParams?.id)
74
+ // A new plan has nothing saved and no Stripe context yet.
75
+ const savedPlan = useApiData<PlanDraft>(() =>
76
+ planId.value ? `${PLANS_ENDPOINT}/${planId.value}` : null,
77
+ )
78
+ const editorContext = useApiData<EditorContext>(() =>
79
+ planId.value ? `${PLANS_ENDPOINT}/${planId.value}/editor-context` : null,
80
+ )
81
+ const saved = savedPlan.data
82
+ const context = editorContext.data
79
83
  // The form declared beside the preview, in the same grid row.
80
84
  const formComponentId = computed(() =>
81
85
  props.componentId
@@ -84,6 +88,16 @@ const formComponentId = computed(() =>
84
88
  )
85
89
  const live = useLiveFormValues(() => formComponentId.value) as Ref<PlanDraft | null>
86
90
  const planCatalog = usePlanCatalog()
91
+ const catalog = computed(() => planCatalog.data.value ?? EMPTY_CATALOG)
92
+ const reads = [planCatalog, savedPlan, editorContext]
93
+ const hasError = computed(() =>
94
+ reads.some((read) => read.status.value === 'error'),
95
+ )
96
+ const isLoading = computed(
97
+ () =>
98
+ !hasError.value &&
99
+ (!planCatalog.data.value || reads.some((read) => read.pending.value)),
100
+ )
87
101
  const draft = computed<PlanDraft>(() => live.value ?? saved.value ?? {})
88
102
  const currency = computed(() => draft.value.currency ?? 'EUR')
89
103
  const price = computed(() => Number(draft.value.price ?? 0))
@@ -187,31 +201,8 @@ const isPriceChanged = computed(() => {
187
201
  const productUrl = computed(() => context.value?.stripeProductUrl ?? undefined)
188
202
 
189
203
  async function load(): Promise<void> {
190
- isLoading.value = true
191
- hasError.value = false
192
- try {
193
- const [loadedCatalog, plan, editor] = await Promise.all([
194
- planCatalog.refresh(),
195
- planId.value
196
- ? $authFetch<PlanDraft>(`${PLANS_ENDPOINT}/${planId.value}`)
197
- : null,
198
- planId.value
199
- ? $authFetch<EditorContext>(
200
- `${PLANS_ENDPOINT}/${planId.value}/editor-context`,
201
- )
202
- : null,
203
- ])
204
- if (loadedCatalog) catalog.value = loadedCatalog
205
- saved.value = plan
206
- context.value = editor
207
- } catch {
208
- hasError.value = true
209
- } finally {
210
- isLoading.value = false
211
- }
204
+ await Promise.all(reads.map((read) => read.refresh()))
212
205
  }
213
-
214
- onMounted(() => void load())
215
206
  </script>
216
207
 
217
208
  <template>
@@ -21,7 +21,7 @@ const toast = useToast()
21
21
  const { t, locale } = useI18n()
22
22
  const { resolveApiError } = useApiErrorMessage()
23
23
  const identity = useBillingIdentity()
24
- const { changePlan, previewChange } = useTenantPlan()
24
+ const { changePlan, previewChange } = useTenantPlanChanges()
25
25
  const { offerFor: offerPendingCheckout } = usePendingCheckout()
26
26
  const { formatMajorUnits, formatMinorUnits } = useMoneyFormat()
27
27
  const planIntervalLabel = usePlanIntervalLabel('saas.workspace.plan.interval')