d59e4708cf
* feat(nav): concept sidebar with folds, collapse rail, and user menu (UI migration PR 2) The concept's navigation, exactly, with all current functionality kept: - Groups restructured per concept: top (Hem, Assistenten), ARBETA (Bokforing, Underlag, Transaktioner, Granskning, Kundfakturor, Leverantorsfakturor, Loner), ANALYS, DATA (Register fold + Importera/exportera), SKATT & BOKSLUT (Moms, Skattekonto, Viktiga datum, Bokslut fold). Entity/capability/dimension gating unchanged. - Register and Bokslut are animated folds (grid-rows 0fr/1fr), children text-indented behind a hairline; closed by default, forced open by an active child route; state persists per user. - Sidebar collapses to a 64px icon rail (toggle top of rail); width is one inline --nav-w CSS variable on #dash-shell that aside and <main> both read, so the panel follows in lockstep. Server-rendered from ui_state so first paint is right. - Sticky bottom user block (avatar, name, active company) opening an upward user menu: identity, company-switcher flyout (search + building glyphs + roles + check, real switch mechanism via shared lib/company/switch-client), Installningar, Medlemmar och roller, Abonnemang, Hjalp, support, terracotta logout. Trial touchpoint kept. - CompanySwitcher removed from desktop top (lives in the user menu now); mobile bottom nav + sheet unchanged. - New migration 20260723120000: user_preferences.ui_state jsonb bag (founder-approved) + POST /api/user/ui-state (requireAuth, strict zod, merge semantics) with route tests. - i18n: fold/collapse/menu keys added sv+en; deadlines -> "Viktiga datum", year_end -> "Arsbokslut" per concept. Discord-community row deferred: no invite URL exists in the repo. Badges stay the current two (Transaktioner, Granskning); an Underlag count is a follow-up with lib/worklist. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(nav): brand-mark sidebar header + auto-hiding scrollbars Concept alignment feedback: the sidebar gets a header row (brand mark left, collapse toggle right) hanging from the same top line as the panel, instead of a lone right-aligned toggle. Scrollbars go overlay-style app-wide: transparent at rest, revealed only while their container scrolls (ScrollbarReveal stamps .is-scrolling via one capture-phase document listener), fading out after 700ms idle. The gutter stays reserved so revealing never shifts layout. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(nav): company flyout opens downward + Discord community row The flyout was bottom-anchored to its row and grew upward over the menu; founder feedback: top-align with the row and grow downward. Adds the Discord community row to the user menu (external invite link). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
39 lines
1.4 KiB
TypeScript
39 lines
1.4 KiB
TypeScript
'use client'
|
|
|
|
import { switchCompany } from '@/lib/company/actions'
|
|
|
|
/**
|
|
* Client-side company switch: persists the new active company via the
|
|
* server action, notifies sibling tabs, then hard-reloads onto the new
|
|
* company. Shared by CompanySwitcher (mobile sheet) and the sidebar
|
|
* user-menu flyout so both use the exact same mechanism.
|
|
*
|
|
* Returns an error code instead of navigating when the switch fails.
|
|
*/
|
|
export async function performCompanySwitch(
|
|
companyId: string,
|
|
): Promise<{ error: string } | void> {
|
|
const result = await switchCompany(companyId)
|
|
if (result.error) {
|
|
return { error: result.error }
|
|
}
|
|
// Notify every other open tab of the same user so they hard-reload
|
|
// onto the new company. BroadcastChannel is best-effort: if the
|
|
// browser doesn't support it (very old) we still hard-reload
|
|
// ourselves, and other tabs will self-correct via the visibilitychange
|
|
// / pageshow listeners in CompanyTabSync on their next focus event.
|
|
if (typeof BroadcastChannel !== 'undefined') {
|
|
try {
|
|
const channel = new BroadcastChannel('gnubok-company-switch')
|
|
channel.postMessage({ companyId })
|
|
channel.close()
|
|
} catch {
|
|
// Ignore: hard reload still happens below
|
|
}
|
|
}
|
|
// Hard navigation: tears down React state, router cache, in-flight
|
|
// fetches, blob URLs, etc. This is the whole point: nothing from the
|
|
// previous company can survive the switch.
|
|
window.location.assign('/')
|
|
}
|