Allow the admins to delete users
This commit is contained in:
parent
7dee9e0a7c
commit
aa6059b1c7
@ -30,3 +30,13 @@ export function updateUser(data) {
|
||||
]
|
||||
)
|
||||
}
|
||||
|
||||
export function deleteUser(username) {
|
||||
return request(
|
||||
"ADMIN_DELETE_USER",
|
||||
configureAxios().delete("/admins/users/"+ username),
|
||||
[
|
||||
() => getUsers(),
|
||||
]
|
||||
)
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ export const User = ({
|
||||
<td>
|
||||
<UserEdit
|
||||
id={id}
|
||||
name={name}
|
||||
admin={admin}
|
||||
activated={activated}
|
||||
polochonActivated={polochonActivated}
|
||||
|
@ -3,7 +3,7 @@ import PropTypes from "prop-types"
|
||||
import { connect } from "react-redux"
|
||||
import { List } from "immutable"
|
||||
|
||||
import { updateUser } from "../../actions/admins"
|
||||
import { updateUser, deleteUser } from "../../actions/admins"
|
||||
|
||||
import Toggle from "react-bootstrap-toggle";
|
||||
|
||||
@ -13,12 +13,14 @@ import { FormInput } from "../forms/input"
|
||||
|
||||
const UserEditConnect = ({
|
||||
id,
|
||||
name,
|
||||
admin: initAdmin,
|
||||
activated: initActivated,
|
||||
polochonToken,
|
||||
polochonId: initPolochonId,
|
||||
polochonActivated: initPolochonActivated,
|
||||
updateUser,
|
||||
deleteUser,
|
||||
publicPolochons,
|
||||
}) => {
|
||||
const [modal, setModal] = useState(false);
|
||||
@ -28,8 +30,9 @@ const UserEditConnect = ({
|
||||
const [polochonId, setPolochonId] = useState(initPolochonId);
|
||||
const [polochonActivated, setPolochonActivated] = useState(initPolochonActivated);
|
||||
const [password, setPassword] = useState("");
|
||||
const [confirmDelete, setConfirmDelete] = useState(false);
|
||||
|
||||
const handleSubmit = function(e) {
|
||||
const handleSubmit = (e) => {
|
||||
if (e) { e.preventDefault(); }
|
||||
updateUser({
|
||||
userId: id,
|
||||
@ -43,6 +46,16 @@ const UserEditConnect = ({
|
||||
setModal(false);
|
||||
};
|
||||
|
||||
const handleDeleteUser = (e) => {
|
||||
if (e) { e.preventDefault(); }
|
||||
if (confirmDelete) {
|
||||
deleteUser(name)
|
||||
setModal(false)
|
||||
} else {
|
||||
setConfirmDelete(true)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<span>
|
||||
<i
|
||||
@ -81,16 +94,23 @@ const UserEditConnect = ({
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<button className="btn btn-danger w-100" onClick={handleDeleteUser}>
|
||||
{!confirmDelete ? "Delete user forever" : "Are you sure ?"}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
</FormModal>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
UserEditConnect.propTypes = {
|
||||
id: PropTypes.string,
|
||||
name: PropTypes.string,
|
||||
activated: PropTypes.bool,
|
||||
admin: PropTypes.bool,
|
||||
data: PropTypes.object,
|
||||
updateUser: PropTypes.func,
|
||||
deleteUser: PropTypes.func,
|
||||
polochonToken: PropTypes.string,
|
||||
polochonId: PropTypes.string,
|
||||
polochonActivated: PropTypes.bool,
|
||||
@ -101,4 +121,4 @@ const mapStateToProps = (state) => ({
|
||||
publicPolochons: state.polochon.get("public"),
|
||||
});
|
||||
|
||||
export const UserEdit = connect(mapStateToProps, {updateUser})(UserEditConnect);
|
||||
export const UserEdit = connect(mapStateToProps, {updateUser, deleteUser})(UserEditConnect);
|
||||
|
Loading…
x
Reference in New Issue
Block a user