Client - init administration + refacto
This commit is contained in:
@ -28,4 +28,22 @@ export const actions: ActionTree<IRootState, IRootState> & IRootActions = {
|
||||
context.commit(ROOT_STORE.MUTATIONS.UPDATE_APPLICATION_LOADING, false)
|
||||
)
|
||||
},
|
||||
[ROOT_STORE.ACTIONS.GET_APPLICATION_STATS](
|
||||
context: ActionContext<IRootState, IRootState>
|
||||
): void {
|
||||
context.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES)
|
||||
authApi
|
||||
.get('stats/all')
|
||||
.then((res) => {
|
||||
if (res.data.status === 'success') {
|
||||
context.commit(
|
||||
ROOT_STORE.MUTATIONS.UPDATE_APPLICATION_STATS,
|
||||
res.data.data
|
||||
)
|
||||
} else {
|
||||
handleError(context, null)
|
||||
}
|
||||
})
|
||||
.catch((error) => handleError(context, error))
|
||||
},
|
||||
}
|
||||
|
@ -1,10 +1,12 @@
|
||||
export enum RootActions {
|
||||
GET_APPLICATION_CONFIG = 'GET_APPLICATION_CONFIG',
|
||||
GET_APPLICATION_STATS = 'GET_APPLICATION_STATS',
|
||||
}
|
||||
|
||||
export enum RootGetters {
|
||||
APP_CONFIG = 'APP_CONFIG',
|
||||
APP_LOADING = 'APP_LOADING',
|
||||
APP_STATS = 'APP_STATS',
|
||||
ERROR_MESSAGES = 'ERROR_MESSAGES',
|
||||
LANGUAGE = 'LANGUAGE',
|
||||
LOCALE = 'LOCALE', // date-fns
|
||||
@ -15,5 +17,6 @@ export enum RootMutations {
|
||||
SET_ERROR_MESSAGES = 'SET_ERROR_MESSAGES',
|
||||
UPDATE_APPLICATION_CONFIG = 'UPDATE_APPLICATION_CONFIG',
|
||||
UPDATE_APPLICATION_LOADING = 'UPDATE_APPLICATION_LOADING',
|
||||
UPDATE_APPLICATION_STATS = 'UPDATE_APPLICATION_STATS',
|
||||
UPDATE_LANG = 'UPDATE_LANG',
|
||||
}
|
||||
|
@ -10,6 +10,9 @@ export const getters: GetterTree<IRootState, IRootState> & IRootGetters = {
|
||||
[ROOT_STORE.GETTERS.APP_LOADING]: (state: IRootState) => {
|
||||
return state.appLoading
|
||||
},
|
||||
[ROOT_STORE.GETTERS.APP_STATS]: (state: IRootState) => {
|
||||
return state.application.statistics
|
||||
},
|
||||
[ROOT_STORE.GETTERS.ERROR_MESSAGES]: (state: IRootState) => {
|
||||
return state.errorMessages
|
||||
},
|
||||
|
@ -2,7 +2,7 @@ import { MutationTree } from 'vuex'
|
||||
|
||||
import { ROOT_STORE } from '@/store/constants'
|
||||
import { IRootState, TRootMutations } from '@/store/modules/root/types'
|
||||
import { IAppConfig } from '@/types/application'
|
||||
import { IAppConfig, IAppStatistics } from '@/types/application'
|
||||
import { localeFromLanguage } from '@/utils/locales'
|
||||
|
||||
export const mutations: MutationTree<IRootState> & TRootMutations = {
|
||||
@ -27,6 +27,12 @@ export const mutations: MutationTree<IRootState> & TRootMutations = {
|
||||
) {
|
||||
state.appLoading = loading
|
||||
},
|
||||
[ROOT_STORE.MUTATIONS.UPDATE_APPLICATION_STATS](
|
||||
state: IRootState,
|
||||
statistics: IAppStatistics
|
||||
) {
|
||||
state.application.statistics = statistics
|
||||
},
|
||||
[ROOT_STORE.MUTATIONS.UPDATE_LANG](state: IRootState, language: string) {
|
||||
state.language = language
|
||||
state.locale = localeFromLanguage[language]
|
||||
|
@ -7,7 +7,7 @@ import {
|
||||
} from 'vuex'
|
||||
|
||||
import { ROOT_STORE } from '@/store/constants'
|
||||
import { IAppConfig, IApplication } from '@/types/application'
|
||||
import { IAppConfig, IApplication, IAppStatistics } from '@/types/application'
|
||||
|
||||
export interface IRootState {
|
||||
root: boolean
|
||||
@ -22,6 +22,9 @@ export interface IRootActions {
|
||||
[ROOT_STORE.ACTIONS.GET_APPLICATION_CONFIG](
|
||||
context: ActionContext<IRootState, IRootState>
|
||||
): void
|
||||
[ROOT_STORE.ACTIONS.GET_APPLICATION_STATS](
|
||||
context: ActionContext<IRootState, IRootState>
|
||||
): void
|
||||
}
|
||||
|
||||
export interface IRootGetters {
|
||||
@ -29,6 +32,8 @@ export interface IRootGetters {
|
||||
|
||||
[ROOT_STORE.GETTERS.APP_LOADING](state: IRootState): boolean
|
||||
|
||||
[ROOT_STORE.GETTERS.APP_STATS](state: IRootState): IAppStatistics
|
||||
|
||||
[ROOT_STORE.GETTERS.ERROR_MESSAGES](
|
||||
state: IRootState
|
||||
): string | string[] | null
|
||||
@ -44,6 +49,18 @@ export type TRootMutations<S = IRootState> = {
|
||||
state: S,
|
||||
errorMessages: string
|
||||
): void
|
||||
[ROOT_STORE.MUTATIONS.UPDATE_APPLICATION_CONFIG](
|
||||
state: S,
|
||||
config: IAppConfig
|
||||
): void
|
||||
[ROOT_STORE.MUTATIONS.UPDATE_APPLICATION_LOADING](
|
||||
state: S,
|
||||
loading: boolean
|
||||
): void
|
||||
[ROOT_STORE.MUTATIONS.UPDATE_APPLICATION_STATS](
|
||||
state: S,
|
||||
statistics: IAppStatistics
|
||||
): void
|
||||
[ROOT_STORE.MUTATIONS.UPDATE_LANG](state: S, language: string): void
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,7 @@ export enum UserActions {
|
||||
export enum UserGetters {
|
||||
AUTH_TOKEN = 'AUTH_TOKEN',
|
||||
AUTH_USER_PROFILE = 'AUTH_USER_PROFILE',
|
||||
IS_ADMIN = 'IS_ADMIN',
|
||||
IS_AUTHENTICATED = 'IS_AUTHENTICATED',
|
||||
USER_LOADING = 'USER_LOADING',
|
||||
}
|
||||
|
@ -14,6 +14,9 @@ export const getters: GetterTree<IUserState, IRootState> & IUserGetters = {
|
||||
[USER_STORE.GETTERS.IS_AUTHENTICATED]: (state: IUserState) => {
|
||||
return state.authToken !== null
|
||||
},
|
||||
[USER_STORE.GETTERS.IS_ADMIN]: (state: IUserState) => {
|
||||
return state.authUserProfile && state.authUserProfile.admin
|
||||
},
|
||||
[USER_STORE.GETTERS.USER_LOADING]: (state: IUserState) => {
|
||||
return state.loading
|
||||
},
|
||||
|
@ -82,6 +82,8 @@ export interface IUserGetters {
|
||||
|
||||
[USER_STORE.GETTERS.AUTH_USER_PROFILE](state: IUserState): IAuthUserProfile
|
||||
|
||||
[USER_STORE.GETTERS.IS_ADMIN](state: IUserState): boolean
|
||||
|
||||
[USER_STORE.GETTERS.IS_AUTHENTICATED](state: IUserState): boolean
|
||||
|
||||
[USER_STORE.GETTERS.USER_LOADING](state: IUserState): boolean
|
||||
|
Reference in New Issue
Block a user