@shopbite-de/storefront 1.31.3 → 2.0.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 (185) hide show
  1. package/.github/workflows/ci.yaml +54 -0
  2. package/CLAUDE.md +23 -8
  3. package/app/app.vue +10 -6
  4. package/app/assets/css/main.css +100 -61
  5. package/app/components/AddToWishlist.vue +15 -25
  6. package/app/components/Address/Card.vue +6 -11
  7. package/app/components/Address/Detail.vue +23 -23
  8. package/app/components/Address/Fields.vue +175 -73
  9. package/app/components/Address/Form.vue +107 -106
  10. package/app/components/Cart/Bar.vue +6 -9
  11. package/app/components/Cart/Item.vue +48 -63
  12. package/app/components/Cart/QuickView.vue +38 -25
  13. package/app/components/Cart/Upsell.vue +24 -62
  14. package/app/components/Category/Breadcrumb.vue +29 -3
  15. package/app/components/Category/FilterGroup.vue +20 -41
  16. package/app/components/Category/Listing.vue +100 -130
  17. package/app/components/Category/SearchInput.vue +22 -19
  18. package/app/components/Checkout/DeliveryTimeSelect.vue +55 -77
  19. package/app/components/Checkout/LoginOrRegister.vue +28 -29
  20. package/app/components/Checkout/PaymentAndDelivery.vue +114 -86
  21. package/app/components/Checkout/Summary.vue +90 -60
  22. package/app/components/Checkout/VoucherInput.vue +40 -27
  23. package/app/components/Contact/Form.vue +164 -192
  24. package/app/components/DemoBanner.vue +5 -5
  25. package/app/components/Footer/StoreStatus.vue +2 -2
  26. package/app/components/Footer.vue +125 -57
  27. package/app/components/Header.vue +283 -18
  28. package/app/components/Home/Categories.vue +116 -0
  29. package/app/components/Home/Facts.vue +71 -0
  30. package/app/components/Home/Faq.vue +34 -16
  31. package/app/components/Home/Hero.vue +172 -0
  32. package/app/components/Home/Highlights.vue +29 -37
  33. package/app/components/Home/Restaurant.vue +102 -0
  34. package/app/components/Menu/BonCard.vue +180 -0
  35. package/app/components/Menu/CartPanel.vue +24 -0
  36. package/app/components/Menu/CategoryIndex.vue +54 -0
  37. package/app/components/Menu/OrderMode.vue +20 -0
  38. package/app/components/Menu/SectionHeader.vue +38 -0
  39. package/app/components/Navigation/MobileTop.vue +23 -15
  40. package/app/components/Order/Confirmation.vue +119 -0
  41. package/app/components/Order/Detail.vue +80 -88
  42. package/app/components/Product/CardSkeleton.vue +8 -12
  43. package/app/components/Product/Configurator.vue +8 -16
  44. package/app/components/Product/CrossSelling.vue +75 -83
  45. package/app/components/Product/DeselectIngredient.vue +17 -22
  46. package/app/components/Product/Detail.vue +35 -27
  47. package/app/components/Product/QuickView.vue +80 -51
  48. package/app/components/SalesChannelSwitch.vue +14 -28
  49. package/app/components/Sb/Button.vue +70 -0
  50. package/app/components/Sb/Checkbox.vue +73 -0
  51. package/app/components/Sb/Chip.vue +51 -0
  52. package/app/components/Sb/ChoiceGroup.vue +82 -0
  53. package/app/components/Sb/ConfirmDialog.vue +60 -0
  54. package/app/components/Sb/Field.vue +77 -0
  55. package/app/components/Sb/Icon.vue +66 -0
  56. package/app/components/Sb/IconButton.vue +55 -0
  57. package/app/components/Sb/Input.vue +23 -0
  58. package/app/components/Sb/SegmentedControl.vue +34 -0
  59. package/app/components/Sb/Select.vue +49 -0
  60. package/app/components/Sb/Sheet.vue +83 -0
  61. package/app/components/Sb/Stars.vue +60 -0
  62. package/app/components/Sb/StatusPill.vue +38 -0
  63. package/app/components/Sb/Stepper.vue +72 -0
  64. package/app/components/User/AccountHeader.vue +16 -0
  65. package/app/components/User/AuthPanel.vue +41 -0
  66. package/app/components/User/Detail.vue +32 -29
  67. package/app/components/User/LoginForm.vue +92 -98
  68. package/app/components/User/RegistrationForm.vue +285 -249
  69. package/app/components/Wishlist.vue +55 -155
  70. package/app/composables/useCartMutations.ts +9 -27
  71. package/app/composables/useCheckoutMethodGuard.ts +2 -24
  72. package/app/composables/useContactForm.ts +66 -0
  73. package/app/composables/useHomeMenuCategories.ts +41 -0
  74. package/app/composables/useNavigation.ts +10 -2
  75. package/app/composables/useOrderMode.ts +65 -0
  76. package/app/composables/useRegistrationForm.ts +161 -0
  77. package/app/composables/useRestaurantSchema.ts +1 -1
  78. package/app/composables/useShareLink.ts +3 -13
  79. package/app/composables/useSortingSelection.ts +13 -0
  80. package/app/composables/useThemePreset.ts +15 -0
  81. package/app/composables/useVoucherCode.ts +7 -16
  82. package/app/composables/useWishlistActions.ts +0 -51
  83. package/app/error.vue +31 -9
  84. package/app/layouts/account.vue +45 -50
  85. package/app/layouts/default.vue +2 -3
  86. package/app/layouts/listing.vue +3 -5
  87. package/app/pages/[...all].vue +8 -4
  88. package/app/pages/account/recover/password/index.vue +113 -80
  89. package/app/pages/anmelden.vue +11 -10
  90. package/app/pages/bestellung/[id]/erfolg.vue +1 -15
  91. package/app/pages/bestellung/[id]/fehler.vue +63 -51
  92. package/app/pages/bestellung/[id]/index.vue +3 -85
  93. package/app/pages/bestellung/kasse.vue +29 -0
  94. package/app/pages/bestellung.vue +8 -60
  95. package/app/pages/index.vue +12 -52
  96. package/app/pages/kontakt.vue +27 -7
  97. package/app/pages/konto/adressen.vue +106 -102
  98. package/app/pages/konto/bestellung/[id].vue +9 -43
  99. package/app/pages/konto/bestellungen.vue +55 -33
  100. package/app/pages/konto/index.vue +47 -62
  101. package/app/pages/konto/profil.vue +162 -100
  102. package/app/pages/maintenance.vue +8 -6
  103. package/app/pages/merkliste.vue +7 -8
  104. package/app/pages/passwort-vergessen.vue +92 -75
  105. package/app/pages/registrierung/bestaetigen.vue +20 -48
  106. package/app/pages/registrierung/index.vue +16 -7
  107. package/app/pages/suche.vue +94 -95
  108. package/app/plugins/theme-preset.ts +9 -0
  109. package/app/utils/highlight.ts +25 -0
  110. package/app/utils/product.ts +9 -0
  111. package/app/validation/registrationSchema.ts +1 -1
  112. package/modules/theme.ts +115 -0
  113. package/nuxt.config.ts +27 -15
  114. package/package.json +6 -8
  115. package/playwright.config.ts +11 -0
  116. package/server/api/listing/[categoryId].get.ts +3 -0
  117. package/shared/theme/presets.ts +303 -0
  118. package/test/a11y/presets.test.ts +225 -0
  119. package/test/nuxt/AccountPagesPreset.test.ts +191 -0
  120. package/test/nuxt/AuthPagesPreset.test.ts +87 -0
  121. package/test/nuxt/CartCheckoutPreset.test.ts +154 -0
  122. package/test/nuxt/CartItem.test.ts +18 -3
  123. package/test/nuxt/CartUpsell.test.ts +1 -2
  124. package/test/nuxt/CheckoutFormsPreset.test.ts +120 -0
  125. package/test/nuxt/CheckoutOnePage.test.ts +115 -0
  126. package/test/nuxt/CheckoutSummary.test.ts +6 -6
  127. package/test/nuxt/CheckoutVoucherInput.test.ts +20 -32
  128. package/test/nuxt/ContactFormPreset.test.ts +115 -0
  129. package/test/nuxt/FooterStoreStatus.test.ts +2 -2
  130. package/test/nuxt/HeaderFooterPreset.test.ts +134 -0
  131. package/test/nuxt/HomeFaq.test.ts +3 -2
  132. package/test/nuxt/MenuBonCard.test.ts +122 -0
  133. package/test/nuxt/OrderPagesPreset.test.ts +132 -0
  134. package/test/nuxt/PaymentAndDelivery.test.ts +0 -4
  135. package/test/nuxt/ProductCrossSelling.test.ts +2 -1
  136. package/test/nuxt/ProductDeselectIngredient.test.ts +5 -3
  137. package/test/nuxt/ProductSheetPreset.test.ts +105 -0
  138. package/test/nuxt/RegisterConfirmPage.test.ts +0 -8
  139. package/test/nuxt/RegistrationForm.test.ts +89 -270
  140. package/test/nuxt/SbBaseComponents.test.ts +170 -0
  141. package/test/nuxt/SbStars.test.ts +25 -0
  142. package/test/nuxt/useCartMutations.test.ts +3 -17
  143. package/test/nuxt/useCartUpsell.test.ts +1 -1
  144. package/test/nuxt/useCheckoutMethodGuard.test.ts +0 -27
  145. package/test/nuxt/useShareLink.test.ts +1 -9
  146. package/test/nuxt/useWishlistActions.test.ts +3 -26
  147. package/test/unit/highlight.spec.ts +31 -0
  148. package/test/unit/product.spec.ts +12 -0
  149. package/test/unit/themePresets.spec.ts +61 -0
  150. package/app/app.config.ts +0 -19
  151. package/app/components/AnimatedSection.vue +0 -74
  152. package/app/components/BottomNavi.vue +0 -70
  153. package/app/components/Category/Header.vue +0 -48
  154. package/app/components/Checkout/PaymentMethod.vue +0 -30
  155. package/app/components/Checkout/ShippingMethod.vue +0 -30
  156. package/app/components/Cta.vue +0 -30
  157. package/app/components/Feature/Card.vue +0 -121
  158. package/app/components/Features.vue +0 -42
  159. package/app/components/Footer/Contact.vue +0 -82
  160. package/app/components/Header/Body.vue +0 -82
  161. package/app/components/Header/Right.vue +0 -187
  162. package/app/components/Header/Title.vue +0 -10
  163. package/app/components/Hero.vue +0 -233
  164. package/app/components/Home/MenuCategories.vue +0 -148
  165. package/app/components/ImageGallery.vue +0 -63
  166. package/app/components/Loading.vue +0 -29
  167. package/app/components/Navigation/DesktopLeft.vue +0 -39
  168. package/app/components/Product/Card.vue +0 -177
  169. package/app/components/Product/CardCompact.vue +0 -72
  170. package/app/components/Product/CardDietBadges.vue +0 -43
  171. package/app/components/Product/CardIngredients.vue +0 -35
  172. package/app/components/Product/CardKitchen.vue +0 -34
  173. package/app/components/Product/SearchBar.vue +0 -95
  174. package/app/components/PublicAnnouncement.vue +0 -17
  175. package/app/pages/bestellung/bestaetigen.vue +0 -16
  176. package/app/pages/bestellung/warenkorb.vue +0 -49
  177. package/app/pages/bestellung/zahlung-versand.vue +0 -25
  178. package/test/nuxt/AddressFields.test.ts +0 -222
  179. package/test/nuxt/AnimatedSection.test.ts +0 -67
  180. package/test/nuxt/ContactForm.test.ts +0 -207
  181. package/test/nuxt/FooterContact.test.ts +0 -102
  182. package/test/nuxt/HeaderRight.test.ts +0 -142
  183. package/test/nuxt/Hero.test.ts +0 -126
  184. package/test/nuxt/HomeMenuCategories.test.ts +0 -94
  185. package/test/nuxt/LoginForm.test.ts +0 -159
