Advertisement
BearSharkN

Todos os Produtos

Dec 6th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.07 KB | None | 0 0
  1. import React,{Component, Fragment } from 'react'
  2. //import CardReceita from '../src/components/cardReceita/CardReceita'
  3. import {api} from '../src/services/api'
  4.  
  5. //modal
  6. import Button from '@material-ui/core/Button';
  7. import Dialog from '@material-ui/core/Dialog';
  8. import DialogActions from '@material-ui/core/DialogActions';
  9. import DialogContent from '@material-ui/core/DialogContent';
  10. import DialogContentText from '@material-ui/core/DialogContentText';
  11. import DialogTitle from '@material-ui/core/DialogTitle';
  12. import { string } from 'prop-types';
  13. // import Slide from '@material-ui/core/Slide';
  14.  
  15.  
  16.  
  17.  
  18.  
  19. export default class App extends Component {
  20.  
  21.  
  22. constructor(){
  23. super();
  24. this.state = {
  25. listaOfertas: [],
  26. umaOferta:{
  27. idProdutoNavigation: {
  28.  
  29. },
  30. idUsuarioNavigation: {
  31. endereco: [],
  32. },
  33.  
  34. },
  35.  
  36. idEscolhido:"",
  37. open:false,
  38. }
  39. }
  40.  
  41. openDialog() {
  42. this.setState({ open: true });
  43. }
  44. closeDialog() {
  45. this.setState({ open:false });
  46. }
  47.  
  48.  
  49. componentDidMount(){
  50. this.getOferta();
  51. }
  52.  
  53. //#region GETs
  54.  
  55. getOferta = () => {
  56. api.get('/oferta')
  57. .then(response => {
  58. if(response.status === 200){
  59. this.setState({listaOfertas : response.data})
  60. }
  61. })
  62. }
  63.  
  64. //esta função está recebendo o id da receita que foi mapeada <<<
  65. visualizarOferta = (idOferta) => {
  66.  
  67. api.get('/oferta/'+ idOferta)
  68. .then(response => {
  69. if(response.status === 200){
  70. this.setState({umaOferta : response.data})
  71. console.log(this.state.umaOferta)
  72. this.openDialog()
  73. }
  74. })
  75. }
  76.  
  77.  
  78.  
  79.  
  80. //#endregion
  81.  
  82.  
  83. render() {
  84. return(
  85. <Fragment>
  86.  
  87. <Dialog
  88. aria-labelledby="alert-dialog-slide-title"
  89. aria-describedby="alert-dialog-slide-description"
  90. open={this.state.open}
  91. onClose={this.handleClose}>
  92.  
  93. <DialogTitle id="alert-dialog-slide-title">
  94. {this.state.umaOferta.idProdutoNavigation.nomeProduto}
  95. </DialogTitle>
  96. <DialogContent>
  97. <DialogContentText id="alert-dialog-slide-description">
  98. <table>
  99. <tr>
  100. <td>Produto: {this.state.umaOferta.idProdutoNavigation.nomeProduto}</td>
  101.  
  102. <td>Preço: {this.state.umaOferta.preco}</td>
  103. </tr>
  104. <tr>
  105. <td>Data de produção: {this.state.umaOferta.dataFabricacao}</td>
  106. <td>Data de Validade: {this.state.umaOferta.dataVencimento}</td>
  107. </tr>
  108.  
  109. <tr>
  110. <td>Vendedor: {this.state.umaOferta.idUsuarioNavigation.nome}</td>
  111.  
  112. <td>CNPJ: {this.state.umaOferta.idUsuarioNavigation.cpfCnpj}</td>
  113. </tr>
  114. <tr>
  115. <td>Email: {this.state.umaOferta.idUsuarioNavigation.email}</td>
  116. </tr>
  117.  
  118. </table>
  119. </DialogContentText>
  120. </DialogContent>
  121.  
  122. <DialogActions>
  123. <Button onClick={this.closeDialog.bind(this)} color="primary" >
  124. FECHAR
  125. </Button>
  126. </DialogActions>
  127. </Dialog>
  128.  
  129.  
  130.  
  131.  
  132. <main className="itens-encontrados-cadastro">
  133.  
  134. <div className="esquerdo_perfil">
  135. <img src="#" alt="avatar do produtor"/>
  136. <div className="menu_perfil">
  137. <h2>Renata Amaral</h2>
  138. <p><a href="perfil.html">Perfil</a></p>
  139. <p><a href="pesquisar_produtos.html">Buscar Produtos</a></p>
  140. <p><a href="receitas.html">Receitas</a></p>
  141. <p><a href="cadastro_receitas.html">Cadastro de Receitas</a></p>
  142. <p><a href="index.html">Dicas</a></p>
  143. </div>
  144. </div>
  145. <div className="lado-direito-resultado">
  146. <div className="container-perfil">
  147. <h2>Produtos</h2>
  148. <div className="container-cards">
  149. {
  150. this.state.listaOfertas.map(
  151. function(oferta){
  152. return(
  153. <Fragment>
  154.  
  155. <div className="card-produto">
  156. <div className="imagem-redonda-card-receita">
  157. <img src={"http://localhost:5000/"+oferta.idProdutoNavigation.imagem} />
  158. </div>
  159.  
  160. <p className='nome-produto' key={oferta.idProdutoNavigation.idProduto}>{oferta.idProdutoNavigation.nomeProduto}</p>
  161. <ul>
  162. <li>Região:{oferta.idUsuarioNavigation.endereco.regiao}</li>
  163. <li>Estado do Produto: {oferta.estadoProduto}</li>
  164. </ul>
  165. <Button size="small" variant="outlined" color="primary" onClick={e => this.visualizarOferta(oferta.idOferta)} >
  166. Ver Oferta
  167. </Button>
  168. </div>
  169.  
  170. </Fragment>
  171.  
  172. );
  173. }.bind(this)
  174. )
  175. }
  176.  
  177.  
  178.  
  179. </div>
  180. <div className="lado-direito-resultado1"></div>
  181.  
  182. </div>
  183. </div>
  184.  
  185. </main>
  186.  
  187. </Fragment>
  188.  
  189.  
  190. )
  191.  
  192.  
  193. }
  194. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement