Client - error message style (wip)
Need some updates api side.
This commit is contained in:
@ -1,10 +1,10 @@
|
||||
export enum RootGetters {
|
||||
ERROR_MESSAGE = 'ERROR_MESSAGE',
|
||||
ERROR_MESSAGES = 'ERROR_MESSAGES',
|
||||
LANGUAGE = 'LANGUAGE',
|
||||
}
|
||||
|
||||
export enum RootMutations {
|
||||
EMPTY_ERROR_MESSAGE = 'EMPTY_ERROR_MESSAGE',
|
||||
SET_ERROR_MESSAGE = 'SET_ERROR_MESSAGE',
|
||||
EMPTY_ERROR_MESSAGES = 'EMPTY_ERROR_MESSAGES',
|
||||
SET_ERROR_MESSAGES = 'SET_ERROR_MESSAGES',
|
||||
UPDATE_LANG = 'UPDATE_LANG',
|
||||
}
|
||||
|
@ -4,8 +4,8 @@ import { ROOT_STORE } from '@/store/constants'
|
||||
import { IRootState, IRootGetters } from '@/store/modules/root/interfaces'
|
||||
|
||||
export const getters: GetterTree<IRootState, IRootState> & IRootGetters = {
|
||||
[ROOT_STORE.GETTERS.ERROR_MESSAGE]: (state: IRootState) => {
|
||||
return state.errorMessage
|
||||
[ROOT_STORE.GETTERS.ERROR_MESSAGES]: (state: IRootState) => {
|
||||
return state.errorMessages
|
||||
},
|
||||
[ROOT_STORE.GETTERS.LANGUAGE]: (state: IRootState) => {
|
||||
return state.language
|
||||
|
@ -3,10 +3,12 @@ import { ROOT_STORE } from '@/store/constants'
|
||||
export interface IRootState {
|
||||
root: boolean
|
||||
language: string
|
||||
errorMessage: string | null
|
||||
errorMessages: string | string[] | null
|
||||
}
|
||||
|
||||
export interface IRootGetters {
|
||||
[ROOT_STORE.GETTERS.ERROR_MESSAGE](state: IRootState): string | null
|
||||
[ROOT_STORE.GETTERS.ERROR_MESSAGES](
|
||||
state: IRootState
|
||||
): string | string[] | null
|
||||
[ROOT_STORE.GETTERS.LANGUAGE](state: IRootState): string
|
||||
}
|
||||
|
@ -5,14 +5,14 @@ import { IRootState } from '@/store/modules/root/interfaces'
|
||||
import { TRootMutations } from '@/store/modules/root/types'
|
||||
|
||||
export const mutations: MutationTree<IRootState> & TRootMutations = {
|
||||
[ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGE](state: IRootState) {
|
||||
state.errorMessage = null
|
||||
[ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES](state: IRootState) {
|
||||
state.errorMessages = null
|
||||
},
|
||||
[ROOT_STORE.MUTATIONS.SET_ERROR_MESSAGE](
|
||||
[ROOT_STORE.MUTATIONS.SET_ERROR_MESSAGES](
|
||||
state: IRootState,
|
||||
errorMessage: string
|
||||
errorMessages: string
|
||||
) {
|
||||
state.errorMessage = errorMessage
|
||||
state.errorMessages = errorMessages
|
||||
},
|
||||
[ROOT_STORE.MUTATIONS.UPDATE_LANG](state: IRootState, language: string) {
|
||||
state.language = language
|
||||
|
@ -3,5 +3,5 @@ import { IRootState } from '@/store/modules/root/interfaces'
|
||||
export const state: IRootState = {
|
||||
root: true,
|
||||
language: 'en',
|
||||
errorMessage: null,
|
||||
errorMessages: null,
|
||||
}
|
||||
|
@ -4,8 +4,11 @@ import { ROOT_STORE } from '@/store/constants'
|
||||
import { IRootGetters, IRootState } from '@/store/modules/root/interfaces'
|
||||
|
||||
export type TRootMutations<S = IRootState> = {
|
||||
[ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGE](state: S): void
|
||||
[ROOT_STORE.MUTATIONS.SET_ERROR_MESSAGE](state: S, errorMessage: string): void
|
||||
[ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES](state: S): void
|
||||
[ROOT_STORE.MUTATIONS.SET_ERROR_MESSAGES](
|
||||
state: S,
|
||||
errorMessages: string
|
||||
): void
|
||||
[ROOT_STORE.MUTATIONS.UPDATE_LANG](state: S, language: string): void
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ export const actions: ActionTree<IUserState, IRootState> & IUserActions = {
|
||||
[USER_STORE.ACTIONS.GET_USER_PROFILE](
|
||||
context: ActionContext<IUserState, IRootState>
|
||||
): void {
|
||||
context.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGE)
|
||||
context.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES)
|
||||
authApi
|
||||
.get('auth/profile')
|
||||
.then((res) => {
|
||||
@ -49,7 +49,7 @@ export const actions: ActionTree<IUserState, IRootState> & IUserActions = {
|
||||
context: ActionContext<IUserState, IRootState>,
|
||||
data: ILoginOrRegisterData
|
||||
): void {
|
||||
context.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGE)
|
||||
context.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES)
|
||||
api
|
||||
.post(`/auth/${data.actionType}`, data.formData)
|
||||
.then((res) => {
|
||||
@ -71,7 +71,7 @@ export const actions: ActionTree<IUserState, IRootState> & IUserActions = {
|
||||
): void {
|
||||
localStorage.removeItem('authToken')
|
||||
context.commit(USER_STORE.MUTATIONS.CLEAR_AUTH_USER_TOKEN)
|
||||
context.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGE)
|
||||
context.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES)
|
||||
router.push('/login')
|
||||
},
|
||||
}
|
||||
|
Reference in New Issue
Block a user