wrbapp/frontend/pages/settings/admin/users.vue

99 lines
4.6 KiB
Vue
Raw Permalink Normal View History

2022-09-16 21:11:44 +02:00
<template>
2023-02-02 19:35:03 +01:00
<div @click.self="showModel = false" v-if="showModel" class="fixed flex justify-center items-center h-screen w-full bg-black top-0 left-0 z-50 bg-opacity-50" >
<form @submit.prevent="submitModelForm" class="dark:bg-neutral-800 bg-neutral-200 p-10 rounded-xl flex flex-col w-full max-w-sm">
<h1 class="font-bold text-center text-lg mb-5">Beheer Gebruiker</h1>
<div class="text-default mb-2">
Relatiecodes: <b>{{ modelData.relatiecodes.join(', ') }}</b>
</div>
<div class="text-default mb-2">
Email: <b>{{ modelData.email }}</b>
</div>
<div class="text-default mb-5">
ID: <b>{{ modelData.id }}</b>
</div>
<label class="relative inline-flex items-center cursor-pointer mb-5">
<input type="checkbox" value="" v-model="modelData.admin" class="sr-only peer">
<div class="w-11 h-6 bg-neutral-300 peer-focus:outline-none peer-focus:ring-none rounded-full peer dark:bg-neutral-700 peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all dark:border-gray-600 peer-checked:bg-primary"></div>
<span class="ml-3 font-medium text-gray-900 dark:text-gray-300">Admin</span>
</label>
<label class="relative inline-flex items-center cursor-pointer mb-5">
<input type="checkbox" value="" v-model="modelData.sendNews" class="sr-only peer">
<div class="w-11 h-6 bg-neutral-300 peer-focus:outline-none peer-focus:ring-none rounded-full peer dark:bg-neutral-700 peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all dark:border-gray-600 peer-checked:bg-primary"></div>
<span class="ml-3 font-medium text-gray-900 dark:text-gray-300">Berichten Sturen</span>
</label>
2023-02-05 22:47:13 +01:00
<label class="relative inline-flex items-center cursor-pointer mb-5">
<input type="checkbox" value="" v-model="modelData.wedstrijdAdmin" class="sr-only peer">
<div class="w-11 h-6 bg-neutral-300 peer-focus:outline-none peer-focus:ring-none rounded-full peer dark:bg-neutral-700 peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all dark:border-gray-600 peer-checked:bg-primary"></div>
<span class="ml-3 font-medium text-gray-900 dark:text-gray-300">Wedstrijd Admin</span>
</label>
2023-02-02 19:35:03 +01:00
<input :disabled="disableButtons" type="submit" class="btn" :value="'Bewerken'" />
</form>
</div>
<div class="flex flex-col gap-5 mx-auto p-2 w-full max-w-md">
<input v-model="searchTerm" class="input mb-2 font-bold" type="search" placeholder="Search">
<div v-for="user in filteredUsers" :key="user.relatiecode">
<div @click="handleModel(user)" class="item container flex flex-wrap hover:cursor-pointer">
<b class="w-24">{{ user.email }}</b>
</div>
2022-09-16 21:11:44 +02:00
</div>
2023-02-02 19:35:03 +01:00
</div>
2022-09-16 21:11:44 +02:00
</template>
<script setup>
2023-03-20 11:23:46 +01:00
import { getDocs, collection, doc, updateDoc, getFirestore } from 'firebase/firestore'
2023-02-02 19:35:03 +01:00
import { useToast } from 'vue-toastification'
2022-09-16 21:11:44 +02:00
definePageMeta({
2023-02-02 19:35:03 +01:00
title: 'Manage users',
key: 'back'
2022-09-16 21:11:44 +02:00
})
2023-02-02 19:35:03 +01:00
const toast = useToast()
2023-03-20 11:23:46 +01:00
const db = getFirestore()
const usersStore = useUsersStore()
2023-02-02 19:35:03 +01:00
const searchTerm = ref('')
const disableButtons = ref(false)
const showModel = ref(false)
const modelData = ref({})
onMounted(async () => {
2023-03-20 11:23:46 +01:00
usersStore.getUsers()
2023-02-02 19:35:03 +01:00
})
const handleModel = (user) => {
modelData.value = user
if (!modelData.value.hasOwnProperty('admin')) modelData.value.admin = false
if (!modelData.value.hasOwnProperty('sendNews')) modelData.value.sendNews = false
2023-02-05 22:47:13 +01:00
if (!modelData.value.hasOwnProperty('wedstrijdAdmin')) modelData.value.wedstrijdAdmin = false
2023-02-02 19:35:03 +01:00
showModel.value = true
}
const filteredUsers = computed(() => {
2023-03-20 11:23:46 +01:00
return usersStore.users.filter(user => user.email.toLowerCase().includes(searchTerm.value.toLowerCase()))
2023-02-02 19:35:03 +01:00
})
const submitModelForm = async () => {
disableButtons.value = true
const docRef = doc(db, "users", modelData.value.id)
await updateDoc(docRef, {
admin: modelData.value.admin,
2023-02-05 22:47:13 +01:00
sendNews: modelData.value.sendNews,
wedstrijdAdmin: modelData.value.wedstrijdAdmin
2023-02-02 19:35:03 +01:00
})
toast.success('Gebruiker is bewerkt')
disableButtons.value = false
showModel.value = false
}
</script>