import React, { useContext, useState } from "react";
import { Text, View, StyleSheet, ScrollView } from "react-native";
import Screen from "../components/Screen";
import { AuthContext } from "../auth/context";
import authStorage from "../auth/storage";
import { TouchableOpacity } from "react-native-gesture-handler";
import assets from "../config/assets";
import { MaterialCommunityIcons } from "@expo/vector-icons";
import colors from "../config/colors";
import ConfirmationModal from "../components/ConfirmationModal";
import utils from "../config/utils";
function UserHeader({ name, fone }) {
const index = utils.hashPhoneNumber(fone) % assets.avatar.length || 2
const Avatar = assets.avatar[index];
return (
{name}
{fone}
);
}
function ProfileItensList({ icon, IconProvider, title, onPress }) {
return (
{title}
);
}
function AccountScreen(props) {
const { user, setUser } = useContext(AuthContext);
const isRegistered = user?.username != null;
const [showLog, setShowLog] = useState(false);
//console.log(user);
const logout = () => {
setShowLog(false)
setUser(true);
props.navigation.navigate("Home")
authStorage.removeToken();
authStorage.removeUser();
};
const activationActions = () => {
if (user?.providerActivationKey)
props.navigation.navigate("ActivateInstitutionShowCode");
else
props.navigation.navigate("ActivateInstitutionCode");
};
const showActivation = () => {
if (!isRegistered)
return false
else if (user.role === "ROLE_CLIENT")
return !user.active
else
return true
}
const profileItems = [
{
icon: "account",
show: user.pluviometer != undefined,
IconProvider: MaterialCommunityIcons,
title: user.pluviometer? "Dados do pluviômetro" : "Cadastrar pluviômetro",
onPress: () => {
props.navigation.navigate("PluviometerRegister");
},
},
{
icon: "bank",
show: showActivation(),
// show: true,
IconProvider: MaterialCommunityIcons,
title: "ATIVAR INSTITUIÇÃO",
onPress: () => {
activationActions();
},
},
{
icon: "information-outline",
show: true,
IconProvider: MaterialCommunityIcons,
title: "SOBRE O PROJETO",
onPress: () => {
props.navigation.navigate("Abbout");
},
},
{
icon: "logout",
show: isRegistered,
IconProvider: MaterialCommunityIcons,
title: "sair",
onPress: () => {
setShowLog(true);
},
},
{
icon: "login",
show: !isRegistered,
IconProvider: MaterialCommunityIcons,
title: "Entrar",
onPress: () => {
setUser(false);
},
},
];
return (
{profileItems.map(
({ icon, IconProvider, title, onPress, show }) =>
show && (
)
)}
setShowLog(false)}
/>
);
}
const styles = StyleSheet.create({
text: {
fontSize: 16,
},
});
export default AccountScreen;