Standard guest-invite form: one email field, no name input

Same form as the admin panel: 'Invite a guest' heading, a single required
email input, a 'Send invite' button, submit on Enter. The inviter is the
logged-in member (automatic); the portal applies the one-per-30-days rule,
recipient checks and the pending-approval gate as before. No name is
collected or derived — the guest chooses their own at Cloudron setup.
This commit is contained in:
inference-bot committed 2026-11-08 02:55:23 +00:00
1 parent 84d5389eb6
commit 8f8106742a
1 file changed
+16 -10
+16 -10
View File
@@ -630,7 +630,9 @@ PAGE_HTML = """<!DOCTYPE html>
/* ---------- Guest access (members inviting a friend) ---------- */ /* ---------- Guest access (members inviting a friend) ---------- */
.guest-hint { color: var(--muted); font-size: 12px; margin-bottom: 12px; } .guest-hint { color: var(--muted); font-size: 12px; margin-bottom: 12px; }
.new-key .name-input { max-width: 200px; } /* Standard guest-invite form (shared with the admin panel): ONE field. */
.guest-invite-title { font-size: 14px; font-weight: 700; margin: 0 0 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.guest-trail { margin-top: 6px; } .guest-trail { margin-top: 6px; }
.guest-row { .guest-row {
display: flex; align-items: baseline; justify-content: space-between; gap: 12px; display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
@@ -843,11 +845,12 @@ PAGE_HTML = """<!DOCTYPE html>
<div class="card" id="guests-card" style="display:none"> <div class="card" id="guests-card" style="display:none">
<h2>Guest access</h2> <h2>Guest access</h2>
<p class="guest-hint" id="guest-hint">Give a friend $5 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.</p> <p class="guest-hint" id="guest-hint">Give a friend $5 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.</p>
<div class="new-key"> <h3 class="guest-invite-title">Invite a guest</h3>
<input id="guest-email" type="email" placeholder="their@email.org" maxlength="254" /> <form class="new-key" id="guest-invite-form" onsubmit="sendGuestInvite(event)">
<input id="guest-name" type="text" class="name-input" placeholder="Their name (optional)" maxlength="80" /> <label class="sr-only" for="guest-email">Their email</label>
<button class="primary" id="guest-btn" onclick="sendGuestInvite()">Send request</button> <input id="guest-email" type="email" required placeholder="their@email.org" maxlength="254" autocomplete="off" inputmode="email" />
</div> <button class="primary" id="guest-btn" type="submit">Send invite</button>
</form>
<div class="hint" id="guest-allowance"></div> <div class="hint" id="guest-allowance"></div>
<div class="guest-trail" id="guest-trail"></div> <div class="guest-trail" id="guest-trail"></div>
</div> </div>
@@ -1018,9 +1021,13 @@ function renderGuests(d) {
}).join(''); }).join('');
} }
async function sendGuestInvite() { // The standard guest-invite form (ONE field: the guest's email). 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, with the trial gate on, holds the request for approval.
async function sendGuestInvite(ev) {
if (ev) ev.preventDefault();
const email = ($('guest-email').value || '').trim(); const email = ($('guest-email').value || '').trim();
const name = ($('guest-name').value || '').trim();
const btn = $('guest-btn'); const btn = $('guest-btn');
const label = btn.textContent; const label = btn.textContent;
if (!email || email.indexOf('@') < 1) { flash('Enter their email address', false); return; } if (!email || email.indexOf('@') < 1) { flash('Enter their email address', false); return; }
@@ -1029,7 +1036,7 @@ async function sendGuestInvite() {
try { try {
const r = await fetch('/api/guests', { const r = await fetch('/api/guests', {
method: 'POST', headers: {'Content-Type': 'application/json'}, method: 'POST', headers: {'Content-Type': 'application/json'},
body: JSON.stringify({ email, name }) body: JSON.stringify({ email })
}); });
const d = await r.json().catch(() => ({})); const d = await r.json().catch(() => ({}));
if (!r.ok || d.error) { if (!r.ok || d.error) {
@@ -1037,7 +1044,6 @@ async function sendGuestInvite() {
return; return;
} }
$('guest-email').value = ''; $('guest-email').value = '';
$('guest-name').value = '';
flash(d.note || 'Request sent — waiting for approval.', true); flash(d.note || 'Request sent — waiting for approval.', true);
await loadGuests(); await loadGuests();
} catch (e) { } catch (e) {