No Description

RegisterScreen.js 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import React, { Component } from "react";
  2. import { TextInput, TouchableWithoutFeedback, Keyboard, ImageBackground, Text } from "react-native";
  3. import firebase from "firebase";
  4. import { Picker } from "@react-native-picker/picker";
  5. import { styles } from "../../config/styles";
  6. import CustomButton from "../../components/CustomButton";
  7. export default class RegisterScreen extends Component {
  8. constructor(props) {
  9. super(props);
  10. this.state = {
  11. username: '',
  12. email: '',
  13. password: '',
  14. interpreter: '',
  15. };
  16. this.onRegister = this.onRegister.bind(this)
  17. };
  18. onRegister() {
  19. const { username, email, password, interpreter } = this.state;
  20. firebase.auth().createUserWithEmailAndPassword(email, password)
  21. .then((result) => {
  22. if (interpreter) {
  23. firebase.firestore().collection("Interprete")
  24. .doc(firebase.auth().currentUser.uid)
  25. .set({
  26. username,
  27. email,
  28. interpreter,
  29. })
  30. console.log(result)
  31. }
  32. else {
  33. firebase.firestore().collection("Users")
  34. .doc(firebase.auth().currentUser.uid)
  35. .set({
  36. username,
  37. email,
  38. interpreter,
  39. })
  40. console.log(result)
  41. }
  42. })
  43. .catch((error) => {
  44. console.log(error)
  45. })
  46. }
  47. render() {
  48. return (
  49. <TouchableWithoutFeedback style={styles.regcontainer} onPress={Keyboard.dismiss} accessible={false}>
  50. <ImageBackground style={styles.regcontainer} source={require('../../assets/yellow-white.jpg')}>
  51. <TextInput style={styles.regtxtfield} placeholder="Userame" onChangeText={(username) => this.setState({ username })}/>
  52. <TextInput style={styles.regtxtfield} placeholder="Email" onChangeText={(email) => this.setState({ email })}/>
  53. <TextInput style={styles.regtxtfield} placeholder="Password" onChangeText={(password) => this.setState({ password })} secureTextEntry={ true }/>
  54. <Text style={styles.qsttxt}>Are you an interpreter?</Text>
  55. <Picker style={styles.picker} selectedValue={this.state.interpreter} onValueChange={(itemValue,itemIndex) => this.setState({interpreter: itemValue})}>
  56. <Picker.Item label="Yes" value={true}/>
  57. <Picker.Item label="No" value={false}/>
  58. </Picker>
  59. <CustomButton marginTop={50} title="Register" onPress={() => this.onRegister()}/>
  60. </ImageBackground>
  61. </TouchableWithoutFeedback>
  62. );
  63. }
  64. }