Delete users #4
@ -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>
|
<td>
|
||||||
<UserEdit
|
<UserEdit
|
||||||
id={id}
|
id={id}
|
||||||
|
name={name}
|
||||||
admin={admin}
|
admin={admin}
|
||||||
activated={activated}
|
activated={activated}
|
||||||
polochonActivated={polochonActivated}
|
polochonActivated={polochonActivated}
|
||||||
|
@ -3,7 +3,7 @@ import PropTypes from "prop-types"
|
|||||||
import { connect } from "react-redux"
|
import { connect } from "react-redux"
|
||||||
import { List } from "immutable"
|
import { List } from "immutable"
|
||||||
|
|
||||||
import { updateUser } from "../../actions/admins"
|
import { updateUser, deleteUser } from "../../actions/admins"
|
||||||
|
|
||||||
import Toggle from "react-bootstrap-toggle";
|
import Toggle from "react-bootstrap-toggle";
|
||||||
|
|
||||||
@ -13,12 +13,14 @@ import { FormInput } from "../forms/input"
|
|||||||
|
|
||||||
const UserEditConnect = ({
|
const UserEditConnect = ({
|
||||||
id,
|
id,
|
||||||
|
name,
|
||||||
admin: initAdmin,
|
admin: initAdmin,
|
||||||
activated: initActivated,
|
activated: initActivated,
|
||||||
polochonToken,
|
polochonToken,
|
||||||
polochonId: initPolochonId,
|
polochonId: initPolochonId,
|
||||||
polochonActivated: initPolochonActivated,
|
polochonActivated: initPolochonActivated,
|
||||||
updateUser,
|
updateUser,
|
||||||
|
deleteUser,
|
||||||
publicPolochons,
|
publicPolochons,
|
||||||
}) => {
|
}) => {
|
||||||
const [modal, setModal] = useState(false);
|
const [modal, setModal] = useState(false);
|
||||||
@ -28,8 +30,9 @@ const UserEditConnect = ({
|
|||||||
const [polochonId, setPolochonId] = useState(initPolochonId);
|
const [polochonId, setPolochonId] = useState(initPolochonId);
|
||||||
const [polochonActivated, setPolochonActivated] = useState(initPolochonActivated);
|
const [polochonActivated, setPolochonActivated] = useState(initPolochonActivated);
|
||||||
const [password, setPassword] = useState("");
|
const [password, setPassword] = useState("");
|
||||||
|
const [confirmDelete, setConfirmDelete] = useState(false);
|
||||||
|
|
||||||
const handleSubmit = function(e) {
|
const handleSubmit = (e) => {
|
||||||
if (e) { e.preventDefault(); }
|
if (e) { e.preventDefault(); }
|
||||||
updateUser({
|
updateUser({
|
||||||
userId: id,
|
userId: id,
|
||||||
@ -43,6 +46,16 @@ const UserEditConnect = ({
|
|||||||
setModal(false);
|
setModal(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleDeleteUser = (e) => {
|
||||||
|
if (e) { e.preventDefault(); }
|
||||||
|
if (confirmDelete) {
|
||||||
|
deleteUser(name)
|
||||||
|
setModal(false)
|
||||||
|
} else {
|
||||||
|
setConfirmDelete(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span>
|
<span>
|
||||||
<i
|
<i
|
||||||
@ -81,16 +94,23 @@ const UserEditConnect = ({
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className="form-group">
|
||||||
|
<button className="btn btn-danger w-100" onClick={handleDeleteUser}>
|
||||||
|
{!confirmDelete ? "Delete user forever" : "Are you sure ?"}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
</FormModal>
|
</FormModal>
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
UserEditConnect.propTypes = {
|
UserEditConnect.propTypes = {
|
||||||
id: PropTypes.string,
|
id: PropTypes.string,
|
||||||
|
name: PropTypes.string,
|
||||||
activated: PropTypes.bool,
|
activated: PropTypes.bool,
|
||||||
admin: PropTypes.bool,
|
admin: PropTypes.bool,
|
||||||
data: PropTypes.object,
|
|
||||||
updateUser: PropTypes.func,
|
updateUser: PropTypes.func,
|
||||||
|
deleteUser: PropTypes.func,
|
||||||
polochonToken: PropTypes.string,
|
polochonToken: PropTypes.string,
|
||||||
polochonId: PropTypes.string,
|
polochonId: PropTypes.string,
|
||||||
polochonActivated: PropTypes.bool,
|
polochonActivated: PropTypes.bool,
|
||||||
@ -101,4 +121,4 @@ const mapStateToProps = (state) => ({
|
|||||||
publicPolochons: state.polochon.get("public"),
|
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