Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.41 KB | None | 0 0
  1. // @flow
  2. import React, { PureComponent } from 'react';
  3. import { FlatList, StyleSheet, View, ActivityIndicator } from 'react-native';
  4. import { type NavigationScreenProps } from 'react-navigation';
  5. import { Page, Card, CardFormButton, Text } from '../../components';
  6. import { SubmitEditPoiButton } from './components/SubmitEditPoiButton';
  7. import I18n from '../../lib/I18n';
  8. import theme from '../../theme';
  9.  
  10. type PropsType = {
  11. loading: boolean,
  12. poiTypes?: PoiTypeType[],
  13. tags?: TagType[],
  14. address?: string,
  15. name?: string,
  16. email?: string,
  17. phoneNumber?: string,
  18. description?: string,
  19. website?: string,
  20. clearUserInputPointOfInterest: Function,
  21. } & NavigationScreenProps;
  22.  
  23. export default class EditPoi extends PureComponent<PropsType> {
  24. componentWillUnmount() {
  25. this.props.clearUserInputPointOfInterest();
  26. }
  27. static navigationOptions = () => ({
  28. headerRight: <SubmitEditPoiButton />,
  29. });
  30.  
  31. _navigateToPoiTypeSelection = () => {
  32. const { navigation } = this.props;
  33. return navigation.navigate('SelectPoiTypes', {
  34. title: I18n.t('EditPoi.PoiType.title'),
  35. stepTitle: I18n.t('EditPoi.PoiType.step_title'),
  36. buttonLabel: I18n.t('EditPoi.back_button_label'),
  37. fromEditPoi: true,
  38. });
  39. };
  40.  
  41. _navigateToPoiNameAndAdress = () => {
  42. const { navigation } = this.props;
  43. return navigation.navigate('SelectPoiNameAndAddress', {
  44. fromEditPoi: true,
  45. title: I18n.t('EditPoi.PoiNameAndAddress.title'),
  46. });
  47. };
  48.  
  49. _navigateToPoiTags = () => {
  50. const { navigation } = this.props;
  51. return navigation.navigate('SelectPoiTags', {
  52. fromEditPoi: true,
  53. });
  54. };
  55.  
  56. _navigateToEditPoiField = type => {
  57. const { navigation } = this.props;
  58. return navigation.navigate('EditPoiField', {
  59. type,
  60. });
  61. };
  62.  
  63. _getFormSections = () => {
  64. const { poiTypes, tags, name, address, email, phoneNumber, website, description } = this.props;
  65. return [
  66. {
  67. title: I18n.t('EditPoi.name_and_address'),
  68. value: name ? (address ? `${name} - ${address}` : name) : '',
  69. onPress: this._navigateToPoiNameAndAdress,
  70. },
  71. {
  72. title: I18n.t('EditPoi.poi_types'),
  73. value: poiTypes ? poiTypes.map(({ type }) => I18n.t('Map.PoiType.' + type.toLowerCase())).join(', ') : '',
  74. onPress: this._navigateToPoiTypeSelection,
  75. },
  76. {
  77. title: I18n.t('EditPoi.tags'),
  78. value: tags
  79. ? tags
  80. .map(({ name }) => {
  81. return name
  82. ? name.length > 1 ? name.charAt(0).toUpperCase() + name.slice(1).toLowerCase() : name.toUpperCase()
  83. : '';
  84. })
  85. .filter(Boolean)
  86. .join(', ')
  87. : '',
  88. onPress: this._navigateToPoiTags,
  89. },
  90. {
  91. title: I18n.t('EditPoi.website'),
  92. onPress: () => this._navigateToEditPoiField('website'),
  93. value: website || '',
  94. },
  95. {
  96. title: I18n.t('EditPoi.phoneNumber'),
  97. onPress: () => this._navigateToEditPoiField('phoneNumber'),
  98. value: phoneNumber || '',
  99. },
  100. {
  101. title: I18n.t('EditPoi.email'),
  102. onPress: () => this._navigateToEditPoiField('email'),
  103. value: email || '',
  104. },
  105. {
  106. title: I18n.t('EditPoi.description'),
  107. value: description || '',
  108. onPress: () => this._navigateToEditPoiField('description'),
  109. hideSeparator: true,
  110. },
  111. ];
  112. };
  113.  
  114. _renderFormSection = ({ item: formSection }) => <CardFormButton {...formSection} />;
  115.  
  116. _keyExtractor = (section): string => section.title;
  117.  
  118. render() {
  119. const { loading, name } = this.props;
  120. return (
  121. <Page noPadding>
  122. <View style={[styles.cardContainer, !name && styles.loaderContainer]}>
  123. {name ? (
  124. <Card style={styles.card}>
  125. <FlatList
  126. bounces={false}
  127. data={this._getFormSections()}
  128. renderItem={this._renderFormSection}
  129. showsVerticalScrollIndicator={false}
  130. keyExtractor={this._keyExtractor}
  131. />
  132. </Card>
  133. ) : loading ? (
  134. <ActivityIndicator />
  135. ) : (
  136. <Text>{I18n.t('EditPoi.no_data')}</Text>
  137. )}
  138. </View>
  139. </Page>
  140. );
  141. }
  142. }
  143.  
  144. const styles = StyleSheet.create({
  145. card: {
  146. paddingTop: 0,
  147. },
  148. cardContainer: {
  149. margin: theme.margin,
  150. },
  151. loaderContainer: {
  152. flex: 1,
  153. justifyContent: 'center',
  154. alignItems: 'center',
  155. },
  156. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement