Standard guest-invite form: one email field, admin inviter, mobile-first
Replaces the tab-bar form (email + name + inviting-member inputs, which overflowed a narrow frame) with the standard form: a card in the members view — 'Invite a guest', a single required email input, a 'Send invite' button. No name field (the guest chooses their own at Cloudron setup) and no inviter field: the portal records the co-op's ADMIN account and applies no monthly cap to admin invites. Form submits on Enter; full-width input and button under 600px. Removed the dead member-email datalist.
This commit is contained in:
1 parent
d5baffdb48
commit
d6d960324a
1 file changed
+47
-38
+47
-38
@@ -201,23 +201,22 @@ async def api_set_credits(request: Request):
|
||||
async def api_provision_guest(request: Request):
|
||||
"""Provision a guest account via the portal's /admin/provision-guest.
|
||||
|
||||
The portal enforces the abuse rules (one guest access per inviter per 30 days,
|
||||
one per recipient ever, active-member inviter) and returns a clear
|
||||
refusal — surfaced to the operator as-is.
|
||||
The standard guest-invite form: ONE field (the guest's email). No name is
|
||||
collected and none is derived — the guest chooses their own display name
|
||||
and username during Cloudron account setup, and the invitation greets
|
||||
neutrally. The portal records the co-op's ADMIN account as the inviter —
|
||||
admins are not bound by the member's one-per-30-days cap, and the
|
||||
recipient-side guards (one guest per recipient ever, no existing portal
|
||||
row) still run there. A refusal is surfaced to the operator as-is.
|
||||
"""
|
||||
if not is_admin(request):
|
||||
return JSONResponse({"error": "forbidden"}, status_code=403)
|
||||
body = await request.json()
|
||||
email = (body.get("email") or "").strip().lower()
|
||||
name = (body.get("name") or "").strip()
|
||||
inviter = (body.get("inviter") or body.get("inviter_email") or "").strip().lower()
|
||||
if not email or "@" not in email:
|
||||
return JSONResponse({"error": "A valid recipient email is required"}, status_code=400)
|
||||
if not inviter or "@" not in inviter:
|
||||
return JSONResponse({"error": "The inviting member's email is required"}, status_code=400)
|
||||
try:
|
||||
return await portal_post("/admin/provision-guest",
|
||||
{"email": email, "name": name, "inviter": inviter})
|
||||
return await portal_post("/admin/provision-guest", {"email": email})
|
||||
except HTTPException as e:
|
||||
return JSONResponse({"error": e.detail}, status_code=e.status_code)
|
||||
|
||||
@@ -363,8 +362,19 @@ PAGE_HTML = """<!DOCTYPE html>
|
||||
.pill.org { background: #e7edf5; color: #4a6a8a; }
|
||||
.pill.grace { background: #fdf3e3; color: #a97a2a; }
|
||||
.pill.guest { background: #efe7f2; color: #7a5a92; }
|
||||
#guest-group input { padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 12px; width: 170px; }
|
||||
#guest-group input#guest-name { width: 120px; }
|
||||
/* Standard guest-invite form (shared with the member dashboard): ONE field,
|
||||
plain labels, fits a narrow frame. */
|
||||
.guest-invite-card { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 16px 20px; margin-top: 20px; }
|
||||
.guest-invite-title { font-size: 14px; font-weight: 700; color: var(--ink); }
|
||||
.guest-invite-sub { color: var(--muted); font-size: 12px; margin: 4px 0 12px; }
|
||||
.guest-invite-form { display: flex; flex-direction: column; gap: 8px; max-width: 420px; }
|
||||
.guest-invite-label { font-size: 12px; font-weight: 600; color: var(--muted); }
|
||||
.guest-invite-form input { width: 100%; min-width: 0; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; font-family: inherit; background: #fff; color: var(--ink); }
|
||||
.guest-invite-form input:focus { outline: none; border-color: var(--green-mid); }
|
||||
.guest-invite-btn { cursor: pointer; border: none; border-radius: 8px; background: var(--green-deep); color: #fff; font-size: 13px; font-weight: 600; padding: 10px 16px; align-self: flex-start; }
|
||||
.guest-invite-btn:hover { background: #4e7a4d; }
|
||||
.guest-invite-btn:disabled { opacity: 0.6; cursor: default; }
|
||||
@media (max-width: 600px) { .guest-invite-btn { align-self: stretch; } }
|
||||
/* Trends tab (charts). Colours come from the same vars as the rest of the
|
||||
panel; the SVG is inline so there is no chart library and no CDN. */
|
||||
.trend-controls { display: flex; gap: 22px; flex-wrap: wrap; margin: 14px 0 0; }
|
||||
@@ -448,14 +458,6 @@ PAGE_HTML = """<!DOCTYPE html>
|
||||
<button class="range-btn active" id="mmode-balance" onclick="setMemberMode('balance')">Balance</button>
|
||||
<button class="range-btn" id="mmode-all" onclick="setMemberMode('all')">All time</button>
|
||||
</span>
|
||||
<span class="range-group" id="guest-group">
|
||||
<span class="range-label">Guest access</span>
|
||||
<input id="guest-email" type="email" placeholder="friend@example.com" list="member-email-list" autocomplete="off" />
|
||||
<input id="guest-name" type="text" placeholder="Their name" autocomplete="off" />
|
||||
<input id="guest-inviter" type="email" placeholder="Inviting member" list="member-email-list" autocomplete="off" />
|
||||
<datalist id="member-email-list"></datalist>
|
||||
<button class="range-btn" id="guest-send" onclick="sendGuestAccess()">Send guest access</button>
|
||||
</span>
|
||||
<span class="range-group" id="range-group" style="display:none;">
|
||||
<span class="range-label">Period</span>
|
||||
<button class="range-btn" id="range-30" onclick="setRange(30)">Last 30 days</button>
|
||||
@@ -483,6 +485,18 @@ PAGE_HTML = """<!DOCTYPE html>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div id="guest-invite-section">
|
||||
<div class="guest-invite-card">
|
||||
<h3 class="guest-invite-title">Invite a guest</h3>
|
||||
<p class="guest-invite-sub">Sends $5 of credits and 60 days of chat + dashboard access. The invitation comes from the co-op (admin) — no monthly cap.</p>
|
||||
<form class="guest-invite-form" id="guest-invite-form" onsubmit="sendGuestAccess(event)">
|
||||
<label class="guest-invite-label" for="guest-email">Their email</label>
|
||||
<input id="guest-email" type="email" required placeholder="friend@example.com" autocomplete="off" inputmode="email" maxlength="254" />
|
||||
<button type="submit" class="guest-invite-btn" id="guest-send">Send invite</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="guests-section" style="display:none;">
|
||||
<h3 style="margin:20px 0 8px;">Guests</h3>
|
||||
<p style="color:var(--muted);font-size:12px;margin:0 0 8px;">Guest accounts — access an inviting member gave to someone outside the co-op. Not members — excluded from member counts; guest access lapses on its time box or when its credits are spent.</p>
|
||||
@@ -1210,10 +1224,10 @@ function switchView(view) {
|
||||
$('tab-guestrequests').className = 'tab-btn' + (view === 'guestrequests' ? ' active' : '');
|
||||
$('view-title').textContent = view === 'members' ? 'Members' : (view === 'models' ? 'Model usage' : (view === 'trends' ? 'Trends' : (view === 'money' ? 'Money' : 'Guest requests')));
|
||||
// Mode groups: Balance/All-time for members; Period for models; the guest
|
||||
// action belongs to the members view too.
|
||||
// invite form belongs to the members view too.
|
||||
$('range-group').style.display = view === 'models' ? '' : 'none';
|
||||
$('member-mode-group').style.display = view === 'members' ? '' : 'none';
|
||||
$('guest-group').style.display = view === 'members' ? '' : 'none';
|
||||
$('guest-invite-section').style.display = view === 'members' ? '' : 'none';
|
||||
// Trends renders on first visit only, so the panel's initial load stays fast.
|
||||
if (view === 'trends') loadMetrics();
|
||||
// Money renders on first visit only, same rule: one fetch, then the
|
||||
@@ -1271,10 +1285,6 @@ function render() {
|
||||
}
|
||||
|
||||
function renderMembers() {
|
||||
// Datalist for the guest form's recipient/inviter fields: member emails the
|
||||
// operator can pick from (rebuilt per render; tiny).
|
||||
const dl = document.getElementById('member-email-list');
|
||||
if (dl) dl.innerHTML = membersData.map(m => '<option value="' + esc(m.email) + '"></option>').join('');
|
||||
const rows = [...membersData].sort((a, b) => {
|
||||
let va = a[memberSort.key], vb = b[memberSort.key];
|
||||
if (memberSort.key === 'spend') { va = memberSpend(a); vb = memberSpend(b); }
|
||||
@@ -1464,31 +1474,30 @@ async function addBalance(email) {
|
||||
} catch (e) { flash(e.message, false); }
|
||||
}
|
||||
|
||||
// Guest action: provision a $5 guest account for a friend of a member. The
|
||||
// portal enforces the abuse rules (one guest access per inviter per 30 days, one per
|
||||
// recipient ever, inviter must be an active member) and reports a clear
|
||||
// refusal; the panel only collects the three fields.
|
||||
async function sendGuestAccess() {
|
||||
// Guest action: provision a $5 guest account — the standard guest-invite form
|
||||
// (ONE field: the guest's email). The inviter is always the co-op's ADMIN
|
||||
// account, recorded by the portal; admins have no monthly cap. The portal
|
||||
// enforces the recipient-side guards (one guest per recipient ever, no
|
||||
// existing portal row) and reports a clear refusal.
|
||||
async function sendGuestAccess(ev) {
|
||||
if (ev) ev.preventDefault();
|
||||
const email = ($('guest-email').value || '').trim();
|
||||
const name = ($('guest-name').value || '').trim();
|
||||
const inviter = ($('guest-inviter').value || '').trim();
|
||||
const btn = $('guest-send');
|
||||
if (!email || email.indexOf('@') < 1) { flash("Enter the recipient's email", false); return; }
|
||||
if (!inviter || inviter.indexOf('@') < 1) { flash("Enter the inviting member's email", false); return; }
|
||||
if (!email || email.indexOf('@') < 1) { flash("Enter the guest's email", false); return; }
|
||||
btn.disabled = true; btn.textContent = "Sending…";
|
||||
try {
|
||||
const r = await fetch('/api/provision-guest', {
|
||||
method: 'POST', headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({ email, name, inviter })
|
||||
body: JSON.stringify({ email })
|
||||
});
|
||||
const d = await r.json().catch(() => ({}));
|
||||
if (!r.ok || d.error) { flash(d.error || ('Could not send guest access (' + r.status + ')'), false); return; }
|
||||
flash('Guest access sent — ' + email + ' has $5 of credits (expires in ' + (d.expires_in_days || 60) +
|
||||
flash('Invite sent — ' + email + ' has $5 of credits (expires in ' + (d.expires_in_days || 60) +
|
||||
' days). The welcome email is on its way.', true);
|
||||
$('guest-email').value = ''; $('guest-name').value = '';
|
||||
$('guest-email').value = '';
|
||||
load();
|
||||
} catch (e) { flash('Guest access failed: ' + e.message, false); }
|
||||
finally { btn.disabled = false; btn.textContent = 'Send guest access'; }
|
||||
finally { btn.disabled = false; btn.textContent = 'Send invite'; }
|
||||
}
|
||||
|
||||
// ---- Guest requests: the member self-serve trial gate ----------------------
|
||||
|
||||
Reference in new issue
Block a user