Client - refactor store interfaces (move w/ types)
This commit is contained in:
parent
3b8ac44433
commit
cac9607489
@ -1,7 +1,7 @@
|
||||
import { createStore } from 'vuex'
|
||||
|
||||
import root from '@/store/modules/root'
|
||||
import { IRootState } from '@/store/modules/root/interfaces'
|
||||
import { IRootState } from '@/store/modules/root/types'
|
||||
|
||||
const store = createStore<IRootState>(root)
|
||||
|
||||
|
@ -2,7 +2,7 @@ import { ActionContext, ActionTree } from 'vuex'
|
||||
|
||||
import authApi from '@/api/authApi'
|
||||
import { ROOT_STORE } from '@/store/constants'
|
||||
import { IRootActions, IRootState } from '@/store/modules/root/interfaces'
|
||||
import { IRootActions, IRootState } from '@/store/modules/root/types'
|
||||
import { handleError } from '@/utils'
|
||||
|
||||
export const actions: ActionTree<IRootState, IRootState> & IRootActions = {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { GetterTree } from 'vuex'
|
||||
|
||||
import { ROOT_STORE } from '@/store/constants'
|
||||
import { IRootState, IRootGetters } from '@/store/modules/root/interfaces'
|
||||
import { IRootGetters, IRootState } from '@/store/modules/root/types'
|
||||
|
||||
export const getters: GetterTree<IRootState, IRootState> & IRootGetters = {
|
||||
[ROOT_STORE.GETTERS.APP_CONFIG]: (state: IRootState) => {
|
||||
|
@ -2,9 +2,9 @@ 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'
|
||||
import { state } from '@/store/modules/root/state.ts'
|
||||
import { IRootState } from '@/store/modules/root/types'
|
||||
import statsModule from '@/store/modules/statistics'
|
||||
import userModule from '@/store/modules/user'
|
||||
|
||||
|
@ -1,27 +0,0 @@
|
||||
import { ActionContext } from 'vuex'
|
||||
|
||||
import { ROOT_STORE } from '@/store/constants'
|
||||
import { IAppConfig, IApplication } from '@/types/application'
|
||||
|
||||
export interface IRootState {
|
||||
root: boolean
|
||||
language: string
|
||||
errorMessages: string | string[] | null
|
||||
application: IApplication
|
||||
appLoading: boolean
|
||||
}
|
||||
|
||||
export interface IRootActions {
|
||||
[ROOT_STORE.ACTIONS.GET_APPLICATION_CONFIG](
|
||||
context: ActionContext<IRootState, IRootState>
|
||||
): void
|
||||
}
|
||||
|
||||
export interface IRootGetters {
|
||||
[ROOT_STORE.GETTERS.APP_CONFIG](state: IRootState): IAppConfig
|
||||
[ROOT_STORE.GETTERS.APP_LOADING](state: IRootState): boolean
|
||||
[ROOT_STORE.GETTERS.ERROR_MESSAGES](
|
||||
state: IRootState
|
||||
): string | string[] | null
|
||||
[ROOT_STORE.GETTERS.LANGUAGE](state: IRootState): string
|
||||
}
|
@ -1,8 +1,7 @@
|
||||
import { MutationTree } from 'vuex'
|
||||
|
||||
import { ROOT_STORE } from '@/store/constants'
|
||||
import { IRootState } from '@/store/modules/root/interfaces'
|
||||
import { TRootMutations } from '@/store/modules/root/types'
|
||||
import { IRootState, TRootMutations } from '@/store/modules/root/types'
|
||||
import { IAppConfig } from '@/types/application'
|
||||
|
||||
export const mutations: MutationTree<IRootState> & TRootMutations = {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { IRootState } from '@/store/modules/root/interfaces'
|
||||
import { IRootState } from '@/store/modules/root/types'
|
||||
import { IApplication } from '@/types/application'
|
||||
|
||||
export const state: IRootState = {
|
||||
|
@ -1,11 +1,38 @@
|
||||
import { Store as VuexStore, CommitOptions, DispatchOptions } from 'vuex'
|
||||
import {
|
||||
ActionContext,
|
||||
CommitOptions,
|
||||
DispatchOptions,
|
||||
Store as VuexStore,
|
||||
} from 'vuex'
|
||||
|
||||
import { ROOT_STORE } from '@/store/constants'
|
||||
import {
|
||||
IRootActions,
|
||||
IRootGetters,
|
||||
IRootState,
|
||||
} from '@/store/modules/root/interfaces'
|
||||
import { IAppConfig, IApplication } from '@/types/application'
|
||||
|
||||
export interface IRootState {
|
||||
root: boolean
|
||||
language: string
|
||||
errorMessages: string | string[] | null
|
||||
application: IApplication
|
||||
appLoading: boolean
|
||||
}
|
||||
|
||||
export interface IRootActions {
|
||||
[ROOT_STORE.ACTIONS.GET_APPLICATION_CONFIG](
|
||||
context: ActionContext<IRootState, IRootState>
|
||||
): void
|
||||
}
|
||||
|
||||
export interface IRootGetters {
|
||||
[ROOT_STORE.GETTERS.APP_CONFIG](state: IRootState): IAppConfig
|
||||
|
||||
[ROOT_STORE.GETTERS.APP_LOADING](state: IRootState): boolean
|
||||
|
||||
[ROOT_STORE.GETTERS.ERROR_MESSAGES](
|
||||
state: IRootState
|
||||
): string | string[] | null
|
||||
|
||||
[ROOT_STORE.GETTERS.LANGUAGE](state: IRootState): string
|
||||
}
|
||||
|
||||
export type TRootMutations<S = IRootState> = {
|
||||
[ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES](state: S): void
|
||||
|
@ -2,11 +2,11 @@ import { ActionContext, ActionTree } from 'vuex'
|
||||
|
||||
import authApi from '@/api/authApi'
|
||||
import { STATS_STORE, ROOT_STORE } from '@/store/constants'
|
||||
import { IRootState } from '@/store/modules/root/interfaces'
|
||||
import { IRootState } from '@/store/modules/root/types'
|
||||
import {
|
||||
IStatisticsActions,
|
||||
IStatisticsState,
|
||||
} from '@/store/modules/statistics/interfaces'
|
||||
} from '@/store/modules/statistics/types'
|
||||
import { IUserStatisticsPayload } from '@/types/statistics'
|
||||
import { handleError } from '@/utils'
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { GetterTree } from 'vuex'
|
||||
|
||||
import { STATS_STORE } from '@/store/constants'
|
||||
import { IRootState } from '@/store/modules/root/interfaces'
|
||||
import { IRootState } from '@/store/modules/root/types'
|
||||
import {
|
||||
IStatisticsGetters,
|
||||
IStatisticsState,
|
||||
} from '@/store/modules/statistics/interfaces'
|
||||
} from '@/store/modules/statistics/types'
|
||||
|
||||
export const getters: GetterTree<IStatisticsState, IRootState> &
|
||||
IStatisticsGetters = {
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { Module } from 'vuex'
|
||||
|
||||
import { IRootState } from '@/store/modules/root/interfaces'
|
||||
import { IRootState } from '@/store/modules/root/types'
|
||||
import { actions } from '@/store/modules/statistics/actions'
|
||||
import { getters } from '@/store/modules/statistics/getters'
|
||||
import { IStatisticsState } from '@/store/modules/statistics/interfaces'
|
||||
import { mutations } from '@/store/modules/statistics/mutations'
|
||||
import { statisticsState } from '@/store/modules/statistics/state'
|
||||
import { IStatisticsState } from '@/store/modules/statistics/types'
|
||||
|
||||
const statistics: Module<IStatisticsState, IRootState> = {
|
||||
state: statisticsState,
|
||||
|
@ -1,20 +0,0 @@
|
||||
import { ActionContext } from 'vuex'
|
||||
|
||||
import { STATS_STORE } from '@/store/constants'
|
||||
import { IRootState } from '@/store/modules/root/interfaces'
|
||||
import { IUserStatisticsPayload, TStatisticsFromApi } from '@/types/statistics'
|
||||
|
||||
export interface IStatisticsState {
|
||||
statistics: TStatisticsFromApi
|
||||
}
|
||||
|
||||
export interface IStatisticsActions {
|
||||
[STATS_STORE.ACTIONS.GET_USER_STATS](
|
||||
context: ActionContext<IStatisticsState, IRootState>,
|
||||
payload: IUserStatisticsPayload
|
||||
): void
|
||||
}
|
||||
|
||||
export interface IStatisticsGetters {
|
||||
[STATS_STORE.GETTERS.USER_STATS](state: IStatisticsState): TStatisticsFromApi
|
||||
}
|
@ -1,8 +1,10 @@
|
||||
import { MutationTree } from 'vuex'
|
||||
|
||||
import { STATS_STORE } from '@/store/constants'
|
||||
import { IStatisticsState } from '@/store/modules/statistics/interfaces'
|
||||
import { TStatisticsMutations } from '@/store/modules/statistics/types'
|
||||
import {
|
||||
IStatisticsState,
|
||||
TStatisticsMutations,
|
||||
} from '@/store/modules/statistics/types'
|
||||
import { TStatisticsFromApi } from '@/types/statistics'
|
||||
|
||||
export const mutations: MutationTree<IStatisticsState> & TStatisticsMutations =
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { IStatisticsState } from '@/store/modules/statistics/interfaces'
|
||||
import { IStatisticsState } from '@/store/modules/statistics/types'
|
||||
import { TStatisticsFromApi } from '@/types/statistics'
|
||||
|
||||
export const statisticsState: IStatisticsState = {
|
||||
|
@ -1,12 +1,28 @@
|
||||
import { Store as VuexStore, CommitOptions, DispatchOptions } from 'vuex'
|
||||
import {
|
||||
ActionContext,
|
||||
CommitOptions,
|
||||
DispatchOptions,
|
||||
Store as VuexStore,
|
||||
} from 'vuex'
|
||||
|
||||
import { STATS_STORE } from '@/store/constants'
|
||||
import {
|
||||
IStatisticsState,
|
||||
IStatisticsActions,
|
||||
IStatisticsGetters,
|
||||
} from '@/store/modules/statistics/interfaces'
|
||||
import { TStatisticsFromApi } from '@/types/statistics'
|
||||
import { IRootState } from '@/store/modules/root/types'
|
||||
import { IUserStatisticsPayload, TStatisticsFromApi } from '@/types/statistics'
|
||||
|
||||
export interface IStatisticsState {
|
||||
statistics: TStatisticsFromApi
|
||||
}
|
||||
|
||||
export interface IStatisticsActions {
|
||||
[STATS_STORE.ACTIONS.GET_USER_STATS](
|
||||
context: ActionContext<IStatisticsState, IRootState>,
|
||||
payload: IUserStatisticsPayload
|
||||
): void
|
||||
}
|
||||
|
||||
export interface IStatisticsGetters {
|
||||
[STATS_STORE.GETTERS.USER_STATS](state: IStatisticsState): TStatisticsFromApi
|
||||
}
|
||||
|
||||
export type TStatisticsMutations<S = IStatisticsState> = {
|
||||
[STATS_STORE.MUTATIONS.UPDATE_USER_STATS](
|
||||
|
@ -4,8 +4,8 @@ import authApi from '@/api/authApi'
|
||||
import api from '@/api/defaultApi'
|
||||
import router from '@/router'
|
||||
import { ROOT_STORE, USER_STORE } from '@/store/constants'
|
||||
import { IRootState } from '@/store/modules/root/interfaces'
|
||||
import { IUserActions, IUserState } from '@/store/modules/user/interfaces'
|
||||
import { IRootState } from '@/store/modules/root/types'
|
||||
import { IUserActions, IUserState } from '@/store/modules/user/types'
|
||||
import { ILoginOrRegisterData } from '@/types/user'
|
||||
import { handleError } from '@/utils'
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { GetterTree } from 'vuex'
|
||||
|
||||
import { USER_STORE } from '@/store/constants'
|
||||
import { IRootState } from '@/store/modules/root/interfaces'
|
||||
import { IUserGetters, IUserState } from '@/store/modules/user/interfaces'
|
||||
import { IRootState } from '@/store/modules/root/types'
|
||||
import { IUserGetters, IUserState } from '@/store/modules/user/types'
|
||||
|
||||
export const getters: GetterTree<IUserState, IRootState> & IUserGetters = {
|
||||
[USER_STORE.GETTERS.AUTH_TOKEN]: (state: IUserState) => {
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { Module } from 'vuex'
|
||||
|
||||
import { IRootState } from '@/store/modules/root/interfaces'
|
||||
import { IRootState } from '@/store/modules/root/types'
|
||||
import { actions } from '@/store/modules/user/actions'
|
||||
import { getters } from '@/store/modules/user/getters'
|
||||
import { IUserState } from '@/store/modules/user/interfaces'
|
||||
import { mutations } from '@/store/modules/user/mutations'
|
||||
import { userState } from '@/store/modules/user/state.ts'
|
||||
import { IUserState } from '@/store/modules/user/types'
|
||||
|
||||
const user: Module<IUserState, IRootState> = {
|
||||
state: userState,
|
||||
|
@ -1,32 +0,0 @@
|
||||
import { ActionContext } from 'vuex'
|
||||
|
||||
import { USER_STORE } from '@/store/constants'
|
||||
import { IRootState } from '@/store/modules/root/interfaces'
|
||||
import { IAuthUserProfile, ILoginOrRegisterData } from '@/types/user'
|
||||
|
||||
export interface IUserState {
|
||||
authToken: string | null
|
||||
authUserProfile: IAuthUserProfile
|
||||
}
|
||||
|
||||
export interface IUserActions {
|
||||
[USER_STORE.ACTIONS.CHECK_AUTH_USER](
|
||||
context: ActionContext<IUserState, IRootState>
|
||||
): void
|
||||
[USER_STORE.ACTIONS.GET_USER_PROFILE](
|
||||
context: ActionContext<IUserState, IRootState>
|
||||
): void
|
||||
[USER_STORE.ACTIONS.LOGIN_OR_REGISTER](
|
||||
context: ActionContext<IUserState, IRootState>,
|
||||
data: ILoginOrRegisterData
|
||||
): void
|
||||
[USER_STORE.ACTIONS.LOGOUT](
|
||||
context: ActionContext<IUserState, IRootState>
|
||||
): void
|
||||
}
|
||||
|
||||
export interface IUserGetters {
|
||||
[USER_STORE.GETTERS.AUTH_TOKEN](state: IUserState): string | null
|
||||
[USER_STORE.GETTERS.AUTH_USER_PROFILE](state: IUserState): IAuthUserProfile
|
||||
[USER_STORE.GETTERS.IS_AUTHENTICATED](state: IUserState): boolean
|
||||
}
|
@ -1,8 +1,7 @@
|
||||
import { MutationTree } from 'vuex'
|
||||
|
||||
import { USER_STORE } from '@/store/constants'
|
||||
import { IUserState } from '@/store/modules/user/interfaces'
|
||||
import { TUserMutations } from '@/store/modules/user/types'
|
||||
import { IUserState, TUserMutations } from '@/store/modules/user/types'
|
||||
import { IAuthUserProfile } from '@/types/user'
|
||||
|
||||
export const mutations: MutationTree<IUserState> & TUserMutations = {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { IUserState } from '@/store/modules/user/interfaces'
|
||||
import { IUserState } from '@/store/modules/user/types'
|
||||
import { IAuthUserProfile } from '@/types/user'
|
||||
|
||||
export const userState: IUserState = {
|
||||
|
@ -1,12 +1,45 @@
|
||||
import { Store as VuexStore, CommitOptions, DispatchOptions } from 'vuex'
|
||||
import {
|
||||
ActionContext,
|
||||
CommitOptions,
|
||||
DispatchOptions,
|
||||
Store as VuexStore,
|
||||
} from 'vuex'
|
||||
|
||||
import { USER_STORE } from '@/store/constants'
|
||||
import {
|
||||
IUserActions,
|
||||
IUserGetters,
|
||||
IUserState,
|
||||
} from '@/store/modules/user/interfaces'
|
||||
import { IAuthUserProfile } from '@/types/user'
|
||||
import { IRootState } from '@/store/modules/root/types'
|
||||
import { IAuthUserProfile, ILoginOrRegisterData } from '@/types/user'
|
||||
|
||||
export interface IUserState {
|
||||
authToken: string | null
|
||||
authUserProfile: IAuthUserProfile
|
||||
}
|
||||
|
||||
export interface IUserActions {
|
||||
[USER_STORE.ACTIONS.CHECK_AUTH_USER](
|
||||
context: ActionContext<IUserState, IRootState>
|
||||
): void
|
||||
|
||||
[USER_STORE.ACTIONS.GET_USER_PROFILE](
|
||||
context: ActionContext<IUserState, IRootState>
|
||||
): void
|
||||
|
||||
[USER_STORE.ACTIONS.LOGIN_OR_REGISTER](
|
||||
context: ActionContext<IUserState, IRootState>,
|
||||
data: ILoginOrRegisterData
|
||||
): void
|
||||
|
||||
[USER_STORE.ACTIONS.LOGOUT](
|
||||
context: ActionContext<IUserState, IRootState>
|
||||
): void
|
||||
}
|
||||
|
||||
export interface IUserGetters {
|
||||
[USER_STORE.GETTERS.AUTH_TOKEN](state: IUserState): string | null
|
||||
|
||||
[USER_STORE.GETTERS.AUTH_USER_PROFILE](state: IUserState): IAuthUserProfile
|
||||
|
||||
[USER_STORE.GETTERS.IS_AUTHENTICATED](state: IUserState): boolean
|
||||
}
|
||||
|
||||
export type TUserMutations<S = IUserState> = {
|
||||
[USER_STORE.MUTATIONS.CLEAR_AUTH_USER_TOKEN](state: S): void
|
||||
|
@ -2,9 +2,9 @@ import { AxiosError } from 'axios'
|
||||
import { ActionContext } from 'vuex'
|
||||
|
||||
import { ROOT_STORE } from '@/store/constants'
|
||||
import { IRootState } from '@/store/modules/root/interfaces'
|
||||
import { IStatisticsState } from '@/store/modules/statistics/interfaces'
|
||||
import { IUserState } from '@/store/modules/user/interfaces'
|
||||
import { IRootState } from '@/store/modules/root/types'
|
||||
import { IStatisticsState } from '@/store/modules/statistics/types'
|
||||
import { IUserState } from '@/store/modules/user/types'
|
||||
|
||||
export const getApiUrl = (): string => {
|
||||
return process.env.NODE_ENV === 'production'
|
||||
|
Loading…
Reference in New Issue
Block a user