diff --git a/apps/amakrushi/package.json b/apps/amakrushi/package.json index 4504060..7e6cf47 100644 --- a/apps/amakrushi/package.json +++ b/apps/amakrushi/package.json @@ -50,7 +50,7 @@ "react-router-dom": "^6.3.0", "react-scripts": "5.0.0", "react-toastify": "^9.0.5", - "socket-package": "0.13.0", + "socket-package": "0.14.0", "socket.io-client": "^4.5.1", "typescript": "^4.9.3", "underscore": "^1.13.6", diff --git a/apps/amakrushi/src/components/ChatWindow/ChatUiWindow.tsx b/apps/amakrushi/src/components/ChatWindow/ChatUiWindow.tsx index a15b8ec..5c2f57e 100644 --- a/apps/amakrushi/src/components/ChatWindow/ChatUiWindow.tsx +++ b/apps/amakrushi/src/components/ChatWindow/ChatUiWindow.tsx @@ -23,6 +23,7 @@ import shareIcon from '../../assets/icons/share.svg'; import downloadIcon from '../../assets/icons/download.svg'; import Image from 'next/image'; import Draggable from 'react-draggable' +import { recordUserLocation } from '../../utils/location'; const ChatUiWindow: React.FC = () => { const t = useLocalization(); @@ -34,8 +35,7 @@ const ChatUiWindow: React.FC = () => { await context?.fetchIsDown(); if (!context?.isDown) { const chatHistory = await axios.get( - `${ - process.env.NEXT_PUBLIC_BASE_URL + `${process.env.NEXT_PUBLIC_BASE_URL }/user/chathistory/${sessionStorage.getItem('conversationId')}`, { headers: { @@ -68,6 +68,7 @@ const ChatUiWindow: React.FC = () => { }); } }; + recordUserLocation(); !context?.loading && fetchData(); // eslint-disable-next-line react-hooks/exhaustive-deps }, [context?.setMessages, context?.fetchIsDown, context?.isDown]); @@ -132,13 +133,13 @@ const ChatUiWindow: React.FC = () => { const msgToRender = useMemo(() => { return context?.isMsgReceiving ? [ - ...normalizeMsgs, - { - type: 'loader', - position: 'left', - botUuid: '1', - }, - ] + ...normalizeMsgs, + { + type: 'loader', + position: 'left', + botUuid: '1', + }, + ] : normalizeMsgs; }, [context?.isMsgReceiving, normalizeMsgs]); @@ -148,11 +149,10 @@ const ChatUiWindow: React.FC = () => { const downloadShareHandler = async (type: string) => { try { - const url = `${ - process.env.NEXT_PUBLIC_BASE_URL - }/user/chathistory/generate-pdf/${sessionStorage.getItem( - 'conversationId' - )}`; + const url = `${process.env.NEXT_PUBLIC_BASE_URL + }/user/chathistory/generate-pdf/${sessionStorage.getItem( + 'conversationId' + )}`; const response = await axios.post(url, null, { headers: { @@ -191,10 +191,10 @@ const ChatUiWindow: React.FC = () => { if (!navigator.canShare) { //@ts-ignore - if(window?.AndroidHandler?.shareUrl){ + if (window?.AndroidHandler?.shareUrl) { //@ts-ignore window.AndroidHandler.shareUrl(pdfUrl); - }else{ + } else { context?.shareChat(pdfUrl); } } else if (navigator.canShare({ files: [file] })) { @@ -262,30 +262,30 @@ const ChatUiWindow: React.FC = () => { placeholder={placeholder} /> -
-
downloadShareHandler('share')}> - {/* Share */} - -
-
downloadShareHandler('download')}> - {/* Download */} - + position: 'absolute', + right: 0, + top: '40%', + background: 'white', + padding: '5px', + borderRadius: '5px 0 0 5px', + boxShadow: 'rgba(50, 50, 93, 0.25) 0px 6px 12px -2px, rgba(0, 0, 0, 0.3) 0px 3px 7px -3px' + }}> +
downloadShareHandler('share')}> + {/* Share */} + +
+
+
downloadShareHandler('download')}> + {/* Download */} + +
-
); diff --git a/apps/amakrushi/src/components/HomePage/index.tsx b/apps/amakrushi/src/components/HomePage/index.tsx index 3f7b01d..af3b7c2 100644 --- a/apps/amakrushi/src/components/HomePage/index.tsx +++ b/apps/amakrushi/src/components/HomePage/index.tsx @@ -27,6 +27,7 @@ import { v4 as uuidv4 } from 'uuid'; import RenderVoiceRecorder from '../recorder/RenderVoiceRecorder'; import { useFlags } from 'flagsmith/react'; import DownTimePage from '../down-time-page'; +import { recordUserLocation } from '../../utils/location'; const HomePage: NextPage = () => { const context = useContext(AppContext); @@ -197,6 +198,9 @@ const HomePage: NextPage = () => { sessionStorage.setItem('conversationId', newConversationId); context?.setConversationId(newConversationId); } + recordUserLocation(); + + // eslint-disable-next-line react-hooks/exhaustive-deps }, []); @@ -391,9 +395,8 @@ const HomePage: NextPage = () => {
suggestionClickHandler(elem)} - className={`${styles.suggestion} ${ - activeSuggestion === index ? styles.active : '' - }`} + className={`${styles.suggestion} ${activeSuggestion === index ? styles.active : '' + }`} onMouseEnter={(e) => suggestionHandler(e, index)}> {elem}
@@ -411,7 +414,7 @@ const HomePage: NextPage = () => { diff --git a/apps/amakrushi/src/context/ContextProvider.tsx b/apps/amakrushi/src/context/ContextProvider.tsx index e7a74e4..fcc1175 100644 --- a/apps/amakrushi/src/context/ContextProvider.tsx +++ b/apps/amakrushi/src/context/ContextProvider.tsx @@ -150,7 +150,7 @@ const ContextProvider: FC<{ .get( `${process.env.NEXT_PUBLIC_BASE_URL}/incrementaudioused/${content?.data?.messageId}` ) - .then((res) => {}) + .then((res) => { }) .catch((err) => { console.log(err); }); @@ -381,14 +381,18 @@ const ContextProvider: FC<{ newSocket.sendMessage({ text: text, to: localStorage.getItem('userID'), - from: localStorage.getItem('phoneNumber'), - optional: { + payload: { + from: localStorage.getItem('phoneNumber'), appId: 'AKAI_App_Id', channel: 'AKAI', - }, - asrId: sessionStorage.getItem('asrId'), - userId: localStorage.getItem('userID'), - conversationId: sessionStorage.getItem('conversationId'), + latitude: sessionStorage.getItem('latitude'), + longitude: sessionStorage.getItem('longitude'), + city: sessionStorage.getItem('city'), + state: sessionStorage.getItem('state'), + asrId: sessionStorage.getItem('asrId'), + userId: localStorage.getItem('userID'), + conversationId: sessionStorage.getItem('conversationId') + } }); setStartTime(Date.now()); if (isVisibile) diff --git a/apps/amakrushi/src/utils/location.ts b/apps/amakrushi/src/utils/location.ts index 53b9bc6..2ffa5e8 100644 --- a/apps/amakrushi/src/utils/location.ts +++ b/apps/amakrushi/src/utils/location.ts @@ -1,12 +1,26 @@ +import { toast } from 'react-hot-toast'; -export function recordUserLocation() { - if (navigator.geolocation) { - navigator.geolocation.getCurrentPosition(saveUserLocation); +export async function recordUserLocation() { + try { + if (navigator.geolocation) { + navigator.geolocation.getCurrentPosition(saveUserLocation); + } + let apiRes: any = await fetch('https://api.ipify.org?format=json'); + apiRes = await apiRes.json(); + if (apiRes?.ip) { + let locationRes: any = await fetch(`https://geoip.samagra.io/city/${apiRes.ip}`); + locationRes = await locationRes.json(); + sessionStorage.setItem('city', locationRes.city); + sessionStorage.setItem('state', locationRes.regionName); + } + } catch (err) { + console.log(err) + toast.error('Unable to record user location') } } function saveUserLocation(position: any) { - sessionStorage.setItem('userLat', position.coords.latitude); - sessionStorage.setItem('userLong', position.coords.longitude); + sessionStorage.setItem('latitude', position.coords.latitude); + sessionStorage.setItem('longitude', position.coords.longitude); }