// @flow import * as React from 'react'; import {FlatList, StyleSheet, View} from "react-native"; import {Avatar, Button, Card, Divider, List, Paragraph, withTheme} from 'react-native-paper'; import AuthenticatedScreen from "../../components/Amicale/AuthenticatedScreen"; import i18n from 'i18n-js'; import LogoutDialog from "../../components/Amicale/LogoutDialog"; import MaterialHeaderButtons, {Item} from "../../components/Overrides/CustomHeaderButton"; import type {cardList} from "../../components/Lists/CardList/CardList"; import CardList from "../../components/Lists/CardList/CardList"; import {StackNavigationProp} from "@react-navigation/stack"; import type {CustomTheme} from "../../managers/ThemeManager"; import AvailableWebsites from "../../constants/AvailableWebsites"; import Mascot, {MASCOT_STYLE} from "../../components/Mascot/Mascot"; import ServicesManager, {SERVICES_KEY} from "../../managers/ServicesManager"; import CollapsibleFlatList from "../../components/Collapsible/CollapsibleFlatList"; type Props = { navigation: StackNavigationProp, theme: CustomTheme, } type State = { dialogVisible: boolean, } type ProfileData = { first_name: string, last_name: string, email: string, birthday: string, phone: string, branch: string, link: string, validity: boolean, clubs: Array, } type Club = { id: number, name: string, is_manager: boolean, } class ProfileScreen extends React.Component { state = { dialogVisible: false, }; data: ProfileData; flatListData: Array<{ id: string }>; amicaleDataset: cardList; constructor(props: Props) { super(props); this.flatListData = [ {id: '0'}, {id: '1'}, {id: '2'}, {id: '3'}, ] const services = new ServicesManager(props.navigation); this.amicaleDataset = services.getAmicaleServices([SERVICES_KEY.PROFILE]); } componentDidMount() { this.props.navigation.setOptions({ headerRight: this.getHeaderButton, }); } showDisconnectDialog = () => this.setState({dialogVisible: true}); hideDisconnectDialog = () => this.setState({dialogVisible: false}); /** * Gets the logout header button * * @returns {*} */ getHeaderButton = () => ; /** * Gets the main screen component with the fetched data * * @param data The data fetched from the server * @returns {*} */ getScreen = (data: Array<{ [key: string]: any } | null>) => { if (data[0] != null) { this.data = data[0]; } return ( ) }; getRenderItem = ({item}: { item: { id: string } }) => { switch (item.id) { case '0': return this.getWelcomeCard(); case '1': return this.getPersonalCard(); case '2': return this.getClubCard(); default: return this.getMembershipCar(); } }; /** * Gets the list of services available with the Amicale account * * @returns {*} */ getServicesList() { return ( ); } /** * Gets a card welcoming the user to his account * * @returns {*} */ getWelcomeCard() { return ( } titleStyle={{marginLeft: 10}} /> {i18n.t("screens.profile.welcomeDescription")} {this.getServicesList()} {i18n.t("screens.profile.welcomeFeedback")} ); } /** * 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("screens.profile.noData"); } /** * 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) { let title = this.isFieldAvailable(field) ? this.getFieldValue(field) : ':('; let subtitle = this.isFieldAvailable(field) ? '' : this.getFieldValue(field); return ( } /> ); } /** * Gets a card containing user personal information * * @return {*} */ getPersonalCard() { return ( } /> {i18n.t("screens.profile.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}: { item: Club }) => { const onPress = () => this.openClubDetailsScreen(item.id); let description = i18n.t("screens.profile.isMember"); let icon = (props) => ; if (item.is_manager) { description = i18n.t("screens.profile.isManager"); icon = (props) => ; } return ; }; clubKeyExtractor = (item: Club) => item.name; sortClubList = (a: Club, b: Club) => a.is_manager ? -1 : 1; /** * Renders the list of clubs the user is part of * * @param list The club list * @return {*} */ getClubList(list: Array) { list.sort(this.sortClubList); return ( //$FlowFixMe ); } render() { return ( ); } } const styles = StyleSheet.create({ card: { margin: 10, }, icon: { backgroundColor: 'transparent' }, editButton: { marginLeft: 'auto' } }); export default withTheme(ProfileScreen);