11import React , { Component } from "react" ;
22import "./Filter.scss" ;
3+ import Axios from "axios" ;
34import Form from "react-bootstrap/Form" ;
5+ import Modal from "react-bootstrap/Modal" ;
6+ import Image from "react-bootstrap/Image" ;
47import Button from "react-bootstrap/Button" ;
58import Dropdown from "react-bootstrap/Dropdown" ;
9+ import { BASE_URL } from "../../../../actions/baseApi" ;
10+ import PeopleAltIcon from "@material-ui/icons/PeopleAlt" ;
11+ import userIcon2 from "../../../../assets/images/userIcon2.jpg" ;
612import CheckOutlinedIcon from "@material-ui/icons/CheckOutlined" ;
713import SearchOutlinedIcon from "@material-ui/icons/SearchOutlined" ;
14+ import LocationOnOutlinedIcon from "@material-ui/icons/LocationOnOutlined" ;
15+
816
917// Author, tags and status are the three filters that we want
1018// only one author can be selected at a time, clicking on a different authoir will unclick the first author
@@ -16,6 +24,7 @@ class Filter extends Component {
1624 super ( props ) ;
1725 this . state = {
1826 author : null ,
27+ modal : null ,
1928 status : [ ] ,
2029 tags : [ ] ,
2130 search : "" ,
@@ -138,11 +147,64 @@ class Filter extends Component {
138147 ) ;
139148 } ;
140149
150+ toggleModal = ( ) => {
151+ this . setState ( {
152+ modal : ! this . state . modal ,
153+ } ) ;
154+ } ;
155+
156+ getUsers = async ( ) => {
157+ const users = ( await Axios . get ( `${ BASE_URL } /ticket/users/all` ) ) . data . users ;
158+ this . setState ( { users } ) ;
159+ } ;
160+
161+ handleViewChange = ( view ) => {
162+ this . setState ( { modal : { view } } ) ;
163+ } ;
164+
141165 componentDidMount ( ) {
142- // fetch all labels and all
166+ if ( localStorage . getItem ( "admin" ) === "true" ) {
167+ this . getUsers ( ) ;
168+ }
143169 }
144170
171+ addModerator = async ( userId ) => {
172+ const users = ( await Axios . post ( `${ BASE_URL } /ticket/moderator/${ userId } ` ) )
173+ . data . users ;
174+ this . setState ( { users } ) ;
175+ } ;
176+
177+ removeModerator = async ( userId ) => {
178+ const users = ( await Axios . delete ( `${ BASE_URL } /ticket/moderator/${ userId } ` ) )
179+ . data . users ;
180+ this . setState ( { users } ) ;
181+ } ;
182+
145183 render ( ) {
184+ const userInfo = ( ele ) => (
185+ < div className = "user-info" >
186+ < div style = { { display : "flex" } } >
187+ < Image
188+ style = { { margin : "10px" } }
189+ src = { userIcon2 }
190+ alt = "icon"
191+ rounded
192+ className = "profile-img"
193+ roundedCircle
194+ />
195+ < div style = { { fontSize : "13px" , fontFamily : "Inter" } } >
196+ < strong > { ele . name . firstName } </ strong >
197+ < div > { ele . info . about . designation } </ div >
198+ < div >
199+ { ele . info . about . location && < LocationOnOutlinedIcon /> }
200+ { ele . info . about . location }
201+ </ div >
202+ < div > { ele . email } </ div >
203+ < div > { ele . info . about . shortDescription } </ div >
204+ </ div >
205+ </ div >
206+ </ div >
207+ ) ;
146208 // console.log(this.state.allAuthors);
147209 const allStatus = [
148210 { label : "Open" , status : "OPEN" } ,
@@ -151,6 +213,7 @@ class Filter extends Component {
151213 { label : "Solved" , status : "SOLVED" } ,
152214 { label : "On Hold" , status : "ON_HOLD" } ,
153215 ] ;
216+ const isAdmin = localStorage . getItem ( "admin" ) === "true" ;
154217 return (
155218 < div className = "tickets-dashboard-filter" >
156219 < div className = "searchbar-container" >
@@ -170,6 +233,14 @@ class Filter extends Component {
170233 < Button onClick = { ( ) => this . props . toggleNewTicketEditor ( true ) } >
171234 New Ticket
172235 </ Button >
236+ { isAdmin && (
237+ < Button
238+ style = { { marginLeft : "1rem" } }
239+ onClick = { ( ) => this . setState ( { modal : { view : "add" } } ) }
240+ >
241+ < PeopleAltIcon />
242+ </ Button >
243+ ) }
173244 </ div >
174245 < div className = "filters" >
175246 < div onClick = { this . clearFilters } className = "clear-filters" >
@@ -233,6 +304,74 @@ class Filter extends Component {
233304 </ Dropdown . Menu >
234305 </ Dropdown >
235306 </ div >
307+ { this . state . modal && (
308+ < Modal
309+ centered
310+ className = "modal"
311+ show = { ! ! this . state . modal }
312+ onHide = { this . toggleModal }
313+ >
314+ < Modal . Header closeButton >
315+ < Modal . Title > Manage Moderators</ Modal . Title >
316+ </ Modal . Header >
317+ < Modal . Body style = { { height : "500px" , overflowY : "scroll" } } >
318+ < div className = "ticket-tabs" >
319+ < span className = "nav__tab container" >
320+ < ul className = "nav__list__container" >
321+ { [
322+ { view : "add" , opt : "Add" } ,
323+ { view : "remove" , opt : "Remove" } ,
324+ ] . map ( ( ele , index ) => (
325+ < li
326+ key = { index }
327+ className = {
328+ this . state . modal . view === ele . view
329+ ? "nav__single__tab selected"
330+ : "nav__single__tab"
331+ }
332+ onClick = { ( ) => this . handleViewChange ( ele . view ) }
333+ >
334+ { ele . opt }
335+ </ li >
336+ ) ) }
337+ </ ul >
338+ </ span >
339+ </ div >
340+ { this . state . modal . view === "add" &&
341+ this . state . users . map ( ( ele , index ) => (
342+ < div key = { index } >
343+ { ! ele . isTicketsModerator && (
344+ < div className = "moderator-modal-user" >
345+ { userInfo ( ele ) }
346+ < Button
347+ onClick = { ( ) => this . addModerator ( ele . _id . toString ( ) ) }
348+ >
349+ Add
350+ </ Button >
351+ </ div >
352+ ) }
353+ </ div >
354+ ) ) }
355+ { this . state . modal . view === "remove" &&
356+ this . state . users . map ( ( ele , index ) => (
357+ < div key = { index } >
358+ { ele . isTicketsModerator && (
359+ < div className = "moderator-modal-user" >
360+ { userInfo ( ele ) }
361+ < Button
362+ onClick = { ( ) =>
363+ this . removeModerator ( ele . _id . toString ( ) )
364+ }
365+ >
366+ Remove
367+ </ Button >
368+ </ div >
369+ ) }
370+ </ div >
371+ ) ) }
372+ </ Modal . Body >
373+ </ Modal >
374+ ) }
236375 </ div >
237376 ) ;
238377 }
0 commit comments