Fixed birthday is not a Date

This commit is contained in:
Ferdinand Thiessen 2020-11-17 18:09:05 +01:00
parent 4c9fb07f7d
commit 06b259cd74
3 changed files with 14 additions and 5 deletions

View File

@ -45,8 +45,8 @@ export default defineComponent({
const today = new Date(); const today = new Date();
return ( return (
user.birthday && user.birthday &&
user.birthday.getMonth === today.getMonth && user.birthday.getMonth() === today.getMonth() &&
user.birthday.getDate === today.getDate user.birthday.getDate() === today.getDate()
); );
} }

View File

@ -196,6 +196,8 @@ export default defineComponent({
function save() { function save() {
let changed = <FG.User>props.user; let changed = <FG.User>props.user;
if (typeof changed.birthday === 'string')
changed.birthday = new Date(changed.birthday);
changed = Object.assign(changed, { changed = Object.assign(changed, {
password: password.value, password: password.value,
}); });

View File

@ -14,11 +14,17 @@ export interface UserStateInterface {
loading: number; loading: number;
} }
function loadUserFromLocalStorage() {
const user = SessionStorage.getItem<FG.User>('currentUser') || undefined;
if (user && user.birthday && typeof user.birthday === 'string')
user.birthday = new Date(user.birthday);
return user;
}
const state: UserStateInterface = { const state: UserStateInterface = {
users: [], users: [],
roles: [], roles: [],
permissions: [], permissions: [],
currentUser: SessionStorage.getItem<FG.User>('currentUser') || undefined, currentUser: loadUserFromLocalStorage(),
currentPermissions: currentPermissions:
SessionStorage.getItem<FG.Permission[]>('currentPermissions') || [], SessionStorage.getItem<FG.Permission[]>('currentPermissions') || [],
loading: 0 loading: 0
@ -26,6 +32,9 @@ const state: UserStateInterface = {
const mutations: MutationTree<UserStateInterface> = { const mutations: MutationTree<UserStateInterface> = {
setCurrentUser(state, data: FG.User) { setCurrentUser(state, data: FG.User) {
if (typeof data.birthday === 'string')
data.birthday = new Date(data.birthday);
console.warn(data.birthday);
SessionStorage.set('currentUser', data); SessionStorage.set('currentUser', data);
state.currentUser = data; state.currentUser = data;
}, },
@ -68,8 +77,6 @@ const actions: ActionTree<UserStateInterface, StateInterface> = {
axios axios
.get(`/users/${rootState.session.currentSession.userid}`) .get(`/users/${rootState.session.currentSession.userid}`)
.then((response: AxiosResponse<CurrentUserResponse>) => { .then((response: AxiosResponse<CurrentUserResponse>) => {
if (response.data.birthday)
response.data.birthday = new Date(response.data.birthday);
commit('setCurrentUser', response.data); commit('setCurrentUser', response.data);
commit('setCurrentPermissions', response.data.permissions); commit('setCurrentPermissions', response.data.permissions);
}) })