Compare commits

..

No commits in common. "b6447d4d21e7e682ef320495862b7eb729fb5e77" and "3efb9a76f58ab39f8ea9ae11aa800b230e75b01e" have entirely different histories.

2 changed files with 7 additions and 27 deletions

View file

@ -89,11 +89,11 @@ module.exports = (pool, query, authMiddleware) => {
} }
}); });
// Update user (admin can update is_disabled, is_admin and internal_notes) // Update user (admin can update is_disabled and internal_notes)
router.patch('/:id', async (req, res, next) => { router.patch('/:id', async (req, res, next) => {
try { try {
const { id } = req.params; const { id } = req.params;
const { is_disabled, internal_notes, is_admin} = req.body; const { is_disabled, internal_notes } = req.body;
// Check if user is admin // Check if user is admin
if (!req.user.is_admin) { if (!req.user.is_admin) {
@ -118,14 +118,12 @@ module.exports = (pool, query, authMiddleware) => {
UPDATE users UPDATE users
SET SET
is_disabled = $1, is_disabled = $1,
internal_notes = $2, internal_notes = $2
is_admin = $3 WHERE id = $3
WHERE id = $4
RETURNING id, email, first_name, last_name, is_admin, is_disabled, internal_notes RETURNING id, email, first_name, last_name, is_admin, is_disabled, internal_notes
`, [ `, [
is_disabled !== undefined ? is_disabled : userCheck.rows[0].is_disabled, is_disabled !== undefined ? is_disabled : userCheck.rows[0].is_disabled,
internal_notes !== undefined ? internal_notes : userCheck.rows[0].internal_notes, internal_notes !== undefined ? internal_notes : userCheck.rows[0].internal_notes,
is_admin !== undefined ? is_admin : userCheck.rows[0].is_admin,
id id
]); ]);

View file

@ -37,9 +37,8 @@ import {
import { useAdminUsers, useUpdateUser } from '@hooks/adminHooks'; import { useAdminUsers, useUpdateUser } from '@hooks/adminHooks';
import { format } from 'date-fns'; import { format } from 'date-fns';
import EmailDialog from '@components/EmailDialog'; import EmailDialog from '@components/EmailDialog';
import { useAuth } from '@hooks/reduxHooks';
const AdminCustomersPage = () => { const AdminCustomersPage = () => {
const { user, isAuthenticated } = useAuth();
const [page, setPage] = useState(0); const [page, setPage] = useState(0);
const [rowsPerPage, setRowsPerPage] = useState(10); const [rowsPerPage, setRowsPerPage] = useState(10);
const [search, setSearch] = useState(''); const [search, setSearch] = useState('');
@ -49,7 +48,6 @@ const AdminCustomersPage = () => {
const [emailRecipient, setEmailRecipient] = useState(null); const [emailRecipient, setEmailRecipient] = useState(null);
const [formData, setFormData] = useState({ const [formData, setFormData] = useState({
is_disabled: false, is_disabled: false,
is_admin: false,
internal_notes: '' internal_notes: ''
}); });
@ -101,7 +99,6 @@ const AdminCustomersPage = () => {
setCurrentUser(user); setCurrentUser(user);
setFormData({ setFormData({
is_disabled: user.is_disabled, is_disabled: user.is_disabled,
is_admin: user.is_admin,
internal_notes: user.internal_notes || '' internal_notes: user.internal_notes || ''
}); });
setEditDialogOpen(true); setEditDialogOpen(true);
@ -130,7 +127,7 @@ const AdminCustomersPage = () => {
const { name, value, checked } = e.target; const { name, value, checked } = e.target;
setFormData(prev => ({ setFormData(prev => ({
...prev, ...prev,
[name]: name === 'is_disabled' || name === 'is_admin' ? checked : value [name]: name === 'is_disabled' ? checked : value
})); }));
}; };
@ -329,28 +326,13 @@ const AdminCustomersPage = () => {
<Switch <Switch
checked={formData.is_disabled} checked={formData.is_disabled}
onChange={handleFormChange} onChange={handleFormChange}
disabled={user === currentUser.id}
name="is_disabled" name="is_disabled"
color="error" color="error"
/> />
} }
label={`${formData.is_disabled ? "Account is disabled" : "Account is active"}` + `${user === currentUser.id && formData.is_admin? " (Current user can\'t disabled themselves)" : "" }`} label={formData.is_disabled ? "Account is disabled" : "Account is active"}
sx={{ my: 2, display: 'block' }} sx={{ my: 2, display: 'block' }}
/> />
<FormControlLabel
control={
<Switch
checked={formData.is_admin}
onChange={handleFormChange}
disabled={user === currentUser.id && formData.is_admin}
name="is_admin"
color="error"
/>
}
label={`${formData.is_admin ? "Account is Admin" : "Account is not Admin"}` + `${user === currentUser.id && formData.is_admin? " (Admin can't downgrade themselves)" : "" }`}
sx={{ my: 2, display: 'block' }}
/>
<TextField <TextField
autoFocus autoFocus