Created
August 7, 2018 18:35
-
-
Save syamjayaraj/c2b3fddc170d8d65c51b527ae6691ff2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
addDonor = (name, mobile, group) => { | |
if(this.state.name != null && this.state.mobile != null && this.state.group != null){ | |
fetch('https://blood-donors-db.firebaseio.com/donors.json', { | |
method: 'POST', | |
headers: { | |
Accept: 'application/json', | |
'Content-Type': 'application/json', | |
}, | |
body: JSON.stringify({ | |
"name": name, | |
"mobile": mobile, | |
"group": group, | |
}), | |
}) | |
.then((response) => response.json()) | |
.then((responseData) => { | |
if(responseData.name != null ){ | |
this.setState({ | |
name: null, | |
mobile: null, | |
group: null, | |
isSubmited: true, | |
}) | |
} | |
else{ | |
Alert.alert( | |
'Oops !', | |
'Something went wrong', | |
[ | |
{text: 'OK', onPress: () => console.log('Cancel Pressed'), style: 'cancel'}, | |
], | |
{ cancelable: false } | |
) | |
} | |
}) | |
.done(); | |
} | |
else{ | |
Alert.alert( | |
'Oops !', | |
'You forgot some field. Please fill it before submitting', | |
[ | |
{text: 'OK', onPress: () => console.log('Cancel Pressed'), style: 'cancel'}, | |
], | |
{ cancelable: false } | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment