2022-02-17 00:02:41 +05:00
|
|
|
import React, { useRef, useState } from 'react';
|
2022-07-05 14:33:48 +05:00
|
|
|
import { Dimensions, View } from 'react-native';
|
|
|
|
|
import Animated, { FadeInDown, FadeOutDown, FadeOutUp } from 'react-native-reanimated';
|
2022-02-28 23:25:18 +05:00
|
|
|
import { DDS } from '../../services/device-detection';
|
|
|
|
|
import { eSendEvent, ToastEvent } from '../../services/event-manager';
|
|
|
|
|
import { clearMessage, setEmailVerifyMessage } from '../../services/message';
|
2022-07-05 14:33:48 +05:00
|
|
|
import Navigation from '../../services/navigation';
|
2022-02-28 23:25:18 +05:00
|
|
|
import PremiumService from '../../services/premium';
|
2022-07-05 14:33:48 +05:00
|
|
|
import SettingsService from '../../services/settings';
|
2022-04-24 05:59:14 +05:00
|
|
|
import { useThemeStore } from '../../stores/use-theme-store';
|
2022-07-05 14:33:48 +05:00
|
|
|
import { useUserStore } from '../../stores/use-user-store';
|
2022-04-24 05:59:14 +05:00
|
|
|
import umami from '../../utils/analytics';
|
2022-02-17 00:02:41 +05:00
|
|
|
import { db } from '../../utils/database';
|
2022-02-28 13:48:59 +05:00
|
|
|
import { eCloseLoginDialog } from '../../utils/events';
|
2022-02-18 14:45:38 +05:00
|
|
|
import { openLinkInBrowser } from '../../utils/functions';
|
2022-02-28 13:48:59 +05:00
|
|
|
import { SIZE } from '../../utils/size';
|
|
|
|
|
import { sleep } from '../../utils/time';
|
|
|
|
|
import BaseDialog from '../dialog/base-dialog';
|
2022-04-24 05:59:14 +05:00
|
|
|
import { Button } from '../ui/button';
|
2022-02-28 13:48:59 +05:00
|
|
|
import Input from '../ui/input';
|
|
|
|
|
import { SvgView } from '../ui/svg';
|
|
|
|
|
import { BouncingView } from '../ui/transitions/bouncing-view';
|
|
|
|
|
import Heading from '../ui/typography/heading';
|
|
|
|
|
import Paragraph from '../ui/typography/paragraph';
|
2022-02-17 00:02:41 +05:00
|
|
|
import { SVG } from './background';
|
2022-07-05 14:33:48 +05:00
|
|
|
import { hideAuth } from './common';
|
2022-02-17 00:02:41 +05:00
|
|
|
|
|
|
|
|
export const Signup = ({ changeMode, welcome, trial }) => {
|
2022-02-28 23:25:18 +05:00
|
|
|
const colors = useThemeStore(state => state.colors);
|
2022-02-17 00:02:41 +05:00
|
|
|
const email = useRef();
|
|
|
|
|
const emailInputRef = useRef();
|
|
|
|
|
const passwordInputRef = useRef();
|
|
|
|
|
const password = useRef();
|
|
|
|
|
const confirmPasswordInputRef = useRef();
|
|
|
|
|
const confirmPassword = useRef();
|
|
|
|
|
const [error, setError] = useState(false);
|
|
|
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
|
const setUser = useUserStore(state => state.setUser);
|
|
|
|
|
const setLastSynced = useUserStore(state => state.setLastSynced);
|
|
|
|
|
|
|
|
|
|
const validateInfo = () => {
|
|
|
|
|
if (!password.current || !email.current || !confirmPassword.current) {
|
|
|
|
|
ToastEvent.show({
|
|
|
|
|
heading: 'All fields required',
|
|
|
|
|
message: 'Fill all the fields and try again',
|
|
|
|
|
type: 'error',
|
|
|
|
|
context: 'local'
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const signup = async () => {
|
|
|
|
|
if (!validateInfo() || error) return;
|
|
|
|
|
setLoading(true);
|
|
|
|
|
try {
|
2022-02-18 14:45:38 +05:00
|
|
|
await db.user.signup(email.current.toLowerCase(), password.current);
|
2022-02-17 00:02:41 +05:00
|
|
|
let user = await db.user.getUser();
|
|
|
|
|
setUser(user);
|
|
|
|
|
setLastSynced(await db.lastSynced());
|
|
|
|
|
clearMessage();
|
|
|
|
|
setEmailVerifyMessage();
|
2022-07-05 14:33:48 +05:00
|
|
|
hideAuth();
|
2022-02-17 00:02:41 +05:00
|
|
|
umami.pageView('/account-created', '/welcome/signup');
|
|
|
|
|
await sleep(300);
|
|
|
|
|
if (trial) {
|
|
|
|
|
PremiumService.sheet(null, null, true);
|
|
|
|
|
} else {
|
|
|
|
|
PremiumService.showVerifyEmailDialog();
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
setLoading(false);
|
|
|
|
|
ToastEvent.show({
|
|
|
|
|
heading: 'Signup failed',
|
|
|
|
|
message: e.message,
|
|
|
|
|
type: 'error',
|
|
|
|
|
context: 'local'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
{loading ? <BaseDialog transparent={true} visible={true} animation="fade" /> : null}
|
2022-07-05 14:33:48 +05:00
|
|
|
<Animated.View
|
|
|
|
|
entering={FadeInDown}
|
|
|
|
|
exiting={FadeOutUp}
|
2022-02-17 00:02:41 +05:00
|
|
|
style={{
|
|
|
|
|
borderRadius: DDS.isTab ? 5 : 0,
|
|
|
|
|
backgroundColor: colors.bg,
|
|
|
|
|
zIndex: 10,
|
|
|
|
|
width: '100%',
|
|
|
|
|
minHeight: '100%'
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
height: 250,
|
|
|
|
|
overflow: 'hidden'
|
|
|
|
|
}}
|
|
|
|
|
>
|
2022-07-05 14:33:48 +05:00
|
|
|
<SvgView src={SVG(colors.night ? colors.icon : 'black')} height={700} />
|
2022-02-17 00:02:41 +05:00
|
|
|
</View>
|
|
|
|
|
|
2022-04-24 05:59:14 +05:00
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
width: '100%',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
alignSelf: 'center',
|
|
|
|
|
paddingHorizontal: 12,
|
|
|
|
|
marginBottom: 30,
|
|
|
|
|
marginTop: Dimensions.get('window').height < 700 ? -75 : 15
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Heading
|
2022-02-17 00:02:41 +05:00
|
|
|
style={{
|
2022-04-24 05:59:14 +05:00
|
|
|
textAlign: 'center'
|
2022-02-17 00:02:41 +05:00
|
|
|
}}
|
2022-04-24 05:59:14 +05:00
|
|
|
size={30}
|
|
|
|
|
color={colors.heading}
|
2022-02-17 00:02:41 +05:00
|
|
|
>
|
2022-04-24 05:59:14 +05:00
|
|
|
Create your account
|
|
|
|
|
</Heading>
|
|
|
|
|
<Paragraph
|
|
|
|
|
style={{
|
|
|
|
|
textDecorationLine: 'underline',
|
|
|
|
|
textAlign: 'center'
|
|
|
|
|
}}
|
|
|
|
|
onPress={() => {
|
|
|
|
|
changeMode(0);
|
|
|
|
|
}}
|
|
|
|
|
size={SIZE.md}
|
|
|
|
|
>
|
|
|
|
|
Already have an account? Log in
|
|
|
|
|
</Paragraph>
|
|
|
|
|
</View>
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
width: '100%',
|
|
|
|
|
padding: 12,
|
|
|
|
|
backgroundColor: colors.bg,
|
|
|
|
|
flexGrow: 1
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Input
|
|
|
|
|
fwdRef={emailInputRef}
|
|
|
|
|
onChangeText={value => {
|
|
|
|
|
email.current = value;
|
|
|
|
|
}}
|
|
|
|
|
testID="input.email"
|
|
|
|
|
onErrorCheck={e => setError(e)}
|
|
|
|
|
returnKeyLabel="Next"
|
|
|
|
|
returnKeyType="next"
|
|
|
|
|
autoComplete="email"
|
|
|
|
|
validationType="email"
|
|
|
|
|
autoCorrect={false}
|
|
|
|
|
autoCapitalize="none"
|
|
|
|
|
errorMessage="Email is invalid"
|
|
|
|
|
placeholder="Email"
|
|
|
|
|
onSubmit={() => {
|
|
|
|
|
passwordInputRef.current?.focus();
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<Input
|
|
|
|
|
fwdRef={passwordInputRef}
|
|
|
|
|
onChangeText={value => {
|
|
|
|
|
password.current = value;
|
|
|
|
|
}}
|
|
|
|
|
testID="input.password"
|
|
|
|
|
onErrorCheck={e => setError(e)}
|
|
|
|
|
returnKeyLabel="Next"
|
|
|
|
|
returnKeyType="next"
|
|
|
|
|
secureTextEntry
|
|
|
|
|
autoComplete="password"
|
|
|
|
|
autoCapitalize="none"
|
|
|
|
|
validationType="password"
|
|
|
|
|
autoCorrect={false}
|
|
|
|
|
placeholder="Password"
|
|
|
|
|
onSubmit={() => {
|
|
|
|
|
confirmPasswordInputRef.current?.focus();
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<Input
|
|
|
|
|
fwdRef={confirmPasswordInputRef}
|
|
|
|
|
onChangeText={value => {
|
|
|
|
|
confirmPassword.current = value;
|
|
|
|
|
}}
|
|
|
|
|
testID="input.confirmPassword"
|
|
|
|
|
onErrorCheck={e => setError(e)}
|
|
|
|
|
returnKeyLabel="Signup"
|
|
|
|
|
returnKeyType="done"
|
|
|
|
|
secureTextEntry
|
|
|
|
|
autoComplete="password"
|
|
|
|
|
autoCapitalize="none"
|
|
|
|
|
autoCorrect={false}
|
|
|
|
|
validationType="confirmPassword"
|
|
|
|
|
customValidator={() => password.current}
|
|
|
|
|
placeholder="Confirm password"
|
|
|
|
|
marginBottom={5}
|
|
|
|
|
onSubmit={signup}
|
|
|
|
|
/>
|
2022-02-17 00:02:41 +05:00
|
|
|
<View
|
|
|
|
|
style={{
|
2022-07-05 14:33:48 +05:00
|
|
|
marginTop: 25,
|
2022-04-24 05:59:14 +05:00
|
|
|
alignSelf: 'center'
|
2022-02-17 00:02:41 +05:00
|
|
|
}}
|
|
|
|
|
>
|
2022-04-24 05:59:14 +05:00
|
|
|
<Button
|
|
|
|
|
style={{
|
|
|
|
|
width: 250,
|
|
|
|
|
borderRadius: 100
|
2022-02-17 00:02:41 +05:00
|
|
|
}}
|
2022-04-24 05:59:14 +05:00
|
|
|
loading={loading}
|
|
|
|
|
onPress={signup}
|
|
|
|
|
type="accent"
|
|
|
|
|
title={loading ? null : 'Agree and continue'}
|
2022-02-17 00:02:41 +05:00
|
|
|
/>
|
|
|
|
|
</View>
|
2022-07-05 14:33:48 +05:00
|
|
|
|
|
|
|
|
<Paragraph
|
|
|
|
|
style={{
|
|
|
|
|
textAlign: 'center',
|
|
|
|
|
position: 'absolute',
|
|
|
|
|
bottom: 0,
|
|
|
|
|
alignSelf: 'center',
|
|
|
|
|
marginBottom: 20
|
|
|
|
|
}}
|
|
|
|
|
size={SIZE.xs}
|
|
|
|
|
color={colors.icon}
|
|
|
|
|
>
|
|
|
|
|
By signing up, you agree to our{' '}
|
|
|
|
|
<Paragraph
|
|
|
|
|
size={SIZE.xs}
|
|
|
|
|
onPress={() => {
|
|
|
|
|
openLinkInBrowser('https://notesnook.com/tos', colors);
|
|
|
|
|
}}
|
|
|
|
|
style={{
|
|
|
|
|
textDecorationLine: 'underline'
|
|
|
|
|
}}
|
|
|
|
|
color={colors.accent}
|
|
|
|
|
>
|
|
|
|
|
terms of service{' '}
|
|
|
|
|
</Paragraph>
|
|
|
|
|
and{' '}
|
|
|
|
|
<Paragraph
|
|
|
|
|
size={SIZE.xs}
|
|
|
|
|
onPress={() => {
|
|
|
|
|
openLinkInBrowser('https://notesnook.com/privacy', colors);
|
|
|
|
|
}}
|
|
|
|
|
style={{
|
|
|
|
|
textDecorationLine: 'underline'
|
|
|
|
|
}}
|
|
|
|
|
color={colors.accent}
|
|
|
|
|
>
|
|
|
|
|
privacy policy.
|
|
|
|
|
</Paragraph>
|
|
|
|
|
</Paragraph>
|
2022-04-24 05:59:14 +05:00
|
|
|
</View>
|
2022-07-05 14:33:48 +05:00
|
|
|
</Animated.View>
|
2022-02-17 00:02:41 +05:00
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|