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>
222 lines
7.7 KiB
TypeScript
222 lines
7.7 KiB
TypeScript
'use client'
|
|
|
|
import { useLocale, useTranslations } from 'next-intl'
|
|
import { useState, useEffect, useCallback } from 'react'
|
|
import { Button } from '@/components/ui/button'
|
|
import { Input } from '@/components/ui/input'
|
|
import { Label } from '@/components/ui/label'
|
|
import {
|
|
Dialog,
|
|
DialogContent,
|
|
DialogDescription,
|
|
DialogFooter,
|
|
DialogHeader,
|
|
DialogTitle,
|
|
} from '@/components/ui/dialog'
|
|
import { DestructiveConfirmDialog, useDestructiveConfirm } from '@/components/ui/destructive-confirm-dialog'
|
|
import { EmptyState } from '@/components/ui/empty-state'
|
|
import { HelpPopover } from '@/components/ui/help-popover'
|
|
import { useToast } from '@/components/ui/use-toast'
|
|
import { SettingsGroup } from '@/components/settings/SettingsRows'
|
|
import { formatDateLong } from '@/lib/utils'
|
|
import { Loader2, Plus, Trash2, Globe } from 'lucide-react'
|
|
|
|
interface OAuthClient {
|
|
id: string
|
|
client_name: string
|
|
redirect_uri: string
|
|
created_at: string
|
|
revoked_at: string | null
|
|
}
|
|
|
|
export function OAuthClientsPanel() {
|
|
const t = useTranslations('settings_oauth_clients')
|
|
const locale = useLocale()
|
|
const { toast } = useToast()
|
|
const { dialogProps: revokeDialogProps, confirm: confirmRevoke } = useDestructiveConfirm()
|
|
|
|
const [clients, setClients] = useState<OAuthClient[]>([])
|
|
const [isLoading, setIsLoading] = useState(true)
|
|
const [isCreating, setIsCreating] = useState(false)
|
|
const [showCreateDialog, setShowCreateDialog] = useState(false)
|
|
const [clientName, setClientName] = useState('')
|
|
const [redirectUri, setRedirectUri] = useState('')
|
|
|
|
const fetchClients = useCallback(async () => {
|
|
try {
|
|
const res = await fetch('/api/settings/oauth-clients')
|
|
const json = await res.json()
|
|
if (json.data) {
|
|
setClients(json.data.filter((c: OAuthClient) => !c.revoked_at))
|
|
}
|
|
} catch {
|
|
toast({ title: t('toast_fetch_failed'), variant: 'destructive' })
|
|
} finally {
|
|
setIsLoading(false)
|
|
}
|
|
}, [toast, t])
|
|
|
|
useEffect(() => {
|
|
fetchClients()
|
|
}, [fetchClients])
|
|
|
|
async function handleCreate() {
|
|
setIsCreating(true)
|
|
try {
|
|
const res = await fetch('/api/settings/oauth-clients', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({
|
|
client_name: clientName.trim() || t('default_client_name'),
|
|
redirect_uri: redirectUri.trim(),
|
|
}),
|
|
})
|
|
const json = await res.json()
|
|
|
|
if (!res.ok) {
|
|
toast({ title: json.error ?? t('toast_register_failed'), variant: 'destructive' })
|
|
return
|
|
}
|
|
|
|
setShowCreateDialog(false)
|
|
setClientName('')
|
|
setRedirectUri('')
|
|
fetchClients()
|
|
} catch {
|
|
toast({ title: t('toast_register_failed'), variant: 'destructive' })
|
|
} finally {
|
|
setIsCreating(false)
|
|
}
|
|
}
|
|
|
|
async function handleRevoke(id: string, name: string) {
|
|
const ok = await confirmRevoke({
|
|
title: t('revoke_dialog_title'),
|
|
description: t('revoke_dialog_description', { name }),
|
|
confirmLabel: t('revoke_confirm'),
|
|
})
|
|
if (!ok) return
|
|
|
|
try {
|
|
const res = await fetch(`/api/settings/oauth-clients/${id}`, { method: 'DELETE' })
|
|
if (!res.ok) {
|
|
const body = await res.json().catch(() => ({}))
|
|
toast({
|
|
title: body?.error || t('toast_revoke_failed'),
|
|
variant: 'destructive',
|
|
})
|
|
return
|
|
}
|
|
setClients((prev) => prev.filter((c) => c.id !== id))
|
|
toast({ title: t('toast_revoked') })
|
|
} catch {
|
|
toast({ title: t('toast_revoke_failed'), variant: 'destructive' })
|
|
}
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<SettingsGroup>
|
|
{/* Group eyebrow with the group's primary action on the right. Styling
|
|
mirrors SettingsGroup's label line; the "?" holds the old panel
|
|
description. */}
|
|
<div className="flex items-center justify-between gap-4 px-1">
|
|
<p className="flex items-center gap-2 text-[11px] font-medium uppercase tracking-wider text-muted-foreground">
|
|
<span>{t('title')}</span>
|
|
<HelpPopover className="shrink-0">{t('description')}</HelpPopover>
|
|
</p>
|
|
<Button size="sm" onClick={() => setShowCreateDialog(true)}>
|
|
<Plus className="mr-1.5 h-3.5 w-3.5" />
|
|
{t('register_uri')}
|
|
</Button>
|
|
</div>
|
|
|
|
{isLoading ? (
|
|
<div className="flex items-center justify-center py-8">
|
|
<Loader2 className="h-5 w-5 animate-spin text-muted-foreground" />
|
|
</div>
|
|
) : clients.length === 0 ? (
|
|
<EmptyState
|
|
icon={Globe}
|
|
title={t('empty_title')}
|
|
description={t('empty_help')}
|
|
/>
|
|
) : (
|
|
clients.map((c) => (
|
|
<div
|
|
key={c.id}
|
|
className="flex items-center gap-3 border-b border-border px-1 py-3"
|
|
>
|
|
<div className="flex min-w-0 flex-1 flex-wrap items-baseline gap-x-3 gap-y-1">
|
|
<span className="truncate text-sm">{c.client_name}</span>
|
|
<code className="min-w-0 truncate font-mono text-xs text-muted-foreground">
|
|
{c.redirect_uri}
|
|
</code>
|
|
<span className="shrink-0 text-xs tabular-nums text-muted-foreground">
|
|
{t('registered_on')} {formatDateLong(c.created_at, locale)}
|
|
</span>
|
|
</div>
|
|
<Button
|
|
variant="ghost"
|
|
size="icon"
|
|
className="h-8 w-8 shrink-0 text-muted-foreground hover:text-destructive"
|
|
onClick={() => handleRevoke(c.id, c.client_name)}
|
|
aria-label={t('revoke_aria', { name: c.client_name })}
|
|
>
|
|
<Trash2 className="h-3.5 w-3.5" />
|
|
</Button>
|
|
</div>
|
|
))
|
|
)}
|
|
</SettingsGroup>
|
|
|
|
<Dialog open={showCreateDialog} onOpenChange={setShowCreateDialog}>
|
|
<DialogContent>
|
|
<DialogHeader>
|
|
<DialogTitle>{t('register_dialog_title')}</DialogTitle>
|
|
<DialogDescription>
|
|
{t.rich('register_dialog_description', {
|
|
bold: (chunks) => <span className="font-medium">{chunks}</span>,
|
|
code: (chunks) => <code className="rounded bg-muted px-1 py-0.5 font-mono text-[11px]">{chunks}</code>,
|
|
})}
|
|
</DialogDescription>
|
|
</DialogHeader>
|
|
<div className="space-y-4">
|
|
<div className="space-y-2">
|
|
<Label htmlFor="client-name">{t('client_name_label')}</Label>
|
|
<Input
|
|
id="client-name"
|
|
placeholder={t('client_name_placeholder')}
|
|
value={clientName}
|
|
onChange={(e) => setClientName(e.target.value)}
|
|
/>
|
|
</div>
|
|
<div className="space-y-2">
|
|
<Label htmlFor="redirect-uri">{t('redirect_uri_label')}</Label>
|
|
<Input
|
|
id="redirect-uri"
|
|
type="url"
|
|
placeholder="https://min-agent.exempel.se/oauth/callback"
|
|
value={redirectUri}
|
|
onChange={(e) => setRedirectUri(e.target.value)}
|
|
onKeyDown={(e) => e.key === 'Enter' && redirectUri && handleCreate()}
|
|
/>
|
|
</div>
|
|
</div>
|
|
<DialogFooter>
|
|
<Button variant="outline" onClick={() => setShowCreateDialog(false)}>
|
|
{t('cancel')}
|
|
</Button>
|
|
<Button onClick={handleCreate} disabled={isCreating || !redirectUri.trim()}>
|
|
{isCreating && <Loader2 className="mr-1.5 h-3.5 w-3.5 animate-spin" />}
|
|
{t('register')}
|
|
</Button>
|
|
</DialogFooter>
|
|
</DialogContent>
|
|
</Dialog>
|
|
|
|
<DestructiveConfirmDialog {...revokeDialogProps} />
|
|
</>
|
|
)
|
|
}
|