Last active
June 24, 2021 02:47
-
-
Save lucasgomesoficial/594db5e3d7af725d42a291195466bfcf to your computer and use it in GitHub Desktop.
Como usar a API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from 'react' | |
| import api from '../../services/api' | |
| import { | |
| InputDescricao, | |
| MainContainer, | |
| ContainerPagamento, | |
| SelectEstilizado, | |
| InputServico, | |
| BotaoOferecerServico, | |
| InputDataEstilizado | |
| } from './styled' | |
| export default class MainCadastro extends React.Component { | |
| state = { | |
| inputTitle: '', | |
| inputPrice: '', | |
| inputDescription: '', | |
| inputPaymentMethods: [], | |
| inputDueDate: '' | |
| } | |
| createJob = () => { | |
| try { | |
| api.post('/jobs', { | |
| title: this.state.inputTitle, | |
| description: this.state.inputDescription, | |
| price: this.state.inputPrice, | |
| paymentMethods: [...this.state.inputPaymentMethods], | |
| dueDate: this.state.inputDueDate | |
| }) | |
| alert('Serviço Cadastrado') | |
| // voltar os valores pra vazio, pra conseguir realiza um novo cadastro | |
| this.setState({ | |
| inputTitle: '', | |
| inputPrice: '', | |
| inputDescription: '', | |
| inputPaymentMethods: [], | |
| inputDueDate: '' | |
| }) | |
| } catch(err) { | |
| alert(err) | |
| } | |
| } | |
| render() { | |
| return ( | |
| <MainContainer> | |
| <h4> | |
| Nome do Serviço | |
| </h4> | |
| <InputServico | |
| placeholder="Nome do serviço" | |
| value={this.state.inputTitle} | |
| onChange={e => this.setState({ inputTitle: e.target.value })} | |
| /> | |
| <ContainerPagamento> | |
| <h4>Método de pagamento</h4> | |
| <SelectEstilizado> | |
| <option>Picpay</option> | |
| <option>PIX</option> | |
| <option>Crédito</option> | |
| <option>Boleto</option> | |
| </SelectEstilizado> | |
| <h4>Valor</h4> | |
| <input | |
| placeholder="Valor" | |
| value={this.state.inputPrice} | |
| onChange={e => this.setState({ inputPrice: e.target.value })} | |
| /> | |
| </ContainerPagamento> | |
| <h4>Prazo</h4> | |
| <InputDataEstilizado | |
| id="date" | |
| type="date" | |
| value={this.state.inputDueDate} | |
| onChange={e => this.setState({ inputDueDate: e.target.value })} | |
| /> | |
| <h4>Descrição do serviço:</h4> | |
| <InputDescricao | |
| value={this.state.inputDescription} | |
| onChange={e => this.setState({ inputDescription: e.target.value })} | |
| /> | |
| <BotaoOferecerServico onCLick={this.createJob}>Oferecer serviço!</BotaoOferecerServico> | |
| {/*Botão acima é sugestão de implementação*/} | |
| </MainContainer> | |
| ) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment