* feat: event log, pending operations, and MCP staging - Event log system: persist bus events to event_log table for external automation platforms. Batch insert for transaction.synced. Daily cleanup cron at 02:00 UTC. - Pending operations: MCP write tools (categorize, create customer, create invoice) now stage to pending_operations instead of executing directly. Users review and commit/reject from /pending in the web UI. - Granskning page: card-based review UI with expandable previews, commit/reject dialogs. Only shown in nav when pending ops exist. - Commit route re-executes using core lib functions (no extension imports). Guards against stale state (double-commit, deleted entities). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * feat: stage new MCP write tools after main merge Add staging for 4 new write tools from #133: - mark_invoice_paid, send_invoice, mark_invoice_sent, match_transaction_invoice - Expand pending_operations CHECK constraint - Add commit executors with full execution logic - Add UI labels and generic preview component - Remove confirm parameter from categorize (single-call staging) - Fix UUID in pending op title (fetch transaction description) - Hide Granskning nav when no pending ops Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: address PR review feedback - Fix TS build error: use `select('*, customer:customers(*)')` for match_transaction_invoice to avoid array type inference - Add status guard to commitSendInvoice (prevents duplicate sends) - Replace auth.admin.getUserById with user email from session auth - Restore optimistic lock check in commitMatchTransactionInvoice - Fix tool description typo: expense_software → expense_office Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * feat: add support contact links and improve SIE import UX Add a SupportLink component with a contact dialog throughout the app (nav, help page, settings, MFA, error pages, empty states). Improve SIE import flow with phased loading states, structured skip breakdowns, and an elapsed-time counter. Fix MFA enroll stale factor cleanup and URL encoding for settings return path. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: address PR review — open redirect, XSS, test cleanup, fallback email - Validate returnTo is a relative path in MFA enroll (prevents open redirect) - Add afterEach import to event-log-handler tests (fixes handler leak) - HTML-escape user-supplied subject and message in support email body - Replace hardcoded personal email with support@gnubok.se fallback Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
222 lines
7.8 KiB
TypeScript
222 lines
7.8 KiB
TypeScript
'use client'
|
|
|
|
import { useState, useCallback, useEffect } from 'react'
|
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
|
import { Progress } from '@/components/ui/progress'
|
|
import { Upload, FileText, AlertCircle, CheckCircle, Loader2 } from 'lucide-react'
|
|
|
|
const LOADING_PHASES = [
|
|
{ message: 'Läser fil...', progress: 10 },
|
|
{ message: 'Identifierar teckenkodning...', progress: 30 },
|
|
{ message: 'Tolkar SIE-data...', progress: 55 },
|
|
{ message: 'Matchar konton mot BAS-kontoplanen...', progress: 85 },
|
|
] as const
|
|
|
|
interface SIEUploadStepProps {
|
|
onFileSelect: (file: File) => void
|
|
isLoading: boolean
|
|
error: string | null
|
|
}
|
|
|
|
export default function SIEUploadStep({ onFileSelect, isLoading, error }: SIEUploadStepProps) {
|
|
const [isDragging, setIsDragging] = useState(false)
|
|
const [selectedFile, setSelectedFile] = useState<File | null>(null)
|
|
const [loadingPhase, setLoadingPhase] = useState(0)
|
|
|
|
// Cycle through loading phases on timers
|
|
useEffect(() => {
|
|
if (!isLoading) {
|
|
setLoadingPhase(0)
|
|
return
|
|
}
|
|
|
|
const timers = [
|
|
setTimeout(() => setLoadingPhase(1), 2000),
|
|
setTimeout(() => setLoadingPhase(2), 4000),
|
|
setTimeout(() => setLoadingPhase(3), 7000),
|
|
]
|
|
|
|
return () => timers.forEach(clearTimeout)
|
|
}, [isLoading])
|
|
|
|
const handleDragOver = useCallback((e: React.DragEvent) => {
|
|
e.preventDefault()
|
|
setIsDragging(true)
|
|
}, [])
|
|
|
|
const handleDragLeave = useCallback((e: React.DragEvent) => {
|
|
e.preventDefault()
|
|
setIsDragging(false)
|
|
}, [])
|
|
|
|
const handleDrop = useCallback((e: React.DragEvent) => {
|
|
e.preventDefault()
|
|
setIsDragging(false)
|
|
|
|
const files = e.dataTransfer.files
|
|
if (files.length > 0) {
|
|
const file = files[0]
|
|
if (file.name.toLowerCase().endsWith('.sie') || file.name.toLowerCase().endsWith('.se')) {
|
|
setSelectedFile(file)
|
|
onFileSelect(file)
|
|
}
|
|
}
|
|
}, [onFileSelect])
|
|
|
|
const handleFileInput = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
|
|
const files = e.target.files
|
|
if (files && files.length > 0) {
|
|
setSelectedFile(files[0])
|
|
onFileSelect(files[0])
|
|
}
|
|
}, [onFileSelect])
|
|
|
|
const phase = LOADING_PHASES[loadingPhase]
|
|
|
|
// Full-card takeover while analyzing the file
|
|
if (isLoading && selectedFile) {
|
|
return (
|
|
<div className="space-y-6">
|
|
<Card>
|
|
<CardContent className="pt-8 pb-8">
|
|
<div className="flex flex-col items-center text-center space-y-6">
|
|
<Loader2 className="h-10 w-10 text-primary animate-spin" />
|
|
<div className="space-y-1">
|
|
<p className="font-medium text-lg">{phase.message}</p>
|
|
<p className="text-sm text-muted-foreground">
|
|
{selectedFile.name} ({(selectedFile.size / 1024).toFixed(1)} KB)
|
|
</p>
|
|
</div>
|
|
<Progress value={phase.progress} className="w-64 mx-auto transition-all duration-1000" />
|
|
<p className="text-xs text-muted-foreground">
|
|
Lämna inte sidan förrän analysen är klar
|
|
</p>
|
|
</div>
|
|
</CardContent>
|
|
</Card>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<div className="space-y-6">
|
|
<Card>
|
|
<CardHeader>
|
|
<CardTitle className="flex items-center gap-2">
|
|
<Upload className="h-5 w-5" />
|
|
Ladda upp SIE-fil
|
|
</CardTitle>
|
|
<CardDescription>
|
|
Exportera en SIE4-fil från ditt nuvarande bokföringssystem (Fortnox, Visma, etc.)
|
|
och ladda upp den här för att importera din bokföring.
|
|
</CardDescription>
|
|
</CardHeader>
|
|
<CardContent>
|
|
{/* Drop zone */}
|
|
<div
|
|
className={`
|
|
relative border-2 border-dashed rounded-lg p-8 text-center transition-colors cursor-pointer hover:border-primary/50
|
|
${isDragging ? 'border-primary bg-primary/5' : 'border-muted-foreground/25'}
|
|
${error ? 'border-destructive bg-destructive/5' : ''}
|
|
`}
|
|
onDragOver={handleDragOver}
|
|
onDragLeave={handleDragLeave}
|
|
onDrop={handleDrop}
|
|
onClick={() => document.getElementById('file-input')?.click()}
|
|
>
|
|
<input
|
|
id="file-input"
|
|
type="file"
|
|
accept=".sie,.se"
|
|
className="hidden"
|
|
onChange={handleFileInput}
|
|
disabled={isLoading}
|
|
/>
|
|
|
|
{selectedFile ? (
|
|
<div className="space-y-4">
|
|
<CheckCircle className="mx-auto h-12 w-12 text-success" />
|
|
<div>
|
|
<p className="font-medium">{selectedFile.name}</p>
|
|
<p className="text-sm text-muted-foreground">
|
|
{(selectedFile.size / 1024).toFixed(1)} KB
|
|
</p>
|
|
</div>
|
|
</div>
|
|
) : (
|
|
<div className="space-y-4">
|
|
<Upload className="mx-auto h-12 w-12 text-muted-foreground" />
|
|
<div>
|
|
<p className="font-medium hidden sm:block">Dra och släpp SIE-fil här</p>
|
|
<p className="font-medium sm:hidden">Tryck för att välja SIE-fil</p>
|
|
<p className="text-sm text-muted-foreground hidden sm:block">eller klicka för att välja fil</p>
|
|
<p className="text-sm text-muted-foreground sm:hidden">.sie eller .se-filer</p>
|
|
</div>
|
|
</div>
|
|
)}
|
|
</div>
|
|
|
|
{/* Error display */}
|
|
{error && (
|
|
<div className="mt-4 p-4 bg-destructive/10 border border-destructive/20 rounded-lg flex gap-3">
|
|
<AlertCircle className="h-5 w-5 text-destructive flex-shrink-0 mt-0.5" />
|
|
<div>
|
|
<p className="font-medium text-destructive">Kunde inte läsa filen</p>
|
|
<p className="text-sm text-muted-foreground">{error}</p>
|
|
</div>
|
|
</div>
|
|
)}
|
|
</CardContent>
|
|
</Card>
|
|
|
|
{/* Info cards */}
|
|
<div className="grid gap-4 md:grid-cols-2">
|
|
<Card>
|
|
<CardHeader>
|
|
<CardTitle className="text-base">Vad är SIE?</CardTitle>
|
|
</CardHeader>
|
|
<CardContent className="text-sm text-muted-foreground">
|
|
<p>
|
|
SIE (Standard Import Export) är det svenska standardformatet för att överföra
|
|
bokföringsdata mellan system. Det används av alla större bokföringsprogram i Sverige.
|
|
</p>
|
|
</CardContent>
|
|
</Card>
|
|
|
|
<Card>
|
|
<CardHeader>
|
|
<CardTitle className="text-base">Vilken SIE-typ?</CardTitle>
|
|
</CardHeader>
|
|
<CardContent className="text-sm text-muted-foreground">
|
|
<ul className="space-y-1">
|
|
<li><strong>SIE4</strong> - Full historik med alla verifikationer (rekommenderas)</li>
|
|
<li><strong>SIE1</strong> - Endast årssaldon (enklare import)</li>
|
|
</ul>
|
|
</CardContent>
|
|
</Card>
|
|
</div>
|
|
|
|
{/* Export instructions */}
|
|
<Card className="bg-muted/50">
|
|
<CardHeader>
|
|
<CardTitle className="text-base">Så exporterar du från...</CardTitle>
|
|
</CardHeader>
|
|
<CardContent className="text-sm space-y-3">
|
|
<div>
|
|
<p className="font-medium">Fortnox</p>
|
|
<p className="text-muted-foreground">Inställningar → Import/Export → Exportera SIE</p>
|
|
</div>
|
|
<div>
|
|
<p className="font-medium">Visma eEkonomi</p>
|
|
<p className="text-muted-foreground">Rapporter → Övrigt → Exportera till SIE</p>
|
|
</div>
|
|
<div>
|
|
<p className="font-medium">Bokio</p>
|
|
<p className="text-muted-foreground">Inställningar → Bokföring → Exportera SIE-fil</p>
|
|
</div>
|
|
</CardContent>
|
|
</Card>
|
|
</div>
|
|
)
|
|
}
|