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 +} +