2022-08-30 16:13:11 +05:00
|
|
|
/* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2022-08-29 16:19:17 +05:00
|
|
|
import React, { useEffect, useRef, useState } from "react";
|
|
|
|
|
import { Platform, View } from "react-native";
|
|
|
|
|
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
2022-08-26 16:19:39 +05:00
|
|
|
import {
|
|
|
|
|
eSubscribeEvent,
|
|
|
|
|
eUnSubscribeEvent
|
|
|
|
|
} from "../../services/event-manager";
|
|
|
|
|
import { useThemeStore } from "../../stores/use-theme-store";
|
|
|
|
|
import { eCloseLoginDialog, eOpenLoginDialog } from "../../utils/events";
|
|
|
|
|
import { sleep } from "../../utils/time";
|
|
|
|
|
import BaseDialog from "../dialog/base-dialog";
|
|
|
|
|
import { Toast } from "../toast";
|
|
|
|
|
import { Button } from "../ui/button";
|
|
|
|
|
import { IconButton } from "../ui/icon-button";
|
|
|
|
|
import { hideAuth, initialAuthMode } from "./common";
|
|
|
|
|
import { Login } from "./login";
|
|
|
|
|
import { Signup } from "./signup";
|
2022-07-05 14:33:48 +05:00
|
|
|
|
|
|
|
|
export const AuthMode = {
|
|
|
|
|
login: 0,
|
|
|
|
|
signup: 1,
|
|
|
|
|
welcomeSignup: 2,
|
|
|
|
|
trialSignup: 3
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const AuthModal = () => {
|
2022-08-26 16:19:39 +05:00
|
|
|
const colors = useThemeStore((state) => state.colors);
|
2022-07-05 14:33:48 +05:00
|
|
|
const [visible, setVisible] = useState(false);
|
|
|
|
|
const [currentAuthMode, setCurrentAuthMode] = useState(AuthMode.login);
|
|
|
|
|
const actionSheetRef = useRef();
|
2022-07-09 15:51:43 +05:00
|
|
|
const insets = useSafeAreaInsets();
|
2022-07-05 14:33:48 +05:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
eSubscribeEvent(eOpenLoginDialog, open);
|
|
|
|
|
eSubscribeEvent(eCloseLoginDialog, close);
|
|
|
|
|
return () => {
|
|
|
|
|
eUnSubscribeEvent(eOpenLoginDialog, open);
|
|
|
|
|
eUnSubscribeEvent(eCloseLoginDialog, close);
|
|
|
|
|
};
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
async function open(mode) {
|
|
|
|
|
setCurrentAuthMode(mode ? mode : AuthMode.login);
|
2022-07-06 12:17:08 +05:00
|
|
|
initialAuthMode.current = mode ? mode : AuthMode.login;
|
2022-07-05 14:33:48 +05:00
|
|
|
setVisible(true);
|
|
|
|
|
await sleep(10);
|
|
|
|
|
actionSheetRef.current?.show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const close = () => {
|
|
|
|
|
actionSheetRef.current?.hide();
|
|
|
|
|
setCurrentAuthMode(AuthMode.login);
|
|
|
|
|
setVisible(false);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return !visible ? null : (
|
|
|
|
|
<BaseDialog
|
|
|
|
|
overlayOpacity={0}
|
|
|
|
|
statusBarTranslucent={false}
|
|
|
|
|
onRequestClose={currentAuthMode !== AuthMode.welcomeSignup && close}
|
|
|
|
|
visible={true}
|
|
|
|
|
onClose={close}
|
|
|
|
|
useSafeArea={false}
|
|
|
|
|
bounce={false}
|
|
|
|
|
background={colors.bg}
|
|
|
|
|
transparent={false}
|
2022-07-06 12:17:08 +05:00
|
|
|
animated={false}
|
2022-07-05 14:33:48 +05:00
|
|
|
>
|
|
|
|
|
{currentAuthMode !== AuthMode.login ? (
|
|
|
|
|
<Signup
|
2022-08-26 16:19:39 +05:00
|
|
|
changeMode={(mode) => setCurrentAuthMode(mode)}
|
2022-07-05 14:33:48 +05:00
|
|
|
trial={AuthMode.trialSignup === currentAuthMode}
|
2022-07-06 12:17:08 +05:00
|
|
|
welcome={initialAuthMode.current === AuthMode.welcomeSignup}
|
2022-07-05 14:33:48 +05:00
|
|
|
/>
|
|
|
|
|
) : (
|
2022-07-06 12:17:08 +05:00
|
|
|
<Login
|
|
|
|
|
welcome={initialAuthMode.current === AuthMode.welcomeSignup}
|
2022-08-26 16:19:39 +05:00
|
|
|
changeMode={(mode) => setCurrentAuthMode(mode)}
|
2022-07-06 12:17:08 +05:00
|
|
|
/>
|
2022-07-05 14:33:48 +05:00
|
|
|
)}
|
|
|
|
|
|
2022-07-09 15:51:43 +05:00
|
|
|
<View
|
|
|
|
|
style={{
|
2022-08-26 16:19:39 +05:00
|
|
|
position: "absolute",
|
|
|
|
|
top: Platform.OS === "ios" ? insets.top : 0,
|
2022-07-09 15:51:43 +05:00
|
|
|
zIndex: 999,
|
2022-08-26 16:19:39 +05:00
|
|
|
flexDirection: "row",
|
|
|
|
|
alignItems: "center",
|
2022-07-09 15:51:43 +05:00
|
|
|
paddingHorizontal: 12,
|
2022-08-26 16:19:39 +05:00
|
|
|
width: "100%",
|
2022-07-09 15:51:43 +05:00
|
|
|
height: 50,
|
2022-07-09 18:42:02 +05:00
|
|
|
justifyContent:
|
2022-08-26 16:19:39 +05:00
|
|
|
initialAuthMode.current !== AuthMode.welcomeSignup
|
|
|
|
|
? "space-between"
|
|
|
|
|
: "flex-end"
|
2022-07-09 15:51:43 +05:00
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{initialAuthMode.current === AuthMode.welcomeSignup ? null : (
|
|
|
|
|
<IconButton
|
|
|
|
|
name="arrow-left"
|
|
|
|
|
onPress={() => {
|
|
|
|
|
hideAuth();
|
|
|
|
|
}}
|
|
|
|
|
color={colors.pri}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2022-07-05 14:33:48 +05:00
|
|
|
|
2022-07-09 15:51:43 +05:00
|
|
|
{initialAuthMode.current !== AuthMode.welcomeSignup ? null : (
|
|
|
|
|
<Button
|
|
|
|
|
title="Skip for now"
|
|
|
|
|
onPress={() => {
|
|
|
|
|
hideAuth();
|
|
|
|
|
}}
|
|
|
|
|
iconSize={20}
|
|
|
|
|
type="gray"
|
|
|
|
|
iconPosition="right"
|
|
|
|
|
icon="chevron-right"
|
|
|
|
|
height={25}
|
|
|
|
|
iconStyle={{
|
|
|
|
|
marginTop: 2
|
|
|
|
|
}}
|
|
|
|
|
style={{
|
|
|
|
|
paddingHorizontal: 6
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</View>
|
2022-07-08 23:25:12 +05:00
|
|
|
|
2022-07-05 14:33:48 +05:00
|
|
|
<Toast context="local" />
|
|
|
|
|
</BaseDialog>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default AuthModal;
|