@@ -4,8 +4,8 @@ import { AiOutlineEye } from "react-icons/ai"
44import { API_ENDPOINTS } from "../../constants/urls"
55import { BiLoader } from "react-icons/bi"
66import { clearFromStorage , handleS3Upload } from "../../services/storage_service"
7- import { createMessage } from "../interview-voice"
87import { createUserProfileApi } from "api/endpoints/user"
8+ import { createMessage } from "../interview-voice"
99import { getChatsFromDB , endStoryV2Api , getStoryBySessionAPI , updateStoryMediaApi , updateReflectionStatusApi , getAI4BharatAudioApi , ai4BharatASRApi , getFlowInfoApi } from "../../api/endpoints"
1010import { extractStoryData , extractTextBlocks , getEditorContentBlocks , handleMultipleUploads } from "../../utils/story"
1111import { FaCircle } from "react-icons/fa6"
@@ -335,14 +335,14 @@ const DynamicVoiceChat = ({
335335 setChatHistory ( [
336336 ...currentHistory ,
337337 {
338- msg : "Thank you. I have all the information I need. Redirecting you to Saathi" ,
338+ msg : t ( "profileOnboardingCompleteMessage" ) ,
339339 source : "bot" ,
340340 updated_at : Date . now ( ) ,
341341 received : true ,
342342 } ,
343343 ] )
344344 onProfileExtractedRef . current ?. ( )
345- } , [ ] )
345+ } , [ t ] )
346346
347347 const onWebSocketMessage = useCallback (
348348 event => {
@@ -1123,16 +1123,18 @@ const DynamicVoiceChat = ({
11231123 setChatLanguage ( languageList [ 0 ] . value )
11241124 stopAllAudio ( )
11251125 if ( accessToken ) {
1126- clearFromStorage ( )
1127- navigateSsoFlow ( ssoRerouteURL )
1126+ navigate ( {
1127+ pathname : ROUTES . SHIKSHALOKAM_HOME_PAGE ,
1128+ search : new URLSearchParams ( { flow : env . FLOW_NAME ( ) } ) . toString ( ) ,
1129+ } , { replace : true } )
11281130 } else {
11291131 navigate ( ROUTES . SHIKSHALOKAM_VOICE_CHAT_LOGIN )
11301132 }
11311133 }
11321134 }
1133- // Check if we already pushed a custom state
1135+
11341136 if ( ! window . history . state ?. isCustom ) {
1135- window . history . pushState ( { isCustom : true } , "" , window . location . href )
1137+ window . history . replaceState ( { isCustom : true } , "" , window . location . href )
11361138 }
11371139
11381140 window . addEventListener ( "popstate" , handleBack )
@@ -1249,12 +1251,38 @@ const DynamicVoiceChat = ({
12491251 }
12501252
12511253 if ( ! profileToUse && accessToken ) {
1252- createUserProfile ( )
1254+ // createUserProfile()
12531255 setShouldFetchIntro ( true )
12541256 setIsStreamingComplete ( true )
12551257 }
12561258 } , [ accessToken , profileToUse ] )
12571259
1260+ /**
1261+ * Initialize popup mode: generate session and open new chat
1262+ * Runs when popup renders with an already-known profile (chat-container bypassed)
1263+ */
1264+ useEffect ( ( ) => {
1265+ if ( ! isPopupMode ) return
1266+ if ( ! accessToken || ! profileToUse ) return
1267+
1268+ ; ( async ( ) => {
1269+ try {
1270+ setIsLoading ( true )
1271+ if ( ! sessionId ) {
1272+ const session = await getSessionDetails ( )
1273+ setSessionId ( session . sessionid )
1274+ }
1275+ setIsNewChatOpen ( true )
1276+ setShouldFetchIntro ( true )
1277+ setIsStreamingComplete ( true )
1278+ } catch ( error ) {
1279+ console . error ( "[DynamicVoiceChat popup] session init failed:" , error )
1280+ } finally {
1281+ setIsLoading ( false )
1282+ }
1283+ } ) ( )
1284+ } , [ isPopupMode , accessToken , profileToUse ] )
1285+
12581286 /**
12591287 * Fetch chat session for Reflection flow based on projectId
12601288 * Retrieves existing session for project-based reflections
@@ -2004,29 +2032,14 @@ const DynamicVoiceChat = ({
20042032 }
20052033
20062034 const navigateBack = ( ) => {
2007- let rerouteUrl = previousUrl
2008- const currentFlow = storageFlow
20092035 stopAllAudio ( )
2010- if ( accessToken ) {
2011- console . log ( "clearing storage" )
2012- clearFromStorage ( )
2013- navigateSsoFlow ( ssoRerouteURL )
2014- return
2015- }
2016- console . log ( "clearing storage" )
2017- clearFromStorage ( )
2018- setLanguage ( LANGUAGE_ENUMS . ENGLISH )
2019- setChatLanguage ( LANGUAGE_ENUMS . ENGLISH )
2020- setHasSelectedLanguage ( false )
2021- if ( rerouteUrl && rerouteUrl !== null && rerouteUrl !== undefined && rerouteUrl !== "" ) {
2022- window . location . href = rerouteUrl
2023- } else {
2024- navigate ( {
2036+ navigate (
2037+ {
20252038 pathname : ROUTES . SHIKSHALOKAM_HOME_PAGE ,
2026- search : currentFlow ? new URLSearchParams ( { flow : currentFlow } ) . toString ( ) : ''
2027- } )
2028- window . location . reload ( )
2029- }
2039+ search : new URLSearchParams ( { flow : env . FLOW_NAME ( ) } ) . toString ( ) ,
2040+ } ,
2041+ { replace : true }
2042+ )
20302043 }
20312044
20322045 function navigateSsoFlow ( ) {
0 commit comments