fix(pos): replace undefined toast.error() calls with a real toast
confirmSale() called toast.error(...) on checkout rejection (e.g. insufficient stock), but no toast global was ever defined anywhere in the app, so the ReferenceError swallowed the intended error message and operators saw nothing. Adds a minimal self-contained showToast() and bumps the SW cache so tills pick it up.
This commit is contained in:
parent
1bd659869d
commit
b20651b12d
2 changed files with 23 additions and 3 deletions
|
|
@ -783,6 +783,26 @@ function clearCust(){
|
|||
}
|
||||
|
||||
// ---------------- save sale ----------------
|
||||
// Minimal, self-contained error toast. `toast.error(...)` below used
|
||||
// to reference a `toast` global that was never defined anywhere in
|
||||
// this app (no library included, no local implementation) — every
|
||||
// checkout rejection (e.g. insufficient stock) threw a
|
||||
// ReferenceError instead of showing the operator anything, so the
|
||||
// cart just sat there with no feedback.
|
||||
function showToast(message){
|
||||
let el = document.getElementById('posToast');
|
||||
if(!el){
|
||||
el = document.createElement('div');
|
||||
el.id = 'posToast';
|
||||
el.style.cssText = 'position:fixed;left:16px;right:16px;bottom:calc(96px + env(safe-area-inset-bottom));max-width:448px;margin:0 auto;background:#c92a2a;color:#fff;padding:14px 16px;border-radius:12px;font-size:14px;font-weight:600;line-height:1.4;box-shadow:0 8px 24px rgba(0,0,0,.25);z-index:999;opacity:0;transition:opacity .15s ease';
|
||||
document.body.appendChild(el);
|
||||
}
|
||||
el.textContent = message;
|
||||
el.style.opacity = '1';
|
||||
clearTimeout(el._hideTimer);
|
||||
el._hideTimer = setTimeout(()=>{ el.style.opacity = '0'; }, 5000);
|
||||
}
|
||||
|
||||
async function confirmSale(){
|
||||
const btn = document.getElementById('confirmBtn');
|
||||
if(btn.disabled) return;
|
||||
|
|
@ -905,9 +925,9 @@ async function confirmSale(){
|
|||
: s.stock_item_id;
|
||||
return `${name}: only ${s.available} in stock (you asked for ${s.requested})`;
|
||||
});
|
||||
toast.error('Not enough stock — ' + lines.join('; '));
|
||||
showToast('Not enough stock — ' + lines.join('; '));
|
||||
} else {
|
||||
toast.error('Sale rejected: ' + (serverError.kind === 'other' ? serverError.message : 'Unknown error'));
|
||||
showToast('Sale rejected: ' + (serverError.kind === 'other' ? serverError.message : 'Unknown error'));
|
||||
}
|
||||
if (btn) {
|
||||
btn.disabled = false;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// Service worker — cache app shell, network-first for HTML + theme.js, cache-first for other static.
|
||||
const CACHE = "pos-v20";
|
||||
const CACHE = "pos-v21";
|
||||
const APP_SHELL = [
|
||||
'./',
|
||||
'./index.html',
|
||||
|
|
|
|||
Loading…
Reference in a new issue