From 72e622f11bb74f63307b054027526cccd4bd96c0 Mon Sep 17 00:00:00 2001 From: Xeovalyte Date: Thu, 2 Feb 2023 19:35:03 +0100 Subject: [PATCH] added manage users --- frontend/pages/settings/admin/ledenlijst.vue | 2 +- frontend/pages/settings/admin/users.vue | 96 +++++++++++++++++++- 2 files changed, 92 insertions(+), 6 deletions(-) diff --git a/frontend/pages/settings/admin/ledenlijst.vue b/frontend/pages/settings/admin/ledenlijst.vue index 86556f4..a83d09e 100644 --- a/frontend/pages/settings/admin/ledenlijst.vue +++ b/frontend/pages/settings/admin/ledenlijst.vue @@ -15,7 +15,7 @@ diff --git a/frontend/pages/settings/admin/users.vue b/frontend/pages/settings/admin/users.vue index 97a4c02..3859fdf 100644 --- a/frontend/pages/settings/admin/users.vue +++ b/frontend/pages/settings/admin/users.vue @@ -1,13 +1,99 @@ \ No newline at end of file + +const { users, db } = inject('firebase') +const toast = useToast() + +const searchTerm = ref('') +const disableButtons = ref(false) +const showModel = ref(false) + +const modelData = ref({}) + +onMounted(async () => { + if (!users.value.length) { + try { + const querySnapshot = await getDocs(collection(db, "users")); + querySnapshot.forEach((doc) => { + users.value.push(doc.data()) + }); + } catch (e) { + console.log(e) + } + } +}) + +const handleModel = (user) => { + modelData.value = user + if (!modelData.value.hasOwnProperty('admin')) modelData.value.admin = false + if (!modelData.value.hasOwnProperty('sendNews')) modelData.value.sendNews = false + + showModel.value = true +} + +const filteredUsers = computed(() => { + return users.value.filter(user => user.email.toLowerCase().includes(searchTerm.value.toLowerCase())) +}) + +const submitModelForm = async () => { + disableButtons.value = true + + const docRef = doc(db, "users", modelData.value.id) + + await updateDoc(docRef, { + admin: modelData.value.admin, + sendNews: modelData.value.sendNews + }) + + toast.success('Gebruiker is bewerkt') + + disableButtons.value = false + showModel.value = false +} +