diff --git a/src/ChatBot.js b/src/ChatBot.js
index 287f445..af6524a 100644
--- a/src/ChatBot.js
+++ b/src/ChatBot.js
@@ -55,7 +55,7 @@
try {
// Send to backend
- const response = await fetch('https://bot.kediritechnopark.com/webhook/master-agent/ask', {
+ const response = await fetch('https://bot.kediritechnopark.com/webhook/master-agent/ask/dev', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ pertanyaan: message, sessionId: JSON.parse(localStorage.getItem('session')).sessionId, lastSeen: new Date().toISOString() }),
diff --git a/src/Dashboard.js b/src/Dashboard.js
index 1a55a2b..af49d28 100644
--- a/src/Dashboard.js
+++ b/src/Dashboard.js
@@ -1,5 +1,6 @@
import React, { useRef, useState, useEffect } from 'react';
import styles from './Dashboard.module.css';
+import { useNavigate } from 'react-router-dom';
import Modal from './Modal';
import Conversations from './Conversations';
@@ -21,21 +22,32 @@ const Dashboard = () => {
botMessages: 0,
});
-
const [isDragging, setIsDragging] = useState(false);
const [selectedFile, setSelectedFile] = useState(null);
+ const [isLoggedIn, setIsLoggedIn] = useState(false);
+
const handleFile = (file) => {
if (file) {
setSelectedFile(file);
}
};
+ useEffect(() => {
+ const token = localStorage.getItem('token');
+ setIsLoggedIn(!!token);
+ }, []);
+
+ const handleLogout = () => {
+ localStorage.removeItem('token');
+ localStorage.removeItem('user');
+ window.location.reload(); // Bisa juga: window.location.href = '/login';
+ };
useEffect(() => {
async function fetchStats() {
try {
- const response = await fetch('https://bot.kediritechnopark.com/webhook/master-agent/dashboard');
+ const response = await fetch('https://bot.kediritechnopark.com/webhook/master-agent/dashboard/dev');
const data = await response.json();
setDiscussedTopics(data[0]?.result?.topics)
@@ -59,7 +71,6 @@ const Dashboard = () => {
});
});
-
setStats({
totalChats: totalSessions.size,
userMessages,
@@ -74,6 +85,45 @@ const Dashboard = () => {
fetchStats();
}, []);
+const navigate = useNavigate();
+
+ useEffect(() => {
+ const fetchData = async () => {
+ const token = localStorage.getItem('token');
+
+ try {
+ const response = await fetch('https://bot.kediritechnopark.com/webhook/profile/dev', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': `Bearer ${token}`,
+ },
+ });
+
+ if (response.status === 401 || response.status === 403) {
+ // Token tidak valid atau tidak punya akses, redirect ke login
+ localStorage.removeItem('token'); // Hapus token agar bersih
+ navigate('/login');
+ return;
+ }
+
+ if (!response.ok) {
+ throw new Error('Fetch gagal dengan status: ' + response.status);
+ }
+
+ const data = await response.json();
+ console.log(data);
+ // lanjutkan penggunaan data
+ } catch (error) {
+ console.error('Error:', error);
+ // Bisa juga redirect ke login kalau error tertentu
+ navigate('/login');
+ }
+ };
+
+ fetchData();
+ }, [navigate]);
+
const openConversationsModal = () => {
setModalContent(