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

Added more components

File:
1 edited

Legend:

Unmodified
Added
Removed
  • phonelux-frontend/src/components/PhoneOfferComponent/PhoneOfferComponent.js

    r775e15e r7e88e46  
    22import { Link } from 'react-router-dom'
    33import './PhoneOfferComponent.css'
     4import StarBorderIcon from '@mui/icons-material/StarBorder';
     5import StarIcon from '@mui/icons-material/Star';
     6import Tippy from '@tippyjs/react';
     7import axios from 'axios';
     8import UserContext from '../../context/UserContext';
     9import VisibilityIcon from '@mui/icons-material/Visibility';
     10import CheckIcon from '@mui/icons-material/Check';
    411
    512export class PhoneOfferComponent extends Component {
     
    1219      }
    1320    }
     21
     22    addToFavourite = () => {
     23      var config = {
     24        method: 'put',
     25        url: '/user/'+this.context.userId+'/addoffer/'+this.props.id,
     26        headers: {
     27          'Authorization': 'Bearer '+localStorage.getItem('token')
     28        }
     29      };
     30
     31      axios(config)
     32      .then(response => {
     33        this.props.getFavouriteOffersForLoggedUser()
     34      })
     35      .catch(error => {
     36        console.log(error)
     37      })
     38    }
     39
     40    removeFromFavourite = () => {
     41      var config = {
     42        method: 'put',
     43        url: '/user/'+this.context.userId+'/removeoffer/'+this.props.id,
     44        headers: {
     45          'Authorization': 'Bearer '+localStorage.getItem('token')
     46        }
     47      };
     48
     49      axios(config)
     50      .then(response => {
     51        this.props.getFavouriteOffersForLoggedUser()
     52      })
     53      .catch(error => {
     54        console.log(error);
     55      });
     56    }
     57
     58
     59    getCheaperOffers = () =>{
     60      var config = {
     61        method: 'get',
     62        url: '/phoneoffer/'+this.props.id+'/cheaperoffers',
     63        headers: { }
     64      };
     65     
     66      axios(config)
     67      .then(response => {
     68        this.props.handleOpen(response.data,this.props.price)
     69      })
     70      .catch(error => {
     71        console.log(error);
     72      });
     73    }
    1474   
    1575   
    1676  render() {
    17     // console.log(this.props)
    1877    return (
    1978      <tr className='phone-with-offers-table-row'>
     
    2281      <td>{this.props.price} ден.</td>
    2382      <td>
     83        {
     84          window.location.href.split('/')[5] == 'favouriteoffers' ?   
     85          <Tippy placement='bottom' content='Прикажи поевтини понуди'>
     86            <VisibilityIcon onClick={this.getCheaperOffers} className='phone-offer-cheaperoffers-icon' style={{fontSize: '40px', marginRight: '10px' }}/>
     87          </Tippy> : <></>
     88        }
     89        {
     90          localStorage.getItem('token') && this.props.loggedUserFavouriteOffers.filter(offer => offer.id == this.props.id).length == 0?
     91          <Tippy placement='bottom' content='Додади во омилени понуди'>
     92          <StarBorderIcon onClick={this.addToFavourite} className='phone-offer-favouriteoffer-icon' style={{fontSize: '40px', marginRight: '10px' }}/>
     93          </Tippy>
     94          : <></>
     95        }
     96
     97        {
     98          localStorage.getItem('token') && this.props.loggedUserFavouriteOffers.filter(offer => offer.id == this.props.id).length != 0?
     99          <Tippy placement='bottom' content='Избриши од омилени понуди'>
     100          <StarIcon onClick={this.removeFromFavourite} className='phone-offer-favouriteoffer-icon' style={{fontSize: '40px', marginRight: '10px' }}/>
     101          </Tippy>
     102          : <></>
     103        }
     104
     105
    24106        <Link style={{ textDecoration: 'none' }} to={"/phoneoffer/"+this.props.id}>
    25107          <button className='phone-offer-specifications-button'>Спецификации</button>
     
    31113}
    32114
     115PhoneOfferComponent.contextType = UserContext
    33116export default PhoneOfferComponent
    34117
Note: See TracChangeset for help on using the changeset viewer.