1 | import { Pagination } from '@mui/material'
|
---|
2 | import axios from 'axios'
|
---|
3 | import React, { Component } from 'react'
|
---|
4 | import HeaderComponent from '../HeaderComponent/HeaderComponent'
|
---|
5 | import './OfferReportsComponent.css'
|
---|
6 | import SingleReportComponent from './SingleReportComponent'
|
---|
7 |
|
---|
8 | export class OfferReportsComponent extends Component {
|
---|
9 |
|
---|
10 | constructor(props) {
|
---|
11 | super(props)
|
---|
12 |
|
---|
13 | this.state = {
|
---|
14 | offerReports: [],
|
---|
15 | currentReports: [],
|
---|
16 | reportsPerPage:10,
|
---|
17 | numberOfPages: 0,
|
---|
18 | currentPage: 1,
|
---|
19 | }
|
---|
20 | }
|
---|
21 |
|
---|
22 | componentDidMount(){
|
---|
23 | this.getOfferReports()
|
---|
24 | }
|
---|
25 |
|
---|
26 | removeOfferReport = (id) => {
|
---|
27 | var config = {
|
---|
28 | method: 'delete',
|
---|
29 | url: '/offerreport/remove/'+id,
|
---|
30 | headers: {
|
---|
31 | 'Authorization': 'Bearer '+localStorage.getItem('token')
|
---|
32 | }
|
---|
33 | };
|
---|
34 |
|
---|
35 | axios(config)
|
---|
36 | .then(response => {
|
---|
37 | this.getOfferReports()
|
---|
38 | })
|
---|
39 | .catch(error => {
|
---|
40 | console.log(error);
|
---|
41 | });
|
---|
42 |
|
---|
43 | }
|
---|
44 |
|
---|
45 | removeAllOfferReports = () => {
|
---|
46 | var config = {
|
---|
47 | method: 'delete',
|
---|
48 | url: '/offerreport/removeall',
|
---|
49 | headers: {
|
---|
50 | 'Authorization': 'Bearer '+localStorage.getItem('token')
|
---|
51 | }
|
---|
52 | };
|
---|
53 |
|
---|
54 | axios(config)
|
---|
55 | .then(response => {
|
---|
56 | this.getOfferReports()
|
---|
57 | })
|
---|
58 | .catch(error => {
|
---|
59 | console.log(error);
|
---|
60 | });
|
---|
61 | }
|
---|
62 |
|
---|
63 | getOfferReports = () => {
|
---|
64 | var config = {
|
---|
65 | method: 'get',
|
---|
66 | url: '/offerreport/allreports',
|
---|
67 | headers: {
|
---|
68 | 'Authorization': 'Bearer '+localStorage.getItem('token')
|
---|
69 | }
|
---|
70 | };
|
---|
71 |
|
---|
72 | axios(config)
|
---|
73 | .then(response => {
|
---|
74 | this.setState({
|
---|
75 | offerReports: response.data,
|
---|
76 | numberOfPages: Math.ceil(response.data.length / this.state.reportsPerPage)
|
---|
77 | },(e) => this.setNewPage(e,this.state.currentPage))
|
---|
78 | })
|
---|
79 | .catch(error => {
|
---|
80 | console.log(error);
|
---|
81 | });
|
---|
82 | }
|
---|
83 |
|
---|
84 | setNewPage = (event,page) => {
|
---|
85 |
|
---|
86 | const indexOfLastReport = parseInt(page) * this.state.reportsPerPage;
|
---|
87 | const indexOfFirstReport = indexOfLastReport - this.state.reportsPerPage;
|
---|
88 |
|
---|
89 | const currReports = this.state.offerReports.slice(indexOfFirstReport, indexOfLastReport)
|
---|
90 |
|
---|
91 | this.setState({
|
---|
92 | currentPage: parseInt(page),
|
---|
93 | currentReports: currReports
|
---|
94 | })
|
---|
95 | }
|
---|
96 |
|
---|
97 | render() {
|
---|
98 | console.log(this.state)
|
---|
99 | return (
|
---|
100 | <div className='offerreports-section-main'>
|
---|
101 | <HeaderComponent/>
|
---|
102 | <div className='offerreports-section-header'>
|
---|
103 | <h1 className='offerreports-section-header-text'>
|
---|
104 | Пријавени невалидни понуди
|
---|
105 | </h1>
|
---|
106 | </div>
|
---|
107 |
|
---|
108 | {
|
---|
109 | this.state.offerReports.length > 0 ?
|
---|
110 | <>
|
---|
111 | <div className='offerreports-section'>
|
---|
112 | <table cellPadding={20} className='offerreports-section-table'>
|
---|
113 | <thead className='offerreports-section-table-head'>
|
---|
114 | <tr>
|
---|
115 | <th>Име на понуда</th>
|
---|
116 | <th>Време на пријавување</th>
|
---|
117 | <th>Последно пријавена од</th>
|
---|
118 | <th>Вкупно пријави</th>
|
---|
119 | <th>
|
---|
120 | <button className='reportoffer-removeall-button' onClick={this.removeAllOfferReports}>Отстрани ги сите пријави</button>
|
---|
121 | </th>
|
---|
122 | </tr>
|
---|
123 | </thead>
|
---|
124 | <tbody>
|
---|
125 | {
|
---|
126 | this.state.currentReports.map((offer,idx) => <SingleReportComponent key={idx} id={offer.id}
|
---|
127 | times_reported={offer.times_reported} reportedAt={offer.reportedAt} phoneOffer={offer.phoneOffer}
|
---|
128 | reportedBy={offer.reportedBy} removeOfferReport={this.removeOfferReport}/>)
|
---|
129 | }
|
---|
130 | </tbody>
|
---|
131 | </table>
|
---|
132 |
|
---|
133 | </div>
|
---|
134 | <div className='offerreports-pagination-wrapper'>
|
---|
135 | <Pagination className='offerreports-pagination' onChange={this.setNewPage} page={this.state.currentPage}
|
---|
136 | count={this.state.numberOfPages} color="primary" />
|
---|
137 | </div>
|
---|
138 | </>
|
---|
139 | :
|
---|
140 | <div className='no-offerreports-wrapper'>
|
---|
141 | <h1 className='no-offerreports-message'>Нема пријавено понуди</h1>
|
---|
142 | </div>
|
---|
143 | }
|
---|
144 | </div>
|
---|
145 | )
|
---|
146 | }
|
---|
147 | }
|
---|
148 |
|
---|
149 | export default OfferReportsComponent
|
---|