-
Notifications
You must be signed in to change notification settings - Fork 1
/
Posts.jsx
250 lines (225 loc) · 9.2 KB
/
Posts.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
import React from 'react'
import './Posts.css'
import Button from 'react-bootstrap/Button';
import Card from 'react-bootstrap/Card';
import { Popconfirm } from 'antd';
import { Web3Storage } from 'web3.storage';
import done from "../../assests/done.png";
import redCircle from "../../assests/redCircle.png";
import image from '../../assests/image.png';
import docx from '../../assests/docx.png';
import pdf from '../../assests/pdf.png';
import excel from '../../assests/excel.png';
import ppt from '../../assests/ppt.png';
import comment from '../../assests/comments.png';
import { Steps } from 'antd';
const client = new Web3Storage({ token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJkaWQ6ZXRocjoweDcxOTdiN2M2OGFEMTNhNzREMGIzMGQ3OTI4OTNGMDc4MWQxZjE4M2QiLCJpc3MiOiJ3ZWIzLXN0b3JhZ2UiLCJpYXQiOjE2NzAxNjM1MTczNDIsIm5hbWUiOiJsb2RoYS1maWxlcyJ9.rmkUCge8MPPj5TC6i8Z5lVAjIevCSVni0gpu-_jUzlI" });
import {
MDBBtn,
MDBCard,
MDBCardBody,
MDBCardFooter,
MDBCardHeader,
MDBCardImage,
MDBCol,
MDBContainer,
MDBIcon,
MDBRow,
MDBTypography,
} from "mdb-react-ui-kit";
import { useGlobalContext } from '../../context/StateContext';
import axios from 'axios';
import { useState } from 'react';
import Spinner from '../Spinner/Spinner';
function Posts({ props }) {
const [isVisible, setIsVisible] = useState(false);
const [loading, setLoading] = useState(false);
let timeStamp = Date.parse(props.Time);
var date = new Date(timeStamp);
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
var year = date.getFullYear();
var month = months[date.getMonth()];
var dateVal = date.getDate();
var formattedDate = dateVal + '-' + (date.getMonth() + 1) + '-' + year;
const { User } = useGlobalContext();
const refreshPage = () => {
window.location.reload();
}
const createNotification = async (FlatNo, subject, message) => {
const { data } = await axios.post("https://lodha-backend.onrender.com/api/v1/postNotification", { FlatNo: FlatNo, NotificationTitle: subject, NotificationDesc: message });
}
const updateComplaint = async () => {
const { data } = await axios.get("https://lodha-backend.onrender.com/api/v1/updatecomplaint", { params: { complaint: props } });
setLoading(false);
refreshPage();
}
const UpdateDescription = (e) => {
e.preventDefault();
setLoading(true);
const desc = document.getElementById((props._id).toString()).innerText;
props.Description = desc;
updateComplaint();
}
const getSourceimg = (item) => {
let x = ''
let i = item.lastIndexOf('.');
for (let index = i + 1; index < item.length; index++) {
x += item[index]
}
if (x === 'png' || x === 'jpg' || x === 'gif' || x === 'jpeg') {
return image;
}
if (x === 'docx' || x === 'doc') {
return docx;
}
if (x === 'pdf') {
return pdf;
}
if (x === 'xlsx' || x === 'xls') {
return excel;
}
if (x === 'pptx' || x === 'ppt') {
return ppt;
}
}
return (
<>
<Card className="m-3 backgroundcoloring PostBackground">
<Card.Header className="PostTitle">
<div className='PostHeader'>
<div>
<label className='PostHeading'>Complaint Type </label>
<span className='PostsIssue'> {props.Issue}</span>
</div>
<div>
{/* {props.Status ? <div>
<img src={done} height="20px" width="20px"></img>
<span style={{ color: "green", fontWeight: "bold", fontSize: "18px", letterSpacing: "2px" }}>Done</span>
</div>
:
<div>
<img src={redCircle} height="20px" width="20px"></img>
<span style={{ color: "red", fontWeight: "bold", fontSize: "18px", letterSpacing: "2px" }}>Pending</span>
</div>
} */}
<label className='PostHeading'>Posted on</label>
<span style={{ color: "black", fontWeight: "bold", fontSize: "16px", letterSpacing: "1px", marginLeft: "20px" }}>{formattedDate}</span>
</div>
</div>
</Card.Header>
<Card.Body>
<Card.Text className="PostDesc">
<form
onSubmit={UpdateDescription}
>
<div className='complaintsDescDocuments'>
<div className="ComplaintDocumentDiv">
<p className='DescriptionTitle'>DESCRIPTION</p>
<div contentEditable style={{ width: "100%", letterSpacing:"1px" }} id={props._id}>{props.Description}</div>
</div>
<div className="ComplaintDocumentDiv" style={{ width: "50%" }}>
<p className='DescriptionTitle'>DOCUMENTS</p>
{
props.FileObjects.length ?
<div className='documentDiv'>
{
props.FileObjects.map((item) => {
return (
<Card className="card CardDocument" style={{ width: "250px", margin: "10px", backgroundColor: "whitesmoke" }}>
<Card.Body className='CardBodyDiv'>
{
item.endsWith('.png')
?
<div>
<img src={"https://" + props.FileHashes + ".ipfs.w3s.link/" + item} width="150px" height="150px"></img>
<p style={{ marginLeft: "10px", letterSpacing:"1px" }}> {item}</p>
</div>
:
<div style={{ display: "flex", }}>
<img src={getSourceimg(item)} width="50px" height="50px"></img>
<p style={{ marginLeft: "10px", letterSpacing:"1px" }}> {item}</p>
</div>
}
</Card.Body>
<Button href={"https://" + props.FileHashes + ".ipfs.w3s.link/" + item} style={{ width: "100%", marginBottom: "0px" }} target="blank" variant="primary" >View document</Button>
</Card>
);
})
}
</div>
:
<p style={{letterSpacing:"1px"}}>
No Documents!
</p>
}
</div>
</div>
<div>
<p className='DescriptionTitle'>STATUS</p>
<Steps
current={props.Status == 0 ? 1 : 3}
style={{ marginTop: "50px", color:"green" }}
items={[
{
title: 'Submitted',
className: "statusTitles"
},
{
title: 'In Progress',
className: "statusTitles"
},
{
title: (props.Status>0) ? props.Status===1 ? 'Resolved' : 'Closed' : 'Waiting',
className: "statusTitles",
},
]}
/></div>
<div>
{
isVisible ?
<p className='CommentHeader' onClick={() => setIsVisible(false)}>
<img src={comment} height="20px" width="20px"></img> Hide Comments
</p>
:
<p className='CommentHeader' onClick={() => setIsVisible(true)}>
<img src={comment} height="20px" width="20px"></img> Comments {
props.Comments !== undefined && props.Comments.length > 0 ? "(1)" : "(0)"
}
</p>
}
</div>
{
isVisible ?
<div>
<p className='DescriptionTitle'> COMMENTS </p>
{
props.Comments !== undefined && props.Comments.length > 0 ?
<div style={{ letterSpacing:"1px",width: "100%" }} >{props.Comments}</div>
:
<>
<p style={{letterSpacing:"1px"}}>No comments!</p>
</>
}
</div>
:
<></>
}
{
loading && <Spinner />
}
<div style={{ display: "flex", justifyContent: "center", marginTop: "50px" }}>
<Popconfirm
title="Clicking ok button will edit the complaint details "
onConfirm={(e) => UpdateDescription(e)}
>
<button className="btn btn-success ComplaintsButton" type="submit">Edit Complaint</button>
</Popconfirm>
</div>
</form>
</Card.Text>
</Card.Body>
</Card>
</>
)
}
export default Posts;