Application Android et IOS pour l'amicale des élèves
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ServicesScreen.js 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. // @flow
  2. import * as React from 'react';
  3. import {Image, View} from 'react-native';
  4. import {
  5. Avatar,
  6. Card,
  7. Divider,
  8. List,
  9. TouchableRipple,
  10. withTheme,
  11. } from 'react-native-paper';
  12. import i18n from 'i18n-js';
  13. import {StackNavigationProp} from '@react-navigation/stack';
  14. import CardList from '../../components/Lists/CardList/CardList';
  15. import type {CustomThemeType} from '../../managers/ThemeManager';
  16. import MaterialHeaderButtons, {
  17. Item,
  18. } from '../../components/Overrides/CustomHeaderButton';
  19. import {MASCOT_STYLE} from '../../components/Mascot/Mascot';
  20. import MascotPopup from '../../components/Mascot/MascotPopup';
  21. import AsyncStorageManager from '../../managers/AsyncStorageManager';
  22. import ServicesManager, {
  23. SERVICES_CATEGORIES_KEY,
  24. } from '../../managers/ServicesManager';
  25. import CollapsibleFlatList from '../../components/Collapsible/CollapsibleFlatList';
  26. import type {ServiceCategoryType} from '../../managers/ServicesManager';
  27. type PropsType = {
  28. navigation: StackNavigationProp,
  29. theme: CustomThemeType,
  30. };
  31. class ServicesScreen extends React.Component<PropsType> {
  32. finalDataset: Array<ServiceCategoryType>;
  33. constructor(props: PropsType) {
  34. super(props);
  35. const services = new ServicesManager(props.navigation);
  36. this.finalDataset = services.getCategories([
  37. SERVICES_CATEGORIES_KEY.SPECIAL,
  38. ]);
  39. }
  40. componentDidMount() {
  41. const {props} = this;
  42. props.navigation.setOptions({
  43. headerRight: this.getAboutButton,
  44. });
  45. }
  46. getAboutButton = (): React.Node => (
  47. <MaterialHeaderButtons>
  48. <Item
  49. title="information"
  50. iconName="information"
  51. onPress={this.onAboutPress}
  52. />
  53. </MaterialHeaderButtons>
  54. );
  55. onAboutPress = () => {
  56. const {props} = this;
  57. props.navigation.navigate('amicale-contact');
  58. };
  59. /**
  60. * Gets the list title image for the list.
  61. *
  62. * If the source is a string, we are using an icon.
  63. * If the source is a number, we are using an internal image.
  64. *
  65. * @param source The source image to display. Can be a string for icons or a number for local images
  66. * @returns {*}
  67. */
  68. getListTitleImage(source: string | number): React.Node {
  69. const {props} = this;
  70. if (typeof source === 'number')
  71. return (
  72. <Image
  73. size={48}
  74. source={source}
  75. style={{
  76. width: 48,
  77. height: 48,
  78. }}
  79. />
  80. );
  81. return (
  82. <Avatar.Icon
  83. size={48}
  84. icon={source}
  85. color={props.theme.colors.primary}
  86. style={{backgroundColor: 'transparent'}}
  87. />
  88. );
  89. }
  90. /**
  91. * A list item showing a list of available services for the current category
  92. *
  93. * @param item
  94. * @returns {*}
  95. */
  96. getRenderItem = ({item}: {item: ServiceCategoryType}): React.Node => {
  97. const {props} = this;
  98. return (
  99. <TouchableRipple
  100. style={{
  101. margin: 5,
  102. marginBottom: 20,
  103. }}
  104. onPress={() => {
  105. props.navigation.navigate('services-section', {data: item});
  106. }}>
  107. <View>
  108. <Card.Title
  109. title={item.title}
  110. subtitle={item.subtitle}
  111. left={(): React.Node => this.getListTitleImage(item.image)}
  112. right={(): React.Node => <List.Icon icon="chevron-right" />}
  113. />
  114. <CardList dataset={item.content} isHorizontal />
  115. </View>
  116. </TouchableRipple>
  117. );
  118. };
  119. keyExtractor = (item: ServiceCategoryType): string => item.title;
  120. render(): React.Node {
  121. return (
  122. <View>
  123. <CollapsibleFlatList
  124. data={this.finalDataset}
  125. renderItem={this.getRenderItem}
  126. keyExtractor={this.keyExtractor}
  127. ItemSeparatorComponent={(): React.Node => <Divider />}
  128. hasTab
  129. />
  130. <MascotPopup
  131. prefKey={AsyncStorageManager.PREFERENCES.servicesShowMascot.key}
  132. title={i18n.t('screens.services.mascotDialog.title')}
  133. message={i18n.t('screens.services.mascotDialog.message')}
  134. icon="cloud-question"
  135. buttons={{
  136. action: null,
  137. cancel: {
  138. message: i18n.t('screens.services.mascotDialog.button'),
  139. icon: 'check',
  140. },
  141. }}
  142. emotion={MASCOT_STYLE.WINK}
  143. />
  144. </View>
  145. );
  146. }
  147. }
  148. export default withTheme(ServicesScreen);