├── .gitignore ├── README.md ├── jsconfig.json ├── package.json ├── public ├── assets │ ├── abobora.png │ ├── batata.png │ ├── brocolis.png │ ├── pepino.png │ └── tomate.png └── index.html ├── src ├── assets │ └── logo.svg ├── common │ └── contexts │ │ ├── Carrinho.js │ │ ├── Pagamento.js │ │ └── Usuario.js ├── components │ └── Produto │ │ ├── index.js │ │ └── styles.js ├── index.css ├── index.js ├── pages │ ├── Carrinho │ │ ├── index.js │ │ └── styles.js │ ├── Feira │ │ ├── NavBar │ │ │ ├── index.js │ │ │ └── styles.js │ │ ├── feira.json │ │ ├── index.js │ │ └── styles.js │ └── Login │ │ ├── index.js │ │ └── styles.js └── router.js └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `yarn start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 13 | 14 | The page will reload if you make edits.\ 15 | You will also see any lint errors in the console. 16 | 17 | ### `yarn test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `yarn build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `yarn eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 35 | 36 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 37 | 38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 39 | 40 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | 48 | ### Code Splitting 49 | 50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) 51 | 52 | ### Analyzing the Bundle Size 53 | 54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) 55 | 56 | ### Making a Progressive Web App 57 | 58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) 59 | 60 | ### Advanced Configuration 61 | 62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) 63 | 64 | ### Deployment 65 | 66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) 67 | 68 | ### `yarn build` fails to minify 69 | 70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) 71 | -------------------------------------------------------------------------------- /jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": "src", 4 | "paths": { 5 | "components": ["components"], 6 | "pages": ["pages"], 7 | "common": ["common"] 8 | } 9 | }, 10 | "exclude": ["node_modules"], 11 | "include": ["src"] 12 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "course-1-context", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@material-ui/core": "^4.12.1", 7 | "@material-ui/icons": "^4.11.2", 8 | "@material-ui/lab": "^4.0.0-alpha.60", 9 | "@testing-library/jest-dom": "^5.11.4", 10 | "@testing-library/react": "^11.1.0", 11 | "@testing-library/user-event": "^12.1.10", 12 | "react": "^17.0.2", 13 | "react-dom": "^17.0.2", 14 | "react-router-dom": "^5.2.0", 15 | "react-scripts": "4.0.3", 16 | "styled-components": "^5.3.0", 17 | "web-vitals": "^1.0.1" 18 | }, 19 | "scripts": { 20 | "start": "react-scripts start", 21 | "build": "react-scripts build", 22 | "test": "react-scripts test", 23 | "eject": "react-scripts eject" 24 | }, 25 | "eslintConfig": { 26 | "extends": [ 27 | "react-app", 28 | "react-app/jest" 29 | ] 30 | }, 31 | "browserslist": { 32 | "production": [ 33 | ">0.2%", 34 | "not dead", 35 | "not op_mini all" 36 | ], 37 | "development": [ 38 | "last 1 chrome version", 39 | "last 1 firefox version", 40 | "last 1 safari version" 41 | ] 42 | }, 43 | "devDependencies": {} 44 | } 45 | -------------------------------------------------------------------------------- /public/assets/abobora.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alura-cursos/react-context/a1797c1c6fe386f9d9132696a943f5dc77423ff5/public/assets/abobora.png -------------------------------------------------------------------------------- /public/assets/batata.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alura-cursos/react-context/a1797c1c6fe386f9d9132696a943f5dc77423ff5/public/assets/batata.png -------------------------------------------------------------------------------- /public/assets/brocolis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alura-cursos/react-context/a1797c1c6fe386f9d9132696a943f5dc77423ff5/public/assets/brocolis.png -------------------------------------------------------------------------------- /public/assets/pepino.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alura-cursos/react-context/a1797c1c6fe386f9d9132696a943f5dc77423ff5/public/assets/pepino.png -------------------------------------------------------------------------------- /public/assets/tomate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alura-cursos/react-context/a1797c1c6fe386f9d9132696a943f5dc77423ff5/public/assets/tomate.png -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | React Context 9 | 10 | 11 | 12 |
13 | 14 | 15 | -------------------------------------------------------------------------------- /src/assets/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/common/contexts/Carrinho.js: -------------------------------------------------------------------------------- 1 | import { createContext, useContext, useEffect, useState } from 'react'; 2 | import { usePagamento } from './Pagamento'; 3 | import { UsuarioContext } from './Usuario'; 4 | 5 | const CarrinhoContext = createContext(); 6 | CarrinhoContext.displayName = "Carrinho" 7 | 8 | export default function CarrinhoProvider({ children }) { 9 | const [carrinho, setCarrinho] = useState([]); 10 | const [quantidadeCarrinho, setQuantidadeCarrinho] = useState(0); 11 | const [valorTotal, setValorTotal] = useState(0); 12 | return ( 13 | 23 | {children} 24 | 25 | ) 26 | } 27 | 28 | export function useCarrinhoContext() { 29 | const { 30 | carrinho, 31 | setCarrinho, 32 | quantidadeCarrinho, 33 | setQuantidadeCarrinho, 34 | valorTotal, 35 | setValorTotal 36 | } = useContext(CarrinhoContext); 37 | 38 | const { 39 | saldo, 40 | setSaldo 41 | } = useContext(UsuarioContext); 42 | 43 | const { formaPagamento } = usePagamento(); 44 | 45 | const mudarQuantidade = (id, quantidade) => carrinho.map(item => { 46 | if (item.id === id) item.quantidade += quantidade; 47 | return item; 48 | }); 49 | 50 | function adicionarProduto(novoProduto) { 51 | const temOProduto = carrinho.some(item => item.id === novoProduto.id); 52 | let novoCarrinho = [...carrinho]; 53 | if (!temOProduto) { 54 | novoProduto.quantidade = 1; 55 | novoCarrinho.push(novoProduto); 56 | return setCarrinho(novoCarrinho); 57 | } 58 | novoCarrinho = mudarQuantidade(novoProduto.id, 1); 59 | setCarrinho(novoCarrinho); 60 | }; 61 | 62 | function removerProduto(id) { 63 | const produto = carrinho.find(item => item.id === id); 64 | const ultimo = produto.quantidade === 1; 65 | let novoCarrinho; 66 | if (ultimo) { 67 | novoCarrinho = carrinho.filter(item => item.id !== id); 68 | return setCarrinho(novoCarrinho); 69 | } 70 | novoCarrinho = mudarQuantidade(id, -1); 71 | setCarrinho(novoCarrinho); 72 | } 73 | 74 | function comprar() { 75 | setCarrinho([]); 76 | setSaldo(saldo - valorTotal); 77 | } 78 | 79 | useEffect(() => { 80 | let { novaQuantidade, novoTotal } = carrinho.reduce((contador, novoItem) => ({ 81 | novaQuantidade: contador.novaQuantidade + novoItem.quantidade, 82 | novoTotal: contador.novoTotal + (novoItem.valor * novoItem.quantidade) 83 | }), { novaQuantidade: 0, novoTotal: 0 }); 84 | setQuantidadeCarrinho(novaQuantidade); 85 | setValorTotal(novoTotal * formaPagamento.juros); 86 | },[carrinho, formaPagamento, setQuantidadeCarrinho, setValorTotal]) 87 | 88 | return { 89 | carrinho, 90 | adicionarProduto, 91 | removerProduto, 92 | quantidadeCarrinho, 93 | valorTotal, 94 | comprar 95 | } 96 | } -------------------------------------------------------------------------------- /src/common/contexts/Pagamento.js: -------------------------------------------------------------------------------- 1 | import { createContext, useContext, useState } from 'react'; 2 | 3 | const PagamentoContext = createContext(); 4 | PagamentoContext.displayName = "Pagamento" 5 | 6 | export function PagamentoProvider({ children }) { 7 | const tiposPagamento = [{ 8 | nome: "Boleto", 9 | juros: 1, 10 | id: 1 11 | }, { 12 | nome: "Cartão de crédito", 13 | juros: 1.3, 14 | id: 2 15 | }, { 16 | nome: "PIX", 17 | juros: 1, 18 | id: 3 19 | }, { 20 | nome: "Crediário", 21 | juros: 1.5, 22 | id: 4 23 | }] 24 | const [formaPagamento, setFormaPagamento] = useState(tiposPagamento[0]); 25 | 26 | return ( 27 | 32 | {children} 33 | 34 | ) 35 | } 36 | 37 | export function usePagamento() { 38 | const { 39 | formaPagamento, 40 | setFormaPagamento, 41 | tiposPagamento 42 | } = useContext(PagamentoContext); 43 | 44 | function mudarFormaPagamento(id) { 45 | const formaNova = tiposPagamento.find(pagamento => pagamento.id === id); 46 | setFormaPagamento(formaNova); 47 | } 48 | 49 | return { 50 | formaPagamento, 51 | mudarFormaPagamento, 52 | tiposPagamento 53 | } 54 | } -------------------------------------------------------------------------------- /src/common/contexts/Usuario.js: -------------------------------------------------------------------------------- 1 | import { createContext, useState } from 'react'; 2 | 3 | export const UsuarioContext = createContext(); 4 | UsuarioContext.displayName = "Usuário" 5 | 6 | export default function UsuarioProvider({ children }) { 7 | const [nome, setNome] = useState(''); 8 | const [saldo, setSaldo] = useState(0); 9 | return ( 10 | 18 | {children} 19 | 20 | ) 21 | } -------------------------------------------------------------------------------- /src/components/Produto/index.js: -------------------------------------------------------------------------------- 1 | import { Container } from './styles'; 2 | import { memo, useContext } from 'react'; 3 | import { IconButton } from '@material-ui/core'; 4 | import AddIcon from '@material-ui/icons/Add'; 5 | import RemoveIcon from '@material-ui/icons/Remove'; 6 | import { useCarrinhoContext } from 'common/contexts/Carrinho'; 7 | import { UsuarioContext } from 'common/contexts/Usuario'; 8 | 9 | function Produto({ 10 | nome, 11 | foto, 12 | id, 13 | valor, 14 | unidade 15 | }) { 16 | const { carrinho, adicionarProduto, removerProduto, valorTotal } = useCarrinhoContext(); 17 | const { saldo } = useContext(UsuarioContext); 18 | const itemNoCarrinho = carrinho.find(item => item.id === id); 19 | return ( 20 | 21 |
22 | {`foto 26 |

27 | {nome} - R$ {valor?.toFixed(2)} Kg 28 |

29 |
30 |
31 | removerProduto(id)} 33 | disabled={!itemNoCarrinho || itemNoCarrinho.quantidade === 0} 34 | color="secondary" 35 | > 36 | 37 | 38 | {itemNoCarrinho?.quantidade || 0} 39 | saldo} 41 | onClick={() => adicionarProduto({ 42 | nome, 43 | foto, 44 | id, 45 | valor, 46 | unidade 47 | })} 48 | color="primary" 49 | > 50 | 51 | 52 |
53 |
54 | ) 55 | } 56 | 57 | export default memo(Produto) -------------------------------------------------------------------------------- /src/components/Produto/styles.js: -------------------------------------------------------------------------------- 1 | import styled from 'styled-components'; 2 | import Card from '@material-ui/core/Card'; 3 | 4 | export const Container = styled(Card)` 5 | align-items: center; 6 | display: flex; 7 | justify-content: space-between; 8 | padding: 20px; 9 | width: 100%; 10 | div { 11 | align-items: center; 12 | display: flex; 13 | gap: 20px; 14 | p { 15 | font-size: 22px; 16 | font-weight: bold; 17 | padding: 5px 0 0 5px; 18 | } 19 | span { 20 | font-size: 16px; 21 | } 22 | } 23 | `; -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | @import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@100;400;700&display=swap'); 2 | 3 | * { 4 | box-sizing: border-box; 5 | font-family: 'Montserrat', sans-serif; 6 | margin: 0; 7 | padding: 0; 8 | } 9 | 10 | html, body { 11 | background-color: #F6F6F6; 12 | margin: 0; 13 | padding: 0; 14 | } -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import { ThemeProvider, createTheme } from '@material-ui/core/styles'; 2 | import { StylesProvider } from '@material-ui/core/styles'; 3 | import React from 'react'; 4 | import ReactDOM from 'react-dom'; 5 | import Routes from './router'; 6 | import './index.css'; 7 | 8 | const theme = createTheme({ 9 | palette: { 10 | primary: { 11 | main: '#2A9F85' 12 | }, 13 | secondary: { 14 | main: '#FF7070' 15 | }, 16 | } 17 | }) 18 | 19 | ReactDOM.render( 20 | 21 | 22 | 23 | 24 | 25 | 26 | , 27 | document.getElementById('root') 28 | ); 29 | -------------------------------------------------------------------------------- /src/pages/Carrinho/index.js: -------------------------------------------------------------------------------- 1 | import { Button, MenuItem, Select, Snackbar, InputLabel } from '@material-ui/core'; 2 | import MuiAlert from '@material-ui/lab/Alert'; 3 | import { useCarrinhoContext } from 'common/contexts/Carrinho'; 4 | import Produto from 'components/Produto'; 5 | import { useContext, useMemo, useState } from 'react'; 6 | import { Container, Voltar, TotalContainer, PagamentoContainer} from './styles'; 7 | import { useHistory } from 'react-router-dom'; 8 | import { UsuarioContext } from 'common/contexts/Usuario'; 9 | import { usePagamento } from 'common/contexts/Pagamento'; 10 | 11 | function Carrinho() { 12 | const { 13 | carrinho, 14 | quantidadeCarrinho, 15 | comprar, 16 | valorTotal = 0 17 | } = useCarrinhoContext(); 18 | const { saldo = 0 } = useContext(UsuarioContext); 19 | const { 20 | formaPagamento, 21 | mudarFormaPagamento, 22 | tiposPagamento 23 | } = usePagamento(); 24 | const [openSnackbar, setOpenSnackbar] = useState(false); 25 | const history = useHistory(); 26 | const total = useMemo(() => saldo - valorTotal, [saldo, valorTotal]); 27 | return ( 28 | 29 | 30 |

31 | Carrinho 32 |

33 | {carrinho.map((produto) => ( 34 | 38 | ))} 39 | 40 | Forma de Pagamento 41 | 54 | 55 | 56 |
57 |

Total no Carrinho:

58 | R$ {valorTotal.toFixed(2)} 59 |
60 |
61 |

Saldo:

62 | R$ {saldo.toFixed(2)} 63 |
64 |
65 |

Saldo Total:

66 | R$ {total.toFixed(2)} 67 |
68 |
69 | 80 | setOpenSnackbar(false)} 89 | > 90 | setOpenSnackbar(false)} 92 | severity="success" 93 | > 94 | Compra feita com sucesso! 95 | 96 | 97 |
98 | ) 99 | } 100 | 101 | export default Carrinho; -------------------------------------------------------------------------------- /src/pages/Carrinho/styles.js: -------------------------------------------------------------------------------- 1 | import { FormControl, IconButton } from '@material-ui/core'; 2 | import styled from 'styled-components'; 3 | import ArrowBackIcon from '@material-ui/icons/ArrowBack'; 4 | const titleGray = '#464646'; 5 | 6 | export const Container = styled.main` 7 | align-items: center; 8 | display: flex; 9 | flex-direction: column; 10 | gap: 20px; 11 | min-height: 100vh; 12 | padding: 20px; 13 | position: relative; 14 | @media(min-width: 768px) { 15 | margin: 0 auto; 16 | width: 50%; 17 | } 18 | h2 { 19 | color: ${titleGray}; 20 | font-size: 32px; 21 | } 22 | `; 23 | 24 | export const Voltar = styled(IconButton).attrs({ 25 | children: 26 | })` 27 | left: 20px; 28 | position: absolute; 29 | top: 15px; 30 | ` 31 | 32 | export const TotalContainer = styled.section` 33 | margin-top: 20px; 34 | > div { 35 | align-items: center; 36 | display: flex; 37 | gap: 20px; 38 | justify-content: space-between; 39 | h2 { 40 | color: ${titleGray}; 41 | font-size: 32px; 42 | } 43 | span { 44 | font-size: 30px; 45 | } 46 | } 47 | ` 48 | 49 | export const PagamentoContainer = styled(FormControl)` 50 | width: 100%; 51 | ` -------------------------------------------------------------------------------- /src/pages/Feira/NavBar/index.js: -------------------------------------------------------------------------------- 1 | import { Nav } from './styles'; 2 | import { ReactComponent as Logo } from 'assets/logo.svg'; 3 | import ShoppingCartIcon from '@material-ui/icons/ShoppingCart'; 4 | import IconButton from '@material-ui/core/IconButton'; 5 | import Badge from '@material-ui/core/Badge'; 6 | import { useCarrinhoContext } from 'common/contexts/Carrinho'; 7 | import { useHistory } from 'react-router-dom'; 8 | 9 | export default function NavBar() { 10 | const { quantidadeCarrinho } = useCarrinhoContext(); 11 | const history = useHistory(); 12 | return ( 13 | 27 | ) 28 | } -------------------------------------------------------------------------------- /src/pages/Feira/NavBar/styles.js: -------------------------------------------------------------------------------- 1 | import styled from 'styled-components'; 2 | 3 | export const Nav = styled.nav` 4 | display: flex; 5 | justify-content: space-between; 6 | margin-bottom: 30px; 7 | padding: 20px; 8 | `; -------------------------------------------------------------------------------- /src/pages/Feira/feira.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "nome": "Tomate", 4 | "foto": "tomate", 5 | "valor": 4.80, 6 | "id": "1" 7 | }, 8 | { 9 | "nome": "Brócolis", 10 | "foto": "brocolis", 11 | "valor": 2.50, 12 | "id": "2" 13 | }, 14 | { 15 | "nome": "Batata", 16 | "foto": "batata", 17 | "valor": 3.60, 18 | "id": "3" 19 | }, 20 | { 21 | "nome": "Pepino", 22 | "foto": "pepino", 23 | "valor": 1.80, 24 | "id": "4" 25 | }, 26 | { 27 | "nome": "Abóbora", 28 | "foto": "abobora", 29 | "valor": 5, 30 | "id": "5" 31 | } 32 | ] -------------------------------------------------------------------------------- /src/pages/Feira/index.js: -------------------------------------------------------------------------------- 1 | import { 2 | Container, 3 | Header, 4 | Lista, 5 | } from './styles'; 6 | import feira from './feira.json'; 7 | import Produto from 'components/Produto'; 8 | import { useContext } from 'react'; 9 | import { UsuarioContext } from 'common/contexts/Usuario'; 10 | import NavBar from './NavBar'; 11 | 12 | 13 | function Feira() { 14 | const { nome, saldo = 0 } = useContext(UsuarioContext); 15 | return ( 16 | 17 | 18 |
19 |
20 |

Olá {nome}!

21 |

Saldo: R${saldo.toFixed(2)}

22 |
23 |

Encontre os melhores produtos orgânicos!

24 |
25 | 26 |

27 | Produtos: 28 |

29 | {feira.map(produto => ( 30 | 34 | ))} 35 |
36 |
37 | ) 38 | } 39 | 40 | export default Feira; -------------------------------------------------------------------------------- /src/pages/Feira/styles.js: -------------------------------------------------------------------------------- 1 | import styled from 'styled-components'; 2 | const titleGray = '#464646'; 3 | 4 | export const Container = styled.main` 5 | min-height: 100vh; 6 | padding: 0 20px; 7 | 8 | @media(min-width: 768px) { 9 | margin: 0 auto; 10 | width: 50%; 11 | } 12 | `; 13 | 14 | export const Header = styled.header` 15 | > div { 16 | align-items: center; 17 | display: flex; 18 | justify-content: space-between; 19 | margin-bottom: 10px; 20 | > h2, > h3 { 21 | color: ${titleGray}; 22 | } 23 | h2 { 24 | font-size: 32px; 25 | } 26 | h3 { 27 | font-size: 26px; 28 | } 29 | } 30 | > p { 31 | color: #A3A3A3; 32 | font-size: 26px; 33 | } 34 | `; 35 | 36 | export const Lista = styled.section` 37 | display: flex; 38 | flex-direction: column; 39 | gap: 10px; 40 | padding: 20px 0; 41 | > h2 { 42 | color: ${titleGray}; 43 | font-size: 32px; 44 | margin-top: 20px; 45 | } 46 | `; -------------------------------------------------------------------------------- /src/pages/Login/index.js: -------------------------------------------------------------------------------- 1 | import { Button } from '@material-ui/core'; 2 | import { 3 | Container, 4 | Titulo, 5 | InputContainer 6 | } from './styles'; 7 | import { useHistory } from 'react-router-dom'; 8 | import { useContext } from 'react'; 9 | import { UsuarioContext } from 'common/contexts/Usuario'; 10 | import { 11 | Input, 12 | InputLabel, 13 | InputAdornment 14 | } from '@material-ui/core'; 15 | 16 | function Login() { 17 | const history = useHistory(); 18 | const { nome, setNome, saldo, setSaldo } = useContext(UsuarioContext); 19 | 20 | 21 | return ( 22 | 23 | 24 | Insira o seu nome 25 | 26 | 27 | 28 | Nome 29 | 30 | setNome(event.target.value)} 34 | /> 35 | 36 | 37 | 38 | Saldo 39 | 40 | setSaldo(Number(event.target.value))} 44 | startAdornment={ 45 | 46 | R$ 47 | 48 | } 49 | /> 50 | 51 | 59 | 60 | ) 61 | }; 62 | 63 | export default Login; -------------------------------------------------------------------------------- /src/pages/Login/styles.js: -------------------------------------------------------------------------------- 1 | import styled from 'styled-components'; 2 | import FormControl from '@material-ui/core/FormControl'; 3 | 4 | export const Container = styled.div` 5 | display: flex; 6 | flex-direction: column; 7 | padding: 0 20px; 8 | 9 | @media(min-width: 768px) { 10 | margin: 0 auto; 11 | width: 60%; 12 | } 13 | `; 14 | 15 | export const Titulo = styled.h2` 16 | margin-bottom: 20px; 17 | margin-top: 50px; 18 | `; 19 | 20 | export const InputContainer = styled(FormControl)` 21 | margin-bottom: 30px; 22 | ` -------------------------------------------------------------------------------- /src/router.js: -------------------------------------------------------------------------------- 1 | import { BrowserRouter as Router, Route, Switch } from 'react-router-dom'; 2 | import Login from 'pages/Login'; 3 | import Feira from 'pages/Feira'; 4 | import UsuarioProvider from 'common/contexts/Usuario'; 5 | import CarrinhoProvider from 'common/contexts/Carrinho'; 6 | import Carrinho from 'pages/Carrinho'; 7 | import { PagamentoProvider } from 'common/contexts/Pagamento'; 8 | 9 | export default function Routes() { 10 | return ( 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | ) 31 | }; --------------------------------------------------------------------------------