|
|
@ -10,32 +10,40 @@ import colors from "../config/colors"; |
|
|
|
import ConfirmationModal from "../components/ConfirmationModal"; |
|
|
|
import utils from "../config/utils"; |
|
|
|
import { mask } from "react-native-mask-text"; |
|
|
|
import { useNetInfo } from "@react-native-community/netinfo"; |
|
|
|
import ConnectionWarning from "../components/ConnectionWarning"; |
|
|
|
|
|
|
|
function UserHeader({ name, fone }) { |
|
|
|
const index = utils.hashPhoneNumber(fone) % assets.avatar.length || 2 |
|
|
|
const index = utils.hashPhoneNumber(fone) % assets.avatar.length || 2; |
|
|
|
const Avatar = assets.avatar[index]; |
|
|
|
|
|
|
|
var _mask = ""; |
|
|
|
switch (fone?.length) { |
|
|
|
case 12: |
|
|
|
_mask = "(999) 99999-9999" ; |
|
|
|
_mask = "(999) 99999-9999"; |
|
|
|
break; |
|
|
|
case 11: |
|
|
|
_mask = "(99) 99999-9999" |
|
|
|
_mask = "(99) 99999-9999"; |
|
|
|
break; |
|
|
|
case 10: |
|
|
|
_mask = "(99) 9999-9999" |
|
|
|
_mask = "(99) 9999-9999"; |
|
|
|
break; |
|
|
|
default: |
|
|
|
_mask = "(99) 9999-9999" |
|
|
|
_mask = "(99) 9999-9999"; |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
const fone_mask = mask(fone, _mask); |
|
|
|
|
|
|
|
return ( |
|
|
|
<View style={{ flexDirection: "row", alignItems: "center", justifyContent: name ? "flex-start" : "center" }}> |
|
|
|
<Avatar width={60} height={60}/> |
|
|
|
<View |
|
|
|
style={{ |
|
|
|
flexDirection: "row", |
|
|
|
alignItems: "center", |
|
|
|
justifyContent: name ? "flex-start" : "center", |
|
|
|
}} |
|
|
|
> |
|
|
|
<Avatar width={60} height={60} /> |
|
|
|
<View style={{ marginLeft: 16 }}> |
|
|
|
<Text style={[styles.text, { fontWeight: "bold" }]}>{name}</Text> |
|
|
|
<Text style={styles.text}>{fone ? fone_mask : ""}</Text> |
|
|
@ -45,6 +53,7 @@ function UserHeader({ name, fone }) { |
|
|
|
} |
|
|
|
|
|
|
|
function ProfileItensList({ icon, IconProvider, title, onPress }) { |
|
|
|
const isConnected = useNetInfo().isConnected; |
|
|
|
return ( |
|
|
|
<View> |
|
|
|
<View |
|
|
@ -54,7 +63,7 @@ function ProfileItensList({ icon, IconProvider, title, onPress }) { |
|
|
|
}} |
|
|
|
></View> |
|
|
|
|
|
|
|
<TouchableOpacity onPress={onPress}> |
|
|
|
<TouchableOpacity disabled={!isConnected} onPress={onPress}> |
|
|
|
<View |
|
|
|
style={{ |
|
|
|
marginVertical: 16, |
|
|
@ -62,13 +71,14 @@ function ProfileItensList({ icon, IconProvider, title, onPress }) { |
|
|
|
alignItems: "center", |
|
|
|
}} |
|
|
|
> |
|
|
|
<IconProvider name={icon} size={18} color={colors.dark} /> |
|
|
|
<IconProvider name={icon} size={18} color={isConnected ? colors.black : colors.gray} /> |
|
|
|
<Text |
|
|
|
style={{ |
|
|
|
fontSize: 16, |
|
|
|
marginLeft: 16, |
|
|
|
textTransform: "uppercase", |
|
|
|
fontWeight: "500", |
|
|
|
color: isConnected ? colors.black : colors.gray, |
|
|
|
}} |
|
|
|
> |
|
|
|
{title} |
|
|
@ -82,7 +92,7 @@ function ProfileItensList({ icon, IconProvider, title, onPress }) { |
|
|
|
<MaterialCommunityIcons |
|
|
|
name={"chevron-right"} |
|
|
|
size={20} |
|
|
|
color={colors.dark} |
|
|
|
color={isConnected ? colors.black : colors.gray} |
|
|
|
/> |
|
|
|
</View> |
|
|
|
</View> |
|
|
@ -98,9 +108,9 @@ function AccountScreen(props) { |
|
|
|
|
|
|
|
//console.log(user);
|
|
|
|
const logout = () => { |
|
|
|
setShowLog(false) |
|
|
|
setShowLog(false); |
|
|
|
setUser(true); |
|
|
|
props.navigation.navigate("Home") |
|
|
|
props.navigation.navigate("Home"); |
|
|
|
authStorage.removeToken(); |
|
|
|
authStorage.removeUser(); |
|
|
|
}; |
|
|
@ -108,19 +118,14 @@ function AccountScreen(props) { |
|
|
|
const activationActions = () => { |
|
|
|
if (user?.providerActivationKey) |
|
|
|
props.navigation.navigate("ActivateInstitutionShowCode"); |
|
|
|
else |
|
|
|
props.navigation.navigate("ActivateInstitutionCode"); |
|
|
|
else props.navigation.navigate("ActivateInstitutionCode"); |
|
|
|
}; |
|
|
|
|
|
|
|
const showActivation = () => { |
|
|
|
if (!isRegistered) |
|
|
|
return false |
|
|
|
else if (user.role === "ROLE_CLIENT") |
|
|
|
return !user.active |
|
|
|
else |
|
|
|
return true |
|
|
|
} |
|
|
|
|
|
|
|
if (!isRegistered) return false; |
|
|
|
else if (user.role === "ROLE_CLIENT") return !user.active; |
|
|
|
else return true; |
|
|
|
}; |
|
|
|
|
|
|
|
const profileItems = [ |
|
|
|
{ |
|
|
@ -129,14 +134,16 @@ function AccountScreen(props) { |
|
|
|
IconProvider: MaterialCommunityIcons, |
|
|
|
title: "alterar senha", |
|
|
|
onPress: () => { |
|
|
|
props.navigation.navigate("PasswordRecovery", {user: user}); |
|
|
|
props.navigation.navigate("PasswordRecovery", { user: user }); |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
icon: "account", |
|
|
|
show: user.pluviometer != undefined, |
|
|
|
IconProvider: MaterialCommunityIcons, |
|
|
|
title: user.pluviometer? "Dados do pluviômetro" : "Cadastrar pluviômetro", |
|
|
|
title: user.pluviometer |
|
|
|
? "Dados do pluviômetro" |
|
|
|
: "Cadastrar pluviômetro", |
|
|
|
onPress: () => { |
|
|
|
props.navigation.navigate("PluviometerRegister"); |
|
|
|
}, |
|
|
@ -182,6 +189,9 @@ function AccountScreen(props) { |
|
|
|
]; |
|
|
|
|
|
|
|
return ( |
|
|
|
<View style={{flex:1, width: "100%"}}> |
|
|
|
|
|
|
|
<ConnectionWarning /> |
|
|
|
<Screen> |
|
|
|
<ScrollView> |
|
|
|
<View |
|
|
@ -189,7 +199,7 @@ function AccountScreen(props) { |
|
|
|
padding: 16, |
|
|
|
}} |
|
|
|
> |
|
|
|
<UserHeader name={user.nickname} fone={user.username}/> |
|
|
|
<UserHeader name={user.nickname} fone={user.username} /> |
|
|
|
|
|
|
|
<View style={{ marginTop: 24 }}> |
|
|
|
{profileItems.map( |
|
|
@ -218,6 +228,7 @@ function AccountScreen(props) { |
|
|
|
</View> |
|
|
|
</ScrollView> |
|
|
|
</Screen> |
|
|
|
</View> |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|