Files
ladill-qr-plus/resources/js/ladill-modals.js
T
isaaccladandCursor f7d79809b4
Deploy Ladill QR Plus / deploy (push) Successful in 27s
Replace native confirm() dialogs with styled confirm modals.
Add shared confirm-dialog component, Alpine ladillConfirm store, and
swap browser confirms for consistent bottom-sheet modals across user,
admin, and hosting flows.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-07 21:10:58 +00:00

76 lines
2.0 KiB
JavaScript

/**
* Lightweight modal dispatch helpers (optional — balanceGate in layout is primary).
*/
export function openLadillModal(name) {
if (!name) {
return false;
}
window.dispatchEvent(new CustomEvent('open-modal', { detail: name, bubbles: true }));
return true;
}
export function closeLadillModal(name) {
if (!name) {
return false;
}
window.dispatchEvent(new CustomEvent('close-modal', { detail: name, bubbles: true }));
return true;
}
export function ladillNeedsTopup(balance, price) {
const normalizedBalance = Number.parseFloat(balance);
const normalizedPrice = Number.parseFloat(price);
if (!Number.isFinite(normalizedBalance) || !Number.isFinite(normalizedPrice)) {
return false;
}
return normalizedBalance <= 0 || normalizedBalance < normalizedPrice;
}
export function registerLadillConfirmStore(Alpine) {
Alpine.store('ladillConfirm', {
open: false,
title: '',
message: '',
confirmLabel: 'Confirm',
cancelLabel: 'Cancel',
variant: 'danger',
_resolve: null,
ask(options = {}) {
return new Promise((resolve) => {
this.title = options.title || 'Are you sure?';
this.message = options.message || '';
this.confirmLabel = options.confirmLabel || 'Confirm';
this.cancelLabel = options.cancelLabel || 'Cancel';
this.variant = options.variant || 'danger';
this._resolve = resolve;
this.open = true;
});
},
answer(confirmed) {
if (this._resolve) {
this._resolve(confirmed);
}
this.open = false;
this._resolve = null;
},
});
window.ladillConfirm = (options = {}) => Alpine.store('ladillConfirm').ask(options);
}
export function registerLadillModalHelpers() {
window.openLadillModal = openLadillModal;
window.closeLadillModal = closeLadillModal;
window.ladillNeedsTopup = ladillNeedsTopup;
}