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.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 {getTimeOnlyString, isDescriptionEmpty} from '../../utils/Planning';
  7. import CustomHTML from '../Overrides/CustomHTML';
  8. import type {PlanningEventType} from '../../utils/Planning';
  9. type PropsType = {
  10. event?: PlanningEventType | 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={getTimeOnlyString(event.date_begin)}
  60. left={getImage}
  61. />
  62. ) : (
  63. <Card.Title
  64. title={event.title}
  65. subtitle={getTimeOnlyString(event.date_begin)}
  66. />
  67. )}
  68. {!isEmpty ? (
  69. <Card.Content style={styles.content}>
  70. <CustomHTML html={event.description} />
  71. </Card.Content>
  72. ) : null}
  73. <Card.Actions style={styles.actions}>
  74. <Button icon="chevron-right">
  75. {i18n.t('screens.home.dashboard.seeMore')}
  76. </Button>
  77. </Card.Actions>
  78. </View>
  79. </TouchableRipple>
  80. </Card>
  81. );
  82. }
  83. return null;
  84. }
  85. }
  86. export default PreviewEventDashboardItem;