@revenexx/cover 0.14.0 → 0.16.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 (113) hide show
  1. package/app/api/account.ts +1 -0
  2. package/app/components/RevenexxForm.vue +183 -19
  3. package/app/components/account/address/AccountAddressCard.vue +8 -2
  4. package/app/components/account/address/AccountAddressView.vue +5 -1
  5. package/app/components/account/carts/AccountCartsTable.vue +85 -3
  6. package/app/components/account/dashboard/AccountDashboardBudgets.vue +2 -1
  7. package/app/components/account/dashboard/AccountDashboardRecentOrders.vue +2 -1
  8. package/app/components/account/dashboard/AccountDashboardRequisitions.vue +2 -1
  9. package/app/components/account/directorder/AccountDirectOrder.vue +100 -12
  10. package/app/components/account/governance/AccountApprovalLimitsTable.vue +124 -8
  11. package/app/components/account/governance/AccountCostCenterDetail.vue +3 -2
  12. package/app/components/account/governance/AccountCostCentersTable.vue +133 -6
  13. package/app/components/account/governance/AccountRequisitionDetail.vue +2 -1
  14. package/app/components/account/governance/AccountRequisitionsTable.vue +102 -6
  15. package/app/components/account/governance/AccountWorkflowDetail.vue +3 -2
  16. package/app/components/account/governance/AccountWorkflowsTable.vue +76 -1
  17. package/app/components/account/governance/GovernanceApprovalLimitModal.vue +8 -0
  18. package/app/components/account/governance/GovernanceCostCenterModal.vue +7 -0
  19. package/app/components/account/governance/GovernanceWorkflowModal.vue +7 -0
  20. package/app/components/account/orderlists/AccountOrderListDetail.vue +14 -4
  21. package/app/components/account/orderlists/AccountOrderListsTable.vue +115 -7
  22. package/app/components/account/orders/AccountOrderDetail.vue +67 -3
  23. package/app/components/account/orders/AccountOrderPay.vue +211 -0
  24. package/app/components/account/orders/AccountOrdersTable.vue +119 -10
  25. package/app/components/account/organization/AccountOrganization.vue +6 -0
  26. package/app/components/account/profile/AccountPasswordForm.vue +2 -0
  27. package/app/components/account/profile/AccountProfileForm.vue +4 -0
  28. package/app/components/account/quotes/AccountQuoteDetail.vue +7 -10
  29. package/app/components/account/team/AccountTeam.vue +91 -0
  30. package/app/components/auth/AuthLoginTeaser.vue +1 -1
  31. package/app/components/auth/AuthRegisterPanel.vue +22 -3
  32. package/app/components/cart/manage/CartNameModal.vue +4 -0
  33. package/app/components/checkout/onepage/CheckoutAddressSection.vue +5 -1
  34. package/app/components/checkout/onepage/CheckoutGuestDetailsSection.vue +9 -1
  35. package/app/components/checkout/onepage/CheckoutSummarySection.vue +6 -1
  36. package/app/components/form/FormPage.vue +7 -4
  37. package/app/components/layout/footer/Footer.vue +15 -2
  38. package/app/components/layout/header/LocaleSwitcher.vue +79 -12
  39. package/app/components/ui/forms/PasswordInput.vue +2 -0
  40. package/app/components/ui/forms/SearchInput.vue +205 -8
  41. package/app/components/ui/table/TableCardList.vue +69 -0
  42. package/app/components/ui/table/TableSortButton.vue +1 -1
  43. package/app/components/ui/table/TableToolbar.vue +2 -0
  44. package/app/components/withdrawal/WithdrawalDeclaration.vue +286 -0
  45. package/app/composables/useCheckoutOnePage.ts +22 -0
  46. package/app/composables/useMobileTableSort.ts +82 -0
  47. package/app/composables/useProductCard.ts +14 -0
  48. package/app/composables/useProductListing.ts +27 -1
  49. package/app/composables/useSearchEvents.ts +67 -0
  50. package/app/config/forms.ts +8 -0
  51. package/app/config/navigation.ts +8 -0
  52. package/app/formkit.config.ts +21 -0
  53. package/app/interfaces/account/order-list.ts +11 -0
  54. package/app/interfaces/account/quotes.ts +7 -3
  55. package/app/interfaces/market.ts +7 -0
  56. package/app/pages/punchout/transfer.vue +36 -1
  57. package/app/pages/widerruf.vue +33 -0
  58. package/app/plugins/search-events.client.ts +41 -0
  59. package/app/shared/addressLines.ts +66 -0
  60. package/app/shared/checkoutAddressRefusal.ts +63 -0
  61. package/app/shared/locale.ts +133 -0
  62. package/app/shared/searchAttribution.ts +91 -0
  63. package/app/shared/themeEvents.ts +1 -1
  64. package/i18n/locales/de/account.json +13 -1
  65. package/i18n/locales/de/cart.json +1 -0
  66. package/i18n/locales/de/checkout.json +1 -1
  67. package/i18n/locales/de/common.json +7 -0
  68. package/i18n/locales/de/search.json +7 -0
  69. package/i18n/locales/de/withdrawal.json +34 -0
  70. package/i18n/locales/en/account.json +13 -1
  71. package/i18n/locales/en/cart.json +1 -0
  72. package/i18n/locales/en/checkout.json +1 -1
  73. package/i18n/locales/en/common.json +7 -0
  74. package/i18n/locales/en/search.json +7 -0
  75. package/i18n/locales/en/withdrawal.json +34 -0
  76. package/nuxt.config.ts +3 -0
  77. package/package.json +1 -1
  78. package/server/api/account/orders/[id]/pay.post.ts +100 -0
  79. package/server/api/account/orders/[id].get.ts +5 -1
  80. package/server/api/account/quotes/[id]/order.post.ts +22 -22
  81. package/server/api/brands.get.ts +3 -2
  82. package/server/api/categories/[slug]/subcategories.get.ts +9 -6
  83. package/server/api/forms/[slug].get.ts +1 -3
  84. package/server/api/orders/index.post.ts +33 -50
  85. package/server/api/products/index.get.ts +6 -1
  86. package/server/api/punchout/return.post.ts +3 -1
  87. package/server/api/search/events.post.ts +65 -0
  88. package/server/api/typesense/search.post.ts +12 -1
  89. package/server/api/typesense/suggest.post.ts +43 -22
  90. package/server/data/forms/authored.json +69 -8
  91. package/server/dev/errorHandler.ts +47 -0
  92. package/server/interfaces/brand.ts +3 -2
  93. package/server/interfaces/product.ts +5 -0
  94. package/server/interfaces/punchout.ts +5 -0
  95. package/server/middleware/missing-media.ts +35 -0
  96. package/server/middleware/punchout-hand-back-csp.ts +17 -0
  97. package/server/plugins/vue-devtools-sink.ts +28 -0
  98. package/server/services/ApiBrandService.ts +8 -8
  99. package/server/services/ApiMarketService.ts +9 -2
  100. package/server/services/ApiProductService.ts +1 -1
  101. package/server/services/MockFormsService.ts +3 -1
  102. package/server/utils/addressRefusal.ts +63 -0
  103. package/server/utils/country.ts +23 -0
  104. package/server/utils/forms.ts +23 -1
  105. package/server/utils/liveOrders.ts +44 -2
  106. package/server/utils/locale.ts +58 -4
  107. package/server/utils/orderPayment.ts +155 -0
  108. package/server/utils/punchoutFormAction.ts +44 -0
  109. package/server/utils/searchClient.ts +27 -4
  110. package/server/utils/searchEvents.ts +46 -0
  111. package/server/utils/searchMultiSearchFallback.ts +2 -0
  112. package/server/utils/searchSuggest.ts +207 -0
  113. package/server/utils/suggestTiles.ts +141 -0
