feat(ui): Implement delete user

This commit is contained in:
Ferdinand Thiessen 2021-12-02 21:15:45 +01:00
parent 45e0defe7e
commit 7d3e47494f
2 changed files with 34 additions and 7 deletions

View File

@ -6,16 +6,23 @@
<UserSelector v-model="user" /> <UserSelector v-model="user" />
</div> </div>
</q-card-section> </q-card-section>
<MainUserSettings :user="user" @update:user="updateUser" /> <MainUserSettings
:user="user"
:removeable="canDelete && !isCurrentUser"
@update:user="updateUser"
@remove="remove"
/>
</q-card> </q-card>
</template> </template>
<script lang="ts"> <script lang="ts">
import { defineComponent, ref, onMounted } from 'vue'; import { computed, defineComponent, ref, onMounted } from 'vue';
import { hasPermission, useMainStore, useUserStore } from '@flaschengeist/api';
import { Notify } from 'quasar';
import { PERMISSIONS } from '../permissions';
import MainUserSettings from './settings/MainUserSettings.vue'; import MainUserSettings from './settings/MainUserSettings.vue';
import UserSelector from './UserSelector.vue'; import UserSelector from './UserSelector.vue';
import { useMainStore, useUserStore } from '@flaschengeist/api';
import { Notify } from 'quasar';
export default defineComponent({ export default defineComponent({
name: 'UpdateUser', name: 'UpdateUser',
@ -23,7 +30,10 @@ export default defineComponent({
setup() { setup() {
const mainStore = useMainStore(); const mainStore = useMainStore();
const userStore = useUserStore(); const userStore = useUserStore();
const user = ref(mainStore.currentUser); const user = ref(mainStore.currentUser);
const canDelete = computed(() => hasPermission(PERMISSIONS.DELETE));
const isCurrentUser = computed(() => user.value.userid === mainStore.currentUser.userid);
onMounted(() => { onMounted(() => {
void userStore.getUsers(true); void userStore.getUsers(true);
@ -42,7 +52,15 @@ export default defineComponent({
}); });
} }
async function remove() {
await userStore.deleteUser(user.value);
user.value = mainStore.currentUser;
}
return { return {
canDelete,
isCurrentUser,
remove,
user, user,
updateUser, updateUser,
}; };

View File

@ -125,9 +125,12 @@
class="col-xs-12 col-sm-6 q-pa-sm" class="col-xs-12 col-sm-6 q-pa-sm"
/> />
</q-card-section> </q-card-section>
<q-card-actions align="right"> <q-card-actions :align="removeable ? 'between' : 'right'">
<q-btn label="Reset" type="reset" /> <q-btn v-if="removeable" label="Löschen" color="negative" @click="remove" />
<q-btn color="primary" type="submit" label="Speichern" /> <div>
<q-btn label="Reset" type="reset" style="margin-right: 0.5em" />
<q-btn label="Speichern" type="submit" color="primary" />
</div>
</q-card-actions> </q-card-actions>
</q-form> </q-form>
</template> </template>
@ -151,6 +154,10 @@ export default defineComponent({
name: 'MainUserSettings', name: 'MainUserSettings',
components: { IsoDateInput, PasswordInput }, components: { IsoDateInput, PasswordInput },
props: { props: {
removeable: {
type: Boolean,
default: false,
},
user: { user: {
required: true, required: true,
type: Object as PropType<FG.User>, type: Object as PropType<FG.User>,
@ -159,6 +166,7 @@ export default defineComponent({
}, },
emits: { emits: {
'update:user': (payload: FG.User) => !!payload, 'update:user': (payload: FG.User) => !!payload,
remove: () => true,
}, },
setup(props, { emit }) { setup(props, { emit }) {
const userStore = useUserStore(); const userStore = useUserStore();
@ -285,6 +293,7 @@ export default defineComponent({
onAvatarRejected, onAvatarRejected,
password, password,
preview, preview,
remove: () => emit('remove'),
reset, reset,
save, save,
userModel, userModel,