refactor: remove extension toggle system — compiled-in extensions are always active (#59)
The runtime toggle system (extension_toggles table, API routes, hooks, UI components) added unnecessary complexity. Extensions controlled via extensions.config.json at build time are now always active for all users. This removes ~835 lines of toggle-related code including API routes, DB queries, the ExtensionToggleButton component, useEnabledExtensions and useExtensionToggle hooks, and the toggle-check module. AI consent gating remains unchanged. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
38b658205d
commit
cf77adaa0a
@@ -5,41 +5,12 @@ import { Button } from '@/components/ui/button'
|
||||
import { ChatPanel } from './ChatPanel'
|
||||
import { MessageCircle, X } from 'lucide-react'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { ENABLED_EXTENSION_IDS } from '@/lib/extensions/_generated/enabled-extensions'
|
||||
|
||||
const chatEnabled = ENABLED_EXTENSION_IDS.has('ai-chat')
|
||||
|
||||
export function ChatWidget() {
|
||||
const [isOpen, setIsOpen] = useState(false)
|
||||
// Default to true for legacy compatibility (ai-chat defaults to enabled)
|
||||
const [enabled, setEnabled] = useState(true)
|
||||
|
||||
// Fetch initial toggle state
|
||||
useEffect(() => {
|
||||
const check = async () => {
|
||||
try {
|
||||
const res = await fetch('/api/extensions/toggles/general/ai-chat')
|
||||
if (res.ok) {
|
||||
const { data } = await res.json()
|
||||
// Legacy: enabled by default when no toggle row exists
|
||||
setEnabled(data?.enabled ?? true)
|
||||
}
|
||||
} catch {
|
||||
// Keep default (enabled) on fetch failure
|
||||
}
|
||||
}
|
||||
check()
|
||||
}, [])
|
||||
|
||||
// Listen for real-time toggle changes
|
||||
useEffect(() => {
|
||||
const handler = (e: Event) => {
|
||||
const { sectorSlug, extensionSlug, enabled: newValue } = (e as CustomEvent).detail
|
||||
if (sectorSlug === 'general' && extensionSlug === 'ai-chat') {
|
||||
setEnabled(newValue)
|
||||
if (!newValue) setIsOpen(false)
|
||||
}
|
||||
}
|
||||
window.addEventListener('extension-toggle-changed', handler)
|
||||
return () => window.removeEventListener('extension-toggle-changed', handler)
|
||||
}, [])
|
||||
|
||||
// Allow other components to open the chat via custom event
|
||||
useEffect(() => {
|
||||
@@ -48,7 +19,7 @@ export function ChatWidget() {
|
||||
return () => window.removeEventListener('open-ai-chat', handler)
|
||||
}, [])
|
||||
|
||||
if (!enabled) return null
|
||||
if (!chatEnabled) return null
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -19,7 +19,7 @@ import {
|
||||
FileWarning,
|
||||
Clock,
|
||||
} from 'lucide-react'
|
||||
import { getExtensionDefinition } from '@/lib/extensions/sectors'
|
||||
import { getAllExtensions } from '@/lib/extensions/sectors'
|
||||
import { resolveIcon } from '@/lib/extensions/icon-resolver'
|
||||
import type { QuickActionDefinition } from '@/lib/extensions/types'
|
||||
import type { CompanySettings, Deadline, ReceiptQueueSummary, OnboardingProgress } from '@/types'
|
||||
@@ -47,31 +47,11 @@ interface DashboardContentProps {
|
||||
staleUncategorizedCount: number
|
||||
}
|
||||
onboardingProgress?: OnboardingProgress
|
||||
enabledExtensions?: { sector_slug: string; extension_slug: string }[]
|
||||
}
|
||||
|
||||
export default function DashboardContent({ firstName, settings, summary, onboardingProgress, enabledExtensions }: DashboardContentProps) {
|
||||
export default function DashboardContent({ firstName, settings, summary, onboardingProgress }: DashboardContentProps) {
|
||||
const [showAllAlerts, setShowAllAlerts] = useState(false)
|
||||
const [showMore, setShowMore] = useState(false)
|
||||
const [liveExtensions, setLiveExtensions] = useState(enabledExtensions ?? [])
|
||||
|
||||
useEffect(() => {
|
||||
setLiveExtensions(enabledExtensions ?? [])
|
||||
}, [enabledExtensions])
|
||||
|
||||
useEffect(() => {
|
||||
const handler = ((e: CustomEvent<{ sector_slug: string; extension_slug: string; enabled: boolean }>) => {
|
||||
setLiveExtensions(prev => {
|
||||
if (e.detail.enabled) {
|
||||
if (prev.some(x => x.sector_slug === e.detail.sector_slug && x.extension_slug === e.detail.extension_slug)) return prev
|
||||
return [...prev, { sector_slug: e.detail.sector_slug, extension_slug: e.detail.extension_slug }]
|
||||
}
|
||||
return prev.filter(x => !(x.sector_slug === e.detail.sector_slug && x.extension_slug === e.detail.extension_slug))
|
||||
})
|
||||
}) as EventListener
|
||||
window.addEventListener('extension-toggle-changed', handler)
|
||||
return () => window.removeEventListener('extension-toggle-changed', handler)
|
||||
}, [])
|
||||
|
||||
// Setup gate — blocks dashboard until user imports data or chooses fresh start
|
||||
const needsSetup = onboardingProgress && !onboardingProgress.hasBankConnected && !onboardingProgress.hasSIEImport
|
||||
@@ -256,14 +236,10 @@ 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
|
||||
|
||||
// Build extension quick actions from enabled extensions
|
||||
const extensionQuickActions: (QuickActionDefinition & { key: string })[] = liveExtensions
|
||||
.map(toggle => {
|
||||
const def = getExtensionDefinition(toggle.sector_slug, toggle.extension_slug)
|
||||
if (!def?.quickAction) return null
|
||||
return { ...def.quickAction, key: `${toggle.sector_slug}/${toggle.extension_slug}` }
|
||||
})
|
||||
.filter((a): a is QuickActionDefinition & { key: string } => a !== null)
|
||||
// Build extension quick actions from all compiled extensions
|
||||
const extensionQuickActions: (QuickActionDefinition & { key: string })[] = getAllExtensions()
|
||||
.filter(def => def.quickAction)
|
||||
.map(def => ({ ...def.quickAction!, key: `${def.sector}/${def.slug}` }))
|
||||
.sort((a, b) => (a.order ?? 0) - (b.order ?? 0))
|
||||
|
||||
// Quick action items
|
||||
|
||||
@@ -1,43 +1,34 @@
|
||||
'use client'
|
||||
|
||||
import { Card, CardContent } from '@/components/ui/card'
|
||||
import { resolveIcon } from '@/lib/extensions/icon-resolver'
|
||||
import type { ExtensionDefinition } from '@/lib/extensions/types'
|
||||
import CategoryBadge from './CategoryBadge'
|
||||
import ExtensionToggleButton from './ExtensionToggleButton'
|
||||
import Link from 'next/link'
|
||||
|
||||
export default function ExtensionCard({ extension }: { extension: ExtensionDefinition }) {
|
||||
|
||||
|
||||
const Icon = resolveIcon(extension.icon)
|
||||
|
||||
return (
|
||||
<Card className="group relative">
|
||||
<CardContent className="pt-6">
|
||||
<div className="flex items-start justify-between gap-3">
|
||||
<div className="flex items-start gap-3 min-w-0">
|
||||
<div className="flex h-10 w-10 items-center justify-center rounded-lg bg-primary/10 flex-shrink-0">
|
||||
<Icon className="h-5 w-5 text-primary" />
|
||||
</div>
|
||||
<div className="min-w-0">
|
||||
<Link
|
||||
href={`/extensions/${extension.sector}/${extension.slug}`}
|
||||
className="text-sm font-medium hover:underline"
|
||||
>
|
||||
{extension.name}
|
||||
</Link>
|
||||
<p className="text-xs text-muted-foreground mt-0.5 line-clamp-2">
|
||||
{extension.description}
|
||||
</p>
|
||||
<div className="mt-2">
|
||||
<CategoryBadge category={extension.category} />
|
||||
</div>
|
||||
<div className="flex items-start gap-3 min-w-0">
|
||||
<div className="flex h-10 w-10 items-center justify-center rounded-lg bg-primary/10 flex-shrink-0">
|
||||
<Icon className="h-5 w-5 text-primary" />
|
||||
</div>
|
||||
<div className="min-w-0">
|
||||
<Link
|
||||
href={`/extensions/${extension.sector}/${extension.slug}`}
|
||||
className="text-sm font-medium hover:underline"
|
||||
>
|
||||
{extension.name}
|
||||
</Link>
|
||||
<p className="text-xs text-muted-foreground mt-0.5 line-clamp-2">
|
||||
{extension.description}
|
||||
</p>
|
||||
<div className="mt-2">
|
||||
<CategoryBadge category={extension.category} />
|
||||
</div>
|
||||
</div>
|
||||
<ExtensionToggleButton
|
||||
sectorSlug={extension.sector}
|
||||
extensionSlug={extension.slug}
|
||||
/>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
'use client'
|
||||
|
||||
import { useState } from 'react'
|
||||
import { Switch } from '@/components/ui/switch'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog'
|
||||
import { useExtensionToggle } from '@/lib/extensions/hooks'
|
||||
|
||||
export default function ExtensionToggleButton({
|
||||
sectorSlug,
|
||||
extensionSlug,
|
||||
subscriptionNotice,
|
||||
}: {
|
||||
sectorSlug: string
|
||||
extensionSlug: string
|
||||
subscriptionNotice?: string
|
||||
}) {
|
||||
const { enabled, isLoading, toggle } = useExtensionToggle(sectorSlug, extensionSlug)
|
||||
const [showConfirm, setShowConfirm] = useState(false)
|
||||
|
||||
function handleToggle() {
|
||||
// Show confirmation dialog when enabling an extension with a subscription notice
|
||||
if (!enabled && subscriptionNotice) {
|
||||
setShowConfirm(true)
|
||||
return
|
||||
}
|
||||
toggle()
|
||||
}
|
||||
|
||||
function handleConfirm() {
|
||||
setShowConfirm(false)
|
||||
toggle()
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Switch
|
||||
checked={enabled}
|
||||
onCheckedChange={handleToggle}
|
||||
disabled={isLoading}
|
||||
aria-label={enabled ? 'Inaktivera tillägg' : 'Aktivera tillägg'}
|
||||
/>
|
||||
|
||||
{subscriptionNotice && (
|
||||
<Dialog open={showConfirm} onOpenChange={setShowConfirm}>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>Extern prenumeration krävs</DialogTitle>
|
||||
<DialogDescription>{subscriptionNotice}</DialogDescription>
|
||||
</DialogHeader>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={() => setShowConfirm(false)}>
|
||||
Avbryt
|
||||
</Button>
|
||||
<Button onClick={handleConfirm}>
|
||||
Jag förstår, aktivera
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user