From 5519c1f54bf42d7c3b11e11d3fcd328799c14d10 Mon Sep 17 00:00:00 2001 From: Krao Hasanee Date: Mon, 30 Mar 2026 09:14:53 -0400 Subject: [PATCH] Surface actual error message when user creation fails Co-Authored-By: Claude Sonnet 4.6 --- src/pages/team/Companies.jsx | 80 ++++++++++++++++++++++++++++++++++-- 1 file changed, 76 insertions(+), 4 deletions(-) diff --git a/src/pages/team/Companies.jsx b/src/pages/team/Companies.jsx index 04dc8d3..a8b901b 100644 --- a/src/pages/team/Companies.jsx +++ b/src/pages/team/Companies.jsx @@ -12,7 +12,10 @@ export default function Companies() { const [loading, setLoading] = useState(true); const [showNew, setShowNew] = useState(false); const [newForm, setNewForm] = useState({ name: '', phone: '', address: '' }); + const [showNewUser, setShowNewUser] = useState(false); + const [userForm, setUserForm] = useState({ name: '', email: '', password: '', company_id: '' }); const [saving, setSaving] = useState(false); + const [userError, setUserError] = useState(''); useEffect(() => { load(); @@ -49,6 +52,29 @@ export default function Companies() { } }; + const handleCreateUser = async (e) => { + e.preventDefault(); + setUserError(''); + setSaving(true); + const { data, error } = await supabase.functions.invoke('create-user', { + body: { + name: userForm.name.trim(), + email: userForm.email.trim(), + password: userForm.password, + company_id: userForm.company_id || null, + }, + }); + setSaving(false); + const errMsg = data?.error || error?.message || (error ? JSON.stringify(error) : null); + if (errMsg) { + setUserError(errMsg); + return; + } + setShowNewUser(false); + setUserForm({ name: '', email: '', password: '', company_id: '' }); + load(); + }; + if (loading) return

Loading...

; const unassigned = profiles.filter(p => !p.company_id); @@ -59,7 +85,7 @@ export default function Companies() {
Companies
- {companies.length} company{companies.length !== 1 ? 'ies' : ''} + {companies.length} {companies.length !== 1 ? 'companies' : 'company'} {unassigned.length > 0 && ( ยท {unassigned.length} unassigned user{unassigned.length !== 1 ? 's' : ''} @@ -67,11 +93,57 @@ export default function Companies() { )}
- +
+ + +
+ {showNewUser && ( +
+
New User
+
+
+
+ + setUserForm(f => ({ ...f, name: e.target.value }))} required autoFocus /> +
+
+ + setUserForm(f => ({ ...f, email: e.target.value }))} required /> +
+
+
+
+ + setUserForm(f => ({ ...f, password: e.target.value }))} required minLength={6} /> +
+
+ + +
+
+ {userError &&

{userError}

} +
+ + +
+
+
+ )} + {showNew && (
New Company