Client - get application config
This commit is contained in:
@ -1,4 +1,8 @@
|
||||
import { RootGetters, RootMutations } from '@/store/modules/root/enums'
|
||||
import {
|
||||
RootActions,
|
||||
RootGetters,
|
||||
RootMutations,
|
||||
} from '@/store/modules/root/enums'
|
||||
import {
|
||||
UserActions,
|
||||
UserGetters,
|
||||
@ -6,6 +10,7 @@ import {
|
||||
} from '@/store/modules/user/enums'
|
||||
|
||||
export const ROOT_STORE = {
|
||||
ACTIONS: RootActions,
|
||||
GETTERS: RootGetters,
|
||||
MUTATIONS: RootMutations,
|
||||
}
|
||||
|
27
fittrackee_client/src/store/modules/root/actions.ts
Normal file
27
fittrackee_client/src/store/modules/root/actions.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import { ActionContext, ActionTree } from 'vuex'
|
||||
|
||||
import { ROOT_STORE } from '@/store/constants'
|
||||
import { IRootActions, IRootState } from '@/store/modules/root/interfaces'
|
||||
import authApi from '@/api/authApi'
|
||||
import { handleError } from '@/utils'
|
||||
|
||||
export const actions: ActionTree<IRootState, IRootState> & IRootActions = {
|
||||
[ROOT_STORE.ACTIONS.GET_APPLICATION_CONFIG](
|
||||
context: ActionContext<IRootState, IRootState>
|
||||
): void {
|
||||
context.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES)
|
||||
authApi
|
||||
.get('config')
|
||||
.then((res) => {
|
||||
if (res.data.status === 'success') {
|
||||
context.commit(
|
||||
ROOT_STORE.MUTATIONS.UPDATE_APPLICATION_CONFIG,
|
||||
res.data.data
|
||||
)
|
||||
} else {
|
||||
handleError(context, null)
|
||||
}
|
||||
})
|
||||
.catch((error) => handleError(context, error))
|
||||
},
|
||||
}
|
@ -1,3 +1,7 @@
|
||||
export enum RootActions {
|
||||
GET_APPLICATION_CONFIG = 'GET_APPLICATION_CONFIG',
|
||||
}
|
||||
|
||||
export enum RootGetters {
|
||||
ERROR_MESSAGES = 'ERROR_MESSAGES',
|
||||
LANGUAGE = 'LANGUAGE',
|
||||
@ -6,5 +10,6 @@ export enum RootGetters {
|
||||
export enum RootMutations {
|
||||
EMPTY_ERROR_MESSAGES = 'EMPTY_ERROR_MESSAGES',
|
||||
SET_ERROR_MESSAGES = 'SET_ERROR_MESSAGES',
|
||||
UPDATE_APPLICATION_CONFIG = 'UPDATE_APPLICATION_CONFIG',
|
||||
UPDATE_LANG = 'UPDATE_LANG',
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { Module, ModuleTree } from 'vuex'
|
||||
|
||||
import { actions } from '@/store/modules/root/actions'
|
||||
import { getters } from '@/store/modules/root/getters'
|
||||
import { IRootState } from '@/store/modules/root/interfaces'
|
||||
import { mutations } from '@/store/modules/root/mutations'
|
||||
@ -12,6 +13,7 @@ const modules: ModuleTree<IRootState> = {
|
||||
|
||||
const root: Module<IRootState, IRootState> = {
|
||||
state,
|
||||
actions,
|
||||
getters,
|
||||
mutations,
|
||||
modules,
|
||||
|
@ -1,9 +1,39 @@
|
||||
import { ROOT_STORE } from '@/store/constants'
|
||||
import { ActionContext } from 'vuex'
|
||||
|
||||
export interface IAppStatistics {
|
||||
sports: number
|
||||
uploads_dir_size: number
|
||||
users: number
|
||||
workouts: number
|
||||
}
|
||||
|
||||
export interface IAppConfig {
|
||||
federation_enabled: boolean
|
||||
gpx_limit_import: number | null
|
||||
is_registration_enabled: boolean
|
||||
map_attribution: string
|
||||
max_single_file_size: number | null
|
||||
max_users: number | null
|
||||
max_zip_file_size: number | null
|
||||
}
|
||||
|
||||
export interface IApplication {
|
||||
statistics: IAppStatistics
|
||||
config: IAppConfig
|
||||
}
|
||||
|
||||
export interface IRootState {
|
||||
root: boolean
|
||||
language: string
|
||||
errorMessages: string | string[] | null
|
||||
application: IApplication
|
||||
}
|
||||
|
||||
export interface IRootActions {
|
||||
[ROOT_STORE.ACTIONS.GET_APPLICATION_CONFIG](
|
||||
context: ActionContext<IRootState, IRootState>
|
||||
): void
|
||||
}
|
||||
|
||||
export interface IRootGetters {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { MutationTree } from 'vuex'
|
||||
|
||||
import { ROOT_STORE } from '@/store/constants'
|
||||
import { IRootState } from '@/store/modules/root/interfaces'
|
||||
import { IAppConfig, IRootState } from '@/store/modules/root/interfaces'
|
||||
import { TRootMutations } from '@/store/modules/root/types'
|
||||
|
||||
export const mutations: MutationTree<IRootState> & TRootMutations = {
|
||||
@ -14,6 +14,12 @@ export const mutations: MutationTree<IRootState> & TRootMutations = {
|
||||
) {
|
||||
state.errorMessages = errorMessages
|
||||
},
|
||||
[ROOT_STORE.MUTATIONS.UPDATE_APPLICATION_CONFIG](
|
||||
state: IRootState,
|
||||
config: IAppConfig
|
||||
) {
|
||||
state.application.config = config
|
||||
},
|
||||
[ROOT_STORE.MUTATIONS.UPDATE_LANG](state: IRootState, language: string) {
|
||||
state.language = language
|
||||
},
|
||||
|
@ -1,7 +1,9 @@
|
||||
import { IRootState } from '@/store/modules/root/interfaces'
|
||||
import { IApplication } from '@/store/modules/root/interfaces'
|
||||
|
||||
export const state: IRootState = {
|
||||
root: true,
|
||||
language: 'en',
|
||||
errorMessages: null,
|
||||
application: <IApplication>{},
|
||||
}
|
||||
|
@ -1,7 +1,11 @@
|
||||
import { Store as VuexStore, CommitOptions } from 'vuex'
|
||||
import { Store as VuexStore, CommitOptions, DispatchOptions } from 'vuex'
|
||||
|
||||
import { ROOT_STORE } from '@/store/constants'
|
||||
import { IRootGetters, IRootState } from '@/store/modules/root/interfaces'
|
||||
import {
|
||||
IRootActions,
|
||||
IRootGetters,
|
||||
IRootState,
|
||||
} from '@/store/modules/root/interfaces'
|
||||
|
||||
export type TRootMutations<S = IRootState> = {
|
||||
[ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES](state: S): void
|
||||
@ -16,6 +20,12 @@ export type TRootStoreModule<S = IRootState> = Omit<
|
||||
VuexStore<S>,
|
||||
'commit' | 'getters' | 'dispatch'
|
||||
> & {
|
||||
dispatch<K extends keyof IRootActions>(
|
||||
key: K,
|
||||
payload?: Parameters<IRootActions[K]>[1],
|
||||
options?: DispatchOptions
|
||||
): ReturnType<IRootActions[K]>
|
||||
} & {
|
||||
getters: {
|
||||
[K in keyof IRootGetters]: ReturnType<IRootGetters[K]>
|
||||
}
|
||||
|
Reference in New Issue
Block a user