Files
notesnook/apps/mobile/src/components/LoginDialog/index.js

871 lines
29 KiB
JavaScript
Raw Normal View History

2020-09-14 12:17:06 +05:00
import CheckBox from '@react-native-community/checkbox';
2020-09-19 16:02:21 +05:00
import React, {createRef, useEffect, useState} from 'react';
import {Clipboard, Modal, Text, TouchableOpacity, View} from 'react-native';
import {TextInput} from 'react-native-gesture-handler';
2020-09-14 11:43:07 +05:00
import QRCode from 'react-native-qrcode-generator';
2020-09-19 16:02:21 +05:00
import {useSafeAreaInsets} from 'react-native-safe-area-context';
2020-09-14 11:43:07 +05:00
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
2020-09-19 16:02:21 +05:00
import {opacity, ph, pv, SIZE, WEIGHT} from '../../common/common';
import {Button} from '../../components/Button';
2020-09-14 11:43:07 +05:00
import Seperator from '../../components/Seperator';
2020-09-19 16:02:21 +05:00
import {Toast} from '../../components/Toast';
import {ACTIONS} from '../../provider/actions';
import {useTracked} from '../../provider/index';
2020-09-14 12:33:04 +05:00
import {
eSendEvent,
eSubscribeEvent,
2020-09-19 16:02:21 +05:00
eUnSubscribeEvent,
2020-09-14 12:33:04 +05:00
} from '../../services/eventManager';
2020-09-24 09:17:14 +05:00
import {
eCloseLoginDialog,
eOpenLoginDialog,
eStartSyncer,
refreshNotesPage,
} from '../../services/events';
2020-09-14 11:43:07 +05:00
import {
validateEmail,
validatePass,
2020-09-19 16:02:21 +05:00
validateUsername,
2020-09-14 11:43:07 +05:00
} from '../../services/validation';
2020-09-19 16:02:21 +05:00
import {db, DDS, getElevation, ToastEvent} from '../../utils/utils';
import {Loading} from '../Loading';
2020-01-23 23:18:15 +05:00
2020-09-14 11:43:07 +05:00
const LoginDialog = () => {
const [state, dispatch] = useTracked();
const colors = state.colors;
2020-09-14 12:33:04 +05:00
const [visible, setVisible] = useState(false);
2020-09-14 12:17:06 +05:00
const [status, setStatus] = useState('Logging you in');
2020-09-14 11:43:07 +05:00
const [loggingIn, setLoggingIn] = useState(false);
const [email, setEmail] = useState(null);
const [password, setPassword] = useState(null);
const [invalidEmail, setInvalidEmail] = useState(false);
const [invalidPassword, setInvalidPassword] = useState(false);
const [username, setUsername] = useState(null);
const [invalidUsername, setInvalidUsername] = useState(false);
const [secureEntry, setSecureEntry] = useState(true);
const [confirmPassword, setConfirmPassword] = useState(false);
2020-09-14 12:17:06 +05:00
const [key, setKey] = useState('abc123');
2020-09-14 11:43:07 +05:00
const [passwordReEnter, setPasswordReEnter] = useState(null);
const [failed, setFailed] = useState(false);
const [signingIn, setSigningIn] = useState(false);
const [login, setLogin] = useState(true);
const [modalVisible, setModalVisible] = useState(false);
const [userConsent, setUserConsent] = useState(false);
const _email = createRef();
const _pass = createRef();
const _username = createRef();
const _passConfirm = createRef();
const _passContainer = createRef();
2020-09-14 12:33:04 +05:00
const insets = useSafeAreaInsets();
useEffect(() => {
eSubscribeEvent(eOpenLoginDialog, open);
return () => {
eUnSubscribeEvent(eOpenLoginDialog, open);
};
}, []);
2020-01-23 23:18:15 +05:00
2020-09-14 11:43:07 +05:00
function open() {
setVisible(true);
2020-01-23 23:18:15 +05:00
}
2020-09-14 11:43:07 +05:00
const close = () => {
2020-09-27 10:15:19 +05:00
_email.current?.clear();
_pass.current?.clear();
_passConfirm.current?.clear();
_username.current?.clear();
2020-09-14 11:43:07 +05:00
setVisible(false);
2020-09-27 10:15:19 +05:00
setUsername(null);
setPassword(null);
setConfirmPassword(null);
setKey(null);
setLogin(true);
setModalVisible(false);
setUserConsent(false);
setEmail(false);
setLoggingIn(false);
2020-09-14 11:43:07 +05:00
};
2020-01-23 23:18:15 +05:00
2020-09-14 11:43:07 +05:00
const loginUser = async () => {
if (
!password ||
password.length < 8 ||
!username ||
invalidPassword ||
invalidUsername
) {
2020-09-14 13:34:55 +05:00
ToastEvent.show('username or password is invalid', 'error', 'local');
2020-09-14 11:43:07 +05:00
return;
}
2020-09-14 13:34:55 +05:00
2020-09-14 11:43:07 +05:00
setLoggingIn(true);
_username.current.blur();
_pass.current.blur();
2020-09-24 09:42:12 +05:00
setStatus('Logging in');
2020-09-14 11:43:07 +05:00
try {
let res = await db.user.login(username.toLowerCase(), password);
console.log(res, username, password);
} catch (e) {
setTimeout(() => {
2020-09-14 13:34:55 +05:00
ToastEvent.show(e.message, 'error', 'local');
2020-09-14 11:43:07 +05:00
setLoggingIn(false);
}, 500);
return;
}
try {
2020-09-24 09:42:12 +05:00
let user = await db.user.get();
2020-09-14 11:43:07 +05:00
if (!user) throw new Error('Username or password incorrect');
2020-09-14 12:33:04 +05:00
setStatus('Syncing your notes');
2020-09-14 11:43:07 +05:00
dispatch({type: ACTIONS.USER, user: user});
dispatch({type: ACTIONS.SYNCING, syncing: true});
await db.sync();
eSendEvent(eStartSyncer);
dispatch({type: ACTIONS.ALL});
eSendEvent(refreshNotesPage);
2020-09-14 12:33:04 +05:00
setVisible(false);
2020-09-14 13:34:55 +05:00
ToastEvent.show(`Logged in as ${username}`, 'success', 'local');
2020-09-14 11:43:07 +05:00
} catch (e) {
2020-09-24 09:42:12 +05:00
ToastEvent.show(e.message, 'error', 'local');
} finally {
2020-09-14 11:43:07 +05:00
dispatch({type: ACTIONS.SYNCING, syncing: false});
setLoggingIn(false);
}
};
2020-09-27 10:15:19 +05:00
2020-09-14 11:43:07 +05:00
2020-09-14 12:43:15 +05:00
const validateInfo = () => {
if (!password || !email || !username || !passwordReEnter) {
ToastEvent.show('All fields are required', 'error', 'local');
return false;
}
if (!confirmPassword) {
ToastEvent.show('Passwords do not match', 'error', 'local');
return false;
}
if (!invalidEmail && !invalidPassword && !invalidUsername) {
ToastEvent.show('Signup information is invalid', 'error', 'local');
return false;
}
if (!userConsent) {
ToastEvent.show(
'You must agree to our terms of service and privacy policy.',
'error',
'local',
5000,
() => {
setUserConsent(true);
signupUser();
ToastEvent.hide();
},
'I Agree',
);
return false;
}
};
2020-09-14 11:43:07 +05:00
const signupUser = async () => {
if (!validateInfo) return;
setSigningIn(true);
2020-09-14 12:33:04 +05:00
setStatus('Creating your account');
2020-09-14 11:43:07 +05:00
try {
await db.user.signup(username, email, password);
} catch (e) {
setSigningIn(false);
setFailed(true);
ToastEvent.show('Signup failed, Network Error', 'error', 'local');
return;
}
let user;
try {
2020-09-24 09:17:14 +05:00
user = await db.user.get();
2020-09-14 11:43:07 +05:00
let k = await db.user.key();
setKey(k.key);
2020-09-14 12:33:04 +05:00
setStatus('Setting up crenditials');
2020-09-14 11:43:07 +05:00
dispatch({type: ACTIONS.USER, user: user});
eSendEvent(eStartSyncer);
2020-09-14 12:33:04 +05:00
setModalVisible(true);
2020-09-14 11:43:07 +05:00
} catch (e) {
setSigningIn(false);
setFailed(true);
ToastEvent.show('Login Failed, try again', 'error', 'local');
}
};
return (
<Modal
animated={true}
2020-09-14 12:33:04 +05:00
animationType="slide"
statusBarTranslucent={true}
2020-09-14 11:43:07 +05:00
onRequestClose={close}
visible={visible}
transparent={true}>
2020-09-14 12:33:04 +05:00
<View
2020-09-14 11:43:07 +05:00
style={{
2020-09-14 12:33:04 +05:00
opacity: 1,
2020-09-14 11:43:07 +05:00
flex: 1,
2020-09-14 12:33:04 +05:00
paddingTop: insets.top,
2020-09-14 11:43:07 +05:00
backgroundColor: DDS.isTab ? 'rgba(0,0,0,0.3)' : colors.bg,
width: '100%',
height: '100%',
alignSelf: 'center',
justifyContent: 'center',
alignItems: 'center',
}}>
{DDS.isTab ? (
2020-01-23 23:18:15 +05:00
<TouchableOpacity
2020-09-14 11:43:07 +05:00
onPress={close}
2020-01-23 23:18:15 +05:00
style={{
width: '100%',
height: '100%',
position: 'absolute',
zIndex: 1,
}}
/>
2020-09-14 11:43:07 +05:00
) : null}
<View
style={{
height: '100%',
width: '100%',
backgroundColor: colors.bg,
2020-09-14 12:17:06 +05:00
justifyContent: 'center',
2020-09-14 11:43:07 +05:00
}}>
2020-09-14 13:34:55 +05:00
<Toast context="local" />
2020-09-14 12:17:06 +05:00
{loggingIn || signingIn ? (
modalVisible ? (
2020-09-14 11:43:07 +05:00
<View
style={{
2020-09-14 12:17:06 +05:00
paddingHorizontal: 12,
2020-09-14 11:43:07 +05:00
width: '100%',
alignItems: 'center',
}}>
<Text
style={{
fontFamily: WEIGHT.bold,
2020-09-14 12:17:06 +05:00
fontSize: SIZE.xxxl,
2020-09-14 11:43:07 +05:00
color: colors.accent,
}}>
2020-09-14 12:17:06 +05:00
Data Recovery Key
2020-09-14 11:43:07 +05:00
</Text>
<Text
style={{
fontFamily: WEIGHT.regular,
2020-09-14 12:17:06 +05:00
fontSize: SIZE.md,
color: colors.icon,
2020-09-14 11:43:07 +05:00
textAlign: 'center',
}}>
2020-09-14 12:17:06 +05:00
We cannot recover your data if you forget your password. You
can use this recovery key to get your data back if you lose
your password.
2020-09-14 11:43:07 +05:00
</Text>
2020-01-23 23:18:15 +05:00
2020-09-14 11:43:07 +05:00
<Text
style={{
fontFamily: WEIGHT.regular,
fontSize: SIZE.sm,
maxWidth: '85%',
marginTop: 25,
marginBottom: 10,
color: colors.pri,
}}>
2020-09-14 12:17:06 +05:00
Take a Sceenshot of this screen
2020-09-14 11:43:07 +05:00
</Text>
<QRCode
value={key}
size={200}
bgColor="black"
fgColor="white"
/>
<TouchableOpacity
activeOpacity={0.6}
onPress={() => {
Clipboard.setString(key);
ToastEvent.show('Recovery key copied!', 'success', 'local');
}}
style={{
flexDirection: 'row',
borderWidth: 1,
borderRadius: 5,
paddingVertical: 8,
paddingHorizontal: 10,
marginTop: 15,
alignItems: 'center',
borderColor: colors.nav,
}}>
<Text
numberOfLines={2}
style={{
fontFamily: WEIGHT.regular,
fontSize: SIZE.sm,
width: '85%',
maxWidth: '85%',
paddingRight: 10,
color: colors.pri,
}}>
{key}
</Text>
<Icon color={colors.accent} size={SIZE.lg} name="clipboard" />
</TouchableOpacity>
<Text
style={{
color: colors.pri,
2020-09-14 12:17:06 +05:00
fontSize: SIZE.xs,
2020-09-14 11:43:07 +05:00
width: '85%',
maxWidth: '85%',
2020-09-14 12:17:06 +05:00
textAlign: 'center',
2020-09-14 11:43:07 +05:00
}}>
2020-09-14 12:17:06 +05:00
You can get recovery key in settings on any device later.
2020-09-14 11:43:07 +05:00
</Text>
<TouchableOpacity
onPress={() => {
2020-09-27 10:15:19 +05:00
close();
2020-09-14 11:43:07 +05:00
}}
activeOpacity={opacity}
style={{
...getElevation(5),
paddingVertical: pv + 5,
paddingHorizontal: ph,
borderRadius: 5,
width: '90%',
marginTop: 20,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: colors.accent,
}}>
<Text
style={{
fontFamily: WEIGHT.medium,
color: 'white',
fontSize: SIZE.sm,
}}>
I have saved the key
</Text>
</TouchableOpacity>
</View>
2020-09-14 12:17:06 +05:00
) : (
<Loading tagline={status} />
)
) : (
<>
<Icon
name="arrow-left"
size={SIZE.xxxl}
onPress={() => {
2020-09-27 10:15:19 +05:00
close();
2020-09-14 12:17:06 +05:00
}}
style={{
width: 50,
height: 50,
marginLeft: 12,
position: 'absolute',
textAlignVertical: 'center',
top: 0,
marginBottom: 15,
}}
color={colors.heading}
/>
2020-09-14 11:43:07 +05:00
<View
style={{
2020-09-14 12:17:06 +05:00
justifyContent: 'center',
width: '100%',
height: '100%',
alignSelf: 'center',
paddingHorizontal: 12,
2020-09-14 11:43:07 +05:00
}}>
2020-09-14 12:17:06 +05:00
<View
2020-09-14 11:43:07 +05:00
style={{
2020-09-14 12:17:06 +05:00
marginBottom: 25,
2020-09-14 11:43:07 +05:00
}}>
<Text
style={{
2020-09-14 12:17:06 +05:00
color: colors.accent,
fontFamily: WEIGHT.bold,
fontSize: SIZE.xxxl,
2020-09-14 11:43:07 +05:00
}}>
2020-09-14 12:17:06 +05:00
{login ? 'Login' : 'Sign up'}
{'\n'}
2020-09-14 11:43:07 +05:00
<Text
style={{
2020-09-14 12:17:06 +05:00
color: colors.icon,
fontSize: SIZE.md,
2020-09-14 11:43:07 +05:00
fontFamily: WEIGHT.regular,
}}>
2020-09-14 12:17:06 +05:00
{login
? 'Get all your notes from other devices'
: 'Create an account to access notes anywhere.'}
{}
2020-09-14 11:43:07 +05:00
</Text>
2020-09-14 12:17:06 +05:00
</Text>
</View>
2020-09-14 11:43:07 +05:00
2020-09-19 16:02:21 +05:00
<>
<TextInput
ref={_username}
onFocus={() => {
if (!invalidUsername) {
_username.current.setNativeProps({
style: {
borderColor: colors.accent,
},
});
}
}}
2020-09-24 09:17:14 +05:00
autoCapitalize="none"
2020-09-19 16:02:21 +05:00
defaultValue={username}
onBlur={() => {
if (!validateUsername(username) && username?.length > 0) {
setInvalidUsername(true);
_username.current.setNativeProps({
style: {
color: colors.errorText,
borderColor: colors.errorText,
},
});
} else {
setInvalidUsername(false);
_username.current.setNativeProps({
style: {
borderColor: colors.nav,
},
});
}
}}
textContentType="username"
onChangeText={(value) => {
setUsername(value);
if (invalidUsername && validateUsername(username)) {
setInvalidUsername(false);
_username.current.setNativeProps({
style: {
color: colors.pri,
borderColor: colors.accent,
},
});
}
}}
onSubmitEditing={() => {
if (!validateUsername(username)) {
setInvalidUsername(true);
_username.current.setNativeProps({
style: {
color: colors.errorText,
},
});
}
}}
style={{
paddingHorizontal: pv,
height: 50,
borderWidth: 1.5,
borderColor: colors.nav,
borderRadius: 5,
fontSize: SIZE.sm,
fontFamily: WEIGHT.regular,
2020-09-27 10:15:19 +05:00
color: colors.pri,
2020-09-19 16:02:21 +05:00
}}
placeholder="Username (a-z _- 0-9)"
placeholderTextColor={colors.icon}
/>
{invalidUsername ? (
<Text
style={{
textAlign: 'right',
fontFamily: WEIGHT.regular,
textAlignVertical: 'bottom',
fontSize: SIZE.xs,
marginTop: 2.5,
}}>
<Icon
name="alert-circle-outline"
size={SIZE.xs}
color={colors.errorText}
/>{' '}
Username is invalid
</Text>
) : null}
</>
<Seperator />
2020-09-14 12:17:06 +05:00
{login ? null : (
<>
<TextInput
2020-09-19 16:02:21 +05:00
ref={_email}
2020-09-14 12:17:06 +05:00
onFocus={() => {
2020-09-19 16:02:21 +05:00
if (!invalidEmail) {
_email.current.setNativeProps({
2020-09-14 12:17:06 +05:00
style: {
borderColor: colors.accent,
},
});
}
}}
2020-09-24 09:17:14 +05:00
autoCapitalize="none"
2020-09-19 16:02:21 +05:00
defaultValue={email}
2020-09-14 12:17:06 +05:00
onBlur={() => {
2020-09-19 16:02:21 +05:00
if (!validateEmail(email) && email?.length > 0) {
setInvalidEmail(true);
_email.current.setNativeProps({
2020-09-14 12:17:06 +05:00
style: {
color: colors.errorText,
borderColor: colors.errorText,
},
});
} else {
2020-09-19 16:02:21 +05:00
setInvalidEmail(false);
_email.current.setNativeProps({
2020-09-14 12:17:06 +05:00
style: {
borderColor: colors.nav,
},
});
}
}}
2020-09-19 16:02:21 +05:00
textContentType="emailAddress"
2020-09-14 12:17:06 +05:00
onChangeText={(value) => {
2020-09-19 16:02:21 +05:00
setEmail(value);
if (invalidEmail && validateEmail(email)) {
setInvalidEmail(false);
_email.current.setNativeProps({
2020-09-14 12:17:06 +05:00
style: {
color: colors.pri,
borderColor: colors.accent,
},
});
}
}}
onSubmitEditing={() => {
2020-09-19 16:02:21 +05:00
if (!validateEmail(email)) {
setInvalidEmail(true);
_email.current.setNativeProps({
2020-09-14 12:17:06 +05:00
style: {
color: colors.errorText,
},
});
}
}}
style={{
paddingHorizontal: pv,
height: 50,
borderWidth: 1.5,
2020-09-14 11:43:07 +05:00
borderColor: colors.nav,
2020-09-14 12:17:06 +05:00
borderRadius: 5,
fontSize: SIZE.sm,
fontFamily: WEIGHT.regular,
2020-09-27 10:15:19 +05:00
color: colors.pri,
2020-09-14 12:17:06 +05:00
}}
2020-09-19 16:02:21 +05:00
placeholder="Email"
2020-09-14 12:17:06 +05:00
placeholderTextColor={colors.icon}
/>
2020-09-19 16:02:21 +05:00
{invalidEmail ? (
2020-09-14 12:17:06 +05:00
<Text
style={{
textAlign: 'right',
fontFamily: WEIGHT.regular,
textAlignVertical: 'bottom',
fontSize: SIZE.xs,
marginTop: 2.5,
}}>
<Icon
name="alert-circle-outline"
size={SIZE.xs}
color={colors.errorText}
/>{' '}
2020-09-19 16:02:21 +05:00
Email is invalid
2020-09-14 12:17:06 +05:00
</Text>
) : null}
2020-09-24 09:17:14 +05:00
<Seperator />
2020-09-14 12:17:06 +05:00
</>
)}
<View
ref={_passContainer}
style={{
borderWidth: 1.5,
borderColor: colors.nav,
paddingHorizontal: 10,
borderRadius: 5,
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
}}>
2020-09-14 11:43:07 +05:00
<TextInput
2020-09-14 12:17:06 +05:00
ref={_pass}
onFocus={() => {
if (!invalidPassword) {
_passContainer.current?.setNativeProps({
2020-09-14 11:43:07 +05:00
style: {
2020-09-14 12:17:06 +05:00
borderColor: colors.accent,
2020-09-14 11:43:07 +05:00
},
});
2020-09-14 12:17:06 +05:00
}
}}
2020-09-24 09:17:14 +05:00
autoCapitalize="none"
2020-09-14 12:17:06 +05:00
defaultValue={password}
onBlur={() => {
if (!validatePass(password) && password?.length > 0) {
setInvalidPassword(true);
2020-09-14 11:43:07 +05:00
_pass.current.setNativeProps({
2020-09-14 12:17:06 +05:00
style: {
color: colors.errorText,
},
});
_passContainer.current?.setNativeProps({
2020-09-14 11:43:07 +05:00
style: {
borderColor: colors.errorText,
},
});
} else {
2020-09-14 12:17:06 +05:00
setInvalidPassword(false);
_passContainer.current?.setNativeProps({
2020-09-14 11:43:07 +05:00
style: {
2020-09-14 12:17:06 +05:00
borderColor: colors.nav,
2020-09-14 11:43:07 +05:00
},
});
2020-09-14 12:17:06 +05:00
}
}}
onChangeText={(value) => {
setPassword(value);
if (invalidPassword && validatePass(password)) {
setInvalidPassword(false);
2020-09-14 11:43:07 +05:00
_pass.current.setNativeProps({
style: {
2020-09-14 12:17:06 +05:00
color: colors.pri,
2020-09-14 11:43:07 +05:00
},
});
}
}}
2020-09-14 12:17:06 +05:00
onSubmitEditing={() => {
if (!validatePass(password)) {
setInvalidPassword(true);
_pass.current.setNativeProps({
style: {
color: colors.errorText,
},
});
}
2020-09-14 11:43:07 +05:00
}}
style={{
2020-09-14 12:17:06 +05:00
paddingHorizontal: 0,
2020-09-14 11:43:07 +05:00
height: 50,
fontSize: SIZE.sm,
fontFamily: WEIGHT.regular,
2020-09-14 12:17:06 +05:00
width: '85%',
maxWidth: '85%',
2020-09-27 10:15:19 +05:00
color: colors.pri,
2020-09-14 11:43:07 +05:00
}}
secureTextEntry={secureEntry}
2020-09-14 12:17:06 +05:00
placeholder="Password (6+ characters)"
2020-09-14 11:43:07 +05:00
placeholderTextColor={colors.icon}
/>
2020-09-14 12:17:06 +05:00
<Icon
name="eye"
size={20}
onPress={() => {
setSecureEntry(!secureEntry);
}}
style={{
width: 25,
}}
color={secureEntry ? colors.icon : colors.accent}
/>
</View>
{invalidPassword ? (
<Text
style={{
textAlign: 'right',
fontFamily: WEIGHT.regular,
textAlignVertical: 'bottom',
fontSize: SIZE.xs,
marginTop: 2.5,
}}>
<Icon
name="alert-circle-outline"
size={SIZE.xs}
color={colors.errorText}
/>{' '}
Password is invalid
</Text>
) : null}
<Seperator />
{login ? null : (
<>
<TextInput
ref={_passConfirm}
editable={password && !invalidPassword ? true : false}
defaultValue={passwordReEnter}
2020-09-24 09:17:14 +05:00
autoCapitalize="none"
2020-09-14 12:17:06 +05:00
onChangeText={(value) => {
setPasswordReEnter(value);
if (value !== password) {
setConfirmPassword(false);
_passConfirm.current.setNativeProps({
style: {
borderColor: colors.errorText,
},
});
_pass.current.setNativeProps({
style: {
borderColor: colors.errorText,
},
});
} else {
setConfirmPassword(true);
_passConfirm.current.setNativeProps({
style: {
borderColor: colors.accent,
},
});
_pass.current.setNativeProps({
style: {
borderColor: colors.accent,
},
});
}
}}
onFocus={() => {
_passConfirm.current.setNativeProps({
style: {
borderColor: colors.accent,
},
});
}}
style={{
paddingHorizontal: pv,
borderWidth: 1.5,
height: 50,
borderColor: colors.nav,
borderRadius: 5,
fontSize: SIZE.sm,
fontFamily: WEIGHT.regular,
2020-09-27 10:15:19 +05:00
color: colors.pri,
2020-09-14 12:17:06 +05:00
}}
secureTextEntry={secureEntry}
placeholder="Confirm Password"
placeholderTextColor={colors.icon}
/>
{password && !invalidPassword && !confirmPassword ? (
<Text
style={{
textAlign: 'right',
fontFamily: WEIGHT.regular,
textAlignVertical: 'bottom',
fontSize: SIZE.xs,
marginTop: 2.5,
}}>
<Icon
name="alert-circle-outline"
size={SIZE.xs}
color={colors.errorText}
/>{' '}
Passwords do not match
</Text>
) : null}
</>
)}
{login ? null : (
<View
style={{
flexDirection: 'row',
width: '100%',
}}>
<CheckBox
onValueChange={(value) => {
setUserConsent(value);
}}
boxType="circle"
tintColors={{true: colors.accent, false: colors.icon}}
value={userConsent}
/>
2020-09-14 11:43:07 +05:00
<Text
style={{
2020-09-14 12:17:06 +05:00
fontSize: SIZE.xs + 1,
2020-09-14 11:43:07 +05:00
fontFamily: WEIGHT.regular,
2020-09-14 12:17:06 +05:00
color: colors.pri,
maxWidth: '90%',
2020-09-14 11:43:07 +05:00
}}>
2020-09-14 12:17:06 +05:00
By signing up you agree to our{' '}
<Text
style={{
color: colors.accent,
}}>
terms of service{' '}
</Text>
and{' '}
<Text
style={{
color: colors.accent,
}}>
privacy policy.
</Text>
2020-09-14 11:43:07 +05:00
</Text>
2020-09-14 12:17:06 +05:00
</View>
)}
2020-09-14 12:33:04 +05:00
{login ? null : <Seperator />}
2020-09-14 12:17:06 +05:00
2020-09-14 11:43:07 +05:00
<View
style={{
width: '100%',
}}>
2020-09-14 12:17:06 +05:00
<Button
title={login ? 'Login' : 'Create Account'}
onPress={login ? loginUser : signupUser}
width="100%"
height={50}
2020-09-14 11:43:07 +05:00
/>
2020-09-14 12:17:06 +05:00
</View>
<TouchableOpacity
onPress={() => {
2020-09-14 12:43:15 +05:00
ToastEvent.show('hello world', 'error', 'local');
2020-09-14 12:17:06 +05:00
setLogin(!login);
}}
activeOpacity={opacity}
style={{
alignSelf: 'center',
marginTop: 70,
height: 50,
}}>
2020-09-14 11:43:07 +05:00
<Text
style={{
fontSize: SIZE.xs + 1,
fontFamily: WEIGHT.regular,
color: colors.pri,
2020-09-14 12:17:06 +05:00
height: 25,
2020-09-14 11:43:07 +05:00
}}>
2020-09-14 12:17:06 +05:00
{!login
? 'Already have an account? '
: "Don't have an account? "}
2020-09-14 11:43:07 +05:00
<Text
style={{
color: colors.accent,
}}>
2020-09-14 12:17:06 +05:00
{!login ? 'Login' : 'Sign up now'}
2020-09-14 11:43:07 +05:00
</Text>
</Text>
2020-09-14 12:17:06 +05:00
</TouchableOpacity>
2020-09-14 11:43:07 +05:00
</View>
2020-09-14 12:17:06 +05:00
</>
)}
2020-09-14 11:43:07 +05:00
</View>
2020-09-14 12:33:04 +05:00
</View>
2020-09-14 11:43:07 +05:00
</Modal>
);
};
2020-01-23 23:18:15 +05:00
export default LoginDialog;