Adding Register option on the app
This commit is contained in:
2
API.js
2
API.js
@@ -189,7 +189,7 @@ const API = {
|
|||||||
return postCall("/user/invite", { name, email });
|
return postCall("/user/invite", { name, email });
|
||||||
},
|
},
|
||||||
getInvitation(email){
|
getInvitation(email){
|
||||||
return getCall("/user/invite", { email });
|
return getCall("/invite/" + email );
|
||||||
},
|
},
|
||||||
//Profiles
|
//Profiles
|
||||||
async getMe() {
|
async getMe() {
|
||||||
|
|||||||
@@ -1,10 +1,15 @@
|
|||||||
import { StatusBar } from 'expo-status-bar';
|
import { StatusBar } from 'expo-status-bar';
|
||||||
import React, { useEffect, useState } from 'react';
|
import React, { use, useEffect, useState } from 'react';
|
||||||
import { StyleSheet, Text, View, TextInput, SafeAreaView } from 'react-native';
|
import { StyleSheet, Text, View, Image, SafeAreaView } from 'react-native';
|
||||||
import API from './../API.js';
|
import API from './../API.js';
|
||||||
import LoginForm from './../components/Login.js';
|
import LoginForm from './../components/Login.js';
|
||||||
|
import RegisterForm from './../components/Register.js';
|
||||||
|
import i18n from "../i18nMessages.js";
|
||||||
|
import { Button } from 'react-native-paper';
|
||||||
|
|
||||||
export default function App({ navigation, route }) {
|
export default function App({ navigation, route }) {
|
||||||
|
const [isLogin, setIsLogin] = useState(true);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getData = async () => {
|
getData = async () => {
|
||||||
let r = await API.isLoggedIn();
|
let r = await API.isLoggedIn();
|
||||||
@@ -21,19 +26,54 @@ export default function App({ navigation, route }) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView style={styles.container}>
|
<SafeAreaView style={styles.container}>
|
||||||
<LoginForm />
|
<Image
|
||||||
<StatusBar style="auto" />
|
style={styles.logo}
|
||||||
<View style={{ position: "absolute", top: 60, left: 10, opacity: 0.5 }} >
|
source={require('./../assets/icon.png')}
|
||||||
<Text onPress={()=>{
|
/>
|
||||||
alert("Register your church on fellowshipapps.com");
|
<Text style={styles.header}>EMI Fellowship</Text>
|
||||||
}}>{"<- Not an EMI family member?"}</Text>
|
<View style={{ flexDirection: "row", justifyContent: "center", width: "100%" }}>
|
||||||
|
<Button disabled={isLogin} onPress={() => setIsLogin(true)}>
|
||||||
|
{i18n.t("message.login")}
|
||||||
|
</Button>
|
||||||
|
<Button disabled={!isLogin} onPress={() => setIsLogin(false)}>
|
||||||
|
{i18n.t("message.register")}
|
||||||
|
</Button>
|
||||||
</View>
|
</View>
|
||||||
|
{
|
||||||
|
isLogin ? <LoginForm /> : <RegisterForm />
|
||||||
|
}
|
||||||
|
<StatusBar style="auto" />
|
||||||
|
{/* <View style={{ position: "absolute", top: 60, left: 10, opacity: 0.5 }} >
|
||||||
|
<Text onPress={() => {
|
||||||
|
alert("Register your church on fellowshipapps.com");
|
||||||
|
}}>{"<- Not an EMI family member?"}</Text>
|
||||||
|
</View> */}
|
||||||
</SafeAreaView>
|
</SafeAreaView>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
container: {
|
container: {
|
||||||
|
backgroundColor: 'white',
|
||||||
flex: 1,
|
flex: 1,
|
||||||
|
flexDirection: "column",
|
||||||
|
justifyContent: "center",
|
||||||
|
width: "100%",
|
||||||
|
alignContent: 'center',
|
||||||
|
alignItems: 'center',
|
||||||
|
},
|
||||||
|
header: {
|
||||||
|
fontFamily: 'Helvetica-Bold',
|
||||||
|
fontSize: 42,
|
||||||
|
textAlign: "left",
|
||||||
|
paddingBottom: 15,
|
||||||
|
color: '#777',
|
||||||
|
alignContent: 'center'
|
||||||
|
},
|
||||||
|
logo: {
|
||||||
|
width: 250,
|
||||||
|
height: 250,
|
||||||
|
justifyContent: 'center',
|
||||||
|
alignItems: 'center',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -42,12 +42,6 @@ let LoginForm = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.mainView}>
|
<View style={styles.mainView}>
|
||||||
<Image
|
|
||||||
style={styles.logo}
|
|
||||||
source={require('./../assets/icon.png')}
|
|
||||||
/>
|
|
||||||
<Text style={styles.header}>EMI Fellowship</Text>
|
|
||||||
<Text >{i18n.t("message.login")}</Text>
|
|
||||||
<TextInput
|
<TextInput
|
||||||
style={styles.input}
|
style={styles.input}
|
||||||
onChangeText={text => setEmail(text)}
|
onChangeText={text => setEmail(text)}
|
||||||
@@ -107,29 +101,10 @@ export default LoginForm;
|
|||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
mainView: {
|
mainView: {
|
||||||
backgroundColor: 'white',
|
|
||||||
flex: 1,
|
|
||||||
flexDirection: "column",
|
|
||||||
justifyContent: "center",
|
|
||||||
padding: 15,
|
|
||||||
width: "100%",
|
width: "100%",
|
||||||
alignContent: 'center',
|
alignContent: 'center',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
},
|
},
|
||||||
header: {
|
|
||||||
fontFamily: 'Helvetica-Bold',
|
|
||||||
fontSize: 42,
|
|
||||||
textAlign: "left",
|
|
||||||
paddingBottom: 15,
|
|
||||||
color: '#777',
|
|
||||||
alignContent: 'center'
|
|
||||||
},
|
|
||||||
logo: {
|
|
||||||
width: 250,
|
|
||||||
height: 250,
|
|
||||||
justifyContent: 'center',
|
|
||||||
alignItems: 'center',
|
|
||||||
},
|
|
||||||
input: {
|
input: {
|
||||||
backgroundColor: 'white',
|
backgroundColor: 'white',
|
||||||
width: "80%"
|
width: "80%"
|
||||||
|
|||||||
165
components/Register.js
Normal file
165
components/Register.js
Normal file
@@ -0,0 +1,165 @@
|
|||||||
|
import React, { useState } from 'react';
|
||||||
|
import { Text, View, StyleSheet, Image } from 'react-native';
|
||||||
|
import { TextInput, Button, HelperText } from 'react-native-paper';
|
||||||
|
import API from './../API.js';
|
||||||
|
import { useNavigation } from '@react-navigation/native';
|
||||||
|
import i18n from "../i18nMessages.js";
|
||||||
|
|
||||||
|
|
||||||
|
let RegisterForm = () => {
|
||||||
|
const [email, setEmail] = useState('');
|
||||||
|
const [password, setPassword] = useState('');
|
||||||
|
const [password2, setPassword2] = useState('');
|
||||||
|
const navigation = useNavigation();
|
||||||
|
const [firstName, setFirstName] = useState('');
|
||||||
|
const [lastName, setLastName] = useState('');
|
||||||
|
const [description, setDescription] = useState('');
|
||||||
|
const [emailValidated, setEmailValidated] = useState(false);
|
||||||
|
|
||||||
|
const validateEmail = async () => {
|
||||||
|
if (!email) return;
|
||||||
|
API.getInvitation(email)
|
||||||
|
.then(data => {
|
||||||
|
//console.log(data);
|
||||||
|
if (data && data.status && data.status === 'ok') setEmailValidated(true);
|
||||||
|
else alert(data.status);
|
||||||
|
}).catch(console.log);
|
||||||
|
}
|
||||||
|
|
||||||
|
const registerUser = async () => {
|
||||||
|
if (!password || (password != password2))
|
||||||
|
return alert("Passwords do not match!");
|
||||||
|
if (!firstName || !lastName)
|
||||||
|
return alert("Please enter your name!");
|
||||||
|
if (!description)
|
||||||
|
return alert("Please enter a description!");
|
||||||
|
await API.signup(email, password, email, {
|
||||||
|
firstName,
|
||||||
|
lastName,
|
||||||
|
description
|
||||||
|
})
|
||||||
|
.then(data => {
|
||||||
|
console.log('registerData:', data);
|
||||||
|
if (data && data.status && data.status === 'ok') {
|
||||||
|
return navigation.reset({
|
||||||
|
index: 0,
|
||||||
|
routes: [{ name: 'MainNavigation' }],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}).catch( (error) => {
|
||||||
|
console.error("error at registering", error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const registrationData = (
|
||||||
|
<>
|
||||||
|
<TextInput
|
||||||
|
style={styles.input}
|
||||||
|
onChangeText={text => setPassword(text)}
|
||||||
|
defaultValue={password}
|
||||||
|
placeholder="password"
|
||||||
|
textContentType="password"
|
||||||
|
label={i18n.t("message.password")}
|
||||||
|
secureTextEntry={true}
|
||||||
|
autoCapitalize='none'
|
||||||
|
autoComplete='email'
|
||||||
|
autoCorrect={false}
|
||||||
|
mode="outlined"
|
||||||
|
/>
|
||||||
|
<TextInput
|
||||||
|
style={styles.input}
|
||||||
|
onChangeText={text => setPassword2(text)}
|
||||||
|
defaultValue={password}
|
||||||
|
placeholder="same password"
|
||||||
|
textContentType="same password"
|
||||||
|
label={i18n.t("message.rpassword")}
|
||||||
|
secureTextEntry={true}
|
||||||
|
autoCapitalize='none'
|
||||||
|
autoComplete='email'
|
||||||
|
autoCorrect={false}
|
||||||
|
mode="outlined"
|
||||||
|
/>
|
||||||
|
<TextInput
|
||||||
|
style={styles.input}
|
||||||
|
onChangeText={text => setFirstName(text)}
|
||||||
|
defaultValue={firstName}
|
||||||
|
placeholder="First Name"
|
||||||
|
label={i18n.t("message.name")}
|
||||||
|
autoCapitalize='words'
|
||||||
|
autoComplete='name'
|
||||||
|
mode="outlined"
|
||||||
|
keyboardType='default'
|
||||||
|
/>
|
||||||
|
<TextInput
|
||||||
|
style={styles.input}
|
||||||
|
onChangeText={text => setLastName(text)}
|
||||||
|
defaultValue={lastName}
|
||||||
|
placeholder="Last Name"
|
||||||
|
label={i18n.t("message.lastName")}
|
||||||
|
autoCapitalize='words'
|
||||||
|
autoComplete='name'
|
||||||
|
mode="outlined"
|
||||||
|
keyboardType='default'
|
||||||
|
/>
|
||||||
|
<TextInput
|
||||||
|
style={styles.input}
|
||||||
|
onChangeText={text => setDescription(text)}
|
||||||
|
defaultValue={description}
|
||||||
|
placeholder="Description so others can know you"
|
||||||
|
label={i18n.t("message.describeYourself")}
|
||||||
|
autoCapitalize='sentences'
|
||||||
|
autoComplete='description'
|
||||||
|
mode="outlined"
|
||||||
|
keyboardType='default'
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={styles.mainView}>
|
||||||
|
<TextInput
|
||||||
|
style={styles.input}
|
||||||
|
onChangeText={text => setEmail(text)}
|
||||||
|
defaultValue={email}
|
||||||
|
placeholder="email"
|
||||||
|
label={i18n.t("message.email")}
|
||||||
|
autoCapitalize='none'
|
||||||
|
autoComplete='email'
|
||||||
|
autoCorrect={false}
|
||||||
|
mode="outlined"
|
||||||
|
keyboardType='email-address'
|
||||||
|
disabled={emailValidated}
|
||||||
|
/>
|
||||||
|
{emailValidated ? registrationData : <></>}
|
||||||
|
<View style={{ flexDirection: "row" }}>
|
||||||
|
<Button
|
||||||
|
style={styles.button}
|
||||||
|
onPress={async () => {
|
||||||
|
if (emailValidated) registerUser();
|
||||||
|
else validateEmail();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{i18n.t("message.submit")}
|
||||||
|
</Button>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default RegisterForm;
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
mainView: {
|
||||||
|
width: "100%",
|
||||||
|
alignContent: 'center',
|
||||||
|
alignItems: 'center',
|
||||||
|
},
|
||||||
|
input: {
|
||||||
|
backgroundColor: 'white',
|
||||||
|
width: "80%"
|
||||||
|
},
|
||||||
|
button: {
|
||||||
|
marginTop: 10,
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -41,7 +41,8 @@ const messages = {
|
|||||||
rpassword: "Repeat Password",
|
rpassword: "Repeat Password",
|
||||||
resetPassword: "Reset password",
|
resetPassword: "Reset password",
|
||||||
register: "Register",
|
register: "Register",
|
||||||
name: "Nombre",
|
name: "Name",
|
||||||
|
firstName: "First Name",
|
||||||
lastName: "Last Name",
|
lastName: "Last Name",
|
||||||
describeYourself: 'Describe Yourself',
|
describeYourself: 'Describe Yourself',
|
||||||
continueWatching: "Continues Watching",
|
continueWatching: "Continues Watching",
|
||||||
@@ -114,6 +115,7 @@ const messages = {
|
|||||||
resetPassword: 'Restablecer contraseña',
|
resetPassword: 'Restablecer contraseña',
|
||||||
register: 'Registrarse',
|
register: 'Registrarse',
|
||||||
name: 'Nombre',
|
name: 'Nombre',
|
||||||
|
firstName: 'Nombre',
|
||||||
lastName: 'Apellido',
|
lastName: 'Apellido',
|
||||||
describeYourself: 'Describirse',
|
describeYourself: 'Describirse',
|
||||||
continueWatching: 'Continuar viendo',
|
continueWatching: 'Continuar viendo',
|
||||||
@@ -186,6 +188,7 @@ const messages = {
|
|||||||
resetPassword: 'Réinitialiser le mot de passe',
|
resetPassword: 'Réinitialiser le mot de passe',
|
||||||
register: 'S\'inscrire',
|
register: 'S\'inscrire',
|
||||||
name: 'Nom',
|
name: 'Nom',
|
||||||
|
firstName: 'Prénom',
|
||||||
lastName: 'Nom de famille',
|
lastName: 'Nom de famille',
|
||||||
describeYourself: 'Décrivez-vous',
|
describeYourself: 'Décrivez-vous',
|
||||||
continueWatching: 'Continuer à regarder',
|
continueWatching: 'Continuer à regarder',
|
||||||
@@ -258,6 +261,7 @@ const messages = {
|
|||||||
resetPassword: "Nulstil adgangskode",
|
resetPassword: "Nulstil adgangskode",
|
||||||
register: "Registrer",
|
register: "Registrer",
|
||||||
name: "Navn",
|
name: "Navn",
|
||||||
|
firstName: "Fornavn",
|
||||||
lastName: "Efternavn",
|
lastName: "Efternavn",
|
||||||
describeYourself: 'Beskriv dig selv',
|
describeYourself: 'Beskriv dig selv',
|
||||||
continueWatching: "Fortsæt med at se",
|
continueWatching: "Fortsæt med at se",
|
||||||
|
|||||||
Reference in New Issue
Block a user