From 69dd0b4830d0703c3f1a5b29f6330443697dc526 Mon Sep 17 00:00:00 2001 From: Nareshkumar Rao <_accounts@nareshkumarrao.com> Date: Tue, 27 Jul 2021 17:07:06 +0200 Subject: [PATCH] revert to telegram as unique key --- src/screens/CreateScreen.js | 48 +++++-------------------------------- src/screens/HomeScreen.js | 4 +++- src/screens/LoginScreen.js | 21 +++++++--------- 3 files changed, 18 insertions(+), 55 deletions(-) diff --git a/src/screens/CreateScreen.js b/src/screens/CreateScreen.js index 630e969..8dec631 100644 --- a/src/screens/CreateScreen.js +++ b/src/screens/CreateScreen.js @@ -4,9 +4,7 @@ import { FormControl, FormLabel, Heading, - Input, - Select, - useToast, + Input, useToast } from '@chakra-ui/react'; import axios from 'axios'; import { useState } from 'react'; @@ -14,34 +12,18 @@ import { useDispatch } from 'react-redux'; import { useHistory } from 'react-router-dom'; import { authLogin } from '../features/auth/authSlice'; -function OrgSelect(props) { - const orgs = ['MISI: Solidariti', 'UNDI18']; - const orgOptions = orgs.map(name => { - return ; - }); - - return ( - - ); -} - function Create() { const dispatch = useDispatch(); const toast = useToast(); const history = useHistory(); - const [name, setName] = useState(null); - const [email, setEmail] = useState(null); - const [phoneNumber, setPhoneNumber] = useState(null); - const [org, setOrg] = useState(null); + const [telegram, setTelegram] = useState(null); const [password, setPassword] = useState(null); const handleSubmit = e => { e.preventDefault(); - if (!name | !email | !phoneNumber | !org | !password) { + if (!telegram | !password) { toast({ title: 'Problem!', description: 'Please fill in all the fields', @@ -56,10 +38,7 @@ function Create() { .post( `${process.env.REACT_APP_API_URL}/create`, { - name: name, - email: email, - org: org, - phoneNumber: org, + telegram: telegram, password: password, }, { @@ -105,23 +84,8 @@ function Create() { Create Account
- Name: - setName(e.target.value)} /> - - - Email: - setEmail(e.target.value)} /> - - - Phone Number: - setPhoneNumber(e.target.value)} /> - - - Organization: - setOrg(e.target.value)} - /> + Telegram Username: + setTelegram(e.target.value)} /> Password: diff --git a/src/screens/HomeScreen.js b/src/screens/HomeScreen.js index df420f3..e940355 100644 --- a/src/screens/HomeScreen.js +++ b/src/screens/HomeScreen.js @@ -18,7 +18,9 @@ function QRCode() { } }) .catch(err => { - if (err.response.status === 401) { + if(!err.response){ + console.log("No response... Strange"); + }else if (err.response.status === 401) { dispatch(authLogout()); } }); diff --git a/src/screens/LoginScreen.js b/src/screens/LoginScreen.js index a73aac9..7d3a751 100644 --- a/src/screens/LoginScreen.js +++ b/src/screens/LoginScreen.js @@ -5,7 +5,7 @@ import { FormLabel, Heading, Input, - useToast, + useToast } from '@chakra-ui/react'; import axios from 'axios'; import { React, useState } from 'react'; @@ -14,7 +14,7 @@ import { Redirect, useHistory } from 'react-router-dom'; import { authLogin, authLogout } from '../features/auth/authSlice'; function Login() { - const [email, setEmail] = useState(null); + const [telegram, setTelegram] = useState(null); const [password, setPassword] = useState(null); const toast = useToast(); const history = useHistory(); @@ -24,10 +24,10 @@ function Login() { if (isAuthenticated) return ; const handleSubmit = e => { - if (!email | !password) { + if (!telegram | !password) { toast({ title: 'Invalid Login', - description: 'Please fill in email and password', + description: 'Please fill in Telegram Username and password', status: 'error', duration: 9000, isClosable: true, @@ -46,7 +46,7 @@ function Login() { .post( `${process.env.REACT_APP_API_URL}/login`, { - email: email, + telegram: telegram, password: password, }, { @@ -56,6 +56,7 @@ function Login() { .then(response => { if (response.data.authorized) { dispatch(authLogin()); + toast.closeAll(); history.push('/home'); } else { dispatch(authLogout()); @@ -77,9 +78,6 @@ function Login() { duration: 9000, isClosable: true, }); - }) - .finally(() => { - toast.closeAll(); }); e.preventDefault(); @@ -101,15 +99,14 @@ function Login() { - Email address + Telegram Username: setEmail(event.target.value)} + onChange={event => setTelegram(event.target.value)} /> - Password + Password: