// @flow import * as React from 'react'; import {FlatList, StyleSheet, View} from "react-native"; import {Avatar, Button, Card, Divider, List, withTheme} from 'react-native-paper'; import AuthenticatedScreen from "../../components/Amicale/AuthenticatedScreen"; import {openBrowser} from "../../utils/WebBrowser"; import HeaderButton from "../../components/Custom/HeaderButton"; import i18n from 'i18n-js'; import LogoutDialog from "../../components/Amicale/LogoutDialog"; type Props = { navigation: Object, theme: Object, } type State = { dialogVisible: boolean, } class ProfileScreen extends React.Component { state = { dialogVisible: false, }; colors: Object; data: Object; flatListData: Array; constructor(props) { super(props); this.colors = props.theme.colors; this.flatListData = [ {id: '0'}, {id: '1'}, {id: '2'}, ] } componentDidMount() { this.props.navigation.setOptions({ headerRight: this.getHeaderButton, }); } showDisconnectDialog = () => this.setState({dialogVisible: true}); hideDisconnectDialog = () => this.setState({dialogVisible: false}); getHeaderButton = () => ; getScreen = (data: Object) => { this.data = data[0]; return ( {/*$FlowFixMe*/} ) }; getRenderItem = ({item}: Object) => { switch (item.id) { case '0': return this.getPersonalCard(); case '1': return this.getClubCard(); default: return this.getMembershipCar(); } }; /** * Checks if the given field is available * * @param field The field to check * @return {boolean} */ isFieldAvailable(field: ?string) { return field !== null; } /** * Gets the given field value. * If the field does not have a value, returns a placeholder text * * @param field The field to get the value from * @return {*} */ getFieldValue(field: ?string) { return this.isFieldAvailable(field) ? field : i18n.t("profileScreen.noData"); } /** * Gets the color depending on the value. * * @param field The field to get the color for * @return {*} */ getFieldColor(field: ?string) { return this.isFieldAvailable(field) ? this.colors.text : this.colors.textDisabled; } /** * Gets a list item showing personal information * * @param field The field to display * @param icon The icon to use * @return {*} */ getPersonalListItem(field: ?string, icon: string) { return ( } titleStyle={{color: this.getFieldColor(field)}} /> ); } /** * Gets a card containing user personal information * * @return {*} */ getPersonalCard() { return ( } /> {i18n.t("profileScreen.personalInformation")} {this.getPersonalListItem(this.data.birthday, "cake-variant")} {this.getPersonalListItem(this.data.phone, "phone")} {this.getPersonalListItem(this.data.email, "email")} {this.getPersonalListItem(this.data.branch, "school")} ); } /** * Gets a cars containing clubs the user is part of * * @return {*} */ getClubCard() { return ( } /> {this.getClubList(this.data.clubs)} ); } /** * Gets a card showing if the user has payed his membership * * @return {*} */ getMembershipCar() { return ( } /> {this.getMembershipItem(this.data.validity)} ); } /** * Gets the item showing if the user has payed his membership * * @return {*} */ getMembershipItem(state: boolean) { return ( } /> ); } /** * Opens the club details screen for the club of given ID * @param id The club's id to open */ openClubDetailsScreen(id: number) { this.props.navigation.navigate("club-information", {clubId: id}); } /** * Gets a list item for the club list * * @param item The club to render * @return {*} */ clubListItem = ({item}: Object) => { const onPress = () => this.openClubDetailsScreen(0); // TODO get club id const isManager = false; // TODO detect if manager let description = i18n.t("profileScreen.isMember"); let icon = (props) => ; if (isManager) { description = i18n.t("profileScreen.isManager"); icon = (props) => ; } return ; }; clubKeyExtractor = (item: Object) => item.name; /** * Renders the list of clubs the user is part of * * @param list The club list * @return {*} */ getClubList(list: Array) { let dataset = []; for (let i = 0; i < list.length; i++) { dataset.push({name: list[i]}); } return ( //$FlowFixMe ); } render() { return ( ); } } const styles = StyleSheet.create({ card: { margin: 10, }, icon: { backgroundColor: 'transparent' }, editButton: { marginLeft: 'auto' } }); export default withTheme(ProfileScreen);