2022-07-05 14:33:48 +05:00
|
|
|
import React, { useEffect, useRef, useState } from 'react';
|
2022-07-06 12:17:08 +05:00
|
|
|
import { eSubscribeEvent, eUnSubscribeEvent } from '../../services/event-manager';
|
2022-07-05 14:33:48 +05:00
|
|
|
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 { IconButton } from '../ui/icon-button';
|
2022-07-06 12:17:08 +05:00
|
|
|
import { hideAuth, initialAuthMode } from './common';
|
2022-07-05 14:33:48 +05:00
|
|
|
import { Login } from './login';
|
|
|
|
|
import { Signup } from './signup';
|
|
|
|
|
|
|
|
|
|
export const AuthMode = {
|
|
|
|
|
login: 0,
|
|
|
|
|
signup: 1,
|
|
|
|
|
welcomeSignup: 2,
|
|
|
|
|
trialSignup: 3
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const AuthModal = () => {
|
|
|
|
|
const colors = useThemeStore(state => state.colors);
|
|
|
|
|
const [visible, setVisible] = useState(false);
|
|
|
|
|
const [currentAuthMode, setCurrentAuthMode] = useState(AuthMode.login);
|
|
|
|
|
const actionSheetRef = useRef();
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
changeMode={mode => setCurrentAuthMode(mode)}
|
|
|
|
|
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}
|
|
|
|
|
changeMode={mode => setCurrentAuthMode(mode)}
|
|
|
|
|
/>
|
2022-07-05 14:33:48 +05:00
|
|
|
)}
|
|
|
|
|
|
2022-07-06 12:17:08 +05:00
|
|
|
{initialAuthMode.current === AuthMode.welcomeSignup ? null : (
|
|
|
|
|
<IconButton
|
|
|
|
|
name="arrow-left"
|
|
|
|
|
onPress={() => {
|
|
|
|
|
hideAuth();
|
|
|
|
|
}}
|
|
|
|
|
color={colors.pri}
|
|
|
|
|
customStyle={{
|
|
|
|
|
position: 'absolute',
|
|
|
|
|
zIndex: 999,
|
2022-07-08 19:00:32 +05:00
|
|
|
left: 12,
|
|
|
|
|
top: 0
|
2022-07-06 12:17:08 +05:00
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2022-07-05 14:33:48 +05:00
|
|
|
|
|
|
|
|
<Toast context="local" />
|
|
|
|
|
</BaseDialog>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default AuthModal;
|