Skip to content

Commit

Permalink
Mock google ads login flow
Browse files Browse the repository at this point in the history
  • Loading branch information
harishmohanraj committed Dec 5, 2023
1 parent 5493241 commit 78dd051
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 40 deletions.
16 changes: 9 additions & 7 deletions src/client/chatConversationHelper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `<p>Replying to ${team_name}:</p><br/><br/>` + userQuery;
isAnswerToAgentQuestion = true;
user_answer_to_team_id = team_id;
Expand Down
40 changes: 23 additions & 17 deletions src/client/components/ConversationWrapper.tsx
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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();
Expand All @@ -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(
Expand Down Expand Up @@ -145,7 +152,6 @@ export default function ConversationWrapper() {
ref={formInputRef}
/>
<button
ref={submitBtnRef}
type="submit"
className="text-white absolute right-2.5 bottom-2.5 bg-captn-cta-green hover:bg-captn-cta-green-hover focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-4 py-2 dark:bg-captn-cta-green dark:hover:bg-captn-cta-green-hover dark:focus:ring-blue-800"
>
Expand Down
16 changes: 0 additions & 16 deletions src/client/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,3 @@ export function getQueryParam(paramName: string) {
paramName
);
}

export function setRedirectMsg(formInputRef: any, loginMsgQuery: string) {
if (loginMsgQuery) {
formInputRef.value = decodeURIComponent(loginMsgQuery);
}
}

export function triggerSubmit(
node: any,
loginMsgQuery: string,
formInputRef: any
) {
if (loginMsgQuery && formInputRef && formInputRef.value !== "") {
node.click();
}
}

0 comments on commit 78dd051

Please sign in to comment.