@@ -5,6 +5,7 @@ import { bindActionCreators } from 'redux';
55import { BarCodeScanner , Permissions } from 'expo' ;
66import { Keyboard , TextInput , Text , TouchableWithoutFeedback , TouchableOpacity , View , StyleSheet } from 'react-native' ;
77import Spacer from 'react-native-keyboard-spacer' ;
8+ import Sentry from 'sentry-expo' ;
89import { accept } from '../actions/authentication' ;
910import { initialize } from '../actions/overview' ;
1011import colours from '../styles/colours' ;
@@ -44,6 +45,9 @@ const styles = StyleSheet.create({
4445 fontSize : fonts . normal ,
4546 lineHeight : fonts . large ,
4647 } ,
48+ failed : {
49+ color : colours . reds . base ,
50+ } ,
4751 acceptButton : {
4852 marginLeft : 10 ,
4953 alignItems : 'center' ,
@@ -53,12 +57,16 @@ const styles = StyleSheet.create({
5357 color : colours . text ,
5458 fontSize : fonts . normal ,
5559 } ,
60+ disabled : {
61+ color : colours . greys . base ,
62+ } ,
5663} ) ;
5764
5865class Invites extends PureComponent {
5966 state = {
6067 hasCameraPermission : null ,
6168 inviteCode : null ,
69+ inviting : false ,
6270 } ;
6371
6472 componentDidMount ( ) {
@@ -92,14 +100,25 @@ class Invites extends PureComponent {
92100 return ;
93101 }
94102
95- await this . props . acceptInvite ( this . state . inviteCode ) ;
96- await this . props . initialize ( ) ;
97- this . props . navigation . goBack ( null ) ;
103+ try {
104+ this . setState ( { inviting : true , failed : false } ) ;
105+
106+ await this . props . acceptInvite ( this . state . inviteCode ) ;
107+ await this . props . initialize ( ) ;
108+ this . props . navigation . goBack ( null ) ;
109+ } catch ( err ) {
110+ Sentry . captureException ( err ) ;
111+ this . setState ( { failed : true } ) ;
112+ } finally {
113+ this . setState ( { inviting : false } ) ;
114+ }
98115 }
99116
100117 dismissKeyboard = ( ) => Keyboard . dismiss ( )
101118
102119 render ( ) {
120+ const disabled = ! this . state . inviteCode || this . state . inviting || this . state . failed ;
121+
103122 return (
104123 < View style = { styles . container } >
105124 { this . state . hasCameraPermission && (
@@ -125,20 +144,20 @@ class Invites extends PureComponent {
125144 </ View >
126145 < View style = { styles . bottomBar } >
127146 < TextInput
128- style = { styles . input }
147+ style = { [ styles . input , this . state . failed && styles . failed ] }
129148 autoCorrect = { false }
130149 spellCheck = { false }
131150 clearButtonMode = "always"
132151 onSubmitEditing = { this . accept }
133152 returnKeyType = "done"
134- onChangeText = { inviteCode => this . setState ( { inviteCode } ) }
153+ onChangeText = { inviteCode => this . setState ( { inviteCode, failed : false } ) }
135154 value = { this . state . inviteCode }
136155 placeholderTextColor = { colours . greys . lighter }
137156 placeholder = { I18n . t ( 'invites/placeholder' ) }
138157 underlineColorAndroid = "transparent"
139158 />
140- < TouchableOpacity style = { styles . acceptButton } onPress = { this . accept } disabled = { ! this . state . inviteCode } >
141- < Text style = { styles . acceptButtonText } > { I18n . t ( 'invites/accept' ) } </ Text >
159+ < TouchableOpacity style = { styles . acceptButton } onPress = { this . accept } disabled = { disabled } >
160+ < Text style = { [ styles . acceptButtonText , disabled && styles . disabled ] } > { I18n . t ( 'invites/accept' ) } </ Text >
142161 </ TouchableOpacity >
143162 </ View >
144163 < Spacer />
0 commit comments