@revenexx/cover 0.7.1 → 0.11.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 (175) hide show
  1. package/app/api/account.ts +4 -0
  2. package/app/api/forms.ts +1 -0
  3. package/app/app.config.ts +17 -12
  4. package/app/assets/css/cover.css +9 -0
  5. package/app/components/RevenexxForm.vue +84 -12
  6. package/app/components/account/AccountShell.vue +18 -0
  7. package/app/components/account/AccountSidebar.vue +2 -5
  8. package/app/components/account/approvals/AccountPendingApprovals.vue +178 -0
  9. package/app/components/account/dashboard/AccountDashboardKpis.vue +74 -34
  10. package/app/components/account/dashboard/AccountDashboardQuickActions.vue +24 -6
  11. package/app/components/account/orderlists/AccountOrderListDetail.vue +47 -4
  12. package/app/components/account/orders/AccountOrderDetail.vue +186 -1
  13. package/app/components/account/organization/AccountOrganization.vue +3 -1
  14. package/app/components/account/payments/AccountPayments.vue +129 -0
  15. package/app/components/account/quotes/AccountQuoteDetail.vue +48 -16
  16. package/app/components/account/team/AccountTeam.vue +32 -7
  17. package/app/components/auth/AuthForgotPasswordPanel.vue +9 -4
  18. package/app/components/auth/AuthLoginPanel.vue +136 -18
  19. package/app/components/auth/AuthMagicLinkPanel.vue +70 -0
  20. package/app/components/cart/actions/CartSaveToListModal.vue +5 -0
  21. package/app/components/cart/item/CartItem.vue +17 -75
  22. package/app/components/cart/position/CartPosition.vue +17 -30
  23. package/app/components/cart/quote/CartQuoteRequestModal.vue +9 -1
  24. package/app/components/cart/view/CartSummaryPanel.vue +54 -0
  25. package/app/components/category/view/GridView.vue +10 -1
  26. package/app/components/category/view/ListView.vue +10 -1
  27. package/app/components/checkout/confirmation/CheckoutConfirmationActions.vue +2 -0
  28. package/app/components/checkout/onepage/CheckoutAddressSection.vue +4 -4
  29. package/app/components/checkout/onepage/CheckoutDeliverySection.vue +31 -3
  30. package/app/components/checkout/onepage/CheckoutGate.vue +10 -7
  31. package/app/components/checkout/onepage/CheckoutOnePageView.vue +1 -1
  32. package/app/components/checkout/onepage/CheckoutPaymentSection.vue +10 -0
  33. package/app/components/checkout/onepage/CheckoutSummarySection.vue +7 -1
  34. package/app/components/form/FormPage.vue +40 -0
  35. package/app/components/layout/Region.vue +13 -0
  36. package/app/components/layout/footer/Footer.vue +8 -0
  37. package/app/components/layout/header/AppBar.vue +11 -4
  38. package/app/components/layout/header/MainNav.vue +26 -4
  39. package/app/components/layout/header/MobileMenu.vue +12 -0
  40. package/app/components/listing/ListingResults.vue +3 -1
  41. package/app/components/product/card/Compact.vue +10 -1
  42. package/app/components/product/detail/ProductDetailAddToCart.vue +51 -18
  43. package/app/components/product/detail/ProductDetailIdentity.vue +1 -1
  44. package/app/components/product/detail/ProductDetailPriceRequest.vue +39 -0
  45. package/app/components/product/detail/ProductDetailSaveToList.vue +10 -0
  46. package/app/components/product/detail/ProductDetailView.vue +57 -0
  47. package/app/composables/useAccountDashboard.ts +0 -10
  48. package/app/composables/useAccountHold.ts +45 -0
  49. package/app/composables/useAccountNavigation.ts +35 -0
  50. package/app/composables/useAccountPayments.ts +21 -0
  51. package/app/composables/useAccountQuotes.ts +15 -2
  52. package/app/composables/useAuthStore.ts +84 -2
  53. package/app/composables/useAuthoredForms.ts +26 -0
  54. package/app/composables/useAvailableOffers.ts +42 -0
  55. package/app/composables/useCategoryListing.ts +6 -0
  56. package/app/composables/useCheckoutOnePage.ts +21 -2
  57. package/app/composables/useGuestOrdering.ts +28 -0
  58. package/app/composables/useMasterDataEditable.ts +45 -7
  59. package/app/composables/useOrderListRules.ts +21 -1
  60. package/app/composables/usePendingApprovals.ts +37 -0
  61. package/app/composables/useProductCard.ts +29 -2
  62. package/app/composables/useProductListing.ts +79 -0
  63. package/app/composables/useQuantityStepper.ts +90 -0
  64. package/app/composables/useQuickActions.ts +35 -0
  65. package/app/composables/useRoleGrants.ts +32 -0
  66. package/app/composables/useSearchListing.ts +4 -0
  67. package/app/composables/useThemeEvents.ts +144 -0
  68. package/app/config/accountDashboard.ts +26 -0
  69. package/app/config/icons.ts +2 -0
  70. package/app/config/navigation.ts +2 -2
  71. package/app/config/quickActions.ts +40 -5
  72. package/app/formkit.config.ts +14 -0
  73. package/app/interfaces/account/approvals.ts +37 -0
  74. package/app/interfaces/account/dashboard.ts +2 -0
  75. package/app/interfaces/account/order-list.ts +29 -0
  76. package/app/interfaces/account/order-lists.ts +9 -0
  77. package/app/interfaces/account/payments.ts +48 -0
  78. package/app/interfaces/auth.ts +24 -2
  79. package/app/interfaces/b2b.ts +8 -8
  80. package/app/interfaces/offers.ts +35 -0
  81. package/app/interfaces/quantity-stepper.ts +17 -0
  82. package/app/interfaces/shopSettings.ts +77 -0
  83. package/app/layouts/default.vue +19 -10
  84. package/app/layouts/focus.vue +28 -7
  85. package/app/middleware/checkout-guard.ts +7 -1
  86. package/app/pages/punchout/transfer.vue +22 -0
  87. package/app/plugins/account-hold.client.ts +20 -0
  88. package/app/plugins/shop-settings.ts +27 -12
  89. package/app/plugins/theme-events.client.ts +132 -0
  90. package/app/shared/themeEvents.ts +445 -0
  91. package/i18n/locales/de/account.json +87 -0
  92. package/i18n/locales/de/auth.json +30 -0
  93. package/i18n/locales/de/cart.json +9 -1
  94. package/i18n/locales/de/checkout.json +4 -2
  95. package/i18n/locales/de/common.json +4 -0
  96. package/i18n/locales/de/cover.json +44 -0
  97. package/i18n/locales/de/editor.json +47 -1
  98. package/i18n/locales/de/forms.json +27 -0
  99. package/i18n/locales/en/account.json +87 -0
  100. package/i18n/locales/en/auth.json +30 -0
  101. package/i18n/locales/en/cart.json +9 -1
  102. package/i18n/locales/en/checkout.json +4 -2
  103. package/i18n/locales/en/common.json +4 -0
  104. package/i18n/locales/en/cover.json +44 -0
  105. package/i18n/locales/en/editor.json +47 -1
  106. package/i18n/locales/en/forms.json +27 -0
  107. package/nuxt.config.ts +15 -1
  108. package/package.json +6 -2
  109. package/server/api/account/address/[id].delete.ts +1 -1
  110. package/server/api/account/address/[id].put.ts +1 -1
  111. package/server/api/account/address/index.post.ts +1 -1
  112. package/server/api/account/order-lists/[id].get.ts +37 -3
  113. package/server/api/account/orders/[id]/cancel.post.ts +54 -0
  114. package/server/api/account/orders/[id]/messages.get.ts +63 -0
  115. package/server/api/account/orders/[id]/messages.post.ts +44 -0
  116. package/server/api/account/orders/[id]/return.post.ts +1 -0
  117. package/server/api/account/orders/[id].get.ts +1 -1
  118. package/server/api/account/organization.put.ts +1 -1
  119. package/server/api/account/payments.get.ts +54 -0
  120. package/server/api/account/pending-approvals/[id]/approve.post.ts +10 -0
  121. package/server/api/account/pending-approvals/[id]/decline.post.ts +10 -0
  122. package/server/api/account/pending-approvals/index.get.ts +26 -0
  123. package/server/api/account/profile.get.ts +3 -1
  124. package/server/api/account/profile.put.ts +1 -1
  125. package/server/api/account/quotes/[id]/decline.post.ts +35 -6
  126. package/server/api/account/team/[id].put.ts +1 -1
  127. package/server/api/account/team.post.ts +1 -1
  128. package/server/api/auth/login.post.ts +6 -0
  129. package/server/api/auth/magic-link.post.ts +32 -0
  130. package/server/api/auth/magic-link.put.ts +35 -0
  131. package/server/api/auth/otp.post.ts +33 -0
  132. package/server/api/auth/otp.put.ts +33 -0
  133. package/server/api/carts/[id]/activate.post.ts +1 -0
  134. package/server/api/carts/[id]/index.delete.ts +1 -0
  135. package/server/api/carts/[id]/index.put.ts +1 -0
  136. package/server/api/carts/[id]/items.post.ts +1 -0
  137. package/server/api/checkout/profile.get.ts +6 -3
  138. package/server/api/forms/[slug]/submit.post.ts +27 -16
  139. package/server/api/forms/[slug].get.ts +9 -1
  140. package/server/api/forms/index.get.ts +23 -0
  141. package/server/api/orders/index.post.ts +41 -0
  142. package/server/api/promotions/available.post.ts +37 -0
  143. package/server/api/quick-actions.get.ts +6 -38
  144. package/server/config/account/organization.json +0 -4
  145. package/server/config/shop/app-settings.json +4 -0
  146. package/server/data/forms/authored.json +337 -0
  147. package/server/interfaces/forms.ts +51 -0
  148. package/server/middleware/buyer-principal.ts +18 -0
  149. package/server/routes/punchout/start.get.ts +2 -2
  150. package/server/services/ApiAddressBookService.ts +43 -1
  151. package/server/services/ApiAuthService.ts +101 -10
  152. package/server/services/ApiCartService.ts +3 -10
  153. package/server/services/ApiFormsService.ts +56 -0
  154. package/server/services/ApiOrganizationService.ts +7 -2
  155. package/server/services/ApiTeamService.ts +93 -21
  156. package/server/services/MockB2BContextService.ts +1 -5
  157. package/server/services/MockFormsService.ts +63 -0
  158. package/server/utils/accountPayments.ts +45 -0
  159. package/server/utils/appSettings.ts +69 -4
  160. package/server/utils/buyerIdentity.ts +168 -0
  161. package/server/utils/cartOwnership.ts +27 -0
  162. package/server/utils/forms.ts +62 -14
  163. package/server/utils/formsService.ts +29 -0
  164. package/server/utils/liveOrderLists.ts +50 -23
  165. package/server/utils/liveOrders.ts +65 -24
  166. package/server/utils/livePrices.ts +7 -15
  167. package/server/utils/masterData.ts +60 -11
  168. package/server/utils/passwordlessSignIn.ts +82 -0
  169. package/server/utils/pendingApprovals.ts +175 -0
  170. package/server/utils/procurementCheckout.ts +2 -0
  171. package/server/utils/promotionsService.ts +90 -0
  172. package/server/utils/quickActionCatalogue.ts +53 -0
  173. package/server/utils/quotesService.ts +15 -0
  174. package/server/utils/revenexxSdk.ts +116 -2
  175. package/server/utils/shopSettings.ts +35 -4
