import React, { useEffect, useState } from 'react'; import { UserFormDetails as UserProfileController, useSession, useLanguage, } from 'ordering-components/native'; import { useTheme } from 'styled-components/native'; import { TouchableOpacity, View, StyleSheet } from 'react-native'; import { ProfileParams } from '../../types'; import { LogoutButton } from '../LogoutButton' import { LanguageSelector } from '../LanguageSelector' import MaterialIcons from 'react-native-vector-icons/MaterialIcons' import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons' import Ionicons from 'react-native-vector-icons/Ionicons' import { OAlert, OIcon, OText } from '../shared'; import { Container, Names, UserInfoContainer, LanguageContainer, RemoveAccountContainer } from './styles'; export const UserProfileFormUI = (props: ProfileParams) => { const { navigation, handleRemoveAccount, removeAccountState } = props; const theme = useTheme(); const [{ user }, { logout }] = useSession(); const [, t] = useLanguage(); const isAdmin = user?.level === 0 const [confirm, setConfirm] = useState({ open: false, content: null, handleOnAccept: null, id: null, title: null }) const styles = StyleSheet.create({ linkStyle: { color: theme.colors.primary, textDecorationLine: 'underline', }, subItemStyle: { flexDirection: 'row', alignItems: 'center', marginVertical: 12 }, iconStyle: { fontSize: 24 }, removeAccount: { flexDirection: 'row' } }); const _pickerStyle = StyleSheet.create({ inputAndroid: { color: '#000', borderWidth: 1, borderColor: theme.colors.clear, padding: 10, height: 40, backgroundColor: theme.colors.disabled, borderRadius: 8 }, inputIOS: { color: '#000', padding: 10, height: 40, borderWidth: 1, borderColor: theme.colors.clear, backgroundColor: theme.colors.clear, }, icon: { width: 10, marginTop: 9, marginEnd: 10 }, placeholder: { color: theme.colors.secundaryContrast }, chevronDown: { display: 'none' }, chevronUp: { display: 'none' }, }) const onRedirect = (route: string, params?: any) => { navigation.navigate(route, params) } const onRemoveAccount = () => { setConfirm({ open: true, content: [t('QUESTION_REMOVE_ACCOUNT', 'Are you sure that you want to remove your account?')], title: t('ACCOUNT_ALERT', 'Account alert'), handleOnAccept: () => { setConfirm({ ...confirm, open: false }) handleRemoveAccount && handleRemoveAccount(user?.id) } }) } useEffect(() => { if (removeAccountState?.result === 'OK') { logout() } }, [removeAccountState]) return ( {t('MOBILE_PROFILE', 'Profile')} {user?.name} {user?.lastname} onRedirect('Account')} > {t('ACCOUNT', 'Account')} onRedirect('AddressList', { isFromProfile: true })} style={styles.subItemStyle} > {t('SAVED_PLACES', 'My saved places')} onRedirect('Help')} style={styles.subItemStyle} > {t('HELP', 'Help')} onRemoveAccount()} activeOpacity={0.7} > {t('REMOVE_ACCOUNT', 'Remove account')} setConfirm({ ...confirm, open: false, title: null })} onClose={() => setConfirm({ ...confirm, open: false, title: null })} /> ); }; export const UserProfileForm = (props: any) => { const profileProps = { ...props, UIComponent: UserProfileFormUI, useSessionUser: true }; return ; };