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...