AuthorBot commited on
Commit
2bbde84
·
1 Parent(s): 6d85d9d

Improve: Create Author flow - success modal with details + redirect to Grant Access with pre-filled email

Browse files
app/superadmin/templates/superadmin.html CHANGED
@@ -672,22 +672,65 @@ async function executeCreateAuthor() {
672
  if (!name || !email || !pass) { toast('Please fill in all required fields', 'error'); return; }
673
  if (pass.length < 8) { toast('Password must be at least 8 characters', 'error'); return; }
674
 
 
 
 
 
675
  try {
676
  const body = { email, password: pass, full_name: name };
677
  if (plan) { body.plan = plan; body.auto_renew = autoRenew; }
678
  const result = await apiPost('/super/authors', body);
679
  closeModal();
680
- let msg = `Author "${name}" created successfully`;
681
- if (result.subscription) msg += ` with ${plan} plan`;
682
- toast(msg, 'success');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
683
  loadAuthors();
684
  loadOverview();
685
  } catch(e) {
686
  console.error('Create author error:', e);
 
687
  toast(e.message || 'Failed to create author', 'error');
688
  }
689
  }
690
 
 
 
 
 
 
 
 
 
691
  /* SUBSCRIPTIONS — now powered by /super/grants */
692
  let allGrants = [];
693
  async function loadSubscriptions() {
 
672
  if (!name || !email || !pass) { toast('Please fill in all required fields', 'error'); return; }
673
  if (pass.length < 8) { toast('Password must be at least 8 characters', 'error'); return; }
674
 
675
+ // Disable button during request
676
+ const btn = document.querySelector('#modal-content .btn-primary');
677
+ if (btn) { btn.disabled = true; btn.textContent = 'Creating...'; }
678
+
679
  try {
680
  const body = { email, password: pass, full_name: name };
681
  if (plan) { body.plan = plan; body.auto_renew = autoRenew; }
682
  const result = await apiPost('/super/authors', body);
683
  closeModal();
684
+
685
+ // Show success confirmation with next steps
686
+ const hasSub = result.subscription;
687
+ const subInfo = hasSub
688
+ ? `<div style="margin-top:16px;padding:14px;background:var(--green-bg);border-radius:var(--radius-sm);font-size:13px;">
689
+ <strong>✅ Subscription Assigned</strong><br>
690
+ Plan: <strong>${plan}</strong> · Auto-renew: ${autoRenew ? 'Yes' : 'No'}<br>
691
+ ${result.subscription.expires_at ? 'Expires: ' + new Date(result.subscription.expires_at).toLocaleDateString() : ''}
692
+ </div>`
693
+ : `<div style="margin-top:16px;padding:14px;background:var(--yellow-bg);border-radius:var(--radius-sm);font-size:13px;">
694
+ <strong>⚠️ No subscription assigned yet.</strong><br>
695
+ The author needs a subscription plan before their chatbot can go live.
696
+ </div>`;
697
+
698
+ showModal('✅ Author Created Successfully',
699
+ `<div style="font-size:14px;line-height:1.8;">
700
+ <div style="display:grid;grid-template-columns:auto 1fr;gap:8px 16px;margin-top:12px;">
701
+ <span class="text-muted">Name:</span> <strong>${esc(name)}</strong>
702
+ <span class="text-muted">Email:</span> <strong>${esc(email)}</strong>
703
+ <span class="text-muted">Author ID:</span> <code style="font-size:11px;background:var(--surface2);padding:2px 8px;border-radius:4px;">${result.author_id || '—'}</code>
704
+ </div>
705
+ ${subInfo}
706
+ <div style="margin-top:16px;padding:12px;background:var(--surface2);border-radius:var(--radius-sm);font-size:12px;color:var(--muted);">
707
+ <strong>Login credentials:</strong> The author can now sign in at <code>/admin</code> with the email and password you just set.
708
+ </div>
709
+ </div>`,
710
+ hasSub
711
+ ? `<button class="btn btn-secondary" onclick="closeModal()">Done</button>
712
+ <button class="btn btn-primary" onclick="closeModal(); nav('authors');">View Authors</button>`
713
+ : `<button class="btn btn-secondary" onclick="closeModal()">Skip for Now</button>
714
+ <button class="btn btn-primary" onclick="closeModal(); prefillGrant('${esc(email)}');">Assign Subscription →</button>`
715
+ );
716
+
717
  loadAuthors();
718
  loadOverview();
719
  } catch(e) {
720
  console.error('Create author error:', e);
721
+ if (btn) { btn.disabled = false; btn.textContent = 'Create Author'; }
722
  toast(e.message || 'Failed to create author', 'error');
723
  }
724
  }
725
 
726
+ function prefillGrant(email) {
727
+ nav('grant');
728
+ setTimeout(function() {
729
+ const el = document.getElementById('g-email');
730
+ if (el) { el.value = email; el.focus(); }
731
+ }, 100);
732
+ }
733
+
734
  /* SUBSCRIPTIONS — now powered by /super/grants */
735
  let allGrants = [];
736
  async function loadSubscriptions() {