2020-09-19 16:02:21 +05:00
|
|
|
import React, {createRef, useEffect, useState} from 'react';
|
2020-11-23 12:32:33 +05:00
|
|
|
import {Modal, TouchableOpacity, View} from 'react-native';
|
2020-09-19 16:02:21 +05:00
|
|
|
import {TextInput} from 'react-native-gesture-handler';
|
|
|
|
|
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 {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';
|
2020-10-13 17:02:14 +05:00
|
|
|
import {Actions} from '../../provider/Actions';
|
2020-09-19 16:02:21 +05:00
|
|
|
import {useTracked} from '../../provider/index';
|
2020-11-02 20:50:07 +05:00
|
|
|
import {DDS} from '../../services/DeviceDetection';
|
2020-09-14 12:33:04 +05:00
|
|
|
import {
|
2020-10-26 12:01:05 +05:00
|
|
|
eSendEvent,
|
|
|
|
|
eSubscribeEvent,
|
|
|
|
|
eUnSubscribeEvent,
|
|
|
|
|
ToastEvent,
|
2020-10-13 17:02:14 +05:00
|
|
|
} from '../../services/EventManager';
|
2020-09-14 11:43:07 +05:00
|
|
|
import {
|
|
|
|
|
validateEmail,
|
|
|
|
|
validatePass,
|
2020-09-19 16:02:21 +05:00
|
|
|
validateUsername,
|
2020-10-13 17:02:14 +05:00
|
|
|
} from '../../services/Validation';
|
|
|
|
|
import {getElevation} from '../../utils';
|
2020-10-26 12:01:05 +05:00
|
|
|
import {db} from '../../utils/DB';
|
2020-11-02 20:50:07 +05:00
|
|
|
import {
|
|
|
|
|
eOpenLoginDialog,
|
|
|
|
|
eOpenRecoveryKeyDialog,
|
|
|
|
|
eStartSyncer,
|
|
|
|
|
refreshNotesPage,
|
|
|
|
|
} from '../../utils/Events';
|
2020-11-20 01:21:58 +05:00
|
|
|
import {pv, SIZE, WEIGHT} from '../../utils/SizeUtils';
|
2020-10-28 15:52:15 +05:00
|
|
|
import {sleep} from '../../utils/TimeUtils';
|
2020-11-02 20:50:07 +05:00
|
|
|
import {ActionIcon} from '../ActionIcon';
|
2020-11-10 17:17:39 +05:00
|
|
|
import {ListHeaderComponent} from '../SimpleList/ListHeaderComponent';
|
2020-11-14 11:07:01 +05:00
|
|
|
import Paragraph from '../Typography/Paragraph';
|
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 [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-11-20 01:21:58 +05:00
|
|
|
if (loggingIn || signingIn) return;
|
2020-09-27 10:15:19 +05:00
|
|
|
_email.current?.clear();
|
|
|
|
|
_pass.current?.clear();
|
|
|
|
|
_passConfirm.current?.clear();
|
|
|
|
|
_username.current?.clear();
|
2020-10-01 17:23:04 +05:00
|
|
|
|
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);
|
|
|
|
|
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);
|
|
|
|
|
} 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-10-28 15:52:15 +05:00
|
|
|
if (!user) throw new Error('Username or passoword incorrect!');
|
2020-10-28 11:26:49 +05:00
|
|
|
setStatus('Syncing your notes');
|
2020-10-13 17:02:14 +05:00
|
|
|
dispatch({type: Actions.USER, user: user});
|
2020-09-14 11:43:07 +05:00
|
|
|
await db.sync();
|
|
|
|
|
eSendEvent(eStartSyncer);
|
2020-10-13 17:02:14 +05:00
|
|
|
dispatch({type: Actions.ALL});
|
2020-09-14 11:43:07 +05:00
|
|
|
eSendEvent(refreshNotesPage);
|
2020-11-02 20:50:07 +05:00
|
|
|
close();
|
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
|
|
|
setLoggingIn(false);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
2020-11-23 12:32:33 +05:00
|
|
|
|
2020-10-28 11:26:49 +05:00
|
|
|
if (invalidEmail && invalidPassword && invalidUsername) {
|
2020-09-14 12:43:15 +05:00
|
|
|
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-10-28 11:26:49 +05:00
|
|
|
|
|
|
|
|
return true;
|
2020-09-14 12:43:15 +05:00
|
|
|
};
|
|
|
|
|
|
2020-09-14 11:43:07 +05:00
|
|
|
const signupUser = async () => {
|
2020-10-26 12:01:05 +05:00
|
|
|
if (!validateInfo()) return;
|
2020-09-14 11:43:07 +05:00
|
|
|
|
|
|
|
|
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 12:33:04 +05:00
|
|
|
setStatus('Setting up crenditials');
|
2020-10-13 17:02:14 +05:00
|
|
|
dispatch({type: Actions.USER, user: user});
|
2020-09-14 11:43:07 +05:00
|
|
|
eSendEvent(eStartSyncer);
|
2020-10-28 11:26:49 +05:00
|
|
|
close();
|
|
|
|
|
await sleep(500);
|
2020-10-28 15:52:15 +05:00
|
|
|
eSendEvent(eOpenRecoveryKeyDialog, true);
|
2020-09-14 11:43:07 +05:00
|
|
|
} catch (e) {
|
|
|
|
|
setFailed(true);
|
|
|
|
|
ToastEvent.show('Login Failed, try again', 'error', 'local');
|
2020-10-28 11:26:49 +05:00
|
|
|
} finally {
|
|
|
|
|
setSigningIn(false);
|
2020-09-14 11:43:07 +05:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-11-23 12:32:33 +05:00
|
|
|
return !visible ? null : (
|
2020-09-14 11:43:07 +05:00
|
|
|
<Modal
|
|
|
|
|
animated={true}
|
2020-10-01 17:23:04 +05:00
|
|
|
animationType={DDS.isTab ? 'fade' : 'slide'}
|
2020-09-14 12:33:04 +05:00
|
|
|
statusBarTranslucent={true}
|
2020-09-14 11:43:07 +05:00
|
|
|
onRequestClose={close}
|
2020-11-23 12:32:33 +05:00
|
|
|
visible={true}
|
2020-09-14 11:43:07 +05:00
|
|
|
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-10-01 17:23:04 +05:00
|
|
|
paddingTop: DDS.isTab ? 0 : 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',
|
2020-10-28 11:26:49 +05:00
|
|
|
overflow: 'hidden',
|
2020-09-14 11:43:07 +05:00
|
|
|
}}>
|
|
|
|
|
{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={{
|
2020-11-20 01:21:58 +05:00
|
|
|
maxHeight: DDS.isLargeTablet() ? '90%' : '100%',
|
|
|
|
|
minHeight: '50%',
|
|
|
|
|
height: DDS.isLargeTablet() ? null : '100%',
|
2020-10-01 17:23:04 +05:00
|
|
|
width: DDS.isTab ? 500 : '100%',
|
|
|
|
|
borderRadius: DDS.isTab ? 5 : 0,
|
2020-11-20 01:21:58 +05:00
|
|
|
backgroundColor: colors.bg,
|
2020-10-01 17:23:04 +05:00
|
|
|
zIndex: 10,
|
2020-10-26 12:01:05 +05:00
|
|
|
...getElevation(DDS.isTab ? 5 : 0),
|
2020-11-20 01:21:58 +05:00
|
|
|
paddingBottom: DDS.isLargeTablet() ? 20 : 0,
|
2020-09-14 11:43:07 +05:00
|
|
|
}}>
|
2020-09-14 13:34:55 +05:00
|
|
|
<Toast context="local" />
|
2020-10-26 12:01:05 +05:00
|
|
|
|
2020-11-20 01:21:58 +05:00
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
justifyContent: 'space-between',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
paddingHorizontal: 12,
|
|
|
|
|
height: 50,
|
|
|
|
|
}}>
|
|
|
|
|
{DDS.isLargeTablet() ? (
|
|
|
|
|
<View />
|
|
|
|
|
) : (
|
2020-11-14 11:07:01 +05:00
|
|
|
<ActionIcon
|
|
|
|
|
name="arrow-left"
|
|
|
|
|
size={SIZE.xxxl}
|
|
|
|
|
onPress={() => {
|
|
|
|
|
close();
|
|
|
|
|
}}
|
|
|
|
|
customStyle={{
|
|
|
|
|
width: 40,
|
|
|
|
|
height: 40,
|
|
|
|
|
marginLeft: -5,
|
|
|
|
|
}}
|
|
|
|
|
color={colors.heading}
|
|
|
|
|
/>
|
2020-11-20 01:21:58 +05:00
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
<Paragraph
|
|
|
|
|
onPress={() => setLogin(!login)}
|
|
|
|
|
size={SIZE.md}
|
|
|
|
|
color={colors.accent}>
|
|
|
|
|
{login ? 'Sign Up' : 'Login'}
|
|
|
|
|
</Paragraph>
|
|
|
|
|
</View>
|
2020-10-28 11:26:49 +05:00
|
|
|
|
2020-11-10 17:17:39 +05:00
|
|
|
<ListHeaderComponent
|
|
|
|
|
color="transparent"
|
|
|
|
|
type="settings"
|
2020-11-20 01:21:58 +05:00
|
|
|
shouldShow
|
2020-11-10 17:17:39 +05:00
|
|
|
title={login ? 'Login' : 'Sign Up'}
|
|
|
|
|
messageCard={false}
|
2020-11-14 11:07:01 +05:00
|
|
|
onPress={() => {
|
|
|
|
|
setLogin(!login);
|
|
|
|
|
}}
|
|
|
|
|
paragraph={login ? 'create an account' : 'login to your account'}
|
2020-11-10 17:17:39 +05:00
|
|
|
/>
|
|
|
|
|
|
2020-10-28 11:26:49 +05:00
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
paddingHorizontal: 12,
|
2020-11-10 17:17:39 +05:00
|
|
|
paddingTop: 12,
|
2020-10-28 11:26:49 +05:00
|
|
|
}}>
|
|
|
|
|
<>
|
|
|
|
|
<TextInput
|
|
|
|
|
ref={_username}
|
|
|
|
|
onFocus={() => {
|
|
|
|
|
if (!invalidUsername) {
|
2020-11-02 23:13:56 +05:00
|
|
|
_username.current?.setNativeProps({
|
2020-10-28 11:26:49 +05:00
|
|
|
style: {
|
|
|
|
|
borderColor: colors.accent,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}}
|
2020-11-14 11:31:25 +05:00
|
|
|
editable={!loggingIn || !signingIn}
|
2020-10-28 11:26:49 +05:00
|
|
|
autoCapitalize="none"
|
|
|
|
|
defaultValue={username}
|
|
|
|
|
onBlur={() => {
|
|
|
|
|
if (!validateUsername(username) && username?.length > 0) {
|
|
|
|
|
setInvalidUsername(true);
|
2020-11-02 23:13:56 +05:00
|
|
|
_username.current?.setNativeProps({
|
2020-10-28 11:26:49 +05:00
|
|
|
style: {
|
|
|
|
|
color: colors.errorText,
|
|
|
|
|
borderColor: colors.errorText,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
setInvalidUsername(false);
|
2020-11-02 23:13:56 +05:00
|
|
|
_username.current?.setNativeProps({
|
2020-10-28 11:26:49 +05:00
|
|
|
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,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
2020-10-26 12:01:05 +05:00
|
|
|
}}
|
|
|
|
|
style={{
|
2020-10-28 11:26:49 +05:00
|
|
|
paddingHorizontal: pv,
|
|
|
|
|
height: 50,
|
2020-11-02 20:50:07 +05:00
|
|
|
borderBottomWidth: 1,
|
2020-10-28 11:26:49 +05:00
|
|
|
borderColor: colors.nav,
|
2020-11-14 11:09:06 +05:00
|
|
|
fontSize: SIZE.md,
|
2020-10-28 11:26:49 +05:00
|
|
|
fontFamily: WEIGHT.regular,
|
|
|
|
|
color: colors.pri,
|
|
|
|
|
}}
|
|
|
|
|
placeholder="Username (a-z _- 0-9)"
|
|
|
|
|
placeholderTextColor={colors.icon}
|
|
|
|
|
/>
|
|
|
|
|
{invalidUsername ? (
|
2020-11-20 01:21:58 +05:00
|
|
|
<Paragraph
|
|
|
|
|
size={SIZE.xs}
|
2020-09-14 11:43:07 +05:00
|
|
|
style={{
|
2020-10-28 11:26:49 +05:00
|
|
|
textAlign: 'right',
|
|
|
|
|
textAlignVertical: 'bottom',
|
|
|
|
|
marginTop: 2.5,
|
2020-09-14 11:43:07 +05:00
|
|
|
}}>
|
2020-10-28 11:26:49 +05:00
|
|
|
<Icon
|
|
|
|
|
name="alert-circle-outline"
|
|
|
|
|
size={SIZE.xs}
|
|
|
|
|
color={colors.errorText}
|
|
|
|
|
/>{' '}
|
|
|
|
|
Username is invalid
|
2020-11-20 01:21:58 +05:00
|
|
|
</Paragraph>
|
2020-10-28 11:26:49 +05:00
|
|
|
) : null}
|
|
|
|
|
</>
|
|
|
|
|
|
|
|
|
|
<Seperator />
|
|
|
|
|
|
|
|
|
|
{login ? null : (
|
|
|
|
|
<>
|
|
|
|
|
<TextInput
|
|
|
|
|
ref={_email}
|
|
|
|
|
onFocus={() => {
|
|
|
|
|
if (!invalidEmail) {
|
|
|
|
|
_email.current.setNativeProps({
|
|
|
|
|
style: {
|
|
|
|
|
borderColor: colors.accent,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}}
|
2020-11-14 11:31:25 +05:00
|
|
|
editable={!loggingIn || !signingIn}
|
2020-10-28 11:26:49 +05:00
|
|
|
autoCapitalize="none"
|
|
|
|
|
defaultValue={email}
|
|
|
|
|
onBlur={() => {
|
|
|
|
|
if (!validateEmail(email) && email?.length > 0) {
|
|
|
|
|
setInvalidEmail(true);
|
2020-11-02 23:13:56 +05:00
|
|
|
_email.current?.setNativeProps({
|
2020-10-28 11:26:49 +05:00
|
|
|
style: {
|
|
|
|
|
color: colors.errorText,
|
|
|
|
|
borderColor: colors.errorText,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
setInvalidEmail(false);
|
2020-11-02 23:13:56 +05:00
|
|
|
_email.current?.setNativeProps({
|
2020-10-28 11:26:49 +05:00
|
|
|
style: {
|
|
|
|
|
borderColor: colors.nav,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
textContentType="emailAddress"
|
|
|
|
|
onChangeText={(value) => {
|
|
|
|
|
setEmail(value);
|
|
|
|
|
if (invalidEmail && validateEmail(email)) {
|
|
|
|
|
setInvalidEmail(false);
|
|
|
|
|
_email.current.setNativeProps({
|
|
|
|
|
style: {
|
|
|
|
|
color: colors.pri,
|
|
|
|
|
borderColor: colors.accent,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
2020-10-01 17:23:04 +05:00
|
|
|
}}
|
2020-10-28 11:26:49 +05:00
|
|
|
onSubmitEditing={() => {
|
|
|
|
|
if (!validateEmail(email)) {
|
|
|
|
|
setInvalidEmail(true);
|
|
|
|
|
_email.current.setNativeProps({
|
|
|
|
|
style: {
|
|
|
|
|
color: colors.errorText,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
2020-10-01 17:23:04 +05:00
|
|
|
}}
|
2020-10-28 11:26:49 +05:00
|
|
|
style={{
|
|
|
|
|
paddingHorizontal: pv,
|
|
|
|
|
height: 50,
|
2020-11-02 20:50:07 +05:00
|
|
|
borderBottomWidth: 1,
|
2020-10-28 11:26:49 +05:00
|
|
|
borderColor: colors.nav,
|
2020-11-14 11:09:06 +05:00
|
|
|
fontSize: SIZE.md,
|
2020-10-28 11:26:49 +05:00
|
|
|
fontFamily: WEIGHT.regular,
|
|
|
|
|
color: colors.pri,
|
|
|
|
|
}}
|
|
|
|
|
placeholder="Email"
|
|
|
|
|
placeholderTextColor={colors.icon}
|
2020-10-01 17:23:04 +05:00
|
|
|
/>
|
|
|
|
|
|
2020-10-28 11:26:49 +05:00
|
|
|
{invalidEmail ? (
|
2020-11-20 01:21:58 +05:00
|
|
|
<Paragraph
|
|
|
|
|
size={SIZE.xs}
|
2020-09-14 11:43:07 +05:00
|
|
|
style={{
|
2020-10-28 11:26:49 +05:00
|
|
|
textAlign: 'right',
|
|
|
|
|
textAlignVertical: 'bottom',
|
|
|
|
|
marginTop: 2.5,
|
2020-09-14 11:43:07 +05:00
|
|
|
}}>
|
2020-10-28 11:26:49 +05:00
|
|
|
<Icon
|
|
|
|
|
name="alert-circle-outline"
|
|
|
|
|
size={SIZE.xs}
|
|
|
|
|
color={colors.errorText}
|
|
|
|
|
/>{' '}
|
|
|
|
|
Email is invalid
|
2020-11-20 01:21:58 +05:00
|
|
|
</Paragraph>
|
2020-10-28 11:26:49 +05:00
|
|
|
) : null}
|
2020-09-19 16:02:21 +05:00
|
|
|
<Seperator />
|
2020-10-28 11:26:49 +05:00
|
|
|
</>
|
|
|
|
|
)}
|
2020-09-19 16:02:21 +05:00
|
|
|
|
2020-10-28 11:26:49 +05:00
|
|
|
<View
|
|
|
|
|
ref={_passContainer}
|
|
|
|
|
style={{
|
2020-11-02 20:50:07 +05:00
|
|
|
borderBottomWidth: 1,
|
2020-10-28 11:26:49 +05:00
|
|
|
borderColor: colors.nav,
|
|
|
|
|
paddingHorizontal: 10,
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
justifyContent: 'space-between',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
}}>
|
|
|
|
|
<TextInput
|
|
|
|
|
ref={_pass}
|
|
|
|
|
onFocus={() => {
|
|
|
|
|
if (!invalidPassword) {
|
|
|
|
|
_passContainer.current?.setNativeProps({
|
|
|
|
|
style: {
|
|
|
|
|
borderColor: colors.accent,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}}
|
2020-11-14 11:31:25 +05:00
|
|
|
editable={!loggingIn || !signingIn}
|
2020-10-28 11:26:49 +05:00
|
|
|
autoCapitalize="none"
|
|
|
|
|
defaultValue={password}
|
|
|
|
|
onBlur={() => {
|
|
|
|
|
if (!validatePass(password) && password?.length > 0) {
|
|
|
|
|
setInvalidPassword(true);
|
2020-11-02 23:13:56 +05:00
|
|
|
_pass.current?.setNativeProps({
|
2020-10-28 11:26:49 +05:00
|
|
|
style: {
|
|
|
|
|
color: colors.errorText,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
_passContainer.current?.setNativeProps({
|
|
|
|
|
style: {
|
|
|
|
|
borderColor: colors.errorText,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
setInvalidPassword(false);
|
|
|
|
|
_passContainer.current?.setNativeProps({
|
|
|
|
|
style: {
|
2020-09-14 11:43:07 +05:00
|
|
|
borderColor: colors.nav,
|
2020-10-28 11:26:49 +05:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
onChangeText={(value) => {
|
|
|
|
|
setPassword(value);
|
|
|
|
|
if (invalidPassword && validatePass(password)) {
|
|
|
|
|
setInvalidPassword(false);
|
|
|
|
|
_pass.current.setNativeProps({
|
|
|
|
|
style: {
|
2020-09-27 10:15:19 +05:00
|
|
|
color: colors.pri,
|
2020-10-28 11:26:49 +05:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
onSubmitEditing={() => {
|
|
|
|
|
if (!validatePass(password)) {
|
|
|
|
|
setInvalidPassword(true);
|
|
|
|
|
_pass.current.setNativeProps({
|
|
|
|
|
style: {
|
|
|
|
|
color: colors.errorText,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
style={{
|
|
|
|
|
paddingHorizontal: 0,
|
|
|
|
|
height: 50,
|
2020-11-14 11:09:06 +05:00
|
|
|
fontSize: SIZE.md,
|
2020-10-28 11:26:49 +05:00
|
|
|
fontFamily: WEIGHT.regular,
|
|
|
|
|
width: '85%',
|
|
|
|
|
maxWidth: '85%',
|
|
|
|
|
color: colors.pri,
|
|
|
|
|
}}
|
|
|
|
|
secureTextEntry={secureEntry}
|
|
|
|
|
placeholder="Password (6+ characters)"
|
|
|
|
|
placeholderTextColor={colors.icon}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<Icon
|
|
|
|
|
name="eye"
|
|
|
|
|
size={20}
|
|
|
|
|
onPress={() => {
|
|
|
|
|
setSecureEntry(!secureEntry);
|
|
|
|
|
}}
|
|
|
|
|
style={{
|
|
|
|
|
width: 25,
|
|
|
|
|
}}
|
|
|
|
|
color={secureEntry ? colors.icon : colors.accent}
|
|
|
|
|
/>
|
|
|
|
|
</View>
|
|
|
|
|
{invalidPassword ? (
|
2020-11-20 01:21:58 +05:00
|
|
|
<Paragraph
|
|
|
|
|
size={SIZE.xs}
|
2020-10-28 11:26:49 +05:00
|
|
|
style={{
|
|
|
|
|
textAlign: 'right',
|
|
|
|
|
textAlignVertical: 'bottom',
|
|
|
|
|
marginTop: 2.5,
|
|
|
|
|
}}>
|
|
|
|
|
<Icon
|
|
|
|
|
name="alert-circle-outline"
|
|
|
|
|
size={SIZE.xs}
|
|
|
|
|
color={colors.errorText}
|
|
|
|
|
/>{' '}
|
|
|
|
|
Password is invalid
|
2020-11-20 01:21:58 +05:00
|
|
|
</Paragraph>
|
2020-10-28 11:26:49 +05:00
|
|
|
) : null}
|
|
|
|
|
|
|
|
|
|
<Seperator />
|
|
|
|
|
|
|
|
|
|
{login ? null : (
|
|
|
|
|
<>
|
|
|
|
|
<TextInput
|
|
|
|
|
ref={_passConfirm}
|
2020-11-14 11:31:25 +05:00
|
|
|
editable={
|
|
|
|
|
!loggingIn || !signingIn || (password && !invalidPassword)
|
|
|
|
|
? true
|
|
|
|
|
: false
|
|
|
|
|
}
|
2020-10-28 11:26:49 +05:00
|
|
|
defaultValue={passwordReEnter}
|
|
|
|
|
autoCapitalize="none"
|
|
|
|
|
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,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}}
|
2020-09-14 12:17:06 +05:00
|
|
|
style={{
|
2020-10-28 11:26:49 +05:00
|
|
|
paddingHorizontal: pv,
|
2020-11-02 20:50:07 +05:00
|
|
|
borderBottomWidth: 1,
|
2020-10-28 11:26:49 +05:00
|
|
|
height: 50,
|
2020-09-14 12:17:06 +05:00
|
|
|
borderColor: colors.nav,
|
2020-11-14 11:09:06 +05:00
|
|
|
fontSize: SIZE.md,
|
2020-10-28 11:26:49 +05:00
|
|
|
fontFamily: WEIGHT.regular,
|
|
|
|
|
color: colors.pri,
|
|
|
|
|
}}
|
|
|
|
|
secureTextEntry={secureEntry}
|
|
|
|
|
placeholder="Confirm Password"
|
|
|
|
|
placeholderTextColor={colors.icon}
|
|
|
|
|
/>
|
2020-09-14 11:43:07 +05:00
|
|
|
|
2020-10-28 11:26:49 +05:00
|
|
|
{password && !invalidPassword && !confirmPassword ? (
|
2020-11-20 01:21:58 +05:00
|
|
|
<Paragraph
|
|
|
|
|
size={SIZE.xs}
|
2020-09-14 12:17:06 +05:00
|
|
|
style={{
|
|
|
|
|
textAlign: 'right',
|
|
|
|
|
textAlignVertical: 'bottom',
|
|
|
|
|
marginTop: 2.5,
|
|
|
|
|
}}>
|
|
|
|
|
<Icon
|
|
|
|
|
name="alert-circle-outline"
|
|
|
|
|
size={SIZE.xs}
|
|
|
|
|
color={colors.errorText}
|
|
|
|
|
/>{' '}
|
2020-10-28 11:26:49 +05:00
|
|
|
Passwords do not match
|
2020-11-20 01:21:58 +05:00
|
|
|
</Paragraph>
|
2020-09-14 12:17:06 +05:00
|
|
|
) : null}
|
2020-10-28 11:26:49 +05:00
|
|
|
</>
|
|
|
|
|
)}
|
2020-11-02 20:50:07 +05:00
|
|
|
|
2020-10-28 11:26:49 +05:00
|
|
|
{login ? null : (
|
2020-11-02 20:50:07 +05:00
|
|
|
<>
|
|
|
|
|
<Seperator />
|
|
|
|
|
<TouchableOpacity
|
2020-11-14 11:31:25 +05:00
|
|
|
disabled={loggingIn || signingIn}
|
2020-11-02 20:50:07 +05:00
|
|
|
onPress={() => {
|
|
|
|
|
setUserConsent(!userConsent);
|
2020-09-14 12:17:06 +05:00
|
|
|
}}
|
2020-11-02 20:50:07 +05:00
|
|
|
activeOpacity={0.7}
|
2020-09-14 12:17:06 +05:00
|
|
|
style={{
|
2020-11-02 20:50:07 +05:00
|
|
|
flexDirection: 'row',
|
|
|
|
|
width: '100%',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
height: 40,
|
2020-09-14 12:17:06 +05:00
|
|
|
}}>
|
2020-11-02 20:50:07 +05:00
|
|
|
<Icon
|
|
|
|
|
size={SIZE.lg}
|
|
|
|
|
color={userConsent ? colors.accent : colors.icon}
|
|
|
|
|
name={
|
|
|
|
|
userConsent
|
|
|
|
|
? 'check-circle-outline'
|
|
|
|
|
: 'checkbox-blank-circle-outline'
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
|
2020-11-20 01:21:58 +05:00
|
|
|
<Paragraph
|
2020-10-28 11:26:49 +05:00
|
|
|
style={{
|
2020-11-02 20:50:07 +05:00
|
|
|
maxWidth: '90%',
|
|
|
|
|
marginLeft: 10,
|
2020-09-14 11:43:07 +05:00
|
|
|
}}>
|
2020-11-02 20:50:07 +05:00
|
|
|
By signing up you agree to our{' '}
|
2020-11-20 01:21:58 +05:00
|
|
|
<Paragraph color={colors.accent}>
|
2020-11-02 20:50:07 +05:00
|
|
|
terms of service{' '}
|
2020-11-20 01:21:58 +05:00
|
|
|
</Paragraph>
|
2020-11-02 20:50:07 +05:00
|
|
|
and{' '}
|
2020-11-20 01:21:58 +05:00
|
|
|
<Paragraph color={colors.accent}>privacy policy.</Paragraph>
|
|
|
|
|
</Paragraph>
|
2020-11-02 20:50:07 +05:00
|
|
|
</TouchableOpacity>
|
|
|
|
|
</>
|
2020-10-28 11:26:49 +05:00
|
|
|
)}
|
2020-11-02 20:50:07 +05:00
|
|
|
|
2020-10-28 11:26:49 +05:00
|
|
|
{login ? null : <Seperator />}
|
|
|
|
|
|
2020-11-20 01:21:58 +05:00
|
|
|
<Button
|
|
|
|
|
title={login ? 'Login' : 'Create Account'}
|
|
|
|
|
onPress={login ? loginUser : signupUser}
|
|
|
|
|
width="100%"
|
|
|
|
|
type="accent"
|
|
|
|
|
loading={loggingIn || signingIn}
|
|
|
|
|
fontSize={SIZE.md}
|
|
|
|
|
height={50}
|
|
|
|
|
/>
|
2020-10-28 11:26:49 +05:00
|
|
|
</View>
|
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;
|