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