-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.tsx
94 lines (84 loc) · 2.37 KB
/
index.tsx
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
import React, { useEffect, useState, useRef } from 'react';
import { connect } from 'react-redux';
import ReactDataGrid from 'react-data-grid';
import { Data } from 'react-data-grid-addons';
import * as POC from '../../core';
import { AppState } from '../../store';
import { getTasks } from '../../store/task/actions';
import CreateFilterableHeaderCell from '../../components/global/FilterableHeaderCell';
import Grid from '../../components/global/Grid';
import './index.scss';
interface ITasksProps {
isLoading: boolean;
error?: POC.Models.POCError;
tasks?: POC.Models.Task[];
dispatchGetTasks(): () => Promise<void>;
}
const Tasks: React.FC<ITasksProps> = props => {
const { isLoading, error, tasks, dispatchGetTasks } = props;
// Define columns
const columns = [
{
key: 'id',
name: 'ID',
editable: false,
width: 80
},
{
key: 'order',
name: 'Order',
editable: false,
width: 80
},
{
key: 'title',
name: 'Title',
editable: false,
width: 500
},
{
key: 'description',
name: 'Description',
editable: false,
filterable: true,
// Omit the filterRenderer property to use the default renderer found here:
// https://github.com/adazzle/react-data-grid/blob/master/packages/common/cells/headerCells/FilterableHeaderCell.js
filterRenderer: CreateFilterableHeaderCell(['/'])
}
] as AdazzleReactDataGrid.Column<POC.Models.Task>[];
// Get tasks
useEffect(() => {
dispatchGetTasks();
}, [dispatchGetTasks]);
if (isLoading) {
return <p>Loading...</p>;
} else if (error) {
return <p>Error occurred...</p>;
} else if (tasks && tasks.length > 0) {
return (
<React.Fragment>
<section>
<div className="heading_block">
<div className="top_wrap">
<h2>Tasks</h2>
</div>
</div>
<Grid columns={columns} data={tasks} />
</section>
</React.Fragment>
);
} else {
return <p>No tasks found.</p>;
}
};
const mapStateToProps = (state: AppState) => {
return {
isLoading: state.taskState.isLoading,
error: state.taskState.error,
tasks: state.taskState.tasks
};
};
const mapDispatchToProps = (dispatch: any) => ({
dispatchGetTasks: () => dispatch(getTasks())
});
export default connect(mapStateToProps, mapDispatchToProps)(Tasks);