Added ProfileSelection when no profile is selected

This commit is contained in:
2024-04-16 11:34:13 +02:00
parent c1108314c1
commit 1269d3b838
2 changed files with 46 additions and 14 deletions

View File

@@ -0,0 +1,24 @@
<script setup>
const dataStore = useDataStore()
</script>
<template>
<div class="w-1/2 mx-auto">
<p class="text-2xl mb-5 text-center">Bitte wähle dein gewünschtes Profil</p>
<div v-for="profile in dataStore.ownProfiles" class="flex justify-between my-3">
{{dataStore.tenants.find(i => i.id === profile.tenant).name}}
<UButton
variant="outline"
@click="dataStore.changeProfile(profile.id)"
>Auswählen</UButton>
</div>
</div>
</template>
<style scoped>
</style>

View File

@@ -149,6 +149,7 @@ export const useDataStore = defineStore('data', () => {
const loaded = ref(false)
const showProfileSelection = ref(false)
const ownTenant = ref({
calendarConfig: {
eventTypes: []
@@ -271,11 +272,19 @@ export const useDataStore = defineStore('data', () => {
let profileconnections = (await supabase.from("profileconnections").select()).data
let profiles = (await supabase.from("profiles").select()).data
let profileId = profileconnections.find(i => i.active).profile_id
activeProfile.value = profiles.find(i => i.id === profileId)
let activeProfileConnection = profileconnections.find(i => i.active)
if(activeProfileConnection) {
activeProfile.value = profiles.find(i => i.id === activeProfileConnection.profile_id)
currentTenant.value = activeProfile.value.tenant
await fetchData()
} else {
console.log("No Profile Active")
await fetchOwnProfiles()
await fetchTenants()
showProfileSelection.value = true
}
}
@@ -284,23 +293,21 @@ export const useDataStore = defineStore('data', () => {
let profileconnections = (await supabase.from("profileconnections").select()).data
let oldActiveProfileId = profileconnections.find(i => i.active).profile_id
let oldActiveProfileConnection = profileconnections.find(i => i.active)
const {error} = await supabase.from("profileconnections").update({active: true}).eq("profile_id", newActiveProfileId)
if(error) {
console.log(error)
} else {
const {error} = await supabase.from("profileconnections").update({active: false}).eq("profile_id", oldActiveProfileId)
if(oldActiveProfileConnection){
const {error} = await supabase.from("profileconnections").update({active: false}).eq("profile_id", oldActiveProfileConnection.profile_id)
}
if(error) {
} else {
reloadNuxtApp({
path:"/",
ttl: 10000
})
}
/*await clearStore()
await fetchData()
@@ -1479,6 +1486,7 @@ export const useDataStore = defineStore('data', () => {
//General
currentTenant,
loaded,
showProfileSelection,
ownTenant,
initializeData,
changeProfile,