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

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