Ignore:
Timestamp:
09/17/22 01:24:24 (2 years ago)
Author:
Marko <Marko@…>
Branches:
master
Children:
5201690
Parents:
775e15e
Message:

Added more components

Location:
phonelux-frontend/src/components/PhoneWithOffersComponent
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • phonelux-frontend/src/components/PhoneWithOffersComponent/PhoneWithOffersComponent.css

    r775e15e r7e88e46  
    6969    border-radius: 50px;
    7070}
     71
     72
  • phonelux-frontend/src/components/PhoneWithOffersComponent/PhoneWithOffersComponent.js

    r775e15e r7e88e46  
    55import './PhoneWithOffersComponent.css'
    66import phoneImg from '../../images/phone.png'
     7import UserContext from '../../context/UserContext'
     8
    79
    810export class PhoneWithOffersComponent extends Component {
     
    1214   
    1315      this.state = {
    14          phone_offers: []
     16         phone_offers: [],
     17         loggedUserFavouriteOffers: []
    1518      }
    1619    }
     
    2124          this.setState({
    2225              phone_offers: response.data
     26          }, this.getFavouriteOffersForLoggedUser)
     27      }).catch(error => console.log(error))
     28    }
     29
     30    getFavouriteOffersForLoggedUser = () => {
     31      if(localStorage.getItem('token'))
     32      {
     33        var config = {
     34          method: 'get',
     35          url: '/user/'+this.context.userId+'/favouriteoffers',
     36          headers: {
     37            'Authorization': 'Bearer '+localStorage.getItem('token')
     38          }
     39        };
     40       
     41        axios(config)
     42        .then(response => {
     43          this.setState({
     44            loggedUserFavouriteOffers: response.data
    2345          })
    24       }).catch(error => console.log(error))
     46        })
     47        .catch(error => {
     48          console.log(error);
     49        });
     50      }
    2551    }
    2652
     
    6086                this.state.phone_offers.map((offer,idx) => <PhoneOfferComponent key={idx} id={offer.id}
    6187                is_validated={offer.is_validated} offer_shop={offer.offer_shop} offer_name={offer.offer_name}
    62                 price={offer.price} offer_url={offer.offer_url}
     88                price={offer.price} offer_url={offer.offer_url} loggedUserFavouriteOffers={this.state.loggedUserFavouriteOffers}
     89                getFavouriteOffersForLoggedUser={this.getFavouriteOffersForLoggedUser}
    6390                />)
    6491              }
     
    73100}
    74101
     102PhoneWithOffersComponent.contextType = UserContext
     103
    75104export default PhoneWithOffersComponent
Note: See TracChangeset for help on using the changeset viewer.