Browse Source

formatting

feature/qrscanner
Nareshkumar Rao 3 years ago
parent
commit
81f0a541f9
  1. 9
      README.md
  2. 43
      src/screens/CreateScreen.js
  3. 16
      src/screens/HomeScreen.js
  4. 9
      src/screens/LoginScreen.js
  5. 17
      src/screens/SuccessScreen.js

9
README.md

@ -3,24 +3,29 @@
This app was created to serve the need for easy to use contact tracing. This app was created to serve the need for easy to use contact tracing.
## Usage ## Usage
The app should work as such: The app should work as such:
1. Group/Organization leaders will be created an account on the app. 1. Group/Organization leaders will be created an account on the app.
2. Upon logging in, they will see a QR code that they can display 2. Upon logging in, they will see a QR code that they can display
3. Their members can scan this QR code, in order to create their own accounts. This way, there each member has a "parent" member, and all memberships can be traced. 3. Their members can scan this QR code, in order to create their own accounts. This way, there each member has a "parent" member, and all memberships can be traced.
4. Upon creating their account, new members will also have a QR Code they can display. 4. Upon creating their account, new members will also have a QR Code they can display.
5. Other members can scan each other QR codes in order to register a *Contact* in the backend.
6. All *Contacts* between members can be retrievable from the backend at a later time.
5. Other members can scan each other QR codes in order to register a _Contact_ in the backend.
6. All _Contacts_ between members can be retrievable from the backend at a later time.
## Development ## Development
### Prerequisites ### Prerequisites
- NodeJS - NodeJS
- Yarn - Yarn
### Building ### Building
- Use `yarn install` to install the necessary packages - Use `yarn install` to install the necessary packages
- Use `yarn start` to start app in development mode in [http://localhost:3000](http://localhost:3000) - Use `yarn start` to start app in development mode in [http://localhost:3000](http://localhost:3000)
- Use `yarn build` to build an optimized app for production. - Use `yarn build` to build an optimized app for production.
### .env ### .env
Don't forget to copy the .env.template to .env and fill in the values Don't forget to copy the .env.template to .env and fill in the values

43
src/screens/CreateScreen.js

@ -1,4 +1,13 @@
import { Button, Flex, FormControl, FormLabel, Heading, Input, Select, useToast } from '@chakra-ui/react';
import {
Button,
Flex,
FormControl,
FormLabel,
Heading,
Input,
Select,
useToast,
} from '@chakra-ui/react';
import axios from 'axios'; import axios from 'axios';
import { useState } from 'react'; import { useState } from 'react';
import { useDispatch } from 'react-redux'; import { useDispatch } from 'react-redux';
@ -6,11 +15,9 @@ import { useHistory } from 'react-router-dom';
import { authLogin } from '../features/auth/authSlice'; import { authLogin } from '../features/auth/authSlice';
function OrgSelect(props) { function OrgSelect(props) {
const orgs = ["MISI: Solidariti", "UNDI18"];
const orgOptions = orgs.map((name) => {
return (
<option value={name}>{name}</option>
)
const orgs = ['MISI: Solidariti', 'UNDI18'];
const orgOptions = orgs.map(name => {
return <option value={name}>{name}</option>;
}); });
return ( return (
@ -21,7 +28,6 @@ function OrgSelect(props) {
} }
function Create() { function Create() {
const dispatch = useDispatch(); const dispatch = useDispatch();
const toast = useToast(); const toast = useToast();
const history = useHistory(); const history = useHistory();
@ -32,7 +38,7 @@ function Create() {
const [org, setOrg] = useState(null); const [org, setOrg] = 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 (!name | !email | !phoneNumber | !org | !password) {
@ -78,14 +84,15 @@ function Create() {
if (e.response.status === 401) { if (e.response.status === 401) {
toast({ toast({
title: 'Verification Error', title: 'Verification Error',
description: "You couldn't be verified. Please try scanning the verification QR Code again.",
description:
"You couldn't be verified. Please try scanning the verification QR Code again.",
status: 'error', status: 'error',
duration: 9000, duration: 9000,
isClosable: true, isClosable: true,
}); });
} }
}); });
}
};
return ( return (
<Flex <Flex
@ -95,9 +102,7 @@ function Create() {
justifyContent="center" justifyContent="center"
> >
<Flex direction="column" background="white" p={12} rounded={6}> <Flex direction="column" background="white" p={12} rounded={6}>
<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> <FormLabel>Name:</FormLabel>
@ -113,17 +118,23 @@ function Create() {
</FormControl> </FormControl>
<FormControl mb={6}> <FormControl mb={6}>
<FormLabel>Organization:</FormLabel> <FormLabel>Organization:</FormLabel>
<OrgSelect placeholder="Select Organization" onChange={e => setOrg(e.target.value)} />
<OrgSelect
placeholder="Select Organization"
onChange={e => setOrg(e.target.value)}
/>
</FormControl> </FormControl>
<FormControl mb={6}> <FormControl mb={6}>
<FormLabel>Password:</FormLabel> <FormLabel>Password:</FormLabel>
<Input type="password" onChange={e => setPassword(e.target.value)} />
<Input
type="password"
onChange={e => setPassword(e.target.value)}
/>
</FormControl> </FormControl>
<Button type="submit">Create!</Button> <Button type="submit">Create!</Button>
</form> </form>
</Flex> </Flex>
</Flex> </Flex>
)
);
} }
export default Create; export default Create;

16
src/screens/HomeScreen.js

@ -22,14 +22,13 @@ function QRCode() {
dispatch(authLogout()); dispatch(authLogout());
} }
}); });
}, [])
}, []);
if (url) { if (url) {
return <Image src={url} />; return <Image src={url} />;
} else { } else {
return <Spinner />; return <Spinner />;
} }
} }
function Home() { function Home() {
@ -43,9 +42,18 @@ function Home() {
alignItems="center" alignItems="center"
justifyContent="center" justifyContent="center"
> >
<Flex direction="column" background="white" p={12} rounded={6} id="QRFlex">
<Flex
direction="column"
background="white"
p={12}
rounded={6}
id="QRFlex"
>
<QRCode /> <QRCode />
<Text align="center" fontSize="lg">This is your QR code. Show this to others to allow them to confirm a contact, or allow them to create an account!</Text>
<Text align="center" fontSize="lg">
This is your QR code. Show this to others to allow them to confirm a
contact, or allow them to create an account!
</Text>
</Flex> </Flex>
</Flex> </Flex>
); );

9
src/screens/LoginScreen.js

@ -1,10 +1,11 @@
import { import {
Button, Flex,
Button,
Flex,
FormControl, FormControl,
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';
@ -77,7 +78,9 @@ function Login() {
isClosable: true, isClosable: true,
}); });
}) })
.finally(() => { toast.closeAll(); });
.finally(() => {
toast.closeAll();
});
e.preventDefault(); e.preventDefault();
}; };

17
src/screens/SuccessScreen.js

@ -1,5 +1,5 @@
import { Button, Flex, Heading, Text } from "@chakra-ui/react";
import { useHistory } from "react-router-dom";
import { Button, Flex, Heading, Text } from '@chakra-ui/react';
import { useHistory } from 'react-router-dom';
function Success() { function Success() {
const history = useHistory(); const history = useHistory();
@ -13,8 +13,17 @@ function Success(){
> >
<Flex direction="column" background="white" p={12} rounded={6}> <Flex direction="column" background="white" p={12} rounded={6}>
<Heading>Success!</Heading> <Heading>Success!</Heading>
<Text fontSize="lg">We have succesfully saved your contact! Stay safe out there, and let others scan your QR code too!</Text>
<Button onClick={()=>{history.push("/home")}}>Return home</Button>
<Text fontSize="lg">
We have succesfully saved your contact! Stay safe out there, and let
others scan your QR code too!
</Text>
<Button
onClick={() => {
history.push('/home');
}}
>
Return home
</Button>
</Flex> </Flex>
</Flex> </Flex>
); );

Loading…
Cancel
Save