Skip to content

Instantly share code, notes, and snippets.

@lucasgomesoficial
Last active June 24, 2021 02:47
Show Gist options
  • Select an option

  • Save lucasgomesoficial/594db5e3d7af725d42a291195466bfcf to your computer and use it in GitHub Desktop.

Select an option

Save lucasgomesoficial/594db5e3d7af725d42a291195466bfcf to your computer and use it in GitHub Desktop.
Como usar a API
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