feat: add document bucket auto-creation, extension defaults, and chat widget on dashboard

Auto-create documents storage bucket on first upload. Default legacy general
extensions to enabled when no toggle row exists. Add ChatWidget to dashboard
root page with open-ai-chat event support and AI assistant quick action.
Add ensureInitialized to supplier invoices route for event emission.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Emil
2026-02-23 13:00:16 +01:00
co-authored by Claude Opus 4.6
parent 263c229903
commit ce66a21010
8 changed files with 86 additions and 7 deletions
+10 -4
View File
@@ -10,7 +10,6 @@ export function ChatWidget() {
const [isOpen, setIsOpen] = useState(false)
// Default to true for legacy compatibility (ai-chat defaults to enabled)
const [enabled, setEnabled] = useState(true)
const [loaded, setLoaded] = useState(false)
// Fetch initial toggle state
useEffect(() => {
@@ -22,8 +21,8 @@ export function ChatWidget() {
// Legacy: enabled by default when no toggle row exists
setEnabled(data?.enabled ?? true)
}
} finally {
setLoaded(true)
} catch {
// Keep default (enabled) on fetch failure
}
}
check()
@@ -42,7 +41,14 @@ export function ChatWidget() {
return () => window.removeEventListener('extension-toggle-changed', handler)
}, [])
if (!loaded || !enabled) return null
// Allow other components to open the chat via custom event
useEffect(() => {
const handler = () => setIsOpen(true)
window.addEventListener('open-ai-chat', handler)
return () => window.removeEventListener('open-ai-chat', handler)
}, [])
if (!enabled) return null
return (
<>
+15
View File
@@ -27,6 +27,7 @@ import {
Landmark,
CheckCircle2,
ClipboardList,
MessageCircle,
} from 'lucide-react'
import type { CompanySettings, EntityType, Deadline, ReceiptQueueSummary, OnboardingProgress } from '@/types'
@@ -179,6 +180,8 @@ export default function DashboardContent({ firstName, settings, summary, onboard
const visibleAlerts = showAllAlerts ? alertItems : alertItems.slice(0, MAX_VISIBLE_ALERTS)
const hasMoreAlerts = alertItems.length > MAX_VISIBLE_ALERTS
const openAiChat = () => window.dispatchEvent(new Event('open-ai-chat'))
// Quick action items
const quickActions = [
{ href: '/invoices/new', icon: Receipt, label: 'Ny faktura', desc: 'Skapa och skicka', accent: true },
@@ -400,6 +403,18 @@ export default function DashboardContent({ firstName, settings, summary, onboard
</Link>
)
})}
{/* AI assistant quick action */}
<button onClick={openAiChat} className="group text-left">
<div className="flex items-center gap-3 px-4 py-3 rounded-xl border border-border/40 hover:bg-muted/30 transition-colors duration-150">
<div className="p-2 rounded-lg bg-muted/50">
<MessageCircle className="h-4 w-4 text-muted-foreground" />
</div>
<div className="min-w-0">
<p className="text-sm font-medium truncate">AI-assistent</p>
<p className="text-xs text-muted-foreground truncate hidden md:block">Fråga om bokföring</p>
</div>
</div>
</button>
</div>
</section>