Prepaid login-ad slot queue (Marty, 2026-10-23: "they need to pay for the slot now to get a place in line")
When all member login slots are taken the Ads screen offers "Reserve the next slot" instead of a dead button. Same price and checks as a slot (purchased credits only), paid at reserve time; the campaign is 'queued' with queuedAt, never serves and has no 30-day clock. First paid, first served: the member sees their place and an estimated start (Central time, labelled an estimate) built from the live slots' end dates and the line ahead. A freed slot (ended, paused, or found by the new 1-minute tick) goes to the oldest reservation: starts now, expires now + 30 days, never more than loginSlotsMax live. Idempotent across the deploy overlap: JSON mode takes a lock file and records every promotion/cancel in DATA_DIR/login-queue.json, re-read before any change; MySQL mode uses guarded UPDATEs (status + live count in one statement). Owner gets an on-site notice and an email (unsubscribes respected). A paused slot resumes only when live + queued < max. Cancel before start = full refund (credited back as purchased credits; any unburned accrual released). Edits while queued are free and keep the free correction. Admin: Login-ad queue card with cancel + refund, plus the Member content action. New credit activity log (credit-log.json / credit_log table): reserved (queue #N), bought, started, refunds, shown on the Ads screen. Audit skips queued/cancelled login rows. Chatbot CANNED + FACTS updated (6 slots, paid queue, full refund before start). Tags bumped: ads-screen.js, admin.js, my.js 20261023q. Tests: qa/loginqueue.test.cjs (two app copies promoting at once) + qa/loginqueue.e2e.mjs; bash qa/run.sh loginqueue. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -261,7 +261,24 @@
|
||||
|
||||
// ── all campaigns ──
|
||||
let allCamps = [];
|
||||
// prepaid login-slot queue (2026-10-23): the line, with admin cancel + full refund
|
||||
async function loadLoginQueue() {
|
||||
try {
|
||||
const r = await api('/api/admin/login-queue'); const q = r.queue || [], L = r.slots || {};
|
||||
$('lqSub').textContent = (L.used || 0) + ' of ' + (L.max || 0) + ' slots live · ' + q.length + ' in line';
|
||||
$('lqTable').innerHTML = q.length ? '<tr><th>Place</th><th>ID</th><th>Owner</th><th>Ad</th><th>Paid</th><th>Reserved</th><th>Est. start (CT)</th><th></th></tr>' + q.map(x => '<tr><td>#' + x.place + '</td><td>#' + x.id + '</td><td><span class="trunc" title="' + esc(x.owner) + '">' + esc(x.owner) + '</span></td><td>' + esc(x.name) + '<div><a class="small trunc" href="' + esc(x.targetUrl) + '" target="_blank" rel="noopener">' + esc(x.targetUrl) + '</a></div></td><td class="mono small">' + (x.budget || 0).toLocaleString() + '</td><td class="small muted">' + when(x.queuedAt) + '</td><td class="small">' + esc(x.estStartCt || 'no estimate') + '</td><td class="act"><button class="btn small sec" type="button" data-lqcancel="' + x.id + '" data-owner="' + esc(x.owner) + '" data-paid="' + (x.budget || 0) + '">Cancel + refund</button></td></tr>').join('') : '<tr><td class="muted">Nobody is waiting for a login-ad slot.</td></tr>';
|
||||
} catch (e) { $('lqSub').textContent = e.message; }
|
||||
}
|
||||
$('lqTable').addEventListener('click', async e => {
|
||||
const b = e.target.closest('[data-lqcancel]'); if (!b) return;
|
||||
let ok = false; try { ok = await IAP.confirmBox('Cancel reservation #' + b.dataset.lqcancel + ' for ' + b.dataset.owner + '? Their ' + Number(b.dataset.paid).toLocaleString() + ' credits come back in full as purchased credits, and they leave the line.', { title: 'Cancel and refund', ok: 'Cancel and refund', cancel: 'Keep it' }); } catch (err) { ok = false; }
|
||||
if (!ok) return;
|
||||
b.disabled = true;
|
||||
try { const r = await api('/api/admin/campaigns/' + b.dataset.lqcancel + '/cancel-reservation', {}); IAP.status('Reservation #' + b.dataset.lqcancel + ' cancelled, ' + r.refunded + ' credits refunded.', 'ok'); await Promise.all([loadLoginQueue(), loadCampaigns()]); }
|
||||
catch (err) { IAP.status(err.message, 'bad'); b.disabled = false; }
|
||||
});
|
||||
async function loadCampaigns() {
|
||||
loadLoginQueue();
|
||||
const r = await api('/api/admin/campaigns');
|
||||
allCamps = r.campaigns || [];
|
||||
drawCamps();
|
||||
|
||||
Reference in New Issue
Block a user