feat(mileage): surface Körjournal in the nav behind a settings toggle (#1540)

* feat(mileage): surface Körjournal in the nav behind a settings toggle

The /mileage page shipped hidden: the route works but no nav row points at
it. Add company_settings.mileage_enabled (mirroring dimensions_enabled) with
a switch in Fönster -> Bokföring, and show the Arbeta nav row when the toggle
is on OR the company already has mileage_trips rows, the same hybrid gate as
webshop orders, so trips created via API/MCP can never become invisible
underlag. UI visibility only, never load-bearing for correctness.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* fix(migrations): move mileage_enabled migration after already-applied 20260812153208

origin/main merged in 20260812153208 which prod has already applied; a new
file sorting before it risks an out-of-order db push abort.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Mattsson
2026-08-12 21:48:01 +02:00
committed by GitHub
co-authored by Claude Fable 5
parent 67febd5097
commit 45d7f1be4e
12 changed files with 191 additions and 6 deletions
+15
View File
@@ -152,6 +152,7 @@ export default async function DashboardLayout({
{ data: allSettingsNames },
{ data: userPrefs },
hasWebshop,
hasMileageTrips,
] = await Promise.all([
supabase.from('companies').select('*').eq('id', companyId).single(),
supabase.from('company_members').select('role').eq('company_id', companyId).eq('user_id', user.id).single(),
@@ -195,6 +196,16 @@ export default async function DashboardLayout({
([woo, orders]) =>
(woo.data?.length ?? 0) > 0 || (orders.data?.length ?? 0) > 0,
),
// Whether the company already has mileage trips: OR-ed with the
// mileage_enabled settings toggle below so trips created via API/MCP can
// never be invisible underlag even if nobody flipped the toggle. Indexed
// limit-1 select, same accepted first-paint cost as the webshop gate.
supabase
.from('mileage_trips')
.select('id')
.eq('company_id', companyId)
.limit(1)
.then((trips) => (trips.data?.length ?? 0) > 0),
])
// company_id -> current display name for every company the user belongs to.
@@ -267,6 +278,9 @@ export default async function DashboardLayout({
// mechanism as paysSalaries: UI gate only, never load-bearing for
// correctness (dimensions plan §2).
const dimensionsEnabled = settings?.dimensions_enabled ?? false
// Körjournal visibility: the settings toggle is the normal way in, existing
// trips force the row on so already-created data stays reachable.
const hasMileage = (settings?.mileage_enabled ?? false) || hasMileageTrips
const companyWithName = {
...companyRow,
name: displayName,
@@ -336,6 +350,7 @@ export default async function DashboardLayout({
paysSalaries={paysSalaries}
dimensionsEnabled={dimensionsEnabled}
hasWebshop={hasWebshop}
hasMileage={hasMileage}
isSandbox={isSandbox}
extensionNavItems={getExtensionNavItems()}
userName={userProfile?.full_name ?? null}
+1 -1
View File
@@ -37,7 +37,7 @@ export const getDashboardSettings = cache(async () => {
return supabase
.from('company_settings')
.select('company_name, onboarding_complete, entity_type, pays_salaries, is_sandbox, dimensions_enabled, ore_rounding, initial_setup_path, initial_setup_completed_at, initial_setup_dismissed_at, vat_registered, moms_period')
.select('company_name, onboarding_complete, entity_type, pays_salaries, is_sandbox, dimensions_enabled, mileage_enabled, ore_rounding, initial_setup_path, initial_setup_completed_at, initial_setup_dismissed_at, vat_registered, moms_period')
.eq('company_id', companyId)
.maybeSingle()
})
+19
View File
@@ -97,6 +97,25 @@ describe('PUT /api/settings', () => {
expect(deadlineMocks.regenerate).not.toHaveBeenCalled()
})
it('accepts the mileage_enabled visibility toggle', async () => {
enqueueMany([
{ data: { entity_type: 'enskild_firma', onboarding_complete: true } }, // fetch oldSettings
{ data: { id: 's1', mileage_enabled: true } }, // update ... returning
{ data: null, count: 5 }, // deadlines count (has some -> no regen)
])
const request = createMockRequest('/api/settings', {
method: 'PUT',
body: { mileage_enabled: true },
})
const response = await PUT(request, { params: Promise.resolve({}) })
const { status, body } = await parseJsonResponse<{ data: { mileage_enabled: boolean } }>(response)
expect(status).toBe(200)
expect(body.data.mileage_enabled).toBe(true)
expect(deadlineMocks.regenerate).not.toHaveBeenCalled()
})
it('round-trips share capital fields and clears them with null', async () => {
const updates = { aktiekapital: 25000, antal_aktier: 500 }
enqueueMany([