6d9846b1e7
* feat(settings): Fönster redesign - flat rows, help behind ?, dirty save bar Founder-approved concept (2026-07-25) applied to the whole settings surface, modal and full-page variants alike: - New primitives in components/settings/SettingsRows.tsx: section header (serif title + one-line intro), eyebrow groups, hairline label/control rows, flat inputs/selects/textareas, segmented control, animated reveal for gated settings, danger zone. - Every static explanation paragraph moved behind a "?" popover (HelpPopover) at row or group level; dynamic status stays visible. - Modal chrome: company kicker over serif title, fixed 920x680 window. - SettingsFormWrapper: save is a sticky bar that appears only when the form is dirty; collapses to zero height when clean. - All 11 sections converted (Konto, Abonnemang, Företag, Bokföring, Skatt, Löner, Fakturering, Mallar, Bank incl. Enable Banking-panel, Assistenten, API) with handlers, validation, role/entitlement/sandbox gates and i18n keys preserved; checkboxes became switches, cards dissolved into groups. - Fix: Escape with an open help popover closed the whole settings modal; it now closes the popover first. - New i18n keys: settings_intro.*, group labels, wrapper_unsaved (sv+en). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(settings): founder feedback round 1 on the Fönster redesign - Abonnemang paying state: status and manage split into two rows so the row no longer wraps awkwardly; the included-features list now shows for paying companies too. - Logos where the counterpart has one: BankID mark on the security row and on the Koppla BankID button, Skatteverket mark on the connection rows. - Buttons are unmistakably buttons: 27 text-labeled row actions went from ghost to outline pills; icon-only actions stay quiet. - The agent-knowledge view (Regler & profil: Dina regler, Momsprofil, Konventioner) converted to the flat row language; it was the last old-style surface inside settings. Descriptions moved behind "?", rules render as hairline rows, the per-row "Regel" chip demoted to muted text. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(settings): address review-bot findings on the Fönster redesign - SettingsFormWrapper marks the form dirty on switch clicks too: Radix Switch is a button and fires no input event, so switch-only changes (f-skatt, KU, ROT/RUT, OSS...) never revealed the save bar. - i18n: the migrated hardcoded strings got keys in both locales (fiscal-period start date/range/months, security set-password trio); dates in ApiKeysPanel/OAuthClientsPanel/CalendarFeedSettings now pass the active locale to formatDateLong. - A11y: member remove/revoke buttons and the invite role select got correct accessible names; BankNameCombobox accepts aria-label wired from its row; the pinned-fact icon exposes role img. - BankIdSettings: explicit Avbryt under the QR block so a cancelled BankID flow cannot strand isLinking. - VoucherSeriesManager: clear the skeleton when no company is resolved. Verified end to end in sandbox: switch-only dirty bar, PUT /api/settings 200 for text and switch saves, persistence across hard reload. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
202 lines
6.0 KiB
TypeScript
202 lines
6.0 KiB
TypeScript
'use client'
|
|
|
|
import { useEffect, useRef, useState } from 'react'
|
|
import { Input } from '@/components/ui/input'
|
|
import { cn } from '@/lib/utils'
|
|
|
|
interface BankOption {
|
|
name: string
|
|
logo?: string
|
|
bic?: string
|
|
}
|
|
|
|
const FALLBACK_BANKS: BankOption[] = [
|
|
{ name: 'Nordea', bic: 'NDEASESS' },
|
|
{ name: 'SEB', bic: 'ESSESESS' },
|
|
{ name: 'Swedbank', bic: 'SWEDSESS' },
|
|
{ name: 'Handelsbanken', bic: 'HANDSESS' },
|
|
{ name: 'Danske Bank', bic: 'DABASES' },
|
|
{ name: 'Länsförsäkringar', bic: 'ELLFSESS' },
|
|
{ name: 'Skandiabanken', bic: 'SKIASESS' },
|
|
{ name: 'ICA Banken' },
|
|
{ name: 'Avanza Bank' },
|
|
{ name: 'Sparbanken' },
|
|
]
|
|
|
|
interface BankNameComboboxProps {
|
|
defaultValue?: string
|
|
value?: string
|
|
onChange?: (value: string) => void
|
|
enableBankingEnabled?: boolean
|
|
'aria-label'?: string
|
|
}
|
|
|
|
export function BankNameCombobox({ defaultValue = '', value: controlledValue, onChange, enableBankingEnabled = false, 'aria-label': ariaLabel }: BankNameComboboxProps) {
|
|
const isControlled = controlledValue !== undefined
|
|
const [internalValue, setInternalValue] = useState(defaultValue)
|
|
const value = isControlled ? controlledValue : internalValue
|
|
const setValue = (v: string) => {
|
|
if (!isControlled) setInternalValue(v)
|
|
onChange?.(v)
|
|
}
|
|
const [banks, setBanks] = useState<BankOption[]>(FALLBACK_BANKS)
|
|
const [isOpen, setIsOpen] = useState(false)
|
|
const [highlightedIndex, setHighlightedIndex] = useState(-1)
|
|
const containerRef = useRef<HTMLDivElement>(null)
|
|
const inputRef = useRef<HTMLInputElement>(null)
|
|
const listRef = useRef<HTMLUListElement>(null)
|
|
|
|
useEffect(() => {
|
|
if (!enableBankingEnabled) return
|
|
|
|
let cancelled = false
|
|
async function fetchBanks() {
|
|
try {
|
|
const res = await fetch('/api/extensions/ext/enable-banking/banks')
|
|
if (!res.ok) return
|
|
const data = await res.json()
|
|
if (!cancelled && data.banks?.length > 0) {
|
|
setBanks(data.banks)
|
|
}
|
|
} catch {
|
|
// Keep fallback list
|
|
}
|
|
}
|
|
fetchBanks()
|
|
return () => { cancelled = true }
|
|
}, [enableBankingEnabled])
|
|
|
|
const filtered = value.trim()
|
|
? banks.filter((b) => b.name.toLowerCase().includes(value.toLowerCase()))
|
|
: banks
|
|
|
|
useEffect(() => {
|
|
setHighlightedIndex(-1)
|
|
}, [value])
|
|
|
|
useEffect(() => {
|
|
if (!isOpen) return
|
|
function handleClickOutside(e: MouseEvent) {
|
|
if (containerRef.current && !containerRef.current.contains(e.target as Node)) {
|
|
setIsOpen(false)
|
|
}
|
|
}
|
|
document.addEventListener('mousedown', handleClickOutside)
|
|
return () => document.removeEventListener('mousedown', handleClickOutside)
|
|
}, [isOpen])
|
|
|
|
// Scroll highlighted item into view
|
|
useEffect(() => {
|
|
if (highlightedIndex < 0 || !listRef.current) return
|
|
const item = listRef.current.children[highlightedIndex] as HTMLElement
|
|
item?.scrollIntoView({ block: 'nearest' })
|
|
}, [highlightedIndex])
|
|
|
|
function selectBank(bank: BankOption) {
|
|
setValue(bank.name)
|
|
setIsOpen(false)
|
|
inputRef.current?.focus()
|
|
}
|
|
|
|
function handleKeyDown(e: React.KeyboardEvent) {
|
|
if (!isOpen && (e.key === 'ArrowDown' || e.key === 'ArrowUp')) {
|
|
setIsOpen(true)
|
|
e.preventDefault()
|
|
return
|
|
}
|
|
|
|
if (!isOpen) return
|
|
|
|
switch (e.key) {
|
|
case 'ArrowDown':
|
|
e.preventDefault()
|
|
setHighlightedIndex((i) => (i < filtered.length - 1 ? i + 1 : 0))
|
|
break
|
|
case 'ArrowUp':
|
|
e.preventDefault()
|
|
setHighlightedIndex((i) => (i > 0 ? i - 1 : filtered.length - 1))
|
|
break
|
|
case 'Enter':
|
|
e.preventDefault()
|
|
if (highlightedIndex >= 0 && filtered[highlightedIndex]) {
|
|
selectBank(filtered[highlightedIndex])
|
|
}
|
|
break
|
|
case 'Escape':
|
|
setIsOpen(false)
|
|
break
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div ref={containerRef} className="relative">
|
|
<input type="hidden" name="bank_name" value={value} />
|
|
<Input
|
|
aria-label={ariaLabel}
|
|
ref={inputRef}
|
|
type="text"
|
|
placeholder="t.ex. Nordea"
|
|
maxLength={100}
|
|
value={value}
|
|
onChange={(e) => {
|
|
setValue(e.target.value)
|
|
if (!isOpen) setIsOpen(true)
|
|
}}
|
|
onFocus={() => setIsOpen(true)}
|
|
onKeyDown={handleKeyDown}
|
|
role="combobox"
|
|
aria-expanded={isOpen}
|
|
aria-autocomplete="list"
|
|
aria-controls="bank-name-listbox"
|
|
autoComplete="off"
|
|
/>
|
|
{isOpen && filtered.length > 0 && (
|
|
<ul
|
|
ref={listRef}
|
|
id="bank-name-listbox"
|
|
role="listbox"
|
|
className="absolute z-50 mt-1 max-h-56 w-full overflow-auto rounded-md border border-border bg-popover shadow-md"
|
|
>
|
|
{filtered.map((bank, i) => (
|
|
<li
|
|
key={bank.name}
|
|
role="option"
|
|
aria-selected={highlightedIndex === i}
|
|
className={cn(
|
|
'flex items-center gap-2 px-3 py-2 text-sm cursor-pointer transition-colors',
|
|
highlightedIndex === i && 'bg-accent text-accent-foreground',
|
|
)}
|
|
onMouseEnter={() => setHighlightedIndex(i)}
|
|
onMouseDown={(e) => {
|
|
e.preventDefault() // prevent blur before click registers
|
|
selectBank(bank)
|
|
}}
|
|
>
|
|
{bank.logo ? (
|
|
<img
|
|
src={bank.logo}
|
|
alt=""
|
|
className="h-5 w-5 flex-shrink-0 rounded object-contain"
|
|
/>
|
|
) : (
|
|
<svg
|
|
className="h-5 w-5 flex-shrink-0 text-muted-foreground"
|
|
fill="none"
|
|
stroke="currentColor"
|
|
viewBox="0 0 24 24"
|
|
strokeWidth={1.5}
|
|
strokeLinecap="round"
|
|
strokeLinejoin="round"
|
|
>
|
|
<path d="M3 21h18M3 10h18M5 6l7-3 7 3M4 10v11M20 10v11M8 14v4M12 14v4M16 14v4" />
|
|
</svg>
|
|
)}
|
|
<span className="truncate">{bank.name}</span>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|