Client - fix redirection after deleting user account in admin
This commit is contained in:
@ -47,7 +47,7 @@
|
||||
import { format } from 'date-fns'
|
||||
import { ComputedRef, Ref, computed, ref, toRefs, withDefaults } from 'vue'
|
||||
|
||||
import { AUTH_USER_STORE } from '@/store/constants'
|
||||
import { AUTH_USER_STORE, USERS_STORE } from '@/store/constants'
|
||||
import { IUserProfile } from '@/types/user'
|
||||
import { useStore } from '@/use/useStore'
|
||||
|
||||
@ -81,7 +81,7 @@
|
||||
displayModal.value = value
|
||||
}
|
||||
function deleteUserAccount(username: string) {
|
||||
store.dispatch(AUTH_USER_STORE.ACTIONS.DELETE_ACCOUNT, { username })
|
||||
store.dispatch(USERS_STORE.ACTIONS.DELETE_USER_ACCOUNT, { username })
|
||||
}
|
||||
</script>
|
||||
|
||||
|
@ -17,6 +17,7 @@ import {
|
||||
IAuthUserState,
|
||||
} from '@/store/modules/authUser/types'
|
||||
import { IRootState } from '@/store/modules/root/types'
|
||||
import { deleteUserAccount } from '@/store/modules/users/actions'
|
||||
import {
|
||||
ILoginOrRegisterData,
|
||||
IUserDeletionPayload,
|
||||
@ -228,19 +229,7 @@ export const actions: ActionTree<IAuthUserState, IRootState> &
|
||||
context: ActionContext<IAuthUserState, IRootState>,
|
||||
payload: IUserDeletionPayload
|
||||
): void {
|
||||
context.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES)
|
||||
authApi
|
||||
.delete(`users/${payload.username}`)
|
||||
.then((res) => {
|
||||
if (res.status === 204) {
|
||||
context
|
||||
.dispatch(AUTH_USER_STORE.ACTIONS.LOGOUT)
|
||||
.then(() => router.push('/'))
|
||||
} else {
|
||||
handleError(context, null)
|
||||
}
|
||||
})
|
||||
.catch((error) => handleError(context, error))
|
||||
deleteUserAccount(context, payload)
|
||||
},
|
||||
[AUTH_USER_STORE.ACTIONS.DELETE_PICTURE](
|
||||
context: ActionContext<IAuthUserState, IRootState>
|
||||
|
@ -1,13 +1,40 @@
|
||||
import { ActionContext, ActionTree } from 'vuex'
|
||||
|
||||
import authApi from '@/api/authApi'
|
||||
import { ROOT_STORE, USERS_STORE } from '@/store/constants'
|
||||
import router from '@/router'
|
||||
import { AUTH_USER_STORE, ROOT_STORE, USERS_STORE } from '@/store/constants'
|
||||
import { IAuthUserState } from '@/store/modules/authUser/types'
|
||||
import { IRootState } from '@/store/modules/root/types'
|
||||
import { IUsersActions, IUsersState } from '@/store/modules/users/types'
|
||||
import { TPaginationPayload } from '@/types/api'
|
||||
import { IAdminUserPayload } from '@/types/user'
|
||||
import { IAdminUserPayload, IUserDeletionPayload } from '@/types/user'
|
||||
import { handleError } from '@/utils'
|
||||
|
||||
export const deleteUserAccount = (
|
||||
context:
|
||||
| ActionContext<IAuthUserState, IRootState>
|
||||
| ActionContext<IUsersState, IRootState>,
|
||||
payload: IUserDeletionPayload
|
||||
): void => {
|
||||
context.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES)
|
||||
authApi
|
||||
.delete(`users/${payload.username}`)
|
||||
.then((res) => {
|
||||
if (res.status === 204) {
|
||||
if (payload.fromAdmin) {
|
||||
router.push('/admin/users')
|
||||
} else {
|
||||
context
|
||||
.dispatch(AUTH_USER_STORE.ACTIONS.LOGOUT)
|
||||
.then(() => router.push('/'))
|
||||
}
|
||||
} else {
|
||||
handleError(context, null)
|
||||
}
|
||||
})
|
||||
.catch((error) => handleError(context, error))
|
||||
}
|
||||
|
||||
export const actions: ActionTree<IUsersState, IRootState> & IUsersActions = {
|
||||
[USERS_STORE.ACTIONS.EMPTY_USER](
|
||||
context: ActionContext<IUsersState, IRootState>
|
||||
@ -94,4 +121,13 @@ export const actions: ActionTree<IUsersState, IRootState> & IUsersActions = {
|
||||
context.commit(USERS_STORE.MUTATIONS.UPDATE_USERS_LOADING, false)
|
||||
)
|
||||
},
|
||||
[USERS_STORE.ACTIONS.DELETE_USER_ACCOUNT](
|
||||
context: ActionContext<IUsersState, IRootState>,
|
||||
payload: IUserDeletionPayload
|
||||
): void {
|
||||
deleteUserAccount(context, {
|
||||
username: payload.username,
|
||||
fromAdmin: true,
|
||||
})
|
||||
},
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ export enum UsersActions {
|
||||
GET_USER = 'GET_USER',
|
||||
GET_USERS = 'GET_USERS',
|
||||
UPDATE_USER = 'UPDATE_USER',
|
||||
DELETE_USER_ACCOUNT = 'DELETE_USER_ACCOUNT',
|
||||
}
|
||||
|
||||
export enum UsersGetters {
|
||||
|
@ -8,7 +8,11 @@ import {
|
||||
import { USERS_STORE } from '@/store/constants'
|
||||
import { IRootState } from '@/store/modules/root/types'
|
||||
import { IPagination, TPaginationPayload } from '@/types/api'
|
||||
import { IAdminUserPayload, IUserProfile } from '@/types/user'
|
||||
import {
|
||||
IAdminUserPayload,
|
||||
IUserDeletionPayload,
|
||||
IUserProfile,
|
||||
} from '@/types/user'
|
||||
|
||||
export interface IUsersState {
|
||||
user: IUserProfile
|
||||
@ -36,6 +40,10 @@ export interface IUsersActions {
|
||||
context: ActionContext<IUsersState, IRootState>,
|
||||
payload: IAdminUserPayload
|
||||
): void
|
||||
[USERS_STORE.ACTIONS.DELETE_USER_ACCOUNT](
|
||||
context: ActionContext<IUsersState, IRootState>,
|
||||
payload: IUserDeletionPayload
|
||||
): void
|
||||
}
|
||||
|
||||
export interface IUsersGetters {
|
||||
|
@ -68,6 +68,7 @@ export interface IUserPasswordResetPayload {
|
||||
|
||||
export interface IUserDeletionPayload {
|
||||
username: string
|
||||
fromAdmin?: boolean
|
||||
}
|
||||
|
||||
export interface ILoginRegisterFormData {
|
||||
|
Reference in New Issue
Block a user