From 1269d3b838c8e7c6219df1be8e5e03736e7b87ed Mon Sep 17 00:00:00 2001 From: flfeders Date: Tue, 16 Apr 2024 11:34:13 +0200 Subject: [PATCH] Added ProfileSelection when no profile is selected --- components/ProfileSelection.vue | 24 ++++++++++++++++++++++ stores/data.js | 36 ++++++++++++++++++++------------- 2 files changed, 46 insertions(+), 14 deletions(-) create mode 100644 components/ProfileSelection.vue diff --git a/components/ProfileSelection.vue b/components/ProfileSelection.vue new file mode 100644 index 0000000..01dbb63 --- /dev/null +++ b/components/ProfileSelection.vue @@ -0,0 +1,24 @@ + + + + + \ No newline at end of file diff --git a/stores/data.js b/stores/data.js index 125eb90..4468226 100644 --- a/stores/data.js +++ b/stores/data.js @@ -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,