From 9b19dc225b2bc10a1f7acda6a9abc399c8d62036 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Sun, 15 Nov 2020 19:47:05 +0100 Subject: [PATCH] Allow setting the birthday --- src/components/utils/IsoDateInput.vue | 85 +++++++++++++++++++ src/flaschengeist.d.ts | 8 +- .../components/settings/MainUserSettings.vue | 60 ++++++++----- src/plugins/user/store/user.ts | 5 ++ 4 files changed, 132 insertions(+), 26 deletions(-) create mode 100644 src/components/utils/IsoDateInput.vue diff --git a/src/components/utils/IsoDateInput.vue b/src/components/utils/IsoDateInput.vue new file mode 100644 index 0000000..d14bbea --- /dev/null +++ b/src/components/utils/IsoDateInput.vue @@ -0,0 +1,85 @@ + + + diff --git a/src/flaschengeist.d.ts b/src/flaschengeist.d.ts index 8663558..1308f48 100644 --- a/src/flaschengeist.d.ts +++ b/src/flaschengeist.d.ts @@ -13,6 +13,7 @@ declare namespace FG { firstname: string; lastname: string; mail: string; + birthday?: Date; roles: Array; } type Permission = string; @@ -25,10 +26,9 @@ declare namespace FG { id: number; time: Date; amount: number; - reversal?: this; - sender_id?: string; - receiver_id?: string; - author_id?: string; + sender_id: string; + receiver_id: string; + author_id: string; } interface Event { id: number; diff --git a/src/plugins/user/components/settings/MainUserSettings.vue b/src/plugins/user/components/settings/MainUserSettings.vue index e1e4064..37b6205 100644 --- a/src/plugins/user/components/settings/MainUserSettings.vue +++ b/src/plugins/user/components/settings/MainUserSettings.vue @@ -1,5 +1,8 @@ @@ -94,11 +109,12 @@ import { computed, defineComponent, ref, - onBeforeMount + onBeforeMount, } from '@vue/composition-api'; import { Store } from 'vuex'; import { StateInterface } from 'src/store'; import { hasPermission } from 'src/components/permission'; +import IsoDateInput from 'src/components/utils/IsoDateInput.vue'; interface Props { user?: FG.User; @@ -107,19 +123,20 @@ interface Props { export default defineComponent({ name: 'MainUserSettings', + components: { IsoDateInput: IsoDateInput }, props: { user: { - required: true + required: true, }, newUser: { - default: false - } + default: false, + }, }, setup(props: Props, { root, emit }) { const store = >root.$store; onBeforeMount(() => { - store.dispatch('user/getRoles', false).catch(error => { + store.dispatch('user/getRoles', false).catch((error) => { console.warn(error); }); }); @@ -133,13 +150,13 @@ export default defineComponent({ const oldUser = computed(() => { if (isCurrentUser.value) return store.state.user.currentUser; else - return store.state.user.users.filter(user => { + return store.state.user.users.filter((user) => { user.userid === props.user?.userid; })[0]; }); const allRoles = computed(() => - store.state.user.roles.map(role => role.name) + store.state.user.roles.map((role) => role.name) ); const password = ref(''); const new_password = ref(''); @@ -148,14 +165,13 @@ export default defineComponent({ function save() { let changed = props.user; changed = Object.assign(changed, { - password: password.value + password: password.value, }); if (new_password.value != '') { changed = Object.assign(changed, { - new_password: new_password.value + new_password: new_password.value, }); } - console.log(changed); emit('update:user', changed); } @@ -206,8 +222,8 @@ export default defineComponent({ notEmpty, isUseridUsed, save, - reset + reset, }; - } + }, }); diff --git a/src/plugins/user/store/user.ts b/src/plugins/user/store/user.ts index 11400cf..b8f91be 100644 --- a/src/plugins/user/store/user.ts +++ b/src/plugins/user/store/user.ts @@ -68,6 +68,8 @@ 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); }) @@ -87,6 +89,9 @@ const actions: ActionTree = { axios .get('/users') .then((response: AxiosResponse) => { + response.data.forEach(user => { + if (user.birthday) user.birthday = new Date(user.birthday); + }); commit('setUsers', response.data); }) .catch(err => {