1
1
import React , { Component } from 'react' ;
2
- import { View , Text , TextInput , KeyboardAvoidingView , Keyboard , TouchableOpacity , Modal , TouchableWithoutFeedback } from "react-native" ;
2
+ import { View , Text , TextInput , KeyboardAvoidingView , Keyboard , TouchableOpacity , Modal , TouchableWithoutFeedback , Switch , ActivityIndicator } from "react-native" ;
3
3
import DateTimePicker from 'react-native-modal-datetime-picker' ;
4
4
import { CreateActivityStyle as styles } from './styles' ;
5
+ import { sendNotificationToAllUsers } from '../notification/NotificationService' ;
5
6
6
7
class CreateActivityView extends Component {
7
8
constructor ( props ) {
@@ -18,6 +19,8 @@ class CreateActivityView extends Component {
18
19
isButtonDisabled : true ,
19
20
modalVisible :false ,
20
21
success :false ,
22
+ notificationToAll :true ,
23
+ loading :false ,
21
24
} ;
22
25
}
23
26
_showDateTimePicker = ( ) => {
@@ -47,6 +50,19 @@ class CreateActivityView extends Component {
47
50
res = await this . props . onNewActivityHandler ( this . state . fullDate , this . state . fullTime , this . state . activityName , this . state . fullFormatDate )
48
51
if ( res === 'ok' )
49
52
this . setState ( { success : true } ) ;
53
+ //send notification to all users
54
+ if ( this . state . notificationToAll ) {
55
+ const { hospital, first, last } = this . props ;
56
+ let activity = {
57
+ hospital : hospital ,
58
+ coordinatorName : first + ' ' + last ,
59
+ nameActivity : this . state . activityName ,
60
+ time : this . state . fullDate ,
61
+ }
62
+ this . setState ( { loading :true } )
63
+ await sendNotificationToAllUsers ( activity )
64
+ this . setState ( { loading :false } )
65
+ }
50
66
this . setState ( { modalVisible : true } ) ;
51
67
}
52
68
else {
@@ -100,12 +116,28 @@ class CreateActivityView extends Component {
100
116
: this . alertDate
101
117
}
102
118
</ Text >
119
+ < View style = { { flexDirection :'row' , justifyContent : "center" } } >
120
+ < Text style = { { fontSize : 14 , color :'#B93A32' } } > לשלוח התראות על האירוע לכל המשתמשים?</ Text >
121
+ < Switch
122
+ onTintColor = { '#00A591' }
123
+ thumbTintColor = { this . state . notificationToAll ? '#79C753' : '#898E8C' }
124
+ tintColor = { '#B93A32' }
125
+ style = { styles . switch }
126
+ onValueChange = { ( ) => this . setState ( { notificationToAll :! this . state . notificationToAll } ) }
127
+ value = { this . state . notificationToAll }
128
+ />
129
+ </ View >
103
130
< TouchableOpacity
104
131
rounded
105
- disabled = { this . state . isButtonDisabled }
132
+ disabled = { this . state . isButtonDisabled || this . state . loading }
106
133
onPress = { this . createNewActivity }
107
134
style = { [ styles . button , this . state . isButtonDisabled ? { backgroundColor :'#c6c6c6' } : { } ] } >
135
+ {
136
+ ! this . state . loading ?
108
137
< Text style = { styles . buttonText } > אישור</ Text >
138
+ :
139
+ < ActivityIndicator size = 'large' color = '#FFFFFF' />
140
+ }
109
141
</ TouchableOpacity >
110
142
</ View >
111
143
</ TouchableWithoutFeedback >
0 commit comments