import { ChevronDown, Clock3, FileEdit, Inbox, ListChecks, LogOut, Mail, Menu, Plug, Send, Settings, ShieldAlert, Sparkles, Star, Trash2, X, } from "lucide-react"; import { useCallback, useEffect, useState } from "react"; import { getCurrentAccount, getMyCompanyDomain } from "../api"; import Brand from "./Brand"; import CompanyDnsSetup from "./CompanyDnsSetup"; import ComposeModal from "./ComposeModal"; import MailboxView from "./MailboxView"; const mailItems = [ [Inbox, "Inbox", "unread"], [Star, "Starred", "starred"], [Clock3, "Snoozed"], [Send, "Sent"], [FileEdit, "Drafts", "drafts"], [ShieldAlert, "Spam"], [Trash2, "Trash"], [Clock3, "Scheduled"], ]; const labels = [ ["Important", "rose", "Important"], ["Projects", "violet", "Projects"], ["Clients", "blue", "Clients"], ["Finance", "amber", "Finance"], ["Personal", "green", "Personal"], ]; const agentItems = [ [Sparkles, "Ask Agent", "ask"], [ListChecks, "Action Items", "actions"], [Sparkles, "Summaries", "summaries"], [Plug, "Integrations", "integrations"], ]; function clearSession() { sessionStorage.removeItem("agmail_access_token"); sessionStorage.removeItem("agmail_account"); } function SidebarSection({ title, children, className = "" }) { return (

{title}

{children}
); } function NavBadge({ value, variant = "coral" }) { if (!value || value <= 0) return null; return {value}; } export default function DashboardPage() { const [account, setAccount] = useState(null); const [companyDomain, setCompanyDomain] = useState(null); const [needsDnsSetup, setNeedsDnsSetup] = useState(false); const [domainError, setDomainError] = useState(""); const [active, setActive] = useState("Inbox"); const [menuOpen, setMenuOpen] = useState(false); const [composeOpen, setComposeOpen] = useState(false); const [notice, setNotice] = useState(""); const [loading, setLoading] = useState(true); const [mailRefreshKey, setMailRefreshKey] = useState(0); const [lens, setLens] = useState("all"); const [agentNav, setAgentNav] = useState(null); const [labelsExpanded, setLabelsExpanded] = useState(false); const [mailStats, setMailStats] = useState({ unread: 0, starred: 0, important: 0, drafts: 0, actionItems: 0, labels: {}, }); const handleStats = useCallback((stats) => setMailStats(stats), []); useEffect(() => { const token = sessionStorage.getItem("agmail_access_token"); if (!token) { window.location.replace("/login"); return; } getCurrentAccount(token) .then(async (currentAccount) => { sessionStorage.setItem("agmail_account", JSON.stringify(currentAccount)); setAccount(currentAccount); if (currentAccount.account_type === "company") { try { const domain = await getMyCompanyDomain(token); setCompanyDomain(domain); setNeedsDnsSetup(domain.status === "pending_dns"); } catch (error) { setDomainError(error.message || "Could not load your company domain."); } } setLoading(false); }) .catch(() => { clearSession(); window.location.replace("/login"); }); }, []); function logout() { clearSession(); window.location.assign("/login"); } function selectMailItem(item) { setAgentNav(null); if (item === "Starred") { setActive("Inbox"); setLens("starred"); } else if (item === "Sent") { setActive("Outbox"); setLens("all"); } else { setActive(item); setLens("all"); } setMenuOpen(false); } function selectLabel(name) { setAgentNav(null); setActive("Inbox"); setLens(name); setMenuOpen(false); } function selectAgentItem(item, actionKey) { setActive("Inbox"); setLens("all"); setAgentNav(actionKey); setMenuOpen(false); } function emailSent() { setComposeOpen(false); setActive("Outbox"); setMailRefreshKey((key) => key + 1); setNotice("Message accepted by the mail server. Delivery can take a few minutes — check spam if it does not arrive."); window.setTimeout(() => setNotice(""), 4000); } if (loading || !account) { return
Opening your workspace…
; } if (account.account_type === "company" && domainError) { return (

Company setup

Domain not ready

{domainError}

); } if (needsDnsSetup && companyDomain) { return ( { setCompanyDomain({ ...companyDomain, status: "active" }); setNeedsDnsSetup(false); }} onLogout={logout} /> ); } const workspaceLabel = account.account_type === "company" ? "Company" : "Individual"; const workspaceTitle = account.account_type === "company" && companyDomain ? companyDomain.domain_name : "Personal workspace"; const mailActive = lens === "starred" ? "Starred" : active === "Outbox" ? "Sent" : labels.some(([name]) => lens === name) ? "Inbox" : active; return (
{menuOpen &&
{account.first_name[0]}{account.last_name[0]}
{account.first_name} {account.last_name}{account.email}
{!["Inbox", "Outbox", "Trash"].includes(active) && (

{workspaceTitle}

{active}

{workspaceLabel}
)} {active === "Inbox" && ( selectMailItem("Settings")} onStats={handleStats} /> )} {active === "Outbox" && ( selectMailItem("Settings")} /> )} {active === "Trash" && ( selectMailItem("Settings")} /> )} {!["Inbox", "Outbox", "Trash"].includes(active) && (

{active} is ready for you

Your personal mail and agent tools will appear here.

)}
{notice &&
{notice}
} {composeOpen && setComposeOpen(false)} onSent={emailSent} />} ); }