@@ -4,12 +4,15 @@ import {
4
4
Paper ,
5
5
Container ,
6
6
Box ,
7
+ Button ,
8
+ Grid ,
7
9
Table ,
8
10
TableBody ,
9
11
TableCell ,
10
12
TableContainer ,
11
13
TableHead ,
12
- TableRow
14
+ TableRow ,
15
+ Typography
13
16
} from '@material-ui/core' ;
14
17
import CircularProgress from '@material-ui/core/CircularProgress' ;
15
18
import styles from "./styles/DataView360.module.css" ;
@@ -33,6 +36,20 @@ const customStyles = theme => ({
33
36
table : {
34
37
minWidth : 700
35
38
} ,
39
+ tableRowEven : {
40
+ backgroundColor : "#FFFFFF" ,
41
+ "&:hover" : {
42
+ backgroundColor : "#E6F7FF" ,
43
+ cursor : "pointer"
44
+ }
45
+ } ,
46
+ tableRowOdd : {
47
+ backgroundColor : "#E8E8E8" ,
48
+ "&:hover" : {
49
+ backgroundColor : "#CCEEFF" ,
50
+ cursor : "pointer"
51
+ }
52
+ } ,
36
53
headerCell : {
37
54
fontWeight : "bold" ,
38
55
minWidth : 60 ,
@@ -49,80 +66,88 @@ class DataView360 extends Component {
49
66
50
67
this . state = {
51
68
search_participant : '' ,
52
- participantData : undefined ,
69
+ participantData : { } ,
53
70
isDataBusy : false ,
54
71
participantList : [ ] ,
55
- participantTable : undefined
72
+ participantTable : undefined ,
73
+ showParticipant : false ,
74
+ showTable : true ,
75
+ showSearchBar : true
56
76
}
57
77
58
- // this.handleGetParticipant = this.handleGetParticipant.bind(this);
78
+ this . handleGetParticipant = this . handleGetParticipant . bind ( this ) ;
59
79
this . handleSearchChange = this . handleSearchChange . bind ( this ) ;
60
80
}
61
81
62
- /*
63
- async handleGetParticipant(event) {
64
- const participant = _.get(event, "target.value");
65
- this.setState({participant: participant});
66
- this.setState({isDataBusy: true});
82
+ async handleGetParticipant ( matching_id ) {
83
+ this . setState ( { isDataBusy : true , showSearchBar : false } ) ;
67
84
68
85
await new Promise ( resolve => setTimeout ( resolve , 1000 ) ) ;
69
- let response = await fetch(`/api/360/${participant }`);
86
+ let response = await fetch ( `/api/360/${ matching_id } ` ) ;
70
87
response = await response . json ( ) ;
71
88
72
- this.setState({participantData: response});
73
- this.setState({isDataBusy: false});
89
+ this . setState ( {
90
+ participantData : response . result ,
91
+ isDataBusy : false ,
92
+ showParticipant : true ,
93
+ showTable : false ,
94
+ showSearchBar : false
95
+ } ) ;
74
96
}
75
- */
76
97
77
98
renderParticipantsTable ( ) {
78
99
const { classes} = this . props ;
79
- const tableRowColors = [ "#FFFFFF" , "#E8E8E8" ]
100
+ const tableRowColors = [ classes . tableRowEven , classes . tableRowOdd ]
80
101
81
102
let participantListGrouped = _ . groupBy ( this . state . participantList , "matching_id" ) ;
82
103
participantListGrouped = _ . reverse ( _ . sortBy ( participantListGrouped , matching_group => {
83
104
return _ . size ( matching_group ) ;
84
105
} ) ) ;
85
106
86
107
return (
87
- < Paper className = { classes . tableCard } >
88
- < TableContainer className = { classes . container } >
89
- < Table className = { classes . table } size = "small" stickyHeader aria-label = "sticky table" >
90
- < TableHead >
91
- < TableRow >
92
- < TableCell align = "left" className = { classes . headerCell } > Match ID</ TableCell >
93
- < TableCell align = "left" className = { classes . headerCell } > First Name</ TableCell >
94
- < TableCell align = "left" className = { classes . headerCell } > Last Name</ TableCell >
95
- < TableCell align = "left" className = { classes . headerCell } > Email</ TableCell >
96
- < TableCell align = "left" className = { classes . headerCell } > Mobile</ TableCell >
97
- < TableCell align = "left" className = { classes . headerCell } > Source</ TableCell >
98
- < TableCell align = "left" className = { classes . headerCell } > ID in Source</ TableCell >
99
- </ TableRow >
100
- </ TableHead >
101
- < TableBody >
102
- {
103
- _ . map ( participantListGrouped , ( row_group , index ) => {
104
- return _ . map ( row_group , row => {
105
- return < TableRow key = { row . source_id }
106
- style = { { backgroundColor : tableRowColors [ index % _ . size ( tableRowColors ) ] } } >
107
- < TableCell align = "left" > { row . matching_id } </ TableCell >
108
- < TableCell align = "left" > { row . first_name } </ TableCell >
109
- < TableCell align = "left" > { row . last_name } </ TableCell >
110
- < TableCell align = "left" > { row . email } </ TableCell >
111
- < TableCell align = "left" > { row . mobile } </ TableCell >
112
- < TableCell align = "left" > { row . source_type } </ TableCell >
113
- < TableCell align = "left" > { row . source_id } </ TableCell >
114
- </ TableRow >
108
+ < Container >
109
+ < Typography paragraph = { true } > You searched for < b > { this . state . search_participant } </ b > </ Typography >
110
+ < Paper className = { classes . tableCard } >
111
+ < TableContainer className = { classes . container } >
112
+ < Table className = { classes . table } size = "small" stickyHeader aria-label = "sticky table" >
113
+ < TableHead >
114
+ < TableRow >
115
+ < TableCell align = "left" className = { classes . headerCell } > Match ID</ TableCell >
116
+ < TableCell align = "left" className = { classes . headerCell } > First Name</ TableCell >
117
+ < TableCell align = "left" className = { classes . headerCell } > Last Name</ TableCell >
118
+ < TableCell align = "left" className = { classes . headerCell } > Email</ TableCell >
119
+ < TableCell align = "left" className = { classes . headerCell } > Mobile</ TableCell >
120
+ < TableCell align = "left" className = { classes . headerCell } > Source</ TableCell >
121
+ < TableCell align = "left" className = { classes . headerCell } > ID in Source</ TableCell >
122
+ </ TableRow >
123
+ </ TableHead >
124
+ < TableBody >
125
+ {
126
+ _ . map ( participantListGrouped , ( row_group , index ) => {
127
+ return _ . map ( row_group , row => {
128
+ return < TableRow key = { row . source_id }
129
+ className = { tableRowColors [ index % _ . size ( tableRowColors ) ] }
130
+ onClick = { ( ) => this . handleGetParticipant ( row . matching_id ) } >
131
+ < TableCell align = "left" > { row . matching_id } </ TableCell >
132
+ < TableCell align = "left" > { row . first_name } </ TableCell >
133
+ < TableCell align = "left" > { row . last_name } </ TableCell >
134
+ < TableCell align = "left" > { row . email } </ TableCell >
135
+ < TableCell align = "left" > { row . mobile } </ TableCell >
136
+ < TableCell align = "left" > { row . source_type } </ TableCell >
137
+ < TableCell align = "left" > { row . source_id } </ TableCell >
138
+ </ TableRow >
139
+ } )
115
140
} )
116
- } )
117
- }
118
- </ TableBody >
119
- </ Table >
120
- </ TableContainer >
121
- </ Paper > )
141
+ }
142
+ </ TableBody >
143
+ </ Table >
144
+ </ TableContainer >
145
+ </ Paper >
146
+ </ Container > )
122
147
}
123
148
124
149
async handleSearchChange ( search_participant ) {
125
- this . setState ( { isDataBusy : true } ) ;
150
+ this . setState ( { isDataBusy : true , search_participant : search_participant } ) ;
126
151
127
152
await new Promise ( resolve => setTimeout ( resolve , 1000 ) ) ;
128
153
let response = await fetch ( `/api/contacts/${ search_participant } ` ) ;
@@ -131,27 +156,47 @@ class DataView360 extends Component {
131
156
await this . setState ( { participantList : response . result } )
132
157
133
158
this . state . participantTable = this . renderParticipantsTable ( ) ;
134
- this . setState ( { isDataBusy : false } ) ;
159
+ this . setState ( {
160
+ isDataBusy : false ,
161
+ showParticipant : false ,
162
+ showTable : true
163
+ } ) ;
135
164
}
136
165
137
166
render ( ) {
138
167
const { classes} = this . props ;
139
168
return (
140
169
< Container >
141
- < SearchBar participant = { this . state . participant }
170
+ { this . state . showSearchBar &&
171
+ ( < SearchBar participant = { this . state . participant }
142
172
handleParticipantChange = { this . handleGetParticipant }
143
173
handleSearchChange = { this . handleSearchChange } />
144
- { ( _ . isEmpty ( this . state . participantTable ) !== true && this . state . isDataBusy !== true ) && (
174
+ ) }
175
+ { ( _ . isEmpty ( this . state . participantTable ) !== true &&
176
+ this . state . isDataBusy !== true &&
177
+ this . state . showTable === true &&
178
+ this . state . showParticipant === false ) && (
145
179
< Container className = { styles . main } elevation = { 1 } style = { { "padding" : "1em" } } >
146
180
{ this . state . participantTable }
147
181
</ Container >
148
182
) }
149
- { ( _ . isEmpty ( this . state . participantData ) !== true && this . state . isDataBusy !== true ) && (
183
+ { ( _ . isEmpty ( this . state . participantData ) !== true &&
184
+ this . state . isDataBusy !== true &&
185
+ this . state . showParticipant === true ) && (
150
186
< Paper className = { styles . main } elevation = { 1 } style = { { "padding" : "1em" } } >
151
- < ContactInfo participant = { _ . get ( this . state , "participantData.salesforcecontacts" ) } />
152
- < Donations donations = { _ . get ( this . state , 'participantData.salesforcedonations' ) } />
153
- < Adoptions adoptions = { _ . get ( this . state , 'participantData.shelterluvpeople' ) } />
154
- < Volunteer volunteer = { _ . get ( this . state , 'participantData.volgistics.json' ) }
187
+ < ContactInfo participant = { _ . get ( this . state , 'participantData.contact_details' ) } />
188
+ < Container >
189
+ < Grid container direction = "row" justify = "center" alignItems = "center" style = { { "margin-top" : "1em" } } >
190
+ < Button variant = "contained" color = "primary"
191
+ onClick = { ( ) => {
192
+ this . setState ( { showParticipant : false , showTable : true , showSearchBar : true } )
193
+ } } > Back to Results
194
+ </ Button >
195
+ </ Grid >
196
+ </ Container >
197
+ < Donations donations = { _ . get ( this . state , 'participantData.donations' ) } />
198
+ < Adoptions adoptions = { _ . get ( this . state , 'participantData.adoptions' ) } />
199
+ < Volunteer volunteer = { _ . get ( this . state , 'participantData.shifts' ) }
155
200
volunteerShifts = { _ . get ( this . state , 'participantData.volgistics_shifts_results' ) } />
156
201
157
202
</ Paper > ) }
0 commit comments