/* This file is part of the Notesnook project (https://notesnook.com/) * * Copyright (C) 2022 Streetwriters (Private) Limited * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ import React, { useRef, useState } from "react"; import { Dimensions, View } from "react-native"; import Animated, { FadeInDown, FadeOutUp } from "react-native-reanimated"; import umami from "../../common/analytics"; import { db } from "../../common/database"; import { DDS } from "../../services/device-detection"; import { ToastEvent } from "../../services/event-manager"; import { clearMessage, setEmailVerifyMessage } from "../../services/message"; import PremiumService from "../../services/premium"; import { useThemeStore } from "../../stores/use-theme-store"; import { useUserStore } from "../../stores/use-user-store"; import { openLinkInBrowser } from "../../utils/functions"; import { SIZE } from "../../utils/size"; import { sleep } from "../../utils/time"; import BaseDialog from "../dialog/base-dialog"; import { Button } from "../ui/button"; import Input from "../ui/input"; import { SvgView } from "../ui/svg"; import Heading from "../ui/typography/heading"; import Paragraph from "../ui/typography/paragraph"; import { SVG } from "./background"; import { hideAuth } from "./common"; export const Signup = ({ changeMode, trial }) => { const colors = useThemeStore((state) => state.colors); 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 { await db.user.signup(email.current.toLowerCase(), password.current); let user = await db.user.getUser(); setUser(user); setLastSynced(await db.lastSynced()); clearMessage(); setEmailVerifyMessage(); hideAuth(); 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 ? ( ) : null} Create your account { changeMode(0); }} size={SIZE.md} > Already have an account? Log in { 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(); }} /> { 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(); }} /> { 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} />