import React, { useState, useEffect } from 'react'; import { StyleSheet, View, Dimensions, Platform } from 'react-native'; import { useForm, Controller } from 'react-hook-form'; import { useLanguage, useApi } from 'ordering-components/native'; import { useTheme } from 'styled-components/native'; import { LogoWrapper, Container, BackgroundImage, FormInput } from './styles'; import { OButton, OIcon, OText, OInput } from '../shared'; import { _setStoreData } from '../../providers/StoreUtil'; export const Home = (props: any) => { const { onNavigationRedirect, useRootPoint } = props; const safeHeight = Platform.OS === 'ios' ? 80 : 40; const theme = useTheme(); const [ordering, { setOrdering }] = useApi(); const [, t] = useLanguage(); const { control, handleSubmit, errors } = useForm(); const styles = StyleSheet.create({ logo: { height: 65, width: 300, }, wrapperContent: { width: '100%', }, wrapperText: { marginBottom: 20, }, textTitle: { fontWeight: '600', fontStyle: 'normal', fontSize: 50, }, textSubtitle: { fontWeight: 'normal', fontStyle: 'normal', fontSize: 14, }, wrapperBtn: { marginBottom: 20 }, btn: { borderRadius: 7.6, marginTop: 20, }, btnText: { fontFamily: 'Poppins', fontStyle: 'normal', fontWeight: 'normal', fontSize: 18, }, input: { borderWidth: 1, borderRadius: 7.6, borderColor: Object.keys(errors).length > 0 ? theme.colors.error : theme.colors.inputSignup, backgroundColor: theme.colors.transparent, }, }); const [projectName, setProjectName] = useState(null) const [isLoadingProject, setLoadingProject] = useState(false) const [orientation, setOrientation] = useState( Dimensions.get('window').width < Dimensions.get('window').height ? 'Portrait' : 'Landscape', ); const [windowHeight, setWindowHeight] = useState( parseInt(parseFloat(String(Dimensions.get('window').height)).toFixed(0)), ); Dimensions.addEventListener('change', ({ window: { width, height } }) => { setWindowHeight( parseInt(parseFloat(String(Dimensions.get('window').height)).toFixed(0)), ); if (width < height) { setOrientation('Portrait'); } else { setOrientation('Landscape'); } }); const onSubmit = (values: any) => { setLoadingProject(true) setProjectName(values) setOrdering({ ...ordering, project: values?.project_name }) _setStoreData('project_name', values?.project_name) }; useEffect(() => { if (Object.keys(errors).length > 0) { setProjectName(null) setLoadingProject(false) } }, [errors]) useEffect(() => { if (ordering?.project === projectName?.project_name) { setLoadingProject(false) onNavigationRedirect('Login') } }, [ordering]) return ( {t('TITLE_SIGN_UP', 'Welcome')} {t(props.title.key, props.title.value)} <> {useRootPoint && ( ( { const project = e?.target?.value?.replace(/\s/g, '') onChange(project) }} selectionColor={theme.colors.primary} color={theme.colors.white} value={value} style={styles.input} returnKeyType='done' autoCorrect={false} autoCapitalize='none' blurOnSubmit={false} onSubmitEditing={() => handleSubmit(onSubmit)()} isValueSync /> )} /> )} {Object.keys(errors).length > 0 && ( {errors['project_name'].message} )} useRootPoint ? handleSubmit(onSubmit)() : onNavigationRedirect('Login')} /> ); };