mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-15 17:24:10 +00:00
Add frontend handling for users without a company
Make setSelectedCompany null-safe and clear stale localStorage. Conditionally initialize company store state in bootstrap. Add router guard to redirect no-company users to NoCompanyView while allowing super admins through. Hide sidebar when no company. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
11
resources/scripts/admin/admin-router.js
vendored
11
resources/scripts/admin/admin-router.js
vendored
@@ -147,12 +147,6 @@ export default [
|
||||
component: RegisterWithInvitation,
|
||||
meta: { requiresAuth: false },
|
||||
},
|
||||
{
|
||||
path: '/admin/no-company',
|
||||
name: 'no.company',
|
||||
component: NoCompanyView,
|
||||
meta: { requiresAuth: true },
|
||||
},
|
||||
{
|
||||
path: '/installation',
|
||||
component: LayoutInstallation,
|
||||
@@ -203,6 +197,11 @@ export default [
|
||||
component: LayoutBasic,
|
||||
meta: { requiresAuth: true },
|
||||
children: [
|
||||
{
|
||||
path: 'no-company',
|
||||
name: 'no.company',
|
||||
component: NoCompanyView,
|
||||
},
|
||||
{
|
||||
path: 'dashboard',
|
||||
name: 'dashboard',
|
||||
|
||||
@@ -6,12 +6,15 @@
|
||||
|
||||
<SiteHeader />
|
||||
|
||||
<SiteSidebar />
|
||||
<SiteSidebar v-if="hasCompany" />
|
||||
|
||||
<ExchangeRateBulkUpdateModal />
|
||||
|
||||
<main
|
||||
class="h-screen h-screen-ios overflow-y-auto md:pl-56 xl:pl-64 min-h-0"
|
||||
:class="[
|
||||
'h-screen h-screen-ios overflow-y-auto min-h-0',
|
||||
hasCompany ? 'md:pl-56 xl:pl-64' : '',
|
||||
]"
|
||||
>
|
||||
<div class="pt-16 pb-16">
|
||||
<router-view />
|
||||
@@ -51,8 +54,19 @@ const isAppLoaded = computed(() => {
|
||||
return globalStore.isAppLoaded
|
||||
})
|
||||
|
||||
const hasCompany = computed(() => {
|
||||
return !!companyStore.selectedCompany || !!userStore.currentUser?.is_super_admin
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
globalStore.bootstrap().then((res) => {
|
||||
if (!res.data.current_company && !res.data.current_user.is_super_admin) {
|
||||
if (route.name !== 'no.company') {
|
||||
router.push({ name: 'no.company' })
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if (route.meta.ability && !userStore.hasAbilities(route.meta.ability)) {
|
||||
router.push({ name: 'account.settings' })
|
||||
} else if (route.meta.isSuperAdmin && !userStore.currentUser.is_super_admin) {
|
||||
|
||||
6
resources/scripts/admin/stores/company.js
vendored
6
resources/scripts/admin/stores/company.js
vendored
@@ -18,7 +18,11 @@ export const useCompanyStore = (useWindow = false) => {
|
||||
|
||||
actions: {
|
||||
setSelectedCompany(data) {
|
||||
window.Ls.set('selectedCompany', data.id)
|
||||
if (data) {
|
||||
window.Ls.set('selectedCompany', data.id)
|
||||
} else {
|
||||
window.Ls.remove('selectedCompany')
|
||||
}
|
||||
this.selectedCompany = data
|
||||
},
|
||||
|
||||
|
||||
18
resources/scripts/admin/stores/global.js
vendored
18
resources/scripts/admin/stores/global.js
vendored
@@ -79,12 +79,18 @@ export const useGlobalStore = (useWindow = false) => {
|
||||
|
||||
// company store
|
||||
companyStore.companies = response.data.companies
|
||||
companyStore.selectedCompany = response.data.current_company
|
||||
companyStore.setSelectedCompany(response.data.current_company)
|
||||
companyStore.selectedCompanySettings =
|
||||
response.data.current_company_settings
|
||||
companyStore.selectedCompanyCurrency =
|
||||
response.data.current_company_currency
|
||||
|
||||
if (response.data.current_company) {
|
||||
companyStore.setSelectedCompany(response.data.current_company)
|
||||
companyStore.selectedCompanySettings =
|
||||
response.data.current_company_settings
|
||||
companyStore.selectedCompanyCurrency =
|
||||
response.data.current_company_currency
|
||||
} else {
|
||||
companyStore.setSelectedCompany(null)
|
||||
companyStore.selectedCompanySettings = {}
|
||||
companyStore.selectedCompanyCurrency = null
|
||||
}
|
||||
|
||||
// Determine and load the appropriate language
|
||||
const userLanguage = response.data.current_user_settings?.language
|
||||
|
||||
Reference in New Issue
Block a user