@@ -7,13 +7,16 @@ import data from "../../../assets/jsonData/tickets";
77import TicketContent from "./TicketContent/TicketContent" ;
88import Navigation from "../../dashboard/navigation/navigation" ;
99import SearchOutlinedIcon from "@material-ui/icons/SearchOutlined" ;
10+ import { connect } from "react-redux" ;
11+ import { getTickets } from "../../../actions/ticketAction" ;
12+
1013
1114class TicketDashboard extends Component {
1215 constructor ( props ) {
1316 super ( props ) ;
1417 this . state = {
1518 view : "all" ,
16- all : [ ... data ] ,
19+ all : [ ] ,
1720 open : [ ] ,
1821 pending : [ ] ,
1922 onHold : [ ] ,
@@ -23,7 +26,17 @@ class TicketDashboard extends Component {
2326 } ;
2427 }
2528
29+ componentWillReceiveProps ( nextProps ) {
30+ console . log ( nextProps . tickets . tickets )
31+ this . setState ( {
32+ all : nextProps . tickets . tickets
33+ } ) ;
34+ }
35+
2636 componentDidMount ( ) {
37+ setTimeout ( ( ) => {
38+ this . props . getTickets ( ) ;
39+ } ) ;
2740 this . setState ( {
2841 open : this . state . all . filter ( ( ele ) => ele . genres . indexOf ( "open" ) !== - 1 ) ,
2942 pending : this . state . all . filter (
@@ -65,11 +78,11 @@ class TicketDashboard extends Component {
6578 < div className = "ticket-details" >
6679 < div className = "ticket-description" >
6780 < div className = "dashboard-title" > Tickets</ div >
68- { ! this . state . editorMode && (
81+ { ! this . state . editorMode && this . state . all . length && (
6982 < React . Fragment >
7083 < div className = "searchbar-container" >
7184 < div className = "searchbar" >
72- < span class = "searchbar-icon" >
85+ < span className = "searchbar-icon" >
7386 < SearchOutlinedIcon />
7487 </ span >
7588 < Form >
@@ -123,4 +136,9 @@ class TicketDashboard extends Component {
123136 }
124137}
125138
126- export default TicketDashboard ;
139+ // map state to props
140+ const mapStateToProps = ( state ) => ( {
141+ tickets : state . tickets ,
142+ } ) ;
143+
144+ export default connect ( mapStateToProps , { getTickets } ) ( TicketDashboard ) ;
0 commit comments