@revenexx/cover 0.7.0 → 0.10.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 (101) hide show
  1. package/app/api/forms.ts +1 -0
  2. package/app/app.config.ts +17 -12
  3. package/app/components/RevenexxForm.vue +80 -12
  4. package/app/components/account/AccountShell.vue +18 -0
  5. package/app/components/account/approvals/AccountPendingApprovals.vue +178 -0
  6. package/app/components/account/orderlists/AccountOrderListDetail.vue +47 -4
  7. package/app/components/account/orders/AccountOrderDetail.vue +186 -1
  8. package/app/components/account/payments/AccountPayments.vue +129 -0
  9. package/app/components/account/quotes/AccountQuoteDetail.vue +48 -16
  10. package/app/components/auth/AuthLoginPanel.vue +131 -15
  11. package/app/components/auth/AuthMagicLinkPanel.vue +70 -0
  12. package/app/components/cart/view/CartSummaryPanel.vue +54 -0
  13. package/app/components/checkout/onepage/CheckoutDeliverySection.vue +13 -1
  14. package/app/components/checkout/onepage/CheckoutGate.vue +8 -7
  15. package/app/components/form/FormPage.vue +40 -0
  16. package/app/components/layout/header/AppBar.vue +7 -1
  17. package/app/components/layout/header/MainNav.vue +23 -1
  18. package/app/components/layout/header/MobileMenu.vue +12 -0
  19. package/app/components/product/detail/ProductDetailPriceRequest.vue +39 -0
  20. package/app/components/product/detail/ProductDetailView.vue +57 -0
  21. package/app/composables/useAccountHold.ts +45 -0
  22. package/app/composables/useAccountPayments.ts +21 -0
  23. package/app/composables/useAccountQuotes.ts +15 -2
  24. package/app/composables/useAuthStore.ts +82 -2
  25. package/app/composables/useAuthoredForms.ts +26 -0
  26. package/app/composables/useAvailableOffers.ts +42 -0
  27. package/app/composables/useGuestOrdering.ts +28 -0
  28. package/app/composables/useMasterDataEditable.ts +22 -7
  29. package/app/composables/useOrderListRules.ts +21 -1
  30. package/app/composables/usePendingApprovals.ts +37 -0
  31. package/app/config/icons.ts +2 -0
  32. package/app/config/navigation.ts +2 -2
  33. package/app/formkit.config.ts +14 -0
  34. package/app/interfaces/account/approvals.ts +37 -0
  35. package/app/interfaces/account/order-list.ts +29 -0
  36. package/app/interfaces/account/order-lists.ts +9 -0
  37. package/app/interfaces/account/payments.ts +48 -0
  38. package/app/interfaces/auth.ts +11 -0
  39. package/app/interfaces/b2b.ts +8 -8
  40. package/app/interfaces/offers.ts +35 -0
  41. package/app/interfaces/shopSettings.ts +77 -0
  42. package/app/plugins/account-hold.client.ts +20 -0
  43. package/app/plugins/shop-settings.ts +27 -12
  44. package/i18n/locales/de/account.json +80 -0
  45. package/i18n/locales/de/auth.json +29 -0
  46. package/i18n/locales/de/cart.json +7 -0
  47. package/i18n/locales/de/checkout.json +2 -1
  48. package/i18n/locales/de/common.json +4 -2
  49. package/i18n/locales/de/forms.json +27 -0
  50. package/i18n/locales/en/account.json +80 -0
  51. package/i18n/locales/en/auth.json +29 -0
  52. package/i18n/locales/en/cart.json +7 -0
  53. package/i18n/locales/en/checkout.json +2 -1
  54. package/i18n/locales/en/common.json +2 -0
  55. package/i18n/locales/en/forms.json +27 -0
  56. package/package.json +2 -1
  57. package/server/api/account/address/[id].delete.ts +1 -1
  58. package/server/api/account/address/[id].put.ts +1 -1
  59. package/server/api/account/address/index.post.ts +1 -1
  60. package/server/api/account/order-lists/[id].get.ts +37 -3
  61. package/server/api/account/orders/[id]/cancel.post.ts +54 -0
  62. package/server/api/account/orders/[id]/messages.get.ts +63 -0
  63. package/server/api/account/orders/[id]/messages.post.ts +44 -0
  64. package/server/api/account/organization.put.ts +1 -1
  65. package/server/api/account/payments.get.ts +54 -0
  66. package/server/api/account/pending-approvals/[id]/approve.post.ts +10 -0
  67. package/server/api/account/pending-approvals/[id]/decline.post.ts +10 -0
  68. package/server/api/account/pending-approvals/index.get.ts +25 -0
  69. package/server/api/account/profile.put.ts +1 -1
  70. package/server/api/account/quotes/[id]/decline.post.ts +35 -6
  71. package/server/api/account/team/[id].put.ts +1 -1
  72. package/server/api/account/team.post.ts +1 -1
  73. package/server/api/auth/magic-link.post.ts +32 -0
  74. package/server/api/auth/magic-link.put.ts +30 -0
  75. package/server/api/auth/otp.post.ts +33 -0
  76. package/server/api/auth/otp.put.ts +28 -0
  77. package/server/api/checkout/profile.get.ts +6 -3
  78. package/server/api/forms/[slug]/submit.post.ts +27 -16
  79. package/server/api/forms/[slug].get.ts +9 -1
  80. package/server/api/forms/index.get.ts +23 -0
  81. package/server/api/orders/index.post.ts +8 -0
  82. package/server/api/promotions/available.post.ts +37 -0
  83. package/server/config/account/organization.json +0 -4
  84. package/server/config/shop/app-settings.json +4 -0
  85. package/server/data/forms/authored.json +337 -0
  86. package/server/interfaces/forms.ts +51 -0
  87. package/server/services/ApiAuthService.ts +10 -0
  88. package/server/services/ApiFormsService.ts +56 -0
  89. package/server/services/MockB2BContextService.ts +1 -5
  90. package/server/services/MockFormsService.ts +63 -0
  91. package/server/utils/accountPayments.ts +45 -0
  92. package/server/utils/appSettings.ts +69 -4
  93. package/server/utils/forms.ts +62 -14
  94. package/server/utils/formsService.ts +29 -0
  95. package/server/utils/liveOrders.ts +26 -0
  96. package/server/utils/masterData.ts +31 -11
  97. package/server/utils/passwordlessSignIn.ts +73 -0
  98. package/server/utils/pendingApprovals.ts +153 -0
  99. package/server/utils/promotionsService.ts +90 -0
  100. package/server/utils/quotesService.ts +15 -0
  101. package/server/utils/shopSettings.ts +35 -4
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
  },
