Client - add application administration

This commit is contained in:
Sam
2021-10-24 20:13:28 +02:00
parent 04cf43cfd2
commit 2ba931dcf7
20 changed files with 351 additions and 28 deletions

View File

@ -1,8 +1,10 @@
import { ActionContext, ActionTree } from 'vuex'
import authApi from '@/api/authApi'
import router from '@/router'
import { ROOT_STORE } from '@/store/constants'
import { IRootActions, IRootState } from '@/store/modules/root/types'
import { TAppConfigForm } from '@/types/application'
import { handleError } from '@/utils'
export const actions: ActionTree<IRootState, IRootState> & IRootActions = {
@ -46,4 +48,24 @@ export const actions: ActionTree<IRootState, IRootState> & IRootActions = {
})
.catch((error) => handleError(context, error))
},
[ROOT_STORE.ACTIONS.UPDATE_APPLICATION_CONFIG](
context: ActionContext<IRootState, IRootState>,
payload: TAppConfigForm
): void {
context.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES)
authApi
.patch('config', payload)
.then((res) => {
if (res.data.status === 'success') {
context.commit(
ROOT_STORE.MUTATIONS.UPDATE_APPLICATION_CONFIG,
res.data.data
)
router.push('/admin/application')
} else {
handleError(context, null)
}
})
.catch((error) => handleError(context, error))
},
}

View File

@ -1,6 +1,7 @@
export enum RootActions {
GET_APPLICATION_CONFIG = 'GET_APPLICATION_CONFIG',
GET_APPLICATION_STATS = 'GET_APPLICATION_STATS',
UPDATE_APPLICATION_CONFIG = 'UPDATE_APPLICATION_CONFIG',
}
export enum RootGetters {

View File

@ -2,7 +2,7 @@ import { MutationTree } from 'vuex'
import { ROOT_STORE } from '@/store/constants'
import { IRootState, TRootMutations } from '@/store/modules/root/types'
import { IAppConfig, IAppStatistics } from '@/types/application'
import { TAppConfig, IAppStatistics } from '@/types/application'
import { localeFromLanguage } from '@/utils/locales'
export const mutations: MutationTree<IRootState> & TRootMutations = {
@ -17,7 +17,7 @@ export const mutations: MutationTree<IRootState> & TRootMutations = {
},
[ROOT_STORE.MUTATIONS.UPDATE_APPLICATION_CONFIG](
state: IRootState,
config: IAppConfig
config: TAppConfig
) {
state.application.config = config
},

View File

@ -7,7 +7,12 @@ import {
} from 'vuex'
import { ROOT_STORE } from '@/store/constants'
import { IAppConfig, IApplication, IAppStatistics } from '@/types/application'
import {
TAppConfig,
IApplication,
IAppStatistics,
TAppConfigForm,
} from '@/types/application'
export interface IRootState {
root: boolean
@ -25,10 +30,14 @@ export interface IRootActions {
[ROOT_STORE.ACTIONS.GET_APPLICATION_STATS](
context: ActionContext<IRootState, IRootState>
): void
[ROOT_STORE.ACTIONS.UPDATE_APPLICATION_CONFIG](
context: ActionContext<IRootState, IRootState>,
payload: TAppConfigForm
): void
}
export interface IRootGetters {
[ROOT_STORE.GETTERS.APP_CONFIG](state: IRootState): IAppConfig
[ROOT_STORE.GETTERS.APP_CONFIG](state: IRootState): TAppConfig
[ROOT_STORE.GETTERS.APP_LOADING](state: IRootState): boolean
@ -51,7 +60,7 @@ export type TRootMutations<S = IRootState> = {
): void
[ROOT_STORE.MUTATIONS.UPDATE_APPLICATION_CONFIG](
state: S,
config: IAppConfig
config: TAppConfig
): void
[ROOT_STORE.MUTATIONS.UPDATE_APPLICATION_LOADING](
state: S,