Client - refactoring (rename auth user store)
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
import axios from 'axios'
|
||||
|
||||
import store from '@/store'
|
||||
import { USER_STORE } from '@/store/constants'
|
||||
import { AUTH_USER_STORE } from '@/store/constants'
|
||||
import { getApiUrl } from '@/utils'
|
||||
|
||||
const authApi = axios.create({
|
||||
@ -10,7 +10,7 @@ const authApi = axios.create({
|
||||
|
||||
authApi.interceptors.request.use(
|
||||
(config) => {
|
||||
const authToken = store.getters[USER_STORE.GETTERS.AUTH_TOKEN]
|
||||
const authToken = store.getters[AUTH_USER_STORE.GETTERS.AUTH_TOKEN]
|
||||
if (authToken) {
|
||||
const auth = `Bearer ${authToken}`
|
||||
if (config.headers.Authorization !== auth) {
|
||||
|
@ -132,7 +132,7 @@
|
||||
import FilterSelects from '@/components/Common/FilterSelects.vue'
|
||||
import Pagination from '@/components/Common/Pagination.vue'
|
||||
import UserPicture from '@/components/User/UserPicture.vue'
|
||||
import { ROOT_STORE, USER_STORE, USERS_STORE } from '@/store/constants'
|
||||
import { AUTH_USER_STORE, ROOT_STORE, USERS_STORE } from '@/store/constants'
|
||||
import { IPagination, TPaginationPayload } from '@/types/api'
|
||||
import { IUserProfile } from '@/types/user'
|
||||
import { useStore } from '@/use/useStore'
|
||||
@ -163,7 +163,7 @@
|
||||
)
|
||||
|
||||
const authUser: ComputedRef<IUserProfile> = computed(
|
||||
() => store.getters[USER_STORE.GETTERS.AUTH_USER_PROFILE]
|
||||
() => store.getters[AUTH_USER_STORE.GETTERS.AUTH_USER_PROFILE]
|
||||
)
|
||||
const users: ComputedRef<IUserProfile[]> = computed(
|
||||
() => store.getters[USERS_STORE.GETTERS.USERS]
|
||||
|
@ -82,7 +82,7 @@
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
import UserPicture from '@/components/User/UserPicture.vue'
|
||||
import { ROOT_STORE, USER_STORE } from '@/store/constants'
|
||||
import { AUTH_USER_STORE, ROOT_STORE } from '@/store/constants'
|
||||
import { IDropdownOption } from '@/types/forms'
|
||||
import { IUserProfile } from '@/types/user'
|
||||
import { useStore } from '@/use/useStore'
|
||||
@ -100,10 +100,10 @@
|
||||
const store = useStore()
|
||||
|
||||
const authUser: ComputedRef<IUserProfile> = computed(
|
||||
() => store.getters[USER_STORE.GETTERS.AUTH_USER_PROFILE]
|
||||
() => store.getters[AUTH_USER_STORE.GETTERS.AUTH_USER_PROFILE]
|
||||
)
|
||||
const isAuthenticated: ComputedRef<boolean> = computed(
|
||||
() => store.getters[USER_STORE.GETTERS.IS_AUTHENTICATED]
|
||||
() => store.getters[AUTH_USER_STORE.GETTERS.IS_AUTHENTICATED]
|
||||
)
|
||||
const authUserPictureUrl: ComputedRef<string> = computed(() =>
|
||||
isAuthenticated.value && authUser.value.picture
|
||||
@ -130,7 +130,7 @@
|
||||
store.commit(ROOT_STORE.MUTATIONS.UPDATE_LANG, option.value)
|
||||
}
|
||||
function logout() {
|
||||
store.dispatch(USER_STORE.ACTIONS.LOGOUT)
|
||||
store.dispatch(AUTH_USER_STORE.ACTIONS.LOGOUT)
|
||||
}
|
||||
|
||||
return {
|
||||
|
@ -54,7 +54,7 @@
|
||||
ref,
|
||||
} from 'vue'
|
||||
|
||||
import { USER_STORE } from '@/store/constants'
|
||||
import { AUTH_USER_STORE } from '@/store/constants'
|
||||
import { IUserProfile } from '@/types/user'
|
||||
import { useStore } from '@/use/useStore'
|
||||
|
||||
@ -73,7 +73,7 @@
|
||||
setup(props) {
|
||||
const store = useStore()
|
||||
const authUser: ComputedRef<IUserProfile> = computed(
|
||||
() => store.getters[USER_STORE.GETTERS.AUTH_USER_PROFILE]
|
||||
() => store.getters[AUTH_USER_STORE.GETTERS.AUTH_USER_PROFILE]
|
||||
)
|
||||
const registrationDate = computed(() =>
|
||||
props.user.created_at
|
||||
@ -91,7 +91,7 @@
|
||||
displayModal.value = value
|
||||
}
|
||||
function deleteUserAccount(username: string) {
|
||||
store.dispatch(USER_STORE.ACTIONS.DELETE_ACCOUNT, { username })
|
||||
store.dispatch(AUTH_USER_STORE.ACTIONS.DELETE_ACCOUNT, { username })
|
||||
}
|
||||
|
||||
return {
|
||||
|
@ -106,7 +106,7 @@
|
||||
onMounted,
|
||||
} from 'vue'
|
||||
|
||||
import { ROOT_STORE, USER_STORE } from '@/store/constants'
|
||||
import { AUTH_USER_STORE, ROOT_STORE } from '@/store/constants'
|
||||
import { IUserProfile, IUserPayload } from '@/types/user'
|
||||
import { useStore } from '@/use/useStore'
|
||||
|
||||
@ -135,7 +135,7 @@
|
||||
: ''
|
||||
)
|
||||
const loading = computed(
|
||||
() => store.getters[USER_STORE.GETTERS.USER_LOADING]
|
||||
() => store.getters[AUTH_USER_STORE.GETTERS.USER_LOADING]
|
||||
)
|
||||
const errorMessages: ComputedRef<string | string[] | null> = computed(
|
||||
() => store.getters[ROOT_STORE.GETTERS.ERROR_MESSAGES]
|
||||
@ -161,13 +161,13 @@
|
||||
userForm.bio = value
|
||||
}
|
||||
function updateProfile() {
|
||||
store.dispatch(USER_STORE.ACTIONS.UPDATE_USER_PROFILE, userForm)
|
||||
store.dispatch(AUTH_USER_STORE.ACTIONS.UPDATE_USER_PROFILE, userForm)
|
||||
}
|
||||
function updateDisplayModal(value: boolean) {
|
||||
displayModal.value = value
|
||||
}
|
||||
function deleteAccount(username: string) {
|
||||
store.dispatch(USER_STORE.ACTIONS.DELETE_ACCOUNT, { username })
|
||||
store.dispatch(AUTH_USER_STORE.ACTIONS.DELETE_ACCOUNT, { username })
|
||||
}
|
||||
|
||||
return {
|
||||
|
@ -38,7 +38,7 @@
|
||||
} from 'vue'
|
||||
|
||||
import UserPicture from '@/components/User/UserPicture.vue'
|
||||
import { ROOT_STORE, USER_STORE } from '@/store/constants'
|
||||
import { AUTH_USER_STORE, ROOT_STORE } from '@/store/constants'
|
||||
import { TAppConfig } from '@/types/application'
|
||||
import { IUserProfile } from '@/types/user'
|
||||
import { useStore } from '@/use/useStore'
|
||||
@ -69,7 +69,7 @@
|
||||
let pictureFile: Ref<File | null> = ref(null)
|
||||
|
||||
function deleteUserPicture() {
|
||||
store.dispatch(USER_STORE.ACTIONS.DELETE_PICTURE)
|
||||
store.dispatch(AUTH_USER_STORE.ACTIONS.DELETE_PICTURE)
|
||||
}
|
||||
function updatePictureFile(event: Event & { target: HTMLInputElement }) {
|
||||
if (event.target.files) {
|
||||
@ -78,7 +78,7 @@
|
||||
}
|
||||
function updateUserPicture() {
|
||||
if (pictureFile.value) {
|
||||
store.dispatch(USER_STORE.ACTIONS.UPDATE_USER_PICTURE, {
|
||||
store.dispatch(AUTH_USER_STORE.ACTIONS.UPDATE_USER_PICTURE, {
|
||||
picture: pictureFile.value,
|
||||
})
|
||||
}
|
||||
|
@ -61,7 +61,7 @@
|
||||
onMounted,
|
||||
} from 'vue'
|
||||
|
||||
import { ROOT_STORE, USER_STORE } from '@/store/constants'
|
||||
import { AUTH_USER_STORE, ROOT_STORE } from '@/store/constants'
|
||||
import { IUserProfile, IUserPreferencesPayload } from '@/types/user'
|
||||
import { useStore } from '@/use/useStore'
|
||||
import { availableLanguages } from '@/utils/locales'
|
||||
@ -92,7 +92,7 @@
|
||||
},
|
||||
]
|
||||
const loading = computed(
|
||||
() => store.getters[USER_STORE.GETTERS.USER_LOADING]
|
||||
() => store.getters[AUTH_USER_STORE.GETTERS.USER_LOADING]
|
||||
)
|
||||
const errorMessages: ComputedRef<string | string[] | null> = computed(
|
||||
() => store.getters[ROOT_STORE.GETTERS.ERROR_MESSAGES]
|
||||
@ -110,7 +110,10 @@
|
||||
userForm.weekm = user.weekm ? user.weekm : false
|
||||
}
|
||||
function updateProfile() {
|
||||
store.dispatch(USER_STORE.ACTIONS.UPDATE_USER_PREFERENCES, userForm)
|
||||
store.dispatch(
|
||||
AUTH_USER_STORE.ACTIONS.UPDATE_USER_PREFERENCES,
|
||||
userForm
|
||||
)
|
||||
}
|
||||
|
||||
return {
|
||||
|
@ -21,7 +21,7 @@
|
||||
import { computed, defineComponent, PropType } from 'vue'
|
||||
|
||||
import UserProfileTabs from '@/components/User/UserProfileTabs.vue'
|
||||
import { USER_STORE } from '@/store/constants'
|
||||
import { AUTH_USER_STORE } from '@/store/constants'
|
||||
import { IUserProfile } from '@/types/user'
|
||||
import { useStore } from '@/use/useStore'
|
||||
|
||||
@ -43,7 +43,9 @@
|
||||
setup() {
|
||||
const store = useStore()
|
||||
return {
|
||||
loading: computed(() => store.getters[USER_STORE.GETTERS.USER_LOADING]),
|
||||
loading: computed(
|
||||
() => store.getters[AUTH_USER_STORE.GETTERS.USER_LOADING]
|
||||
),
|
||||
tabs: ['PROFILE', 'PICTURE', 'PREFERENCES'],
|
||||
}
|
||||
},
|
||||
|
@ -80,7 +80,7 @@
|
||||
import { ComputedRef, computed, defineComponent, reactive, watch } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
|
||||
import { ROOT_STORE, USER_STORE } from '@/store/constants'
|
||||
import { AUTH_USER_STORE, ROOT_STORE } from '@/store/constants'
|
||||
import { TAppConfig } from '@/types/application'
|
||||
import { ILoginRegisterFormData } from '@/types/user'
|
||||
import { useStore } from '@/use/useStore'
|
||||
@ -140,20 +140,20 @@
|
||||
'user.INVALID_TOKEN'
|
||||
)
|
||||
}
|
||||
return store.dispatch(USER_STORE.ACTIONS.RESET_USER_PASSWORD, {
|
||||
return store.dispatch(AUTH_USER_STORE.ACTIONS.RESET_USER_PASSWORD, {
|
||||
password: formData.password,
|
||||
password_conf: formData.password_conf,
|
||||
token: props.token,
|
||||
})
|
||||
case 'reset-request':
|
||||
return store.dispatch(
|
||||
USER_STORE.ACTIONS.SEND_PASSWORD_RESET_REQUEST,
|
||||
AUTH_USER_STORE.ACTIONS.SEND_PASSWORD_RESET_REQUEST,
|
||||
{
|
||||
email: formData.email,
|
||||
}
|
||||
)
|
||||
default:
|
||||
store.dispatch(USER_STORE.ACTIONS.LOGIN_OR_REGISTER, {
|
||||
store.dispatch(AUTH_USER_STORE.ACTIONS.LOGIN_OR_REGISTER, {
|
||||
actionType,
|
||||
formData,
|
||||
redirectUrl: route.query.from,
|
||||
|
@ -12,7 +12,7 @@ import UserInfosEdition from '@/components/User/ProfileEdition/UserInfosEdition.
|
||||
import UserPictureEdition from '@/components/User/ProfileEdition/UserPictureEdition.vue'
|
||||
import UserPreferencesEdition from '@/components/User/ProfileEdition/UserPreferencesEdition.vue'
|
||||
import store from '@/store'
|
||||
import { USER_STORE } from '@/store/constants'
|
||||
import { AUTH_USER_STORE } from '@/store/constants'
|
||||
|
||||
const getTabFromPath = (path: string): string => {
|
||||
const regex = /(\/profile)(\/edit)*(\/*)/
|
||||
@ -238,15 +238,15 @@ const pathsWithoutAuthentication = [
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
store
|
||||
.dispatch(USER_STORE.ACTIONS.CHECK_AUTH_USER)
|
||||
.dispatch(AUTH_USER_STORE.ACTIONS.CHECK_AUTH_USER)
|
||||
.then(() => {
|
||||
if (
|
||||
store.getters[USER_STORE.GETTERS.IS_AUTHENTICATED] &&
|
||||
store.getters[AUTH_USER_STORE.GETTERS.IS_AUTHENTICATED] &&
|
||||
pathsWithoutAuthentication.includes(to.path)
|
||||
) {
|
||||
return next('/')
|
||||
} else if (
|
||||
!store.getters[USER_STORE.GETTERS.IS_AUTHENTICATED] &&
|
||||
!store.getters[AUTH_USER_STORE.GETTERS.IS_AUTHENTICATED] &&
|
||||
!pathsWithoutAuthentication.includes(to.path)
|
||||
) {
|
||||
const path =
|
||||
|
@ -1,3 +1,8 @@
|
||||
import {
|
||||
AuthUserActions,
|
||||
AuthUserGetters,
|
||||
AuthUserMutations,
|
||||
} from '@/store/modules/authUser/enums'
|
||||
import {
|
||||
RootActions,
|
||||
RootGetters,
|
||||
@ -13,11 +18,6 @@ import {
|
||||
StatisticsGetters,
|
||||
StatisticsMutations,
|
||||
} from '@/store/modules/statistics/enums'
|
||||
import {
|
||||
UserActions,
|
||||
UserGetters,
|
||||
UserMutations,
|
||||
} from '@/store/modules/user/enums'
|
||||
import {
|
||||
UsersActions,
|
||||
UsersGetters,
|
||||
@ -47,10 +47,10 @@ export const STATS_STORE = {
|
||||
MUTATIONS: StatisticsMutations,
|
||||
}
|
||||
|
||||
export const USER_STORE = {
|
||||
ACTIONS: UserActions,
|
||||
GETTERS: UserGetters,
|
||||
MUTATIONS: UserMutations,
|
||||
export const AUTH_USER_STORE = {
|
||||
ACTIONS: AuthUserActions,
|
||||
GETTERS: AuthUserGetters,
|
||||
MUTATIONS: AuthUserMutations,
|
||||
}
|
||||
|
||||
export const USERS_STORE = {
|
||||
|
@ -5,15 +5,18 @@ import api from '@/api/defaultApi'
|
||||
import createI18n from '@/i18n'
|
||||
import router from '@/router'
|
||||
import {
|
||||
AUTH_USER_STORE,
|
||||
ROOT_STORE,
|
||||
SPORTS_STORE,
|
||||
STATS_STORE,
|
||||
USER_STORE,
|
||||
USERS_STORE,
|
||||
WORKOUTS_STORE,
|
||||
} from '@/store/constants'
|
||||
import {
|
||||
IAuthUserActions,
|
||||
IAuthUserState,
|
||||
} from '@/store/modules/authUser/types'
|
||||
import { IRootState } from '@/store/modules/root/types'
|
||||
import { IUserActions, IUserState } from '@/store/modules/user/types'
|
||||
import {
|
||||
ILoginOrRegisterData,
|
||||
IUserDeletionPayload,
|
||||
@ -27,34 +30,37 @@ import { handleError } from '@/utils'
|
||||
|
||||
const { locale } = createI18n.global
|
||||
|
||||
const removeUserData = (context: ActionContext<IUserState, IRootState>) => {
|
||||
const removeAuthUserData = (
|
||||
context: ActionContext<IAuthUserState, IRootState>
|
||||
) => {
|
||||
localStorage.removeItem('authToken')
|
||||
context.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES)
|
||||
context.commit(STATS_STORE.MUTATIONS.EMPTY_USER_STATS)
|
||||
context.commit(USER_STORE.MUTATIONS.CLEAR_AUTH_USER_TOKEN)
|
||||
context.commit(AUTH_USER_STORE.MUTATIONS.CLEAR_AUTH_USER_TOKEN)
|
||||
context.commit(USERS_STORE.MUTATIONS.UPDATE_USERS, [])
|
||||
context.commit(WORKOUTS_STORE.MUTATIONS.EMPTY_WORKOUTS)
|
||||
context.commit(WORKOUTS_STORE.MUTATIONS.EMPTY_WORKOUT)
|
||||
router.push('/login')
|
||||
}
|
||||
|
||||
export const actions: ActionTree<IUserState, IRootState> & IUserActions = {
|
||||
[USER_STORE.ACTIONS.CHECK_AUTH_USER](
|
||||
context: ActionContext<IUserState, IRootState>
|
||||
export const actions: ActionTree<IAuthUserState, IRootState> &
|
||||
IAuthUserActions = {
|
||||
[AUTH_USER_STORE.ACTIONS.CHECK_AUTH_USER](
|
||||
context: ActionContext<IAuthUserState, IRootState>
|
||||
): void {
|
||||
if (
|
||||
window.localStorage.authToken &&
|
||||
!context.getters[USER_STORE.GETTERS.IS_AUTHENTICATED]
|
||||
!context.getters[AUTH_USER_STORE.GETTERS.IS_AUTHENTICATED]
|
||||
) {
|
||||
context.commit(
|
||||
USER_STORE.MUTATIONS.UPDATE_AUTH_TOKEN,
|
||||
AUTH_USER_STORE.MUTATIONS.UPDATE_AUTH_TOKEN,
|
||||
window.localStorage.authToken
|
||||
)
|
||||
context.dispatch(USER_STORE.ACTIONS.GET_USER_PROFILE)
|
||||
context.dispatch(AUTH_USER_STORE.ACTIONS.GET_USER_PROFILE)
|
||||
}
|
||||
},
|
||||
[USER_STORE.ACTIONS.GET_USER_PROFILE](
|
||||
context: ActionContext<IUserState, IRootState>
|
||||
[AUTH_USER_STORE.ACTIONS.GET_USER_PROFILE](
|
||||
context: ActionContext<IAuthUserState, IRootState>
|
||||
): void {
|
||||
context.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES)
|
||||
authApi
|
||||
@ -62,7 +68,7 @@ export const actions: ActionTree<IUserState, IRootState> & IUserActions = {
|
||||
.then((res) => {
|
||||
if (res.data.status === 'success') {
|
||||
context.commit(
|
||||
USER_STORE.MUTATIONS.UPDATE_AUTH_USER_PROFILE,
|
||||
AUTH_USER_STORE.MUTATIONS.UPDATE_AUTH_USER_PROFILE,
|
||||
res.data.data
|
||||
)
|
||||
if (res.data.data.language) {
|
||||
@ -75,16 +81,16 @@ export const actions: ActionTree<IUserState, IRootState> & IUserActions = {
|
||||
context.dispatch(SPORTS_STORE.ACTIONS.GET_SPORTS)
|
||||
} else {
|
||||
handleError(context, null)
|
||||
removeUserData(context)
|
||||
removeAuthUserData(context)
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
handleError(context, error)
|
||||
removeUserData(context)
|
||||
removeAuthUserData(context)
|
||||
})
|
||||
},
|
||||
[USER_STORE.ACTIONS.LOGIN_OR_REGISTER](
|
||||
context: ActionContext<IUserState, IRootState>,
|
||||
[AUTH_USER_STORE.ACTIONS.LOGIN_OR_REGISTER](
|
||||
context: ActionContext<IAuthUserState, IRootState>,
|
||||
data: ILoginOrRegisterData
|
||||
): void {
|
||||
context.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES)
|
||||
@ -94,9 +100,9 @@ export const actions: ActionTree<IUserState, IRootState> & IUserActions = {
|
||||
if (res.data.status === 'success') {
|
||||
const token = res.data.auth_token
|
||||
window.localStorage.setItem('authToken', token)
|
||||
context.commit(USER_STORE.MUTATIONS.UPDATE_AUTH_TOKEN, token)
|
||||
context.commit(AUTH_USER_STORE.MUTATIONS.UPDATE_AUTH_TOKEN, token)
|
||||
context
|
||||
.dispatch(USER_STORE.ACTIONS.GET_USER_PROFILE)
|
||||
.dispatch(AUTH_USER_STORE.ACTIONS.GET_USER_PROFILE)
|
||||
.then(() =>
|
||||
router.push(
|
||||
typeof data.redirectUrl === 'string' ? data.redirectUrl : '/'
|
||||
@ -108,23 +114,23 @@ export const actions: ActionTree<IUserState, IRootState> & IUserActions = {
|
||||
})
|
||||
.catch((error) => handleError(context, error))
|
||||
},
|
||||
[USER_STORE.ACTIONS.LOGOUT](
|
||||
context: ActionContext<IUserState, IRootState>
|
||||
[AUTH_USER_STORE.ACTIONS.LOGOUT](
|
||||
context: ActionContext<IAuthUserState, IRootState>
|
||||
): void {
|
||||
removeUserData(context)
|
||||
removeAuthUserData(context)
|
||||
},
|
||||
[USER_STORE.ACTIONS.UPDATE_USER_PROFILE](
|
||||
context: ActionContext<IUserState, IRootState>,
|
||||
[AUTH_USER_STORE.ACTIONS.UPDATE_USER_PROFILE](
|
||||
context: ActionContext<IAuthUserState, IRootState>,
|
||||
payload: IUserPayload
|
||||
): void {
|
||||
context.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES)
|
||||
context.commit(USER_STORE.MUTATIONS.UPDATE_USER_LOADING, true)
|
||||
context.commit(AUTH_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,
|
||||
AUTH_USER_STORE.MUTATIONS.UPDATE_AUTH_USER_PROFILE,
|
||||
res.data.data
|
||||
)
|
||||
router.push('/profile')
|
||||
@ -134,21 +140,21 @@ export const actions: ActionTree<IUserState, IRootState> & IUserActions = {
|
||||
})
|
||||
.catch((error) => handleError(context, error))
|
||||
.finally(() =>
|
||||
context.commit(USER_STORE.MUTATIONS.UPDATE_USER_LOADING, false)
|
||||
context.commit(AUTH_USER_STORE.MUTATIONS.UPDATE_USER_LOADING, false)
|
||||
)
|
||||
},
|
||||
[USER_STORE.ACTIONS.UPDATE_USER_PREFERENCES](
|
||||
context: ActionContext<IUserState, IRootState>,
|
||||
[AUTH_USER_STORE.ACTIONS.UPDATE_USER_PREFERENCES](
|
||||
context: ActionContext<IAuthUserState, IRootState>,
|
||||
payload: IUserPreferencesPayload
|
||||
): void {
|
||||
context.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES)
|
||||
context.commit(USER_STORE.MUTATIONS.UPDATE_USER_LOADING, true)
|
||||
context.commit(AUTH_USER_STORE.MUTATIONS.UPDATE_USER_LOADING, true)
|
||||
authApi
|
||||
.post('auth/profile/edit/preferences', payload)
|
||||
.then((res) => {
|
||||
if (res.data.status === 'success') {
|
||||
context.commit(
|
||||
USER_STORE.MUTATIONS.UPDATE_AUTH_USER_PROFILE,
|
||||
AUTH_USER_STORE.MUTATIONS.UPDATE_AUTH_USER_PROFILE,
|
||||
res.data.data
|
||||
)
|
||||
context.commit(
|
||||
@ -163,15 +169,15 @@ export const actions: ActionTree<IUserState, IRootState> & IUserActions = {
|
||||
})
|
||||
.catch((error) => handleError(context, error))
|
||||
.finally(() =>
|
||||
context.commit(USER_STORE.MUTATIONS.UPDATE_USER_LOADING, false)
|
||||
context.commit(AUTH_USER_STORE.MUTATIONS.UPDATE_USER_LOADING, false)
|
||||
)
|
||||
},
|
||||
[USER_STORE.ACTIONS.UPDATE_USER_PICTURE](
|
||||
context: ActionContext<IUserState, IRootState>,
|
||||
[AUTH_USER_STORE.ACTIONS.UPDATE_USER_PICTURE](
|
||||
context: ActionContext<IAuthUserState, IRootState>,
|
||||
payload: IUserPicturePayload
|
||||
): void {
|
||||
context.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES)
|
||||
context.commit(USER_STORE.MUTATIONS.UPDATE_USER_LOADING, true)
|
||||
context.commit(AUTH_USER_STORE.MUTATIONS.UPDATE_USER_LOADING, true)
|
||||
if (!payload.picture) {
|
||||
throw new Error('No file part')
|
||||
}
|
||||
@ -186,7 +192,7 @@ export const actions: ActionTree<IUserState, IRootState> & IUserActions = {
|
||||
.then((res) => {
|
||||
if (res.data.status === 'success') {
|
||||
context
|
||||
.dispatch(USER_STORE.ACTIONS.GET_USER_PROFILE)
|
||||
.dispatch(AUTH_USER_STORE.ACTIONS.GET_USER_PROFILE)
|
||||
.then(() => router.push('/profile'))
|
||||
} else {
|
||||
handleError(context, null)
|
||||
@ -194,11 +200,11 @@ export const actions: ActionTree<IUserState, IRootState> & IUserActions = {
|
||||
})
|
||||
.catch((error) => handleError(context, error))
|
||||
.finally(() =>
|
||||
context.commit(USER_STORE.MUTATIONS.UPDATE_USER_LOADING, false)
|
||||
context.commit(AUTH_USER_STORE.MUTATIONS.UPDATE_USER_LOADING, false)
|
||||
)
|
||||
},
|
||||
[USER_STORE.ACTIONS.DELETE_ACCOUNT](
|
||||
context: ActionContext<IUserState, IRootState>,
|
||||
[AUTH_USER_STORE.ACTIONS.DELETE_ACCOUNT](
|
||||
context: ActionContext<IAuthUserState, IRootState>,
|
||||
payload: IUserDeletionPayload
|
||||
): void {
|
||||
context.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES)
|
||||
@ -207,7 +213,7 @@ export const actions: ActionTree<IUserState, IRootState> & IUserActions = {
|
||||
.then((res) => {
|
||||
if (res.status === 204) {
|
||||
context
|
||||
.dispatch(USER_STORE.ACTIONS.LOGOUT)
|
||||
.dispatch(AUTH_USER_STORE.ACTIONS.LOGOUT)
|
||||
.then(() => router.push('/'))
|
||||
} else {
|
||||
handleError(context, null)
|
||||
@ -215,17 +221,17 @@ export const actions: ActionTree<IUserState, IRootState> & IUserActions = {
|
||||
})
|
||||
.catch((error) => handleError(context, error))
|
||||
},
|
||||
[USER_STORE.ACTIONS.DELETE_PICTURE](
|
||||
context: ActionContext<IUserState, IRootState>
|
||||
[AUTH_USER_STORE.ACTIONS.DELETE_PICTURE](
|
||||
context: ActionContext<IAuthUserState, IRootState>
|
||||
): void {
|
||||
context.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES)
|
||||
context.commit(USER_STORE.MUTATIONS.UPDATE_USER_LOADING, true)
|
||||
context.commit(AUTH_USER_STORE.MUTATIONS.UPDATE_USER_LOADING, true)
|
||||
authApi
|
||||
.delete(`auth/picture`)
|
||||
.then((res) => {
|
||||
if (res.status === 204) {
|
||||
context
|
||||
.dispatch(USER_STORE.ACTIONS.GET_USER_PROFILE)
|
||||
.dispatch(AUTH_USER_STORE.ACTIONS.GET_USER_PROFILE)
|
||||
.then(() => router.push('/profile'))
|
||||
} else {
|
||||
handleError(context, null)
|
||||
@ -233,11 +239,11 @@ export const actions: ActionTree<IUserState, IRootState> & IUserActions = {
|
||||
})
|
||||
.catch((error) => handleError(context, error))
|
||||
.finally(() =>
|
||||
context.commit(USER_STORE.MUTATIONS.UPDATE_USER_LOADING, false)
|
||||
context.commit(AUTH_USER_STORE.MUTATIONS.UPDATE_USER_LOADING, false)
|
||||
)
|
||||
},
|
||||
[USER_STORE.ACTIONS.SEND_PASSWORD_RESET_REQUEST](
|
||||
context: ActionContext<IUserState, IRootState>,
|
||||
[AUTH_USER_STORE.ACTIONS.SEND_PASSWORD_RESET_REQUEST](
|
||||
context: ActionContext<IAuthUserState, IRootState>,
|
||||
payload: IUserPasswordPayload
|
||||
): void {
|
||||
context.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES)
|
||||
@ -252,8 +258,8 @@ export const actions: ActionTree<IUserState, IRootState> & IUserActions = {
|
||||
})
|
||||
.catch((error) => handleError(context, error))
|
||||
},
|
||||
[USER_STORE.ACTIONS.RESET_USER_PASSWORD](
|
||||
context: ActionContext<IUserState, IRootState>,
|
||||
[AUTH_USER_STORE.ACTIONS.RESET_USER_PASSWORD](
|
||||
context: ActionContext<IAuthUserState, IRootState>,
|
||||
payload: IUserPasswordResetPayload
|
||||
): void {
|
||||
context.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES)
|
@ -1,4 +1,4 @@
|
||||
export enum UserActions {
|
||||
export enum AuthUserActions {
|
||||
CHECK_AUTH_USER = 'CHECK_AUTH_USER',
|
||||
DELETE_ACCOUNT = 'DELETE_ACCOUNT',
|
||||
DELETE_PICTURE = 'DELETE_PICTURE',
|
||||
@ -12,7 +12,7 @@ export enum UserActions {
|
||||
UPDATE_USER_PREFERENCES = 'UPDATE_USER_PREFERENCES',
|
||||
}
|
||||
|
||||
export enum UserGetters {
|
||||
export enum AuthUserGetters {
|
||||
AUTH_TOKEN = 'AUTH_TOKEN',
|
||||
AUTH_USER_PROFILE = 'AUTH_USER_PROFILE',
|
||||
IS_ADMIN = 'IS_ADMIN',
|
||||
@ -20,7 +20,7 @@ export enum UserGetters {
|
||||
USER_LOADING = 'USER_LOADING',
|
||||
}
|
||||
|
||||
export enum UserMutations {
|
||||
export enum AuthUserMutations {
|
||||
CLEAR_AUTH_USER_TOKEN = 'CLEAR_AUTH_USER_TOKEN',
|
||||
UPDATE_AUTH_TOKEN = 'UPDATE_AUTH_TOKEN',
|
||||
UPDATE_AUTH_USER_PROFILE = 'UPDATE_AUTH_USER_PROFILE',
|
27
fittrackee_client/src/store/modules/authUser/getters.ts
Normal file
27
fittrackee_client/src/store/modules/authUser/getters.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import { GetterTree } from 'vuex'
|
||||
|
||||
import { AUTH_USER_STORE } from '@/store/constants'
|
||||
import {
|
||||
IAuthUserGetters,
|
||||
IAuthUserState,
|
||||
} from '@/store/modules/authUser/types'
|
||||
import { IRootState } from '@/store/modules/root/types'
|
||||
|
||||
export const getters: GetterTree<IAuthUserState, IRootState> &
|
||||
IAuthUserGetters = {
|
||||
[AUTH_USER_STORE.GETTERS.AUTH_TOKEN]: (state: IAuthUserState) => {
|
||||
return state.authToken
|
||||
},
|
||||
[AUTH_USER_STORE.GETTERS.AUTH_USER_PROFILE]: (state: IAuthUserState) => {
|
||||
return state.authUserProfile
|
||||
},
|
||||
[AUTH_USER_STORE.GETTERS.IS_AUTHENTICATED]: (state: IAuthUserState) => {
|
||||
return state.authToken !== null
|
||||
},
|
||||
[AUTH_USER_STORE.GETTERS.IS_ADMIN]: (state: IAuthUserState) => {
|
||||
return state.authUserProfile && state.authUserProfile.admin
|
||||
},
|
||||
[AUTH_USER_STORE.GETTERS.USER_LOADING]: (state: IAuthUserState) => {
|
||||
return state.loading
|
||||
},
|
||||
}
|
17
fittrackee_client/src/store/modules/authUser/index.ts
Normal file
17
fittrackee_client/src/store/modules/authUser/index.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { Module } from 'vuex'
|
||||
|
||||
import { actions } from '@/store/modules/authUser/actions'
|
||||
import { getters } from '@/store/modules/authUser/getters'
|
||||
import { mutations } from '@/store/modules/authUser/mutations'
|
||||
import { authUserState } from '@/store/modules/authUser/state.ts'
|
||||
import { IAuthUserState } from '@/store/modules/authUser/types'
|
||||
import { IRootState } from '@/store/modules/root/types'
|
||||
|
||||
const authUser: Module<IAuthUserState, IRootState> = {
|
||||
state: authUserState,
|
||||
actions,
|
||||
getters,
|
||||
mutations,
|
||||
}
|
||||
|
||||
export default authUser
|
33
fittrackee_client/src/store/modules/authUser/mutations.ts
Normal file
33
fittrackee_client/src/store/modules/authUser/mutations.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import { MutationTree } from 'vuex'
|
||||
|
||||
import { AUTH_USER_STORE } from '@/store/constants'
|
||||
import {
|
||||
IAuthUserState,
|
||||
TAuthUserMutations,
|
||||
} from '@/store/modules/authUser/types'
|
||||
import { IUserProfile } from '@/types/user'
|
||||
|
||||
export const mutations: MutationTree<IAuthUserState> & TAuthUserMutations = {
|
||||
[AUTH_USER_STORE.MUTATIONS.CLEAR_AUTH_USER_TOKEN](state: IAuthUserState) {
|
||||
state.authToken = null
|
||||
state.authUserProfile = <IUserProfile>{}
|
||||
},
|
||||
[AUTH_USER_STORE.MUTATIONS.UPDATE_AUTH_TOKEN](
|
||||
state: IAuthUserState,
|
||||
authToken: string
|
||||
) {
|
||||
state.authToken = authToken
|
||||
},
|
||||
[AUTH_USER_STORE.MUTATIONS.UPDATE_AUTH_USER_PROFILE](
|
||||
state: IAuthUserState,
|
||||
authUserProfile: IUserProfile
|
||||
) {
|
||||
state.authUserProfile = authUserProfile
|
||||
},
|
||||
[AUTH_USER_STORE.MUTATIONS.UPDATE_USER_LOADING](
|
||||
state: IAuthUserState,
|
||||
loading: boolean
|
||||
) {
|
||||
state.loading = loading
|
||||
},
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
import { IUserState } from '@/store/modules/user/types'
|
||||
import { IAuthUserState } from '@/store/modules/authUser/types'
|
||||
import { IUserProfile } from '@/types/user'
|
||||
|
||||
export const userState: IUserState = {
|
||||
export const authUserState: IAuthUserState = {
|
||||
authToken: null,
|
||||
authUserProfile: <IUserProfile>{},
|
||||
loading: false,
|
132
fittrackee_client/src/store/modules/authUser/types.ts
Normal file
132
fittrackee_client/src/store/modules/authUser/types.ts
Normal file
@ -0,0 +1,132 @@
|
||||
import {
|
||||
ActionContext,
|
||||
CommitOptions,
|
||||
DispatchOptions,
|
||||
Store as VuexStore,
|
||||
} from 'vuex'
|
||||
|
||||
import { AUTH_USER_STORE } from '@/store/constants'
|
||||
import { IRootState } from '@/store/modules/root/types'
|
||||
import {
|
||||
IUserProfile,
|
||||
ILoginOrRegisterData,
|
||||
IUserDeletionPayload,
|
||||
IUserPasswordPayload,
|
||||
IUserPasswordResetPayload,
|
||||
IUserPayload,
|
||||
IUserPicturePayload,
|
||||
IUserPreferencesPayload,
|
||||
} from '@/types/user'
|
||||
|
||||
export interface IAuthUserState {
|
||||
authToken: string | null
|
||||
authUserProfile: IUserProfile
|
||||
loading: boolean
|
||||
}
|
||||
|
||||
export interface IAuthUserActions {
|
||||
[AUTH_USER_STORE.ACTIONS.CHECK_AUTH_USER](
|
||||
context: ActionContext<IAuthUserState, IRootState>
|
||||
): void
|
||||
|
||||
[AUTH_USER_STORE.ACTIONS.GET_USER_PROFILE](
|
||||
context: ActionContext<IAuthUserState, IRootState>
|
||||
): void
|
||||
|
||||
[AUTH_USER_STORE.ACTIONS.LOGIN_OR_REGISTER](
|
||||
context: ActionContext<IAuthUserState, IRootState>,
|
||||
data: ILoginOrRegisterData
|
||||
): void
|
||||
|
||||
[AUTH_USER_STORE.ACTIONS.LOGOUT](
|
||||
context: ActionContext<IAuthUserState, IRootState>
|
||||
): void
|
||||
|
||||
[AUTH_USER_STORE.ACTIONS.UPDATE_USER_PROFILE](
|
||||
context: ActionContext<IAuthUserState, IRootState>,
|
||||
payload: IUserPayload
|
||||
): void
|
||||
|
||||
[AUTH_USER_STORE.ACTIONS.UPDATE_USER_PREFERENCES](
|
||||
context: ActionContext<IAuthUserState, IRootState>,
|
||||
payload: IUserPreferencesPayload
|
||||
): void
|
||||
|
||||
[AUTH_USER_STORE.ACTIONS.UPDATE_USER_PICTURE](
|
||||
context: ActionContext<IAuthUserState, IRootState>,
|
||||
payload: IUserPicturePayload
|
||||
): void
|
||||
|
||||
[AUTH_USER_STORE.ACTIONS.SEND_PASSWORD_RESET_REQUEST](
|
||||
context: ActionContext<IAuthUserState, IRootState>,
|
||||
payload: IUserPasswordPayload
|
||||
): void
|
||||
|
||||
[AUTH_USER_STORE.ACTIONS.RESET_USER_PASSWORD](
|
||||
context: ActionContext<IAuthUserState, IRootState>,
|
||||
payload: IUserPasswordResetPayload
|
||||
): void
|
||||
|
||||
[AUTH_USER_STORE.ACTIONS.DELETE_ACCOUNT](
|
||||
context: ActionContext<IAuthUserState, IRootState>,
|
||||
payload: IUserDeletionPayload
|
||||
): void
|
||||
|
||||
[AUTH_USER_STORE.ACTIONS.DELETE_PICTURE](
|
||||
context: ActionContext<IAuthUserState, IRootState>
|
||||
): void
|
||||
}
|
||||
|
||||
export interface IAuthUserGetters {
|
||||
[AUTH_USER_STORE.GETTERS.AUTH_TOKEN](state: IAuthUserState): string | null
|
||||
|
||||
[AUTH_USER_STORE.GETTERS.AUTH_USER_PROFILE](
|
||||
state: IAuthUserState
|
||||
): IUserProfile
|
||||
|
||||
[AUTH_USER_STORE.GETTERS.IS_ADMIN](state: IAuthUserState): boolean
|
||||
|
||||
[AUTH_USER_STORE.GETTERS.IS_AUTHENTICATED](state: IAuthUserState): boolean
|
||||
|
||||
[AUTH_USER_STORE.GETTERS.USER_LOADING](state: IAuthUserState): boolean
|
||||
}
|
||||
|
||||
export type TAuthUserMutations<S = IAuthUserState> = {
|
||||
[AUTH_USER_STORE.MUTATIONS.CLEAR_AUTH_USER_TOKEN](state: S): void
|
||||
[AUTH_USER_STORE.MUTATIONS.UPDATE_AUTH_TOKEN](
|
||||
state: S,
|
||||
authToken: string
|
||||
): void
|
||||
[AUTH_USER_STORE.MUTATIONS.UPDATE_AUTH_USER_PROFILE](
|
||||
state: S,
|
||||
authUserProfile: IUserProfile
|
||||
): void
|
||||
[AUTH_USER_STORE.MUTATIONS.UPDATE_USER_LOADING](
|
||||
state: S,
|
||||
loading: boolean
|
||||
): void
|
||||
}
|
||||
|
||||
export type TAuthUserStoreModule<S = IAuthUserState> = Omit<
|
||||
VuexStore<S>,
|
||||
'commit' | 'getters' | 'dispatch'
|
||||
> & {
|
||||
dispatch<K extends keyof IAuthUserActions>(
|
||||
key: K,
|
||||
payload?: Parameters<IAuthUserActions[K]>[1],
|
||||
options?: DispatchOptions
|
||||
): ReturnType<IAuthUserActions[K]>
|
||||
} & {
|
||||
getters: {
|
||||
[K in keyof IAuthUserGetters]: ReturnType<IAuthUserGetters[K]>
|
||||
}
|
||||
} & {
|
||||
commit<
|
||||
K extends keyof TAuthUserMutations,
|
||||
P extends Parameters<TAuthUserMutations[K]>[1]
|
||||
>(
|
||||
key: K,
|
||||
payload?: P,
|
||||
options?: CommitOptions
|
||||
): ReturnType<TAuthUserMutations[K]>
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
import { Module, ModuleTree } from 'vuex'
|
||||
|
||||
import authUserModule from '@/store/modules/authUser'
|
||||
import { actions } from '@/store/modules/root/actions'
|
||||
import { getters } from '@/store/modules/root/getters'
|
||||
import { mutations } from '@/store/modules/root/mutations'
|
||||
@ -7,14 +8,13 @@ import { state } from '@/store/modules/root/state.ts'
|
||||
import { IRootState } from '@/store/modules/root/types'
|
||||
import sportsModule from '@/store/modules/sports'
|
||||
import statsModule from '@/store/modules/statistics'
|
||||
import userModule from '@/store/modules/user'
|
||||
import usersModule from '@/store/modules/users'
|
||||
import workoutsModule from '@/store/modules/workouts'
|
||||
|
||||
const modules: ModuleTree<IRootState> = {
|
||||
authUserModule,
|
||||
sportsModule,
|
||||
statsModule,
|
||||
userModule,
|
||||
usersModule,
|
||||
workoutsModule,
|
||||
}
|
||||
|
@ -1,23 +0,0 @@
|
||||
import { GetterTree } from 'vuex'
|
||||
|
||||
import { USER_STORE } from '@/store/constants'
|
||||
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) => {
|
||||
return state.authToken
|
||||
},
|
||||
[USER_STORE.GETTERS.AUTH_USER_PROFILE]: (state: IUserState) => {
|
||||
return state.authUserProfile
|
||||
},
|
||||
[USER_STORE.GETTERS.IS_AUTHENTICATED]: (state: IUserState) => {
|
||||
return state.authToken !== null
|
||||
},
|
||||
[USER_STORE.GETTERS.IS_ADMIN]: (state: IUserState) => {
|
||||
return state.authUserProfile && state.authUserProfile.admin
|
||||
},
|
||||
[USER_STORE.GETTERS.USER_LOADING]: (state: IUserState) => {
|
||||
return state.loading
|
||||
},
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
import { Module } from 'vuex'
|
||||
|
||||
import { IRootState } from '@/store/modules/root/types'
|
||||
import { actions } from '@/store/modules/user/actions'
|
||||
import { getters } from '@/store/modules/user/getters'
|
||||
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,
|
||||
actions,
|
||||
getters,
|
||||
mutations,
|
||||
}
|
||||
|
||||
export default user
|
@ -1,30 +0,0 @@
|
||||
import { MutationTree } from 'vuex'
|
||||
|
||||
import { USER_STORE } from '@/store/constants'
|
||||
import { IUserState, TUserMutations } from '@/store/modules/user/types'
|
||||
import { IUserProfile } from '@/types/user'
|
||||
|
||||
export const mutations: MutationTree<IUserState> & TUserMutations = {
|
||||
[USER_STORE.MUTATIONS.CLEAR_AUTH_USER_TOKEN](state: IUserState) {
|
||||
state.authToken = null
|
||||
state.authUserProfile = <IUserProfile>{}
|
||||
},
|
||||
[USER_STORE.MUTATIONS.UPDATE_AUTH_TOKEN](
|
||||
state: IUserState,
|
||||
authToken: string
|
||||
) {
|
||||
state.authToken = authToken
|
||||
},
|
||||
[USER_STORE.MUTATIONS.UPDATE_AUTH_USER_PROFILE](
|
||||
state: IUserState,
|
||||
authUserProfile: IUserProfile
|
||||
) {
|
||||
state.authUserProfile = authUserProfile
|
||||
},
|
||||
[USER_STORE.MUTATIONS.UPDATE_USER_LOADING](
|
||||
state: IUserState,
|
||||
loading: boolean
|
||||
) {
|
||||
state.loading = loading
|
||||
},
|
||||
}
|
@ -1,124 +0,0 @@
|
||||
import {
|
||||
ActionContext,
|
||||
CommitOptions,
|
||||
DispatchOptions,
|
||||
Store as VuexStore,
|
||||
} from 'vuex'
|
||||
|
||||
import { USER_STORE } from '@/store/constants'
|
||||
import { IRootState } from '@/store/modules/root/types'
|
||||
import {
|
||||
IUserProfile,
|
||||
ILoginOrRegisterData,
|
||||
IUserDeletionPayload,
|
||||
IUserPasswordPayload,
|
||||
IUserPasswordResetPayload,
|
||||
IUserPayload,
|
||||
IUserPicturePayload,
|
||||
IUserPreferencesPayload,
|
||||
} from '@/types/user'
|
||||
|
||||
export interface IUserState {
|
||||
authToken: string | null
|
||||
authUserProfile: IUserProfile
|
||||
loading: boolean
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
[USER_STORE.ACTIONS.UPDATE_USER_PROFILE](
|
||||
context: ActionContext<IUserState, IRootState>,
|
||||
payload: IUserPayload
|
||||
): void
|
||||
|
||||
[USER_STORE.ACTIONS.UPDATE_USER_PREFERENCES](
|
||||
context: ActionContext<IUserState, IRootState>,
|
||||
payload: IUserPreferencesPayload
|
||||
): void
|
||||
|
||||
[USER_STORE.ACTIONS.UPDATE_USER_PICTURE](
|
||||
context: ActionContext<IUserState, IRootState>,
|
||||
payload: IUserPicturePayload
|
||||
): void
|
||||
|
||||
[USER_STORE.ACTIONS.SEND_PASSWORD_RESET_REQUEST](
|
||||
context: ActionContext<IUserState, IRootState>,
|
||||
payload: IUserPasswordPayload
|
||||
): void
|
||||
|
||||
[USER_STORE.ACTIONS.RESET_USER_PASSWORD](
|
||||
context: ActionContext<IUserState, IRootState>,
|
||||
payload: IUserPasswordResetPayload
|
||||
): void
|
||||
|
||||
[USER_STORE.ACTIONS.DELETE_ACCOUNT](
|
||||
context: ActionContext<IUserState, IRootState>,
|
||||
payload: IUserDeletionPayload
|
||||
): void
|
||||
|
||||
[USER_STORE.ACTIONS.DELETE_PICTURE](
|
||||
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): IUserProfile
|
||||
|
||||
[USER_STORE.GETTERS.IS_ADMIN](state: IUserState): boolean
|
||||
|
||||
[USER_STORE.GETTERS.IS_AUTHENTICATED](state: IUserState): boolean
|
||||
|
||||
[USER_STORE.GETTERS.USER_LOADING](state: IUserState): boolean
|
||||
}
|
||||
|
||||
export type TUserMutations<S = IUserState> = {
|
||||
[USER_STORE.MUTATIONS.CLEAR_AUTH_USER_TOKEN](state: S): void
|
||||
[USER_STORE.MUTATIONS.UPDATE_AUTH_TOKEN](state: S, authToken: string): void
|
||||
[USER_STORE.MUTATIONS.UPDATE_AUTH_USER_PROFILE](
|
||||
state: S,
|
||||
authUserProfile: IUserProfile
|
||||
): void
|
||||
[USER_STORE.MUTATIONS.UPDATE_USER_LOADING](state: S, loading: boolean): void
|
||||
}
|
||||
|
||||
export type TUserStoreModule<S = IUserState> = Omit<
|
||||
VuexStore<S>,
|
||||
'commit' | 'getters' | 'dispatch'
|
||||
> & {
|
||||
dispatch<K extends keyof IUserActions>(
|
||||
key: K,
|
||||
payload?: Parameters<IUserActions[K]>[1],
|
||||
options?: DispatchOptions
|
||||
): ReturnType<IUserActions[K]>
|
||||
} & {
|
||||
getters: {
|
||||
[K in keyof IUserGetters]: ReturnType<IUserGetters[K]>
|
||||
}
|
||||
} & {
|
||||
commit<
|
||||
K extends keyof TUserMutations,
|
||||
P extends Parameters<TUserMutations[K]>[1]
|
||||
>(
|
||||
key: K,
|
||||
payload?: P,
|
||||
options?: CommitOptions
|
||||
): ReturnType<TUserMutations[K]>
|
||||
}
|
@ -2,7 +2,7 @@ import { ActionContext, ActionTree } from 'vuex'
|
||||
|
||||
import authApi from '@/api/authApi'
|
||||
import router from '@/router'
|
||||
import { ROOT_STORE, USER_STORE, WORKOUTS_STORE } from '@/store/constants'
|
||||
import { ROOT_STORE, AUTH_USER_STORE, WORKOUTS_STORE } from '@/store/constants'
|
||||
import { IRootState } from '@/store/modules/root/types'
|
||||
import { WorkoutsMutations } from '@/store/modules/workouts/enums'
|
||||
import {
|
||||
@ -138,7 +138,7 @@ export const actions: ActionTree<IWorkoutsState, IRootState> &
|
||||
.delete(`workouts/${payload.workoutId}`)
|
||||
.then(() => {
|
||||
context.commit(WORKOUTS_STORE.MUTATIONS.EMPTY_WORKOUT)
|
||||
context.dispatch(USER_STORE.ACTIONS.GET_USER_PROFILE)
|
||||
context.dispatch(AUTH_USER_STORE.ACTIONS.GET_USER_PROFILE)
|
||||
router.push('/')
|
||||
})
|
||||
.catch((error) => {
|
||||
@ -157,7 +157,7 @@ export const actions: ActionTree<IWorkoutsState, IRootState> &
|
||||
authApi
|
||||
.patch(`workouts/${payload.workoutId}`, payload.data)
|
||||
.then(() => {
|
||||
context.dispatch(USER_STORE.ACTIONS.GET_USER_PROFILE)
|
||||
context.dispatch(AUTH_USER_STORE.ACTIONS.GET_USER_PROFILE)
|
||||
context
|
||||
.dispatch(WORKOUTS_STORE.ACTIONS.GET_WORKOUT_DATA, {
|
||||
workoutId: payload.workoutId,
|
||||
@ -199,7 +199,7 @@ export const actions: ActionTree<IWorkoutsState, IRootState> &
|
||||
})
|
||||
.then((res) => {
|
||||
if (res.data.status === 'created') {
|
||||
context.dispatch(USER_STORE.ACTIONS.GET_USER_PROFILE)
|
||||
context.dispatch(AUTH_USER_STORE.ACTIONS.GET_USER_PROFILE)
|
||||
const workout: IWorkout = res.data.data.workouts[0]
|
||||
router.push(
|
||||
res.data.data.workouts.length === 1
|
||||
@ -225,7 +225,7 @@ export const actions: ActionTree<IWorkoutsState, IRootState> &
|
||||
.post('workouts/no_gpx', payload)
|
||||
.then((res) => {
|
||||
if (res.data.status === 'created') {
|
||||
context.dispatch(USER_STORE.ACTIONS.GET_USER_PROFILE)
|
||||
context.dispatch(AUTH_USER_STORE.ACTIONS.GET_USER_PROFILE)
|
||||
const workout: IWorkout = res.data.data.workouts[0]
|
||||
router.push(`/workouts/${workout.id}`)
|
||||
}
|
||||
|
@ -1,20 +1,20 @@
|
||||
import { TAuthUserStoreModule } from '@/store/modules/authUser/types'
|
||||
import { TRootStoreModule } from '@/store/modules/root/types'
|
||||
import { TSportsStoreModule } from '@/store/modules/sports/types'
|
||||
import { TStatisticsStoreModule } from '@/store/modules/statistics/types'
|
||||
import { TUserStoreModule } from '@/store/modules/user/types'
|
||||
import { TUsersStoreModule } from '@/store/modules/users/types'
|
||||
import { TWorkoutsStoreModule } from '@/store/modules/workouts/types'
|
||||
|
||||
type StoreModules = {
|
||||
authUserModule: TAuthUserStoreModule
|
||||
rootModule: TRootStoreModule
|
||||
sportsModule: TSportsStoreModule
|
||||
statsModule: TStatisticsStoreModule
|
||||
userModule: TUserStoreModule
|
||||
usersModule: TUsersStoreModule
|
||||
workoutsModule: TWorkoutsStoreModule
|
||||
}
|
||||
|
||||
export type Store = TUserStoreModule<Pick<StoreModules, 'userModule'>> &
|
||||
export type Store = TAuthUserStoreModule<Pick<StoreModules, 'authUserModule'>> &
|
||||
TSportsStoreModule<Pick<StoreModules, 'sportsModule'>> &
|
||||
TStatisticsStoreModule<Pick<StoreModules, 'statsModule'>> &
|
||||
TWorkoutsStoreModule<Pick<StoreModules, 'workoutsModule'>> &
|
||||
|
@ -2,10 +2,10 @@ import { AxiosError } from 'axios'
|
||||
import { ActionContext } from 'vuex'
|
||||
|
||||
import { ROOT_STORE } from '@/store/constants'
|
||||
import { IAuthUserState } from '@/store/modules/authUser/types'
|
||||
import { IRootState } from '@/store/modules/root/types'
|
||||
import { ISportsState } from '@/store/modules/sports/types'
|
||||
import { IStatisticsState } from '@/store/modules/statistics/types'
|
||||
import { IUserState } from '@/store/modules/user/types'
|
||||
import { IUsersState } from '@/store/modules/users/types'
|
||||
import { IWorkoutsState } from '@/store/modules/workouts/types'
|
||||
|
||||
@ -18,7 +18,7 @@ export const getApiUrl = (): string => {
|
||||
export const handleError = (
|
||||
context:
|
||||
| ActionContext<IRootState, IRootState>
|
||||
| ActionContext<IUserState, IRootState>
|
||||
| ActionContext<IAuthUserState, IRootState>
|
||||
| ActionContext<IStatisticsState, IRootState>
|
||||
| ActionContext<ISportsState, IRootState>
|
||||
| ActionContext<IUsersState, IRootState>
|
||||
|
@ -16,7 +16,7 @@
|
||||
import { computed, ComputedRef, defineComponent, onBeforeMount } from 'vue'
|
||||
|
||||
import NotFound from '@/components/Common/NotFound.vue'
|
||||
import { ROOT_STORE, USER_STORE } from '@/store/constants'
|
||||
import { AUTH_USER_STORE, ROOT_STORE } from '@/store/constants'
|
||||
import { TAppConfig, IAppStatistics } from '@/types/application'
|
||||
import { useStore } from '@/use/useStore'
|
||||
|
||||
@ -42,10 +42,10 @@
|
||||
() => store.getters[ROOT_STORE.GETTERS.APP_STATS]
|
||||
)
|
||||
const isAuthUserAmin: ComputedRef<boolean> = computed(
|
||||
() => store.getters[USER_STORE.GETTERS.IS_ADMIN]
|
||||
() => store.getters[AUTH_USER_STORE.GETTERS.IS_ADMIN]
|
||||
)
|
||||
const userLoading: ComputedRef<boolean> = computed(
|
||||
() => store.getters[USER_STORE.GETTERS.USER_LOADING]
|
||||
() => store.getters[AUTH_USER_STORE.GETTERS.USER_LOADING]
|
||||
)
|
||||
|
||||
return {
|
||||
|
@ -80,7 +80,7 @@
|
||||
import UserMonthStats from '@/components/Dashboard/UserMonthStats.vue'
|
||||
import UserRecords from '@/components/Dashboard/UserRecords/index.vue'
|
||||
import UserStatsCards from '@/components/Dashboard/UserStatsCards/index.vue'
|
||||
import { SPORTS_STORE, USER_STORE } from '@/store/constants'
|
||||
import { AUTH_USER_STORE, SPORTS_STORE } from '@/store/constants'
|
||||
import { ISport } from '@/types/sports'
|
||||
import { IUserProfile } from '@/types/user'
|
||||
import { useStore } from '@/use/useStore'
|
||||
@ -97,7 +97,7 @@
|
||||
setup() {
|
||||
const store = useStore()
|
||||
const authUser: ComputedRef<IUserProfile> = computed(
|
||||
() => store.getters[USER_STORE.GETTERS.AUTH_USER_PROFILE]
|
||||
() => store.getters[AUTH_USER_STORE.GETTERS.AUTH_USER_PROFILE]
|
||||
)
|
||||
const sports: ComputedRef<ISport[]> = computed(
|
||||
() => store.getters[SPORTS_STORE.GETTERS.SPORTS]
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
import Statistics from '@/components/Statistics/index.vue'
|
||||
import NoWorkouts from '@/components/Workouts/NoWorkouts.vue'
|
||||
import { USER_STORE, SPORTS_STORE } from '@/store/constants'
|
||||
import { AUTH_USER_STORE, SPORTS_STORE } from '@/store/constants'
|
||||
import { ISport } from '@/types/sports'
|
||||
import { IUserProfile } from '@/types/user'
|
||||
import { useStore } from '@/use/useStore'
|
||||
@ -35,7 +35,7 @@
|
||||
setup() {
|
||||
const store = useStore()
|
||||
const authUser: ComputedRef<IUserProfile> = computed(
|
||||
() => store.getters[USER_STORE.GETTERS.AUTH_USER_PROFILE]
|
||||
() => store.getters[AUTH_USER_STORE.GETTERS.AUTH_USER_PROFILE]
|
||||
)
|
||||
const sports: ComputedRef<ISport[]> = computed(() =>
|
||||
store.getters[SPORTS_STORE.GETTERS.SPORTS].filter((sport) =>
|
||||
|
@ -7,7 +7,7 @@
|
||||
<script lang="ts">
|
||||
import { computed, ComputedRef, defineComponent } from 'vue'
|
||||
|
||||
import { USER_STORE } from '@/store/constants'
|
||||
import { AUTH_USER_STORE } from '@/store/constants'
|
||||
import { IUserProfile } from '@/types/user'
|
||||
import { useStore } from '@/use/useStore'
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
setup() {
|
||||
const store = useStore()
|
||||
const authUser: ComputedRef<IUserProfile> = computed(
|
||||
() => store.getters[USER_STORE.GETTERS.AUTH_USER_PROFILE]
|
||||
() => store.getters[AUTH_USER_STORE.GETTERS.AUTH_USER_PROFILE]
|
||||
)
|
||||
return { authUser }
|
||||
},
|
||||
|
@ -15,7 +15,11 @@
|
||||
import { computed, defineComponent, ComputedRef } from 'vue'
|
||||
|
||||
import WorkoutEdition from '@/components/Workout/WorkoutEdition.vue'
|
||||
import { SPORTS_STORE, USER_STORE, WORKOUTS_STORE } from '@/store/constants'
|
||||
import {
|
||||
AUTH_USER_STORE,
|
||||
SPORTS_STORE,
|
||||
WORKOUTS_STORE,
|
||||
} from '@/store/constants'
|
||||
import { ISport } from '@/types/sports'
|
||||
import { IUserProfile } from '@/types/user'
|
||||
import { IWorkoutData } from '@/types/workouts'
|
||||
@ -32,7 +36,7 @@
|
||||
() => store.getters[SPORTS_STORE.GETTERS.SPORTS]
|
||||
)
|
||||
const authUser: ComputedRef<IUserProfile> = computed(
|
||||
() => store.getters[USER_STORE.GETTERS.AUTH_USER_PROFILE]
|
||||
() => store.getters[AUTH_USER_STORE.GETTERS.AUTH_USER_PROFILE]
|
||||
)
|
||||
const workoutData: ComputedRef<IWorkoutData> = computed(
|
||||
() => store.getters[WORKOUTS_STORE.GETTERS.WORKOUT_DATA]
|
||||
|
@ -22,7 +22,11 @@
|
||||
import { useRoute } from 'vue-router'
|
||||
|
||||
import WorkoutEdition from '@/components/Workout/WorkoutEdition.vue'
|
||||
import { SPORTS_STORE, USER_STORE, WORKOUTS_STORE } from '@/store/constants'
|
||||
import {
|
||||
AUTH_USER_STORE,
|
||||
SPORTS_STORE,
|
||||
WORKOUTS_STORE,
|
||||
} from '@/store/constants'
|
||||
import { ISport } from '@/types/sports'
|
||||
import { IUserProfile } from '@/types/user'
|
||||
import { IWorkoutData } from '@/types/workouts'
|
||||
@ -44,7 +48,7 @@
|
||||
})
|
||||
|
||||
const authUser: ComputedRef<IUserProfile> = computed(
|
||||
() => store.getters[USER_STORE.GETTERS.AUTH_USER_PROFILE]
|
||||
() => store.getters[AUTH_USER_STORE.GETTERS.AUTH_USER_PROFILE]
|
||||
)
|
||||
const sports: ComputedRef<ISport[]> = computed(
|
||||
() => store.getters[SPORTS_STORE.GETTERS.SPORTS]
|
||||
|
@ -55,7 +55,11 @@
|
||||
import WorkoutDetail from '@/components/Workout/WorkoutDetail/index.vue'
|
||||
import WorkoutNotes from '@/components/Workout/WorkoutNotes.vue'
|
||||
import WorkoutSegments from '@/components/Workout/WorkoutSegments.vue'
|
||||
import { SPORTS_STORE, USER_STORE, WORKOUTS_STORE } from '@/store/constants'
|
||||
import {
|
||||
AUTH_USER_STORE,
|
||||
SPORTS_STORE,
|
||||
WORKOUTS_STORE,
|
||||
} from '@/store/constants'
|
||||
import { ISport } from '@/types/sports'
|
||||
import { IUserProfile } from '@/types/user'
|
||||
import { IWorkoutData, IWorkoutPayload, TCoordinates } from '@/types/workouts'
|
||||
@ -92,7 +96,7 @@
|
||||
() => store.getters[WORKOUTS_STORE.GETTERS.WORKOUT_DATA]
|
||||
)
|
||||
const authUser: ComputedRef<IUserProfile> = computed(
|
||||
() => store.getters[USER_STORE.GETTERS.AUTH_USER_PROFILE]
|
||||
() => store.getters[AUTH_USER_STORE.GETTERS.AUTH_USER_PROFILE]
|
||||
)
|
||||
const sports: ComputedRef<ISport[]> = computed(
|
||||
() => store.getters[SPORTS_STORE.GETTERS.SPORTS]
|
||||
|
@ -32,7 +32,7 @@
|
||||
|
||||
import WorkoutsFilters from '@/components/Workouts/WorkoutsFilters.vue'
|
||||
import WorkoutsList from '@/components/Workouts/WorkoutsList.vue'
|
||||
import { USER_STORE, SPORTS_STORE } from '@/store/constants'
|
||||
import { AUTH_USER_STORE, SPORTS_STORE } from '@/store/constants'
|
||||
import { ISport, ITranslatedSport } from '@/types/sports'
|
||||
import { IUserProfile } from '@/types/user'
|
||||
import { useStore } from '@/use/useStore'
|
||||
@ -48,7 +48,7 @@
|
||||
const { t } = useI18n()
|
||||
const store = useStore()
|
||||
const authUser: ComputedRef<IUserProfile> = computed(
|
||||
() => store.getters[USER_STORE.GETTERS.AUTH_USER_PROFILE]
|
||||
() => store.getters[AUTH_USER_STORE.GETTERS.AUTH_USER_PROFILE]
|
||||
)
|
||||
const sports: ComputedRef<ISport[]> = computed(
|
||||
() => store.getters[SPORTS_STORE.GETTERS.SPORTS]
|
||||
|
Reference in New Issue
Block a user