Client - add link to users in admin
This commit is contained in:
@ -9,6 +9,42 @@ import { IAdminUserPayload } from '@/types/user'
|
||||
import { handleError } from '@/utils'
|
||||
|
||||
export const actions: ActionTree<IUsersState, IRootState> & IUsersActions = {
|
||||
[USERS_STORE.ACTIONS.EMPTY_USER](
|
||||
context: ActionContext<IUsersState, IRootState>
|
||||
): void {
|
||||
context.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES)
|
||||
context.commit(USERS_STORE.MUTATIONS.UPDATE_USER, {})
|
||||
},
|
||||
[USERS_STORE.ACTIONS.EMPTY_USERS](
|
||||
context: ActionContext<IUsersState, IRootState>
|
||||
): void {
|
||||
context.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES)
|
||||
context.commit(USERS_STORE.MUTATIONS.UPDATE_USERS, [])
|
||||
context.commit(USERS_STORE.MUTATIONS.UPDATE_USERS_PAGINATION, {})
|
||||
},
|
||||
[USERS_STORE.ACTIONS.GET_USER](
|
||||
context: ActionContext<IUsersState, IRootState>,
|
||||
username: string
|
||||
): void {
|
||||
context.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES)
|
||||
context.commit(USERS_STORE.MUTATIONS.UPDATE_USERS_LOADING, true)
|
||||
authApi
|
||||
.get(`users/${username}`)
|
||||
.then((res) => {
|
||||
if (res.data.status === 'success') {
|
||||
context.commit(
|
||||
USERS_STORE.MUTATIONS.UPDATE_USER,
|
||||
res.data.data.users[0]
|
||||
)
|
||||
} else {
|
||||
handleError(context, null)
|
||||
}
|
||||
})
|
||||
.catch((error) => handleError(context, error))
|
||||
.finally(() =>
|
||||
context.commit(USERS_STORE.MUTATIONS.UPDATE_USERS_LOADING, false)
|
||||
)
|
||||
},
|
||||
[USERS_STORE.ACTIONS.GET_USERS](
|
||||
context: ActionContext<IUsersState, IRootState>,
|
||||
payload: TPaginationPayload
|
||||
|
@ -1,15 +1,20 @@
|
||||
export enum UsersActions {
|
||||
EMPTY_USER = 'EMPTY_USER',
|
||||
EMPTY_USERS = 'EMPTY_USERS',
|
||||
GET_USER = 'GET_USER',
|
||||
GET_USERS = 'GET_USERS',
|
||||
UPDATE_USER = 'UPDATE_USER',
|
||||
}
|
||||
|
||||
export enum UsersGetters {
|
||||
USER = 'USER',
|
||||
USERS = 'USERS',
|
||||
USERS_LOADING = 'USERS_LOADING',
|
||||
USERS_PAGINATION = 'USERS_PAGINATION',
|
||||
}
|
||||
|
||||
export enum UsersMutations {
|
||||
UPDATE_USER = 'UPDATE_USER',
|
||||
UPDATE_USER_IN_USERS = 'UPDATE_USER_IN_USERS',
|
||||
UPDATE_USERS = 'UPDATE_USERS',
|
||||
UPDATE_USERS_LOADING = 'UPDATE_USERS_LOADING',
|
||||
|
@ -5,6 +5,9 @@ import { IRootState } from '@/store/modules/root/types'
|
||||
import { IUsersGetters, IUsersState } from '@/store/modules/users/types'
|
||||
|
||||
export const getters: GetterTree<IUsersState, IRootState> & IUsersGetters = {
|
||||
[USERS_STORE.GETTERS.USER]: (state: IUsersState) => {
|
||||
return state.user
|
||||
},
|
||||
[USERS_STORE.GETTERS.USERS]: (state: IUsersState) => {
|
||||
return state.users
|
||||
},
|
||||
|
@ -6,6 +6,9 @@ import { IPagination } from '@/types/api'
|
||||
import { IUserProfile } from '@/types/user'
|
||||
|
||||
export const mutations: MutationTree<IUsersState> & TUsersMutations = {
|
||||
[USERS_STORE.MUTATIONS.UPDATE_USER](state: IUsersState, user: IUserProfile) {
|
||||
state.user = user
|
||||
},
|
||||
[USERS_STORE.MUTATIONS.UPDATE_USER_IN_USERS](
|
||||
state: IUsersState,
|
||||
updatedUser: IUserProfile
|
||||
|
@ -1,7 +1,9 @@
|
||||
import { IUsersState } from '@/store/modules/users/types'
|
||||
import { IPagination } from '@/types/api'
|
||||
import { IUserProfile } from '@/types/user'
|
||||
|
||||
export const usersState: IUsersState = {
|
||||
user: <IUserProfile>{},
|
||||
users: [],
|
||||
loading: false,
|
||||
pagination: <IPagination>{},
|
||||
|
@ -11,12 +11,23 @@ import { IPagination, TPaginationPayload } from '@/types/api'
|
||||
import { IAdminUserPayload, IUserProfile } from '@/types/user'
|
||||
|
||||
export interface IUsersState {
|
||||
user: IUserProfile
|
||||
users: IUserProfile[]
|
||||
loading: boolean
|
||||
pagination: IPagination
|
||||
}
|
||||
|
||||
export interface IUsersActions {
|
||||
[USERS_STORE.ACTIONS.EMPTY_USER](
|
||||
context: ActionContext<IUsersState, IRootState>
|
||||
): void
|
||||
[USERS_STORE.ACTIONS.EMPTY_USERS](
|
||||
context: ActionContext<IUsersState, IRootState>
|
||||
): void
|
||||
[USERS_STORE.ACTIONS.GET_USER](
|
||||
context: ActionContext<IUsersState, IRootState>,
|
||||
username: string
|
||||
): void
|
||||
[USERS_STORE.ACTIONS.GET_USERS](
|
||||
context: ActionContext<IUsersState, IRootState>,
|
||||
payload: TPaginationPayload
|
||||
@ -28,12 +39,14 @@ export interface IUsersActions {
|
||||
}
|
||||
|
||||
export interface IUsersGetters {
|
||||
[USERS_STORE.GETTERS.USER](state: IUsersState): IUserProfile
|
||||
[USERS_STORE.GETTERS.USERS](state: IUsersState): IUserProfile[]
|
||||
[USERS_STORE.GETTERS.USERS_LOADING](state: IUsersState): boolean
|
||||
[USERS_STORE.GETTERS.USERS_PAGINATION](state: IUsersState): IPagination
|
||||
}
|
||||
|
||||
export type TUsersMutations<S = IUsersState> = {
|
||||
[USERS_STORE.MUTATIONS.UPDATE_USER](state: S, user: IUserProfile): void
|
||||
[USERS_STORE.MUTATIONS.UPDATE_USER_IN_USERS](
|
||||
state: S,
|
||||
updatedUser: IUserProfile
|
||||
|
Reference in New Issue
Block a user