diff --git a/app/(dashboard)/transactions/page.tsx b/app/(dashboard)/transactions/page.tsx index 1b68176d..1745bd14 100644 --- a/app/(dashboard)/transactions/page.tsx +++ b/app/(dashboard)/transactions/page.tsx @@ -488,7 +488,7 @@ export default function TransactionsPage() { amount: data.amount, currency: data.currency, category: data.category || 'uncategorized', - is_business: data.is_business, + is_business: null, notes: data.notes, }) .select() diff --git a/components/settings/ApiKeysPanel.tsx b/components/settings/ApiKeysPanel.tsx index e95e74ce..f8b98c03 100644 --- a/components/settings/ApiKeysPanel.tsx +++ b/components/settings/ApiKeysPanel.tsx @@ -5,6 +5,7 @@ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/com import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' +import { Badge } from '@/components/ui/badge' import { Dialog, DialogContent, @@ -14,8 +15,9 @@ import { DialogTitle, } from '@/components/ui/dialog' import { Checkbox } from '@/components/ui/checkbox' +import { DestructiveConfirmDialog, useDestructiveConfirm } from '@/components/ui/destructive-confirm-dialog' import { useToast } from '@/components/ui/use-toast' -import { Loader2, Plus, Copy, Check, Trash2, Key } from 'lucide-react' +import { Loader2, Plus, Copy, Check, Trash2, Key, ChevronDown } from 'lucide-react' const SCOPE_GROUPS = [ { @@ -104,19 +106,55 @@ interface ApiKey { created_at: string } +function CopyBlock({ text }: { text: string }) { + const [copied, setCopied] = useState(false) + + async function handleCopy() { + try { + await navigator.clipboard.writeText(text) + setCopied(true) + setTimeout(() => setCopied(false), 2000) + } catch { + // clipboard unavailable (insecure context) — silently ignore + } + } + + return ( +
+
+        {text}
+      
+ +
+ ) +} + export function ApiKeysPanel() { const { toast } = useToast() + const { dialogProps: revokeDialogProps, confirm: confirmRevoke } = useDestructiveConfirm() const [keys, setKeys] = useState([]) const [isLoading, setIsLoading] = useState(true) const [isCreating, setIsCreating] = useState(false) const [showCreateDialog, setShowCreateDialog] = useState(false) const [showKeyDialog, setShowKeyDialog] = useState(false) + const [showApiKeyMethods, setShowApiKeyMethods] = useState(false) const [newKeyName, setNewKeyName] = useState('') const [newKeyScopes, setNewKeyScopes] = useState>(new Set(ALL_SCOPES)) const [newKeyValue, setNewKeyValue] = useState('') const [copied, setCopied] = useState(false) - const [revokingId, setRevokingId] = useState(null) const fetchKeys = useCallback(async () => { try { @@ -164,16 +202,20 @@ export function ApiKeysPanel() { } } - async function handleRevoke(id: string) { - setRevokingId(id) + async function handleRevoke(id: string, name: string) { + const ok = await confirmRevoke({ + title: 'Återkalla API-nyckel', + description: `"${name}" återkallas permanent. Alla klienter som använder nyckeln slutar fungera omedelbart.`, + confirmLabel: 'Återkalla', + }) + if (!ok) return + try { await fetch(`/api/settings/api-keys/${id}`, { method: 'DELETE' }) setKeys((prev) => prev.filter((k) => k.id !== id)) toast({ title: 'Nyckel återkallad' }) } catch { toast({ title: 'Fel', description: 'Kunde inte återkalla nyckel', variant: 'destructive' }) - } finally { - setRevokingId(null) } } @@ -232,59 +274,50 @@ export function ApiKeysPanel() { ) : (
- {keys.map((key) => ( -
-
-
-

{key.name}

-
- {(key.scopes ?? []).map((s) => ( - - {SCOPE_LABELS[s as Scope] ?? s} - - ))} - {(!key.scopes || key.scopes.length === 0) && ( - - Enbart läs - - )} + {keys.map((key) => { + const scopeCount = key.scopes?.length ?? 0 + return ( +
+
+
+

{key.name}

+ + {scopeCount === ALL_SCOPES.length + ? 'Alla behörigheter' + : scopeCount === 0 + ? 'Inga behörigheter' + : `${scopeCount} behörigheter`} + +
+
+ + {key.key_prefix}... + + + Skapad {formatDate(key.created_at)} + + + {key.last_used_at + ? `Använd ${formatDate(key.last_used_at)}` + : 'Aldrig använd'} +
-
- - {key.key_prefix}... - - - Skapad {formatDate(key.created_at)} - - - {key.last_used_at - ? `Använd ${formatDate(key.last_used_at)}` - : 'Aldrig använd'} - -
-
- -
- ))} + +
+ ) + })}
)} @@ -296,12 +329,42 @@ export function ApiKeysPanel() {
-

Claude Desktop

+
+

Claude.ai

+ Rekommenderat +

- Lägg till i claude_desktop_config.json (Inställningar → Developer): + Gå till Settings → Integrations → Add Integration och klistra in MCP-serverns URL. + Du loggas in via ditt gnubok-konto — ingen API-nyckel behövs.

-
-{`{
+            
+          
+ +
+

Claude Code / Cursor

+

+ Kör i terminalen — loggar in via webbläsaren: +

+ +
+ +
+ + {showApiKeyMethods && ( +
+
+

Claude Desktop

+

+ Lägg till i claude_desktop_config.json (Inställningar → Developer): +

+ -
+}`} /> +
-
-

Claude Code / Cursor

-

- Kör i terminalen med en API-nyckel: -

-
-{`claude mcp add gnubok --transport http \\
+                
+

Claude Code / Cursor

+

+ Kör i terminalen med en API-nyckel: +

+ + --header "Authorization: Bearer gnubok_sk_..."`} /> +
+
+ )}
@@ -419,6 +482,8 @@ export function ApiKeysPanel() { + + {/* Show key once dialog */} { if (!open) { diff --git a/components/transactions/TransactionForm.tsx b/components/transactions/TransactionForm.tsx index 7dfd065b..e4912330 100644 --- a/components/transactions/TransactionForm.tsx +++ b/components/transactions/TransactionForm.tsx @@ -78,15 +78,13 @@ export default function TransactionForm({ onSubmit, isLoading }: TransactionForm const isIncome = categories.find((c) => c.value === watchCategory)?.isIncome const onFormSubmit = (data: FormData) => { - const isBusiness = data.category ? data.category !== 'private' : undefined - onSubmit({ date: data.date, description: data.description, amount: data.amount, currency: data.currency, category: data.category as TransactionCategory, - is_business: isBusiness, + is_business: undefined, notes: data.notes, }) } diff --git a/components/transactions/TransactionHistoryList.tsx b/components/transactions/TransactionHistoryList.tsx index ea52f7d0..121dd5ce 100644 --- a/components/transactions/TransactionHistoryList.tsx +++ b/components/transactions/TransactionHistoryList.tsx @@ -138,7 +138,7 @@ export default function TransactionHistoryList({ Bokförd - ) : transaction.is_business === null ? ( + ) : ( <> ·
- {transaction.is_business === null && !transaction.journal_entry_id && ( + {!transaction.journal_entry_id && (