diff --git a/apps/amakrushi/next.config.js b/apps/amakrushi/next.config.js index c5ab32d7..e821846f 100644 --- a/apps/amakrushi/next.config.js +++ b/apps/amakrushi/next.config.js @@ -1,28 +1,30 @@ /** @type {import('next').NextConfig} */ -const nextConfig = { - reactStrictMode: false, - compiler: { - removeConsole: true - }, -} +const withPWA = require("next-pwa"); const withBundleAnalyzer = require('@next/bundle-analyzer')({ - // eslint-disable-next-line turbo/no-undeclared-env-vars enabled: process.env.ANALYZE === 'true' -}) +}); - - -module.exports = withBundleAnalyzer({ - env: { - NEXT_PUBLIC_ENV: 'PRODUCTION', //your next configs goes here - }, - nextConfig, - typescript: { - ignoreBuildErrors: true, - }, - i18n: { - locales: ['or','en'], - defaultLocale: 'en', - } -}) \ No newline at end of file +module.exports = withBundleAnalyzer( + withPWA({ + pwa: { + dest: "public", + register: true, + skipWaiting: true, + }, + env: { + NEXT_PUBLIC_ENV: 'PRODUCTION', // your next configs go here + }, + reactStrictMode: false, + typescript: { + ignoreBuildErrors: true, + }, + compiler: { + removeConsole: true + }, + i18n: { + locales: ['or', 'en'], + defaultLocale: 'en', + }, + }) +); diff --git a/apps/amakrushi/package.json b/apps/amakrushi/package.json index a6eacb3e..9f05492f 100644 --- a/apps/amakrushi/package.json +++ b/apps/amakrushi/package.json @@ -36,6 +36,7 @@ "jwks-rsa": "^3.0.1", "jwt-decode": "^3.1.2", "next": "12.1.6", + "next-pwa": "^5.6.0", "react": "17.0.2", "react-alert": "^7.0.3", "react-alert-template-basic": "^1.0.2", diff --git a/apps/amakrushi/public/logo.png b/apps/amakrushi/public/logo.png new file mode 100644 index 00000000..d2ab58f1 Binary files /dev/null and b/apps/amakrushi/public/logo.png differ diff --git a/apps/amakrushi/public/logo192.png b/apps/amakrushi/public/logo192.png deleted file mode 100644 index fc44b0a3..00000000 Binary files a/apps/amakrushi/public/logo192.png and /dev/null differ diff --git a/apps/amakrushi/public/logo512.png b/apps/amakrushi/public/logo512.png deleted file mode 100644 index a4e47a65..00000000 Binary files a/apps/amakrushi/public/logo512.png and /dev/null differ diff --git a/apps/amakrushi/public/manifest.json b/apps/amakrushi/public/manifest.json index 490b7939..c3808b80 100644 --- a/apps/amakrushi/public/manifest.json +++ b/apps/amakrushi/public/manifest.json @@ -1,6 +1,6 @@ { - "short_name": "React App", - "name": "Create React App Sample", + "short_name": "AmakrushAI", + "name": "AmakrushAI", "icons": [ { "src": "favicon.ico", @@ -8,17 +8,17 @@ "type": "image/x-icon" }, { - "src": "logo192.png", + "src": "logo.png", "type": "image/png", "sizes": "192x192" }, { - "src": "logo512.png", + "src": "logo.png", "type": "image/png", "sizes": "512x512" } ], - "start_url": ".", + "start_url": "/", "display": "standalone", "theme_color": "black", "background_color": "white" diff --git a/apps/amakrushi/src/components/ChatSection/ChatSection.module.css b/apps/amakrushi/src/components/ChatSection/ChatSection.module.css deleted file mode 100644 index b5f75fb8..00000000 --- a/apps/amakrushi/src/components/ChatSection/ChatSection.module.css +++ /dev/null @@ -1,7 +0,0 @@ -.main__container { - flex: 1; - width: 5%; - height: 100vh; - display: flex; - flex-direction: column; -} \ No newline at end of file diff --git a/apps/amakrushi/src/components/ChatSection/index.tsx b/apps/amakrushi/src/components/ChatSection/index.tsx deleted file mode 100644 index a1958bc6..00000000 --- a/apps/amakrushi/src/components/ChatSection/index.tsx +++ /dev/null @@ -1,73 +0,0 @@ -import React from "react"; -import { Flex, Box, Button } from "@chakra-ui/react"; -import styles from "./ChatSection.module.css"; -import ChatItem from "../chat-item"; -import { NextPage } from "next"; - -interface chatSectionProps { - toShowSettings: (event: React.MouseEvent) => void; - toChangeCurrentUser: (name: string) => void; - toRemoveUser: (name: string) => void; - allUsers: { name: string; number: string | null, active: boolean }[]; -} - -const ChatSection: NextPage = ({ - toShowSettings, - toChangeCurrentUser, - toRemoveUser, - allUsers, -}) => { - - const changingUser = (name: string) => { - toChangeCurrentUser(name); - }; - return ( - - {/* Settings Heading */} - - - - - - {/* - - */} - - - {/* Profile Section */} - - {allUsers.map((user) => { - return ( - - ); - })} - - - ); -}; - -export default ChatSection; \ No newline at end of file diff --git a/apps/amakrushi/src/components/PhoneView/ChatWindow/ChatUiWindow.tsx b/apps/amakrushi/src/components/ChatWindow/ChatUiWindow.tsx similarity index 92% rename from apps/amakrushi/src/components/PhoneView/ChatWindow/ChatUiWindow.tsx rename to apps/amakrushi/src/components/ChatWindow/ChatUiWindow.tsx index b28962ea..5ca896bb 100644 --- a/apps/amakrushi/src/components/PhoneView/ChatWindow/ChatUiWindow.tsx +++ b/apps/amakrushi/src/components/ChatWindow/ChatUiWindow.tsx @@ -9,16 +9,16 @@ import React, { useMemo, useState, } from 'react'; -import { analytics } from '../../../utils/firebase'; +import { analytics } from '../../utils/firebase'; import { logEvent } from 'firebase/analytics'; -import { AppContext } from '../../../context'; -import { useLocalization } from '../../../hooks'; -import { getMsgType } from '../../../utils/getMsgType'; -import ChatMessageItem from '../../chat-message-item'; +import { AppContext } from '../../context'; +import { useLocalization } from '../../hooks'; +import { getMsgType } from '../../utils/getMsgType'; +import ChatMessageItem from '../chat-message-item'; import { v4 as uuidv4 } from 'uuid'; -import RenderVoiceRecorder from '../../recorder/RenderVoiceRecorder'; +import RenderVoiceRecorder from '../recorder/RenderVoiceRecorder'; import toast from 'react-hot-toast'; -import DownTimePage from '../../down-time-page'; +import DownTimePage from '../down-time-page'; const ChatUiWindow: React.FC = () => { const t = useLocalization(); diff --git a/apps/amakrushi/src/components/PhoneView/ChatWindow/chatui-theme.css b/apps/amakrushi/src/components/ChatWindow/chatui-theme.css similarity index 100% rename from apps/amakrushi/src/components/PhoneView/ChatWindow/chatui-theme.css rename to apps/amakrushi/src/components/ChatWindow/chatui-theme.css diff --git a/apps/amakrushi/src/components/PhoneView/ChatWindow/index.module.css b/apps/amakrushi/src/components/ChatWindow/index.module.css similarity index 100% rename from apps/amakrushi/src/components/PhoneView/ChatWindow/index.module.css rename to apps/amakrushi/src/components/ChatWindow/index.module.css diff --git a/apps/amakrushi/src/components/FeaturePopup/index.tsx b/apps/amakrushi/src/components/FeaturePopup/index.tsx index 0546f10d..6a54a9dd 100644 --- a/apps/amakrushi/src/components/FeaturePopup/index.tsx +++ b/apps/amakrushi/src/components/FeaturePopup/index.tsx @@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react'; import styles from './styles.module.css'; function FeaturePopup() { - const [popupData, setPopupData] = useState(null); + const [popupData, setPopupData] = useState(null); const [dbExists, setDbExists] = useState(false); useEffect(() => { diff --git a/apps/amakrushi/src/components/HomePage/index.module.css b/apps/amakrushi/src/components/HomePage/index.module.css index 170b6df8..e0157589 100644 --- a/apps/amakrushi/src/components/HomePage/index.module.css +++ b/apps/amakrushi/src/components/HomePage/index.module.css @@ -24,7 +24,7 @@ font-weight: 700; } -.voiceRecorder{ +.voiceRecorder { position: relative; margin: auto; top: 18%; @@ -38,10 +38,11 @@ left: 3px; right: 0; bottom: calc(40px + 1vh); - transition: opacity 0.5s ease-in-out, transform 0.5s ease-in-out, visibility 0.5s ease-in-out; + transition: opacity 0.5s ease-in-out, transform 0.5s ease-in-out, + visibility 0.5s ease-in-out; } -.invisible{ +.invisible { opacity: 0; transform: translateY(50px); /* Initial downward position */ visibility: hidden; @@ -53,7 +54,6 @@ visibility: visible; } - .buttonChoice { display: flex; align-items: center; @@ -69,7 +69,7 @@ margin-top: 2px; } -.keyboard{ +.keyboard { margin: auto; cursor: pointer; position: relative; @@ -109,7 +109,6 @@ outline: none; } - .inputBox.inputBoxOpen { width: 99%; left: 0; diff --git a/apps/amakrushi/src/components/HomePage/index.tsx b/apps/amakrushi/src/components/HomePage/index.tsx index 3622af45..d272bab6 100644 --- a/apps/amakrushi/src/components/HomePage/index.tsx +++ b/apps/amakrushi/src/components/HomePage/index.tsx @@ -22,7 +22,6 @@ import SendIcon from '../../assets/images/sendButton.png'; import { useLocalization } from '../../hooks'; import router from 'next/router'; import Image from 'next/image'; -import { Button, Spinner } from '@chakra-ui/react'; import toast from 'react-hot-toast'; import { v4 as uuidv4 } from 'uuid'; import RenderVoiceRecorder from '../recorder/RenderVoiceRecorder'; @@ -32,6 +31,7 @@ import DownTimePage from '../down-time-page'; const HomePage: NextPage = () => { const context = useContext(AppContext); const t = useLocalization(); + const placeholder = useMemo(() => t('message.ask_ur_question'), [t]); const flags = useFlags([ 'en_example_ques_one', diff --git a/apps/amakrushi/src/components/NavBar/index.tsx b/apps/amakrushi/src/components/NavBar/index.tsx index 39652260..d31305fb 100644 --- a/apps/amakrushi/src/components/NavBar/index.tsx +++ b/apps/amakrushi/src/components/NavBar/index.tsx @@ -57,9 +57,6 @@ function NavBar() { toast.error(`${t('message.no_link')}`); return; } - // window.open(pdfUrl) - const blob = new Blob([response.data], { type: 'application/pdf' }); - const file = new File([blob], 'Chat.pdf', { type: blob.type }); if (type === 'download') { //@ts-ignore @@ -75,6 +72,11 @@ function NavBar() { link.click(); context?.downloadChat(pdfUrl); } else if (type === 'share') { + const response = await axios.get(pdfUrl, { + responseType: 'arraybuffer', + }); + const blob = new Blob([response.data], { type: 'application/pdf' }); + const file = new File([blob], 'Chat.pdf', { type: blob.type }); //@ts-ignore logEvent(analytics, 'share_chat_clicked'); @@ -89,6 +91,7 @@ function NavBar() { } } else if (navigator.canShare({ files: [file] })) { toast.success(`${t('message.sharing')}`); + console.log("hurray", file) await navigator .share({ files: [file], diff --git a/apps/amakrushi/src/components/PhoneView/ChatWindow/index.tsx b/apps/amakrushi/src/components/PhoneView/ChatWindow/index.tsx deleted file mode 100644 index 1a53ade9..00000000 --- a/apps/amakrushi/src/components/PhoneView/ChatWindow/index.tsx +++ /dev/null @@ -1,39 +0,0 @@ -import React, { useContext } from "react"; -import styles from "./index.module.css"; -import dynamic from "next/dynamic"; -import { AppContext } from "../../../context"; - -const ChatUiWindow = dynamic(() => import("./ChatUiWindow"), { - ssr: false, -}); - -interface chatWindowProps { - currentMessageObj: { - user: string; - phoneNumber: string | null; - messages: any[]; - }; - toClearChat: () => void; - messages: any[]; - username: string; - selected: (option: { key: string; text: string; backmenu: boolean }) => void; - toSendMessage: (text: string, media: any) => void; - currentUser: { name: string; number: string | null }; - sendLocation: (location: string) => void; - toShowChats: (event: React.MouseEvent) => void; -} - -const ChatWindow: React.FC = () => { - const context = useContext(AppContext); - console.log("qwerty:", { context }) - return ( - <> -
- -
- - - ); -}; - -export default ChatWindow; diff --git a/apps/amakrushi/src/components/PhoneView/Profile/index.tsx b/apps/amakrushi/src/components/PhoneView/Profile/index.tsx deleted file mode 100644 index 06c5ef83..00000000 --- a/apps/amakrushi/src/components/PhoneView/Profile/index.tsx +++ /dev/null @@ -1,114 +0,0 @@ -import styles from "./profile.module.css"; -import avatar from "../../../public/avatar.jpg"; -import { Box, Text, Flex, Button } from "@chakra-ui/react"; -import { useColorModeValue } from "@chakra-ui/react"; -import React, { useState, useEffect, MouseEventHandler } from "react"; -import ReactDom from "react-dom"; -import Image from "next/image"; - -interface profileProps { - toRemoveProfile: (name: string,number: string | null) => void; - name: string; - number: string | null; - toHide: (e: React.MouseEvent) => void - // userImg: string; - show: boolean; -} - -const Profile: React.FC = ({ - show, - toHide, - name, - number, - toRemoveProfile, -}) => { - const fontColor = useColorModeValue("white", "white"); - - const onRemoveUser: React.MouseEventHandler = (event: React.MouseEvent) => { - toRemoveProfile(name,number); - } - - return show - ? ReactDom.createPortal( - <> - - -
- coverPic -
- profilePic -

- {name} - User -

-

{}

- - - -
-
-
- , - document.getElementById("modal_portal") as HTMLDivElement - ) - : null; -}; - -export default Profile; diff --git a/apps/amakrushi/src/components/PhoneView/Profile/profile.module.css b/apps/amakrushi/src/components/PhoneView/Profile/profile.module.css deleted file mode 100644 index e0973e7f..00000000 --- a/apps/amakrushi/src/components/PhoneView/Profile/profile.module.css +++ /dev/null @@ -1,30 +0,0 @@ - .container { - overflow: hidden; - min-width: 400px; - max-width: 600px; - text-align: left; - line-height: 1.4rem; - } - - .container figcaption::before { - position: absolute; - content: ''; - bottom: 100%; - left: 0; - width: 0; - height: 0; - border-style: solid; - border-width: 55px 0 0 400px; - border-color: transparent transparent transparent black; - } - -.container h2 span { - display: block; - font-size: 0.75rem; - color: var(--blue); -} - -.container p { - font-size: 0.9rem; - margin: 0 0 10px; -} \ No newline at end of file diff --git a/apps/amakrushi/src/components/PhoneView/index.tsx b/apps/amakrushi/src/components/PhoneView/index.tsx deleted file mode 100644 index 2e67308b..00000000 --- a/apps/amakrushi/src/components/PhoneView/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import React from "react"; -import ChatWindow from "./ChatWindow"; - - -const PhoneView: React.FC = () => { - return ; -}; - -export default PhoneView; diff --git a/apps/amakrushi/src/components/Profile/index.tsx b/apps/amakrushi/src/components/Profile/index.tsx deleted file mode 100644 index b9691eb2..00000000 --- a/apps/amakrushi/src/components/Profile/index.tsx +++ /dev/null @@ -1,115 +0,0 @@ -import styles from "./profile.module.css"; -import avatar from "../../../public/avatar.jpg"; -import { Box, Text, Flex, Button } from "@chakra-ui/react"; -import { useColorModeValue } from "@chakra-ui/react"; -import React, { useState, useEffect } from "react"; -import ReactDom from "react-dom"; -import Image from "next/image"; - -interface profileProps { - removeProfile:any; - toRemoveUser: any; - name: string; - userImg: string; - show: boolean; - // number: string; - // bio: string; -} - -const Profile: React.FC = ({ - show, - userImg, - name, - removeProfile, - toRemoveUser -}) => { - const fontColor = useColorModeValue("white", "white"); - - const onRemoveUser: React.MouseEventHandler = (event: React.MouseEvent) => { - toRemoveUser(name); - } - - return show - ? ReactDom.createPortal( - <> - - -
- coverPic -
- profilePic -

- {name} - User -

-

{}

- - - -
-
-
- , - document.getElementById("modal_portal") as HTMLDivElement - ) - : null; -}; - -export default Profile; diff --git a/apps/amakrushi/src/components/Profile/profile.module.css b/apps/amakrushi/src/components/Profile/profile.module.css deleted file mode 100644 index e0973e7f..00000000 --- a/apps/amakrushi/src/components/Profile/profile.module.css +++ /dev/null @@ -1,30 +0,0 @@ - .container { - overflow: hidden; - min-width: 400px; - max-width: 600px; - text-align: left; - line-height: 1.4rem; - } - - .container figcaption::before { - position: absolute; - content: ''; - bottom: 100%; - left: 0; - width: 0; - height: 0; - border-style: solid; - border-width: 55px 0 0 400px; - border-color: transparent transparent transparent black; - } - -.container h2 span { - display: block; - font-size: 0.75rem; - color: var(--blue); -} - -.container p { - font-size: 0.9rem; - margin: 0 0 10px; -} \ No newline at end of file diff --git a/apps/amakrushi/src/components/chat-message-item/index.tsx b/apps/amakrushi/src/components/chat-message-item/index.tsx index e0b556be..beaf4584 100644 --- a/apps/amakrushi/src/components/chat-message-item/index.tsx +++ b/apps/amakrushi/src/components/chat-message-item/index.tsx @@ -159,7 +159,7 @@ const ChatMessageItem: FC = ({ const handleAudio = (url: any) => { // console.log(url) - if (url === '') { + if (!url) { toast.error('No audio'); return; } diff --git a/apps/amakrushi/src/context/ContextProvider.tsx b/apps/amakrushi/src/context/ContextProvider.tsx index 9ffa7b87..e7a74e40 100644 --- a/apps/amakrushi/src/context/ContextProvider.tsx +++ b/apps/amakrushi/src/context/ContextProvider.tsx @@ -67,6 +67,9 @@ const ContextProvider: FC<{ const [ttsLoader, setTtsLoader] = useState(false); const [audioPlaying, setAudioPlaying] = useState(false); const [clickedAudioUrl, setClickedAudioUrl] = useState(null); + const [startTime, setStartTime] = useState(Date.now()); + const [endTime, setEndTime] = useState(Date.now()); + const [lastMsgId, setLastMsgId] = useState(''); const downloadChat = useMemo(() => { return (e: string) => { @@ -318,6 +321,8 @@ const ContextProvider: FC<{ }); } else if (msg.content.msg_type.toUpperCase() === 'TEXT') { if (msg.content.timeTaken + 1000 < timer2 && isOnline) { + setLastMsgId(msg?.messageId); + setEndTime(Date.now()); updateMsgState({ user, msg, media: {} }); } } @@ -325,6 +330,28 @@ const ContextProvider: FC<{ [isOnline, messages, timer2, updateMsgState] ); + useEffect(() => { + if (!lastMsgId) return; + const timeDiff = endTime - startTime; + console.log('time taken', timeDiff); + axios + .post( + `${process.env.NEXT_PUBLIC_BASE_URL}/timetakenatapplication/${lastMsgId}`, + { + data: { + timeTaken: timeDiff, + }, + } + ) + .then((res) => { + console.log(res); + }) + .catch((err) => { + console.log(err); + }); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [endTime]); + const onChangeCurrentUser = useCallback((newUser: UserType) => { setCurrentUser({ ...newUser, active: true }); // setMessages([]); @@ -363,6 +390,7 @@ const ContextProvider: FC<{ userId: localStorage.getItem('userID'), conversationId: sessionStorage.getItem('conversationId'), }); + setStartTime(Date.now()); if (isVisibile) if (media) { if (media.mimeType.slice(0, 5) === 'image') { diff --git a/apps/amakrushi/src/hooks/useLogin.ts b/apps/amakrushi/src/hooks/useLogin.ts index 4b70587d..9657343c 100644 --- a/apps/amakrushi/src/hooks/useLogin.ts +++ b/apps/amakrushi/src/hooks/useLogin.ts @@ -23,7 +23,7 @@ export const useLogin = () => { const login = useCallback(() => { // No need to check for auth if access token is not present if (cookies.access_token) { - const decodedToken = jwt.decode(cookies.access_token); + const decodedToken: any = jwt.decode(cookies.access_token); const expires = new Date(decodedToken?.exp * 1000); // if token not expired then check for auth if (expires > new Date()) { diff --git a/apps/amakrushi/src/pages/_app.tsx b/apps/amakrushi/src/pages/_app.tsx index cd004fea..d0876104 100644 --- a/apps/amakrushi/src/pages/_app.tsx +++ b/apps/amakrushi/src/pages/_app.tsx @@ -2,7 +2,7 @@ import '../styles/globals.css'; import type { AppProps } from 'next/app'; import { ChakraProvider } from '@chakra-ui/react'; import ContextProvider from '../context/ContextProvider'; -import { ReactElement, useCallback, useEffect, useState } from 'react'; +import { ReactElement, useCallback, useEffect, useRef, useState } from 'react'; import 'chatui/dist/index.css'; import { Toaster } from 'react-hot-toast'; import { useCookies } from 'react-cookie'; @@ -17,6 +17,7 @@ import { getToken } from 'firebase/messaging'; import FcmNotification from '../utils/FcmNotification'; import { logEvent } from 'firebase/analytics'; import FeaturePopup from '../components/FeaturePopup'; +import { Button, Modal } from '@material-ui/core'; const LaunchPage = dynamic(() => import('../components/LaunchPage'), { ssr: false, @@ -38,6 +39,8 @@ const App = ({ Component, pageProps }: AppProps) => { const [launch, setLaunch] = useState(true); const [cookie, setCookie, removeCookie] = useCookies(); const [flagsmithState, setflagsmithState] = useState(null); + const [modalOpen, setModalOpen] = useState(false); + const deferredPromptRef = useRef(null); useEffect(() => { const isEventLogged = sessionStorage.getItem('isSplashScreenLogged'); @@ -147,6 +150,39 @@ const App = ({ Component, pageProps }: AppProps) => { globalThis.console.log = () => {}; } + // For install PWA dialog box + useEffect(() => { + if (localStorage.getItem('installPwa') !== 'true') { + // Check if the browser has the install event + if ('serviceWorker' in navigator && 'PushManager' in window) { + setModalOpen(true); + window.addEventListener('beforeinstallprompt', (e) => { + e.preventDefault(); + deferredPromptRef.current = e; + }); + } + } + }, []); + + const closeAndSetLocalStorage = () => { + setModalOpen(false); + localStorage.setItem('installPwa', 'true'); + }; + + const openInstallPrompt = () => { + closeAndSetLocalStorage(); + if (deferredPromptRef.current) { + deferredPromptRef.current.prompt(); + deferredPromptRef.current.userChoice.then((choiceResult: any) => { + if (choiceResult.outcome === 'accepted') { + console.log('App installed'); + } else { + console.log('App installation declined'); + } + }); + } + }; + if (launch || !flagsmithState) { return ; } else { @@ -157,6 +193,40 @@ const App = ({ Component, pageProps }: AppProps) => {
+ {modalOpen && ( + +
+

Install App

+

+ Click the button to install the app. +

+ +
+
+ )} @@ -178,4 +248,4 @@ const App = ({ Component, pageProps }: AppProps) => { // return { flagsmithState: flagsmith.getState() }; // }; -export default App \ No newline at end of file +export default App; diff --git a/apps/amakrushi/src/pages/_document.tsx b/apps/amakrushi/src/pages/_document.tsx index 806028df..2ecd390c 100644 --- a/apps/amakrushi/src/pages/_document.tsx +++ b/apps/amakrushi/src/pages/_document.tsx @@ -1,16 +1,18 @@ - -import { Html, Head, Main, NextScript } from "next/document"; +import { Html, Head, Main, NextScript } from 'next/document'; export default function Document() { return ( - + + + + +