From 1e274cc63f99161e872372ac9c3a25e4e44169ab Mon Sep 17 00:00:00 2001 From: Alexey Safronov Date: Wed, 25 Sep 2019 09:46:45 +0300 Subject: [PATCH] web: People: Added opportunity to delete group --- .../pages/Home/Section/Header/index.js | 12 +++++++----- .../Client/src/store/group/actions.js | 18 ++++++++++++++++++ .../Client/src/store/services/api.js | 4 ++++ 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/products/ASC.People/Client/src/components/pages/Home/Section/Header/index.js b/products/ASC.People/Client/src/components/pages/Home/Section/Header/index.js index bcad97629d..d3a32732c8 100644 --- a/products/ASC.People/Client/src/components/pages/Home/Section/Header/index.js +++ b/products/ASC.People/Client/src/components/pages/Home/Section/Header/index.js @@ -28,7 +28,7 @@ import { resendUserInvites, deleteUsers } from "../../../../../store/services/api"; - +import { deleteGroup } from '../../../../../store/group/actions'; const wrapperStyle = { @@ -53,7 +53,8 @@ const SectionHeaderContent = props => { onLoading, filter, history, - settings + settings, + deleteGroup } = props; const selectedUserIds = getSelectionIds(selection); @@ -150,8 +151,9 @@ const SectionHeaderContent = props => { const onEditGroup = useCallback(() => history.push(`${settings.homepage}/group/edit/${group.id}`), [history, settings, group]); const onDeleteGroup = useCallback(() => { - toastr.success("Delete group action"); - }, []); + deleteGroup(group.id) + .then(() => toastr.success("Group has been removed successfully")); + }, [deleteGroup, group]); const getContextOptions = useCallback(() => { return [ @@ -214,5 +216,5 @@ const mapStateToProps = state => { export default connect( mapStateToProps, - { updateUserStatus, updateUserType, fetchPeople } + { updateUserStatus, updateUserType, fetchPeople, deleteGroup } )(withTranslation()(withRouter(SectionHeaderContent))); diff --git a/products/ASC.People/Client/src/store/group/actions.js b/products/ASC.People/Client/src/store/group/actions.js index f673919a16..470c2cfb2d 100644 --- a/products/ASC.People/Client/src/store/group/actions.js +++ b/products/ASC.People/Client/src/store/group/actions.js @@ -87,3 +87,21 @@ export function updateGroup(id, groupName, groupManager, members) { }); }; } + +export function deleteGroup(id) { + return (dispatch, getState) => { + const { people } = getState(); + const { groups, filter } = people; + + return api + .deleteGroup(id) + .then(res => { + checkResponseError(res); + return dispatch(setGroups(groups.filter(g => g.id !== id))); + }) + .then(() => { + const newFilter = filter.clone(true); + return fetchPeopleByFilter(dispatch, newFilter); + }); + }; +} diff --git a/products/ASC.People/Client/src/store/services/api.js b/products/ASC.People/Client/src/store/services/api.js index bdace944d9..6593d8c947 100644 --- a/products/ASC.People/Client/src/store/services/api.js +++ b/products/ASC.People/Client/src/store/services/api.js @@ -227,3 +227,7 @@ export function updateGroup(id, groupName, groupManager, members) { const group = {groupId: id, groupName, groupManager, members}; return axios.put(`${API_URL}/group/${id}.json`, group); } + +export function deleteGroup(id) { + return axios.delete(`${API_URL}/group/${id}.json`); +}