Client - fix redirection after deleting user account in admin

This commit is contained in:
Sam 2021-11-13 15:09:51 +01:00
parent 1e86a91e25
commit ed0b3863be
14 changed files with 64 additions and 29 deletions

View File

@ -1 +1 @@
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><!--[if IE]><link rel="icon" href="/favicon.ico"><![endif]--><link rel="stylesheet" href="/static/css/fork-awesome.min.css"><link rel="stylesheet" href="/static/css/leaflet.css"><title>FitTrackee</title><link href="/static/css/admin.babfd43e.css" rel="prefetch"><link href="/static/css/main.7229c1ab.css" rel="prefetch"><link href="/static/css/main~workouts.0edb3403.css" rel="prefetch"><link href="/static/css/profile.05400f70.css" rel="prefetch"><link href="/static/css/reset.46776e72.css" rel="prefetch"><link href="/static/css/workouts.1b0a7916.css" rel="prefetch"><link href="/static/js/admin.2f1d393d.js" rel="prefetch"><link href="/static/js/chunk-2d0c9189.c81458cc.js" rel="prefetch"><link href="/static/js/chunk-2d0cf391.020c75ea.js" rel="prefetch"><link href="/static/js/chunk-2d0da8f3.c8c3e7e8.js" rel="prefetch"><link href="/static/js/chunk-2d2248b6.d84473c1.js" rel="prefetch"><link href="/static/js/chunk-2d22523a.4b710d99.js" rel="prefetch"><link href="/static/js/main.db9cee98.js" rel="prefetch"><link href="/static/js/main~workouts.a74990d7.js" rel="prefetch"><link href="/static/js/profile.62578012.js" rel="prefetch"><link href="/static/js/reset.518e646f.js" rel="prefetch"><link href="/static/js/workouts.d69cf48a.js" rel="prefetch"><link href="/static/css/app.f5a49827.css" rel="preload" as="style"><link href="/static/js/app.4af713c5.js" rel="preload" as="script"><link href="/static/js/chunk-vendors.71654064.js" rel="preload" as="script"><link href="/static/css/app.f5a49827.css" rel="stylesheet"><link rel="icon" type="image/png" sizes="32x32" href="/img/icons/favicon-32x32.png"><link rel="icon" type="image/png" sizes="16x16" href="/img/icons/favicon-16x16.png"><link rel="manifest" href="/manifest.json"><meta name="theme-color" content="#4DBA87"><meta name="apple-mobile-web-app-capable" content="no"><meta name="apple-mobile-web-app-status-bar-style" content="default"><meta name="apple-mobile-web-app-title" content="fittrackee_client"><link rel="apple-touch-icon" href="/img/icons/apple-touch-icon-152x152.png"><link rel="mask-icon" href="/img/icons/safari-pinned-tab.svg" color="#4DBA87"><meta name="msapplication-TileImage" content="/img/icons/msapplication-icon-144x144.png"><meta name="msapplication-TileColor" content="#000000"></head><body><noscript><strong>We're sorry but FitTrackee doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="/static/js/chunk-vendors.71654064.js"></script><script src="/static/js/app.4af713c5.js"></script></body></html>
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><!--[if IE]><link rel="icon" href="/favicon.ico"><![endif]--><link rel="stylesheet" href="/static/css/fork-awesome.min.css"><link rel="stylesheet" href="/static/css/leaflet.css"><title>FitTrackee</title><link href="/static/css/admin.babfd43e.css" rel="prefetch"><link href="/static/css/main.7229c1ab.css" rel="prefetch"><link href="/static/css/main~workouts.0edb3403.css" rel="prefetch"><link href="/static/css/profile.05400f70.css" rel="prefetch"><link href="/static/css/reset.46776e72.css" rel="prefetch"><link href="/static/css/workouts.1b0a7916.css" rel="prefetch"><link href="/static/js/admin.2f1d393d.js" rel="prefetch"><link href="/static/js/chunk-2d0c9189.c81458cc.js" rel="prefetch"><link href="/static/js/chunk-2d0cf391.020c75ea.js" rel="prefetch"><link href="/static/js/chunk-2d0da8f3.c8c3e7e8.js" rel="prefetch"><link href="/static/js/chunk-2d2248b6.d84473c1.js" rel="prefetch"><link href="/static/js/chunk-2d22523a.4b710d99.js" rel="prefetch"><link href="/static/js/main.db9cee98.js" rel="prefetch"><link href="/static/js/main~workouts.a74990d7.js" rel="prefetch"><link href="/static/js/profile.62578012.js" rel="prefetch"><link href="/static/js/reset.518e646f.js" rel="prefetch"><link href="/static/js/workouts.d69cf48a.js" rel="prefetch"><link href="/static/css/app.3749d53d.css" rel="preload" as="style"><link href="/static/js/app.e982cbef.js" rel="preload" as="script"><link href="/static/js/chunk-vendors.71654064.js" rel="preload" as="script"><link href="/static/css/app.3749d53d.css" rel="stylesheet"><link rel="icon" type="image/png" sizes="32x32" href="/img/icons/favicon-32x32.png"><link rel="icon" type="image/png" sizes="16x16" href="/img/icons/favicon-16x16.png"><link rel="manifest" href="/manifest.json"><meta name="theme-color" content="#4DBA87"><meta name="apple-mobile-web-app-capable" content="no"><meta name="apple-mobile-web-app-status-bar-style" content="default"><meta name="apple-mobile-web-app-title" content="fittrackee_client"><link rel="apple-touch-icon" href="/img/icons/apple-touch-icon-152x152.png"><link rel="mask-icon" href="/img/icons/safari-pinned-tab.svg" color="#4DBA87"><meta name="msapplication-TileImage" content="/img/icons/msapplication-icon-144x144.png"><meta name="msapplication-TileColor" content="#000000"></head><body><noscript><strong>We're sorry but FitTrackee doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="/static/js/chunk-vendors.71654064.js"></script><script src="/static/js/app.e982cbef.js"></script></body></html>

