1 | import { Paper } from '@mui/material'
|
---|
2 | import axios from 'axios'
|
---|
3 | import React, { Component } from 'react'
|
---|
4 | import PhoneOfferComponent from '../PhoneOfferComponent/PhoneOfferComponent'
|
---|
5 | import './PhoneWithOffersComponent.css'
|
---|
6 | import phoneImg from '../../images/phone.png'
|
---|
7 | import UserContext from '../../context/UserContext'
|
---|
8 |
|
---|
9 |
|
---|
10 | export class PhoneWithOffersComponent extends Component {
|
---|
11 |
|
---|
12 | constructor(props) {
|
---|
13 | super(props)
|
---|
14 |
|
---|
15 | this.state = {
|
---|
16 | phone_offers: [],
|
---|
17 | loggedUserFavouriteOffers: []
|
---|
18 | }
|
---|
19 | }
|
---|
20 |
|
---|
21 | componentDidMount(){
|
---|
22 | axios.get('/phones/offers/'+this.props.phoneId)
|
---|
23 | .then(response => {
|
---|
24 | console.log(response.data)
|
---|
25 | this.setState({
|
---|
26 | phone_offers: response.data
|
---|
27 | }, this.getFavouriteOffersForLoggedUser)
|
---|
28 | }).catch(error => console.log(error))
|
---|
29 | }
|
---|
30 |
|
---|
31 | getFavouriteOffersForLoggedUser = () => {
|
---|
32 | if(localStorage.getItem('token'))
|
---|
33 | {
|
---|
34 | var config = {
|
---|
35 | method: 'get',
|
---|
36 | url: '/user/'+this.context.userId+'/favouriteoffers',
|
---|
37 | headers: {
|
---|
38 | 'Authorization': 'Bearer '+localStorage.getItem('token')
|
---|
39 | }
|
---|
40 | };
|
---|
41 |
|
---|
42 | axios(config)
|
---|
43 | .then(response => {
|
---|
44 | this.setState({
|
---|
45 | loggedUserFavouriteOffers: response.data
|
---|
46 | })
|
---|
47 | })
|
---|
48 | .catch(error => {
|
---|
49 | console.log(error);
|
---|
50 | });
|
---|
51 | }
|
---|
52 | }
|
---|
53 |
|
---|
54 | render() {
|
---|
55 | return (
|
---|
56 | <div className='phone-with-offers-main'>
|
---|
57 |
|
---|
58 | <div className='phone-with-offers-sub-main'>
|
---|
59 | <div className='phone-with-offers-totaloffers-div'>
|
---|
60 | <h3 className='phone-with-offers-totaloffers-header'>Понуди: {this.props.total_offers}</h3>
|
---|
61 | </div>
|
---|
62 |
|
---|
63 | <div className='phone-with-offers-image-wrapper'>
|
---|
64 | <Paper className='phone-with-offers-paper' elevation={5}>
|
---|
65 | <img className='phone-with-offers-image' src={this.props.image_url == null ? phoneImg : this.props.image_url}/>
|
---|
66 | </Paper>
|
---|
67 | </div>
|
---|
68 |
|
---|
69 | <div className='phone-with-offers-model-wrapper'>
|
---|
70 | <h1 className='phone-with-offers-model-header'>{this.props.model}</h1>
|
---|
71 | </div>
|
---|
72 | </div>
|
---|
73 |
|
---|
74 | <div className='phone-with-offers-section'>
|
---|
75 |
|
---|
76 | <table cellPadding={20} className='phone-with-offers-table'>
|
---|
77 | <thead className='phone-with-offers-table-head'>
|
---|
78 | <tr>
|
---|
79 | <th>Продавница</th>
|
---|
80 | <th>Име на понуда</th>
|
---|
81 | <th>Цена</th>
|
---|
82 | <th></th>
|
---|
83 | </tr>
|
---|
84 | </thead>
|
---|
85 | <tbody>
|
---|
86 | {
|
---|
87 | this.state.phone_offers.map((offer,idx) => <PhoneOfferComponent key={idx} id={offer.id}
|
---|
88 | is_validated={offer.is_validated} offer_shop={offer.offer_shop} offer_name={offer.offer_name}
|
---|
89 | price={offer.price} offer_url={offer.offer_url} loggedUserFavouriteOffers={this.state.loggedUserFavouriteOffers}
|
---|
90 | getFavouriteOffersForLoggedUser={this.getFavouriteOffersForLoggedUser}
|
---|
91 | />)
|
---|
92 | }
|
---|
93 | </tbody>
|
---|
94 | </table>
|
---|
95 |
|
---|
96 | </div>
|
---|
97 |
|
---|
98 | </div>
|
---|
99 | )
|
---|
100 | }
|
---|
101 | }
|
---|
102 |
|
---|
103 | PhoneWithOffersComponent.contextType = UserContext
|
---|
104 |
|
---|
105 | export default PhoneWithOffersComponent
|
---|