462 lines
24 KiB
HTML
462 lines
24 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<title>Settings — VitFit</title>
|
||
<link rel="manifest" href="/manifest.json">
|
||
<link rel="stylesheet" href="/styles/base.css">
|
||
<link rel="stylesheet" href="/styles/layout.css">
|
||
<link rel="stylesheet" href="/styles/components.css">
|
||
</head>
|
||
<body>
|
||
<header class="banner">
|
||
<button class="banner-hamburger" id="nav-hamburger" aria-label="Menu">☰</button>
|
||
<img id="banner-logo" alt="Logo" style="display:none;height:36px;">
|
||
<span id="app-name" class="banner-title">VitFit</span>
|
||
</header>
|
||
<div class="drawer-scrim" id="drawer-scrim"></div>
|
||
<nav class="nav-drawer" id="nav-drawer"><ul class="nav-list" id="nav-list"></ul></nav>
|
||
|
||
<main class="main-content">
|
||
<h1 class="page-title">Settings</h1>
|
||
|
||
<div class="tabs" style="margin-bottom:var(--space-6);">
|
||
<button class="tab active" data-tab="org">Organisation</button>
|
||
<button class="tab" data-tab="branding">Branding</button>
|
||
<button class="tab" data-tab="users">Users</button>
|
||
</div>
|
||
|
||
<!-- Org tab -->
|
||
<div id="tab-org">
|
||
<div class="card" style="max-width:560px;">
|
||
<h2 class="card-title" style="margin-bottom:var(--space-6);">Organisation Details</h2>
|
||
<form id="org-form" novalidate>
|
||
<div class="form-group">
|
||
<label class="form-label" for="org-name">Name</label>
|
||
<input class="form-input" type="text" id="org-name" maxlength="120">
|
||
</div>
|
||
<div class="form-group">
|
||
<label class="form-label" for="org-timezone">Timezone</label>
|
||
<input class="form-input" type="text" id="org-timezone" placeholder="e.g. America/Chicago">
|
||
</div>
|
||
<div id="org-error" class="form-error" style="display:none;"></div>
|
||
<button class="btn btn-primary" type="submit" id="org-btn">Save</button>
|
||
</form>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Branding tab -->
|
||
<div id="tab-branding" style="display:none;">
|
||
<div class="card" style="max-width:600px;">
|
||
<h2 class="card-title" style="margin-bottom:var(--space-6);">Branding</h2>
|
||
<form id="branding-form" novalidate>
|
||
|
||
<div class="form-group">
|
||
<label class="form-label" for="app-name-input">App Name</label>
|
||
<input class="form-input" type="text" id="app-name-input" maxlength="60">
|
||
</div>
|
||
|
||
<div class="form-group">
|
||
<label class="form-label" for="logo-file">Logo (PNG/JPG, max 2MB)</label>
|
||
<input class="form-input" type="file" id="logo-file" accept="image/*">
|
||
<img id="logo-preview" style="display:none;max-height:60px;margin-top:var(--space-2);">
|
||
</div>
|
||
|
||
<p class="form-label" style="margin-bottom:var(--space-3);margin-top:var(--space-6);">Accent Colors</p>
|
||
<div class="form-row">
|
||
<div class="form-group">
|
||
<label class="form-label" for="primary-color">Primary</label>
|
||
<div style="display:flex;gap:var(--space-2);">
|
||
<input class="form-input" type="text" id="primary-color" placeholder="#00FF88" maxlength="7" pattern="^#[0-9A-Fa-f]{6}$">
|
||
<input class="form-input" type="color" id="primary-color-pick" style="width:44px;flex-shrink:0;padding:2px 4px;">
|
||
</div>
|
||
</div>
|
||
<div class="form-group">
|
||
<label class="form-label" for="secondary-color">Secondary</label>
|
||
<div style="display:flex;gap:var(--space-2);">
|
||
<input class="form-input" type="text" id="secondary-color" placeholder="#4488FF" maxlength="7" pattern="^#[0-9A-Fa-f]{6}$">
|
||
<input class="form-input" type="color" id="secondary-color-pick" style="width:44px;flex-shrink:0;padding:2px 4px;">
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<p class="form-label" style="margin-bottom:var(--space-3);margin-top:var(--space-2);">Button Colors</p>
|
||
<div class="form-row">
|
||
<div class="form-group">
|
||
<label class="form-label" for="btn-primary-bg">Primary Button</label>
|
||
<div style="display:flex;gap:var(--space-2);">
|
||
<input class="form-input" type="text" id="btn-primary-bg" placeholder="same as primary" maxlength="7" pattern="^#[0-9A-Fa-f]{6}$">
|
||
<input class="form-input" type="color" id="btn-primary-bg-pick" style="width:44px;flex-shrink:0;padding:2px 4px;">
|
||
</div>
|
||
</div>
|
||
<div class="form-group">
|
||
<label class="form-label" for="btn-secondary-bg">Secondary Button</label>
|
||
<div style="display:flex;gap:var(--space-2);">
|
||
<input class="form-input" type="text" id="btn-secondary-bg" placeholder="#242424" maxlength="7" pattern="^#[0-9A-Fa-f]{6}$">
|
||
<input class="form-input" type="color" id="btn-secondary-bg-pick" style="width:44px;flex-shrink:0;padding:2px 4px;">
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<p class="form-label" style="margin-bottom:var(--space-3);margin-top:var(--space-2);">Surface Colors</p>
|
||
<div class="form-row">
|
||
<div class="form-group">
|
||
<label class="form-label" for="page-bg">Page Background</label>
|
||
<div style="display:flex;gap:var(--space-2);">
|
||
<input class="form-input" type="text" id="page-bg" placeholder="#0f0f0f" maxlength="7" pattern="^#[0-9A-Fa-f]{6}$">
|
||
<input class="form-input" type="color" id="page-bg-pick" style="width:44px;flex-shrink:0;padding:2px 4px;">
|
||
</div>
|
||
</div>
|
||
<div class="form-group">
|
||
<label class="form-label" for="banner-bg">Banner / Header</label>
|
||
<div style="display:flex;gap:var(--space-2);">
|
||
<input class="form-input" type="text" id="banner-bg" placeholder="#1a1a1a" maxlength="7" pattern="^#[0-9A-Fa-f]{6}$">
|
||
<input class="form-input" type="color" id="banner-bg-pick" style="width:44px;flex-shrink:0;padding:2px 4px;">
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="form-row">
|
||
<div class="form-group">
|
||
<label class="form-label" for="drawer-bg">Nav Drawer</label>
|
||
<div style="display:flex;gap:var(--space-2);">
|
||
<input class="form-input" type="text" id="drawer-bg" placeholder="#1a1a1a" maxlength="7" pattern="^#[0-9A-Fa-f]{6}$">
|
||
<input class="form-input" type="color" id="drawer-bg-pick" style="width:44px;flex-shrink:0;padding:2px 4px;">
|
||
</div>
|
||
</div>
|
||
<div class="form-group">
|
||
<label class="form-label" for="popup-bg">Popup / Modal</label>
|
||
<div style="display:flex;gap:var(--space-2);">
|
||
<input class="form-input" type="text" id="popup-bg" placeholder="#242424" maxlength="7" pattern="^#[0-9A-Fa-f]{6}$">
|
||
<input class="form-input" type="color" id="popup-bg-pick" style="width:44px;flex-shrink:0;padding:2px 4px;">
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="form-group">
|
||
<label class="form-label" for="overlay-color">Overlay / Scrim</label>
|
||
<div style="display:flex;gap:var(--space-2);max-width:50%;">
|
||
<input class="form-input" type="text" id="overlay-color" placeholder="#000000" maxlength="7" pattern="^#[0-9A-Fa-f]{6}$">
|
||
<input class="form-input" type="color" id="overlay-color-pick" style="width:44px;flex-shrink:0;padding:2px 4px;">
|
||
</div>
|
||
<p class="form-hint">Applied at ~65–70% opacity.</p>
|
||
</div>
|
||
|
||
<p class="form-label" style="margin-bottom:var(--space-3);margin-top:var(--space-2);">Panel & Input Colors</p>
|
||
<div class="form-row">
|
||
<div class="form-group">
|
||
<label class="form-label" for="card-bg">Card / Panel</label>
|
||
<div style="display:flex;gap:var(--space-2);">
|
||
<input class="form-input" type="text" id="card-bg" placeholder="#1a1a1a" maxlength="7" pattern="^#[0-9A-Fa-f]{6}$">
|
||
<input class="form-input" type="color" id="card-bg-pick" style="width:44px;flex-shrink:0;padding:2px 4px;">
|
||
</div>
|
||
</div>
|
||
<div class="form-group">
|
||
<label class="form-label" for="input-bg">Search / Input</label>
|
||
<div style="display:flex;gap:var(--space-2);">
|
||
<input class="form-input" type="text" id="input-bg" placeholder="#242424" maxlength="7" pattern="^#[0-9A-Fa-f]{6}$">
|
||
<input class="form-input" type="color" id="input-bg-pick" style="width:44px;flex-shrink:0;padding:2px 4px;">
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="form-row">
|
||
<div class="form-group">
|
||
<label class="form-label" for="hover-bg">Row / Item Hover</label>
|
||
<div style="display:flex;gap:var(--space-2);">
|
||
<input class="form-input" type="text" id="hover-bg" placeholder="#2a2a2a" maxlength="7" pattern="^#[0-9A-Fa-f]{6}$">
|
||
<input class="form-input" type="color" id="hover-bg-pick" style="width:44px;flex-shrink:0;padding:2px 4px;">
|
||
</div>
|
||
</div>
|
||
<div class="form-group">
|
||
<label class="form-label" for="border-color">Borders</label>
|
||
<div style="display:flex;gap:var(--space-2);">
|
||
<input class="form-input" type="text" id="border-color" placeholder="#2e2e2e" maxlength="7" pattern="^#[0-9A-Fa-f]{6}$">
|
||
<input class="form-input" type="color" id="border-color-pick" style="width:44px;flex-shrink:0;padding:2px 4px;">
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<p class="form-label" style="margin-bottom:var(--space-3);margin-top:var(--space-2);">Text Colors</p>
|
||
<div class="form-row">
|
||
<div class="form-group">
|
||
<label class="form-label" for="text-primary">Primary Text</label>
|
||
<div style="display:flex;gap:var(--space-2);">
|
||
<input class="form-input" type="text" id="text-primary" placeholder="#f0f0f0" maxlength="7" pattern="^#[0-9A-Fa-f]{6}$">
|
||
<input class="form-input" type="color" id="text-primary-pick" style="width:44px;flex-shrink:0;padding:2px 4px;">
|
||
</div>
|
||
</div>
|
||
<div class="form-group">
|
||
<label class="form-label" for="text-secondary">Secondary Text</label>
|
||
<div style="display:flex;gap:var(--space-2);">
|
||
<input class="form-input" type="text" id="text-secondary" placeholder="#a0a0a0" maxlength="7" pattern="^#[0-9A-Fa-f]{6}$">
|
||
<input class="form-input" type="color" id="text-secondary-pick" style="width:44px;flex-shrink:0;padding:2px 4px;">
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="form-group">
|
||
<label class="form-label">Tab Style</label>
|
||
<div style="display:flex;gap:var(--space-4);">
|
||
<label style="display:flex;align-items:center;gap:var(--space-2);cursor:pointer;">
|
||
<input type="radio" name="tab-style" value="underline" checked> Underline
|
||
</label>
|
||
<label style="display:flex;align-items:center;gap:var(--space-2);cursor:pointer;">
|
||
<input type="radio" name="tab-style" value="pill"> Pill
|
||
</label>
|
||
</div>
|
||
</div>
|
||
|
||
<div id="branding-error" class="form-error" style="display:none;"></div>
|
||
<button class="btn btn-primary" type="submit" id="branding-btn">Save Branding</button>
|
||
</form>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Users tab -->
|
||
<div id="tab-users" style="display:none;">
|
||
<div class="page-header" style="margin-bottom:var(--space-4);">
|
||
<h2 class="card-title">Users</h2>
|
||
<button class="btn btn-primary btn-sm" id="invite-btn">Invite User</button>
|
||
</div>
|
||
<div id="user-list">
|
||
<div class="empty-state"><p class="empty-state-text">Loading…</p></div>
|
||
</div>
|
||
|
||
<div class="modal-overlay" id="invite-modal" style="display:none;">
|
||
<div class="modal">
|
||
<div class="modal-header">
|
||
<h2 class="modal-title">Invite User</h2>
|
||
<button class="modal-close" id="invite-modal-close">×</button>
|
||
</div>
|
||
<div class="form-group">
|
||
<label class="form-label" for="invite-name">Name</label>
|
||
<input class="form-input" type="text" id="invite-name" maxlength="80">
|
||
</div>
|
||
<div class="form-group">
|
||
<label class="form-label" for="invite-email">Email</label>
|
||
<input class="form-input" type="email" id="invite-email">
|
||
</div>
|
||
<div class="form-group">
|
||
<label class="form-label" for="invite-role">Role</label>
|
||
<select class="form-select" id="invite-role">
|
||
<option value="Coach">Coach</option>
|
||
<option value="Client">Client</option>
|
||
</select>
|
||
</div>
|
||
<div class="form-group">
|
||
<label class="form-label" for="invite-password">Temporary Password</label>
|
||
<input class="form-input" type="text" id="invite-password" autocomplete="off">
|
||
</div>
|
||
<div id="invite-error" class="form-error" style="display:none;"></div>
|
||
<button class="btn btn-primary" id="invite-confirm-btn">Create User</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</main>
|
||
|
||
<div id="session-expired-overlay" class="session-expired-overlay">
|
||
<div class="session-expired-box"><p>Your session has expired.</p><a href="/" class="btn btn-primary">Sign In Again</a></div>
|
||
</div>
|
||
|
||
<script src="/js/core.js"></script>
|
||
<script>
|
||
async function loadUsers() {
|
||
const el = document.getElementById('user-list');
|
||
try {
|
||
const res = await Api.get('/api/v1/users');
|
||
if (!res.ok) throw new Error();
|
||
const { data } = await res.json();
|
||
el.innerHTML = `<table class="table"><thead><tr><th>Name</th><th>Email</th><th>Role</th><th>Status</th><th></th></tr></thead><tbody>
|
||
${data.map(u => `<tr>
|
||
<td>${u.name}</td>
|
||
<td>${u.email}</td>
|
||
<td>${u.role}</td>
|
||
<td><span class="badge badge-${u.isActive ? 'success' : 'danger'}">${u.isActive ? 'Active' : 'Inactive'}</span></td>
|
||
<td class="table-actions">
|
||
${u.isActive
|
||
? `<button class="btn btn-danger btn-sm" data-action="toggle" data-id="${u.id}" data-active="false">Deactivate</button>`
|
||
: `<button class="btn btn-secondary btn-sm" data-action="toggle" data-id="${u.id}" data-active="true">Activate</button>`}
|
||
</td>
|
||
</tr>`).join('')}
|
||
</tbody></table>`;
|
||
} catch { el.innerHTML = '<div class="empty-state"><p class="empty-state-text">Failed to load.</p></div>'; }
|
||
}
|
||
|
||
async function toggleUser(id, active) {
|
||
try {
|
||
const res = await Api.patch(`/api/v1/users/${id}`, { isActive: active });
|
||
if (res.ok) { toast(active ? 'User activated.' : 'User deactivated.', 'success'); loadUsers(); }
|
||
else { const b = await res.json(); toast(b.message || 'Failed.', 'error'); }
|
||
} catch { toast('Network error.', 'error'); }
|
||
}
|
||
|
||
document.addEventListener('DOMContentLoaded', async () => {
|
||
await Page.init(['Owner']);
|
||
|
||
document.getElementById('user-list').addEventListener('click', (e) => {
|
||
const btn = e.target.closest('button[data-action="toggle"]');
|
||
if (btn) toggleUser(parseInt(btn.dataset.id, 10), btn.dataset.active === 'true');
|
||
});
|
||
|
||
// Tab switching
|
||
document.querySelectorAll('.tab').forEach(btn => {
|
||
btn.addEventListener('click', () => {
|
||
document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
|
||
btn.classList.add('active');
|
||
['org', 'branding', 'users'].forEach(t => {
|
||
document.getElementById(`tab-${t}`).style.display = btn.dataset.tab === t ? '' : 'none';
|
||
});
|
||
if (btn.dataset.tab === 'users') loadUsers();
|
||
});
|
||
});
|
||
|
||
// Load org data
|
||
try {
|
||
const res = await Api.get('/api/v1/org');
|
||
if (res.ok) {
|
||
const { data } = await res.json();
|
||
document.getElementById('org-name').value = data.name || '';
|
||
document.getElementById('org-timezone').value = data.timezone || '';
|
||
}
|
||
} catch {}
|
||
|
||
document.getElementById('org-form').addEventListener('submit', async (e) => {
|
||
e.preventDefault();
|
||
const errEl = document.getElementById('org-error'); errEl.style.display = 'none';
|
||
const btn = document.getElementById('org-btn'); btn.disabled = true; btn.textContent = 'Saving…';
|
||
try {
|
||
const res = await Api.patch('/api/v1/org', { name: document.getElementById('org-name').value.trim(), timezone: document.getElementById('org-timezone').value.trim() });
|
||
if (res.ok) toast('Saved.', 'success');
|
||
else { const b = await res.json(); errEl.textContent = b.message || 'Failed.'; errEl.style.display = 'block'; }
|
||
} catch { errEl.textContent = 'Network error.'; errEl.style.display = 'block'; }
|
||
finally { btn.disabled = false; btn.textContent = 'Save'; }
|
||
});
|
||
|
||
// ── Color picker pairs ───────────────────────────────────────────────
|
||
function wireColorPair(textId, pickId) {
|
||
const text = document.getElementById(textId);
|
||
const pick = document.getElementById(pickId);
|
||
pick.addEventListener('input', () => { text.value = pick.value; });
|
||
text.addEventListener('input', () => { if (/^#[0-9A-Fa-f]{6}$/.test(text.value)) pick.value = text.value; });
|
||
}
|
||
function setColorPair(textId, pickId, val) {
|
||
if (!val) return;
|
||
document.getElementById(textId).value = val;
|
||
document.getElementById(pickId).value = val;
|
||
}
|
||
wireColorPair('primary-color', 'primary-color-pick');
|
||
wireColorPair('secondary-color', 'secondary-color-pick');
|
||
wireColorPair('btn-primary-bg', 'btn-primary-bg-pick');
|
||
wireColorPair('btn-secondary-bg', 'btn-secondary-bg-pick');
|
||
wireColorPair('page-bg', 'page-bg-pick');
|
||
wireColorPair('banner-bg', 'banner-bg-pick');
|
||
wireColorPair('drawer-bg', 'drawer-bg-pick');
|
||
wireColorPair('popup-bg', 'popup-bg-pick');
|
||
wireColorPair('overlay-color', 'overlay-color-pick');
|
||
wireColorPair('card-bg', 'card-bg-pick');
|
||
wireColorPair('input-bg', 'input-bg-pick');
|
||
wireColorPair('hover-bg', 'hover-bg-pick');
|
||
wireColorPair('border-color', 'border-color-pick');
|
||
wireColorPair('text-primary', 'text-primary-pick');
|
||
wireColorPair('text-secondary', 'text-secondary-pick');
|
||
|
||
// Load branding
|
||
try {
|
||
const res = await Api.get('/api/v1/org/branding');
|
||
if (res.ok) {
|
||
const { data } = await res.json();
|
||
document.getElementById('app-name-input').value = data.appName || '';
|
||
setColorPair('primary-color', 'primary-color-pick', data.primaryColor);
|
||
setColorPair('secondary-color', 'secondary-color-pick', data.secondaryColor);
|
||
setColorPair('btn-primary-bg', 'btn-primary-bg-pick', data.btnPrimaryBg);
|
||
setColorPair('btn-secondary-bg', 'btn-secondary-bg-pick', data.btnSecondaryBg);
|
||
setColorPair('page-bg', 'page-bg-pick', data.pageBg);
|
||
setColorPair('banner-bg', 'banner-bg-pick', data.bannerBg);
|
||
setColorPair('drawer-bg', 'drawer-bg-pick', data.drawerBg);
|
||
setColorPair('popup-bg', 'popup-bg-pick', data.popupBg);
|
||
setColorPair('overlay-color', 'overlay-color-pick', data.overlayColor);
|
||
setColorPair('card-bg', 'card-bg-pick', data.cardBg);
|
||
setColorPair('input-bg', 'input-bg-pick', data.inputBg);
|
||
setColorPair('hover-bg', 'hover-bg-pick', data.hoverBg);
|
||
setColorPair('border-color', 'border-color-pick', data.borderColor);
|
||
setColorPair('text-primary', 'text-primary-pick', data.textPrimary);
|
||
setColorPair('text-secondary', 'text-secondary-pick', data.textSecondary);
|
||
if (data.tabStyle) {
|
||
const radio = document.querySelector(`input[name="tab-style"][value="${data.tabStyle}"]`);
|
||
if (radio) radio.checked = true;
|
||
}
|
||
if (data.logoPath) { const img = document.getElementById('logo-preview'); img.src = data.logoPath; img.style.display = ''; }
|
||
}
|
||
} catch {}
|
||
|
||
function hexOrUndefined(id) { const v = document.getElementById(id).value.trim(); return /^#[0-9A-Fa-f]{6}$/.test(v) ? v : undefined; }
|
||
|
||
document.getElementById('branding-form').addEventListener('submit', async (e) => {
|
||
e.preventDefault();
|
||
const errEl = document.getElementById('branding-error'); errEl.style.display = 'none';
|
||
const btn = document.getElementById('branding-btn'); btn.disabled = true; btn.textContent = 'Saving…';
|
||
|
||
const logoFile = document.getElementById('logo-file').files[0];
|
||
const tabStyle = document.querySelector('input[name="tab-style"]:checked')?.value;
|
||
const brandFields = {
|
||
appName: document.getElementById('app-name-input').value.trim() || undefined,
|
||
primaryColor: hexOrUndefined('primary-color'),
|
||
secondaryColor: hexOrUndefined('secondary-color'),
|
||
btnPrimaryBg: hexOrUndefined('btn-primary-bg'),
|
||
btnSecondaryBg: hexOrUndefined('btn-secondary-bg'),
|
||
pageBg: hexOrUndefined('page-bg'),
|
||
bannerBg: hexOrUndefined('banner-bg'),
|
||
drawerBg: hexOrUndefined('drawer-bg'),
|
||
popupBg: hexOrUndefined('popup-bg'),
|
||
overlayColor: hexOrUndefined('overlay-color'),
|
||
cardBg: hexOrUndefined('card-bg'),
|
||
inputBg: hexOrUndefined('input-bg'),
|
||
hoverBg: hexOrUndefined('hover-bg'),
|
||
borderColor: hexOrUndefined('border-color'),
|
||
textPrimary: hexOrUndefined('text-primary'),
|
||
textSecondary: hexOrUndefined('text-secondary'),
|
||
tabStyle,
|
||
};
|
||
|
||
try {
|
||
if (logoFile) {
|
||
const fd = new FormData();
|
||
fd.append('logo', logoFile);
|
||
const logoRes = await Api.upload('/api/v1/org/logo', fd);
|
||
if (!logoRes.ok) { const b = await logoRes.json(); errEl.textContent = b.message || 'Failed.'; errEl.style.display = 'block'; return; }
|
||
}
|
||
const res = await Api.patch('/api/v1/org/branding', brandFields);
|
||
if (!res.ok) { const b = await res.json(); errEl.textContent = b.message || 'Failed.'; errEl.style.display = 'block'; return; }
|
||
toast('Branding updated.', 'success');
|
||
Branding.load();
|
||
} catch { errEl.textContent = 'Network error.'; errEl.style.display = 'block'; }
|
||
finally { btn.disabled = false; btn.textContent = 'Save Branding'; }
|
||
});
|
||
|
||
// Users tab
|
||
document.getElementById('invite-btn').addEventListener('click', () => {
|
||
document.getElementById('invite-modal').style.display = 'flex';
|
||
});
|
||
document.getElementById('invite-modal-close').addEventListener('click', () => {
|
||
document.getElementById('invite-modal').style.display = 'none';
|
||
});
|
||
document.getElementById('invite-confirm-btn').addEventListener('click', async () => {
|
||
const errEl = document.getElementById('invite-error'); errEl.style.display = 'none';
|
||
const name = document.getElementById('invite-name').value.trim();
|
||
const email = document.getElementById('invite-email').value.trim();
|
||
const role = document.getElementById('invite-role').value;
|
||
const password = document.getElementById('invite-password').value;
|
||
if (!name || !email || !password) { errEl.textContent = 'All fields required.'; errEl.style.display = 'block'; return; }
|
||
try {
|
||
const res = await Api.post('/api/v1/users', { name, email, role, password });
|
||
if (res.ok) {
|
||
toast('User created.', 'success');
|
||
document.getElementById('invite-modal').style.display = 'none';
|
||
loadUsers();
|
||
} else { const b = await res.json(); errEl.textContent = b.message || 'Failed.'; errEl.style.display = 'block'; }
|
||
} catch { errEl.textContent = 'Network error.'; errEl.style.display = 'block'; }
|
||
});
|
||
});
|
||
</script>
|
||
</body>
|
||
</html>
|