9dfa6c6708
* feat(home): first-run block as a numbered three-step thread with partner marks The founder-picked stepped shape for 'Hur vill du komma igang?': 1 Fa in din bokforing (primary Flytta bokforingen + Fortnox/Visma/Bokio marks + '+ SIE'; Starta fran borjan as an inline alternative that just checks the step off), 2 Koppla banken (Enable Banking mark only), 3 Bygg din bokforingsassistent (Beta chip, no vendor logo). Dots walk number -> filled active -> sage check; the persisted state machine is unchanged, but choosing a path no longer auto-completes the setup: the block retires when all three steps are done (or via Dolj). DashboardContent's build-assistant hero now waits until the checklist is gone so the assistant is not pitched twice. initial_setup i18n rewritten for the stepped copy (sv+en), unused selected-state keys removed. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(home): Skatteverket as step three, assistant last, ticked steps collapse Founder feedback on #1149: the thread is now four steps: 1 Fa in din bokforing, 2 Koppla banken, 3 Anslut Skatteverket (with the SKV mark, BankID authorize link; skipped entirely in builds without the skatteverket extension), 4 Bygg din bokforingsassistent. A completed step drops its description and actions and keeps only the checked muted title, so the fresh-start pitch never lingers after the books are in. The heading counts honestly ({count} steg) and completion now requires all four steps. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * polish(home): one-line checklist header Founder feedback: the title and sub-line said the same thing twice; only '4 steg sa ar bokforingen igang' remains (Dolj stays beside it). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
122 lines
3.9 KiB
TypeScript
122 lines
3.9 KiB
TypeScript
import { NextResponse } from 'next/server'
|
|
import { withRouteContext } from '@/lib/api/with-route-context'
|
|
import { validateBody } from '@/lib/api/validate'
|
|
import { UpdateInitialSetupStateSchema } from '@/lib/api/schemas'
|
|
import { errorResponseFromCode } from '@/lib/errors/get-structured-error'
|
|
import { getErrorMessage } from '@/lib/errors/get-error-message'
|
|
|
|
const INITIAL_SETUP_SELECT =
|
|
'initial_setup_path, initial_setup_completed_at, initial_setup_dismissed_at' as const
|
|
|
|
function toResponse(data: {
|
|
initial_setup_path: string | null
|
|
initial_setup_completed_at: string | null
|
|
initial_setup_dismissed_at: string | null
|
|
}) {
|
|
return {
|
|
path: data.initial_setup_path,
|
|
completedAt: data.initial_setup_completed_at,
|
|
dismissedAt: data.initial_setup_dismissed_at,
|
|
}
|
|
}
|
|
|
|
export const GET = withRouteContext(
|
|
'onboarding-state.get',
|
|
async (_request, { supabase, companyId, log, requestId }) => {
|
|
const { data, error } = await supabase
|
|
.from('company_settings')
|
|
.select(INITIAL_SETUP_SELECT)
|
|
.eq('company_id', companyId)
|
|
.maybeSingle()
|
|
|
|
if (error) {
|
|
log.error('initial setup state lookup failed', error)
|
|
return errorResponseFromCode('INTERNAL_ERROR', log, {
|
|
requestId,
|
|
details: { reason: getErrorMessage(error) },
|
|
})
|
|
}
|
|
if (!data) return errorResponseFromCode('NOT_FOUND', log, { requestId })
|
|
|
|
return NextResponse.json({ data: toResponse(data) })
|
|
},
|
|
)
|
|
|
|
export const PATCH = withRouteContext(
|
|
'onboarding-state.update',
|
|
async (request, { supabase, companyId, log, requestId }) => {
|
|
const validation = await validateBody(request, UpdateInitialSetupStateSchema, {
|
|
log,
|
|
operation: 'onboarding-state.update',
|
|
})
|
|
if (!validation.success) return validation.response
|
|
const body = validation.data
|
|
|
|
const { data: existing, error: lookupError } = await supabase
|
|
.from('company_settings')
|
|
.select(INITIAL_SETUP_SELECT)
|
|
.eq('company_id', companyId)
|
|
.maybeSingle()
|
|
|
|
if (lookupError) {
|
|
log.error('initial setup state lookup failed', lookupError)
|
|
return errorResponseFromCode('INTERNAL_ERROR', log, {
|
|
requestId,
|
|
details: { reason: getErrorMessage(lookupError) },
|
|
})
|
|
}
|
|
if (!existing) return errorResponseFromCode('NOT_FOUND', log, { requestId })
|
|
|
|
const effectivePath = body.path !== undefined ? body.path : existing.initial_setup_path
|
|
if (body.completed === true && !effectivePath) {
|
|
return NextResponse.json(
|
|
{
|
|
error: 'Validation failed',
|
|
type: 'validation_error',
|
|
errors: [{
|
|
field: 'completed',
|
|
message: 'Välj först hur du vill komma igång',
|
|
code: 'custom',
|
|
}],
|
|
},
|
|
{ status: 400 },
|
|
)
|
|
}
|
|
|
|
const now = new Date().toISOString()
|
|
const update: Record<string, unknown> = {}
|
|
if (body.path !== undefined) {
|
|
update.initial_setup_path = body.path
|
|
// Choosing a path no longer completes the setup: since the stepped
|
|
// Hem block (rest-of-nav 2), "fresh" just checks off step one and the
|
|
// block completes when every step is done.
|
|
update.initial_setup_completed_at = null
|
|
update.initial_setup_dismissed_at = null
|
|
}
|
|
if (body.completed !== undefined) {
|
|
update.initial_setup_completed_at = body.completed ? now : null
|
|
}
|
|
if (body.dismissed !== undefined) {
|
|
update.initial_setup_dismissed_at = body.dismissed ? now : null
|
|
}
|
|
|
|
const { data, error } = await supabase
|
|
.from('company_settings')
|
|
.update(update)
|
|
.eq('company_id', companyId)
|
|
.select(INITIAL_SETUP_SELECT)
|
|
.single()
|
|
|
|
if (error) {
|
|
log.error('initial setup state update failed', error)
|
|
return errorResponseFromCode('INTERNAL_ERROR', log, {
|
|
requestId,
|
|
details: { reason: getErrorMessage(error) },
|
|
})
|
|
}
|
|
|
|
return NextResponse.json({ data: toResponse(data) })
|
|
},
|
|
{ requireWrite: true },
|
|
)
|