11import 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" ;
33import DateTimePicker from 'react-native-modal-datetime-picker' ;
44import { CreateActivityStyle as styles } from './styles' ;
5+ import { sendNotificationToAllUsers } from '../notification/NotificationService' ;
56
67class CreateActivityView extends Component {
78 constructor ( props ) {
@@ -18,6 +19,8 @@ class CreateActivityView extends Component {
1819 isButtonDisabled : true ,
1920 modalVisible :false ,
2021 success :false ,
22+ notificationToAll :true ,
23+ loading :false ,
2124 } ;
2225 }
2326 _showDateTimePicker = ( ) => {
@@ -47,6 +50,19 @@ class CreateActivityView extends Component {
4750 res = await this . props . onNewActivityHandler ( this . state . fullDate , this . state . fullTime , this . state . activityName , this . state . fullFormatDate )
4851 if ( res === 'ok' )
4952 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+ }
5066 this . setState ( { modalVisible : true } ) ;
5167 }
5268 else {
@@ -100,12 +116,28 @@ class CreateActivityView extends Component {
100116 : this . alertDate
101117 }
102118 </ 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 >
103130 < TouchableOpacity
104131 rounded
105- disabled = { this . state . isButtonDisabled }
132+ disabled = { this . state . isButtonDisabled || this . state . loading }
106133 onPress = { this . createNewActivity }
107134 style = { [ styles . button , this . state . isButtonDisabled ? { backgroundColor :'#c6c6c6' } : { } ] } >
135+ {
136+ ! this . state . loading ?
108137 < Text style = { styles . buttonText } > אישור</ Text >
138+ :
139+ < ActivityIndicator size = 'large' color = '#FFFFFF' />
140+ }
109141 </ TouchableOpacity >
110142 </ View >
111143 </ TouchableWithoutFeedback >
0 commit comments