feat(event-detail): disable cancel button when no items are selected

This commit is contained in:
2026-09-21 11:19:38 -03:00
parent c876b2b171
commit db97de6711
2 changed files with 5 additions and 2 deletions

View File

@@ -95,7 +95,7 @@
</div> </div>
<div class="event-detail__total"><span>Total</span><strong>{{ formatPrice(total()) }}</strong></div> <div class="event-detail__total"><span>Total</span><strong>{{ formatPrice(total()) }}</strong></div>
<div class="event-detail__buttons"> <div class="event-detail__buttons">
<app-button variant="cancel" (click)="cancel()">Cancelar</app-button> <app-button variant="cancel" [disabled]="!hasSelectedItems()" (click)="cancel()">Cancelar</app-button>
<app-button variant="primary" [disabled]="total() === 0 || submitting()" (click)="buyNow()"> <app-button variant="primary" [disabled]="total() === 0 || submitting()" (click)="buyNow()">
{{ submitting() ? 'Procesando…' : 'Comprar' }} {{ submitting() ? 'Procesando…' : 'Comprar' }}
</app-button> </app-button>

View File

@@ -56,6 +56,9 @@ export class EventDetailPageComponent {
const choice = this.resolveChoice(product); const choice = this.resolveChoice(product);
return sum + (choice ? choice.price * this.quantityFor(product.id) : 0); return sum + (choice ? choice.price * this.quantityFor(product.id) : 0);
}, 0)); }, 0));
protected readonly hasSelectedItems = computed(() =>
Object.values(this.quantities()).some((quantity) => quantity > 0),
);
constructor() { constructor() {
this.route.paramMap.pipe( this.route.paramMap.pipe(
@@ -131,7 +134,7 @@ export class EventDetailPageComponent {
} }
protected cancel(): void { protected cancel(): void {
void this.router.navigate(['/']); this.quantities.set({});
} }
protected async buyNow(): Promise<void> { protected async buyNow(): Promise<void> {