import React, { useState } from 'react'; import { useLanguage, useOrder, useSession } from 'ordering-components/native'; import { StyleSheet, View, Dimensions, TextStyle, KeyboardAvoidingView, Platform } from 'react-native'; import { useTheme } from 'styled-components/native'; import { OButton, OButtonGroup, OIcon, OModal, OText } from '../shared'; import { LogoWrapper, Slogan } from './styles'; import { LanguageSelector } from '../LanguageSelector' import { TouchableOpacity } from 'react-native-gesture-handler'; import { _setStoreData, _removeStoreData } from '../../providers/StoreUtil'; import { Container } from '../../layouts/Container'; import { LoginForm } from '../LoginForm'; import { SignupForm } from '../SignupForm'; import { useEffect } from 'react'; const w = Dimensions.get('window').width export const Home = (props: any) => { const { navigation, route, onNavigationRedirect, } = props; const theme = useTheme(); const styles = StyleSheet.create({ authHeader: { flexDirection: 'row', height: 57, borderBottomWidth: 1, borderBottomColor: theme.colors.border, alignItems: 'center', paddingHorizontal: 40 }, languageSelector: { marginRight: 10 }, textLink: { flexDirection: 'row', textAlign: 'center', justifyContent: 'center', alignItems: 'center' }, container: { flex: 1, alignItems: 'center', justifyContent: 'space-between', }, logo: { height: 70, width: w * 0.54, marginTop: 10 }, slogan: { height: w * 0.6, width: w * 0.6 }, buttons: { marginVertical: 8.5, marginHorizontal: 30, height: 40, shadowOpacity: 0 }, sloganText: { textAlign: 'center' }, wrapperContent: { marginTop: 20, }, wrapperBtn: { width: '100%', position: 'absolute', bottom: 0, marginBottom: 20 } }); const [, t] = useLanguage(); const [orderState] = useOrder(); const [, { login }] = useSession() const [isAuth, setAuthState] = useState(false); const [activeIndex, setActive] = useState(0); const loginProps = { navigation, useLoginByCellphone: true, useLoginByEmail: true, loginButtonText: t('SIGN_IN', 'Sign in'), loginButtonBackground: theme.colors.primary, forgotButtonText: t('FORGOT_YOUR_PASSWORD', 'Forgot your password?'), onNavigationRedirect: (page: string) => { if (!page) return navigation.navigate(page); }, notificationState: route?.params?.notification_state } const signupProps = { ...props, useChekoutFileds: true, loginButtonText: t('LOGIN', 'Login'), signupButtonText: t('SIGNUP', 'Signup'), useSignupByEmail: true, notificationState: props.route?.params?.notification_state, onNavigationRedirect: (page: string) => { if (!page) return props.navigation.navigate(page); }, handleSuccessSignup: (user: any) => { _removeStoreData('isGuestUser') if (user?.id) { login({ user, token: user.session.access_token }) } } } // _setStoreData('notification_state', props.route?.params?.notification_state); const handleGuessFlow = (page: string, params: any) => { onNavigationRedirect(page, params); _setStoreData('isGuestUser', true); }; const changAuthToggle = (idx: number) => { setActive(idx); } useEffect(() => { setTimeout(() => { setAuthState(route?.params?.showAuth || false); }, 500) }, [route?.params]); return ( {t('WELCOME_MESSAGE', 'Restaurants and more, delivered to your door')} { setActive(1), setAuthState(true) }} /> { setActive(0), setAuthState(true) }} /> orderState?.options?.address?.address ? handleGuessFlow('BusinessList', { isGuestUser: true }) : handleGuessFlow('AddressForm', { isGuestUser: true }) } > {t('CONTINUE_AS_GUEST', 'Continue as guest')} setAuthState(false)} style={{borderRadius: 7.6}}> setAuthState(false)} style={{}}> {activeIndex == 0 && } {activeIndex == 1 && } ); };