source: phonelux-frontend/src/components/PhoneOfferDetailsComponent/PhoneOfferDetailsComponent.js@ 895cd87

Last change on this file since 895cd87 was 48f3030, checked in by Marko <Marko@…>, 22 months ago

Implemented all use cases

  • Property mode set to 100644
File size: 8.0 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'
9
10
11export 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(){
23 this.getPhoneOffer()
24 }
25
26 getPhoneOffer = () => {
27 axios.get('/phoneoffer/'+this.state.offerId)
28 .then(response => {
29 this.setState({
30 offer: response.data
31 })
32 }).catch(error => console.log(error))
33 }
34
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
53 render() {
54 console.log(this.state)
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>
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 }
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 })()}
84 </div>
85 <div className='phone-offer-details-last-updated-wrapper'></div>
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>
108 { !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Предна камера") ?
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>
112 </tr> : <></>
113 }
114
115 { !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Задна камера") ?
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>
119 </tr> : <></>
120 }
121
122 { !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("РОМ меморија") ?
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>
126 </tr> : <></>
127 }
128
129 { !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("РАМ меморија") ?
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>
133 </tr> : <></>
134 }
135
136 { !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Оперативен систем") ?
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>
140 </tr> : <></>
141 }
142
143 { !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Чипсет") ?
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>
147 </tr> : <></>
148 }
149
150 { !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Процесор") ?
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>
154 </tr> : <></>
155 }
156
157 { !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Батерија") ?
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>
161 </tr> : <></>
162 }
163
164 { !localStorage.getItem('pickedSpecifications') || localStorage.getItem('pickedSpecifications').includes("Боја") ?
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>
168 </tr> : <></>
169 }
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
186PhoneOfferDetailsComponent.contextType = UserContext
187
188export default PhoneOfferDetailsComponent
Note: See TracBrowser for help on using the repository browser.