-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
132 lines (117 loc) · 2.88 KB
/
App.js
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
import React, { Component } from 'react';
import './App.css';
import { getAllStudents } from './client.js'
import Container from './Container.js';
import Footer from './footer.js';
import AddStudentForm from './forms/AddStudentForm';
import {
Table,
Avatar,
Spin,
Modal
} from 'antd'
import { LoadingOutlined } from '@ant-design/icons';
const getIndicatorIcon = () => (
<LoadingOutlined
style={{
fontSize: 24,
}}
spin
/>
);
class App extends Component{
state= {
students: [],
isFetching: false,
isAddStudentModalVisiable: false
}
componentDidMount () {
this.fetchStudents();
}
openAddStudentModalVisiable = () => this.setState({isAddStudentModalVisiable:true})
closeAddStudentModalVisiable = () => this.setState({isAddStudentModalVisiable:false})
fetchStudents = () => {
this.setState({
isFetching:true
});
getAllStudents()
.then(res => res.json()
.then(students =>{
console.log(students);
this.setState({
students,
isFetching: false,
isAddStudentModalVisiable: false
});
}));
}
render(){
const { students, isFetching, isAddStudentModalVisiable} = this.state;
if (isFetching){
return(
<Container>
<Spin indicator={getIndicatorIcon} />
</Container>
);
}
if (students && students.length) {
const columns = [
{
title: '',
key: 'avatar',
render: (text, student) => (
<Avatar size='large'>
{`${student.firstName.charAt(0).toUpperCase()}${student.lastName.charAt(0).toUpperCase()}`}
</Avatar>
)
},
{
title: 'Student Id',
dataIndex: 'studentId',
key: 'studentId'
},
{
title: 'First Name',
dataIndex: 'firstName',
key: 'firstName'
},
{
title: 'Last Name',
dataIndex: 'lastName',
key: 'lastName'
},
{
title: 'Email',
dataIndex: 'email',
key: 'email'
},
{
title: 'Gender',
dataIndex: 'gender',
key: 'gender'
}
];
return(
<Container>
<Table
dataSource={students}
columns={columns}
pagination={false}
rowKey='studentId' />
<Modal
title = 'Add new student'
open={isAddStudentModalVisiable}
onOk={this.closeAddStudentModalVisiable}
onCancel={this.closeAddStudentModalVisiable}
width={1000}>
<AddStudentForm />
</Modal>
<Footer numberOfStudents={students.length}
handleAddStudentClickEvent = {this.openAddStudentModalVisiable}/>
</Container>
);
}
return <h1>No Students found</h1>
}
}
export default App;