@@ -4,12 +4,15 @@ import {
4
4
Paper ,
5
5
Container ,
6
6
Box ,
7
+ Button ,
8
+ Link ,
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" ;
@@ -49,30 +52,34 @@ class DataView360 extends Component {
49
52
50
53
this . state = {
51
54
search_participant : '' ,
52
- participantData : undefined ,
55
+ participantData : { } ,
53
56
isDataBusy : false ,
54
57
participantList : [ ] ,
55
- participantTable : undefined
58
+ participantTable : undefined ,
59
+ showParticipant : false ,
60
+ showTable : true ,
61
+ showSearchBar : true
56
62
}
57
63
58
- // this.handleGetParticipant = this.handleGetParticipant.bind(this);
64
+ this . handleGetParticipant = this . handleGetParticipant . bind ( this ) ;
59
65
this . handleSearchChange = this . handleSearchChange . bind ( this ) ;
60
66
}
61
67
62
- /*
63
- async handleGetParticipant(event) {
64
- const participant = _.get(event, "target.value");
65
- this.setState({participant: participant});
66
- this.setState({isDataBusy: true});
68
+ async handleGetParticipant ( matching_id ) {
69
+ this . setState ( { isDataBusy : true , showSearchBar : false } ) ;
67
70
68
71
await new Promise ( resolve => setTimeout ( resolve , 1000 ) ) ;
69
- let response = await fetch(`/api/360/${participant }`);
72
+ let response = await fetch ( `/api/360/${ matching_id } ` ) ;
70
73
response = await response . json ( ) ;
71
74
72
- this.setState({participantData: response});
73
- this.setState({isDataBusy: false});
75
+ this . setState ( {
76
+ participantData : response . result ,
77
+ isDataBusy : false ,
78
+ showParticipant : true ,
79
+ showTable : false ,
80
+ showSearchBar : false
81
+ } ) ;
74
82
}
75
- */
76
83
77
84
renderParticipantsTable ( ) {
78
85
const { classes} = this . props ;
@@ -84,45 +91,48 @@ class DataView360 extends Component {
84
91
} ) ) ;
85
92
86
93
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 >
94
+ < Container >
95
+ < Typography paragraph = { true } > You searched for < b > { this . state . search_participant } </ b > </ Typography >
96
+ < Paper className = { classes . tableCard } >
97
+ < TableContainer className = { classes . container } >
98
+ < Table className = { classes . table } size = "small" stickyHeader aria-label = "sticky table" >
99
+ < TableHead >
100
+ < TableRow >
101
+ < TableCell align = "left" className = { classes . headerCell } > Match ID</ TableCell >
102
+ < TableCell align = "left" className = { classes . headerCell } > First Name</ TableCell >
103
+ < TableCell align = "left" className = { classes . headerCell } > Last Name</ TableCell >
104
+ < TableCell align = "left" className = { classes . headerCell } > Email</ TableCell >
105
+ < TableCell align = "left" className = { classes . headerCell } > Mobile</ TableCell >
106
+ < TableCell align = "left" className = { classes . headerCell } > Source</ TableCell >
107
+ < TableCell align = "left" className = { classes . headerCell } > ID in Source</ TableCell >
108
+ </ TableRow >
109
+ </ TableHead >
110
+ < TableBody >
111
+ {
112
+ _ . map ( participantListGrouped , ( row_group , index ) => {
113
+ return _ . map ( row_group , row => {
114
+ return < TableRow key = { row . source_id }
115
+ style = { { backgroundColor : tableRowColors [ index % _ . size ( tableRowColors ) ] } } >
116
+ < TableCell align = "left" > < Link href = "#" onClick = { ( ) => this . handleGetParticipant ( row . matching_id ) } > { row . matching_id } </ Link > </ TableCell >
117
+ < TableCell align = "left" > { row . first_name } </ TableCell >
118
+ < TableCell align = "left" > { row . last_name } </ TableCell >
119
+ < TableCell align = "left" > { row . email } </ TableCell >
120
+ < TableCell align = "left" > { row . mobile } </ TableCell >
121
+ < TableCell align = "left" > { row . source_type } </ TableCell >
122
+ < TableCell align = "left" > { row . source_id } </ TableCell >
123
+ </ TableRow >
124
+ } )
115
125
} )
116
- } )
117
- }
118
- </ TableBody >
119
- </ Table >
120
- </ TableContainer >
121
- </ Paper > )
126
+ }
127
+ </ TableBody >
128
+ </ Table >
129
+ </ TableContainer >
130
+ </ Paper >
131
+ </ Container > )
122
132
}
123
133
124
134
async handleSearchChange ( search_participant ) {
125
- this . setState ( { isDataBusy : true } ) ;
135
+ this . setState ( { isDataBusy : true , search_participant : search_participant } ) ;
126
136
127
137
await new Promise ( resolve => setTimeout ( resolve , 1000 ) ) ;
128
138
let response = await fetch ( `/api/contacts/${ search_participant } ` ) ;
@@ -131,27 +141,42 @@ class DataView360 extends Component {
131
141
await this . setState ( { participantList : response . result } )
132
142
133
143
this . state . participantTable = this . renderParticipantsTable ( ) ;
134
- this . setState ( { isDataBusy : false } ) ;
144
+ this . setState ( {
145
+ isDataBusy : false ,
146
+ showParticipant : false ,
147
+ showTable : true
148
+ } ) ;
135
149
}
136
150
137
151
render ( ) {
138
152
const { classes} = this . props ;
139
153
return (
140
154
< Container >
141
- < SearchBar participant = { this . state . participant }
155
+ { this . state . showSearchBar &&
156
+ ( < SearchBar participant = { this . state . participant }
142
157
handleParticipantChange = { this . handleGetParticipant }
143
158
handleSearchChange = { this . handleSearchChange } />
144
- { ( _ . isEmpty ( this . state . participantTable ) !== true && this . state . isDataBusy !== true ) && (
159
+ ) }
160
+ { ( _ . isEmpty ( this . state . participantTable ) !== true &&
161
+ this . state . isDataBusy !== true &&
162
+ this . state . showTable === true &&
163
+ this . state . showParticipant === false ) && (
145
164
< Container className = { styles . main } elevation = { 1 } style = { { "padding" : "1em" } } >
146
165
{ this . state . participantTable }
147
166
</ Container >
148
167
) }
149
- { ( _ . isEmpty ( this . state . participantData ) !== true && this . state . isDataBusy !== true ) && (
168
+ { ( _ . isEmpty ( this . state . participantData ) !== true &&
169
+ this . state . isDataBusy !== true &&
170
+ this . state . showParticipant === true ) && (
150
171
< 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' ) }
172
+ < ContactInfo participant = { _ . get ( this . state , 'participantData.contact_details' ) } />
173
+ < Button variant = "contained" color = "primary" className = { styles . back_button }
174
+ onClick = { ( ) => {
175
+ this . setState ( { showParticipant : false , showTable : true , showSearchBar : true } )
176
+ } } > Back to Results</ Button >
177
+ < Donations donations = { _ . get ( this . state , 'participantData.donations' ) } />
178
+ < Adoptions adoptions = { _ . get ( this . state , 'participantData.adoptions' ) } />
179
+ < Volunteer volunteer = { _ . get ( this . state , 'participantData.shifts' ) }
155
180
volunteerShifts = { _ . get ( this . state , 'participantData.volgistics_shifts_results' ) } />
156
181
157
182
</ Paper > ) }
0 commit comments