@@ -1,16 +1,22 @@
1
1
  <script setup lang="ts">
2
2
  import type { AddressSchema } from "~/validation/registrationSchema";
3
3
 
4
+ /**
5
+ * Address fields of the presets (#443): the same model, autocomplete
6
+ * check and correction as Address/Fields.vue, with the base components.
7
+ * `errors` maps "<prefix>.<field>" to the message of the failed check;
8
+ * every input carries its `autocomplete` token, so browsers can fill it.
9
+ */
4
10
  const model = defineModel<AddressSchema>({ required: true });
5
11
 
6
- defineProps<{
12
+ const props = defineProps<{
7
13
  prefix: string;
8
14
  accountType?: string;
9
15
  showNames?: boolean;
16
+ errors?: Record<string, string>;
10
17
  }>();
11
18
 
12
19
  const { getSuggestions } = useAddressAutocomplete();
13
-
14
20
  const {
15
21
  showCorrection,
16
22
  correction,
@@ -19,93 +25,189 @@ const {
19
25
  applyCorrection,
20
26
  } = useAddressValidation(model, { getSuggestions });
21
27
 
22
- defineExpose({
23
- checkAddress,
24
- flushPendingCheck,
25
- showCorrection,
26
- });
28
+ defineExpose({ checkAddress, flushPendingCheck, showCorrection });
29
+
30
+ // The address group for autocomplete: "shipping" or "billing".
31
+ const section = computed(() =>
32
+ props.prefix === "shippingAddress" ? "shipping" : "billing",
33
+ );
34
+ const fieldId = (name: string) => `${props.prefix}-${name}`;
35
+ const error = (name: string) => props.errors?.[`${props.prefix}.${name}`];
27
36
  </script>
28
37
 
29
38
  <template>
30
- <div class="space-y-4">
31
- <UFormField
32
- v-if="accountType === 'business'"
33
- label="Unternehmen"
34
- :name="`${prefix}.company`"
35
- >
36
- <UInput v-model="model.company" type="text" class="w-full" />
37
- </UFormField>
38
-
39
- <UFormField
40
- v-if="accountType === 'business'"
41
- label="Abteilung"
42
- :name="`${prefix}.department`"
43
- >
44
- <UInput v-model="model.department" type="text" class="w-full" />
45
- </UFormField>
39
+ <div class="grid grid-cols-1 gap-4 sm:grid-cols-6">
40
+ <template v-if="accountType === 'business'">
41
+ <SbField
42
+ :id="fieldId('company')"
43
+ v-slot="{ id, describedBy, invalid }"
44
+ label="Unternehmen"
45
+ :error="error('company')"
46
+ class="sm:col-span-3"
47
+ >
48
+ <SbInput
49
+ :id="id"
50
+ v-model="model.company"
51
+ :name="`${prefix}.company`"
52
+ :autocomplete="`${section} organization`"
53
+ :aria-describedby="describedBy"
54
+ :invalid="invalid"
55
+ />
56
+ </SbField>
57
+ <SbField
58
+ :id="fieldId('department')"
59
+ v-slot="{ id, describedBy, invalid }"
60
+ label="Abteilung"
61
+ optional
62
+ :error="error('department')"
63
+ class="sm:col-span-3"
64
+ >
65
+ <SbInput
66
+ :id="id"
67
+ v-model="model.department"
68
+ :name="`${prefix}.department`"
69
+ :aria-describedby="describedBy"
70
+ :invalid="invalid"
71
+ />
72
+ </SbField>
73
+ </template>
46
74
 
47
- <div v-if="showNames" class="flex flex-row justify-between gap-4">
48
- <UFormField
75
+ <template v-if="showNames">
76
+ <SbField
77
+ :id="fieldId('firstName')"
78
+ v-slot="{ id, describedBy, invalid }"
49
79
  label="Vorname"
50
- :name="`${prefix}.firstName`"
51
- required
52
- class="w-full"
80
+ :error="error('firstName')"
81
+ class="sm:col-span-3"
53
82
  >
54
- <UInput v-model="model.firstName" type="text" class="w-full" />
55
- </UFormField>
56
-
57
- <UFormField
83
+ <SbInput
84
+ :id="id"
85
+ v-model="model.firstName"
86
+ :name="`${prefix}.firstName`"
87
+ :autocomplete="`${section} given-name`"
88
+ :aria-describedby="describedBy"
89
+ :invalid="invalid"
90
+ />
91
+ </SbField>
92
+ <SbField
93
+ :id="fieldId('lastName')"
94
+ v-slot="{ id, describedBy, invalid }"
58
95
  label="Nachname"
59
- :name="`${prefix}.lastName`"
60
- required
61
- class="w-full"
96
+ :error="error('lastName')"
97
+ class="sm:col-span-3"
62
98
  >
63
- <UInput v-model="model.lastName" type="text" class="w-full" />
64
- </UFormField>
65
- </div>
66
-
67
- <UFormField label="Straße und Hausnr." :name="`${prefix}.street`" required>
68
- <UInput v-model="model.street" type="text" class="w-full" />
69
- </UFormField>
99
+ <SbInput
100
+ :id="id"
101
+ v-model="model.lastName"
102
+ :name="`${prefix}.lastName`"
103
+ :autocomplete="`${section} family-name`"
104
+ :aria-describedby="describedBy"
105
+ :invalid="invalid"
106
+ />
107
+ </SbField>
108
+ </template>
70
109
 
71
- <div class="flex flex-row gap-4">
72
- <UFormField label="PLZ" :name="`${prefix}.zipcode`" class="w-24">
73
- <UInput v-model="model.zipcode" type="text" class="w-full" />
74
- </UFormField>
75
-
76
- <UFormField label="Ort" :name="`${prefix}.city`" required class="flex-1">
77
- <UInput v-model="model.city" type="text" class="w-full" />
78
- </UFormField>
79
- </div>
110
+ <SbField
111
+ :id="fieldId('street')"
112
+ v-slot="{ id, describedBy, invalid }"
113
+ label="Straße und Hausnummer"
114
+ :error="error('street')"
115
+ class="sm:col-span-6"
116
+ >
117
+ <SbInput
118
+ :id="id"
119
+ v-model="model.street"
120
+ :name="`${prefix}.street`"
121
+ :autocomplete="`${section} address-line1`"
122
+ :aria-describedby="describedBy"
123
+ :invalid="invalid"
124
+ />
125
+ </SbField>
80
126
 
81
- <div v-if="showCorrection" class="flex flex-col items-center gap-2">
82
- <UAlert
83
- color="info"
84
- variant="soft"
85
- icon="i-lucide-info"
86
- :title="`Meinten Sie: ${correction?.label}?`"
87
- class="flex-1"
127
+ <SbField
128
+ :id="fieldId('zipcode')"
129
+ v-slot="{ id, describedBy, invalid }"
130
+ label="PLZ"
131
+ :error="error('zipcode')"
132
+ class="sm:col-span-2"
133
+ >
134
+ <SbInput
135
+ :id="id"
136
+ v-model="model.zipcode"
137
+ :name="`${prefix}.zipcode`"
138
+ inputmode="numeric"
139
+ :autocomplete="`${section} postal-code`"
140
+ :aria-describedby="describedBy"
141
+ :invalid="invalid"
88
142
  />
89
- <UButton
90
- label="Korrigieren"
91
- color="info"
92
- variant="solid"
93
- size="sm"
94
- block
95
- @click="applyCorrection"
143
+ </SbField>
144
+ <SbField
145
+ :id="fieldId('city')"
146
+ v-slot="{ id, describedBy, invalid }"
147
+ label="Ort"
148
+ :error="error('city')"
149
+ class="sm:col-span-4"
150
+ >
151
+ <SbInput
152
+ :id="id"
153
+ v-model="model.city"
154
+ :name="`${prefix}.city`"
155
+ :autocomplete="`${section} address-level2`"
156
+ :aria-describedby="describedBy"
157
+ :invalid="invalid"
96
158
  />
159
+ </SbField>
160
+
161
+ <div
162
+ v-if="showCorrection"
163
+ role="status"
164
+ class="flex flex-col gap-3 rounded-sb-control bg-sb-primary-tint p-4 font-body text-sb-ink sm:col-span-6 sm:flex-row sm:items-center sm:justify-between"
165
+ >
166
+ <span>
167
+ Meinten Sie: <strong>{{ correction?.label }}</strong
168
+ >?
169
+ </span>
170
+ <SbButton variant="secondary" @click="applyCorrection"
171
+ >Übernehmen</SbButton
172
+ >
97
173
  </div>
98
174
 
99
- <UFormField label="Adresszusatz" :name="`${prefix}.additionalAddressLine1`">
100
- <UInput
175
+ <SbField
176
+ :id="fieldId('additionalAddressLine1')"
177
+ v-slot="{ id, describedBy, invalid }"
178
+ label="Adresszusatz"
179
+ hint="z. B. Hinterhaus, 2. Stock, Name am Klingelschild"
180
+ optional
181
+ :error="error('additionalAddressLine1')"
182
+ class="sm:col-span-6"
183
+ >
184
+ <SbInput
185
+ :id="id"
101
186
  v-model="model.additionalAddressLine1"
102
- type="text"
103
- class="w-full"
187
+ :name="`${prefix}.additionalAddressLine1`"
188
+ :autocomplete="`${section} address-line2`"
189
+ :aria-describedby="describedBy"
190
+ :invalid="invalid"
104
191
  />
105
- </UFormField>
192
+ </SbField>
106
193
 
107
- <UFormField label="Telefon" :name="`${prefix}.phoneNumber`" required>
108
- <UInput v-model="model.phoneNumber" type="text" class="w-full" />
109
- </UFormField>
194
+ <SbField
195
+ :id="fieldId('phoneNumber')"
196
+ v-slot="{ id, describedBy, invalid }"
197
+ label="Telefon"
198
+ hint="Nur für Rückfragen zur Bestellung"
199
+ :error="error('phoneNumber')"
200
+ class="sm:col-span-6"
201
+ >
202
+ <SbInput
203
+ :id="id"
204
+ v-model="model.phoneNumber"
205
+ :name="`${prefix}.phoneNumber`"
206
+ type="tel"
207
+ :autocomplete="`${section} tel`"
208
+ :aria-describedby="describedBy"
209
+ :invalid="invalid"
210
+ />
211
+ </SbField>
110
212
  </div>
111
213
  </template>
@@ -1,128 +1,129 @@
1
1
  <script setup lang="ts">
2
+ import * as z from "zod";
2
3
  import type { Schemas } from "#shopware";
3
4
  import { useAddress } from "@shopware/composables";
4
- import type { FormSubmitEvent } from "@nuxt/ui";
5
-
6
- import { createAddressSchema } from "~/validation/addressSchema";
7
- import type { AddressSchema } from "~/validation/addressSchema";
8
-
5
+ import {
6
+ baseAddressSchema,
7
+ type AddressSchema,
8
+ } from "~/validation/registrationSchema";
9
+
10
+ /**
11
+ * Create or edit a customer address in the presets (#445): the address
12
+ * fields of the checkout (`AddressFields`), checked with the same
13
+ * rules on submit. Errors show at the fields, the first one gets focus.
14
+ */
9
15
  const props = defineProps<{
10
- address?: Schemas["CustomerAddress"] | undefined;
16
+ address?: Schemas["CustomerAddress"];
11
17
  }>();
12
18
 
13
- const config = useRuntimeConfig();
19
+ const emit = defineEmits<{
20
+ "submit-success": [data: Schemas["CustomerAddress"]];
21
+ }>();
22
+
23
+ const { site } = useRuntimeConfig().public;
14
24
  const { updateCustomerAddress, createCustomerAddress } = useAddress();
15
25
 
16
- const state = reactive({
17
- id: props.address?.id,
18
- firstName: props.address?.firstName ?? undefined,
19
- lastName: props.address?.lastName ?? undefined,
20
- company: props.address?.company ?? undefined,
21
- department: props.address?.department ?? undefined,
22
- additionalAddressLine1: props.address?.additionalAddressLine1 ?? undefined,
23
- phoneNumber: props.address?.phoneNumber ?? undefined,
24
- street: props.address?.street ?? undefined,
25
- zipcode: props.address?.zipcode ?? undefined,
26
- city: props.address?.city ?? undefined,
27
- countryId: config.public.site.countryId,
26
+ const isBusiness = ref(Boolean(props.address?.company));
27
+ const model = ref<AddressSchema>({
28
+ firstName: props.address?.firstName ?? "",
29
+ lastName: props.address?.lastName ?? "",
30
+ company: props.address?.company ?? "",
31
+ department: props.address?.department ?? "",
32
+ street: props.address?.street ?? "",
33
+ additionalAddressLine1: props.address?.additionalAddressLine1 ?? "",
34
+ zipcode: props.address?.zipcode ?? "",
35
+ city: props.address?.city ?? "",
36
+ countryId: props.address?.countryId ?? site.countryId,
37
+ phoneNumber: props.address?.phoneNumber ?? "",
28
38
  });
29
39
 
30
- const schema = computed(() => createAddressSchema(state));
31
-
32
- const toast = useToast();
33
-
34
- async function onSubmit(event: FormSubmitEvent<AddressSchema>) {
35
- try {
36
- let response: undefined | Schemas["CustomerAddress"] = undefined;
37
- const addressData = event.data as unknown as Parameters<
38
- typeof updateCustomerAddress
39
- >[0];
40
- if (event.data.id) {
41
- response = await updateCustomerAddress(addressData);
42
- } else {
43
- response = await createCustomerAddress(addressData);
40
+ const schema = computed(() =>
41
+ baseAddressSchema
42
+ .extend({
43
+ firstName: z
44
+ .string()
45
+ .min(1, { message: "Bitte geben Sie den Vornamen an." }),
46
+ lastName: z
47
+ .string()
48
+ .min(1, { message: "Bitte geben Sie den Nachnamen an." }),
49
+ zipcode: z
50
+ .string()
51
+ .min(1, { message: "Bitte geben Sie die Postleitzahl an." }),
52
+ })
53
+ .refine((data) => !isBusiness.value || Boolean(data.company), {
54
+ message: "Bitte geben Sie den Firmennamen an.",
55
+ path: ["company"],
56
+ }),
57
+ );
58
+
59
+ const PREFIX = "shippingAddress";
60
+ const errors = ref<Record<string, string>>({});
61
+ const saveError = ref(false);
62
+ const saving = ref(false);
63
+ const form = ref<HTMLFormElement | null>(null);
64
+
65
+ async function onSubmit() {
66
+ saveError.value = false;
67
+ const result = schema.value.safeParse(model.value);
68
+ if (!result.success) {
69
+ const next: Record<string, string> = {};
70
+ for (const issue of result.error.issues) {
71
+ const key = `${PREFIX}.${issue.path.join(".")}`;
72
+ next[key] ??= issue.message;
44
73
  }
45
-
46
- toast.add({
47
- title: "Erfolgreich gespeichert",
48
- color: "success",
49
- });
50
- emit("submit-success", response);
74
+ errors.value = next;
75
+ await nextTick();
76
+ form.value?.querySelector<HTMLElement>('[aria-invalid="true"]')?.focus();
77
+ return;
78
+ }
79
+ errors.value = {};
80
+ saving.value = true;
81
+ try {
82
+ const data = {
83
+ ...result.data,
84
+ company: isBusiness.value ? result.data.company : "",
85
+ department: isBusiness.value ? result.data.department : "",
86
+ } as unknown as Parameters<typeof updateCustomerAddress>[0];
87
+ const saved = props.address?.id
88
+ ? await updateCustomerAddress({ ...data, id: props.address.id })
89
+ : await createCustomerAddress(data);
90
+ emit("submit-success", saved);
51
91
  } catch (error) {
52
92
  console.error("Address save failed:", error);
53
- toast.add({
54
- title: "Speichern fehlgeschlagen",
55
- description: "Bitte versuchen Sie es erneut.",
56
- color: "error",
57
- });
93
+ saveError.value = true;
94
+ } finally {
95
+ saving.value = false;
58
96
  }
59
97
  }
60
-
61
- const accountType = ref("privat");
62
-
63
- const emit = defineEmits<{
64
- "submit-success": [data: Schemas["CustomerAddress"]];
65
- }>();
66
98
  </script>
67
99
 
68
100
  <template>
69
- <UForm
70
- :schema="schema"
71
- :state="state"
72
- class="space-y-4"
73
- @submit="onSubmit"
74
- @error="(error) => console.log('Form validation error:', error)"
101
+ <form
102
+ ref="form"
103
+ novalidate
104
+ class="flex flex-col gap-4 font-body text-sb-ink"
105
+ @submit.prevent="onSubmit"
75
106
  >
76
- <UInput v-model="state.id" type="text" hidden />
77
-
78
- <UFormField label="Vorname" name="firstName">
79
- <UInput v-model="state.firstName" type="text" class="w-full" />
80
- </UFormField>
81
-
82
- <UFormField label="Nachname" name="lastName">
83
- <UInput v-model="state.lastName" type="text" class="w-full" />
84
- </UFormField>
85
-
86
- <UFormField
87
- v-if="accountType === 'commercial'"
88
- label="Unternehmen"
89
- name="company"
107
+ <div
108
+ v-if="saveError"
109
+ role="alert"
110
+ class="rounded-sb-control border-[1.5px] border-sb-danger p-4 text-sm"
90
111
  >
91
- <UInput v-model="state.company" type="text" class="w-full" />
92
- </UFormField>
93
-
94
- <UFormField
95
- v-if="accountType === 'commercial'"
96
- label="Abteilung"
97
- name="department"
112
+ <strong class="block"
113
+ >Die Adresse konnte nicht gespeichert werden.</strong
114
+ >
115
+ Bitte versuchen Sie es noch einmal.
116
+ </div>
117
+ <SbCheckbox v-model="isBusiness" label="Firmenadresse" plain />
118
+ <AddressFields
119
+ v-model="model"
120
+ :prefix="PREFIX"
121
+ :account-type="isBusiness ? 'business' : 'private'"
122
+ show-names
123
+ :errors="errors"
124
+ />
125
+ <SbButton type="submit" size="lg" block :loading="saving"
126
+ >Adresse speichern</SbButton
98
127
  >
99
- <UInput v-model="state.department" type="text" class="w-full" />
100
- </UFormField>
101
-
102
- <UFormField label="Straße und Hausnr." name="street">
103
- <UInput v-model="state.street" type="text" class="w-full" />
104
- </UFormField>
105
-
106
- <UFormField label="Zusatz" name="additionalAddressLine1">
107
- <UInput
108
- v-model="state.additionalAddressLine1"
109
- type="text"
110
- class="w-full"
111
- />
112
- </UFormField>
113
-
114
- <UFormField label="Postleitzahl" name="zipcode">
115
- <UInput v-model="state.zipcode" type="text" class="w-full" />
116
- </UFormField>
117
-
118
- <UFormField label="Ort" name="city">
119
- <UInput v-model="state.city" type="text" class="w-full" />
120
- </UFormField>
121
-
122
- <UFormField label="Telefon" name="phoneNumber">
123
- <UInput v-model="state.phoneNumber" type="phone" class="w-full" />
124
- </UFormField>
125
-
126
- <UButton type="submit" block label="Speichern" />
127
- </UForm>
128
+ </form>
128
129
  </template>
@@ -59,14 +59,14 @@ onBeforeUnmount(() => clearTimeout(addedTimer));
59
59
  <button
60
60
  :key="popKey"
61
61
  type="button"
62
- class="flex h-14 w-full items-center gap-3 rounded-xl bg-primary px-4 text-inverted shadow-lg transition-colors hover:bg-primary/90 active:bg-primary/90 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary"
62
+ class="flex h-14 w-full items-center gap-3 rounded-sb-card bg-sb-primary px-4 font-body text-sb-on-primary shadow-lg transition-colors hover:bg-sb-primary-hover focus-visible:outline-3 focus-visible:outline-offset-2 focus-visible:outline-sb-focus"
63
63
  :class="{ 'motion-safe:animate-cart-pop': popKey > 0 }"
64
64
  aria-haspopup="dialog"
65
65
  aria-live="polite"
66
66
  data-testid="cart-bar"
67
67
  @click="show"
68
68
  >
69
- <UIcon name="i-lucide-shopping-bag" class="size-6 shrink-0" />
69
+ <SbIcon name="bag" :size="24" />
70
70
  <span class="flex min-w-0 flex-1 items-baseline gap-2 text-left">
71
71
  <Transition
72
72
  mode="out-in"
@@ -80,22 +80,19 @@ onBeforeUnmount(() => clearTimeout(addedTimer));
80
80
  key="added"
81
81
  class="flex min-w-0 items-baseline gap-2"
82
82
  >
83
- <UIcon
84
- name="i-lucide-check"
85
- class="size-4 shrink-0 self-center"
86
- />
83
+ <SbIcon name="check" :size="16" class="self-center" />
87
84
  <span class="truncate font-semibold">{{ addedLabel }}</span>
88
- <span class="shrink-0 text-sm opacity-90">hinzugefügt</span>
85
+ <span class="shrink-0 text-sm">hinzugefügt</span>
89
86
  </span>
90
87
  <span v-else key="cart" class="flex min-w-0 items-baseline gap-2">
91
88
  <span class="font-semibold">Warenkorb</span>
92
- <span class="truncate text-sm opacity-90">
89
+ <span class="truncate text-sm">
93
90
  {{ itemsLabel }} · {{ getFormattedPrice(subtotal) }}
94
91
  </span>
95
92
  </span>
96
93
  </Transition>
97
94
  </span>
98
- <UIcon name="i-lucide-chevron-up" class="size-5 shrink-0" />
95
+ <SbIcon name="chevron-up" :size="20" />
99
96
  </button>
100
97
  </div>
101
98
  </Transition>