diff --git a/app/public/icons/popout.svg b/app/public/icons/popout.svg new file mode 100644 index 0000000..e70de62 --- /dev/null +++ b/app/public/icons/popout.svg @@ -0,0 +1,6 @@ + + + pop-out-line + + + \ No newline at end of file diff --git a/app/src/pages/index.tsx b/app/src/pages/index.tsx index 030863b..44b6717 100644 --- a/app/src/pages/index.tsx +++ b/app/src/pages/index.tsx @@ -12,11 +12,24 @@ import OutlineButton from "@/components/OutlineButton"; import { useToasts } from "@/components/ToastProvider"; import { useSession } from 'next-auth/react' +const Session = ({ data, onClick = () => { }, ...props }) => { + return ( +
+ +

Caller Phone: {data.callerPhone}

+

Started At: {data.startedAt}

+
+ ); +} + const Home: NextPage = ({ officers }) => { const { toastDispatch } = useToasts(); const [input, setInput] = useState({ phone: '', }) + const [sessions, setSessions] = useState([]) + const [focusSession, setFocusSession] = useState(null) + const { data: session } = useSession() const submit = async () => { const operator = await fetch(process.env.NEXT_PUBLIC_API_URL + '/operator/update', { @@ -33,30 +46,115 @@ const Home: NextPage = ({ officers }) => { notify(toastDispatch, "", "Updated Phone: " + input.phone, ToastType.SUCCESS) } + const popOut = async (session) => { + const messages = await (await fetch(process.env.NEXT_PUBLIC_API_URL + '/session/message/?sessionId=' + session.id, { + method: 'GET', + headers: { + 'Content-Type': 'application/json' + }, + })).json() + + const summary = await (await fetch(process.env.NEXT_PUBLIC_API_URL + '/session/summary/?sessionId=' + session.id, { + method: 'GET', + headers: { + 'Content-Type': 'application/json' + }, + })).json() + + session.messages = messages.messages; + session.summary = summary.summary; + console.log(session) + + setFocusSession(session) + } + + const transfer = async () => { + console.log(session['token'].sub) + const res = await (await fetch(process.env.NEXT_PUBLIC_API_URL + '/session/transfer/?sessionId=' + focusSession.id, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${session['token'].sub}` + }, + })).json() + await closePop() + } + + const closePop = async () => { + setFocusSession(null) + } + + useEffect(() => { + const interval = setInterval(async () => { + const fetcher = async () => { + const s = await (await fetch(process.env.NEXT_PUBLIC_API_URL + '/session?open=true', { + method: 'GET', + headers: { + 'Content-Type': 'application/json' + } + })).json() + + setSessions(s.sessions) + } + await fetcher() + }, 2000) + + return () => clearInterval(interval) + }, []) + return ( -
+
{ session ? -
-

Hey {session.user.name.split(' ')[0]}!

-

Can you give us your number real quick?

- -
-
- handleInputChange(e, input, setInput)} className="w-full" /> + <> + {focusSession ? +
+ +
+

Caller: {focusSession.callerPhone} | {focusSession.startedAt}

+ +
+

Summary: {focusSession.summary}

+ {focusSession.messages.map(msg => { + return ( +
+

{msg.role}: {msg.content}

+

+
+ ); + })}
-
- + : null + } +
+
+

Hey {session.user.name.split(' ')[0]}!

+

Can you give us your number real quick?

+ +
+
+ handleInputChange(e, input, setInput)} className="w-full" /> +
+
+ +
+
+
+
+

Active Calls

+
+ {sessions.map(session => + popOut(session)} /> + )} +
-
+ + : null } - -
- ); };