"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

{ e.preventDefault(); handleSave(); }} > setCsvUrl(e.target.value)} autoComplete="url" /> setCsvUsername(e.target.value)} autoComplete="username" /> setCsvPassword(e.target.value)} autoComplete="new-password" /> setSentimentThreshold(e.target.value)} />
{message}
); }