Browse Source

revert to telegram as unique key

feature/qrscanner
Nareshkumar Rao 3 years ago
parent
commit
69dd0b4830
  1. 48
      src/screens/CreateScreen.js
  2. 4
      src/screens/HomeScreen.js
  3. 21
      src/screens/LoginScreen.js

48
src/screens/CreateScreen.js

@ -4,9 +4,7 @@ import {
FormControl, FormControl,
FormLabel, FormLabel,
Heading, Heading,
Input,
Select,
useToast,
Input, useToast
} from '@chakra-ui/react'; } from '@chakra-ui/react';
import axios from 'axios'; import axios from 'axios';
import { useState } from 'react'; import { useState } from 'react';
@ -14,34 +12,18 @@ import { useDispatch } from 'react-redux';
import { useHistory } from 'react-router-dom'; import { useHistory } from 'react-router-dom';
import { authLogin } from '../features/auth/authSlice'; import { authLogin } from '../features/auth/authSlice';
function OrgSelect(props) {
const orgs = ['MISI: Solidariti', 'UNDI18'];
const orgOptions = orgs.map(name => {
return <option value={name}>{name}</option>;
});
return (
<Select placeholder={props.placeholder} onChange={props.onChange}>
{orgOptions}
</Select>
);
}
function Create() { function Create() {
const dispatch = useDispatch(); const dispatch = useDispatch();
const toast = useToast(); const toast = useToast();
const history = useHistory(); 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 [password, setPassword] = useState(null);
const handleSubmit = e => { const handleSubmit = e => {
e.preventDefault(); e.preventDefault();
if (!name | !email | !phoneNumber | !org | !password) {
if (!telegram | !password) {
toast({ toast({
title: 'Problem!', title: 'Problem!',
description: 'Please fill in all the fields', description: 'Please fill in all the fields',
@ -56,10 +38,7 @@ function Create() {
.post( .post(
`${process.env.REACT_APP_API_URL}/create`, `${process.env.REACT_APP_API_URL}/create`,
{ {
name: name,
email: email,
org: org,
phoneNumber: org,
telegram: telegram,
password: password, password: password,
}, },
{ {
@ -105,23 +84,8 @@ function Create() {
<Heading mb={6}>Create Account</Heading> <Heading mb={6}>Create Account</Heading>
<form onSubmit={handleSubmit}> <form onSubmit={handleSubmit}>
<FormControl mb={6}> <FormControl mb={6}>
<FormLabel>Name:</FormLabel>
<Input onChange={e => setName(e.target.value)} />
</FormControl>
<FormControl mb={6}>
<FormLabel>Email:</FormLabel>
<Input type="email" onChange={e => setEmail(e.target.value)} />
</FormControl>
<FormControl mb={6}>
<FormLabel>Phone Number:</FormLabel>
<Input onChange={e => setPhoneNumber(e.target.value)} />
</FormControl>
<FormControl mb={6}>
<FormLabel>Organization:</FormLabel>
<OrgSelect
placeholder="Select Organization"
onChange={e => setOrg(e.target.value)}
/>
<FormLabel>Telegram Username:</FormLabel>
<Input onChange={e => setTelegram(e.target.value)} />
</FormControl> </FormControl>
<FormControl mb={6}> <FormControl mb={6}>
<FormLabel>Password:</FormLabel> <FormLabel>Password:</FormLabel>

4
src/screens/HomeScreen.js

@ -18,7 +18,9 @@ function QRCode() {
} }
}) })
.catch(err => { .catch(err => {
if (err.response.status === 401) {
if(!err.response){
console.log("No response... Strange");
}else if (err.response.status === 401) {
dispatch(authLogout()); dispatch(authLogout());
} }
}); });

21
src/screens/LoginScreen.js

@ -5,7 +5,7 @@ import {
FormLabel, FormLabel,
Heading, Heading,
Input, Input,
useToast,
useToast
} from '@chakra-ui/react'; } from '@chakra-ui/react';
import axios from 'axios'; import axios from 'axios';
import { React, useState } from 'react'; import { React, useState } from 'react';
@ -14,7 +14,7 @@ import { Redirect, useHistory } from 'react-router-dom';
import { authLogin, authLogout } from '../features/auth/authSlice'; import { authLogin, authLogout } from '../features/auth/authSlice';
function Login() { function Login() {
const [email, setEmail] = useState(null);
const [telegram, setTelegram] = useState(null);
const [password, setPassword] = useState(null); const [password, setPassword] = useState(null);
const toast = useToast(); const toast = useToast();
const history = useHistory(); const history = useHistory();
@ -24,10 +24,10 @@ function Login() {
if (isAuthenticated) return <Redirect to="/home" />; if (isAuthenticated) return <Redirect to="/home" />;
const handleSubmit = e => { const handleSubmit = e => {
if (!email | !password) {
if (!telegram | !password) {
toast({ toast({
title: 'Invalid Login', title: 'Invalid Login',
description: 'Please fill in email and password',
description: 'Please fill in Telegram Username and password',
status: 'error', status: 'error',
duration: 9000, duration: 9000,
isClosable: true, isClosable: true,
@ -46,7 +46,7 @@ function Login() {
.post( .post(
`${process.env.REACT_APP_API_URL}/login`, `${process.env.REACT_APP_API_URL}/login`,
{ {
email: email,
telegram: telegram,
password: password, password: password,
}, },
{ {
@ -56,6 +56,7 @@ function Login() {
.then(response => { .then(response => {
if (response.data.authorized) { if (response.data.authorized) {
dispatch(authLogin()); dispatch(authLogin());
toast.closeAll();
history.push('/home'); history.push('/home');
} else { } else {
dispatch(authLogout()); dispatch(authLogout());
@ -77,9 +78,6 @@ function Login() {
duration: 9000, duration: 9000,
isClosable: true, isClosable: true,
}); });
})
.finally(() => {
toast.closeAll();
}); });
e.preventDefault(); e.preventDefault();
@ -101,15 +99,14 @@ function Login() {
</Heading> </Heading>
<form onSubmit={handleSubmit}> <form onSubmit={handleSubmit}>
<FormControl mb={6}> <FormControl mb={6}>
<FormLabel>Email address</FormLabel>
<FormLabel>Telegram Username:</FormLabel>
<Input <Input
type="email"
colorScheme="teal" colorScheme="teal"
onChange={event => setEmail(event.target.value)}
onChange={event => setTelegram(event.target.value)}
/> />
</FormControl> </FormControl>
<FormControl mb={6}> <FormControl mb={6}>
<FormLabel>Password</FormLabel>
<FormLabel>Password:</FormLabel>
<Input <Input
type="password" type="password"
colorScheme="teal" colorScheme="teal"

Loading…
Cancel
Save