feat: enhance product ticket selector and vertical cart card components
- Refactor ProductTicketSelectorComponent to improve variant selection logic and error handling. - Introduce a new signal for variant attributes and manage variant loading more efficiently. - Update the UI to reflect saving state in ProductVerticalWithCartCardComponent, preventing actions while saving. - Adjust button text based on saving state for better user feedback.
This commit is contained in:
@@ -36,10 +36,10 @@
|
||||
</app-button>
|
||||
<app-button
|
||||
variant="secondary"
|
||||
[disabled]="hasVariants() && selectedVariant() === null"
|
||||
[disabled]="saving() || (hasVariants() && selectedVariant() === null)"
|
||||
(click)="onAddToCart()"
|
||||
>
|
||||
Agregar al carrito
|
||||
{{ saving() ? 'Guardando' : 'Agregar al carrito' }}
|
||||
</app-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -24,6 +24,7 @@ export class ProductVerticalWithCartCardComponent {
|
||||
readonly description = input<string>('');
|
||||
readonly price = input<number>(0);
|
||||
readonly variants = input<VerticalCartVariant[]>([]);
|
||||
readonly saving = input(false);
|
||||
|
||||
readonly quantity = model<number>(1);
|
||||
readonly selectedVariant = model<number | null>(null);
|
||||
@@ -46,6 +47,10 @@ export class ProductVerticalWithCartCardComponent {
|
||||
protected readonly hasVariants = computed(() => this.variants().length > 0);
|
||||
|
||||
protected onAddToCart(): void {
|
||||
if (this.saving()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.addToCart.emit({ quantity: this.quantity(), variant: this.selectedVariant() });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user