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