From 782bd6cdd72bfd0b6f4e4956563e705a2f9de43a Mon Sep 17 00:00:00 2001 From: Bastian Masanek Date: Mon, 3 Nov 2025 17:00:22 +0100 Subject: [PATCH] Enhance CheckoutForm and Order components with user data integration - Refactored CheckoutForm.vue to utilize an extended user type, incorporating additional address fields for improved user data handling. - Updated OrderSummary.vue to conditionally display salutation based on user input. - Standardized error alert styling across multiple pages, changing variant from 'destructive' to 'error' for consistency. - Adjusted button styles in various components to align with the new 'experimenta' variant. These changes aim to improve user experience by ensuring accurate data representation and consistent UI elements across the checkout and order processes. --- app/components/Checkout/CheckoutForm.vue | 83 +++++++++++++++--------- app/components/Order/OrderSummary.vue | 4 +- app/pages/checkout.vue | 2 +- app/pages/order/confirm/[orderId].vue | 11 ++-- app/pages/order/success/[orderId].vue | 17 ++--- app/pages/payment.vue | 2 +- server/api/auth/login.post.ts | 6 ++ types/auth.d.ts | 29 +++++++++ 8 files changed, 105 insertions(+), 49 deletions(-) create mode 100644 types/auth.d.ts diff --git a/app/components/Checkout/CheckoutForm.vue b/app/components/Checkout/CheckoutForm.vue index a57a66b..ab4444c 100644 --- a/app/components/Checkout/CheckoutForm.vue +++ b/app/components/Checkout/CheckoutForm.vue @@ -64,7 +64,7 @@ interface Props { loading?: boolean } -const props = defineProps() +defineProps() const emit = defineEmits<{ submit: [data: z.infer] @@ -72,20 +72,36 @@ const emit = defineEmits<{ const { user } = useAuth() +// Extended user type with address fields +type ExtendedUser = typeof user.value & { + id?: string + firstName?: string + lastName?: string + email?: string + salutation?: 'male' | 'female' | 'other' | null + dateOfBirth?: Date | string | null + street?: string | null + postCode?: string | null + city?: string | null + countryCode?: string | null +} + +const extendedUser = user.value as ExtendedUser + // Form state const form = reactive({ - salutation: (user.value?.salutation as 'male' | 'female' | 'other') || 'other', - firstName: user.value?.firstName || '', - lastName: user.value?.lastName || '', - dateOfBirth: user.value?.dateOfBirth - ? new Date(user.value.dateOfBirth).toISOString().split('T')[0] + salutation: (extendedUser?.salutation as 'male' | 'female' | 'other') || 'other', + firstName: extendedUser?.firstName || '', + lastName: extendedUser?.lastName || '', + dateOfBirth: extendedUser?.dateOfBirth + ? new Date(extendedUser.dateOfBirth).toISOString().split('T')[0] : '', - street: user.value?.street || '', - postCode: user.value?.postCode || '', - city: user.value?.city || '', - countryCode: user.value?.countryCode || 'DE', + street: extendedUser?.street || '', + postCode: extendedUser?.postCode || '', + city: extendedUser?.city || '', + countryCode: extendedUser?.countryCode || 'DE', // Pre-checked if user doesn't have address yet - saveAddress: !user.value?.street, + saveAddress: !extendedUser?.street, }) // Validation errors @@ -131,7 +147,7 @@ function getError(field: string): string {
-

+

+ {{ getError('salutation') }}

@@ -154,9 +171,10 @@ function getError(field: string): string { type="text" placeholder="Max" :disabled="loading" - :class="{ 'border-red-500': hasError('firstName') }" + :class="{ 'border-warning/50': hasError('firstName') }" /> -

+

+ {{ getError('firstName') }}

@@ -170,9 +188,10 @@ function getError(field: string): string { type="text" placeholder="Mustermann" :disabled="loading" - :class="{ 'border-red-500': hasError('lastName') }" + :class="{ 'border-warning/50': hasError('lastName') }" /> -

+

+ {{ getError('lastName') }}

@@ -187,9 +206,10 @@ function getError(field: string): string { v-model="form.dateOfBirth" type="date" :disabled="loading" - :class="{ 'border-red-500': hasError('dateOfBirth') }" + :class="{ 'border-warning/50': hasError('dateOfBirth') }" /> -

+

+ {{ getError('dateOfBirth') }}

@@ -205,9 +225,10 @@ function getError(field: string): string { type="text" placeholder="Musterstraße 123" :disabled="loading" - :class="{ 'border-red-500': hasError('street') }" + :class="{ 'border-warning/50': hasError('street') }" /> -

+

+ {{ getError('street') }}

@@ -222,9 +243,10 @@ function getError(field: string): string { placeholder="74072" maxlength="5" :disabled="loading" - :class="{ 'border-red-500': hasError('postCode') }" + :class="{ 'border-warning/50': hasError('postCode') }" /> -

+

+ {{ getError('postCode') }}

@@ -238,9 +260,10 @@ function getError(field: string): string { type="text" placeholder="Heilbronn" :disabled="loading" - :class="{ 'border-red-500': hasError('city') }" + :class="{ 'border-warning/50': hasError('city') }" /> -

+

+ {{ getError('city') }}

@@ -249,7 +272,7 @@ function getError(field: string): string {
-

+

+ {{ getError('countryCode') }}

@@ -281,8 +305,9 @@ function getError(field: string): string { - -