|
|
|
@@ -5,9 +5,8 @@ import { useSearchParams, useRouter } from 'next/navigation'
|
|
|
|
|
import { Button } from '@/components/ui/button'
|
|
|
|
|
import { Input } from '@/components/ui/input'
|
|
|
|
|
import { Tabs, TabsList, TabsTrigger, TabsContent } from '@/components/ui/tabs'
|
|
|
|
|
import { User, Mail, Server, Cloud, CloudCog, Shield, Bell, Bot, KeyRound, PlugZap, FolderSync, CalendarDays, BookUser, ArrowLeft, Check, X, AlertTriangle } from 'lucide-react'
|
|
|
|
|
import { User, Mail, Server, CloudCog, Shield, Bell, Bot, KeyRound, PlugZap, FolderSync, CalendarDays, BookUser, ArrowLeft, Check, X, AlertTriangle } from 'lucide-react'
|
|
|
|
|
import { toast } from 'sonner'
|
|
|
|
|
import { invalidateReference } from '@/lib/reference-data'
|
|
|
|
|
import { NotificationsSettings } from '@/components/notifications-settings'
|
|
|
|
|
import { ProfileSettings } from '@/components/profile-settings'
|
|
|
|
|
import { AiSettings } from '@/components/ai-settings'
|
|
|
|
@@ -36,7 +35,6 @@ const NAV_GROUPS = [
|
|
|
|
|
{ value: 'webdav', label: 'WebDAV', icon: FolderSync },
|
|
|
|
|
{ value: 'caldav', label: 'CalDAV', icon: CalendarDays },
|
|
|
|
|
{ value: 'carddav', label: 'CardDAV', icon: BookUser },
|
|
|
|
|
{ value: 'nextcloud', label: 'Contacts sync', icon: Cloud },
|
|
|
|
|
{ value: 'imap', label: 'IMAP', icon: Mail },
|
|
|
|
|
] },
|
|
|
|
|
{ label: 'AI & Automation', items: [
|
|
|
|
@@ -57,15 +55,23 @@ export function SettingsClient({ oidc, callbackUrl }: { oidc: OidcStatus; callba
|
|
|
|
|
const router = useRouter()
|
|
|
|
|
// Automations moved out of Settings to its own workspace; legacy deep
|
|
|
|
|
// links (?tab=automations) redirect there instead of falling back to profile.
|
|
|
|
|
useEffect(() => { if (requestedTab === 'automations') router.replace('/automations') }, [requestedTab, router])
|
|
|
|
|
const initialSection = NAV_GROUPS.some(g => g.items.some(i => i.value === requestedTab))
|
|
|
|
|
? requestedTab
|
|
|
|
|
// The Contacts sync tab was removed — its legacy ?tab=nextcloud deep link
|
|
|
|
|
// lands on the unified Nextcloud tab (the sync API itself remains).
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (requestedTab === 'automations') router.replace('/automations')
|
|
|
|
|
if (requestedTab === 'nextcloud') router.replace('/settings?tab=nextcloud-connect')
|
|
|
|
|
}, [requestedTab, router])
|
|
|
|
|
// The Contacts sync tab was removed — its legacy ?tab=nextcloud deep link
|
|
|
|
|
// lands on the unified Nextcloud tab (the sync API itself remains). Map the
|
|
|
|
|
// legacy value BEFORE deriving the initial section so the tab is selected
|
|
|
|
|
// on first render; the effect above only cleans the URL.
|
|
|
|
|
const mappedTab = requestedTab === 'nextcloud' ? 'nextcloud-connect' : requestedTab
|
|
|
|
|
const initialSection = NAV_GROUPS.some(g => g.items.some(i => i.value === mappedTab))
|
|
|
|
|
? mappedTab
|
|
|
|
|
: 'profile'
|
|
|
|
|
const [imapConfig, setImapConfig] = useState({ host: '', port: 993, tls: true, username: '', password: '', folder: 'INBOX' })
|
|
|
|
|
const [ncConfig, setNcConfig] = useState({ nextcloudUrl: '', cardDavPath: '', username: '', password: '' })
|
|
|
|
|
const [savingImap, setSavingImap] = useState(false)
|
|
|
|
|
const [testingImap, setTestingImap] = useState(false)
|
|
|
|
|
const [syncingContacts, setSyncingContacts] = useState(false)
|
|
|
|
|
const [section, setSection] = useState(initialSection)
|
|
|
|
|
// Below md the grouped nav becomes a list -> detail flow (same
|
|
|
|
|
// master-detail pattern as collections/tags/contacts); at md+ the
|
|
|
|
@@ -113,32 +119,6 @@ export function SettingsClient({ oidc, callbackUrl }: { oidc: OidcStatus; callba
|
|
|
|
|
finally { setTestingImap(false) }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const syncContacts = async () => {
|
|
|
|
|
if (!ncConfig.nextcloudUrl || !ncConfig.username || !ncConfig.password) {
|
|
|
|
|
toast.error('Fill in Nextcloud URL, username, and password')
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
setSyncingContacts(true)
|
|
|
|
|
try {
|
|
|
|
|
const res = await fetch('/api/contacts/sync', {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: { 'Content-Type': 'application/json' },
|
|
|
|
|
body: JSON.stringify(ncConfig),
|
|
|
|
|
})
|
|
|
|
|
const data = await res.json().catch(() => null)
|
|
|
|
|
if (res.ok && data?.synced !== undefined) {
|
|
|
|
|
// Review CR-07: the sync mirrors the address book — remotely deleted
|
|
|
|
|
// contacts are removed too (scoped to this source, never from partial
|
|
|
|
|
// responses). Surface both counts so the policy is visible.
|
|
|
|
|
const removed = typeof data.removed === 'number' && data.removed > 0 ? `, removed ${data.removed} deleted on the server` : ''
|
|
|
|
|
toast.success(`Synced ${data.synced} contacts${removed}`)
|
|
|
|
|
invalidateReference('contacts')
|
|
|
|
|
}
|
|
|
|
|
else toast.error(data?.error ?? 'Sync failed')
|
|
|
|
|
} catch { toast.error('Sync failed') }
|
|
|
|
|
finally { setSyncingContacts(false) }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="max-w-5xl space-y-6">
|
|
|
|
|
<div>
|
|
|
|
@@ -223,30 +203,6 @@ export function SettingsClient({ oidc, callbackUrl }: { oidc: OidcStatus; callba
|
|
|
|
|
</TabsContent>
|
|
|
|
|
<TabsContent value="carddav" className="mt-0 space-y-4">
|
|
|
|
|
<CardDavSettings />
|
|
|
|
|
</TabsContent>
|
|
|
|
|
<TabsContent value="nextcloud" className="mt-0 space-y-4">
|
|
|
|
|
<div className="rounded-lg border p-4 space-y-3">
|
|
|
|
|
<h3 className="font-medium flex items-center gap-2"><Cloud className="h-4 w-4" /> Contacts sync (Nextcloud)</h3>
|
|
|
|
|
<div className="grid grid-cols-2 gap-3">
|
|
|
|
|
<div className="col-span-2">
|
|
|
|
|
<label className="text-xs font-medium text-muted-foreground">Nextcloud URL</label>
|
|
|
|
|
<Input value={ncConfig.nextcloudUrl} onChange={(e: React.ChangeEvent<HTMLInputElement>) => setNcConfig(p => ({ ...p, nextcloudUrl: e.target.value }))} placeholder="https://nextcloud.example.com" />
|
|
|
|
|
</div>
|
|
|
|
|
<div className="col-span-2">
|
|
|
|
|
<label className="text-xs font-medium text-muted-foreground">CardDAV Path (optional)</label>
|
|
|
|
|
<Input value={ncConfig.cardDavPath} onChange={(e: React.ChangeEvent<HTMLInputElement>) => setNcConfig(p => ({ ...p, cardDavPath: e.target.value }))} placeholder="/remote.php/dav/addressbooks/users/USER/contacts/" />
|
|
|
|
|
</div>
|
|
|
|
|
<div>
|
|
|
|
|
<label className="text-xs font-medium text-muted-foreground">Username</label>
|
|
|
|
|
<Input value={ncConfig.username} onChange={(e: React.ChangeEvent<HTMLInputElement>) => setNcConfig(p => ({ ...p, username: e.target.value }))} />
|
|
|
|
|
</div>
|
|
|
|
|
<div>
|
|
|
|
|
<label className="text-xs font-medium text-muted-foreground">App Password</label>
|
|
|
|
|
<Input type="password" value={ncConfig.password} onChange={(e: React.ChangeEvent<HTMLInputElement>) => setNcConfig(p => ({ ...p, password: e.target.value }))} />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<Button onClick={syncContacts} loading={syncingContacts}>Sync Contacts Now</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</TabsContent>
|
|
|
|
|
<TabsContent value="imap" className="mt-0 space-y-4">
|
|
|
|
|
<div className="rounded-lg border p-4 space-y-3">
|
|
|
|
|