This commit is contained in:
@@ -78,6 +78,7 @@ const UserDetailDialog: React.FC<UserDetailDialogProps> = ({
|
|||||||
const [applications, setApplications] = useState<Application[]>([]);
|
const [applications, setApplications] = useState<Application[]>([]);
|
||||||
const [loadingApps, setLoadingApps] = useState(false);
|
const [loadingApps, setLoadingApps] = useState(false);
|
||||||
const [saving, setSaving] = useState(false);
|
const [saving, setSaving] = useState(false);
|
||||||
|
const [togglingActive, setTogglingActive] = useState(false);
|
||||||
const [togglingPermIds, setTogglingPermIds] = useState<Set<number>>(new Set());
|
const [togglingPermIds, setTogglingPermIds] = useState<Set<number>>(new Set());
|
||||||
const { showNotification } = useNotification();
|
const { showNotification } = useNotification();
|
||||||
|
|
||||||
@@ -102,6 +103,20 @@ const UserDetailDialog: React.FC<UserDetailDialogProps> = ({
|
|||||||
}
|
}
|
||||||
}, [tab, user]);
|
}, [tab, user]);
|
||||||
|
|
||||||
|
const handleToggleActive = async (checked: boolean) => {
|
||||||
|
if (!user) return;
|
||||||
|
setTogglingActive(true);
|
||||||
|
const res = await adminService.updateUser(user.id, {
|
||||||
|
active: checked,
|
||||||
|
rate_limit_id: rateLimitId,
|
||||||
|
});
|
||||||
|
setTogglingActive(false);
|
||||||
|
if (res.error) { showNotification(res.error, 'error'); return; }
|
||||||
|
setActive(checked);
|
||||||
|
showNotification(checked ? 'Account enabled' : 'Account disabled', 'success');
|
||||||
|
onUserUpdated();
|
||||||
|
};
|
||||||
|
|
||||||
const handleSaveOverview = async () => {
|
const handleSaveOverview = async () => {
|
||||||
if (!user) return;
|
if (!user) return;
|
||||||
setSaving(true);
|
setSaving(true);
|
||||||
@@ -111,7 +126,7 @@ const UserDetailDialog: React.FC<UserDetailDialogProps> = ({
|
|||||||
});
|
});
|
||||||
setSaving(false);
|
setSaving(false);
|
||||||
if (res.error) { showNotification(res.error, 'error'); return; }
|
if (res.error) { showNotification(res.error, 'error'); return; }
|
||||||
showNotification('User updated', 'success');
|
showNotification('Rate limit updated', 'success');
|
||||||
onUserUpdated();
|
onUserUpdated();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -156,8 +171,8 @@ const UserDetailDialog: React.FC<UserDetailDialogProps> = ({
|
|||||||
<DialogTitle sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>
|
<DialogTitle sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>
|
||||||
{user.username}
|
{user.username}
|
||||||
<Chip
|
<Chip
|
||||||
label={user.active ? 'Active' : 'Disabled'}
|
label={active ? 'Active' : 'Disabled'}
|
||||||
color={user.active ? 'success' : 'error'}
|
color={active ? 'success' : 'error'}
|
||||||
size="small"
|
size="small"
|
||||||
/>
|
/>
|
||||||
</DialogTitle>
|
</DialogTitle>
|
||||||
@@ -173,7 +188,11 @@ const UserDetailDialog: React.FC<UserDetailDialogProps> = ({
|
|||||||
<TabPanel value={tab} index={0}>
|
<TabPanel value={tab} index={0}>
|
||||||
<Stack spacing={3}>
|
<Stack spacing={3}>
|
||||||
<FormControlLabel
|
<FormControlLabel
|
||||||
control={<Switch checked={active} onChange={e => setActive(e.target.checked)} />}
|
control={
|
||||||
|
togglingActive
|
||||||
|
? <Box sx={{ width: 58, display: 'flex', alignItems: 'center', justifyContent: 'center' }}><CircularProgress size={20} /></Box>
|
||||||
|
: <Switch checked={active} onChange={e => handleToggleActive(e.target.checked)} />
|
||||||
|
}
|
||||||
label="Account Active"
|
label="Account Active"
|
||||||
/>
|
/>
|
||||||
<FormControl fullWidth>
|
<FormControl fullWidth>
|
||||||
|
|||||||
Reference in New Issue
Block a user