@@ -34,6 +34,7 @@ function save(): void {
34
34
  <UModal
35
35
  v-model:open="open"
36
36
  :title="mode === 'create' ? t('cart.multi.newCartTitle') : t('cart.multi.renameTitle')"
37
+ :close="{ class: 'max-lg:size-11 max-lg:justify-center' }"
37
38
  >
38
39
  <template #body>
39
40
  <UFormField
@@ -43,6 +44,7 @@ function save(): void {
43
44
  <UInput
44
45
  v-model="name"
45
46
  class="w-full"
47
+ :ui="{ base: 'max-lg:min-h-11' }"
46
48
  :placeholder="t('cart.multi.namePlaceholder')"
47
49
  @keydown.enter="save"
48
50
  />
@@ -53,12 +55,14 @@ function save(): void {
53
55
  color="neutral"
54
56
  variant="ghost"
55
57
  tabindex="0"
58
+ class="max-lg:min-h-11"
56
59
  :label="t('cart.item.cancel')"
57
60
  @click="open = false"
58
61
  />
59
62
  <UButton
60
63
  color="primary"
61
64
  tabindex="0"
65
+ class="max-lg:min-h-11"
62
66
  :disabled="!name.trim()"
63
67
  :label="mode === 'create' ? t('cart.multi.create') : t('cart.multi.rename')"
64
68
  @click="save"
@@ -3,7 +3,7 @@ import CheckoutSectionTitle from "./CheckoutSectionTitle.vue";
3
3
  import CheckoutAddressPickerModal from "../../../components/checkout/onepage/CheckoutAddressPickerModal.vue";
4
4
 
5
5
  const { t } = useI18n();
6
- const { form, profile, profileLoading, fieldErrors } = useCheckoutOnePage();
6
+ const { form, profile, profileLoading, fieldErrors, clearFieldError } = useCheckoutOnePage();
7
7
 
8
8
  const showShippingPicker = ref(false);
9
9
  const showBillingPicker = ref(false);
@@ -16,6 +16,10 @@ const selectedBilling = computed(() =>
16
16
  profile.value?.addresses.find(a => a.id === form.value.billingAddressId),
17
17
  );
18
18
 
19
+ // A refused address (RAD-236) stops being the subject once another is picked.
20
+ watch(() => form.value.shippingAddressId, () => clearFieldError("shippingAddressId"));
21
+ watch(() => form.value.billingAddressId, () => clearFieldError("billingAddressId"));
22
+
19
23
  function changeBilling() {
20
24
  if (form.value.billingSameAsShipping) {
21
25
  form.value.billingSameAsShipping = false;
@@ -9,7 +9,7 @@ import type { CheckoutGuestAddress } from "../../../composables/useCheckoutOnePa
9
9
  */
10
10
  const { t } = useI18n();
11
11
  const {
12
- form, customerType, guestContact, guestShipping, guestBilling, fieldErrors, validateField,
12
+ form, customerType, guestContact, guestShipping, guestBilling, fieldErrors, validateField, clearFieldError,
13
13
  } = useCheckoutOnePage();
14
14
 
15
15
  const isBusiness = computed(() => customerType.value === "guest-business");
@@ -92,21 +92,25 @@ const addressFields: AddressFieldRow[] = [
92
92
  :label="t(field.labelKey)"
93
93
  required
94
94
  :class="field.half ? '' : 'sm:col-span-2'"
95
+ :error="fieldErrors[`guestShipping.${field.key}`]"
95
96
  >
96
97
  <UInput
97
98
  v-model="guestShipping[field.key]"
98
99
  class="w-full"
100
+ @update:model-value="clearFieldError(`guestShipping.${field.key}`)"
99
101
  />
100
102
  </UFormField>
101
103
  </template>
102
104
  <UFormField
103
105
  :label="t('onepage.guest.country')"
104
106
  required
107
+ :error="fieldErrors['guestShipping.country']"
105
108
  >
106
109
  <USelect
107
110
  v-model="guestShipping.country"
108
111
  :items="countryItems"
109
112
  class="w-full"
113
+ @update:model-value="clearFieldError('guestShipping.country')"
110
114
  />
111
115
  </UFormField>
112
116
  </div>
@@ -131,21 +135,25 @@ const addressFields: AddressFieldRow[] = [
131
135
  :label="t(field.labelKey)"
132
136
  required
133
137
  :class="field.half ? '' : 'sm:col-span-2'"
138
+ :error="fieldErrors[`guestBilling.${field.key}`]"
134
139
  >
135
140
  <UInput
136
141
  v-model="guestBilling[field.key]"
137
142
  class="w-full"
143
+ @update:model-value="clearFieldError(`guestBilling.${field.key}`)"
138
144
  />
139
145
  </UFormField>
140
146
  </template>
141
147
  <UFormField
142
148
  :label="t('onepage.guest.country')"
143
149
  required
150
+ :error="fieldErrors['guestBilling.country']"
144
151
  >
145
152
  <USelect
146
153
  v-model="guestBilling.country"
147
154
  :items="countryItems"
148
155
  class="w-full"
156
+ @update:model-value="clearFieldError('guestBilling.country')"
149
157
  />
150
158
  </UFormField>
151
159
  </div>
@@ -2,6 +2,7 @@
2
2
  import CartApprovalsPanel from "../../cart/view/CartApprovalsPanel.vue";
3
3
 
4
4
  const { icon } = useIcons();
5
+ const { getImage } = useProductImage();
5
6
 
6
7
  const { t } = useI18n();
7
8
  const checkout = useCheckoutOnePage();
@@ -83,7 +84,7 @@ async function handlePlaceOrder() {
83
84
  >
84
85
  <img
85
86
  v-if="item.image"
86
- :src="item.image"
87
+ :src="getImage(item.image)"
87
88
  :alt="item.name"
88
89
  class="w-12 h-12 object-cover rounded-md shrink-0 border border-(--ui-border)"
89
90
  >
@@ -172,6 +173,10 @@ async function handlePlaceOrder() {
172
173
  validateField('acceptedTerms')"
173
174
  >
174
175
  <template #label>
176
+ <span
177
+ class="mr-0.5 text-error"
178
+ aria-hidden="true"
179
+ >*</span>
175
180
  <i18n-t keypath="onepage.summary.termsText">
176
181
  <template #link>
177
182
  <a
@@ -32,9 +32,12 @@ useHead({ title: props.title });
32
32
  {{ intro }}
33
33
  </p>
34
34
 
35
- <RevenexxForm
36
- :slug="slug"
37
- :context="context"
38
- />
35
+ <div class="bg-elevated py-6 px-6 sm:px-8 rounded-lg">
36
+ <RevenexxForm
37
+ :slug="slug"
38
+ :context="context"
39
+ cards
40
+ />
41
+ </div>
39
42
  </UContainer>
40
43
  </template>
@@ -1,6 +1,6 @@
1
1
  <script setup lang="ts">
2
2
  import type { ShopContact } from "../../../config/navigation";
3
- import { footerLinks as defaultFooterLinks, legalLinks as defaultLegalLinks, shopContact as noContact } from "../../../config/navigation";
3
+ import { footerLinks as defaultFooterLinks, legalLinks as defaultLegalLinks, shopContact as noContact, withdrawalPath } from "../../../config/navigation";
4
4
 
5
5
  // Consumers replace the footer columns / legal links, in priority order:
6
6
  // per-request live menus (useState, e.g. the Blokkli theme from the pages app)
@@ -15,7 +15,10 @@ const appConfig = useAppConfig();
15
15
  const liveFooterLinks = useState<{ heading: string; links: { label: string; to: string }[] }[] | null>("cover:nav:footerLinks", () => null);
16
16
  const liveLegalLinks = useState<{ label: string; to: string }[] | null>("cover:nav:legalLinks", () => null);
17
17
  const footerLinks = computed(() => liveFooterLinks.value ?? (appConfig.footerLinks as typeof defaultFooterLinks | undefined) ?? defaultFooterLinks);
18
- const legalLinks = computed(() => liveLegalLinks.value ?? (appConfig.legalLinks as typeof defaultLegalLinks | undefined) ?? defaultLegalLinks);
18
+ // The withdrawal entry is rendered on its own below, so a tenant menu that
19
+ // already lists it does not print it twice.
20
+ const legalLinks = computed(() => (liveLegalLinks.value ?? (appConfig.legalLinks as typeof defaultLegalLinks | undefined) ?? defaultLegalLinks)
21
+ .filter(link => link.to !== withdrawalPath));
19
22
  // The shop's own contact details. The design system holds none, so a storefront
20
23
  // that states nothing prints nothing rather than somebody else's address.
21
24
  const shopContact = computed<ShopContact>(() => (appConfig.shopContact as ShopContact | undefined) ?? noContact);
@@ -143,6 +146,16 @@ const year = new Date().getFullYear();
143
146
  >
144
147
  {{ t(link.label) }}
145
148
  </NuxtLink>
149
+ <!-- The withdrawal function (§ 356a BGB) has to be reachable from
150
+ every page, signed in or not, so no tenant menu can drop it. -->
151
+ <NuxtLink
152
+ :to="localePath(withdrawalPath)"
153
+ tabindex="0"
154
+ class="text-xs text-dimmed dark:text-white/70
155
+ hover:text-default dark:hover:text-white transition-colors"
156
+ >
157
+ {{ t('withdrawal.cta') }}
158
+ </NuxtLink>
146
159
  <!-- Reopens the cookie choice (Consent Manager). Renders nothing in
147
160
  the editor, where no banner is shown either. -->
148
161
  <ConsentPreferencesLink
@@ -1,11 +1,16 @@
1
1
  <script setup lang="ts">
2
+ import { marketLanguageOptions } from "../../../shared/locale";
3
+
2
4
  /**
3
5
  * Locale selector (Smashing Magazine, "Designing A Better Language
4
6
  * Selector"): a non-modal popover that decouples language and market.
5
7
  * Markets come from the markets app (live: /v1/markets via the BFF) and
6
8
  * carry region + currency; languages show their native full names (never
7
- * flags or codes) and are limited to the locales the selected market
8
- * offers. The trigger shows the current combination prominently.
9
+ * flags or codes) and are exactly the languages the selected market offers
10
+ * — its default first, a `preparing` locale never (PE-866). A language the
11
+ * shop has no UI strings for is offered too: the catalogue and search answer
12
+ * in it, the pages render in the default UI language. A market without
13
+ * locales offers the shop's UI languages, as before.
9
14
  *
10
15
  * On a product page a language the product has no page in (PE-859 hides
11
16
  * untranslated products) still switches the language, but lands on the
@@ -16,9 +21,13 @@ const { t, locale, locales } = useI18n();
16
21
  const switchLocalePath = useSwitchLocalePath();
17
22
  const localePath = useLocalePath();
18
23
  const { hasPage, fallbackPath } = useProductLocales();
24
+ const runtimeConfig = useRuntimeConfig();
19
25
  const { markets } = useMarkets();
20
26
  const { market, setMarket, region, currencies, currency, currencySymbol, setCurrency } = useLocalePreferences(markets);
21
27
 
28
+ /** The market locale the buyer chose (`de-CH`, `fr-FR`); read by the BFF for catalogue + search. */
29
+ const contentLocale = useCookie<string>("cover-content-locale", { default: () => "", watch: true });
30
+
22
31
  const open = ref(false);
23
32
 
24
33
  const marketItems = computed(() => markets.value.map(entry => ({
@@ -27,20 +36,67 @@ const marketItems = computed(() => markets.value.map(entry => ({
27
36
  active: entry.code === market.value?.code,
28
37
  })));
29
38
 
30
- const languageItems = computed(() => {
31
- const offered = new Set(market.value?.locales.map(entry => entry.language) ?? []);
32
- return locales.value
33
- .filter(entry => offered.size === 0 || offered.has(entry.code))
34
- .map(entry => ({
39
+ const uiLanguages = computed(() => locales.value.map(entry => entry.code));
40
+
41
+ const defaultUiLanguage = computed(() => {
42
+ const i18nConfig = (runtimeConfig.public as { i18n?: { defaultLocale?: string }; defaultLocale?: string });
43
+ return i18nConfig.i18n?.defaultLocale || i18nConfig.defaultLocale || uiLanguages.value[0] || "de";
44
+ });
45
+
46
+ /** The language's own name ("Deutsch", "Français"), for languages without an i18n entry. */
47
+ function nativeLanguageName(language: string): string {
48
+ try {
49
+ const name = new Intl.DisplayNames([language], { type: "language" }).of(language);
50
+ return name ? name.charAt(0).toLocaleUpperCase(language) + name.slice(1) : language;
51
+ }
52
+ catch {
53
+ return language;
54
+ }
55
+ }
56
+
57
+ interface LanguageItem {
58
+ /** What the select reports: the market locale, or the UI language without market locales. */
59
+ code: string;
60
+ name: string;
61
+ to: string;
62
+ /** Market locale to remember, "" when the market has none. */
63
+ contentLocale: string;
64
+ active: boolean;
65
+ /** Whether the open product has a page in this language (always true off a product page). */
66
+ hasPage: boolean;
67
+ }
68
+
69
+ /** Where a UI language leads: the same page, or the product's category when the product has no page there (PE-914). */
70
+ function languageTarget(uiLocale: string): string {
71
+ return hasPage(uiLocale) ? switchLocalePath(uiLocale as typeof locale.value) : localePath(fallbackPath.value, uiLocale as typeof locale.value);
72
+ }
73
+
74
+ const languageItems = computed<LanguageItem[]>(() => {
75
+ const options = marketLanguageOptions(market.value?.locales, uiLanguages.value, defaultUiLanguage.value);
76
+ if (!options) {
77
+ return locales.value.map(entry => ({
35
78
  code: entry.code,
36
79
  /** Native full name ("Deutsch", "English") — never flags or codes. */
37
80
  name: entry.name ?? entry.code,
38
- to: hasPage(entry.code) ? switchLocalePath(entry.code) : localePath(fallbackPath.value, entry.code),
81
+ to: languageTarget(entry.code),
82
+ contentLocale: "",
39
83
  active: entry.code === locale.value,
40
84
  hasPage: hasPage(entry.code),
41
85
  }));
86
+ }
87
+ const chosen = options.find(option => option.locale === contentLocale.value && option.uiLocale === locale.value);
88
+ return options.map(option => ({
89
+ code: option.locale,
90
+ name: locales.value.find(entry => entry.code === option.language)?.name ?? nativeLanguageName(option.language),
91
+ to: languageTarget(option.uiLocale),
92
+ contentLocale: option.locale,
93
+ active: chosen ? option === chosen : option.language === locale.value,
94
+ hasPage: hasPage(option.uiLocale),
95
+ }));
42
96
  });
43
97
 
98
+ const activeLanguageCode = computed(() => languageItems.value.find(item => item.active)?.code ?? locale.value);
99
+
44
100
  /** Languages the open product is missing in, by name — empty off a product page. */
45
101
  const languagesWithoutProduct = computed(() =>
46
102
  languageItems.value.filter(item => !item.hasPage && !item.active).map(item => item.name));
@@ -50,9 +106,17 @@ const currentLanguageName = computed(() =>
50
106
 
51
107
  async function onLanguageChange(code: string): Promise<void> {
52
108
  const target = languageItems.value.find(item => item.code === code);
53
- if (target && !target.active) {
54
- await navigateTo(target.to);
109
+ if (!target || target.active) {
110
+ return;
111
+ }
112
+ contentLocale.value = target.contentLocale;
113
+ if (target.to === useRoute().fullPath) {
114
+ // Same UI language (no UI strings for the target): only the catalogue
115
+ // language changes, so re-render with the new cookie.
116
+ reloadNuxtApp({ ttl: 0 });
117
+ return;
55
118
  }
119
+ await navigateTo(target.to);
56
120
  }
57
121
 
58
122
  const currencyItems = computed(() =>
@@ -60,9 +124,12 @@ const currencyItems = computed(() =>
60
124
 
61
125
  async function onMarketChange(code: string): Promise<void> {
62
126
  setMarket(code);
63
- // The market may not offer the current language — fall back to its first.
127
+ // The market may not offer the current language — fall back to its
128
+ // default (listed first). The remembered locale belongs to the old market.
129
+ contentLocale.value = "";
64
130
  const fallback = languageItems.value[0];
65
131
  if (fallback && !languageItems.value.some(item => item.active)) {
132
+ contentLocale.value = fallback.contentLocale;
66
133
  await navigateTo(fallback.to);
67
134
  }
68
135
  // The market may not trade in the current currency — re-resolve prices.
@@ -125,7 +192,7 @@ const triggerLabel = computed(() =>
125
192
  <!-- Language: native full names within the market's locales -->
126
193
  <UFormField :label="t('topbar.localePanel.language')">
127
194
  <USelect
128
- :model-value="locale"
195
+ :model-value="activeLanguageCode"
129
196
  value-key="code"
130
197
  label-key="name"
131
198
  :items="languageItems"
@@ -74,6 +74,7 @@ const strengthText = computed(() => {
74
74
  :color="showStrength ? color : undefined"
75
75
  :placeholder="placeholder"
76
76
  class="w-full"
77
+ :ui="{ base: 'max-lg:min-h-11 max-lg:pe-12', trailing: 'max-lg:pe-0' }"
77
78
  >
78
79
  <template #trailing>
79
80
  <UTooltip :text="showPassword ? t('auth.password.hide') : t('auth.password.show')">
@@ -81,6 +82,7 @@ const strengthText = computed(() => {
81
82
  color="neutral"
82
83
  variant="link"
83
84
  size="sm"
85
+ class="max-lg:size-11 max-lg:justify-center"
84
86
  :icon="showPassword ? icon('eye-off') : icon('eye')"
85
87
  :aria-label="showPassword ? t('auth.password.hide') : t('auth.password.show')"
86
88
  :aria-pressed="showPassword"
@@ -8,6 +8,8 @@ const { icon } = useIcons();
8
8
 
9
9
  interface Suggestion {
10
10
  id: string;
11
+ /** The record id sent back with the click event. */
12
+ docId?: string;
11
13
  name: string;
12
14
  sku: string;
13
15
  category: string;
@@ -15,6 +17,40 @@ interface Suggestion {
15
17
  subcategorySlug?: string;
16
18
  }
17
19
 
20
+ /** A category of the quick search (PE-867). `to` is a site path without locale. */
21
+ interface CategoryTile {
22
+ docId: string;
23
+ code: string;
24
+ name: string;
25
+ path: string[];
26
+ image: string | null;
27
+ productCount: number;
28
+ to: string;
29
+ }
30
+
31
+ interface ManufacturerTile {
32
+ docId: string;
33
+ code: string;
34
+ name: string;
35
+ logo: string | null;
36
+ productCount: number;
37
+ }
38
+
39
+ interface PageTile {
40
+ docId: string;
41
+ title: string;
42
+ to: string;
43
+ }
44
+
45
+ interface SuggestAnswer {
46
+ suggestions: Suggestion[];
47
+ categories?: CategoryTile[];
48
+ manufacturers?: ManufacturerTile[];
49
+ pages?: PageTile[];
50
+ queryId?: string;
51
+ redirect?: string;
52
+ }
53
+
18
54
  // Optional override for callers that author their own wording (the search_bar
19
55
  // blokkli block lets an editor set one per instance). Unset — the header's two
20
56
  // call sites — keeps the translated default.
@@ -25,6 +61,8 @@ const props = withDefaults(defineProps<{
25
61
  });
26
62
 
27
63
  const { locale, t } = useI18n();
64
+ const localePath = useLocalePath();
65
+ const searchEvents = useSearchEvents();
28
66
 
29
67
  const placeholder = computed(() => props.placeholder || t("search.input.placeholder"));
30
68
 
@@ -37,8 +75,15 @@ const query = ref<string>("");
37
75
  const emit = defineEmits<{ search: [query: string] }>();
38
76
 
39
77
  const suggestions = ref<Suggestion[]>([]);
78
+ const categories = ref<CategoryTile[]>([]);
79
+ const manufacturers = ref<ManufacturerTile[]>([]);
80
+ const pages = ref<PageTile[]>([]);
81
+ // The answer's search id and curated redirect, for the term it answered.
82
+ const answered = ref<{ q: string; queryId: string; redirect?: string } | null>(null);
40
83
  const activeIndex = ref<number>(-1);
41
- const showDropdown = computed(() => suggestions.value.length > 0);
84
+ const showDropdown = computed(() =>
85
+ suggestions.value.length + categories.value.length + manufacturers.value.length + pages.value.length > 0,
86
+ );
42
87
 
43
88
  const containerRef = ref<HTMLElement | null>(null);
44
89
 
@@ -75,29 +120,77 @@ const debouncedFetch = useDebounceFn(fetchSuggestions, 250);
75
120
  watch(query, (val) => {
76
121
  activeIndex.value = -1;
77
122
  if (!val.trim() || val.trim().length < autocompleteMinChars.value) {
78
- suggestions.value = [];
123
+ clearAnswer();
79
124
  return;
80
125
  }
81
126
  void debouncedFetch(val);
82
127
  });
83
128
 
84
129
  async function fetchSuggestions(q: string): Promise<void> {
85
- const data = await $fetch<{ suggestions: Suggestion[] }>(searchApi.suggest(), {
130
+ const data = await $fetch<SuggestAnswer>(searchApi.suggest(), {
86
131
  method: "POST",
87
132
  body: { q },
88
133
  // The BFF filters the index by locale; without it, it guesses from the
89
134
  // cookie or Accept-Language and may suggest the other language.
90
135
  headers: { "x-locale": locale.value },
91
- }).catch(() => ({ suggestions: [] }));
92
- suggestions.value = data.suggestions;
136
+ }).catch((): SuggestAnswer => ({ suggestions: [] }));
137
+ // A slower answer for an older term must not replace the current one.
138
+ if (q !== query.value) {
139
+ return;
140
+ }
141
+ suggestions.value = data.suggestions ?? [];
142
+ categories.value = data.categories ?? [];
143
+ manufacturers.value = data.manufacturers ?? [];
144
+ pages.value = data.pages ?? [];
145
+ answered.value = { q: q.trim(), queryId: data.queryId ?? "", ...(data.redirect ? { redirect: data.redirect } : {}) };
146
+ }
147
+
148
+ function clearAnswer(): void {
149
+ suggestions.value = [];
150
+ categories.value = [];
151
+ manufacturers.value = [];
152
+ pages.value = [];
153
+ answered.value = null;
93
154
  }
94
155
 
95
156
  function close(): void {
96
157
  suggestions.value = [];
158
+ categories.value = [];
159
+ manufacturers.value = [];
160
+ pages.value = [];
97
161
  activeIndex.value = -1;
98
162
  }
99
163
 
164
+ /** Tell the search service which hit or tile was taken (PE-867). */
165
+ function reportClick(collection: string, docId: string | undefined, position: number, sku?: string): void {
166
+ const shown = answered.value;
167
+ if (!shown?.queryId || !docId) {
168
+ return;
169
+ }
170
+ searchEvents.click({ queryId: shown.queryId, q: shown.q, collection, docId, position, ...(sku ? { sku } : {}) });
171
+ }
172
+
173
+ function selectCategory(tile: CategoryTile, index: number): void {
174
+ reportClick("categories", tile.docId, index + 1);
175
+ close();
176
+ void navigateTo(localePath(tile.to));
177
+ }
178
+
179
+ function selectManufacturer(tile: ManufacturerTile, index: number): void {
180
+ reportClick("manufacturers", tile.docId, index + 1);
181
+ close();
182
+ // The brand page is the search filtered to the manufacturer (brand_grid).
183
+ void navigateTo(localePath({ path: "/search", query: { q: tile.name, manufacturer: tile.name } }));
184
+ }
185
+
186
+ function selectPage(tile: PageTile, index: number): void {
187
+ reportClick("pages", tile.docId, index + 1);
188
+ close();
189
+ void navigateTo(localePath(tile.to));
190
+ }
191
+
100
192
  function select(s: Suggestion): void {
193
+ reportClick("products", s.docId ?? s.id, suggestions.value.indexOf(s) + 1, s.sku);
101
194
  query.value = s.name;
102
195
  close();
103
196
  const url = useProductUrl({
@@ -116,11 +209,17 @@ function onEnter(): void {
116
209
 
117
210
  if (activeSuggestion) {
118
211
  select(activeSuggestion);
212
+ return;
119
213
  }
120
- else {
121
- close();
122
- emit("search", query.value);
214
+ // Curation sends this term somewhere else (a category, a landing page):
215
+ // follow it instead of searching, as the search page would.
216
+ const redirect = answered.value?.q === query.value.trim() ? answered.value.redirect : undefined;
217
+ close();
218
+ if (redirect) {
219
+ void navigateTo(/^https?:\/\//i.test(redirect) ? redirect : localePath(redirect), { external: /^https?:\/\//i.test(redirect) });
220
+ return;
123
221
  }
222
+ emit("search", query.value);
124
223
  }
125
224
 
126
225
  function onDown(): void {
@@ -205,6 +304,81 @@ onUnmounted(() => document.removeEventListener("click", handleClickOutside));
205
304
  class="absolute z-50 w-full top-full mt-1 bg-(--ui-bg) border border-(--ui-border)
206
305
  rounded-lg shadow-lg overflow-hidden"
207
306
  >
307
+ <div
308
+ v-if="categories.length || manufacturers.length"
309
+ class="grid gap-2 p-2 border-b border-(--ui-border) sm:grid-cols-2"
310
+ data-testid="search-suggest-tiles"
311
+ >
312
+ <div
313
+ v-if="categories.length"
314
+ class="flex flex-col gap-1"
315
+ >
316
+ <p class="px-1 text-xs font-medium text-(--ui-text-muted)">
317
+ {{ t("search.suggest.categories") }}
318
+ </p>
319
+ <button
320
+ v-for="(tile, i) in categories"
321
+ :key="tile.docId"
322
+ type="button"
323
+ class="flex items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm cursor-pointer
324
+ hover:bg-(--ui-bg-elevated)"
325
+ data-testid="search-suggest-category"
326
+ @click="selectCategory(tile, i)"
327
+ >
328
+ <img
329
+ v-if="tile.image"
330
+ :src="tile.image"
331
+ alt=""
332
+ class="size-8 shrink-0 rounded object-cover"
333
+ >
334
+ <UIcon
335
+ v-else
336
+ :name="icon('folder')"
337
+ class="size-4 shrink-0 text-(--ui-text-muted)"
338
+ />
339
+ <span class="min-w-0 flex-1">
340
+ <span class="block truncate font-medium">{{ tile.name }}</span>
341
+ <span
342
+ v-if="tile.path.length"
343
+ class="block truncate text-xs text-(--ui-text-muted)"
344
+ >{{ tile.path.join(" › ") }}</span>
345
+ </span>
346
+ <span
347
+ v-if="tile.productCount"
348
+ class="shrink-0 text-xs text-(--ui-text-muted)"
349
+ >{{ t("search.suggest.productCount", tile.productCount) }}</span>
350
+ </button>
351
+ </div>
352
+ <div
353
+ v-if="manufacturers.length"
354
+ class="flex flex-col gap-1"
355
+ >
356
+ <p class="px-1 text-xs font-medium text-(--ui-text-muted)">
357
+ {{ t("search.suggest.manufacturers") }}
358
+ </p>
359
+ <button
360
+ v-for="(tile, i) in manufacturers"
361
+ :key="tile.docId"
362
+ type="button"
363
+ class="flex items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm cursor-pointer
364
+ hover:bg-(--ui-bg-elevated)"
365
+ data-testid="search-suggest-manufacturer"
366
+ @click="selectManufacturer(tile, i)"
367
+ >
368
+ <img
369
+ v-if="tile.logo"
370
+ :src="tile.logo"
371
+ :alt="tile.name"
372
+ class="h-6 w-12 shrink-0 object-contain"
373
+ >
374
+ <span class="min-w-0 flex-1 truncate font-medium">{{ tile.name }}</span>
375
+ <span
376
+ v-if="tile.productCount"
377
+ class="shrink-0 text-xs text-(--ui-text-muted)"
378
+ >{{ t("search.suggest.productCount", tile.productCount) }}</span>
379
+ </button>
380
+ </div>
381
+ </div>
208
382
  <button
209
383
  v-for="(s, i) in suggestions"
210
384
  :key="s.id"
@@ -226,6 +400,29 @@ onUnmounted(() => document.removeEventListener("click", handleClickOutside));
226
400
  class="shrink-0"
227
401
  />
228
402
  </button>
403
+ <div
404
+ v-if="pages.length"
405
+ class="border-t border-(--ui-border) p-2"
406
+ >
407
+ <p class="px-1 pb-1 text-xs font-medium text-(--ui-text-muted)">
408
+ {{ t("search.suggest.pages") }}
409
+ </p>
410
+ <button
411
+ v-for="(tile, i) in pages"
412
+ :key="tile.docId"
413
+ type="button"
414
+ class="w-full flex items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm cursor-pointer
415
+ hover:bg-(--ui-bg-elevated)"
416
+ data-testid="search-suggest-page"
417
+ @click="selectPage(tile, i)"
418
+ >
419
+ <UIcon
420
+ :name="icon('file')"
421
+ class="size-4 shrink-0 text-(--ui-text-muted)"
422
+ />
423
+ <span class="truncate">{{ tile.title }}</span>
424
+ </button>
425
+ </div>
229
426
  </div>
230
427
  </div>
231
428
  </template>