Files

27 lines
820 B
TypeScript
Raw Permalink Normal View History

2026-09-14 11:54:20 +08:00
"use client";
import { usePathname } from "next/navigation";
import { useEffect, useState } from "react";
import { apiFetch } from "@/lib/api";
import { AgentChat } from "@/components/agent-chat";
2026-09-14 19:00:48 +08:00
import { isAdvisor } from "@/lib/roles";
import type { UserPayload } from "@/types/api";
2026-09-14 11:54:20 +08:00
export function AgentMount() {
const pathname = usePathname();
const [employee, setEmployee] = useState(false);
useEffect(() => {
if (!pathname.startsWith("/admin")) return;
2026-09-14 19:00:48 +08:00
void apiFetch<{ user: UserPayload }>("/auth/me")
2026-09-14 11:54:20 +08:00
.then(({ user }) => {
2026-09-14 19:00:48 +08:00
setEmployee(isAdvisor(user));
2026-09-14 11:54:20 +08:00
})
.catch(() => setEmployee(false));
}, [pathname]);
if (pathname.startsWith("/admin") && employee) return <AgentChat employeeMode />;
if (pathname.startsWith("/admin")) return null;
return <AgentChat />;
}