source: phonelux-frontend/src/components/PhoneOfferDetailsComponent/PhoneOfferDetailsComponent.js

Last change on this file was 47f4eaf, checked in by Marko <Marko@…>, 20 months ago

Final features implemented

  • Property mode set to 100644
File size: 10.2 KB
Line 
1import React, { Component } from 'react'
2import axios from 'axios'
3import './PhoneOfferDetailsComponent.css'
4import HeaderComponent from '../HeaderComponent/HeaderComponent'
5import UserContext from '../../context/UserContext'
6import CheckIcon from '@mui/icons-material/Check';
7import { Link } from 'react-router-dom'
8import Tippy from '@tippyjs/react'
9import VisibilityIcon from '@mui/icons-material/Visibility';
10import VisibilityOffIcon from '@mui/icons-material/VisibilityOff';
11import ReportIcon from '@mui/icons-material/Report';
12
13
14export class PhoneOfferDetailsComponent extends Component {
15
16 constructor(props) {
17 super(props)
18
19 this.state = {
20 offerId: window.location.href.split('/')[4],
21 offer: null,
22 showAllSpecs: false
23 }
24 }
25
26 componentDidMount(){
27 this.getPhoneOffer()
28 }
29
30 getPhoneOffer = () => {
31 axios.get('/phoneoffer/'+this.state.offerId)
32 .then(response => {
33 this.setState({
34 offer: response.data
35 })
36 }).catch(error => console.log(error))
37 }
38
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
57
58 changeShownSpecs = () => {
59 this.setState({
60 showAllSpecs: !this.state.showAllSpecs
61 })
62 }
63
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
83 render() {
84 console.log(this.state)
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>
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 }
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
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 }
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 })()}
131
132 </div>
133 <div className='phone-offer-details-last-updated-wrapper'></div>
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>
138 <tr><th colSpan={2}>
139 Детали за понудата
140 </th></tr>
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>
158 { this.state.showAllSpecs ||
159 !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Предна камера") ?
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>
163 </tr> : <></>
164 }
165
166 { this.state.showAllSpecs ||
167 !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Задна камера") ?
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>
171 </tr> : <></>
172 }
173
174 { this.state.showAllSpecs ||
175 !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("РОМ меморија") ?
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>
179 </tr> : <></>
180 }
181
182 { this.state.showAllSpecs ||
183 !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("РАМ меморија") ?
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>
187 </tr> : <></>
188 }
189
190 { this.state.showAllSpecs ||
191 !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Оперативен систем") ?
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>
195 </tr> : <></>
196 }
197
198 { this.state.showAllSpecs ||
199 !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Чипсет") ?
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>
203 </tr> : <></>
204 }
205
206 { this.state.showAllSpecs ||
207 !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Процесор") ?
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>
211 </tr> : <></>
212 }
213
214 { this.state.showAllSpecs ||
215 !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Батерија") ?
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>
219 </tr> : <></>
220 }
221
222 { this.state.showAllSpecs ||
223 !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Боја") ?
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>
227 </tr> : <></>
228 }
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
245PhoneOfferDetailsComponent.contextType = UserContext
246
247export default PhoneOfferDetailsComponent
Note: See TracBrowser for help on using the repository browser.