-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preparando review #1
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Olá! Eu gostei bastante das soluções que você desenvolveu ao longo do projeto,
só tenho a acrescentar algumas coisas quanto a semântica.
Buscar por mensagens de commits mais descritivos e usar o .gitignore para ignorar o node_modules.
Bom trabalho!
<form onSubmit={addRegister}> | ||
<Input type="number" value={amount} setValue={setAmount} disabled={loading} placeholder="Valor" /> | ||
<Input type="text" value={description} setValue={setDescription} disabled={loading} placeholder="Descrição" /> | ||
<Button type="submit">{loading ? <ThreeDots /> : "Salvar entrada"}</Button> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gostei bastante desse recurso visual. Bom trabalho! 👍🏽
import Input from "./Input"; | ||
import Button from "./Button"; | ||
import {Container, Back} from "./Styles"; | ||
import { Link, useHistory } from "react-router-dom"; | ||
import UserContext from './contexts/UserContext'; | ||
import { useContext, useState } from "react"; | ||
import axios from "axios"; | ||
import ThreeDots from "./ThreeDots"; | ||
|
||
export default function CashOut() { | ||
const { user } = useContext(UserContext); | ||
const [amount, setAmount] = useState(""); | ||
const [description, setDescription] = useState(""); | ||
const [loading, setLoading] = useState(false); | ||
const history = useHistory() | ||
|
||
function addNewRegister(e) { | ||
e.preventDefault(); | ||
|
||
const config = { headers: { Authorization: `Bearer ${user}` } }; | ||
|
||
if (amount >= 0) return alert("Você deve adicionar saídas com valores negativos!") | ||
|
||
const number = amount?.replace(",", ".") | ||
const value = Number(number).toFixed(2) * 100; | ||
const body = { value, description }; | ||
|
||
const request = axios.post(`http://localhost:4000/cashout`, body, config); | ||
setLoading(true); | ||
request.then(() => { | ||
setAmount(""); | ||
setDescription(""); | ||
history.push("/home") | ||
setLoading(false); | ||
}) | ||
request.catch(() => { | ||
alert("Algo deu errado!") | ||
setLoading(false); | ||
}) | ||
} | ||
return ( | ||
<> | ||
<Container> | ||
<p>Nova Saída</p> | ||
<form onSubmit={addNewRegister}> | ||
<Input type="number" value={amount} setValue={setAmount} disabled={loading} placeholder="Valor" /> | ||
<Input type="text" value={description} setValue={setDescription} disabled={loading} placeholder="Descrição" /> | ||
<Button type="submit">{loading ? <ThreeDots /> : "Salvar saída"}</Button> | ||
</form> | ||
</Container> | ||
<Link to="/home"><Back>Voltar</Back></Link> | ||
</> | ||
) | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Poderíamos ter um componente só para lidar com a entrada e saída e fazer o controle através de uma variável isso reduziria o código duplicado.
No description provided.