diff --git a/src/plugins/user/components/NewUser.vue b/src/plugins/user/components/NewUser.vue new file mode 100644 index 0000000..cd59e2a --- /dev/null +++ b/src/plugins/user/components/NewUser.vue @@ -0,0 +1,42 @@ + + + + + Neues Mitglied + + + + + + + + + + + diff --git a/src/plugins/user/components/UpdateUser.vue b/src/plugins/user/components/UpdateUser.vue new file mode 100644 index 0000000..634bc56 --- /dev/null +++ b/src/plugins/user/components/UpdateUser.vue @@ -0,0 +1,50 @@ + + + + + Benutzereinstellungen + + + + + + + + + + + + diff --git a/src/plugins/user/components/settings/MainUserSettings.vue b/src/plugins/user/components/settings/MainUserSettings.vue index e429a3e..c2f3376 100644 --- a/src/plugins/user/components/settings/MainUserSettings.vue +++ b/src/plugins/user/components/settings/MainUserSettings.vue @@ -19,8 +19,9 @@ - - + + >root.$store; onBeforeMount(() => { @@ -144,9 +156,9 @@ export default defineComponent({ new_password: new_password.value }); } - store.dispatch('user/updateUser', changed).catch(error => { - console.warn(error); - }); + console.log(changed); + + emit('update:user', changed); } function reset() { @@ -172,6 +184,16 @@ export default defineComponent({ ); } + function isUseridUsed(val: string) { + return ( + !store.state.user.users.find((user: FG.User) => { + return user.userid == val; + }) || + !props.newUser || + 'Benutzername ist schon vergeben' + ); + } + const loading = computed(() => store.state.user.loading > 0); return { @@ -185,6 +207,7 @@ export default defineComponent({ isCurrentUser, isEmail, notEmpty, + isUseridUsed, save, reset, loading diff --git a/src/plugins/user/pages/AdminSettings.vue b/src/plugins/user/pages/AdminSettings.vue index e60494d..8604986 100644 --- a/src/plugins/user/pages/AdminSettings.vue +++ b/src/plugins/user/pages/AdminSettings.vue @@ -1,42 +1,52 @@ - + - + - + - + {{ tabindex.label }} - - + + - - - - Benutzereinstellungen - - - - - - - + - hier kommt noch was + - + @@ -50,19 +60,19 @@ import { onBeforeMount, ref } from '@vue/composition-api'; -import UserSelector from '../components/UserSelector.vue'; -import MainUserSettings from '../components/settings/MainUserSettings.vue'; import RoleSettings from '../components/settings/RoleSettings.vue'; -import {Store} from 'vuex'; -import {StateInterface} from 'src/store'; -import {hasPermission} from 'src/components/permission'; -import {PERMISSIONS} from '../permissions'; -import {Screen} from 'quasar'; +import UpdateUser from '../components/UpdateUser.vue'; +import NewUser from '../components/NewUser.vue'; +import { Store } from 'vuex'; +import { StateInterface } from 'src/store'; +import { hasPermission } from 'src/components/permission'; +import { PERMISSIONS } from '../permissions'; +import { Screen } from 'quasar'; export default defineComponent({ name: 'AdminSettings', - components: {UserSelector, MainUserSettings, RoleSettings}, - setup(_, {root}) { + components: { RoleSettings, UpdateUser, NewUser }, + setup(_, { root }) { const store = >root.$store; onBeforeMount(() => { @@ -72,13 +82,6 @@ export default defineComponent({ const canEditRoles = computed(() => hasPermission(PERMISSIONS.ROLES_EDIT, store) ); - const user = ref(store.state.user.currentUser); - - // can be dropped with VUE3 - const userUpdated = (value: FG.User) => { - user.value = value; - console.log(value); - }; interface Tab { name: string; @@ -86,27 +89,25 @@ export default defineComponent({ } const tabs: Tab[] = [ - {name: 'user', label: 'Mitglieder'}, - {name: 'newUser', label: 'Neues Mitglied'}, - {name: 'roles', label: 'Rollen'} - ] + { name: 'user', label: 'Mitglieder' }, + { name: 'newUser', label: 'Neues Mitglied' }, + { name: 'roles', label: 'Rollen' } + ]; - const drawer = ref(false) + const drawer = ref(false); const showDrawer = computed({ get: () => { - return !Screen.gt.sm && drawer.value + return !Screen.gt.sm && drawer.value; }, set: (val: boolean) => { - drawer.value = val + drawer.value = val; } - }) + }); const tab = ref('user'); return { - user, - userUpdated, canEditRoles, showDrawer, tab, diff --git a/src/plugins/user/pages/Settings.vue b/src/plugins/user/pages/Settings.vue index 68f9ce2..b8c4e08 100644 --- a/src/plugins/user/pages/Settings.vue +++ b/src/plugins/user/pages/Settings.vue @@ -11,7 +11,7 @@ > Benutzereinstellungen - + Aktive Sessions: store.state.user.currentUser); const sessions = computed(() => store.state.session.sessions); const sessionsLoading = computed(() => store.state.session.loading); + function updateUser(value: FG.User) { + store.dispatch('user/updateUser', value).catch(error => { + console.warn(error); + }); + } return { currentUser, sessionsLoading, - sessions + sessions, + updateUser }; } }); diff --git a/src/plugins/user/store/user.ts b/src/plugins/user/store/user.ts index 8a1062a..c6b9513 100644 --- a/src/plugins/user/store/user.ts +++ b/src/plugins/user/store/user.ts @@ -103,6 +103,23 @@ const actions: ActionTree = { }); }, + setUser({ commit, state, dispatch }, data: FG.User) { + commit('setLoading'); + axios + .post(`users`, data) + .then(() => { + if (state.currentUser && state.currentUser.userid === data.userid) + void dispatch('getCurrentUser'); + else void dispatch('getUsers'); + }) + .catch(error => { + console.warn(error); + }) + .finally(() => { + commit('setLoading', false); + }); + }, + getRoles({ commit, state }, force = false) { if (!force && state.roles.length > 0) return; commit('setLoading');