Files
InvoiceShelf/resources/scripts/api/services/bootstrap.service.ts
Darko Gjorgjijoski 7743c2e126 feat(modules): dynamic sidebar group rendering active modules
The sidebar gains a new section that lists each currently-activated module
as a direct shortcut to its settings page. This is the always-visible
companion to the company-context Active Modules index — both surface the
same set of modules, but the index is the catalog landing page and the
sidebar group is the per-module quick access.

- BootstrapController returns module_menu populated from
  \InvoiceShelf\Modules\Registry::allMenu(), but only on the company-context
  branch — not on the super-admin branch (lines 53-69), since super admins
  don't see the dynamic group. Because nwidart only boots service providers
  for currently-activated modules, the registry naturally contains only
  active modules at request time, no extra filtering needed.

- bootstrap.service.ts BootstrapResponse type extended with
  module_menu?: ModuleMenuItem[]; new ModuleMenuItem interface
  (title/link/icon) — shaped distinctly from MenuItem because module entries
  use namespaced i18n keys and don't carry group/ability metadata.

- global.store.ts exposes a moduleMenu ref + a hasActiveModules computed.

- SiteSidebar.vue appends a new "Modules" section after the existing
  menuGroups output, in both the mobile (Dialog) and desktop branches. The
  section is hidden when hasActiveModules is false. Uses the
  modules.sidebar.section_title i18n key added in the previous commit.
2026-04-09 00:29:56 +02:00

71 lines
2.0 KiB
TypeScript

import { client } from '../client'
import { API } from '../endpoints'
import type { User, UserSetting } from '@/scripts/types/domain/user'
import type { Company } from '@/scripts/types/domain/company'
import type { Currency } from '@/scripts/types/domain/currency'
import type { Ability } from '@/scripts/types/domain/role'
export interface MenuItem {
title: string
name: string
link: string
icon: string
group: string
group_label?: string
ability?: string
}
/**
* Sidebar item registered by an active module via
* \InvoiceShelf\Modules\Registry::registerMenu() in the module's ServiceProvider::boot().
*
* Distinct shape from MenuItem because module entries are namespaced (i18n
* keys come from the module's lang files) and don't carry group/ability —
* they always render under the dynamic "Modules" sidebar section.
*/
export interface ModuleMenuItem {
title: string
link: string
icon: string
}
export interface BootstrapResponse {
current_user: User
current_user_settings: Record<string, string>
current_user_abilities: Ability[]
companies: Company[]
current_company: Company | null
current_company_settings: Record<string, string>
current_company_currency: Currency | null
main_menu: MenuItem[]
setting_menu: MenuItem[]
config: Record<string, unknown>
global_settings: Record<string, string>
modules: string[]
module_menu?: ModuleMenuItem[]
admin_mode?: boolean
pending_invitations?: Array<{
token: string
company_name: string
invited_by: string
email: string
}>
}
export interface CurrentCompanyResponse {
data: Company
}
export const bootstrapService = {
async bootstrap(adminMode?: boolean): Promise<BootstrapResponse> {
const url = adminMode ? `${API.BOOTSTRAP}?admin_mode=1` : API.BOOTSTRAP
const { data } = await client.get(url)
return data
},
async getCurrentCompany(): Promise<CurrentCompanyResponse> {
const { data } = await client.get(API.CURRENT_COMPANY)
return data
},
}