[e5b84dc] | 1 | import React, { Component } from 'react'
|
---|
| 2 | import axios from 'axios'
|
---|
| 3 | import './PhoneOfferDetailsComponent.css'
|
---|
| 4 | import HeaderComponent from '../HeaderComponent/HeaderComponent'
|
---|
[7e88e46] | 5 | import UserContext from '../../context/UserContext'
|
---|
[d66b8eb] | 6 | import CheckIcon from '@mui/icons-material/Check';
|
---|
[7e88e46] | 7 | import { Link } from 'react-router-dom'
|
---|
[d66b8eb] | 8 | import Tippy from '@tippyjs/react'
|
---|
[e5b84dc] | 9 |
|
---|
| 10 |
|
---|
| 11 | export class PhoneOfferDetailsComponent extends Component {
|
---|
| 12 |
|
---|
| 13 | constructor(props) {
|
---|
| 14 | super(props)
|
---|
| 15 |
|
---|
| 16 | this.state = {
|
---|
| 17 | offerId: window.location.href.split('/')[4],
|
---|
| 18 | offer: null
|
---|
| 19 | }
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 | componentDidMount(){
|
---|
[d66b8eb] | 23 | this.getPhoneOffer()
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | getPhoneOffer = () => {
|
---|
| 27 | axios.get('/phoneoffer/'+this.state.offerId)
|
---|
[e5b84dc] | 28 | .then(response => {
|
---|
| 29 | this.setState({
|
---|
| 30 | offer: response.data
|
---|
| 31 | })
|
---|
| 32 | }).catch(error => console.log(error))
|
---|
| 33 | }
|
---|
| 34 |
|
---|
[d66b8eb] | 35 | validateOffer = () => {
|
---|
| 36 | var config = {
|
---|
| 37 | method: 'put',
|
---|
| 38 | url: '/admin/validateoffer/'+this.state.offerId,
|
---|
| 39 | headers: {
|
---|
| 40 | 'Authorization': 'Bearer '+localStorage.getItem('token')
|
---|
| 41 | }
|
---|
| 42 | };
|
---|
| 43 |
|
---|
| 44 | axios(config)
|
---|
| 45 | .then(response => {
|
---|
| 46 | this.getPhoneOffer();
|
---|
| 47 | })
|
---|
| 48 | .catch(error => {
|
---|
| 49 | console.log(error);
|
---|
| 50 | });
|
---|
| 51 | }
|
---|
| 52 |
|
---|
[e5b84dc] | 53 | render() {
|
---|
[d66b8eb] | 54 | console.log(this.state)
|
---|
[e5b84dc] | 55 | return (
|
---|
| 56 | <div className='phone-offer-details-main'>
|
---|
| 57 | <HeaderComponent/>
|
---|
| 58 | <div className='phone-offer-details-last-updated-wrapper'>
|
---|
| 59 | <h3 className='phone-offer-details-last-updated-header'>Последно ажурирана: {this.state.offer == null ||
|
---|
| 60 | this.state.offer.last_updated == null ? '#' : this.state.offer.last_updated.split('T')[0]}</h3>
|
---|
[7e88e46] | 61 | {
|
---|
| 62 | localStorage.getItem('token') && (this.context.role == 'ADMIN' || this.context.role == 'SUPERADMIN') ?
|
---|
| 63 | <Link className='link-offer-edit' style={{color:'black'}} to={'/admin/editoffer/'+this.state.offerId}>
|
---|
| 64 | <h3 className='phone-offer-details-edit-header'>Измени понуда</h3>
|
---|
| 65 | </Link> : <></>
|
---|
| 66 | }
|
---|
[d66b8eb] | 67 |
|
---|
| 68 |
|
---|
| 69 | {(() => {
|
---|
| 70 | if(this.state.offer != null && this.state.offer.is_validated)
|
---|
| 71 | {
|
---|
| 72 | return <Tippy placement='bottom' content='Понудата е валидна'>
|
---|
| 73 | <CheckIcon className='offer-valid-check-icon' style={{'fontSize': '60px'}}></CheckIcon>
|
---|
| 74 | </Tippy>
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | if(this.state.offer != null && !this.state.offer.is_validated &&
|
---|
| 78 | (this.context.role == 'ADMIN' || this.context.role == 'SUPERADMIN'))
|
---|
| 79 | {
|
---|
| 80 | return <button onClick={this.validateOffer} className='validate-offer-button'>Валидирај понуда</button>
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | })()}
|
---|
[e5b84dc] | 84 | </div>
|
---|
[d66b8eb] | 85 | <div className='phone-offer-details-last-updated-wrapper'></div>
|
---|
[e5b84dc] | 86 | <div className='phone-offer-details-table-wrapper'>
|
---|
| 87 | <div className='phone-offer-details-table-section'>
|
---|
| 88 | <table className='phone-offer-details-table'>
|
---|
| 89 | <thead>
|
---|
| 90 | <tr><th colSpan={2}>Детали за понудата</th></tr>
|
---|
| 91 | </thead>
|
---|
| 92 | <tbody>
|
---|
| 93 | <tr className='phone-offer-details-table-row'>
|
---|
| 94 | <td>Понуда</td><td><a href={this.state.offer == null || this.state.offer.offer_url == null ?
|
---|
| 95 | '#' : this.state.offer.offer_url}>{this.state.offer == null || this.state.offer.offer_name == null ?
|
---|
| 96 | '/' : this.state.offer.offer_name}</a></td>
|
---|
| 97 | </tr>
|
---|
| 98 |
|
---|
| 99 | <tr className='phone-offer-details-table-row'>
|
---|
| 100 | <td>Продавница</td><td>{this.state.offer == null ||
|
---|
| 101 | this.state.offer.offer_shop == null ? '/' : this.state.offer.offer_shop}</td>
|
---|
| 102 | </tr>
|
---|
| 103 |
|
---|
| 104 | <tr className='phone-offer-details-table-row'>
|
---|
| 105 | <td>Цена</td><td>{this.state.offer == null ||
|
---|
| 106 | this.state.offer.price == null ? '/' : this.state.offer.price+' ден.'}</td>
|
---|
| 107 | </tr>
|
---|
[48f3030] | 108 | { !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Предна камера") ?
|
---|
[e5b84dc] | 109 | <tr className='phone-offer-details-table-row'>
|
---|
| 110 | <td>Предна камера</td><td>{this.state.offer == null ||
|
---|
| 111 | this.state.offer.front_camera == null ? '/' : this.state.offer.front_camera}</td>
|
---|
[48f3030] | 112 | </tr> : <></>
|
---|
| 113 | }
|
---|
[e5b84dc] | 114 |
|
---|
[48f3030] | 115 | { !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Задна камера") ?
|
---|
[e5b84dc] | 116 | <tr className='phone-offer-details-table-row'>
|
---|
| 117 | <td>Задна камера</td><td>{this.state.offer == null ||
|
---|
| 118 | this.state.offer.back_camera == null ? '/' : this.state.offer.back_camera}</td>
|
---|
[48f3030] | 119 | </tr> : <></>
|
---|
| 120 | }
|
---|
[e5b84dc] | 121 |
|
---|
[48f3030] | 122 | { !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("РОМ меморија") ?
|
---|
[e5b84dc] | 123 | <tr className='phone-offer-details-table-row'>
|
---|
| 124 | <td>РОМ меморија</td><td>{this.state.offer == null ||
|
---|
| 125 | this.state.offer.rom_memory == null ? '/' : this.state.offer.rom_memory}</td>
|
---|
[48f3030] | 126 | </tr> : <></>
|
---|
| 127 | }
|
---|
[e5b84dc] | 128 |
|
---|
[48f3030] | 129 | { !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("РАМ меморија") ?
|
---|
[e5b84dc] | 130 | <tr className='phone-offer-details-table-row'>
|
---|
| 131 | <td>РАМ меморија</td><td>{this.state.offer == null ||
|
---|
| 132 | this.state.offer.ram_memory == null ? '/' : this.state.offer.ram_memory}</td>
|
---|
[48f3030] | 133 | </tr> : <></>
|
---|
| 134 | }
|
---|
[e5b84dc] | 135 |
|
---|
[48f3030] | 136 | { !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Оперативен систем") ?
|
---|
[e5b84dc] | 137 | <tr className='phone-offer-details-table-row'>
|
---|
| 138 | <td>Оперативен систем</td><td>{this.state.offer == null ||
|
---|
| 139 | this.state.offer.operating_system == null ? '/' : this.state.offer.operating_system}</td>
|
---|
[48f3030] | 140 | </tr> : <></>
|
---|
| 141 | }
|
---|
[e5b84dc] | 142 |
|
---|
[48f3030] | 143 | { !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Чипсет") ?
|
---|
[e5b84dc] | 144 | <tr className='phone-offer-details-table-row'>
|
---|
| 145 | <td>Чипсет</td><td>{this.state.offer == null ||
|
---|
| 146 | this.state.offer.chipset == null ? '/' : this.state.offer.chipset}</td>
|
---|
[48f3030] | 147 | </tr> : <></>
|
---|
| 148 | }
|
---|
[e5b84dc] | 149 |
|
---|
[48f3030] | 150 | { !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Процесор") ?
|
---|
[e5b84dc] | 151 | <tr className='phone-offer-details-table-row'>
|
---|
| 152 | <td>Процесор</td><td>{this.state.offer == null ||
|
---|
| 153 | this.state.offer.cpu == null ? '/' : this.state.offer.cpu}</td>
|
---|
[48f3030] | 154 | </tr> : <></>
|
---|
| 155 | }
|
---|
[e5b84dc] | 156 |
|
---|
[48f3030] | 157 | { !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Батерија") ?
|
---|
[e5b84dc] | 158 | <tr className='phone-offer-details-table-row'>
|
---|
| 159 | <td>Батерија</td><td>{this.state.offer == null ||
|
---|
| 160 | this.state.offer.battery == null ? '/' : this.state.offer.battery}</td>
|
---|
[48f3030] | 161 | </tr> : <></>
|
---|
| 162 | }
|
---|
[e5b84dc] | 163 |
|
---|
[48f3030] | 164 | { !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Боја") ?
|
---|
[e5b84dc] | 165 | <tr className='phone-offer-details-table-row'>
|
---|
| 166 | <td>Боја</td><td>{this.state.offer == null ||
|
---|
| 167 | this.state.offer.color == null ? '/' : this.state.offer.color}</td>
|
---|
[48f3030] | 168 | </tr> : <></>
|
---|
| 169 | }
|
---|
[e5b84dc] | 170 |
|
---|
| 171 | <tr className='phone-offer-details-table-row'>
|
---|
| 172 | <td>Опис</td><td>{this.state.offer == null ||
|
---|
| 173 | this.state.offer.offer_description == null ? '/' : this.state.offer.offer_description}</td>
|
---|
| 174 | </tr>
|
---|
| 175 |
|
---|
| 176 | </tbody>
|
---|
| 177 | </table>
|
---|
| 178 | </div>
|
---|
| 179 | </div>
|
---|
| 180 |
|
---|
| 181 | </div>
|
---|
| 182 | )
|
---|
| 183 | }
|
---|
| 184 | }
|
---|
| 185 |
|
---|
[7e88e46] | 186 | PhoneOfferDetailsComponent.contextType = UserContext
|
---|
| 187 |
|
---|
[e5b84dc] | 188 | export default PhoneOfferDetailsComponent
|
---|