Client - init profile edition
This commit is contained in:
@ -12,7 +12,7 @@ import {
|
||||
} from '@/store/constants'
|
||||
import { IRootState } from '@/store/modules/root/types'
|
||||
import { IUserActions, IUserState } from '@/store/modules/user/types'
|
||||
import { ILoginOrRegisterData } from '@/types/user'
|
||||
import { ILoginOrRegisterData, IUserPayload } from '@/types/user'
|
||||
import { handleError } from '@/utils'
|
||||
|
||||
export const actions: ActionTree<IUserState, IRootState> & IUserActions = {
|
||||
@ -80,4 +80,28 @@ export const actions: ActionTree<IUserState, IRootState> & IUserActions = {
|
||||
context.commit(WORKOUTS_STORE.MUTATIONS.EMPTY_WORKOUTS)
|
||||
router.push('/login')
|
||||
},
|
||||
[USER_STORE.ACTIONS.UPDATE_USER_PROFILE](
|
||||
context: ActionContext<IUserState, IRootState>,
|
||||
payload: IUserPayload
|
||||
): void {
|
||||
context.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES)
|
||||
context.commit(USER_STORE.MUTATIONS.UPDATE_USER_LOADING, true)
|
||||
authApi
|
||||
.post('auth/profile/edit', payload)
|
||||
.then((res) => {
|
||||
if (res.data.status === 'success') {
|
||||
context.commit(
|
||||
USER_STORE.MUTATIONS.UPDATE_AUTH_USER_PROFILE,
|
||||
res.data.data
|
||||
)
|
||||
router.push('/profile')
|
||||
} else {
|
||||
handleError(context, null)
|
||||
}
|
||||
})
|
||||
.catch((error) => handleError(context, error))
|
||||
.finally(() =>
|
||||
context.commit(USER_STORE.MUTATIONS.UPDATE_USER_LOADING, false)
|
||||
)
|
||||
},
|
||||
}
|
||||
|
@ -3,16 +3,19 @@ export enum UserActions {
|
||||
GET_USER_PROFILE = 'GET_USER_PROFILE',
|
||||
LOGIN_OR_REGISTER = 'LOGIN_OR_REGISTER',
|
||||
LOGOUT = 'LOGOUT',
|
||||
UPDATE_USER_PROFILE = 'UPDATE_USER_PROFILE',
|
||||
}
|
||||
|
||||
export enum UserGetters {
|
||||
AUTH_TOKEN = 'AUTH_TOKEN',
|
||||
AUTH_USER_PROFILE = 'AUTH_USER_PROFILE',
|
||||
IS_AUTHENTICATED = 'IS_AUTHENTICATED',
|
||||
USER_LOADING = 'USER_LOADING',
|
||||
}
|
||||
|
||||
export enum UserMutations {
|
||||
CLEAR_AUTH_USER_TOKEN = 'CLEAR_AUTH_USER_TOKEN',
|
||||
UPDATE_AUTH_TOKEN = 'UPDATE_AUTH_TOKEN',
|
||||
UPDATE_AUTH_USER_PROFILE = 'UPDATE_AUTH_USER_PROFILE',
|
||||
UPDATE_USER_LOADING = 'UPDATE_USER_LOADING',
|
||||
}
|
||||
|
@ -14,4 +14,7 @@ export const getters: GetterTree<IUserState, IRootState> & IUserGetters = {
|
||||
[USER_STORE.GETTERS.IS_AUTHENTICATED]: (state: IUserState) => {
|
||||
return state.authToken !== null
|
||||
},
|
||||
[USER_STORE.GETTERS.USER_LOADING]: (state: IUserState) => {
|
||||
return state.loading
|
||||
},
|
||||
}
|
||||
|
@ -21,4 +21,10 @@ export const mutations: MutationTree<IUserState> & TUserMutations = {
|
||||
) {
|
||||
state.authUserProfile = authUserProfile
|
||||
},
|
||||
[USER_STORE.MUTATIONS.UPDATE_USER_LOADING](
|
||||
state: IUserState,
|
||||
loading: boolean
|
||||
) {
|
||||
state.loading = loading
|
||||
},
|
||||
}
|
||||
|
@ -4,4 +4,5 @@ import { IAuthUserProfile } from '@/types/user'
|
||||
export const userState: IUserState = {
|
||||
authToken: null,
|
||||
authUserProfile: <IAuthUserProfile>{},
|
||||
loading: false,
|
||||
}
|
||||
|
@ -7,11 +7,16 @@ import {
|
||||
|
||||
import { USER_STORE } from '@/store/constants'
|
||||
import { IRootState } from '@/store/modules/root/types'
|
||||
import { IAuthUserProfile, ILoginOrRegisterData } from '@/types/user'
|
||||
import {
|
||||
IAuthUserProfile,
|
||||
ILoginOrRegisterData,
|
||||
IUserPayload,
|
||||
} from '@/types/user'
|
||||
|
||||
export interface IUserState {
|
||||
authToken: string | null
|
||||
authUserProfile: IAuthUserProfile
|
||||
loading: boolean
|
||||
}
|
||||
|
||||
export interface IUserActions {
|
||||
@ -31,6 +36,11 @@ export interface IUserActions {
|
||||
[USER_STORE.ACTIONS.LOGOUT](
|
||||
context: ActionContext<IUserState, IRootState>
|
||||
): void
|
||||
|
||||
[USER_STORE.ACTIONS.UPDATE_USER_PROFILE](
|
||||
context: ActionContext<IUserState, IRootState>,
|
||||
payload: IUserPayload
|
||||
): void
|
||||
}
|
||||
|
||||
export interface IUserGetters {
|
||||
@ -39,6 +49,8 @@ export interface IUserGetters {
|
||||
[USER_STORE.GETTERS.AUTH_USER_PROFILE](state: IUserState): IAuthUserProfile
|
||||
|
||||
[USER_STORE.GETTERS.IS_AUTHENTICATED](state: IUserState): boolean
|
||||
|
||||
[USER_STORE.GETTERS.USER_LOADING](state: IUserState): boolean
|
||||
}
|
||||
|
||||
export type TUserMutations<S = IUserState> = {
|
||||
@ -48,6 +60,7 @@ export type TUserMutations<S = IUserState> = {
|
||||
state: S,
|
||||
authUserProfile: IAuthUserProfile
|
||||
): void
|
||||
[USER_STORE.MUTATIONS.UPDATE_USER_LOADING](state: S, loading: boolean): void
|
||||
}
|
||||
|
||||
export type TUserStoreModule<S = IUserState> = Omit<
|
||||
|
Reference in New Issue
Block a user