Added ProfileSelection when no profile is selected
This commit is contained in:
24
components/ProfileSelection.vue
Normal file
24
components/ProfileSelection.vue
Normal 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>
|
||||
@@ -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)
|
||||
currentTenant.value = activeProfile.value.tenant
|
||||
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
|
||||
}
|
||||
|
||||
await fetchData()
|
||||
|
||||
}
|
||||
|
||||
@@ -284,24 +293,22 @@ 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(error) {
|
||||
|
||||
} else {
|
||||
reloadNuxtApp({
|
||||
path:"/",
|
||||
ttl: 10000
|
||||
})
|
||||
if(oldActiveProfileConnection){
|
||||
const {error} = await supabase.from("profileconnections").update({active: false}).eq("profile_id", oldActiveProfileConnection.profile_id)
|
||||
}
|
||||
|
||||
reloadNuxtApp({
|
||||
path:"/",
|
||||
ttl: 10000
|
||||
})
|
||||
|
||||
/*await clearStore()
|
||||
await fetchData()
|
||||
router.push("/")
|
||||
@@ -1479,6 +1486,7 @@ export const useDataStore = defineStore('data', () => {
|
||||
//General
|
||||
currentTenant,
|
||||
loaded,
|
||||
showProfileSelection,
|
||||
ownTenant,
|
||||
initializeData,
|
||||
changeProfile,
|
||||
|
||||
Reference in New Issue
Block a user