From 78dd051f72f0855c0137bea74e7e320b7d0455e0 Mon Sep 17 00:00:00 2001 From: Harish Mohan Raj Date: Tue, 5 Dec 2023 16:33:43 +0530 Subject: [PATCH] Mock google ads login flow --- src/client/chatConversationHelper.tsx | 16 ++++---- src/client/components/ConversationWrapper.tsx | 40 +++++++++++-------- src/client/helpers.tsx | 16 -------- 3 files changed, 32 insertions(+), 40 deletions(-) diff --git a/src/client/chatConversationHelper.tsx b/src/client/chatConversationHelper.tsx index c7bb26a..2c2b1c2 100644 --- a/src/client/chatConversationHelper.tsx +++ b/src/client/chatConversationHelper.tsx @@ -14,13 +14,15 @@ export async function addUserMessageToConversation( let isAnswerToAgentQuestion = false; let user_answer_to_team_id = null; if (team_id) { - const payload = { - chat_id: chat_id, - conv_id: conv_id, - is_question_from_agent: false, - team_status: null, - }; - await updateExistingConversation(payload); + if (conv_id) { + const payload = { + chat_id: chat_id, + conv_id: conv_id, + is_question_from_agent: false, + team_status: null, + }; + await updateExistingConversation(payload); + } userMessage = `

Replying to ${team_name}:



` + userQuery; isAnswerToAgentQuestion = true; user_answer_to_team_id = team_id; diff --git a/src/client/components/ConversationWrapper.tsx b/src/client/components/ConversationWrapper.tsx index b2237fc..5ee22b8 100644 --- a/src/client/components/ConversationWrapper.tsx +++ b/src/client/components/ConversationWrapper.tsx @@ -1,5 +1,5 @@ import React from "react"; -import { useState, useCallback, useRef } from "react"; +import { useState, useCallback } from "react"; import { useParams } from "react-router"; import { Redirect } from "react-router-dom"; @@ -14,7 +14,7 @@ import { addAgentMessageToConversation, } from "../chatConversationHelper"; -import { setRedirectMsg, getQueryParam, triggerSubmit } from "../helpers"; +import { getQueryParam } from "../helpers"; export default function ConversationWrapper() { const { id }: { id: string } = useParams(); @@ -27,23 +27,30 @@ export default function ConversationWrapper() { { enabled: !!id, refetchInterval: 1000 } ); - const loginMsgQuery: any = getQueryParam("msg"); + const googleRedirectLoginMsg: any = getQueryParam("msg"); + const googleRedirectLoginTeamName: any = getQueryParam("team_name"); + const googleRedirectLoginTeadId: any = getQueryParam("team_id"); const formInputRef = useCallback( - (node: any) => { - if (node !== null) { - setRedirectMsg(node, loginMsgQuery); + async (node: any) => { + if ( + node !== null && + googleRedirectLoginMsg && + googleRedirectLoginTeamName && + googleRedirectLoginTeadId + ) { + await addMessagesToConversation( + googleRedirectLoginMsg, + undefined, + googleRedirectLoginTeamName, + googleRedirectLoginTeadId + ); } }, - [loginMsgQuery] - ); - - const submitBtnRef = useCallback( - (node: any) => { - if (node !== null) { - triggerSubmit(node, loginMsgQuery, formInputRef); - } - }, - [loginMsgQuery, formInputRef] + [ + googleRedirectLoginMsg, + googleRedirectLoginTeamName, + googleRedirectLoginTeadId, + ] ); async function addMessagesToConversation( @@ -145,7 +152,6 @@ export default function ConversationWrapper() { ref={formInputRef} />