Client - refactor store interfaces (move w/ types)
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user