Files
accounted/components/settings/useSettingsNavItems.ts
T
Jakob Wennberg ff01640f60 feat(reports,settings): report library + focused report routes, settings modal (#629)
* feat(reports,settings): report library + focused report routes, settings modal

Reports
- Replace the monolithic /reports tab-switcher with a calm, grouped report
  library landing (ReportLibrary + RecentReportsShelf) driven by a new
  lib/reports/catalog.ts.
- Each report opens a focused /reports/[slug] route (FocusedReport) with a
  shared fiscal-year selector, optional date-range, and URL-based account
  drill-down into the general ledger.
- Extract every report view into components/reports/views, add a reusable
  ReportExportMenu, and remove the old ReportsNav.

Settings
- Add an intercepting @settingsModal parallel route so in-app navigation to
  /settings opens as a modal over the current page; hard loads still resolve
  to the full page.
- Share one SettingsShell (rail + content) between page and modal, extract each
  section into components/settings/sections/*Content, add a settings hotkey and
  command-palette entry, and remove the old SettingsSidebar.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(reports,settings): remove dead salary-journal entry, fix border token

Addresses PR review feedback (#629):

- Remove the unreachable `salary-journal` report from the catalog. It had
  needsEmployees + no route + no FocusedView handler and `hasEmployees` was
  never plumbed through, so it never appeared in the library and a direct
  /reports/salary-journal URL rendered a blank frame. The report was never on
  the old page and has no view component; the API + generator stay in place for
  a proper follow-up. Drops its two now-unused i18n keys.

- Replace opacity-suffixed `border-border/8` section dividers with full-opacity
  `border-border` across the extracted settings section components, per the
  design system (no opacity-suffixed border tokens on surfaces).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* ci: re-trigger checks (pg-real hit a Docker Hub registry timeout)

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-02 14:50:50 +02:00

81 lines
3.6 KiB
TypeScript

'use client'
import { useTranslations } from 'next-intl'
import { useCompany } from '@/contexts/CompanyContext'
import { useAgentSheet } from '@/components/agent/AgentSheetProvider'
import { ENABLED_EXTENSION_IDS } from '@/lib/extensions/_generated/enabled-extensions'
export type SettingsGroupKey = 'account' | 'company' | 'accounting' | 'sales' | 'tools'
export interface SettingsNavItem {
id: string
href: string
label: string
group: SettingsGroupKey
}
export interface SettingsNavGroup {
key: SettingsGroupKey
label: string
items: SettingsNavItem[]
}
// Rail group order — personal first (Konto), then company-scoped buckets.
const GROUP_ORDER: SettingsGroupKey[] = ['account', 'company', 'accounting', 'sales', 'tools']
/**
* Single source of truth for the settings sections, their conditional
* visibility, and their grouping. Consumed by both the full-page rail and the
* routed settings modal so the two can never drift on which sections show for
* AB vs EF, sandbox, identity-verified, or enabled extensions.
*
* Visibility is derived from client context (no extra fetch): `isSandbox`
* comes from CompanyContext, identity from the agent sheet, and extension
* availability from the generated enabled-extensions set.
*/
export function useSettingsNavItems(): { items: SettingsNavItem[]; groups: SettingsNavGroup[] } {
const { company, isSandbox } = useCompany()
const { identity } = useAgentSheet()
const t = useTranslations('settings_nav')
const hasCompany = !!company
const hasBankingExtension = ENABLED_EXTENSION_IDS.has('enable-banking')
const hasMcpExtension = ENABLED_EXTENSION_IDS.has('mcp-server')
// Företagsprofil (TIC-snapshot) lives under Företag; Skatteverket under Skatt;
// assistentens minne + kunskap under Assistenten; säkerhetsbackup under
// Importera/Exportera. Team stays hidden (show:false) until enabled.
const defs: Array<SettingsNavItem & { show: boolean }> = [
{ id: 'account', href: '/settings/account', label: t('account'), group: 'account', show: true },
{ id: 'company', href: '/settings/company', label: t('company'), group: 'company', show: hasCompany },
{ id: 'bookkeeping', href: '/settings/bookkeeping', label: t('bookkeeping'), group: 'accounting', show: hasCompany },
{ id: 'tax', href: '/settings/tax', label: t('tax'), group: 'accounting', show: hasCompany },
{ id: 'salary', href: '/settings/salary', label: t('salary'), group: 'accounting', show: hasCompany && company?.entity_type === 'aktiebolag' },
{ id: 'invoicing', href: '/settings/invoicing', label: t('invoicing'), group: 'sales', show: hasCompany },
{ id: 'templates', href: '/settings/templates', label: t('templates'), group: 'sales', show: hasCompany },
{ id: 'banking', href: '/settings/banking', label: t('banking'), group: 'tools', show: hasCompany && !isSandbox && hasBankingExtension },
{ id: 'assistant', href: '/settings/assistant', label: t('assistant'), group: 'tools', show: hasCompany && identity.isVerified },
{ id: 'api', href: '/settings/api', label: t('api'), group: 'tools', show: hasCompany && hasMcpExtension },
]
const items: SettingsNavItem[] = defs
.filter((d) => d.show)
.map(({ show: _show, ...item }) => item)
const groupLabels: Record<SettingsGroupKey, string> = {
account: t('group_account'),
company: t('group_company'),
accounting: t('group_accounting'),
sales: t('group_sales'),
tools: t('group_tools'),
}
const groups: SettingsNavGroup[] = GROUP_ORDER.map((key) => ({
key,
label: groupLabels[key],
items: items.filter((i) => i.group === key),
})).filter((g) => g.items.length > 0)
return { items, groups }
}