feat(checkout): enhance checkout form with user data pre-filling and disable fields
This commit is contained in:
@@ -2,6 +2,8 @@ export interface AuthUser {
|
|||||||
id: number;
|
id: number;
|
||||||
nombre_apellido: string;
|
nombre_apellido: string;
|
||||||
email: string;
|
email: string;
|
||||||
|
dni?: string;
|
||||||
|
telefono?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LoginPayload {
|
export interface LoginPayload {
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
placeholder="Descripcion"
|
placeholder="Descripcion"
|
||||||
[value]="form().controls.nombre.value"
|
[value]="form().controls.nombre.value"
|
||||||
[invalid]="showControlError('nombre')"
|
[invalid]="showControlError('nombre')"
|
||||||
|
[disabled]="form().controls.nombre.disabled"
|
||||||
(valueChange)="updateField('nombre', $event)"
|
(valueChange)="updateField('nombre', $event)"
|
||||||
/>
|
/>
|
||||||
@if (getControlError('nombre'); as errorMessage) {
|
@if (getControlError('nombre'); as errorMessage) {
|
||||||
@@ -32,6 +33,7 @@
|
|||||||
placeholder="Descripcion"
|
placeholder="Descripcion"
|
||||||
[value]="form().controls.email.value"
|
[value]="form().controls.email.value"
|
||||||
[invalid]="showControlError('email')"
|
[invalid]="showControlError('email')"
|
||||||
|
[disabled]="form().controls.email.disabled"
|
||||||
(valueChange)="updateField('email', $event)"
|
(valueChange)="updateField('email', $event)"
|
||||||
/>
|
/>
|
||||||
@if (getControlError('email'); as errorMessage) {
|
@if (getControlError('email'); as errorMessage) {
|
||||||
@@ -49,6 +51,7 @@
|
|||||||
placeholder="Descripcion"
|
placeholder="Descripcion"
|
||||||
[value]="form().controls.dni.value"
|
[value]="form().controls.dni.value"
|
||||||
[invalid]="showControlError('dni')"
|
[invalid]="showControlError('dni')"
|
||||||
|
[disabled]="form().controls.dni.disabled"
|
||||||
(valueChange)="updateField('dni', $event)"
|
(valueChange)="updateField('dni', $event)"
|
||||||
/>
|
/>
|
||||||
@if (getControlError('dni'); as errorMessage) {
|
@if (getControlError('dni'); as errorMessage) {
|
||||||
@@ -66,6 +69,7 @@
|
|||||||
placeholder="Descripcion"
|
placeholder="Descripcion"
|
||||||
[value]="form().controls.telefono.value"
|
[value]="form().controls.telefono.value"
|
||||||
[invalid]="showControlError('telefono')"
|
[invalid]="showControlError('telefono')"
|
||||||
|
[disabled]="form().controls.telefono.disabled"
|
||||||
(valueChange)="updateField('telefono', $event)"
|
(valueChange)="updateField('telefono', $event)"
|
||||||
/>
|
/>
|
||||||
@if (getControlError('telefono'); as errorMessage) {
|
@if (getControlError('telefono'); as errorMessage) {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { startWith } from 'rxjs';
|
|||||||
import { CartService } from '../../../../core/services/cart/cart.service';
|
import { CartService } from '../../../../core/services/cart/cart.service';
|
||||||
import { TenantService } from '../../../../core/services/tenant.service';
|
import { TenantService } from '../../../../core/services/tenant.service';
|
||||||
import { CheckoutService, CreatePurchasePayload } from '../../../../core/services/checkout.service';
|
import { CheckoutService, CreatePurchasePayload } from '../../../../core/services/checkout.service';
|
||||||
|
import { AuthService } from '../../../../core/services/auth/auth.service';
|
||||||
import { BankAccount } from '../../../../core/services/tenant.interface';
|
import { BankAccount } from '../../../../core/services/tenant.interface';
|
||||||
import { CartItem } from '../../../../core/services/cart/cart.interface';
|
import { CartItem } from '../../../../core/services/cart/cart.interface';
|
||||||
import { CartComponent, CartItemMock } from '../../../../shared/components/cart/cart.component';
|
import { CartComponent, CartItemMock } from '../../../../shared/components/cart/cart.component';
|
||||||
@@ -35,6 +36,7 @@ export class CheckoutPageComponent {
|
|||||||
private readonly router = inject(Router);
|
private readonly router = inject(Router);
|
||||||
private readonly tenantService = inject(TenantService);
|
private readonly tenantService = inject(TenantService);
|
||||||
private readonly checkoutService = inject(CheckoutService);
|
private readonly checkoutService = inject(CheckoutService);
|
||||||
|
private readonly authService = inject(AuthService);
|
||||||
|
|
||||||
@ViewChild(StepperComponent) stepper!: StepperComponent;
|
@ViewChild(StepperComponent) stepper!: StepperComponent;
|
||||||
|
|
||||||
@@ -84,6 +86,18 @@ export class CheckoutPageComponent {
|
|||||||
this.form.statusChanges
|
this.form.statusChanges
|
||||||
.pipe(startWith(this.form.status))
|
.pipe(startWith(this.form.status))
|
||||||
.subscribe(() => this.isStep1Valid.set(this.form.valid));
|
.subscribe(() => this.isStep1Valid.set(this.form.valid));
|
||||||
|
|
||||||
|
const user = this.authService.user();
|
||||||
|
if (user) {
|
||||||
|
this.form.patchValue({
|
||||||
|
nombre: user.nombre_apellido,
|
||||||
|
email: user.email,
|
||||||
|
dni: user.dni ?? '',
|
||||||
|
telefono: user.telefono ?? ''
|
||||||
|
});
|
||||||
|
this.form.controls.nombre.disable();
|
||||||
|
this.form.controls.email.disable();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private mapCartItemToMock(item: CartItem): CartItemMock {
|
private mapCartItemToMock(item: CartItem): CartItemMock {
|
||||||
|
|||||||
Reference in New Issue
Block a user