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.

PreviewEventDashboardItem.js 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // @flow
  2. import * as React from 'react';
  3. import {StyleSheet, View} from 'react-native';
  4. import i18n from 'i18n-js';
  5. import {Avatar, Button, Card, TouchableRipple} from 'react-native-paper';
  6. import {getFormattedEventTime, isDescriptionEmpty} from '../../utils/Planning';
  7. import CustomHTML from '../Overrides/CustomHTML';
  8. import type {EventType} from '../../screens/Home/HomeScreen';
  9. type PropsType = {
  10. event?: EventType | null,
  11. clickAction: () => void,
  12. };
  13. const styles = StyleSheet.create({
  14. card: {
  15. marginBottom: 10,
  16. },
  17. content: {
  18. maxHeight: 150,
  19. overflow: 'hidden',
  20. },
  21. actions: {
  22. marginLeft: 'auto',
  23. marginTop: 'auto',
  24. flexDirection: 'row',
  25. },
  26. avatar: {
  27. backgroundColor: 'transparent',
  28. },
  29. });
  30. /**
  31. * Component used to display an event preview if an event is available
  32. */
  33. // eslint-disable-next-line react/prefer-stateless-function
  34. class PreviewEventDashboardItem extends React.Component<PropsType> {
  35. static defaultProps = {
  36. event: null,
  37. };
  38. render(): React.Node {
  39. const {props} = this;
  40. const {event} = props;
  41. const isEmpty =
  42. event == null ? true : isDescriptionEmpty(event.description);
  43. if (event != null) {
  44. const hasImage = event.logo !== '' && event.logo != null;
  45. const getImage = (): React.Node => (
  46. <Avatar.Image
  47. source={{uri: event.logo}}
  48. size={50}
  49. style={styles.avatar}
  50. />
  51. );
  52. return (
  53. <Card style={styles.card} elevation={3}>
  54. <TouchableRipple style={{flex: 1}} onPress={props.clickAction}>
  55. <View>
  56. {hasImage ? (
  57. <Card.Title
  58. title={event.title}
  59. subtitle={getFormattedEventTime(
  60. event.date_begin,
  61. event.date_end,
  62. )}
  63. left={getImage}
  64. />
  65. ) : (
  66. <Card.Title
  67. title={event.title}
  68. subtitle={getFormattedEventTime(
  69. event.date_begin,
  70. event.date_end,
  71. )}
  72. />
  73. )}
  74. {!isEmpty ? (
  75. <Card.Content style={styles.content}>
  76. <CustomHTML html={event.description} />
  77. </Card.Content>
  78. ) : null}
  79. <Card.Actions style={styles.actions}>
  80. <Button icon="chevron-right">
  81. {i18n.t('screens.home.dashboard.seeMore')}
  82. </Button>
  83. </Card.Actions>
  84. </View>
  85. </TouchableRipple>
  86. </Card>
  87. );
  88. }
  89. return null;
  90. }
  91. }
  92. export default PreviewEventDashboardItem;