From 1e6e9e481c630a4cdb1147eb2519ff85967312cb Mon Sep 17 00:00:00 2001 From: Inferencebot Date: Sun, 8 Nov 2026 20:53:51 +0000 Subject: [PATCH] Guest invite: hide the form once the 30-day invite is used; guest errors render in the guest card MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the member has no invite left (one per rolling 30 days), the invite form is REMOVED and a dated line takes its place: 'You have already invited a guest this month. Your next invite is available ' — the date computed by the portal from the last invite (next_eligible_at). All guest-invite feedback (errors, refusals, success) now renders in a dedicated #guest-flash inside the guest access card — never the #flash element in the API-keys card, which is a different feature (the bug the operator reported: over-limit refusals surfaced in the API key area). Hiding the form is UX only; the portal refuses direct over-limit calls server-side regardless. --- app/main.py | 63 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 20 deletions(-) diff --git a/app/main.py b/app/main.py index 4320489..fef258c 100644 --- a/app/main.py +++ b/app/main.py @@ -848,14 +848,19 @@ PAGE_HTML = """ @@ -878,6 +883,16 @@ function flash(msg, ok) { setTimeout(() => { f.className = 'flash'; }, 6000); } +// Guest-invite feedback stays INSIDE the guest access card. The #flash element +// lives in the API-keys card — a different feature — and a guest error landing +// there reads as an API-key problem (this replaces exactly that bug). +function guestFlash(msg, ok) { + const f = $('guest-flash'); + f.textContent = msg; + f.className = 'flash show ' + (ok ? 'ok' : 'err'); + setTimeout(() => { f.className = 'flash'; }, 6000); +} + function fmtMoney(n) { const v = Math.abs(Number(n)) < 0.005 ? 0 : (Number(n) || 0); return '$' + v.toFixed(2); } // --- Guest self-service cancel (reveal → confirm → ended state) ----------- @@ -998,13 +1013,19 @@ function renderGuests(d) { $('guest-btn').textContent = 'Send invite'; $('guest-hint').textContent = "Give a friend $2 of AI credits for the co-op's chat and API — no membership needed. They get 60 days to try it. One guest per member every 30 days."; if (d.eligible) { + // An invite is available: show the form. + $('guest-invite-wrap').style.display = ''; $('guest-allowance').textContent = 'You can send one guest invitation now.'; - } else if (d.next_eligible_at) { - $('guest-allowance').textContent = - 'One guest every ' + (d.per_inviter_days || 30) + ' days — your next invitation opens ' + fmtDay(d.next_eligible_at) + '.'; } else { - $('guest-allowance').textContent = - 'One guest every ' + (d.per_inviter_days || 30) + ' days.'; + // The 30-day invite is used: the form GOES — there is nothing left to + // submit — and the next-open date (computed by the portal from the last + // invite) takes its place. This is UX only; the portal refuses direct + // over-limit calls server-side regardless of what the page shows. + $('guest-invite-wrap').style.display = 'none'; + const next = d.next_eligible_at ? fmtDay(d.next_eligible_at) : ''; + $('guest-allowance').textContent = next + ? 'You have already invited a guest this month. Your next invite is available ' + next + '.' + : 'You have already invited a guest this month.'; } const trail = d.trail || []; if (!trail.length) { @@ -1027,16 +1048,18 @@ function renderGuests(d) { // The standard guest-invite form: the guest's email (required) plus an // OPTIONAL display name. The inviter is the logged-in member — automatic, no -// field; the portal applies the member-side protections (active member, one -// per 30 days, recipient checks) and a valid invitation provisions -// immediately. An empty name is never derived from the email. +// field; the portal applies the member-side protections SERVER-SIDE (active +// member, one per 30 days, recipient checks) and a valid invitation +// provisions immediately — hiding this form is UX, not the gate. An empty +// name is never derived from the email. Every message from this flow renders +// in the guest card (guestFlash), never the API-key flash. async function sendGuestInvite(ev) { if (ev) ev.preventDefault(); const email = ($('guest-email').value || '').trim(); const name = ($('guest-name').value || '').trim(); const btn = $('guest-btn'); const label = btn.textContent; - if (!email || email.indexOf('@') < 1) { flash('Enter their email address', false); return; } + if (!email || email.indexOf('@') < 1) { guestFlash('Enter their email address', false); return; } btn.disabled = true; btn.textContent = 'Sending…'; try { @@ -1046,15 +1069,15 @@ async function sendGuestInvite(ev) { }); const d = await r.json().catch(() => ({})); if (!r.ok || d.error) { - flash(d.detail || d.note || d.error || 'Could not send the invitation', false); + guestFlash(d.detail || d.note || d.error || 'Could not send the invitation', false); return; } $('guest-email').value = ''; $('guest-name').value = ''; - flash(d.note || 'Invitation sent — your friend can set up their account now.', true); + guestFlash(d.note || 'Invitation sent — your friend can set up their account now.', true); await loadGuests(); } catch (e) { - flash('Could not send the invitation: ' + e.message, false); + guestFlash('Could not send the invitation: ' + e.message, false); } finally { btn.disabled = false; btn.textContent = label;