Skip to content

Commit 37c3a3c

Browse files
committed
redux setup
1 parent 4452049 commit 37c3a3c

File tree

7 files changed

+83
-26
lines changed

7 files changed

+83
-26
lines changed

src/actions/ticketAction.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import axios from "axios";
2+
import { GET_TICKETs } from "./types";
3+
import { BASE_URL } from "./baseApi";
4+
import { errorHandler } from "../utils/errorHandler";
5+
6+
export const getTickets = () => async (dispatch) => {
7+
try {
8+
const res = await axios.get(`${BASE_URL}/ticket`);
9+
dispatch({
10+
type: GET_TICKETs,
11+
payload: res.data.tickets,
12+
});
13+
} catch (error) {
14+
dispatch(errorHandler(error));
15+
}
16+
};

src/actions/types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,4 @@ export const GET_PROPOSALVIEW_ANALYTICS="GET_PROPOSALVIEW_ANALYTICS"
5555
export const ACTIVATE_DEACTIVATE_ACCOUNT_TOGGLER = "ACTIVATE_DEACTIVATE_ACCOUNT_TOGGLER";
5656
export const CLEAR_INVITE_LINK = "CLEAR_INVITE_LINK";
5757
export const GET_LOGIN_OPTIONS = "GET_LOGIN_OPTIONS";
58+
export const GET_TICKETs = "GET_TICKETs";

src/reducers/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import proposalReducer from "./proposalReducer";
1414
import adminReducers from "./adminReducers";
1515
import commentReducer from "./commentReducer";
1616
import analyticsReducer from './analyticsReducer';
17+
import ticketReducer from './ticketReducer';
1718

1819
const rootReducer = combineReducers({
1920
auth: authReducers,
@@ -30,7 +31,8 @@ const rootReducer = combineReducers({
3031
proposal: proposalReducer,
3132
admin: adminReducers,
3233
comment: commentReducer,
33-
analytics: analyticsReducer
34+
analytics: analyticsReducer,
35+
tickets: ticketReducer
3436
});
3537

3638
export default rootReducer;

src/reducers/ticketReducer.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { GET_TICKETs } from "../actions/types";
2+
const initialState = {
3+
tickets: "",
4+
};
5+
6+
export default (state = initialState, action) => {
7+
switch (action.type) {
8+
case GET_TICKETs: {
9+
console.log(`Action Recieved in reducer! ${action.type}`);
10+
console.log(action.payload);
11+
return {
12+
...state,
13+
tickets: action.payload,
14+
};
15+
}
16+
default: {
17+
return state;
18+
}
19+
}
20+
};

src/user/Admin/Tickets/NewTicketEditor/Editor.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.new-ticket-editor {
2-
padding: 50px 50px;
2+
padding: 1rem;
33
.top-controls {
44
display: flex;
55
margin-bottom: 50px;

src/user/Admin/Tickets/TicketContent/TicketContent.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,35 +32,35 @@ class TicketContent extends Component {
3232
selector: "plot",
3333
wrap: true,
3434
sortable: true,
35-
format: (row) => `${row.plot.slice(0, 100)}...`,
35+
format: (row) => `${row.content.shortDescription.slice(0, 100)}...`,
3636
},
3737
{
3838
name: "Status",
3939
grow: 1,
4040
// eslint-disable-next-line react/no-array-index-key
41-
cell: (row) => (
42-
<div>
43-
{row.genres.map((genre, i) => (
44-
<BadgeElement ticketState={genre} />
45-
))}
46-
</div>
47-
),
41+
// cell: (row) => (
42+
// <div>
43+
// {row.genres.map((genre, i) => (
44+
// <BadgeElement ticketState={genre} />
45+
// ))}
46+
// </div>
47+
// ),
4848
},
4949
{
5050
name: "User",
5151
grow: 1,
52-
cell: (row) => (
53-
<div>
54-
<Image
55-
src={userIcon2}
56-
alt="icon"
57-
rounded
58-
className="profile-img"
59-
roundedCircle
60-
/>
61-
<span className="profile-text">Devesh Verma</span>
62-
</div>
63-
),
52+
// cell: (row) => (
53+
// <div>
54+
// <Image
55+
// src={userIcon2}
56+
// alt="icon"
57+
// rounded
58+
// className="profile-img"
59+
// roundedCircle
60+
// />
61+
// <span className="profile-text">Devesh Verma</span>
62+
// </div>
63+
// ),
6464
},
6565
{
6666
name: "Created At"

src/user/Admin/Tickets/TicketDashboard.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ import data from "../../../assets/jsonData/tickets";
77
import TicketContent from "./TicketContent/TicketContent";
88
import Navigation from "../../dashboard/navigation/navigation";
99
import SearchOutlinedIcon from "@material-ui/icons/SearchOutlined";
10+
import { connect } from "react-redux";
11+
import { getTickets } from "../../../actions/ticketAction";
12+
1013

1114
class 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

Comments
 (0)