Client - get application config
This commit is contained in:
parent
0235a93c5b
commit
0b95b93e06
@ -7,8 +7,10 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent } from 'vue'
|
import { defineComponent, onBeforeMount } from 'vue'
|
||||||
|
|
||||||
|
import { ROOT_STORE } from '@/store/constants'
|
||||||
|
import { useStore } from '@/use/useStore'
|
||||||
import Footer from '@/components/Footer.vue'
|
import Footer from '@/components/Footer.vue'
|
||||||
import NavBar from '@/components/NavBar.vue'
|
import NavBar from '@/components/NavBar.vue'
|
||||||
|
|
||||||
@ -18,6 +20,12 @@
|
|||||||
Footer,
|
Footer,
|
||||||
NavBar,
|
NavBar,
|
||||||
},
|
},
|
||||||
|
setup() {
|
||||||
|
const store = useStore()
|
||||||
|
onBeforeMount(() =>
|
||||||
|
store.dispatch(ROOT_STORE.ACTIONS.GET_APPLICATION_CONFIG)
|
||||||
|
)
|
||||||
|
},
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
import { RootGetters, RootMutations } from '@/store/modules/root/enums'
|
import {
|
||||||
|
RootActions,
|
||||||
|
RootGetters,
|
||||||
|
RootMutations,
|
||||||
|
} from '@/store/modules/root/enums'
|
||||||
import {
|
import {
|
||||||
UserActions,
|
UserActions,
|
||||||
UserGetters,
|
UserGetters,
|
||||||
@ -6,6 +10,7 @@ import {
|
|||||||
} from '@/store/modules/user/enums'
|
} from '@/store/modules/user/enums'
|
||||||
|
|
||||||
export const ROOT_STORE = {
|
export const ROOT_STORE = {
|
||||||
|
ACTIONS: RootActions,
|
||||||
GETTERS: RootGetters,
|
GETTERS: RootGetters,
|
||||||
MUTATIONS: RootMutations,
|
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 {
|
export enum RootGetters {
|
||||||
ERROR_MESSAGES = 'ERROR_MESSAGES',
|
ERROR_MESSAGES = 'ERROR_MESSAGES',
|
||||||
LANGUAGE = 'LANGUAGE',
|
LANGUAGE = 'LANGUAGE',
|
||||||
@ -6,5 +10,6 @@ export enum RootGetters {
|
|||||||
export enum RootMutations {
|
export enum RootMutations {
|
||||||
EMPTY_ERROR_MESSAGES = 'EMPTY_ERROR_MESSAGES',
|
EMPTY_ERROR_MESSAGES = 'EMPTY_ERROR_MESSAGES',
|
||||||
SET_ERROR_MESSAGES = 'SET_ERROR_MESSAGES',
|
SET_ERROR_MESSAGES = 'SET_ERROR_MESSAGES',
|
||||||
|
UPDATE_APPLICATION_CONFIG = 'UPDATE_APPLICATION_CONFIG',
|
||||||
UPDATE_LANG = 'UPDATE_LANG',
|
UPDATE_LANG = 'UPDATE_LANG',
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { Module, ModuleTree } from 'vuex'
|
import { Module, ModuleTree } from 'vuex'
|
||||||
|
|
||||||
|
import { actions } from '@/store/modules/root/actions'
|
||||||
import { getters } from '@/store/modules/root/getters'
|
import { getters } from '@/store/modules/root/getters'
|
||||||
import { IRootState } from '@/store/modules/root/interfaces'
|
import { IRootState } from '@/store/modules/root/interfaces'
|
||||||
import { mutations } from '@/store/modules/root/mutations'
|
import { mutations } from '@/store/modules/root/mutations'
|
||||||
@ -12,6 +13,7 @@ const modules: ModuleTree<IRootState> = {
|
|||||||
|
|
||||||
const root: Module<IRootState, IRootState> = {
|
const root: Module<IRootState, IRootState> = {
|
||||||
state,
|
state,
|
||||||
|
actions,
|
||||||
getters,
|
getters,
|
||||||
mutations,
|
mutations,
|
||||||
modules,
|
modules,
|
||||||
|
@ -1,9 +1,39 @@
|
|||||||
import { ROOT_STORE } from '@/store/constants'
|
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 {
|
export interface IRootState {
|
||||||
root: boolean
|
root: boolean
|
||||||
language: string
|
language: string
|
||||||
errorMessages: string | string[] | null
|
errorMessages: string | string[] | null
|
||||||
|
application: IApplication
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IRootActions {
|
||||||
|
[ROOT_STORE.ACTIONS.GET_APPLICATION_CONFIG](
|
||||||
|
context: ActionContext<IRootState, IRootState>
|
||||||
|
): void
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IRootGetters {
|
export interface IRootGetters {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { MutationTree } from 'vuex'
|
import { MutationTree } from 'vuex'
|
||||||
|
|
||||||
import { ROOT_STORE } from '@/store/constants'
|
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'
|
import { TRootMutations } from '@/store/modules/root/types'
|
||||||
|
|
||||||
export const mutations: MutationTree<IRootState> & TRootMutations = {
|
export const mutations: MutationTree<IRootState> & TRootMutations = {
|
||||||
@ -14,6 +14,12 @@ export const mutations: MutationTree<IRootState> & TRootMutations = {
|
|||||||
) {
|
) {
|
||||||
state.errorMessages = errorMessages
|
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) {
|
[ROOT_STORE.MUTATIONS.UPDATE_LANG](state: IRootState, language: string) {
|
||||||
state.language = language
|
state.language = language
|
||||||
},
|
},
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
import { IRootState } from '@/store/modules/root/interfaces'
|
import { IRootState } from '@/store/modules/root/interfaces'
|
||||||
|
import { IApplication } from '@/store/modules/root/interfaces'
|
||||||
|
|
||||||
export const state: IRootState = {
|
export const state: IRootState = {
|
||||||
root: true,
|
root: true,
|
||||||
language: 'en',
|
language: 'en',
|
||||||
errorMessages: null,
|
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 { 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> = {
|
export type TRootMutations<S = IRootState> = {
|
||||||
[ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES](state: S): void
|
[ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES](state: S): void
|
||||||
@ -16,6 +20,12 @@ export type TRootStoreModule<S = IRootState> = Omit<
|
|||||||
VuexStore<S>,
|
VuexStore<S>,
|
||||||
'commit' | 'getters' | 'dispatch'
|
'commit' | 'getters' | 'dispatch'
|
||||||
> & {
|
> & {
|
||||||
|
dispatch<K extends keyof IRootActions>(
|
||||||
|
key: K,
|
||||||
|
payload?: Parameters<IRootActions[K]>[1],
|
||||||
|
options?: DispatchOptions
|
||||||
|
): ReturnType<IRootActions[K]>
|
||||||
|
} & {
|
||||||
getters: {
|
getters: {
|
||||||
[K in keyof IRootGetters]: ReturnType<IRootGetters[K]>
|
[K in keyof IRootGetters]: ReturnType<IRootGetters[K]>
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,9 @@ export const getApiUrl = (): string => {
|
|||||||
const removeLastEndOfLine = (text: string): string => text.replace(/\n$/gm, '')
|
const removeLastEndOfLine = (text: string): string => text.replace(/\n$/gm, '')
|
||||||
const removeLastDot = (text: string): string => text.replace(/\.$/gm, '')
|
const removeLastDot = (text: string): string => text.replace(/\.$/gm, '')
|
||||||
export const handleError = (
|
export const handleError = (
|
||||||
context: ActionContext<IUserState, IRootState>,
|
context:
|
||||||
|
| ActionContext<IRootState, IRootState>
|
||||||
|
| ActionContext<IUserState, IRootState>,
|
||||||
error: AxiosError | null,
|
error: AxiosError | null,
|
||||||
msg = 'UNKNOWN'
|
msg = 'UNKNOWN'
|
||||||
): void => {
|
): void => {
|
||||||
|
Loading…
Reference in New Issue
Block a user