Procházet zdrojové kódy

support for two user types

Zander Cuz před 3 roky
rodič
revize
d3515ec629
2 změnil soubory, kde provedl 50 přidání a 27 odebrání
  1. 26
    15
      redux/actions/index.js
  2. 24
    12
      screens/auth/RegisterScreen.js

+ 26
- 15
redux/actions/index.js Zobrazit soubor

@@ -1,19 +1,30 @@
1
-import { USER_STATE_CHANGE } from '../constants/index'
2
-import firebase from 'firebase'
1
+import firebase from "firebase";
3 2
 
4
-export function fetchUser(){
5
-    return((dispatch) => {
3
+import { USER_STATE_CHANGE } from "../constants";
4
+
5
+export function fetchUser() {
6
+    return ((dispatch) => {
6 7
         firebase.firestore()
7
-        .collection("Users")
8
-        .doc(firebase.auth().currentUser.uid)
9
-        .get()
10
-        .then((snapshot) => {
11
-            if(snapshot.exists){
12
-                dispatch({type : USER_STATE_CHANGE, currentUser : snapshot.data()})
13
-            }
14
-            else{
15
-                console.log('Does not exist')
16
-            }
17
-        })
8
+            .collection("Users")
9
+            .doc(firebase.auth().currentUser.uid)
10
+            .get()
11
+            .then((snapshot) => {
12
+                if(snapshot.exists){
13
+                    dispatch({type: USER_STATE_CHANGE, currentUser: snapshot.data()})
14
+                }
15
+                else{
16
+                    firebase.firestore().collection("Interpreters")
17
+                    .doc(firebase.auth().currentUser.uid)
18
+                    .get()
19
+                    .then((snapshot) => {
20
+                        if(snapshot.exists){
21
+                            dispatch({type: USER_STATE_CHANGE, currentUser: snapshot.data()})
22
+                        }
23
+                        else{
24
+                            console.log("DOES NOT EXIST")
25
+                        }
26
+                    })
27
+                }
28
+            })
18 29
     })
19 30
 }

+ 24
- 12
screens/auth/RegisterScreen.js Zobrazit soubor

@@ -1,10 +1,10 @@
1 1
 import React, { Component } from "react";
2
-import { TextInput, TouchableWithoutFeedback, Keyboard, ImageBackground, Text, View } from "react-native";
2
+import { TextInput, TouchableWithoutFeedback, Keyboard, ImageBackground, Text } from "react-native";
3 3
 import firebase from "firebase";
4 4
 import { Picker } from "@react-native-picker/picker";
5 5
 
6
-import { styles } from "../../config/styles";
7
-import CustomButton from "../../components/CustomButton";
6
+import { styles } from "../config/styles";
7
+import CustomButton from "../components/CustomButton";
8 8
 
9 9
 export default class RegisterScreen extends Component {
10 10
     constructor(props) {
@@ -22,14 +22,26 @@ export default class RegisterScreen extends Component {
22 22
         const { username, email, password, interpreter } = this.state;
23 23
         firebase.auth().createUserWithEmailAndPassword(email, password)
24 24
             .then((result) => {
25
-                firebase.firestore().collection("Users")
26
-                    .doc(firebase.auth().currentUser.uid)
27
-                    .set({
28
-                        username,
29
-                        email,
30
-                        interpreter,
31
-                    })
32
-                console.log(result)
25
+                if (interpreter) {
26
+                    firebase.firestore().collection("Interpreters")
27
+                        .doc(firebase.auth().currentUser.uid)
28
+                        .set({
29
+                            username,
30
+                            email,
31
+                            interpreter,
32
+                        })
33
+                    console.log(result)  
34
+                } 
35
+                else {
36
+                    firebase.firestore().collection("Users")
37
+                        .doc(firebase.auth().currentUser.uid)
38
+                        .set({
39
+                            username,
40
+                            email,
41
+                            interpreter,
42
+                        })
43
+                    console.log(result)  
44
+                }
33 45
             })
34 46
             .catch((error) => {
35 47
                 console.log(error)
@@ -39,7 +51,7 @@ export default class RegisterScreen extends Component {
39 51
     render() {
40 52
         return (
41 53
             <TouchableWithoutFeedback style={styles.regcontainer} onPress={Keyboard.dismiss} accessible={false}>
42
-                <ImageBackground style={styles.regcontainer} source={require('../../assets/yellow-white.jpg')}>
54
+                <ImageBackground style={styles.regcontainer} source={require('../assets/yellow-white.jpg')}>
43 55
                     <TextInput style={styles.regtxtfield} placeholder="Userame" onChangeText={(username) => this.setState({ username })}/>
44 56
                     <TextInput style={styles.regtxtfield} placeholder="Email" onChangeText={(email) => this.setState({ email })}/>
45 57
                     <TextInput style={styles.regtxtfield} placeholder="Password" onChangeText={(password) => this.setState({ password })} secureTextEntry={ true }/>