1 | import React, { Component } from 'react'
|
---|
2 | import axios from 'axios'
|
---|
3 | import './PhoneOfferDetailsComponent.css'
|
---|
4 | import HeaderComponent from '../HeaderComponent/HeaderComponent'
|
---|
5 | import UserContext from '../../context/UserContext'
|
---|
6 | import CheckIcon from '@mui/icons-material/Check';
|
---|
7 | import { Link } from 'react-router-dom'
|
---|
8 | import Tippy from '@tippyjs/react'
|
---|
9 | import VisibilityIcon from '@mui/icons-material/Visibility';
|
---|
10 | import VisibilityOffIcon from '@mui/icons-material/VisibilityOff';
|
---|
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],
|
---|
20 | offer: null,
|
---|
21 | showAllSpecs: false
|
---|
22 | }
|
---|
23 | }
|
---|
24 |
|
---|
25 | componentDidMount(){
|
---|
26 | this.getPhoneOffer()
|
---|
27 | }
|
---|
28 |
|
---|
29 | getPhoneOffer = () => {
|
---|
30 | axios.get('/phoneoffer/'+this.state.offerId)
|
---|
31 | .then(response => {
|
---|
32 | this.setState({
|
---|
33 | offer: response.data
|
---|
34 | })
|
---|
35 | }).catch(error => console.log(error))
|
---|
36 | }
|
---|
37 |
|
---|
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 |
|
---|
56 |
|
---|
57 | changeShownSpecs = () => {
|
---|
58 | this.setState({
|
---|
59 | showAllSpecs: !this.state.showAllSpecs
|
---|
60 | })
|
---|
61 | }
|
---|
62 |
|
---|
63 | render() {
|
---|
64 | console.log(this.state)
|
---|
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>
|
---|
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 |
|
---|
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 | }
|
---|
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 | })()}
|
---|
105 | </div>
|
---|
106 | <div className='phone-offer-details-last-updated-wrapper'></div>
|
---|
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>
|
---|
129 | { this.state.showAllSpecs ||
|
---|
130 | !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Предна камера") ?
|
---|
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>
|
---|
134 | </tr> : <></>
|
---|
135 | }
|
---|
136 |
|
---|
137 | { this.state.showAllSpecs ||
|
---|
138 | !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Задна камера") ?
|
---|
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>
|
---|
142 | </tr> : <></>
|
---|
143 | }
|
---|
144 |
|
---|
145 | { this.state.showAllSpecs ||
|
---|
146 | !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("РОМ меморија") ?
|
---|
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>
|
---|
150 | </tr> : <></>
|
---|
151 | }
|
---|
152 |
|
---|
153 | { this.state.showAllSpecs ||
|
---|
154 | !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("РАМ меморија") ?
|
---|
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>
|
---|
158 | </tr> : <></>
|
---|
159 | }
|
---|
160 |
|
---|
161 | { this.state.showAllSpecs ||
|
---|
162 | !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Оперативен систем") ?
|
---|
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>
|
---|
166 | </tr> : <></>
|
---|
167 | }
|
---|
168 |
|
---|
169 | { this.state.showAllSpecs ||
|
---|
170 | !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Чипсет") ?
|
---|
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>
|
---|
174 | </tr> : <></>
|
---|
175 | }
|
---|
176 |
|
---|
177 | { this.state.showAllSpecs ||
|
---|
178 | !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Процесор") ?
|
---|
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>
|
---|
182 | </tr> : <></>
|
---|
183 | }
|
---|
184 |
|
---|
185 | { this.state.showAllSpecs ||
|
---|
186 | !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Батерија") ?
|
---|
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>
|
---|
190 | </tr> : <></>
|
---|
191 | }
|
---|
192 |
|
---|
193 | { this.state.showAllSpecs ||
|
---|
194 | !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Боја") ?
|
---|
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>
|
---|
198 | </tr> : <></>
|
---|
199 | }
|
---|
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 |
|
---|
216 | PhoneOfferDetailsComponent.contextType = UserContext
|
---|
217 |
|
---|
218 | export default PhoneOfferDetailsComponent
|
---|