diff options
Diffstat (limited to 'app/assets/javascripts/vuex_shared/modules/members')
5 files changed, 41 insertions, 2 deletions
diff --git a/app/assets/javascripts/vuex_shared/modules/members/actions.js b/app/assets/javascripts/vuex_shared/modules/members/actions.js index f7fdddfd070..4c31b3c9744 100644 --- a/app/assets/javascripts/vuex_shared/modules/members/actions.js +++ b/app/assets/javascripts/vuex_shared/modules/members/actions.js @@ -1,5 +1,6 @@ import * as types from './mutation_types'; import axios from '~/lib/utils/axios_utils'; +import { formatDate } from '~/lib/utils/datetime_utility'; export const updateMemberRole = async ({ state, commit }, { memberId, accessLevel }) => { try { @@ -23,3 +24,21 @@ export const showRemoveGroupLinkModal = ({ commit }, groupLink) => { export const hideRemoveGroupLinkModal = ({ commit }) => { commit(types.HIDE_REMOVE_GROUP_LINK_MODAL); }; + +export const updateMemberExpiration = async ({ state, commit }, { memberId, expiresAt }) => { + try { + await axios.put( + state.memberPath.replace(':id', memberId), + state.requestFormatter({ expires_at: expiresAt ? formatDate(expiresAt, 'isoDate') : '' }), + ); + + commit(types.RECEIVE_MEMBER_EXPIRATION_SUCCESS, { + memberId, + expiresAt: expiresAt ? formatDate(expiresAt, 'isoUtcDateTime') : null, + }); + } catch (error) { + commit(types.RECEIVE_MEMBER_EXPIRATION_ERROR); + + throw error; + } +}; diff --git a/app/assets/javascripts/vuex_shared/modules/members/index.js b/app/assets/javascripts/vuex_shared/modules/members/index.js index 682e85298ad..586d52a5288 100644 --- a/app/assets/javascripts/vuex_shared/modules/members/index.js +++ b/app/assets/javascripts/vuex_shared/modules/members/index.js @@ -1,6 +1,6 @@ import createState from 'ee_else_ce/vuex_shared/modules/members/state'; -import * as actions from './actions'; -import mutations from './mutations'; +import mutations from 'ee_else_ce/vuex_shared/modules/members/mutations'; +import * as actions from 'ee_else_ce/vuex_shared/modules/members/actions'; export default initialState => ({ namespaced: true, diff --git a/app/assets/javascripts/vuex_shared/modules/members/mutation_types.js b/app/assets/javascripts/vuex_shared/modules/members/mutation_types.js index 00f4c910669..77307aa745b 100644 --- a/app/assets/javascripts/vuex_shared/modules/members/mutation_types.js +++ b/app/assets/javascripts/vuex_shared/modules/members/mutation_types.js @@ -1,6 +1,9 @@ export const RECEIVE_MEMBER_ROLE_SUCCESS = 'RECEIVE_MEMBER_ROLE_SUCCESS'; export const RECEIVE_MEMBER_ROLE_ERROR = 'RECEIVE_MEMBER_ROLE_ERROR'; +export const RECEIVE_MEMBER_EXPIRATION_SUCCESS = 'RECEIVE_MEMBER_EXPIRATION_SUCCESS'; +export const RECEIVE_MEMBER_EXPIRATION_ERROR = 'RECEIVE_MEMBER_EXPIRATION_ERROR'; + export const HIDE_ERROR = 'HIDE_ERROR'; export const SHOW_REMOVE_GROUP_LINK_MODAL = 'SHOW_REMOVE_GROUP_LINK_MODAL'; diff --git a/app/assets/javascripts/vuex_shared/modules/members/mutations.js b/app/assets/javascripts/vuex_shared/modules/members/mutations.js index 281c947e68f..2415e744290 100644 --- a/app/assets/javascripts/vuex_shared/modules/members/mutations.js +++ b/app/assets/javascripts/vuex_shared/modules/members/mutations.js @@ -19,6 +19,21 @@ export default { ); state.showError = true; }, + [types.RECEIVE_MEMBER_EXPIRATION_SUCCESS](state, { memberId, expiresAt }) { + const member = findMember(state, memberId); + + if (!member) { + return; + } + + Vue.set(member, 'expiresAt', expiresAt); + }, + [types.RECEIVE_MEMBER_EXPIRATION_ERROR](state) { + state.errorMessage = s__( + "Members|An error occurred while updating the member's expiration date, please try again.", + ); + state.showError = true; + }, [types.HIDE_ERROR](state) { state.showError = false; state.errorMessage = ''; diff --git a/app/assets/javascripts/vuex_shared/modules/members/state.js b/app/assets/javascripts/vuex_shared/modules/members/state.js index e4867819e17..ab3ebb34616 100644 --- a/app/assets/javascripts/vuex_shared/modules/members/state.js +++ b/app/assets/javascripts/vuex_shared/modules/members/state.js @@ -3,6 +3,7 @@ export default ({ sourceId, currentUserId, tableFields, + tableAttrs, memberPath, requestFormatter, }) => ({ @@ -10,6 +11,7 @@ export default ({ sourceId, currentUserId, tableFields, + tableAttrs, memberPath, requestFormatter, showError: false, |