From a6202e7460b5a5b1e65f194bcb6ed38c8048b0aa Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Fri, 30 Oct 2020 21:23:23 +0300 Subject: [PATCH] Add dropdown for changing report's state and moderating user --- src/store/modules/reports.js | 64 ++++++++++++++++--- .../components/ModerateUserDropdown.vue | 31 +++++++-- src/views/reports/components/Report.vue | 12 ++-- src/views/reports/show.vue | 48 +++++++++++++- 4 files changed, 134 insertions(+), 21 deletions(-) diff --git a/src/store/modules/reports.js b/src/store/modules/reports.js index 51f08219..c42fa894 100644 --- a/src/store/modules/reports.js +++ b/src/store/modules/reports.js @@ -59,6 +59,17 @@ const reports = { } dispatch('SuccessMessage') }, + async ActivateUserFromReportShow({ commit, dispatch, getters, state }, user) { + try { + await activateUsers([user.nickname], getters.authHost, getters.token) + } catch (_e) { + return + } finally { + const updatedReport = { ...state.singleReport, account: { ...user, deactivated: false }} + commit('SET_SINGLE_REPORT', updatedReport) + } + dispatch('SuccessMessage') + }, async AddTagFromReports({ commit, dispatch, getters, state }, { user, tag, reportId }) { try { await tagUser([user.nickname], [tag], getters.authHost, getters.token) @@ -73,16 +84,31 @@ const reports = { } dispatch('SuccessMessage') }, + async AddTagFromReportsFromReportShow({ commit, dispatch, getters, state }, { user, tag }) { + try { + await tagUser([user.nickname], [tag], getters.authHost, getters.token) + } catch (_e) { + return + } finally { + const updatedReport = { ...state.singleReport, account: { ...user, tags: [...user.tags, tag] }} + commit('SET_SINGLE_REPORT', updatedReport) + } + dispatch('SuccessMessage') + }, async ChangeReportState({ commit, dispatch, getters, state }, reportsData) { - changeState(reportsData, getters.authHost, getters.token) + try { + await changeState(reportsData, getters.authHost, getters.token) + } catch (_e) { + return + } finally { + const updatedReports = state.fetchedReports.map(report => { + const updatedReportsIds = reportsData.map(({ id }) => id) + return updatedReportsIds.includes(report.id) ? { ...report, state: reportsData[0].state } : report + }) - const updatedReports = state.fetchedReports.map(report => { - const updatedReportsIds = reportsData.map(({ id }) => id) - return updatedReportsIds.includes(report.id) ? { ...report, state: reportsData[0].state } : report - }) - - commit('SET_REPORTS', updatedReports) - dispatch('FetchOpenReportsCount') + commit('SET_REPORTS', updatedReports) + dispatch('FetchOpenReportsCount') + } }, ClearFetchedReports({ commit }) { commit('SET_REPORTS', []) @@ -101,6 +127,17 @@ const reports = { } dispatch('SuccessMessage') }, + async DeactivateUserFromReportShow({ commit, dispatch, getters, state }, user) { + try { + await deactivateUsers([user.nickname], getters.authHost, getters.token) + } catch (_e) { + return + } finally { + const updatedReport = { ...state.singleReport, account: { ...user, deactivated: true }} + commit('SET_SINGLE_REPORT', updatedReport) + } + dispatch('SuccessMessage') + }, async DeleteUserFromReports({ commit, dispatch, getters, state }, { user, reportId }) { try { await deleteUsers([user.nickname], getters.authHost, getters.token) @@ -152,6 +189,17 @@ const reports = { } dispatch('SuccessMessage') }, + async RemoveTagFromReportsFromReportShow({ commit, dispatch, getters, state }, { user, tag }) { + try { + await untagUser([user.nickname], [tag], getters.authHost, getters.token) + } catch (_e) { + return + } finally { + const updatedReport = { ...state.singleReport, account: { ...user, tags: user.tags.filter(userTag => userTag !== tag) }} + commit('SET_SINGLE_REPORT', updatedReport) + } + dispatch('SuccessMessage') + }, SetReportsFilter({ commit }, filter) { commit('SET_REPORTS_FILTER', filter) }, diff --git a/src/views/reports/components/ModerateUserDropdown.vue b/src/views/reports/components/ModerateUserDropdown.vue index 9e7fb0ec..2608b540 100644 --- a/src/views/reports/components/ModerateUserDropdown.vue +++ b/src/views/reports/components/ModerateUserDropdown.vue @@ -1,6 +1,7 @@