diff --git a/src/api/axios.ts b/src/api/axios.ts index 5bb7162..0e6a733 100644 --- a/src/api/axios.ts +++ b/src/api/axios.ts @@ -8,6 +8,7 @@ const api = axios.create({ api.interceptors.request.use((config) => { const token = localStorage.getItem("token"); + console.log("Attaching token to request:", token); config.headers = config.headers || {}; diff --git a/src/components/ChartArtifact.tsx b/src/components/ChartArtifact.tsx index 01b7832..857c97f 100644 --- a/src/components/ChartArtifact.tsx +++ b/src/components/ChartArtifact.tsx @@ -28,7 +28,10 @@ import { FileText, ImageIcon, RefreshCcw, - Sparkles, + Sparkles, + CheckCircle2, + BarChart3, + Database, } from "lucide-react"; import ErrorBoundary from "@/components/ErrorBoundary"; @@ -785,40 +788,55 @@ function VegaLiteArtifact({
{/* TOP TABS */} -
- +
+ - + - -
+ +
{/* EXPORT BUTTONS */} -
+ {/*
-
+
*/}
diff --git a/src/components/ChatCanvas.tsx b/src/components/ChatCanvas.tsx index 1b08742..0272776 100644 --- a/src/components/ChatCanvas.tsx +++ b/src/components/ChatCanvas.tsx @@ -13,6 +13,7 @@ type ChatMessage = { role: "user" | "assistant"; content: unknown; error?: boolean; + clarification?: boolean; }; function createId() { @@ -34,11 +35,11 @@ function createMessage(role: ChatMessage["role"], content: unknown): ChatMessage export default function ChatCanvas() { const [input, setInput] = useState(""); const [messages, setMessages] = useState([]); - // const [selectedHistoryId, setSelectedHistoryId] = useState(null); const [error, setError] = useState(""); const [isSending, setIsSending] = useState(false); const [showHistory, setShowHistory] = useState(true); const [historyQuestions, setHistoryQuestions] = useState([]); + const [showProfileMenu, setShowProfileMenu] = useState(false); const bottomRef = useRef(null); @@ -52,28 +53,101 @@ export default function ChatCanvas() { loadHistory(); }, []); + + + + // const loadHistory = async () => { + // try { + // const token = localStorage.getItem("token"); + + // const res = await api.get("/fetchUserHistory", { + // headers: { + // Authorization: `Bearer ${token}`, + // }, + // }); + + // console.log("History Response =>", res.data); + + // if (res.data.success) { + // setHistoryQuestions(res.data.data); + // } + // } catch (err) { + // console.error("History Error =>", err); + // } + // }; + const loadHistory = async () => { try { - const res = await api.get("/suggestions"); + const res = await api.get("/fetchUserHistory"); + + console.log("History Response =>", res.data); if (res.data.success) { - setHistoryQuestions(res.data.questions); + setHistoryQuestions(res.data.data); } } catch (err) { - console.error(err); + console.error("History Error =>", err); } }; - // const history = messages.filter((message) => message.role === "user"); + // const handleHistoryClick = async (item: any) => { + // try { + // const token = localStorage.getItem("token"); - // const handleSelectHistory = (message: ChatMessage) => { - // if (typeof message.content === "string") { - // setInput(message.content); - // setSelectedHistoryId(message.id); - // setError(""); + // const response = await api.post( + // "/fetchHistory", + // { + // response_id: item.response_id, + // }, + // { + // headers: { + // Authorization: `Bearer ${token}`, + // "Content-Type": "application/json", + // }, + // } + // ); + + // console.log("History Detail =>", response.data); + + // if (response.data.success) { + // const historyData = response.data.data; + + // setMessages([ + // createMessage("user", historyData.prompt), + // createMessage("assistant", historyData), + // ]); + // } + // } catch (err) { + // console.error("Fetch History Error", err); // } // }; + + const handleHistoryClick = async (item: any) => { + try { + const response = await api.post( + "/fetchHistory", + { + response_id: item.response_id, + } + ); + + console.log("History Detail =>", response.data); + + if (response.data.success) { + const historyData = response.data.data; + + setMessages([ + createMessage("user", historyData.prompt), + createMessage("assistant", historyData), + ]); + } + } catch (err) { + console.error("Fetch History Error", err); + } + }; + + const onSubmit = async (event: React.FormEvent) => { event.preventDefault(); @@ -96,10 +170,29 @@ export default function ChatCanvas() { JSON.stringify(response.data, null, 2) ); - setMessages((current) => [ - ...current, - createMessage("assistant", response.data), - ]); + // setMessages((current) => [ + // ...current, + // createMessage("assistant", response.data), + // ]); + + if (response.data.type === "clarification") { + setMessages((current) => [ + ...current, + { + id: createId(), + role: "assistant", + clarification: true, + content: response.data.message, + }, + ]); + } else { + setMessages((current) => [ + ...current, + createMessage("assistant", response.data), + ]); + } + + } catch (err) { console.error(err); @@ -146,140 +239,260 @@ export default function ChatCanvas() { }; return ( - //
-
- {/*
-
-
-

GenBI

-

- Chat workspace -

-
- - -
-
*/} +
{/*
*/} -
+
-
-

GenBI

-

- Chat workspace -

-
- -
-
- -
- {/* */} - - + ☰ + + +

+ Yoda +

+
{/*
*/}
- {showHistory && ( + + )} + + Yoda Workspace + + + + {/* Arrow */} + + + + + + {/* Dropdown */} + {showProfileMenu && ( +
+ +
+ )} + + + + )}
{messages.length === 0 ? (

- Welcome to GenBI + Welcome to Yoda

@@ -288,10 +501,9 @@ export default function ChatCanvas() {

{[ - "Show sales by region", - "Compare revenue by month", - "Top 10 products", - "Customer growth trends", + "What was the total stock availability across different store types last month?", + "what is the OSA percentage for the month of march 2026?", + "Which products had the highest OSA percentage in March 2026?", ].map((item) => ( + ))} +
+
+ +

Ask GenBI

@@ -422,22 +681,29 @@ export default function ChatCanvas() {
-
-

+

+ */} + + {/* RIGHT PANEL */} +
+ + {/*
*/}
diff --git a/src/pages/Login.tsx b/src/pages/Login.tsx index 004610b..a4132f7 100644 --- a/src/pages/Login.tsx +++ b/src/pages/Login.tsx @@ -47,6 +47,10 @@ export default function Login() { }; const login = async () => { + console.log("Attempting login with:", { + username, + password: password ? "******" : "", + }); if (!validate()) return; setIsLoading(true); @@ -57,8 +61,7 @@ export default function Login() { password, }); - const response = await api.post( - "/loginUser", + const response = await api.post("/loginUser", body, { headers: { @@ -68,6 +71,8 @@ export default function Login() { } ); + console.log("Response:", response.data); + if ( !response.data.success || !response.data.token @@ -85,7 +90,8 @@ export default function Login() { ); window.location.href = "/dashboard"; - } catch (err) { + } + catch (err) { console.error(err); if (isAxiosError(err)) {