Files
accounted/components/settings/BankIdSettings.tsx
T
Jakob Wennberg b800dcd403 style(ui): system-wide UX/UI polish pass — design-system conformance + copy cleanup (#835)
* style(ui): system-wide UX/UI polish pass — design-system conformance + copy cleanup

Multi-agent scan of all 404 UI files against the locked design system, then
141 verified surgical fixes across 109 files (net -32 lines):

- Remove forbidden elevation/motion: shadow-* and rounded-xl on cards, active:scale
  bounce, hover:shadow on list items, transition-all -> transition-colors.
- Drop font-medium from single-weight Hedvig display headings/numerals.
- Replace raw rainbow Tailwind status colors with Badge variants / brand tokens /
  neutral surfaces (achromatic chrome, semantic colors stay data-only).
- Route raw dates through formatDate(), hand-rolled currency through formatCurrency(),
  add tabular-nums to financial figures; text-gray-* -> text-foreground tokens.
- Swap hand-rolled skeletons for the Skeleton primitive; off-scale spacing -> token scale.
- Fix copy: mislabeled "Leverantörsfakturor" -> "Utgifter" on bank-import outflow total,
  collapse no-op identical-branch ternaries, broken Swedish diacritics (mojibake),
  correct mismatch-password toast, correct supplier currency-field label.
- Remove PII-leaking debug console.log on register, stray console.logs.

Verified: tsc clean on all changed files, eslint clean, production build passes.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(auth): sanitize residual error logs in register flow

Follow-up to PR review (compliance swarm V16 / GDPR Art.5(1)(f)): the
remaining console.error calls in the register flow passed raw error
objects, which Supabase may populate with PII (email) in nested fields.
Log only sanitized message strings instead.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-30 13:14:13 +02:00

151 lines
4.5 KiB
TypeScript

'use client'
import { useTranslations } from 'next-intl'
import { useState, useEffect, useCallback } from 'react'
import { createClient } from '@/lib/supabase/client'
import { BankIdAuth } from '@/components/auth/BankIdAuth'
import type { BankIdResult } from '@/components/auth/BankIdAuth'
import { Button } from '@/components/ui/button'
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
import { Shield, ShieldCheck, Loader2 } from 'lucide-react'
import { useToast } from '@/components/ui/use-toast'
import { formatDateLong } from '@/lib/utils'
interface BankIdIdentity {
given_name: string | null
surname: string | null
linked_at: string
}
export function BankIdSettings() {
const t = useTranslations('settings_bankid')
const [identity, setIdentity] = useState<BankIdIdentity | null>(null)
const [isLoading, setIsLoading] = useState(true)
const [isLinking, setIsLinking] = useState(false)
const [isUnlinking, setIsUnlinking] = useState(false)
const { toast } = useToast()
const fetchIdentity = useCallback(async () => {
const supabase = createClient()
const { data: { user } } = await supabase.auth.getUser()
if (!user) { setIsLoading(false); return }
const { data } = await supabase
.from('bankid_identities')
.select('given_name, surname, linked_at')
.eq('user_id', user.id)
.maybeSingle()
setIdentity(data)
setIsLoading(false)
}, [])
useEffect(() => {
fetchIdentity()
}, [fetchIdentity])
const handleLinkComplete = async (result: BankIdResult) => {
if (result.error) {
const message = result.error === 'already_linked'
? t('toast_already_linked')
: t('toast_link_failed')
toast({ title: message, variant: 'destructive' })
setIsLinking(false)
return
}
toast({ title: t('toast_linked') })
setIsLinking(false)
fetchIdentity()
}
const handleUnlink = async () => {
if (!confirm(t('confirm_unlink'))) return
setIsUnlinking(true)
try {
const res = await fetch('/api/extensions/ext/tic/bankid/unlink', { method: 'POST' })
if (!res.ok) throw new Error('Unlink failed')
setIdentity(null)
toast({ title: t('toast_unlinked') })
} catch {
toast({ title: t('toast_unlink_failed'), variant: 'destructive' })
} finally {
setIsUnlinking(false)
}
}
if (isLoading) {
return (
<Card>
<CardContent className="flex items-center justify-center py-8">
<Loader2 className="h-5 w-5 animate-spin text-muted-foreground" />
</CardContent>
</Card>
)
}
if (isLinking) {
return (
<Card>
<CardHeader>
<CardTitle className="text-base">{t('link_bankid_title')}</CardTitle>
<CardDescription>{t('link_bankid_description')}</CardDescription>
</CardHeader>
<CardContent className="flex flex-col items-center">
<BankIdAuth mode="link" onComplete={handleLinkComplete} />
</CardContent>
</Card>
)
}
return (
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2 text-base">
{identity ? (
<ShieldCheck className="h-4 w-4 text-success" />
) : (
<Shield className="h-4 w-4 text-muted-foreground" />
)}
{t('title')}
</CardTitle>
<CardDescription>
{identity ? t('linked_description') : t('not_linked_description')}
</CardDescription>
</CardHeader>
<CardContent>
{identity ? (
<div className="flex items-center justify-between">
<div className="text-sm text-muted-foreground">
<span className="font-medium text-foreground">
{identity.given_name} {identity.surname}
</span>
<span className="ml-2">
{t('linked_on', { date: formatDateLong(identity.linked_at) })}
</span>
</div>
<Button
variant="ghost"
size="sm"
onClick={handleUnlink}
disabled={isUnlinking}
className="text-destructive hover:text-destructive"
>
{isUnlinking ? t('unlinking') : t('unlink_button')}
</Button>
</div>
) : (
<Button
variant="outline"
onClick={() => setIsLinking(true)}
>
{t('link_button')}
</Button>
)}
</CardContent>
</Card>
)
}