Seven radii were in circulation (4/5/6/8/12/16px + pill) with no rule for which went where; one toolbar row on /transactions mixed four shape languages. This locks a 4-tier ladder (design.md convention 16): - pill: interactive toolbar controls (buttons, chips, pickers, segmented controls, toolbar search, count nubs) - rounded-xl (12px): overlay tier: page panel, dialogs, slide-overs - rounded-lg (8px): cards, form fields, popover/menu content, boxes - rounded-sm (4px): nested leaves (menu items, checkboxes, kbd/code nubs) Changes: - New SegmentedControl primitive (pill-in-pill tablist, h-8) replaces the hand-rolled bg-muted/70 tablist copied across 11 files - New ToolbarSearch primitive (pill, h-8) adopted on 9 page toolbars; dialog/picker searches keep the rounded-lg Input - dialog.tsx 8px -> 12px, matching SettingsModal/slide-over/CommandPalette - ContextPicker chips at the shared h-8 toolbar height - ~300 rounded-md / bare rounded call sites remapped by role; auth icon tiles and the mobile nav sheet come down from 16px to 12px - rounded-md, bare rounded, rounded-2xl and rounded-[Npx] are dead vocabulary, enforced by a new off-ladder-radius check in check:guards Verified: lint 0 errors, 14422 unit tests pass, check:guards green, tsc clean on all changed files, sandbox screenshots of transactions/ bookkeeping/granskning toolbars and the Ny verifikation dialog. Co-authored-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
154 lines
6.5 KiB
TypeScript
154 lines
6.5 KiB
TypeScript
'use client'
|
||
|
||
import { useState, useEffect } from 'react'
|
||
import { useTranslations } from 'next-intl'
|
||
import { useSearchParams, useRouter } from 'next/navigation'
|
||
import Link from 'next/link'
|
||
import { Button } from '@/components/ui/button'
|
||
import { EmptyState } from '@/components/ui/empty-state'
|
||
import { useToast } from '@/components/ui/use-toast'
|
||
import { AlertTriangle, CreditCard, ExternalLink } from 'lucide-react'
|
||
import { getSettingsPanel } from '@/lib/extensions/settings-panel-registry'
|
||
import { ENABLED_EXTENSION_IDS } from '@/lib/extensions/_generated/enabled-extensions'
|
||
import BankSyncStatusChip from '@/components/transactions/BankSyncStatusChip'
|
||
import { SettingsSectionHeader } from '@/components/settings/SettingsRows'
|
||
|
||
const BankingPanel = getSettingsPanel('enable-banking')
|
||
|
||
export function BankingSettingsContent() {
|
||
const t = useTranslations('settings_banking')
|
||
const tNav = useTranslations('settings_nav')
|
||
const tIntro = useTranslations('settings_intro')
|
||
const searchParams = useSearchParams()
|
||
const router = useRouter()
|
||
const { toast } = useToast()
|
||
const [bankConnectionError, setBankConnectionError] = useState<string | null>(null)
|
||
const [failedBankName, setFailedBankName] = useState<string | null>(null)
|
||
const [isAccessDenied, setIsAccessDenied] = useState(false)
|
||
const [showHbPoaHint, setShowHbPoaHint] = useState(false)
|
||
const hasBankingExtension = ENABLED_EXTENSION_IDS.has('enable-banking')
|
||
|
||
// Surface a bank connection/authorization failure that the OAuth callback
|
||
// bounced back as `?bank_error=...`. The success path is handled by the
|
||
// callback redirecting to `?select_accounts=<id>`, which the banking panel
|
||
// picks up to open account selection: there is no `bank_connected` param.
|
||
useEffect(() => {
|
||
const bankError = searchParams.get('bank_error')
|
||
if (!bankError) return
|
||
|
||
let errorMsg: string
|
||
try { errorMsg = decodeURIComponent(bankError) } catch { errorMsg = bankError }
|
||
const bankName = searchParams.get('bank_name')
|
||
const errorCode = searchParams.get('bank_error_code')
|
||
const psuType = searchParams.get('psu_type')
|
||
// The bank often returns a bare "server_error" with no description: show a
|
||
// human message instead of the raw OAuth error code.
|
||
if (errorCode === 'server_error' && errorMsg === 'server_error') {
|
||
errorMsg = t('bank_server_error')
|
||
}
|
||
|
||
// Consume the one-shot ?bank_error= param off the render path: a microtask
|
||
// defers these updates out of the effect body (react-hooks/set-state-in-
|
||
// effect) without a user-visible delay, since the param appears at most
|
||
// once per OAuth bounce-back. The cancellation flag drops the deferred work
|
||
// if the effect re-runs or the component unmounts before it flushes (also
|
||
// suppresses a duplicate toast under StrictMode's dev double-invoke).
|
||
let cancelled = false
|
||
queueMicrotask(() => {
|
||
if (cancelled) return
|
||
toast({
|
||
title: t('connect_failed_title'),
|
||
description: errorMsg,
|
||
variant: 'destructive',
|
||
})
|
||
setBankConnectionError(errorMsg)
|
||
if (bankName) setFailedBankName(bankName)
|
||
if (errorCode === 'access_denied') setIsAccessDenied(true)
|
||
// Handelsbanken rejects business connects with server_error when the
|
||
// company hasn't registered the open banking fullmakt ("Internet
|
||
// Företag – tilläggstjänst API Företag"): surface the fix steps.
|
||
if (bankName === 'Handelsbanken' && psuType === 'business' && errorCode === 'server_error') {
|
||
setShowHbPoaHint(true)
|
||
}
|
||
router.replace('/settings/banking')
|
||
})
|
||
return () => { cancelled = true }
|
||
}, [searchParams, router, toast, t])
|
||
|
||
return (
|
||
<div>
|
||
<SettingsSectionHeader title={tNav('banking')} intro={tIntro('banking')} />
|
||
|
||
{/* OAuth bounce-back failure: a live warning, so it stays visible in the
|
||
page flow, as compact warning-tone lines instead of a bordered box. */}
|
||
{bankConnectionError && (
|
||
<div role="alert" className="mt-6 flex items-start gap-2 px-1">
|
||
<AlertTriangle className="mt-0.5 h-4 w-4 shrink-0 text-attn" />
|
||
<div className="min-w-0 flex-1 space-y-1 text-[12.5px] leading-relaxed">
|
||
<p className="text-attn">{bankConnectionError}</p>
|
||
{isAccessDenied && failedBankName && (
|
||
<p className="text-muted-foreground">
|
||
{t('access_denied_hint', { bankName: failedBankName })}
|
||
</p>
|
||
)}
|
||
{showHbPoaHint && (
|
||
<p className="text-muted-foreground">
|
||
{t('hb_business_poa_hint')}{' '}
|
||
<a
|
||
href="https://tilisy.enablebanking.com/guides/SE/Handelsbanken/"
|
||
target="_blank"
|
||
rel="noreferrer"
|
||
className="underline underline-offset-2 hover:text-foreground"
|
||
>
|
||
{t('hb_business_poa_link')}
|
||
</a>
|
||
</p>
|
||
)}
|
||
<p className="text-muted-foreground">
|
||
{t('import_fallback_text')}<Link href="/import?mode=bank" className="underline underline-offset-2 hover:text-foreground">{t('import_fallback_link')}</Link>{t('import_fallback_suffix')}
|
||
</p>
|
||
</div>
|
||
<button
|
||
onClick={() => {
|
||
setBankConnectionError(null)
|
||
setFailedBankName(null)
|
||
setIsAccessDenied(false)
|
||
setShowHbPoaHint(false)
|
||
}}
|
||
className="shrink-0 rounded-sm p-1 text-muted-foreground transition-colors duration-150 hover:text-foreground"
|
||
aria-label={t('dismiss_aria')}
|
||
>
|
||
<span className="text-lg leading-none">×</span>
|
||
</button>
|
||
</div>
|
||
)}
|
||
|
||
{hasBankingExtension && BankingPanel ? (
|
||
<>
|
||
{/* The chip renders null when there are no connections; empty:hidden
|
||
keeps its margin from leaving a stray gap in that case. */}
|
||
<div className="mt-6 empty:hidden">
|
||
<BankSyncStatusChip />
|
||
</div>
|
||
<BankingPanel />
|
||
</>
|
||
) : (
|
||
<div className="pt-8">
|
||
<EmptyState
|
||
icon={CreditCard}
|
||
title={t('not_enabled_title')}
|
||
description={t('not_enabled_description')}
|
||
>
|
||
<Button variant="outline" asChild>
|
||
<Link href="/extensions">
|
||
<ExternalLink className="mr-2 h-4 w-4" />
|
||
{t('go_to_extensions')}
|
||
</Link>
|
||
</Button>
|
||
</EmptyState>
|
||
</div>
|
||
)}
|
||
</div>
|
||
)
|
||
}
|