@@ -20,6 +20,8 @@ export const Chatbot = () => {
2020 const [ sessions , setSessions ] = useState < ChatSession [ ] > ( loadChatbotSessions ) ;
2121 const [ currentSessionId , setCurrentSessionId ] = useState < string | null > ( loadChatbotLastSessionId ) ;
2222 const [ isSidebarOpen , setIsSidebarOpen ] = useState < boolean > ( false ) ;
23+ const [ isPopupOpen , setIsPopupOpen ] = useState < boolean > ( false ) ;
24+ const [ sessionIdToDelete , setSessionIdToDelete ] = useState < string | null > ( null ) ;
2325
2426 /**
2527 * Saving the chat sessions in the session storage only
@@ -62,18 +64,19 @@ export const Chatbot = () => {
6264 * Handles the delete process of a chat session.
6365 */
6466 const handleDeleteChat = async ( ) => {
65- if ( currentSessionId === null ) {
66- console . error ( "No current session active " )
67+ if ( sessionIdToDelete === null ) {
68+ console . error ( "No current selected to delete " )
6769 return
6870 }
6971
70- await deleteChatSession ( currentSessionId ) ;
71- const updatedSessions = sessions . filter ( s => s . id !== currentSessionId ) ;
72- setSessions ( updatedSessions )
72+ await deleteChatSession ( sessionIdToDelete ) ;
73+ const updatedSessions = sessions . filter ( s => s . id !== sessionIdToDelete ) ;
74+ setSessions ( updatedSessions ) ;
75+ setIsPopupOpen ( false ) ;
7376 if ( updatedSessions . length === 0 ) {
7477 setCurrentSessionId ( null ) ;
7578 } else {
76- setCurrentSessionId ( updatedSessions [ 0 ] . id )
79+ setCurrentSessionId ( updatedSessions [ 0 ] . id ) ;
7780 }
7881 } ;
7982
@@ -154,7 +157,12 @@ export const Chatbot = () => {
154157
155158 const onSwitchChat = ( chatSessionId : string ) => {
156159 openSideBar ( ) ;
157- setCurrentSessionId ( chatSessionId )
160+ setCurrentSessionId ( chatSessionId ) ;
161+ }
162+
163+ const openConfirmDeleteChatPopup = ( chatSessionId : string ) => {
164+ setSessionIdToDelete ( chatSessionId ) ;
165+ setIsPopupOpen ( true ) ;
158166 }
159167
160168 const getWelcomePage = ( ) => {
@@ -175,6 +183,31 @@ export const Chatbot = () => {
175183 )
176184 }
177185
186+ const getDeletePopup = ( ) => {
187+ return (
188+
189+ < div
190+ style = { chatbotStyles . popupContainer }
191+ >
192+ < h2 style = { chatbotStyles . popupTitle } > { getChatbotText ( "popupTitle" ) } </ h2 >
193+ < p style = { chatbotStyles . popupMessage } >
194+ { getChatbotText ( "popupMessage" ) }
195+ </ p >
196+ < div style = { chatbotStyles . popupButtonsContainer } >
197+ < button style = { chatbotStyles . popupDeleteButton } onClick = { handleDeleteChat } >
198+ { getChatbotText ( "popupDeleteButton" ) }
199+ </ button >
200+ < button style = { chatbotStyles . popupCancelButton } onClick = { ( ) => {
201+ setIsPopupOpen ( false ) ;
202+ setSessionIdToDelete ( null ) ;
203+ } } >
204+ { getChatbotText ( "popupCancelButton" ) }
205+ </ button >
206+ </ div >
207+ </ div >
208+ )
209+ }
210+
178211 return (
179212 < >
180213 < button
@@ -186,7 +219,7 @@ export const Chatbot = () => {
186219
187220 { isOpen && (
188221 < div
189- style = { { ...chatbotStyles . container } }
222+ style = { { ...chatbotStyles . container , pointerEvents : isPopupOpen ? 'none' : 'auto' } }
190223 >
191224 { isSidebarOpen && (
192225 < Sidebar
@@ -195,9 +228,13 @@ export const Chatbot = () => {
195228 onSwitchChat = { onSwitchChat }
196229 chatList = { sessions }
197230 activeChatId = { currentSessionId }
231+ openConfirmDeleteChatPopup = { openConfirmDeleteChatPopup }
198232 />
199233 ) }
200- < Header isChat = { currentSessionId !== null } openSideBar = { openSideBar } clearMessages = { handleDeleteChat } />
234+ { isPopupOpen && (
235+ getDeletePopup ( )
236+ ) }
237+ < Header currentSessionId = { currentSessionId } openSideBar = { openSideBar } clearMessages = { openConfirmDeleteChatPopup } />
201238 { ( currentSessionId !== null ) ?
202239 < >
203240 < Messages messages = { getSessionMessages ( currentSessionId ) } loading = { getChatLoading ( ) } />
0 commit comments