wrbapp/frontend/pages/settings/config/managerelatiecodes.vue

70 lines
2.4 KiB
Vue
Raw Permalink Normal View History

2022-09-22 16:39:11 +02:00
<template>
2023-03-20 11:23:46 +01:00
<div class="flex flex-col gap-5 mx-auto p-2 w-full max-w-md">
<div v-if="userStore.userAllPersons.length !== 0 && userStore.userPersons.length !== 0" class="flex flex-col gap-3">
<div v-for="person in userStore.userAllPersons" :key="person.relatiecode">
<div @click="updateCheckbox(person)" class="item container flex flex-wrap" :class="person.relatiecode === userStore.userPersons[0].relatiecode ? 'bg-neutral-200 dark:bg-neutral-850 text-neutral-400 dark:text-neutral-500 hover:cursor-not-allowed' : 'hover:cursor-pointer'">
<input v-model="person.checked" :disabled="person.relatiecode === userStore.userPersons[0].relatiecode" class="checkbox my-auto mr-3 disabled:bg-neutral-300 disabled:hover:text-neutral-300 dark:disabled:bg-neutral-600 dark:disabled:hover:text-neutral-600 disabled:hover:cursor-not-allowed" type="checkbox">
<span><b>{{ person.fullName }}</b></span>
2022-11-14 14:21:59 +01:00
</div>
2023-03-20 11:23:46 +01:00
</div>
<div class="w-full flex flex-wrap">
<button :disabled="buttonsDisabled" @click="save" class="btn w-full sm:w-40 mb-1">Opslaan</button>
<span @click="router.back()" class="hover:underline font-bold w-full text-center sm:w-max sm:ml-auto hover:cursor-pointer">Annuleer</span>
</div>
</div>
<div class="w-full flex flex-col justify-center items-center" v-else>
<Icon size="2em" name="ion:load-c" class="animate-spin" />
<h2 class="mt-2 font-bold">Loading...</h2>
2022-09-22 16:39:11 +02:00
</div>
2023-03-20 11:23:46 +01:00
</div>
2022-09-22 16:39:11 +02:00
</template>
<script setup>
2023-03-20 11:23:46 +01:00
import { updateDoc, doc, getFirestore } from 'firebase/firestore'
2022-09-26 16:23:45 +02:00
import { useToast } from 'vue-toastification'
const router = useRouter()
2022-09-22 16:39:11 +02:00
definePageMeta({
2023-03-20 11:23:46 +01:00
title: 'Beheer Personen',
key: 'back'
2022-09-22 16:39:11 +02:00
})
2022-09-26 16:23:45 +02:00
2022-09-27 15:44:44 +02:00
const toast = useToast()
2023-03-20 11:23:46 +01:00
const userStore = useUserStore()
const db = getFirestore()
2022-09-26 16:23:45 +02:00
const buttonsDisabled = ref(false)
onMounted(() => {
2023-03-20 11:23:46 +01:00
userStore.getAllPersons()
2022-09-26 16:23:45 +02:00
})
const save = async () => {
2023-01-21 21:36:22 +01:00
buttonsDisabled.value = true
2022-09-26 16:23:45 +02:00
2023-01-21 21:36:22 +01:00
const newRelatiecodes = []
2022-09-26 16:23:45 +02:00
2023-03-20 11:23:46 +01:00
userStore.userAllPersons.forEach(person => {
2023-01-21 21:36:22 +01:00
if (person.checked) {
newRelatiecodes.push(person.relatiecode)
}
})
2022-09-26 16:23:45 +02:00
2023-03-20 11:23:46 +01:00
await updateDoc(doc(db, "users", userStore.user.uid), {
relatiecodes: newRelatiecodes
2023-01-21 21:36:22 +01:00
})
2022-09-26 16:23:45 +02:00
2023-03-20 11:23:46 +01:00
userStore.getPersons(newRelatiecodes)
2022-09-26 16:23:45 +02:00
2023-01-21 21:36:22 +01:00
buttonsDisabled.value = false
navigateTo('/settings')
2022-09-26 16:23:45 +02:00
}
const updateCheckbox = (person) => {
2023-03-20 11:23:46 +01:00
if (person.relatiecode === userStore.userPersons[0].relatiecode) return;
2022-09-26 16:23:45 +02:00
person.checked = !person.checked
}
2023-01-21 21:36:22 +01:00
</script>