2020-03-09 19:00:12 +01:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import * as React from 'react';
|
2020-03-29 14:46:44 +02:00
|
|
|
import {StyleSheet, View} from "react-native";
|
2020-03-09 19:00:12 +01:00
|
|
|
import HTML from "react-native-render-html";
|
|
|
|
import i18n from "i18n-js";
|
2020-03-09 23:15:13 +01:00
|
|
|
import {Avatar, Button, Card, withTheme} from 'react-native-paper';
|
2020-03-09 19:00:12 +01:00
|
|
|
import PlanningEventManager from "../utils/PlanningEventManager";
|
|
|
|
|
2020-03-29 14:46:44 +02:00
|
|
|
/**
|
|
|
|
* Component used to display an event preview if an event is available
|
|
|
|
*
|
|
|
|
* @param props Props to pass to the component
|
|
|
|
* @return {*}
|
|
|
|
*/
|
2020-03-09 19:00:12 +01:00
|
|
|
function PreviewEventDashboardItem(props) {
|
|
|
|
const {colors} = props.theme;
|
2020-03-29 14:46:44 +02:00
|
|
|
const isEmpty = props.event === undefined
|
|
|
|
? true
|
|
|
|
: PlanningEventManager.isDescriptionEmpty(props.event['description']);
|
|
|
|
|
2020-03-09 19:00:12 +01:00
|
|
|
if (props.event !== undefined && props.event !== null) {
|
|
|
|
const hasImage = props.event['logo'] !== '' && props.event['logo'] !== null;
|
|
|
|
const getImage = () => <Avatar.Image
|
|
|
|
source={{uri: props.event['logo']}}
|
|
|
|
size={50}
|
2020-03-29 14:46:44 +02:00
|
|
|
style={styles.avatar}/>;
|
2020-03-09 19:00:12 +01:00
|
|
|
return (
|
|
|
|
<Card
|
2020-03-29 14:46:44 +02:00
|
|
|
style={styles.card}
|
2020-03-09 19:00:12 +01:00
|
|
|
onPress={props.clickAction}
|
|
|
|
elevation={3}
|
|
|
|
>
|
|
|
|
{hasImage ?
|
|
|
|
<Card.Title
|
|
|
|
title={props.event['title']}
|
2020-03-21 17:23:59 +01:00
|
|
|
subtitle={PlanningEventManager.getFormattedEventTime(props.event['date_begin'], props.event['date_end'])}
|
2020-03-09 19:00:12 +01:00
|
|
|
left={getImage}
|
|
|
|
/> :
|
|
|
|
<Card.Title
|
|
|
|
title={props.event['title']}
|
2020-03-21 17:23:59 +01:00
|
|
|
subtitle={PlanningEventManager.getFormattedEventTime(props.event['date_begin'], props.event['date_end'])}
|
2020-03-09 19:00:12 +01:00
|
|
|
/>}
|
2020-03-11 16:08:02 +01:00
|
|
|
{!isEmpty ?
|
2020-03-29 14:46:44 +02:00
|
|
|
<Card.Content style={styles.content}>
|
2020-03-11 16:08:02 +01:00
|
|
|
<HTML html={"<div>" + props.event['description'] + "</div>"}
|
|
|
|
tagsStyles={{
|
|
|
|
p: {color: colors.text,},
|
|
|
|
div: {color: colors.text},
|
|
|
|
}}/>
|
|
|
|
|
|
|
|
</Card.Content> : null}
|
2020-03-09 19:00:12 +01:00
|
|
|
|
2020-03-29 14:46:44 +02:00
|
|
|
<Card.Actions style={styles.actions}>
|
2020-03-09 23:15:13 +01:00
|
|
|
<Button
|
2020-03-09 19:00:12 +01:00
|
|
|
icon={'chevron-right'}
|
2020-03-09 23:15:13 +01:00
|
|
|
>
|
|
|
|
{i18n.t("homeScreen.dashboard.seeMore")}
|
|
|
|
</Button>
|
|
|
|
</Card.Actions>
|
2020-03-09 19:00:12 +01:00
|
|
|
</Card>
|
|
|
|
);
|
|
|
|
} else
|
|
|
|
return <View/>
|
|
|
|
}
|
|
|
|
|
2020-03-29 14:46:44 +02:00
|
|
|
const styles = StyleSheet.create({
|
|
|
|
card: {
|
|
|
|
marginBottom: 10
|
|
|
|
},
|
|
|
|
content: {
|
|
|
|
maxHeight: 150,
|
|
|
|
overflow: 'hidden',
|
|
|
|
},
|
|
|
|
actions: {
|
|
|
|
marginLeft: 'auto',
|
|
|
|
marginTop: 'auto',
|
|
|
|
flexDirection: 'row'
|
|
|
|
},
|
|
|
|
avatar: {
|
|
|
|
backgroundColor: 'transparent'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-03-09 19:00:12 +01:00
|
|
|
export default withTheme(PreviewEventDashboardItem);
|