-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewAllComponent.js
More file actions
137 lines (126 loc) · 3.39 KB
/
ViewAllComponent.js
File metadata and controls
137 lines (126 loc) · 3.39 KB
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
133
134
135
136
137
import React from "react";
import { Redirect } from "react-router-dom";
import { showModal } from "./SmallModal";
import { academicScores_getAll, academicScores_delete } from "./server";
import { AdminAcademicScoresEdit } from "./AdminAcademicScoresEdit";
import FlashMessage from "./FlashMessage";
import { setFlashMessage } from "./FlashMessage";
class AdminAcademicScoresViewAll extends React.Component {
state = {
id: "",
scores: [],
editPage: false,
loading: true,
deleteHighlight: false,
idToDelete: null,
redirectedFromUpdate: false
};
getAll() {
const myPromise = academicScores_getAll();
myPromise.then(users => {
this.setState({
scores: users.data.items,
loading: false
});
});
}
componentDidMount() {
this.getAll();
}
editPage = userDataId => {
this.setState({
id: userDataId,
editPage: true
});
};
confirmDelete = userDataId => {
this.setState({
id: userDataId,
deleteHighlight: true,
idToDelete: userDataId
});
showModal({
title: "Are you sure you want to delete?",
body: "Click Ok to confirm!"
}).then(
() => {
this.deleteScores(userDataId);
},
() => {
this.setState({
idToDelete: null
});
}
);
};
deleteScores = userDataId => {
const myPromise = academicScores_delete(userDataId);
myPromise.then(e => {
this.getAll();
});
return;
};
render() {
if (this.state.editPage && this.state.id) {
return <Redirect to={"/admin/academic-scores/" + this.state.id} />;
}
return (
<React.Fragment>
<FlashMessage />
{this.state.loading && (
<div>
<i className="fa fa-spinner fa-spin" /> Loading...
</div>
)}
<div className="row">
<div className="col-md-6 form-group">
{this.state.scores.map(score => (
<div
className="form-footer"
key={score.id}
style={
this.state.idToDelete === score.id && {
backgroundColor: "#F6BB42"
}
}
>
<li>
ID: {score.id} <br />
</li>
<li>
USER: {score.userId} <br />
</li>
<li>
GPA: {score.gpa} <br />
</li>
<li>
SAT: {score.sat} <br />
</li>
<li>
ACT: {score.act} <br />
</li>
<button
className="btn btn-theme"
onClick={() =>
this.props.history.push(
"/admin/academic-scores/" + score.id
)
}
>
EDIT
</button>
<button
className="btn btn-danger"
onClick={() => this.confirmDelete(score.id)}
>
DELETE
</button>
</div>
))}
</div>
</div>
</React.Fragment>
);
}
}
export default AdminAcademicScoresViewAll;