From 06b259cd741dcf91039c0d32ded3ff136ed2af2a Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Tue, 17 Nov 2020 18:09:05 +0100 Subject: [PATCH] Fixed birthday is not a Date --- src/plugins/user/components/Widget.vue | 4 ++-- .../user/components/settings/MainUserSettings.vue | 2 ++ src/plugins/user/store/user.ts | 13 ++++++++++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/plugins/user/components/Widget.vue b/src/plugins/user/components/Widget.vue index 97a5949..4788526 100644 --- a/src/plugins/user/components/Widget.vue +++ b/src/plugins/user/components/Widget.vue @@ -45,8 +45,8 @@ export default defineComponent({ const today = new Date(); return ( user.birthday && - user.birthday.getMonth === today.getMonth && - user.birthday.getDate === today.getDate + user.birthday.getMonth() === today.getMonth() && + user.birthday.getDate() === today.getDate() ); } diff --git a/src/plugins/user/components/settings/MainUserSettings.vue b/src/plugins/user/components/settings/MainUserSettings.vue index dd6933b..0f5a56e 100644 --- a/src/plugins/user/components/settings/MainUserSettings.vue +++ b/src/plugins/user/components/settings/MainUserSettings.vue @@ -196,6 +196,8 @@ export default defineComponent({ function save() { let changed = props.user; + if (typeof changed.birthday === 'string') + changed.birthday = new Date(changed.birthday); changed = Object.assign(changed, { password: password.value, }); diff --git a/src/plugins/user/store/user.ts b/src/plugins/user/store/user.ts index 80f252f..cf39ecc 100644 --- a/src/plugins/user/store/user.ts +++ b/src/plugins/user/store/user.ts @@ -14,11 +14,17 @@ export interface UserStateInterface { loading: number; } +function loadUserFromLocalStorage() { + const user = SessionStorage.getItem('currentUser') || undefined; + if (user && user.birthday && typeof user.birthday === 'string') + user.birthday = new Date(user.birthday); + return user; +} const state: UserStateInterface = { users: [], roles: [], permissions: [], - currentUser: SessionStorage.getItem('currentUser') || undefined, + currentUser: loadUserFromLocalStorage(), currentPermissions: SessionStorage.getItem('currentPermissions') || [], loading: 0 @@ -26,6 +32,9 @@ const state: UserStateInterface = { const mutations: MutationTree = { setCurrentUser(state, data: FG.User) { + if (typeof data.birthday === 'string') + data.birthday = new Date(data.birthday); + console.warn(data.birthday); SessionStorage.set('currentUser', data); state.currentUser = data; }, @@ -68,8 +77,6 @@ const actions: ActionTree = { axios .get(`/users/${rootState.session.currentSession.userid}`) .then((response: AxiosResponse) => { - if (response.data.birthday) - response.data.birthday = new Date(response.data.birthday); commit('setCurrentUser', response.data); commit('setCurrentPermissions', response.data.permissions); })