style: apply prettier formatting
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
<div class="checkout-page">
|
||||
<div class="container hero">
|
||||
<h1 class="section-title">{{ 'CHECKOUT.TITLE' | translate }}</h1>
|
||||
<h1 class="section-title">{{ "CHECKOUT.TITLE" | translate }}</h1>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="container">
|
||||
<div class="checkout-layout">
|
||||
|
||||
<!-- LEFT COLUMN: Form -->
|
||||
<div class="checkout-form-section">
|
||||
<!-- Error Message -->
|
||||
@@ -14,50 +13,105 @@
|
||||
</div>
|
||||
|
||||
<form [formGroup]="checkoutForm" (ngSubmit)="onSubmit()" *ngIf="!error">
|
||||
|
||||
<!-- Contact Info Card -->
|
||||
<app-card class="mb-6">
|
||||
<div class="card-header-simple">
|
||||
<h3>{{ 'CHECKOUT.CONTACT_INFO' | translate }}</h3>
|
||||
<h3>{{ "CHECKOUT.CONTACT_INFO" | translate }}</h3>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<app-input formControlName="email" type="email" [label]="'CHECKOUT.EMAIL' | translate" [required]="true" [error]="checkoutForm.get('email')?.hasError('email') ? ('CHECKOUT.INVALID_EMAIL' | translate) : null"></app-input>
|
||||
<app-input formControlName="phone" type="tel" [label]="'CHECKOUT.PHONE' | translate" [required]="true"></app-input>
|
||||
<app-input
|
||||
formControlName="email"
|
||||
type="email"
|
||||
[label]="'CHECKOUT.EMAIL' | translate"
|
||||
[required]="true"
|
||||
[error]="
|
||||
checkoutForm.get('email')?.hasError('email')
|
||||
? ('CHECKOUT.INVALID_EMAIL' | translate)
|
||||
: null
|
||||
"
|
||||
></app-input>
|
||||
<app-input
|
||||
formControlName="phone"
|
||||
type="tel"
|
||||
[label]="'CHECKOUT.PHONE' | translate"
|
||||
[required]="true"
|
||||
></app-input>
|
||||
</div>
|
||||
</app-card>
|
||||
|
||||
<!-- Billing Address Card -->
|
||||
<app-card class="mb-6">
|
||||
<div class="card-header-simple">
|
||||
<h3>{{ 'CHECKOUT.BILLING_ADDR' | translate }}</h3>
|
||||
<h3>{{ "CHECKOUT.BILLING_ADDR" | translate }}</h3>
|
||||
</div>
|
||||
<div formGroupName="billingAddress">
|
||||
<!-- User Type Selector -->
|
||||
<app-toggle-selector class="mb-4 user-type-selector-compact"
|
||||
<app-toggle-selector
|
||||
class="mb-4 user-type-selector-compact"
|
||||
[options]="userTypeOptions"
|
||||
[selectedValue]="checkoutForm.get('customerType')?.value"
|
||||
(selectionChange)="setCustomerType($event)">
|
||||
(selectionChange)="setCustomerType($event)"
|
||||
>
|
||||
</app-toggle-selector>
|
||||
|
||||
|
||||
<!-- Private Person Fields -->
|
||||
<div *ngIf="!isCompany" class="form-row">
|
||||
<app-input formControlName="firstName" [label]="'CHECKOUT.FIRST_NAME' | translate" [required]="true"></app-input>
|
||||
<app-input formControlName="lastName" [label]="'CHECKOUT.LAST_NAME' | translate" [required]="true"></app-input>
|
||||
<app-input
|
||||
formControlName="firstName"
|
||||
[label]="'CHECKOUT.FIRST_NAME' | translate"
|
||||
[required]="true"
|
||||
></app-input>
|
||||
<app-input
|
||||
formControlName="lastName"
|
||||
[label]="'CHECKOUT.LAST_NAME' | translate"
|
||||
[required]="true"
|
||||
></app-input>
|
||||
</div>
|
||||
|
||||
<!-- Company Fields -->
|
||||
<div *ngIf="isCompany" class="company-fields mb-4">
|
||||
<app-input formControlName="companyName" [label]="'CHECKOUT.COMPANY_NAME' | translate" [required]="true" [placeholder]="'CONTACT.PLACEHOLDER_COMPANY' | translate"></app-input>
|
||||
<app-input formControlName="referencePerson" [label]="'CONTACT.REF_PERSON' | translate" [required]="true" [placeholder]="'CONTACT.PLACEHOLDER_REF_PERSON' | translate"></app-input>
|
||||
<app-input
|
||||
formControlName="companyName"
|
||||
[label]="'CHECKOUT.COMPANY_NAME' | translate"
|
||||
[required]="true"
|
||||
[placeholder]="'CONTACT.PLACEHOLDER_COMPANY' | translate"
|
||||
></app-input>
|
||||
<app-input
|
||||
formControlName="referencePerson"
|
||||
[label]="'CONTACT.REF_PERSON' | translate"
|
||||
[required]="true"
|
||||
[placeholder]="'CONTACT.PLACEHOLDER_REF_PERSON' | translate"
|
||||
></app-input>
|
||||
</div>
|
||||
|
||||
<app-input formControlName="addressLine1" [label]="'CHECKOUT.ADDRESS_1' | translate" [required]="true"></app-input>
|
||||
<app-input formControlName="addressLine2" [label]="'CHECKOUT.ADDRESS_2' | translate"></app-input>
|
||||
|
||||
<app-input
|
||||
formControlName="addressLine1"
|
||||
[label]="'CHECKOUT.ADDRESS_1' | translate"
|
||||
[required]="true"
|
||||
></app-input>
|
||||
<app-input
|
||||
formControlName="addressLine2"
|
||||
[label]="'CHECKOUT.ADDRESS_2' | translate"
|
||||
></app-input>
|
||||
|
||||
<div class="form-row three-cols">
|
||||
<app-input formControlName="zip" [label]="'CHECKOUT.ZIP' | translate" [required]="true"></app-input>
|
||||
<app-input formControlName="city" [label]="'CHECKOUT.CITY' | translate" class="city-field" [required]="true"></app-input>
|
||||
<app-input formControlName="countryCode" [label]="'CHECKOUT.COUNTRY' | translate" [disabled]="true" [required]="true"></app-input>
|
||||
<app-input
|
||||
formControlName="zip"
|
||||
[label]="'CHECKOUT.ZIP' | translate"
|
||||
[required]="true"
|
||||
></app-input>
|
||||
<app-input
|
||||
formControlName="city"
|
||||
[label]="'CHECKOUT.CITY' | translate"
|
||||
class="city-field"
|
||||
[required]="true"
|
||||
></app-input>
|
||||
<app-input
|
||||
formControlName="countryCode"
|
||||
[label]="'CHECKOUT.COUNTRY' | translate"
|
||||
[disabled]="true"
|
||||
[required]="true"
|
||||
></app-input>
|
||||
</div>
|
||||
</div>
|
||||
</app-card>
|
||||
@@ -65,60 +119,108 @@
|
||||
<!-- Shipping Option -->
|
||||
<div class="shipping-option">
|
||||
<label class="checkbox-container">
|
||||
<input type="checkbox" formControlName="shippingSameAsBilling">
|
||||
<input type="checkbox" formControlName="shippingSameAsBilling" />
|
||||
<span class="checkmark"></span>
|
||||
{{ 'CHECKOUT.SHIPPING_SAME' | translate }}
|
||||
{{ "CHECKOUT.SHIPPING_SAME" | translate }}
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<!-- Shipping Address Card (Conditional) -->
|
||||
<app-card *ngIf="!checkoutForm.get('shippingSameAsBilling')?.value" class="mb-6">
|
||||
<div class="card-header-simple">
|
||||
<h3>{{ 'CHECKOUT.SHIPPING_ADDR' | translate }}</h3>
|
||||
<app-card
|
||||
*ngIf="!checkoutForm.get('shippingSameAsBilling')?.value"
|
||||
class="mb-6"
|
||||
>
|
||||
<div class="card-header-simple">
|
||||
<h3>{{ "CHECKOUT.SHIPPING_ADDR" | translate }}</h3>
|
||||
</div>
|
||||
<div formGroupName="shippingAddress">
|
||||
<div class="form-row">
|
||||
<app-input formControlName="firstName" [label]="'CHECKOUT.FIRST_NAME' | translate"></app-input>
|
||||
<app-input formControlName="lastName" [label]="'CHECKOUT.LAST_NAME' | translate"></app-input>
|
||||
</div>
|
||||
|
||||
<div *ngIf="isCompany" class="company-fields">
|
||||
<app-input formControlName="companyName" [label]="'CHECKOUT.COMPANY_OPTIONAL' | translate"></app-input>
|
||||
<app-input formControlName="referencePerson" [label]="'CHECKOUT.REF_PERSON_OPTIONAL' | translate"></app-input>
|
||||
<div class="form-row">
|
||||
<app-input
|
||||
formControlName="firstName"
|
||||
[label]="'CHECKOUT.FIRST_NAME' | translate"
|
||||
></app-input>
|
||||
<app-input
|
||||
formControlName="lastName"
|
||||
[label]="'CHECKOUT.LAST_NAME' | translate"
|
||||
></app-input>
|
||||
</div>
|
||||
|
||||
<app-input formControlName="addressLine1" [label]="'CHECKOUT.ADDRESS_1' | translate"></app-input>
|
||||
|
||||
<div *ngIf="isCompany" class="company-fields">
|
||||
<app-input
|
||||
formControlName="companyName"
|
||||
[label]="'CHECKOUT.COMPANY_OPTIONAL' | translate"
|
||||
></app-input>
|
||||
<app-input
|
||||
formControlName="referencePerson"
|
||||
[label]="'CHECKOUT.REF_PERSON_OPTIONAL' | translate"
|
||||
></app-input>
|
||||
</div>
|
||||
|
||||
<app-input
|
||||
formControlName="addressLine1"
|
||||
[label]="'CHECKOUT.ADDRESS_1' | translate"
|
||||
></app-input>
|
||||
|
||||
<div class="form-row three-cols">
|
||||
<app-input formControlName="zip" [label]="'CHECKOUT.ZIP' | translate"></app-input>
|
||||
<app-input formControlName="city" [label]="'CHECKOUT.CITY' | translate" class="city-field"></app-input>
|
||||
<app-input formControlName="countryCode" [label]="'CHECKOUT.COUNTRY' | translate" [disabled]="true"></app-input>
|
||||
<app-input
|
||||
formControlName="zip"
|
||||
[label]="'CHECKOUT.ZIP' | translate"
|
||||
></app-input>
|
||||
<app-input
|
||||
formControlName="city"
|
||||
[label]="'CHECKOUT.CITY' | translate"
|
||||
class="city-field"
|
||||
></app-input>
|
||||
<app-input
|
||||
formControlName="countryCode"
|
||||
[label]="'CHECKOUT.COUNTRY' | translate"
|
||||
[disabled]="true"
|
||||
></app-input>
|
||||
</div>
|
||||
</div>
|
||||
</app-card>
|
||||
|
||||
<div class="legal-consent">
|
||||
<label class="checkbox-container">
|
||||
<input type="checkbox" formControlName="acceptLegal">
|
||||
<input type="checkbox" formControlName="acceptLegal" />
|
||||
<span class="checkmark"></span>
|
||||
<span>
|
||||
{{ 'LEGAL.CONSENT.LABEL_PREFIX' | translate }}
|
||||
<a href="/terms" target="_blank" rel="noopener">{{ 'LEGAL.CONSENT.TERMS_LINK' | translate }}</a>
|
||||
{{ 'LEGAL.CONSENT.AND' | translate }}
|
||||
<a href="/privacy" target="_blank" rel="noopener">{{ 'LEGAL.CONSENT.PRIVACY_LINK' | translate }}</a>.
|
||||
{{ "LEGAL.CONSENT.LABEL_PREFIX" | translate }}
|
||||
<a href="/terms" target="_blank" rel="noopener">{{
|
||||
"LEGAL.CONSENT.TERMS_LINK" | translate
|
||||
}}</a>
|
||||
{{ "LEGAL.CONSENT.AND" | translate }}
|
||||
<a href="/privacy" target="_blank" rel="noopener">{{
|
||||
"LEGAL.CONSENT.PRIVACY_LINK" | translate
|
||||
}}</a
|
||||
>.
|
||||
</span>
|
||||
</label>
|
||||
<div class="consent-error" *ngIf="checkoutForm.get('acceptLegal')?.invalid && checkoutForm.get('acceptLegal')?.touched">
|
||||
{{ 'LEGAL.CONSENT.REQUIRED_ERROR' | translate }}
|
||||
<div
|
||||
class="consent-error"
|
||||
*ngIf="
|
||||
checkoutForm.get('acceptLegal')?.invalid &&
|
||||
checkoutForm.get('acceptLegal')?.touched
|
||||
"
|
||||
>
|
||||
{{ "LEGAL.CONSENT.REQUIRED_ERROR" | translate }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="actions">
|
||||
<app-button type="submit" [disabled]="checkoutForm.invalid || isSubmitting()" [fullWidth]="true">
|
||||
{{ (isSubmitting() ? 'CHECKOUT.PROCESSING' : 'CHECKOUT.PLACE_ORDER') | translate }}
|
||||
<app-button
|
||||
type="submit"
|
||||
[disabled]="checkoutForm.invalid || isSubmitting()"
|
||||
[fullWidth]="true"
|
||||
>
|
||||
{{
|
||||
(isSubmitting()
|
||||
? "CHECKOUT.PROCESSING"
|
||||
: "CHECKOUT.PLACE_ORDER"
|
||||
) | translate
|
||||
}}
|
||||
</app-button>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@@ -126,53 +228,60 @@
|
||||
<div class="checkout-summary-section">
|
||||
<app-card class="sticky-card">
|
||||
<div class="card-header-simple">
|
||||
<h3>{{ 'CHECKOUT.SUMMARY_TITLE' | translate }}</h3>
|
||||
<h3>{{ "CHECKOUT.SUMMARY_TITLE" | translate }}</h3>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="summary-items" *ngIf="quoteSession() as session">
|
||||
<div class="summary-item" *ngFor="let item of session.items">
|
||||
<div class="item-details">
|
||||
<span class="item-name">{{ item.originalFilename }}</span>
|
||||
<div class="item-specs">
|
||||
<span>{{ 'CHECKOUT.QTY' | translate }}: {{ item.quantity }}</span>
|
||||
<span *ngIf="item.colorCode" class="color-dot" [style.background-color]="item.colorCode"></span>
|
||||
</div>
|
||||
<div class="item-specs-sub">
|
||||
{{ (item.printTimeSeconds / 3600) | number:'1.1-1' }}h | {{ item.materialGrams | number:'1.0-0' }}g
|
||||
</div>
|
||||
</div>
|
||||
<div class="item-price">
|
||||
<span class="item-total-price">
|
||||
{{ (item.unitPriceChf * item.quantity) | currency:'CHF' }}
|
||||
</span>
|
||||
<small class="item-unit-price" *ngIf="item.quantity > 1">
|
||||
{{ item.unitPriceChf | currency:'CHF' }} {{ 'CHECKOUT.PER_PIECE' | translate }}
|
||||
</small>
|
||||
</div>
|
||||
</div>
|
||||
<div class="summary-item" *ngFor="let item of session.items">
|
||||
<div class="item-details">
|
||||
<span class="item-name">{{ item.originalFilename }}</span>
|
||||
<div class="item-specs">
|
||||
<span
|
||||
>{{ "CHECKOUT.QTY" | translate }}: {{ item.quantity }}</span
|
||||
>
|
||||
<span
|
||||
*ngIf="item.colorCode"
|
||||
class="color-dot"
|
||||
[style.background-color]="item.colorCode"
|
||||
></span>
|
||||
</div>
|
||||
<div class="item-specs-sub">
|
||||
{{ item.printTimeSeconds / 3600 | number: "1.1-1" }}h |
|
||||
{{ item.materialGrams | number: "1.0-0" }}g
|
||||
</div>
|
||||
</div>
|
||||
<div class="item-price">
|
||||
<span class="item-total-price">
|
||||
{{ item.unitPriceChf * item.quantity | currency: "CHF" }}
|
||||
</span>
|
||||
<small class="item-unit-price" *ngIf="item.quantity > 1">
|
||||
{{ item.unitPriceChf | currency: "CHF" }}
|
||||
{{ "CHECKOUT.PER_PIECE" | translate }}
|
||||
</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="summary-totals" *ngIf="quoteSession() as session">
|
||||
<div class="total-row">
|
||||
<span>{{ 'CHECKOUT.SUBTOTAL' | translate }}</span>
|
||||
<span>{{ session.itemsTotalChf | currency:'CHF' }}</span>
|
||||
<span>{{ "CHECKOUT.SUBTOTAL" | translate }}</span>
|
||||
<span>{{ session.itemsTotalChf | currency: "CHF" }}</span>
|
||||
</div>
|
||||
<div class="total-row">
|
||||
<span>{{ 'CHECKOUT.SETUP_FEE' | translate }}</span>
|
||||
<span>{{ session.session.setupCostChf | currency:'CHF' }}</span>
|
||||
<span>{{ "CHECKOUT.SETUP_FEE" | translate }}</span>
|
||||
<span>{{ session.session.setupCostChf | currency: "CHF" }}</span>
|
||||
</div>
|
||||
<div class="total-row">
|
||||
<span>{{ 'CHECKOUT.SHIPPING' | translate }}</span>
|
||||
<span>{{ session.shippingCostChf | currency:'CHF' }}</span>
|
||||
<span>{{ "CHECKOUT.SHIPPING" | translate }}</span>
|
||||
<span>{{ session.shippingCostChf | currency: "CHF" }}</span>
|
||||
</div>
|
||||
<div class="grand-total">
|
||||
<span>{{ 'CHECKOUT.TOTAL' | translate }}</span>
|
||||
<span>{{ session.grandTotalChf | currency:'CHF' }}</span>
|
||||
<span>{{ "CHECKOUT.TOTAL" | translate }}</span>
|
||||
<span>{{ session.grandTotalChf | currency: "CHF" }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</app-card>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
.hero {
|
||||
.hero {
|
||||
padding: var(--space-8) 0;
|
||||
text-align: center;
|
||||
text-align: center;
|
||||
|
||||
.section-title {
|
||||
font-size: 2.5rem;
|
||||
@@ -25,7 +25,7 @@
|
||||
margin-bottom: var(--space-6);
|
||||
padding-bottom: var(--space-4);
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
|
||||
|
||||
h3 {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 600;
|
||||
@@ -39,10 +39,12 @@
|
||||
flex-direction: column;
|
||||
gap: var(--space-4);
|
||||
margin-bottom: var(--space-4);
|
||||
|
||||
@media(min-width: 768px) {
|
||||
|
||||
@media (min-width: 768px) {
|
||||
flex-direction: row;
|
||||
& > * { flex: 1; }
|
||||
& > * {
|
||||
flex: 1;
|
||||
}
|
||||
}
|
||||
|
||||
&.no-margin {
|
||||
@@ -53,7 +55,7 @@
|
||||
display: grid;
|
||||
grid-template-columns: 1.5fr 2fr 1fr;
|
||||
gap: var(--space-4);
|
||||
|
||||
|
||||
@media (max-width: 768px) {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
@@ -120,7 +122,7 @@ app-toggle-selector.user-type-selector-compact {
|
||||
&:checked ~ .checkmark {
|
||||
background-color: var(--color-brand);
|
||||
border-color: var(--color-brand);
|
||||
|
||||
|
||||
&:after {
|
||||
display: block;
|
||||
}
|
||||
@@ -197,12 +199,16 @@ app-toggle-selector.user-type-selector-compact {
|
||||
padding: var(--space-4) 0;
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
|
||||
&:first-child { padding-top: 0; }
|
||||
&:last-child { border-bottom: none; }
|
||||
&:first-child {
|
||||
padding-top: 0;
|
||||
}
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.item-details {
|
||||
flex: 1;
|
||||
|
||||
|
||||
.item-name {
|
||||
display: block;
|
||||
font-weight: 600;
|
||||
@@ -218,7 +224,7 @@ app-toggle-selector.user-type-selector-compact {
|
||||
gap: var(--space-2);
|
||||
font-size: 0.85rem;
|
||||
color: var(--color-text-muted);
|
||||
|
||||
|
||||
.color-dot {
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
@@ -227,11 +233,11 @@ app-toggle-selector.user-type-selector-compact {
|
||||
border: 1px solid var(--color-border);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
.item-specs-sub {
|
||||
font-size: 0.8rem;
|
||||
color: var(--color-text-muted);
|
||||
margin-top: 2px;
|
||||
color: var(--color-text-muted);
|
||||
margin-top: 2px;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -282,7 +288,7 @@ app-toggle-selector.user-type-selector-compact {
|
||||
|
||||
.actions {
|
||||
margin-top: var(--space-8);
|
||||
|
||||
|
||||
app-button {
|
||||
width: 100%;
|
||||
}
|
||||
@@ -298,4 +304,6 @@ app-toggle-selector.user-type-selector-compact {
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.mb-6 { margin-bottom: var(--space-6); }
|
||||
.mb-6 {
|
||||
margin-bottom: var(--space-6);
|
||||
}
|
||||
|
||||
@@ -1,29 +1,37 @@
|
||||
import { Component, inject, OnInit, signal } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { FormBuilder, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
|
||||
import {
|
||||
FormBuilder,
|
||||
FormGroup,
|
||||
ReactiveFormsModule,
|
||||
Validators,
|
||||
} from '@angular/forms';
|
||||
import { Router, ActivatedRoute } from '@angular/router';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { QuoteEstimatorService } from '../calculator/services/quote-estimator.service';
|
||||
import { AppInputComponent } from '../../shared/components/app-input/app-input.component';
|
||||
import { AppButtonComponent } from '../../shared/components/app-button/app-button.component';
|
||||
import { AppCardComponent } from '../../shared/components/app-card/app-card.component';
|
||||
import { AppToggleSelectorComponent, ToggleOption } from '../../shared/components/app-toggle-selector/app-toggle-selector.component';
|
||||
import {
|
||||
AppToggleSelectorComponent,
|
||||
ToggleOption,
|
||||
} from '../../shared/components/app-toggle-selector/app-toggle-selector.component';
|
||||
import { LanguageService } from '../../core/services/language.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-checkout',
|
||||
standalone: true,
|
||||
imports: [
|
||||
CommonModule,
|
||||
ReactiveFormsModule,
|
||||
CommonModule,
|
||||
ReactiveFormsModule,
|
||||
TranslateModule,
|
||||
AppInputComponent,
|
||||
AppButtonComponent,
|
||||
AppCardComponent,
|
||||
AppToggleSelectorComponent
|
||||
AppToggleSelectorComponent,
|
||||
],
|
||||
templateUrl: './checkout.component.html',
|
||||
styleUrls: ['./checkout.component.scss']
|
||||
styleUrls: ['./checkout.component.scss'],
|
||||
})
|
||||
export class CheckoutComponent implements OnInit {
|
||||
private fb = inject(FormBuilder);
|
||||
@@ -41,7 +49,7 @@ export class CheckoutComponent implements OnInit {
|
||||
|
||||
userTypeOptions: ToggleOption[] = [
|
||||
{ label: 'CONTACT.TYPE_PRIVATE', value: 'PRIVATE' },
|
||||
{ label: 'CONTACT.TYPE_COMPANY', value: 'BUSINESS' }
|
||||
{ label: 'CONTACT.TYPE_COMPANY', value: 'BUSINESS' },
|
||||
];
|
||||
|
||||
constructor() {
|
||||
@@ -49,22 +57,22 @@ export class CheckoutComponent implements OnInit {
|
||||
email: ['', [Validators.required, Validators.email]],
|
||||
phone: ['', Validators.required],
|
||||
customerType: ['PRIVATE', Validators.required], // Default to PRIVATE
|
||||
|
||||
|
||||
shippingSameAsBilling: [true],
|
||||
acceptLegal: [false, Validators.requiredTrue],
|
||||
|
||||
|
||||
billingAddress: this.fb.group({
|
||||
firstName: ['', Validators.required],
|
||||
lastName: ['', Validators.required],
|
||||
companyName: [''],
|
||||
companyName: [''],
|
||||
referencePerson: [''],
|
||||
addressLine1: ['', Validators.required],
|
||||
addressLine2: [''],
|
||||
zip: ['', Validators.required],
|
||||
city: ['', Validators.required],
|
||||
countryCode: ['CH', Validators.required]
|
||||
countryCode: ['CH', Validators.required],
|
||||
}),
|
||||
|
||||
|
||||
shippingAddress: this.fb.group({
|
||||
firstName: [''],
|
||||
lastName: [''],
|
||||
@@ -74,8 +82,8 @@ export class CheckoutComponent implements OnInit {
|
||||
addressLine2: [''],
|
||||
zip: [''],
|
||||
city: [''],
|
||||
countryCode: ['CH']
|
||||
})
|
||||
countryCode: ['CH'],
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -86,13 +94,13 @@ export class CheckoutComponent implements OnInit {
|
||||
setCustomerType(type: string) {
|
||||
this.checkoutForm.patchValue({ customerType: type });
|
||||
const isCompany = type === 'BUSINESS';
|
||||
|
||||
|
||||
const billingGroup = this.checkoutForm.get('billingAddress') as FormGroup;
|
||||
const companyControl = billingGroup.get('companyName');
|
||||
const referenceControl = billingGroup.get('referencePerson');
|
||||
const firstNameControl = billingGroup.get('firstName');
|
||||
const lastNameControl = billingGroup.get('lastName');
|
||||
|
||||
|
||||
if (isCompany) {
|
||||
companyControl?.setValidators([Validators.required]);
|
||||
referenceControl?.setValidators([Validators.required]);
|
||||
@@ -111,43 +119,47 @@ export class CheckoutComponent implements OnInit {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.route.queryParams.subscribe(params => {
|
||||
this.route.queryParams.subscribe((params) => {
|
||||
this.sessionId = params['session'];
|
||||
if (!this.sessionId) {
|
||||
this.error = 'CHECKOUT.ERR_NO_SESSION_START';
|
||||
this.router.navigate(['/']); // Redirect if no session
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
this.loadSessionDetails();
|
||||
});
|
||||
|
||||
// Toggle shipping validation based on checkbox
|
||||
this.checkoutForm.get('shippingSameAsBilling')?.valueChanges.subscribe(isSame => {
|
||||
const shippingGroup = this.checkoutForm.get('shippingAddress') as FormGroup;
|
||||
if (isSame) {
|
||||
shippingGroup.disable();
|
||||
} else {
|
||||
shippingGroup.enable();
|
||||
}
|
||||
});
|
||||
|
||||
this.checkoutForm
|
||||
.get('shippingSameAsBilling')
|
||||
?.valueChanges.subscribe((isSame) => {
|
||||
const shippingGroup = this.checkoutForm.get(
|
||||
'shippingAddress',
|
||||
) as FormGroup;
|
||||
if (isSame) {
|
||||
shippingGroup.disable();
|
||||
} else {
|
||||
shippingGroup.enable();
|
||||
}
|
||||
});
|
||||
|
||||
// Initial state
|
||||
this.checkoutForm.get('shippingAddress')?.disable();
|
||||
}
|
||||
|
||||
loadSessionDetails() {
|
||||
if (!this.sessionId) return; // Ensure sessionId is present before fetching
|
||||
this.quoteService.getQuoteSession(this.sessionId).subscribe({
|
||||
next: (session) => {
|
||||
this.quoteSession.set(session);
|
||||
console.log('Loaded session:', session);
|
||||
},
|
||||
error: (err) => {
|
||||
console.error('Failed to load session', err);
|
||||
this.error = 'CHECKOUT.ERR_LOAD_SESSION';
|
||||
}
|
||||
});
|
||||
if (!this.sessionId) return; // Ensure sessionId is present before fetching
|
||||
this.quoteService.getQuoteSession(this.sessionId).subscribe({
|
||||
next: (session) => {
|
||||
this.quoteSession.set(session);
|
||||
console.log('Loaded session:', session);
|
||||
},
|
||||
error: (err) => {
|
||||
console.error('Failed to load session', err);
|
||||
this.error = 'CHECKOUT.ERR_LOAD_SESSION';
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
onSubmit() {
|
||||
@@ -168,7 +180,7 @@ export class CheckoutComponent implements OnInit {
|
||||
// Assuming firstName, lastName, companyName for customer come from billingAddress if not explicitly in contact group
|
||||
firstName: formVal.billingAddress.firstName,
|
||||
lastName: formVal.billingAddress.lastName,
|
||||
companyName: formVal.billingAddress.companyName
|
||||
companyName: formVal.billingAddress.companyName,
|
||||
},
|
||||
billingAddress: {
|
||||
firstName: formVal.billingAddress.firstName,
|
||||
@@ -179,23 +191,25 @@ export class CheckoutComponent implements OnInit {
|
||||
addressLine2: formVal.billingAddress.addressLine2,
|
||||
zip: formVal.billingAddress.zip,
|
||||
city: formVal.billingAddress.city,
|
||||
countryCode: formVal.billingAddress.countryCode
|
||||
},
|
||||
shippingAddress: formVal.shippingSameAsBilling ? null : {
|
||||
firstName: formVal.shippingAddress.firstName,
|
||||
lastName: formVal.shippingAddress.lastName,
|
||||
companyName: formVal.shippingAddress.companyName,
|
||||
contactPerson: formVal.shippingAddress.referencePerson,
|
||||
addressLine1: formVal.shippingAddress.addressLine1,
|
||||
addressLine2: formVal.shippingAddress.addressLine2,
|
||||
zip: formVal.shippingAddress.zip,
|
||||
city: formVal.shippingAddress.city,
|
||||
countryCode: formVal.shippingAddress.countryCode
|
||||
countryCode: formVal.billingAddress.countryCode,
|
||||
},
|
||||
shippingAddress: formVal.shippingSameAsBilling
|
||||
? null
|
||||
: {
|
||||
firstName: formVal.shippingAddress.firstName,
|
||||
lastName: formVal.shippingAddress.lastName,
|
||||
companyName: formVal.shippingAddress.companyName,
|
||||
contactPerson: formVal.shippingAddress.referencePerson,
|
||||
addressLine1: formVal.shippingAddress.addressLine1,
|
||||
addressLine2: formVal.shippingAddress.addressLine2,
|
||||
zip: formVal.shippingAddress.zip,
|
||||
city: formVal.shippingAddress.city,
|
||||
countryCode: formVal.shippingAddress.countryCode,
|
||||
},
|
||||
shippingSameAsBilling: formVal.shippingSameAsBilling,
|
||||
language: this.languageService.selectedLang(),
|
||||
acceptTerms: formVal.acceptLegal,
|
||||
acceptPrivacy: formVal.acceptLegal
|
||||
acceptPrivacy: formVal.acceptLegal,
|
||||
};
|
||||
|
||||
if (!this.sessionId) {
|
||||
@@ -212,13 +226,18 @@ export class CheckoutComponent implements OnInit {
|
||||
this.error = 'CHECKOUT.ERR_CREATE_ORDER';
|
||||
return;
|
||||
}
|
||||
this.router.navigate(['/', this.languageService.selectedLang(), 'order', orderId]);
|
||||
this.router.navigate([
|
||||
'/',
|
||||
this.languageService.selectedLang(),
|
||||
'order',
|
||||
orderId,
|
||||
]);
|
||||
},
|
||||
error: (err) => {
|
||||
console.error('Order creation failed', err);
|
||||
this.isSubmitting.set(false);
|
||||
this.error = 'CHECKOUT.ERR_CREATE_ORDER';
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user