Browse Source

ran prettier

feature/qrscanner
Nareshkumar Rao 3 years ago
parent
commit
0ba8c8151e
  1. 46
      src/screens/ScannerScreen.js

46
src/screens/ScannerScreen.js

@ -1,27 +1,23 @@
import { Button, Divider, Flex, useToast } from "@chakra-ui/react";
import axios from "axios";
import { useEffect, useState } from "react";
import QrReader from "react-qr-reader";
import { useDispatch, useSelector } from "react-redux";
import { Redirect, useHistory } from "react-router-dom";
import { authLogout } from "../features/auth/authSlice";
import { Button, Divider, Flex, useToast } from '@chakra-ui/react';
import axios from 'axios';
import { useEffect, useState } from 'react';
import QrReader from 'react-qr-reader';
import { useDispatch, useSelector } from 'react-redux';
import { Redirect, useHistory } from 'react-router-dom';
import { authLogout } from '../features/auth/authSlice';
function Scanner() {
const toast = useToast();
const history = useHistory();
const dispatch = useDispatch();
const [scanData, setScanData] = useState(null);
const handleError = (err) => {
const handleError = err => {
console.log(err);
};
const handleScan = (res) => {
const handleScan = res => {
if (res && res !== scanData) {
setScanData(res);
}
@ -34,13 +30,15 @@ function Scanner() {
const re = /verify\/.*$/;
const hash = re.exec(scanData);
if (hash) {
axios.post(`${process.env.REACT_APP_API_URL}/verify`,
axios
.post(
`${process.env.REACT_APP_API_URL}/verify`,
{
id: hash[0].substr(7),
},
{ withCredentials: true })
.then((res) => {
{ withCredentials: true }
)
.then(res => {
if (res.data.success) {
if (res.data.loggedIn) {
toast({
@ -49,13 +47,13 @@ function Scanner() {
duration: 2000,
});
} else {
console.log("Time to logout!");
console.log('Time to logout!');
dispatch(authLogout());
history.push("/login");
history.push('/login');
}
}
})
.catch((e) => {
.catch(e => {
toast({
title: 'Bad Verification',
status: 'error',
@ -86,7 +84,13 @@ function Scanner() {
facingMode="environment"
/>
<Divider mb={6} />
<Button onClick={() => { history.push("/home"); }}>Show my QR Code</Button>
<Button
onClick={() => {
history.push('/home');
}}
>
Show my QR Code
</Button>
</Flex>
</Flex>
);

Loading…
Cancel
Save