@@ -32,7 +32,7 @@ const props = defineProps<{
32
32
  }>();
33
33
 
34
34
  const { icon } = useIcons();
35
- const { locale } = useI18n();
35
+ const { locale, t } = useI18n();
36
36
  const route = useRoute();
37
37
 
38
38
  interface FormPayload {
@@ -40,6 +40,8 @@ interface FormPayload {
40
40
  slug: string;
41
41
  definition: Record<string, unknown>[];
42
42
  settings?: { submit_label?: string; success_message?: string } | null;
43
+ /** The decoy field the tenant configured, when there is one. */
44
+ honeypot?: string | null;
43
45
  }
44
46
 
45
47
  interface FormStep {
@@ -72,12 +74,29 @@ function normalizeSteps(definition: Record<string, unknown>[]): FormStep[] {
72
74
  return steps;
73
75
  }
74
76
 
77
+ /**
78
+ * The headers an internal call has to carry, and why.
79
+ *
80
+ * An internal `$fetch` during SSR gets a FRESH event that inherits nothing from
81
+ * the navigation that triggered it. Without the brokered tenant headers a
82
+ * deployed multi-tenant Site has no credentials at all, so the read falls back to
83
+ * whatever the process was configured with — which is how a live storefront
84
+ * rendered the bundled demo form. The cookie carries the market the visitor
85
+ * chose and the dev panel's live/demo switch.
86
+ *
87
+ * On the client this is {} and the browser's own request already carries all of
88
+ * it, so the same call works there unchanged.
89
+ */
90
+ function forwardedHeaders(): Record<string, string> {
91
+ return useRequestHeaders(["cookie", "x-revenexx-tenant", "x-revenexx-context"]);
92
+ }
93
+
75
94
  // No top-level await — keep this a sync component so it renders its own
76
95
  // pending/empty states. Re-fetches on locale change (BFF localises labels).
77
96
  const { data: form, pending } = useAsyncData(
78
97
  () => `revenexx-form-${props.slug}-${locale.value}`,
79
98
  () => $fetch<FormPayload>(formsApi.schema(props.slug), {
80
- headers: { "x-locale": locale.value },
99
+ headers: { ...forwardedHeaders(), "x-locale": locale.value },
81
100
  }).catch(() => null),
82
101
  { watch: [() => props.slug, locale] },
83
102
  );
@@ -85,7 +104,16 @@ const { data: form, pending } = useAsyncData(
85
104
  const steps = computed(() => normalizeSteps(form.value?.definition ?? []));
86
105
  const fieldSteps = computed(() => steps.value.filter(s => s.kind === "fields"));
87
106
  const thankStep = computed(() => steps.value.find(s => s.kind === "thankyou") ?? null);
88
- const submitLabel = computed(() => form.value?.settings?.submit_label || "Submit");
107
+ const submitLabel = computed(() => form.value?.settings?.submit_label || t("forms.submit"));
108
+
109
+ /**
110
+ * The tenant's decoy field. The forms app expects the STOREFRONT to render it —
111
+ * it can only judge what it is sent — so a tenant who configured a trap and a
112
+ * shop that never rendered the field add up to no trap at all, which is exactly
113
+ * what shipped. Hidden from sight, from the tab order and from a screen reader;
114
+ * a human therefore never fills it, and a bot fills everything.
115
+ */
116
+ const honeypot = computed(() => form.value?.honeypot ?? null);
89
117
 
90
118
  // Product (reference) fields pre-fill from the `context` prop or the matching
91
119
  // URL query param — so a price request linked from a product page carries it.
@@ -120,13 +148,16 @@ function cleanNodes(nodes: Record<string, unknown>[]): FormKitSchemaDefinition {
120
148
 
121
149
  const formId = useId();
122
150
  const stepIndex = ref(0);
151
+ /** Whatever filled the decoy. Kept outside FormKit's value tree so the field
152
+ * never appears in a step, a validation message or the tab order. */
153
+ const honeypotValue = ref("");
123
154
  const tick = ref(0);
124
155
  const submitting = ref(false);
125
156
  const submitted = ref(false);
126
157
  const successMessage = ref<string | null>(null);
127
158
  const submitError = ref<string | null>(null);
128
159
 
129
- watch(() => props.slug, () => { stepIndex.value = 0; submitted.value = false; });
160
+ watch(() => props.slug, () => { stepIndex.value = 0; submitted.value = false; honeypotValue.value = ""; });
130
161
 
131
162
  const isLastStep = computed(() => stepIndex.value >= fieldSteps.value.length - 1);
132
163
 
@@ -156,21 +187,30 @@ async function onSubmit(values: Record<string, unknown>) {
156
187
  submitError.value = null;
157
188
  submitting.value = true;
158
189
  try {
159
- const res = await $fetch<{ ok: boolean; success_message: string | null }>(
190
+ const res = await $fetch<{ ok: boolean; outcome: string; success_message: string | null }>(
160
191
  formsApi.submit(props.slug),
161
192
  {
162
193
  method: "POST",
194
+ headers: forwardedHeaders(),
163
195
  body: {
164
- data: values,
196
+ data: honeypot.value
197
+ ? { ...values, [honeypot.value]: honeypotValue.value }
198
+ : values,
165
199
  source: props.source ?? (import.meta.client ? window.location.pathname : undefined),
166
200
  },
167
201
  },
168
202
  );
169
- successMessage.value = res.success_message || "Thank you — your message has been sent.";
203
+ // A tenant who chose to refuse a caught submission stored nothing, so
204
+ // there is nothing to thank anybody for.
205
+ if (!res.ok) {
206
+ submitError.value = t("forms.rejected");
207
+ return;
208
+ }
209
+ successMessage.value = res.success_message || t("forms.success");
170
210
  submitted.value = true;
171
211
  }
172
212
  catch {
173
- submitError.value = "Something went wrong. Please try again.";
213
+ submitError.value = t("forms.error");
174
214
  }
175
215
  finally {
176
216
  submitting.value = false;
@@ -206,8 +246,15 @@ async function onSubmit(values: Record<string, unknown>) {
206
246
  />
207
247
  </div>
208
248
 
249
+ <UiFeedbackEmptyState
250
+ v-else-if="!form"
251
+ icon="file"
252
+ :title="t('forms.missingTitle')"
253
+ :description="t('forms.missingDescription')"
254
+ />
255
+
209
256
  <FormKit
210
- v-else-if="form"
257
+ v-else
211
258
  :id="formId"
212
259
  type="form"
213
260
  :value="prefill"
@@ -221,7 +268,7 @@ async function onSubmit(values: Record<string, unknown>) {
221
268
  v-if="fieldSteps.length > 1"
222
269
  class="mb-4 text-sm text-muted"
223
270
  >
224
- Step {{ stepIndex + 1 }} of {{ fieldSteps.length }}<template v-if="fieldSteps[stepIndex]?.title"> · {{ fieldSteps[stepIndex]?.title }}</template>
271
+ {{ t('forms.step', { current: stepIndex + 1, total: fieldSteps.length }) }}<template v-if="fieldSteps[stepIndex]?.title"> · {{ fieldSteps[stepIndex]?.title }}</template>
225
272
  </p>
226
273
 
227
274
  <div
@@ -232,13 +279,34 @@ async function onSubmit(values: Record<string, unknown>) {
232
279
  <FormKitSchema :schema="cleanNodes(step.nodes)" />
233
280
  </div>
234
281
 
282
+ <!--
283
+ The decoy. Off-screen rather than display:none, because a bot that
284
+ reads the stylesheet skips a hidden input; aria-hidden and tabindex
285
+ keep it away from everybody it is not meant for.
286
+ -->
287
+ <div
288
+ v-if="honeypot"
289
+ aria-hidden="true"
290
+ class="absolute -left-[9999px] w-px h-px overflow-hidden"
291
+ >
292
+ <label :for="`${formId}-hp`">{{ t('forms.honeypotLabel') }}</label>
293
+ <input
294
+ :id="`${formId}-hp`"
295
+ v-model="honeypotValue"
296
+ :name="honeypot"
297
+ type="text"
298
+ tabindex="-1"
299
+ autocomplete="off"
300
+ >
301
+ </div>
302
+
235
303
  <div class="mt-6 flex items-center justify-between gap-3">
236
304
  <UButton
237
305
  v-if="stepIndex > 0"
238
306
  type="button"
239
307
  color="neutral"
240
308
  variant="ghost"
241
- :label="'Back'"
309
+ :label="t('forms.back')"
242
310
  @click="back"
243
311
  />
244
312
  <span v-else />
@@ -248,7 +316,7 @@ async function onSubmit(values: Record<string, unknown>) {
248
316
  type="button"
249
317
  color="primary"
250
318
  :disabled="!activeStepValid"
251
- :label="'Continue'"
319
+ :label="t('forms.continue')"
252
320
  @click="next"
253
321
  />
254
322
  <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">
@@ -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>
@@ -26,7 +26,9 @@ const { data: list, status, error, refresh } = useFetch<OrderList>(
26
26
  // Two different permissions, because the orderlists app grants two. What is ON
27
27
  // a shared list is the company's to change where the merchant allows it; the
28
28
  // list itself — its name, its sharing, its existence — stays with its owner.
29
- const { canEditPositions, canManage, maxPositions, cartMergeMode } = useOrderListRules();
29
+ const { canEditPositions, canManage, maxPositions, cartMergeMode, onMissingArticle } = useOrderListRules();
30
+ /** Positions the shop no longer carries — the buyer maintaining the list needs them named. */
31
+ const discontinued = computed(() => (list.value?.positions ?? []).filter(p => p.available === false));
30
32
  const isOwner = computed(() => !!list.value && canManage(list.value));
31
33
  const mayEditPositions = computed(() => !!list.value && canEditPositions(list.value));
32
34
  const positionsFull = computed(() =>
@@ -116,8 +118,25 @@ async function addToCart(): Promise<void> {
116
118
  if (cartMergeMode.value === "replace") {
117
119
  cart.clearCart();
118
120
  }
121
+ // A part the shop no longer carries. What becomes of it is the merchant's
122
+ // answer, not this shop's: take it anyway (and let the cart object), leave it
123
+ // out, or refuse the whole list. Told before anything moves, because a buyer
124
+ // who finds out afterwards has a cart they did not assemble.
125
+ const missing = list.value.positions.filter(p => p.available === false);
126
+ if (missing.length > 0 && onMissingArticle.value === "fail") {
127
+ toast.add({
128
+ title: t("orderLists.missing.blocked", { count: missing.length }),
129
+ color: "error",
130
+ icon: icon("error"),
131
+ });
132
+ return;
133
+ }
134
+ const takeable = onMissingArticle.value === "skip"
135
+ ? list.value.positions.filter(p => p.available !== false)
136
+ : list.value.positions;
137
+
119
138
  let added = 0;
120
- for (const position of list.value.positions) {
139
+ for (const position of takeable) {
121
140
  const ok = cart.addItem({
122
141
  id: position.id,
123
142
  name: position.name,
@@ -143,10 +162,12 @@ async function addToCart(): Promise<void> {
143
162
  }
144
163
  }
145
164
  toast.add({
146
- title: t("orderLists.addedToCart", { count: added }),
165
+ title: missing.length > 0 && onMissingArticle.value === "skip"
166
+ ? t("orderLists.missing.skipped", { count: added, skipped: missing.length })
167
+ : t("orderLists.addedToCart", { count: added }),
147
168
  color: "success",
148
169
  icon: icon("success"),
149
- duration: 2000,
170
+ duration: 2500,
150
171
  });
151
172
  await navigateTo(to("/cart"));
152
173
  }
@@ -232,6 +253,16 @@ async function addToCart(): Promise<void> {
232
253
  </div>
233
254
 
234
255
  <!-- Positions -->
256
+ <UAlert
257
+ v-if="discontinued.length"
258
+ color="warning"
259
+ variant="subtle"
260
+ :icon="icon('warning')"
261
+ :description="onMissingArticle === 'fail'
262
+ ? t('orderLists.missing.blocked', { count: discontinued.length })
263
+ : t('orderLists.missing.gone') + ': ' + discontinued.map(p => p.name).join(', ')"
264
+ />
265
+
235
266
  <section class="border border-(--ui-border) rounded-xl overflow-hidden">
236
267
  <h2 class="px-4 sm:px-5 py-3 text-sm font-semibold text-highlighted bg-elevated/60 border-b border-(--ui-border)">
237
268
  {{ t('orderLists.columns.positions') }} ({{ list.positions.length }})
@@ -241,6 +272,7 @@ async function addToCart(): Promise<void> {
241
272
  v-for="(position, index) in list.positions"
242
273
  :key="`${list.id}-${index}`"
243
274
  class="flex items-center gap-3 py-3"
275
+ :class="position.available === false ? 'opacity-60' : ''"
244
276
  >
245
277
  <span
246
278
  class="w-14 h-14 shrink-0 flex items-center justify-center rounded-lg
@@ -255,6 +287,17 @@ async function addToCart(): Promise<void> {
255
287
  <p class="text-sm font-medium text-highlighted truncate">
256
288
  {{ position.name }}
257
289
  </p>
290
+ <!-- A part the shop no longer carries. Said on the list rather
291
+ than only when it reaches the cart: by then it is too late
292
+ to fix the list, and the buyer keeping it is the one who can. -->
293
+ <UBadge
294
+ v-if="position.available === false"
295
+ size="sm"
296
+ color="warning"
297
+ variant="subtle"
298
+ class="my-0.5"
299
+ :label="t('orderLists.missing.gone')"
300
+ />
258
301
  <p class="text-xs text-muted">
259
302
  {{ position.sku }}
260
303
  <template v-if="position.customSku">