27 lines
820 B
TypeScript
27 lines
820 B
TypeScript
"use client";
|
|
|
|
import { usePathname } from "next/navigation";
|
|
import { useEffect, useState } from "react";
|
|
import { apiFetch } from "@/lib/api";
|
|
import { AgentChat } from "@/components/agent-chat";
|
|
import { isAdvisor } from "@/lib/roles";
|
|
import type { UserPayload } from "@/types/api";
|
|
|
|
export function AgentMount() {
|
|
const pathname = usePathname();
|
|
const [employee, setEmployee] = useState(false);
|
|
|
|
useEffect(() => {
|
|
if (!pathname.startsWith("/admin")) return;
|
|
void apiFetch<{ user: UserPayload }>("/auth/me")
|
|
.then(({ user }) => {
|
|
setEmployee(isAdvisor(user));
|
|
})
|
|
.catch(() => setEmployee(false));
|
|
}, [pathname]);
|
|
|
|
if (pathname.startsWith("/admin") && employee) return <AgentChat employeeMode />;
|
|
if (pathname.startsWith("/admin")) return null;
|
|
return <AgentChat />;
|
|
}
|