Skip to content

Commit aaa0b06

Browse files
committed
admin auth
1 parent eabb4f1 commit aaa0b06

File tree

3 files changed

+54
-27
lines changed

3 files changed

+54
-27
lines changed

src/Pages/Admin/AdminPage.jsx

+9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
import React, { useState, useEffect } from "react";
22
import "./AdminPage.css";
33
import axios from "axios";
4+
import { useNavigate } from "react-router-dom";
45

56
const AdminPage = () => {
67
const [faqs, setFaqs] = useState([])
8+
const navigate = useNavigate()
79

810
useEffect(()=>{
11+
const loginStatus = localStorage.getItem("adminID");
12+
if(loginStatus == null){
13+
navigate("/login")
14+
}
15+
916
axios.get("http://localhost:3000/admin/faq/all-waiting").then(res=>{
1017
if(res.data.success){
1118
setFaqs(res.data.data)
@@ -23,6 +30,8 @@ const AdminPage = () => {
2330
const handleLogout = () => {
2431
// Implement your logout logic here
2532
console.log("Logout clicked");
33+
localStorage.removeItem('adminID')
34+
navigate("/login")
2635
};
2736

2837
// Placeholder data for User Queries

src/Pages/User/chatbot.jsx

+30-23
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import TypingAnimation from "../../components/TypingAnimation";
1616
const [botRepliesCounter, setBotRepliesCounter] = useState(0);
1717
const [executiveOptionDisplay, setExecutiveOptionDisplay] = useState(false)
1818
const [loading, setLoading] = useState(false);
19+
const [convoClosed, setConvoClosed] = useState(false);
1920

2021
const chatboxRef = useRef(null);
2122
const chatInputRef = useRef(null);
@@ -53,6 +54,9 @@ import TypingAnimation from "../../components/TypingAnimation";
5354
setConvoIDOfficial(convoID)
5455
}
5556
})
57+
socket.on("convo-ended", ()=>{
58+
setConvoClosed(true)
59+
})
5660
socket.on("response-generation-error", (error)=>{
5761
alert(error)
5862
})
@@ -151,7 +155,7 @@ import TypingAnimation from "../../components/TypingAnimation";
151155
<div className="xyz">
152156
{showChatbot? (
153157
<div className="switch-text" style={{color:"black"}}>
154-
{executiveOptionDisplay ? (<p >Not satisfied with the bot? <span onClick={HanldeSwtichToExecutive} style={{textDecoration:"underline", cursor:"pointer"}}>click here to switch to an actual executive</span></p>): <></>}
158+
{executiveOptionDisplay && handler === "bot" ? (<p >Not satisfied with the bot? <span onClick={HanldeSwtichToExecutive} style={{textDecoration:"underline", cursor:"pointer"}}>click here to switch to an actual executive</span></p>): <></>}
155159
</div>
156160
): (
157161
<div className="switch-text">
@@ -190,32 +194,35 @@ import TypingAnimation from "../../components/TypingAnimation";
190194
<p>{chat.message}</p>
191195
</li>
192196
))}
197+
{handler !== "bot" ? <li style={{listStyle: "none", fontSize:"smaller", margin: "20px 0", textAlign:'center', opacity: "0.7"}}>Interacting with the Executive!</li> : <></>}
193198
</ul>
194199
{/* <TypingAnimation /> */}
195200

196201
<div className="chat_input">
197-
{/* <div> */}
198-
{loading ? <TypingAnimation /> :
199-
<>
200-
<textarea
201-
placeholder="Type your message..."
202-
spellCheck="false"
203-
required
204-
value={userMessage}
205-
onChange={handleInputChange}
206-
onKeyDown={handleKeyDown}
207-
ref={chatInputRef}
208-
/>
209-
<span
210-
id="send-btn"
211-
className="material-symbols-rounded"
212-
onClick={handleChat}
213-
>
214-
<svg viewBox="0 0 24 24" height="24" width="24" preserveAspectRatio="xMidYMid meet" class="" version="1.1" x="0px" y="0px" enable-background="new 0 0 24 24"><title>send</title><path fill="currentColor" d="M1.101,21.757L23.8,12.028L1.101,2.3l0.011,7.912l13.623,1.816L1.112,13.845 L1.101,21.757z"></path></svg>
215-
</span>
216-
</>
217-
}
218-
{/* </div> */}
202+
{!convoClosed ? loading ? <TypingAnimation /> :
203+
<>
204+
<textarea
205+
placeholder="Type your message..."
206+
spellCheck="false"
207+
required
208+
value={userMessage}
209+
onChange={handleInputChange}
210+
onKeyDown={handleKeyDown}
211+
ref={chatInputRef}
212+
/>
213+
<span
214+
id="send-btn"
215+
className="material-symbols-rounded"
216+
onClick={handleChat}
217+
>
218+
<svg viewBox="0 0 24 24" height="24" width="24" preserveAspectRatio="xMidYMid meet" class="" version="1.1" x="0px" y="0px" enable-background="new 0 0 24 24"><title>send</title><path fill="currentColor" d="M1.101,21.757L23.8,12.028L1.101,2.3l0.011,7.912l13.623,1.816L1.112,13.845 L1.101,21.757z"></path></svg>
219+
</span>
220+
</>
221+
:
222+
<div style={{height:"40px", display: "flex", justifyContent:"center", alignItems:"center", width:"inherit"}}>
223+
<p>conversation is closed</p>
224+
</div>
225+
}
219226
</div>
220227

221228

src/Pages/login/Loginexecutive.jsx

+15-4
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,24 @@ const Loginexecutive = () => {
1616

1717
const popup =(e) =>{
1818
e.preventDefault()
19-
20-
axios.post("http://localhost:3000/executive/login", {executiveID:userName, password:userPass}).then((res)=> {
19+
let URL = "http://localhost:3000/executive/login"
20+
let payload = {executiveID:userName, password:userPass}
21+
if(userName.includes("admin")) {
22+
payload = {...payload, adminID: userName}
23+
URL = "http://localhost:3000/admin/login"
24+
}
25+
axios.post(URL, payload).then((res)=> {
2126
if(res.data.success)
2227
{
2328
onSuccess(e)
24-
localStorage.setItem("executiveID",res.data.data.executiveID)
25-
naviagte("/executive")
29+
if(userName.includes("admin")){
30+
localStorage.setItem("adminID",res.data.data.adminID)
31+
naviagte("/admin")
32+
33+
}else{
34+
localStorage.setItem("executiveID",res.data.data.executiveID)
35+
naviagte("/executive")
36+
}
2637

2738
}
2839

0 commit comments

Comments
 (0)