Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Update frontend/src/pages/SuperAdminPanel.jsx
Browse files
frontend/src/pages/SuperAdminPanel.jsx
CHANGED
|
@@ -838,13 +838,14 @@ const SuperAdminPanel = () => {
|
|
| 838 |
...(organizations || []).map(o => ({ label: o.name, value: String(o.id) }))
|
| 839 |
];
|
| 840 |
|
| 841 |
-
setPromptValues({ email: '', role: 'admin', org_id: '' });
|
| 842 |
setPromptModal({
|
| 843 |
isOpen: true,
|
| 844 |
title: 'Add Member',
|
| 845 |
desc: 'Invite or add a new global platform member.',
|
| 846 |
inputs: [
|
| 847 |
{ key: 'email', label: 'User Email', placeholder: 'user@example.com' },
|
|
|
|
| 848 |
{ key: 'role', label: 'Role', type: 'select', options: MEMBER_ROLE_OPTIONS },
|
| 849 |
{ key: 'org_id', label: 'Organization', type: 'select', options: orgOptions }
|
| 850 |
],
|
|
@@ -857,7 +858,12 @@ const SuperAdminPanel = () => {
|
|
| 857 |
const res = await authFetch('/api/auth/users', {
|
| 858 |
method: 'POST',
|
| 859 |
headers: { 'Content-Type': 'application/json' },
|
| 860 |
-
body: JSON.stringify({
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 861 |
});
|
| 862 |
const data = await res.json().catch(() => ({}));
|
| 863 |
if (res.ok) {
|
|
@@ -889,30 +895,36 @@ const SuperAdminPanel = () => {
|
|
| 889 |
setPromptValues({
|
| 890 |
email: u.email,
|
| 891 |
role: u.role || 'admin',
|
| 892 |
-
org_id: initialOrgId
|
|
|
|
| 893 |
});
|
| 894 |
|
| 895 |
setPromptModal({
|
| 896 |
isOpen: true,
|
| 897 |
-
title: 'Edit Member',
|
| 898 |
-
desc: `Update details for ${u.email}`,
|
| 899 |
inputs: [
|
| 900 |
{ key: 'email', label: 'User Email', disabled: true },
|
|
|
|
| 901 |
{ key: 'role', label: 'Role', type: 'select', options: MEMBER_ROLE_OPTIONS },
|
| 902 |
{ key: 'org_id', label: 'Organization', type: 'select', options: orgOptions }
|
| 903 |
],
|
| 904 |
onConfirm: async (vals) => {
|
| 905 |
try {
|
| 906 |
-
const res = await authFetch(`/api/auth/users/${u.id}
|
| 907 |
method: 'PUT',
|
| 908 |
headers: { 'Content-Type': 'application/json' },
|
| 909 |
-
body: JSON.stringify({
|
|
|
|
|
|
|
|
|
|
|
|
|
| 910 |
});
|
|
|
|
| 911 |
if (res.ok) {
|
| 912 |
-
toast.success('Member details updated successfully');
|
| 913 |
fetchStats();
|
| 914 |
} else {
|
| 915 |
-
const data = await res.json();
|
| 916 |
toast.error(data.message || 'Failed to update member');
|
| 917 |
}
|
| 918 |
} catch (err) {
|
|
@@ -1883,7 +1895,7 @@ const SuperAdminPanel = () => {
|
|
| 1883 |
</select>
|
| 1884 |
) : (
|
| 1885 |
<input
|
| 1886 |
-
type="text"
|
| 1887 |
value={promptValues[input.key] || ''}
|
| 1888 |
onChange={(e) => handlePromptChange(input.key, e.target.value)}
|
| 1889 |
placeholder={input.placeholder}
|
|
|
|
| 838 |
...(organizations || []).map(o => ({ label: o.name, value: String(o.id) }))
|
| 839 |
];
|
| 840 |
|
| 841 |
+
setPromptValues({ email: '', password: '', role: 'admin', org_id: '' });
|
| 842 |
setPromptModal({
|
| 843 |
isOpen: true,
|
| 844 |
title: 'Add Member',
|
| 845 |
desc: 'Invite or add a new global platform member.',
|
| 846 |
inputs: [
|
| 847 |
{ key: 'email', label: 'User Email', placeholder: 'user@example.com' },
|
| 848 |
+
{ key: 'password', label: 'Password (Optional - Auto-generated if left blank)', placeholder: 'Set initial password...', type: 'password' },
|
| 849 |
{ key: 'role', label: 'Role', type: 'select', options: MEMBER_ROLE_OPTIONS },
|
| 850 |
{ key: 'org_id', label: 'Organization', type: 'select', options: orgOptions }
|
| 851 |
],
|
|
|
|
| 858 |
const res = await authFetch('/api/auth/users', {
|
| 859 |
method: 'POST',
|
| 860 |
headers: { 'Content-Type': 'application/json' },
|
| 861 |
+
body: JSON.stringify({
|
| 862 |
+
email: values.email.trim(),
|
| 863 |
+
role: values.role,
|
| 864 |
+
org_id: values.org_id || null,
|
| 865 |
+
password: values.password && values.password.trim() ? values.password.trim() : null
|
| 866 |
+
})
|
| 867 |
});
|
| 868 |
const data = await res.json().catch(() => ({}));
|
| 869 |
if (res.ok) {
|
|
|
|
| 895 |
setPromptValues({
|
| 896 |
email: u.email,
|
| 897 |
role: u.role || 'admin',
|
| 898 |
+
org_id: initialOrgId,
|
| 899 |
+
password: ''
|
| 900 |
});
|
| 901 |
|
| 902 |
setPromptModal({
|
| 903 |
isOpen: true,
|
| 904 |
+
title: 'Edit Member & Password',
|
| 905 |
+
desc: `Update details & credentials for ${u.email}`,
|
| 906 |
inputs: [
|
| 907 |
{ key: 'email', label: 'User Email', disabled: true },
|
| 908 |
+
{ key: 'password', label: 'New Password (Leave blank to keep current password)', placeholder: 'Type new password to update...', type: 'password' },
|
| 909 |
{ key: 'role', label: 'Role', type: 'select', options: MEMBER_ROLE_OPTIONS },
|
| 910 |
{ key: 'org_id', label: 'Organization', type: 'select', options: orgOptions }
|
| 911 |
],
|
| 912 |
onConfirm: async (vals) => {
|
| 913 |
try {
|
| 914 |
+
const res = await authFetch(`/api/auth/users/${u.id}`, {
|
| 915 |
method: 'PUT',
|
| 916 |
headers: { 'Content-Type': 'application/json' },
|
| 917 |
+
body: JSON.stringify({
|
| 918 |
+
role: vals.role,
|
| 919 |
+
org_id: vals.org_id || null,
|
| 920 |
+
password: vals.password && vals.password.trim() ? vals.password.trim() : null
|
| 921 |
+
})
|
| 922 |
});
|
| 923 |
+
const data = await res.json().catch(() => ({}));
|
| 924 |
if (res.ok) {
|
| 925 |
+
toast.success('Member details & password updated successfully');
|
| 926 |
fetchStats();
|
| 927 |
} else {
|
|
|
|
| 928 |
toast.error(data.message || 'Failed to update member');
|
| 929 |
}
|
| 930 |
} catch (err) {
|
|
|
|
| 1895 |
</select>
|
| 1896 |
) : (
|
| 1897 |
<input
|
| 1898 |
+
type={input.type || "text"}
|
| 1899 |
value={promptValues[input.key] || ''}
|
| 1900 |
onChange={(e) => handlePromptChange(input.key, e.target.value)}
|
| 1901 |
placeholder={input.placeholder}
|