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