@@ -1,6 +1,10 @@
1
1
  export const accountApi = {
2
2
  profile: () => "/api/account/profile",
3
+ /** The user's B2B context: organization settings, cost centers, workflows. */
4
+ context: () => "/api/account/context",
3
5
  orders: () => "/api/account/orders",
6
+ orderLists: () => "/api/account/order-lists",
7
+ requisitions: () => "/api/account/requisitions",
4
8
  orderReturn: (id: string) => `/api/account/orders/${id}/return`,
5
9
  addresses: () => "/api/account/addresses",
6
10
  addressUpdate: (id: string) => `/api/account/address/${id}`,
package/app/api/forms.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  /** BFF paths for storefront forms (built in the Cockpit, rendered here). */
2
2
  export const formsApi = {
3
+ list: () => "/api/forms",
3
4
  schema: (slug: string) => `/api/forms/${slug}`,
4
5
  submit: (slug: string) => `/api/forms/${slug}/submit`,
5
6
  };
package/app/app.config.ts CHANGED
@@ -35,6 +35,11 @@ export default defineAppConfig({
35
35
  // The quotes app (RX-783): a cart the shop cannot order as it is becomes a
36
36
  // quotation request, priced in the Cockpit and ordered from the account.
37
37
  quotesService: "mock",
38
+ // The forms app: the contact, price-request and return-request forms an
39
+ // operator authors in the Cockpit. `mock` serves the three bundled demo
40
+ // forms, so a storefront without gateway credentials still has a contact
41
+ // page and a browser test still has something to submit.
42
+ formsService: "mock",
38
43
  themeService: "mock",
39
44
  // What the shop was CONFIGURED to do — the platform apps' own tenant
40
45
  // settings, read through the gateway's settings resolver. Mock answers
@@ -107,6 +112,12 @@ export default defineAppConfig({
107
112
  support: true,
108
113
  },
109
114
  },
115
+ // The way into the catalogue, in the header of every storefront. The panel is
116
+ // built from the tenant's own category tree and needs no content backend; what
117
+ // it needs is an entry that opens it, and a storefront writing its own
118
+ // navigation had no reason to know that. On by default, so a shop without a
119
+ // path to its own catalogue is a decision rather than an oversight.
120
+ catalogueMenu: true,
110
121
  // The shipping app states its order cut-off in UTC — it has to, it serves
111
122
  // every market. Which zone a storefront quotes it back in is the shop's own
112
123
  // decision, so it is named here. UTC by default: a shop that has not said
@@ -121,18 +132,12 @@ export default defineAppConfig({
121
132
  checkout: {
122
133
  earliestDeliveryDays: 0,
123
134
  },
124
- // Master data another system owns — an ERP, usually — is shown in the
125
- // account and not changed there. A merchant whose ERP is the record for a
126
- // customer's addresses, profile or company sets the matching flag to
127
- // false: the account shows the data read-only, the checkout offers its
128
- // addresses for SELECTION only, and the BFF refuses the write (403) so no
129
- // forgotten button can reach it. Changes then go through the merchant.
130
- account: {
131
- addresses: { editable: true },
132
- profile: { editable: true },
133
- organization: { editable: true },
134
- team: { editable: true },
135
- },
135
+ // Master data another system owns — an ERP, usually — is shown in the account
136
+ // and not changed there. That used to be four flags here, which was a guess in
137
+ // both directions: the shop hid a form while the platform went on accepting
138
+ // the write, and a storefront could allow what the platform refused. The
139
+ // customers app holds the answer now (`self_service_master_data`) and refuses
140
+ // the write itself; the shop reads it and offers accordingly.
136
141
  ui: {
137
142
  icons: nuxtUiIcons(DEFAULT_ICON_WEIGHT),
138
143
  },
@@ -23,3 +23,12 @@
23
23
  .dark.dark {
24
24
  --ui-warning: var(--ui-color-warning-400);
25
25
  }
26
+
27
+ /* Keep browser autofill visually consistent with the checkout fields. */
28
+ input:-webkit-autofill,
29
+ input:-webkit-autofill:hover,
30
+ input:-webkit-autofill:focus {
31
+ -webkit-text-fill-color: var(--ui-text-highlighted);
32
+ -webkit-box-shadow: 0 0 0 1000px var(--ui-bg) inset;
33
+ box-shadow: 0 0 0 1000px var(--ui-bg) inset;
34
+ }
@@ -31,8 +31,10 @@ const props = defineProps<{
31
31
  context?: Record<string, unknown>;
32
32
  }>();
33
33
 
34
+ const themeEvents = useThemeEvents();
35
+
34
36
  const { icon } = useIcons();
35
- const { locale } = useI18n();
37
+ const { locale, t } = useI18n();
36
38
  const route = useRoute();
37
39
 
38
40
  interface FormPayload {
@@ -40,6 +42,8 @@ interface FormPayload {
40
42
  slug: string;
41
43
  definition: Record<string, unknown>[];
42
44
  settings?: { submit_label?: string; success_message?: string } | null;
45
+ /** The decoy field the tenant configured, when there is one. */
46
+ honeypot?: string | null;
43
47
  }
44
48
 
45
49
  interface FormStep {
@@ -72,12 +76,29 @@ function normalizeSteps(definition: Record<string, unknown>[]): FormStep[] {
72
76
  return steps;
73
77
  }
74
78
 
79
+ /**
80
+ * The headers an internal call has to carry, and why.
81
+ *
82
+ * An internal `$fetch` during SSR gets a FRESH event that inherits nothing from
83
+ * the navigation that triggered it. Without the brokered tenant headers a
84
+ * deployed multi-tenant Site has no credentials at all, so the read falls back to
85
+ * whatever the process was configured with — which is how a live storefront
86
+ * rendered the bundled demo form. The cookie carries the market the visitor
87
+ * chose and the dev panel's live/demo switch.
88
+ *
89
+ * On the client this is {} and the browser's own request already carries all of
90
+ * it, so the same call works there unchanged.
91
+ */
92
+ function forwardedHeaders(): Record<string, string> {
93
+ return useRequestHeaders(["cookie", "x-revenexx-tenant", "x-revenexx-context"]);
94
+ }
95
+
75
96
  // No top-level await — keep this a sync component so it renders its own
76
97
  // pending/empty states. Re-fetches on locale change (BFF localises labels).
77
98
  const { data: form, pending } = useAsyncData(
78
99
  () => `revenexx-form-${props.slug}-${locale.value}`,
79
100
  () => $fetch<FormPayload>(formsApi.schema(props.slug), {
80
- headers: { "x-locale": locale.value },
101
+ headers: { ...forwardedHeaders(), "x-locale": locale.value },
81
102
  }).catch(() => null),
82
103
  { watch: [() => props.slug, locale] },
83
104
  );
@@ -85,7 +106,16 @@ const { data: form, pending } = useAsyncData(
85
106
  const steps = computed(() => normalizeSteps(form.value?.definition ?? []));
86
107
  const fieldSteps = computed(() => steps.value.filter(s => s.kind === "fields"));
87
108
  const thankStep = computed(() => steps.value.find(s => s.kind === "thankyou") ?? null);
88
- const submitLabel = computed(() => form.value?.settings?.submit_label || "Submit");
109
+ const submitLabel = computed(() => form.value?.settings?.submit_label || t("forms.submit"));
110
+
111
+ /**
112
+ * The tenant's decoy field. The forms app expects the STOREFRONT to render it —
113
+ * it can only judge what it is sent — so a tenant who configured a trap and a
114
+ * shop that never rendered the field add up to no trap at all, which is exactly
115
+ * what shipped. Hidden from sight, from the tab order and from a screen reader;
116
+ * a human therefore never fills it, and a bot fills everything.
117
+ */
118
+ const honeypot = computed(() => form.value?.honeypot ?? null);
89
119
 
90
120
  // Product (reference) fields pre-fill from the `context` prop or the matching
91
121
  // URL query param — so a price request linked from a product page carries it.
@@ -120,13 +150,16 @@ function cleanNodes(nodes: Record<string, unknown>[]): FormKitSchemaDefinition {
120
150
 
121
151
  const formId = useId();
122
152
  const stepIndex = ref(0);
153
+ /** Whatever filled the decoy. Kept outside FormKit's value tree so the field
154
+ * never appears in a step, a validation message or the tab order. */
155
+ const honeypotValue = ref("");
123
156
  const tick = ref(0);
124
157
  const submitting = ref(false);
125
158
  const submitted = ref(false);
126
159
  const successMessage = ref<string | null>(null);
127
160
  const submitError = ref<string | null>(null);
128
161
 
129
- watch(() => props.slug, () => { stepIndex.value = 0; submitted.value = false; });
162
+ watch(() => props.slug, () => { stepIndex.value = 0; submitted.value = false; honeypotValue.value = ""; });
130
163
 
131
164
  const isLastStep = computed(() => stepIndex.value >= fieldSteps.value.length - 1);
132
165
 
@@ -156,21 +189,32 @@ async function onSubmit(values: Record<string, unknown>) {
156
189
  submitError.value = null;
157
190
  submitting.value = true;
158
191
  try {
159
- const res = await $fetch<{ ok: boolean; success_message: string | null }>(
192
+ const res = await $fetch<{ ok: boolean; outcome: string; success_message: string | null }>(
160
193
  formsApi.submit(props.slug),
161
194
  {
162
195
  method: "POST",
196
+ headers: forwardedHeaders(),
163
197
  body: {
164
- data: values,
198
+ data: honeypot.value
199
+ ? { ...values, [honeypot.value]: honeypotValue.value }
200
+ : values,
165
201
  source: props.source ?? (import.meta.client ? window.location.pathname : undefined),
166
202
  },
167
203
  },
168
204
  );
169
- successMessage.value = res.success_message || "Thank you — your message has been sent.";
205
+ // A tenant who chose to refuse a caught submission stored nothing, so
206
+ // there is nothing to thank anybody for.
207
+ if (!res.ok) {
208
+ submitError.value = t("forms.rejected");
209
+ return;
210
+ }
211
+ successMessage.value = res.success_message || t("forms.success");
170
212
  submitted.value = true;
213
+ // Which form was sent — never a word of what was typed into it.
214
+ themeEvents.emit("form_submit", { form: { form_code: props.slug.slice(0, 128), outcome: "accepted" } });
171
215
  }
172
216
  catch {
173
- submitError.value = "Something went wrong. Please try again.";
217
+ submitError.value = t("forms.error");
174
218
  }
175
219
  finally {
176
220
  submitting.value = false;
@@ -206,8 +250,15 @@ async function onSubmit(values: Record<string, unknown>) {
206
250
  />
207
251
  </div>
208
252
 
253
+ <UiFeedbackEmptyState
254
+ v-else-if="!form"
255
+ icon="file"
256
+ :title="t('forms.missingTitle')"
257
+ :description="t('forms.missingDescription')"
258
+ />
259
+
209
260
  <FormKit
210
- v-else-if="form"
261
+ v-else
211
262
  :id="formId"
212
263
  type="form"
213
264
  :value="prefill"
@@ -221,7 +272,7 @@ async function onSubmit(values: Record<string, unknown>) {
221
272
  v-if="fieldSteps.length > 1"
222
273
  class="mb-4 text-sm text-muted"
223
274
  >
224
- Step {{ stepIndex + 1 }} of {{ fieldSteps.length }}<template v-if="fieldSteps[stepIndex]?.title"> · {{ fieldSteps[stepIndex]?.title }}</template>
275
+ {{ t('forms.step', { current: stepIndex + 1, total: fieldSteps.length }) }}<template v-if="fieldSteps[stepIndex]?.title"> · {{ fieldSteps[stepIndex]?.title }}</template>
225
276
  </p>
226
277
 
227
278
  <div
@@ -232,13 +283,34 @@ async function onSubmit(values: Record<string, unknown>) {
232
283
  <FormKitSchema :schema="cleanNodes(step.nodes)" />
233
284
  </div>
234
285
 
286
+ <!--
287
+ The decoy. Off-screen rather than display:none, because a bot that
288
+ reads the stylesheet skips a hidden input; aria-hidden and tabindex
289
+ keep it away from everybody it is not meant for.
290
+ -->
291
+ <div
292
+ v-if="honeypot"
293
+ aria-hidden="true"
294
+ class="absolute -left-[9999px] w-px h-px overflow-hidden"
295
+ >
296
+ <label :for="`${formId}-hp`">{{ t('forms.honeypotLabel') }}</label>
297
+ <input
298
+ :id="`${formId}-hp`"
299
+ v-model="honeypotValue"
300
+ :name="honeypot"
301
+ type="text"
302
+ tabindex="-1"
303
+ autocomplete="off"
304
+ >
305
+ </div>
306
+
235
307
  <div class="mt-6 flex items-center justify-between gap-3">
236
308
  <UButton
237
309
  v-if="stepIndex > 0"
238
310
  type="button"
239
311
  color="neutral"
240
312
  variant="ghost"
241
- :label="'Back'"
313
+ :label="t('forms.back')"
242
314
  @click="back"
243
315
  />
244
316
  <span v-else />
@@ -248,7 +320,7 @@ async function onSubmit(values: Record<string, unknown>) {
248
320
  type="button"
249
321
  color="primary"
250
322
  :disabled="!activeStepValid"
251
- :label="'Continue'"
323
+ :label="t('forms.continue')"
252
324
  @click="next"
253
325
  />
254
326
  <UButton
@@ -2,12 +2,30 @@
2
2
  /**
3
3
  * Account area shell: sidebar with the full B2B navigation tree next to the
4
4
  * page content. Account pages wrap their content in this component.
5
+ *
6
+ * It is also where an account on hold is said out loud. Every account page passes
7
+ * through here, so the one sentence that explains why nothing works belongs at
8
+ * this level rather than on each of twenty pages — and a buyer who reads it stops
9
+ * filling a cart they cannot order.
5
10
  */
6
11
  defineSlots<{ default(): unknown }>();
12
+
13
+ const { t } = useI18n();
14
+ const { icon } = useIcons();
15
+ const { onHold, stillAllowed } = useAccountHold();
7
16
  </script>
8
17
 
9
18
  <template>
10
19
  <UContainer class="py-6 lg:py-8">
20
+ <UAlert
21
+ v-if="onHold"
22
+ class="mb-6"
23
+ :color="stillAllowed === 'nothing' ? 'error' : 'warning'"
24
+ variant="subtle"
25
+ :icon="icon('warning')"
26
+ :title="t('account.hold.title')"
27
+ :description="t(`account.hold.${stillAllowed}`)"
28
+ />
11
29
  <div class="flex flex-col lg:flex-row gap-6">
12
30
  <AccountSidebar />
13
31
  <div class="flex-1 min-w-0">
@@ -1,13 +1,10 @@
1
1
  <script setup lang="ts">
2
- import { accountNavigation } from "../../config/navigation";
3
2
  import type { AccountNavGroup } from "../../config/navigation";
4
3
 
5
4
  const { icon } = useIcons();
6
5
 
7
- const appConfig = useAppConfig();
8
- const navigation = computed<AccountNavGroup[]>(() =>
9
- (appConfig.accountNavigation as AccountNavGroup[] | undefined) ?? accountNavigation,
10
- );
6
+ // Live tenant menu → app.config override → the layer's full B2B tree.
7
+ const { navigation } = useAccountNavigation();
11
8
 
12
9
  const { t } = useI18n();
13
10
  const localePath = useLocalePath();
@@ -0,0 +1,178 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * The approver's own queue: what is waiting on them, and yes or no.
4
+ *
5
+ * This is the one surface an approver signs in for, and the shop had none — it
6
+ * listed what the company had asked for, which is a different question, and offered
7
+ * no way to decide anything. So the deciding happened in the Cockpit, an operator's
8
+ * tool a buying organisation's approver has no business being in.
9
+ *
10
+ * A decline asks for a reason. An approval does not: "yes" needs no explaining, and
11
+ * a required field in front of it would be a toll on the common case. A refusal the
12
+ * requester cannot read is one they will simply ask for again.
13
+ */
14
+ const { t, d } = useI18n();
15
+ const { icon } = useIcons();
16
+ const toast = useToast();
17
+ const { approvals, deciding, decide, status } = usePendingApprovals();
18
+ const { formatCurrency } = useCartSummaryFormatting();
19
+
20
+ const declineFor = ref<string | null>(null);
21
+ const declineReason = ref("");
22
+
23
+ async function approve(id: string): Promise<void> {
24
+ try {
25
+ await decide(id, "approve");
26
+ toast.add({ title: t("approvals.queue.approved"), color: "success", icon: icon("success") });
27
+ }
28
+ catch (err) {
29
+ toast.add({
30
+ title: t("approvals.queue.failed"),
31
+ description: (err as { data?: { message?: string } })?.data?.message,
32
+ color: "error",
33
+ icon: icon("error"),
34
+ });
35
+ }
36
+ }
37
+
38
+ async function submitDecline(): Promise<void> {
39
+ const id = declineFor.value;
40
+ if (!id) {
41
+ return;
42
+ }
43
+ try {
44
+ await decide(id, "decline", declineReason.value);
45
+ declineFor.value = null;
46
+ declineReason.value = "";
47
+ toast.add({ title: t("approvals.queue.declined"), color: "success", icon: icon("success") });
48
+ }
49
+ catch (err) {
50
+ toast.add({
51
+ title: t("approvals.queue.failed"),
52
+ description: (err as { data?: { message?: string } })?.data?.message,
53
+ color: "error",
54
+ icon: icon("error"),
55
+ });
56
+ }
57
+ }
58
+ </script>
59
+
60
+ <template>
61
+ <section class="space-y-4">
62
+ <div class="flex items-baseline justify-between gap-3">
63
+ <h2 class="text-lg font-semibold text-highlighted">
64
+ {{ t('approvals.queue.title') }}
65
+ </h2>
66
+ <UBadge
67
+ v-if="approvals.length"
68
+ color="warning"
69
+ variant="subtle"
70
+ :label="String(approvals.length)"
71
+ />
72
+ </div>
73
+
74
+ <p
75
+ v-if="status === 'pending'"
76
+ class="text-sm text-muted"
77
+ >
78
+ {{ t('approvals.queue.loading') }}
79
+ </p>
80
+
81
+ <UiFeedbackEmptyState
82
+ v-else-if="!approvals.length"
83
+ :icon="icon('check')"
84
+ :title="t('approvals.queue.empty.title')"
85
+ :description="t('approvals.queue.empty.description')"
86
+ />
87
+
88
+ <ul
89
+ v-else
90
+ class="border border-(--ui-border) rounded-xl divide-y divide-(--ui-border) overflow-hidden"
91
+ >
92
+ <li
93
+ v-for="approval in approvals"
94
+ :key="approval.id"
95
+ class="px-4 sm:px-5 py-4 flex flex-wrap items-center gap-x-4 gap-y-2"
96
+ >
97
+ <div class="min-w-0 flex-1">
98
+ <p class="text-sm font-medium text-highlighted">
99
+ {{ approval.requestNumber ?? t('approvals.queue.unnamedRequest') }}
100
+ <!-- Which signature this is. Hiding it would let an approver
101
+ think theirs was the only one needed. -->
102
+ <span class="text-xs font-normal text-muted">
103
+ · {{ t('approvals.queue.layer', { layer: approval.layer }) }}
104
+ </span>
105
+ </p>
106
+ <p class="text-xs text-muted">
107
+ <template v-if="approval.requestedBy">{{ approval.requestedBy }} · </template>
108
+ <template v-if="approval.costCentreCode">{{ approval.costCentreCode }} · </template>
109
+ {{ approval.at ? d(new Date(approval.at), { dateStyle: 'medium' }) : '' }}
110
+ </p>
111
+ </div>
112
+
113
+ <!-- The figure, where the request states one. A confident 0,00 € beside
114
+ a signature would be worse than a blank. -->
115
+ <p class="text-sm font-medium text-highlighted tabular-nums">
116
+ {{ approval.total !== null ? formatCurrency(approval.total) : '—' }}
117
+ </p>
118
+
119
+ <div class="flex items-center gap-2">
120
+ <UButton
121
+ size="sm"
122
+ color="neutral"
123
+ variant="outline"
124
+ :disabled="deciding === approval.id"
125
+ :label="t('approvals.queue.decline')"
126
+ @click="declineFor = approval.id"
127
+ />
128
+ <UButton
129
+ size="sm"
130
+ color="primary"
131
+ :loading="deciding === approval.id"
132
+ :label="t('approvals.queue.approve')"
133
+ @click="approve(approval.id)"
134
+ />
135
+ </div>
136
+ </li>
137
+ </ul>
138
+
139
+ <!-- A decline ends the whole request, so the reason is asked for: the
140
+ requester has to know whether to ask again differently. -->
141
+ <UModal
142
+ :open="declineFor !== null"
143
+ :title="t('approvals.queue.declineTitle')"
144
+ @update:open="(open: boolean) => { if (!open) declineFor = null; }"
145
+ >
146
+ <template #body>
147
+ <div class="space-y-4">
148
+ <p class="text-sm text-default">
149
+ {{ t('approvals.queue.declineIntro') }}
150
+ </p>
151
+ <UFormField :label="t('approvals.queue.declineReason')">
152
+ <UTextarea
153
+ v-model="declineReason"
154
+ class="w-full"
155
+ :rows="2"
156
+ :placeholder="t('approvals.queue.declineReasonPlaceholder')"
157
+ />
158
+ </UFormField>
159
+ </div>
160
+ </template>
161
+ <template #footer>
162
+ <div class="flex items-center justify-end gap-2 w-full">
163
+ <UButton
164
+ color="neutral"
165
+ variant="ghost"
166
+ :label="t('cart.item.cancel')"
167
+ @click="declineFor = null"
168
+ />
169
+ <UButton
170
+ color="error"
171
+ :label="t('approvals.queue.decline')"
172
+ @click="submitDecline"
173
+ />
174
+ </div>
175
+ </template>
176
+ </UModal>
177
+ </section>
178
+ </template>
@@ -1,5 +1,25 @@
1
1
  <script setup lang="ts">
2
- /** Dashboard KPI band: open orders, awaiting approval, 30-day spend, budget %. */
2
+ /**
3
+ * Dashboard KPI band: open orders, awaiting approval, 30-day spend, budget %.
4
+ * `kpis` picks which of them render (a block option, a tenant setting); the
5
+ * selection is narrowed through `resolveAccountDashboardKpis`, so an empty or
6
+ * unknown selection still shows the full band — never an empty frame.
7
+ */
8
+ import { ACCOUNT_DASHBOARD_KPI_IDS, resolveAccountDashboardKpis } from "../../../config/accountDashboard";
9
+ import type { AccountDashboardKpiId } from "../../../interfaces/account/dashboard";
10
+
11
+ interface KpiCell {
12
+ readonly id: AccountDashboardKpiId;
13
+ readonly labelKey: string;
14
+ readonly value: string;
15
+ readonly isWarning: boolean;
16
+ }
17
+
18
+ const props = defineProps<{
19
+ /** KPIs to show, in any order; omitted → all four. */
20
+ kpis?: readonly AccountDashboardKpiId[];
21
+ }>();
22
+
3
23
  const {
4
24
  t,
5
25
  formatCurrency,
@@ -15,7 +35,50 @@ const {
15
35
  const pending = computed(() =>
16
36
  ordersPending.value || contextPending.value || requisitionsPending.value);
17
37
 
18
- /** Divider-separated KPI cells: 2-col grid on mobile, 4-col from lg. */
38
+ const visibleKpis = computed(() => resolveAccountDashboardKpis(props.kpis ?? ACCOUNT_DASHBOARD_KPI_IDS));
39
+
40
+ const cellsById = computed<Record<AccountDashboardKpiId, KpiCell>>(() => ({
41
+ openOrders: {
42
+ id: "openOrders",
43
+ labelKey: "account.dashboard.stats.openOrders",
44
+ value: String(openOrdersCount.value),
45
+ isWarning: false,
46
+ },
47
+ awaitingApproval: {
48
+ id: "awaitingApproval",
49
+ labelKey: "account.dashboard.stats.awaitingApproval",
50
+ value: String(awaitingApprovalCount.value),
51
+ isWarning: awaitingApprovalCount.value > 0,
52
+ },
53
+ spend30: {
54
+ id: "spend30",
55
+ labelKey: "account.dashboard.stats.spend30",
56
+ value: formatCurrency(spend30.value),
57
+ isWarning: false,
58
+ },
59
+ budgetUsed: {
60
+ id: "budgetUsed",
61
+ labelKey: "account.dashboard.stats.budgetUsed",
62
+ value: budgetUtilization.value !== null ? `${budgetUtilization.value} %` : "—",
63
+ isWarning: (budgetUtilization.value ?? 0) >= 90,
64
+ },
65
+ }));
66
+
67
+ const cells = computed(() => visibleKpis.value.map(id => cellsById.value[id]));
68
+
69
+ // Static map so Tailwind's JIT emits every utility — the count is computed and
70
+ // a built class name would be purged. Two columns on mobile once there is a
71
+ // pair to show; from lg every KPI gets its own column.
72
+ const COLUMNS_CLASS: Record<number, string> = {
73
+ 1: "grid-cols-1 lg:grid-cols-1",
74
+ 2: "grid-cols-2 lg:grid-cols-2",
75
+ 3: "grid-cols-2 lg:grid-cols-3",
76
+ 4: "grid-cols-2 lg:grid-cols-4",
77
+ };
78
+
79
+ const columnsClass = computed(() => COLUMNS_CLASS[cells.value.length] ?? COLUMNS_CLASS[4]);
80
+
81
+ /** Divider-separated KPI cells: 2-col grid on mobile, one row from lg. */
19
82
  const statCell = `p-4 sm:p-5 border-(--ui-border)
20
83
  max-lg:nth-[n+3]:border-t max-lg:nth-[2n]:border-l lg:not-first:border-l`;
21
84
  </script>
@@ -27,44 +90,21 @@ const statCell = `p-4 sm:p-5 border-(--ui-border)
27
90
  />
28
91
  <dl
29
92
  v-else
30
- class="border border-(--ui-border) rounded-xl grid grid-cols-2 lg:grid-cols-4"
93
+ :class="['border border-(--ui-border) rounded-xl grid', columnsClass]"
31
94
  >
32
- <div :class="statCell">
33
- <dt class="text-sm text-muted truncate">
34
- {{ t('account.dashboard.stats.openOrders') }}
35
- </dt>
36
- <dd class="mt-1 text-2xl font-semibold text-highlighted tabular-nums">
37
- {{ openOrdersCount }}
38
- </dd>
39
- </div>
40
- <div :class="statCell">
41
- <dt class="text-sm text-muted truncate">
42
- {{ t('account.dashboard.stats.awaitingApproval') }}
43
- </dt>
44
- <dd
45
- class="mt-1 text-2xl font-semibold tabular-nums"
46
- :class="awaitingApprovalCount > 0 ? 'text-warning' : 'text-highlighted'"
47
- >
48
- {{ awaitingApprovalCount }}
49
- </dd>
50
- </div>
51
- <div :class="statCell">
52
- <dt class="text-sm text-muted truncate">
53
- {{ t('account.dashboard.stats.spend30') }}
54
- </dt>
55
- <dd class="mt-1 text-2xl font-semibold text-highlighted tabular-nums">
56
- {{ formatCurrency(spend30) }}
57
- </dd>
58
- </div>
59
- <div :class="statCell">
95
+ <div
96
+ v-for="cell in cells"
97
+ :key="cell.id"
98
+ :class="statCell"
99
+ >
60
100
  <dt class="text-sm text-muted truncate">
61
- {{ t('account.dashboard.stats.budgetUsed') }}
101
+ {{ t(cell.labelKey) }}
62
102
  </dt>
63
103
  <dd
64
104
  class="mt-1 text-2xl font-semibold tabular-nums"
65
- :class="(budgetUtilization ?? 0) >= 90 ? 'text-warning' : 'text-highlighted'"
105
+ :class="cell.isWarning ? 'text-warning' : 'text-highlighted'"
66
106
  >
67
- {{ budgetUtilization !== null ? `${budgetUtilization} %` : '—' }}
107
+ {{ cell.value }}
68
108
  </dd>
69
109
  </div>
70
110
  </dl>