View File

@ -64,7 +64,7 @@ self.__precacheManifest = (self.__precacheManifest || []).concat([
"url": "/img/workouts/mountains.svg"
},
{
"revision": "e1822eea53975be4c7802859ebb65de1",
"revision": "1e47e91a6ddb93b35e598a570ff0596f",
"url": "/index.html"
},
{
@ -80,8 +80,8 @@ self.__precacheManifest = (self.__precacheManifest || []).concat([
"url": "/static/css/admin.babfd43e.css"
},
{
"revision": "592aef69082002fccf26",
"url": "/static/css/app.f5a49827.css"
"revision": "24c864abeafb4dc09a5d",
"url": "/static/css/app.3749d53d.css"
},
{
"revision": "82c1118c918377daaa71a320ab8eea42",
@ -196,8 +196,8 @@ self.__precacheManifest = (self.__precacheManifest || []).concat([
"url": "/static/js/admin.2f1d393d.js"
},
{
"revision": "592aef69082002fccf26",
"url": "/static/js/app.4af713c5.js"
"revision": "24c864abeafb4dc09a5d",
"url": "/static/js/app.e982cbef.js"
},
{
"revision": "bd7d183c9f68e5f4027d",

View File

@ -14,7 +14,7 @@
importScripts("https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js");
importScripts(
"/precache-manifest.ddc2833e5b0364615f3352c5edfaec71.js"
"/precache-manifest.c8ddfece14a9cea2c55f73102909715d.js"
);
workbox.core.setCacheNameDetails({prefix: "fittrackee_client"});

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -47,7 +47,7 @@
import { format } from 'date-fns'
import { ComputedRef, Ref, computed, ref, toRefs, withDefaults } from 'vue'
import { AUTH_USER_STORE } from '@/store/constants'
import { AUTH_USER_STORE, USERS_STORE } from '@/store/constants'
import { IUserProfile } from '@/types/user'
import { useStore } from '@/use/useStore'
@ -81,7 +81,7 @@
displayModal.value = value
}
function deleteUserAccount(username: string) {
store.dispatch(AUTH_USER_STORE.ACTIONS.DELETE_ACCOUNT, { username })
store.dispatch(USERS_STORE.ACTIONS.DELETE_USER_ACCOUNT, { username })
}
</script>

View File

@ -17,6 +17,7 @@ import {
IAuthUserState,
} from '@/store/modules/authUser/types'
import { IRootState } from '@/store/modules/root/types'
import { deleteUserAccount } from '@/store/modules/users/actions'
import {
ILoginOrRegisterData,
IUserDeletionPayload,
@ -228,19 +229,7 @@ export const actions: ActionTree<IAuthUserState, IRootState> &
context: ActionContext<IAuthUserState, IRootState>,
payload: IUserDeletionPayload
): void {
context.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES)
authApi
.delete(`users/${payload.username}`)
.then((res) => {
if (res.status === 204) {
context
.dispatch(AUTH_USER_STORE.ACTIONS.LOGOUT)
.then(() => router.push('/'))
} else {
handleError(context, null)
}
})
.catch((error) => handleError(context, error))
deleteUserAccount(context, payload)
},
[AUTH_USER_STORE.ACTIONS.DELETE_PICTURE](
context: ActionContext<IAuthUserState, IRootState>

View File

@ -1,13 +1,40 @@
import { ActionContext, ActionTree } from 'vuex'
import authApi from '@/api/authApi'
import { ROOT_STORE, USERS_STORE } from '@/store/constants'
import router from '@/router'
import { AUTH_USER_STORE, ROOT_STORE, USERS_STORE } from '@/store/constants'
import { IAuthUserState } from '@/store/modules/authUser/types'
import { IRootState } from '@/store/modules/root/types'
import { IUsersActions, IUsersState } from '@/store/modules/users/types'
import { TPaginationPayload } from '@/types/api'
import { IAdminUserPayload } from '@/types/user'
import { IAdminUserPayload, IUserDeletionPayload } from '@/types/user'
import { handleError } from '@/utils'
export const deleteUserAccount = (
context:
| ActionContext<IAuthUserState, IRootState>
| ActionContext<IUsersState, IRootState>,
payload: IUserDeletionPayload
): void => {
context.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES)
authApi
.delete(`users/${payload.username}`)
.then((res) => {
if (res.status === 204) {
if (payload.fromAdmin) {
router.push('/admin/users')
} else {
context
.dispatch(AUTH_USER_STORE.ACTIONS.LOGOUT)
.then(() => router.push('/'))
}
} else {
handleError(context, null)
}
})
.catch((error) => handleError(context, error))
}
export const actions: ActionTree<IUsersState, IRootState> & IUsersActions = {
[USERS_STORE.ACTIONS.EMPTY_USER](
context: ActionContext<IUsersState, IRootState>
@ -94,4 +121,13 @@ export const actions: ActionTree<IUsersState, IRootState> & IUsersActions = {
context.commit(USERS_STORE.MUTATIONS.UPDATE_USERS_LOADING, false)
)
},
[USERS_STORE.ACTIONS.DELETE_USER_ACCOUNT](
context: ActionContext<IUsersState, IRootState>,
payload: IUserDeletionPayload
): void {
deleteUserAccount(context, {
username: payload.username,
fromAdmin: true,
})
},
}

View File

@ -4,6 +4,7 @@ export enum UsersActions {
GET_USER = 'GET_USER',
GET_USERS = 'GET_USERS',
UPDATE_USER = 'UPDATE_USER',
DELETE_USER_ACCOUNT = 'DELETE_USER_ACCOUNT',
}
export enum UsersGetters {

View File

@ -8,7 +8,11 @@ import {
import { USERS_STORE } from '@/store/constants'
import { IRootState } from '@/store/modules/root/types'
import { IPagination, TPaginationPayload } from '@/types/api'
import { IAdminUserPayload, IUserProfile } from '@/types/user'
import {
IAdminUserPayload,
IUserDeletionPayload,
IUserProfile,
} from '@/types/user'
export interface IUsersState {
user: IUserProfile
@ -36,6 +40,10 @@ export interface IUsersActions {
context: ActionContext<IUsersState, IRootState>,
payload: IAdminUserPayload
): void
[USERS_STORE.ACTIONS.DELETE_USER_ACCOUNT](
context: ActionContext<IUsersState, IRootState>,
payload: IUserDeletionPayload
): void
}
export interface IUsersGetters {

View File

@ -68,6 +68,7 @@ export interface IUserPasswordResetPayload {
export interface IUserDeletionPayload {
username: string
fromAdmin?: boolean
}
export interface ILoginRegisterFormData {