diff --git a/frontend/src/pages/WhatsAuth/WhatsAuth.js b/frontend/src/pages/WhatsAuth/WhatsAuth.js
index 91d83a4..dec3e5d 100644
--- a/frontend/src/pages/WhatsAuth/WhatsAuth.js
+++ b/frontend/src/pages/WhatsAuth/WhatsAuth.js
@@ -1,12 +1,17 @@
-import React from "react";
+import React, { useState, useEffect } from "react";
+import { useHistory } from "react-router-dom";
+import api from "../../util/api";
import clsx from "clsx";
import MainDrawer from "../../components/Layout/MainDrawer";
+import openSocket from "socket.io-client";
import { makeStyles } from "@material-ui/core/styles";
import Container from "@material-ui/core/Container";
import Grid from "@material-ui/core/Grid";
import Paper from "@material-ui/core/Paper";
+import Bateryinfo from "./components/Bateryinfo";
+import Qrcode from "./components/Qrcode";
const useStyles = makeStyles(theme => ({
root: {
@@ -41,6 +46,47 @@ const useStyles = makeStyles(theme => ({
const WhatsAuth = () => {
const classes = useStyles();
+ const history = useHistory();
+
+ const [qrCode, setQrCode] = useState("");
+ const [session, setSession] = useState({});
+
+ useEffect(() => {
+ const fetchSession = async () => {
+ try {
+ const res = await api.get("/whatsapp/session");
+ setQrCode(res.data.qrcode);
+ setSession(res.data);
+ } catch (err) {
+ console.log(err);
+ }
+ };
+ fetchSession();
+ }, []);
+
+ useEffect(() => {
+ const socket = openSocket("http://localhost:8080");
+
+ socket.on("qrcode", data => {
+ if (data.action === "update") {
+ setQrCode(data.qr);
+ }
+ });
+
+ socket.on("whats_auth", data => {
+ if (data.action === "authentication") {
+ history.push("/chat");
+ setQrCode("");
+ setSession(data.session);
+ }
+ });
+
+ return () => {
+ socket.disconnect();
+ };
+ }, []);
+
+ console.log(session);
const fixedHeightPaper = clsx(classes.paper, classes.fixedHeight);
@@ -52,16 +98,20 @@ const WhatsAuth = () => {
-
-
- Status da conexão
-
-
-
-
- QR Code
-
-
+ {session.status === "pending" ? (
+
+
+
+
+
+ ) : (
+
+
+
+
+
+ )}
+
{/*
paper2
diff --git a/frontend/src/pages/WhatsAuth/components/Bateryinfo.js b/frontend/src/pages/WhatsAuth/components/Bateryinfo.js
new file mode 100644
index 0000000..300df2e
--- /dev/null
+++ b/frontend/src/pages/WhatsAuth/components/Bateryinfo.js
@@ -0,0 +1,34 @@
+import React from "react";
+import Link from "@material-ui/core/Link";
+import { makeStyles } from "@material-ui/core/styles";
+import Typography from "@material-ui/core/Typography";
+
+const useStyles = makeStyles({
+ main: {
+ flex: 1,
+ },
+});
+
+const Bateryinfo = ({ session }) => {
+ const classes = useStyles();
+ return (
+
+
+ Bateria
+
+
+ {(session && session.baterry) || "Não disponível"}
+
+
+ Carregando: {(session && session.plugged) || "Não disponível"}
+
+
+
+ Verificar bateria
+
+
+
+ );
+};
+
+export default Bateryinfo;
diff --git a/frontend/src/pages/WhatsAuth/components/Qrcode.js b/frontend/src/pages/WhatsAuth/components/Qrcode.js
new file mode 100644
index 0000000..8a76216
--- /dev/null
+++ b/frontend/src/pages/WhatsAuth/components/Qrcode.js
@@ -0,0 +1,25 @@
+import React from "react";
+import QRCode from "qrcode.react";
+import { makeStyles } from "@material-ui/core/styles";
+import Typography from "@material-ui/core/Typography";
+
+const useStyles = makeStyles({
+ main: {
+ flex: 1,
+ },
+});
+
+const Qrcode = ({ qrCode }) => {
+ const classes = useStyles();
+
+ return (
+
+
+ Leia o QrCode para iniciar a sessão
+
+
+
+ );
+};
+
+export default Qrcode;
diff --git a/frontend/src/routes.js b/frontend/src/routes.js
index 627d7c4..5cb63dd 100644
--- a/frontend/src/routes.js
+++ b/frontend/src/routes.js
@@ -57,6 +57,7 @@ const Routes = () => {
+