@@ -16,6 +16,7 @@ export default React.createClass({
16
16
17
17
propTypes : {
18
18
assignment : React . PropTypes . object . isRequired ,
19
+ mission : React . PropTypes . object . isRequired ,
19
20
onChange : React . PropTypes . func ,
20
21
onRemove : React . PropTypes . func ,
21
22
} ,
@@ -35,17 +36,39 @@ export default React.createClass({
35
36
36
37
getInitialState ( ) {
37
38
const group = ( this . context . volunteers [ this . props . assignment . volunteer ] || { } ) . group ;
38
- const volunteers = this . getVolunteersByGroup ( group ) ;
39
- return { group, volunteers } ;
39
+ return { group } ;
40
40
} ,
41
41
42
- getVolunteersByGroup ( group ) {
43
- return _ . filter ( this . context . volunteers , volunteer => group === volunteer . group ) ;
42
+ componentDidMount ( ) {
43
+ this . setSuitableVolunteers ( ) ;
44
+ } ,
45
+
46
+ componentWillReceiveProps ( nextProps ) {
47
+ this . setSuitableVolunteers ( nextProps . mission ) ;
48
+ } ,
49
+
50
+ setSuitableVolunteers ( mission = this . props . mission ) {
51
+ const group = this . state . group ;
52
+ const now = new Date ( ) ;
53
+ const start = new Date ( mission . start ) ;
54
+ const end = new Date ( mission . end ) ;
55
+
56
+ const isAvailable = av => (
57
+ new Date ( av . confirmationTill ) >= now &&
58
+ new Date ( av . from ) <= start &&
59
+ new Date ( av . till ) >= end
60
+ ) ;
61
+
62
+ const volunteers = _ . filter ( this . context . volunteers , volunteer =>
63
+ group === volunteer . group &&
64
+ volunteer . availabilities . length &&
65
+ volunteer . availabilities . find ( isAvailable ) ) ;
66
+
67
+ this . setState ( { volunteers } ) ;
44
68
} ,
45
69
46
70
changeGroup ( { value } ) {
47
- const volunteers = this . getVolunteersByGroup ( value ) ;
48
- this . setState ( { group : value , volunteers } ) ;
71
+ this . setState ( { group : value } , this . setSuitableVolunteers ) ;
49
72
} ,
50
73
51
74
changeName ( { value } ) {
0 commit comments