'use client'; import { useState } from 'react'; import { Company } from '../../lib/types'; import { Session } from 'next-auth'; interface DashboardSettingsProps { company: Company; session: Session; } export default function DashboardSettings({ company, session, }: DashboardSettingsProps) { const [csvUrl, setCsvUrl] = useState(company.csvUrl); const [csvUsername, setCsvUsername] = useState( company.csvUsername || '' ); const [csvPassword, setCsvPassword] = useState(''); const [sentimentThreshold, setSentimentThreshold] = useState( company.sentimentAlert?.toString() || '' ); const [message, setMessage] = useState(''); async function handleSave() { const res = await fetch('/api/dashboard/settings', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ csvUrl, csvUsername, csvPassword, sentimentThreshold, }), }); if (res.ok) setMessage('Settings saved!'); else setMessage('Failed.'); } if (session.user.role !== 'admin') return null; return (

Company Config

setCsvUrl(e.target.value)} /> setCsvUsername(e.target.value)} /> setCsvPassword(e.target.value)} /> setSentimentThreshold(e.target.value)} />
{message}
); }