Application Android et IOS pour l'amicale des élèves https://play.google.com/store/apps/details?id=fr.amicaleinsat.application
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.

EventDashboardItem.js 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // @flow
  2. import * as React from 'react';
  3. import {
  4. Avatar,
  5. Card,
  6. Text,
  7. TouchableRipple,
  8. withTheme,
  9. } from 'react-native-paper';
  10. import {StyleSheet, View} from 'react-native';
  11. import i18n from 'i18n-js';
  12. import type {CustomThemeType} from '../../managers/ThemeManager';
  13. type PropsType = {
  14. eventNumber: number,
  15. clickAction: () => void,
  16. theme: CustomThemeType,
  17. children?: React.Node,
  18. };
  19. const styles = StyleSheet.create({
  20. card: {
  21. width: 'auto',
  22. marginLeft: 10,
  23. marginRight: 10,
  24. marginTop: 10,
  25. overflow: 'hidden',
  26. },
  27. avatar: {
  28. backgroundColor: 'transparent',
  29. },
  30. });
  31. /**
  32. * Component used to display a dashboard item containing a preview event
  33. */
  34. class EventDashBoardItem extends React.Component<PropsType> {
  35. static defaultProps = {
  36. children: null,
  37. };
  38. shouldComponentUpdate(nextProps: PropsType): boolean {
  39. const {props} = this;
  40. return (
  41. nextProps.theme.dark !== props.theme.dark ||
  42. nextProps.eventNumber !== props.eventNumber
  43. );
  44. }
  45. render(): React.Node {
  46. const {props} = this;
  47. const {colors} = props.theme;
  48. const isAvailable = props.eventNumber > 0;
  49. const iconColor = isAvailable ? colors.planningColor : colors.textDisabled;
  50. const textColor = isAvailable ? colors.text : colors.textDisabled;
  51. let subtitle;
  52. if (isAvailable) {
  53. subtitle = (
  54. <Text>
  55. <Text style={{fontWeight: 'bold'}}>{props.eventNumber}</Text>
  56. <Text>
  57. {props.eventNumber > 1
  58. ? i18n.t('screens.home.dashboard.todayEventsSubtitlePlural')
  59. : i18n.t('screens.home.dashboard.todayEventsSubtitle')}
  60. </Text>
  61. </Text>
  62. );
  63. } else subtitle = i18n.t('screens.home.dashboard.todayEventsSubtitleNA');
  64. return (
  65. <Card style={styles.card}>
  66. <TouchableRipple style={{flex: 1}} onPress={props.clickAction}>
  67. <View>
  68. <Card.Title
  69. title={i18n.t('screens.home.dashboard.todayEventsTitle')}
  70. titleStyle={{color: textColor}}
  71. subtitle={subtitle}
  72. subtitleStyle={{color: textColor}}
  73. left={(): React.Node => (
  74. <Avatar.Icon
  75. icon="calendar-range"
  76. color={iconColor}
  77. size={60}
  78. style={styles.avatar}
  79. />
  80. )}
  81. />
  82. <Card.Content>{props.children}</Card.Content>
  83. </View>
  84. </TouchableRipple>
  85. </Card>
  86. );
  87. }
  88. }
  89. export default withTheme(EventDashBoardItem);