Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.27 KB | None | 0 0
  1. import React from 'react';
  2. import styles from 'events/styles';
  3. import {View, Text} from 'react-native';
  4. import PropTypes from 'prop-types';
  5. import {Card, WebViewAutoHeight} from 'common-components';
  6. import {feedContentStyles} from 'theme';
  7. import PriceRow from './PriceRow';
  8. import {moderateScale} from 'react-native-size-matters';
  9.  
  10. const propTypes = {
  11. event: PropTypes.object.isRequired,
  12. handleSelectPrice: PropTypes.func.isRequired,
  13. individualPrices: PropTypes.arrayOf(PropTypes.object),
  14. selectedPrice: PropTypes.object,
  15. tablePrices: PropTypes.arrayOf(PropTypes.object),
  16. };
  17.  
  18. //prettier-ignore
  19. const getHTML = event => `<body style="font-family: -apple-system, Roboto, sans-serif; font-size: ${moderateScale(14, 0.2)}px;">${event.LongDescription}</body>`;
  20.  
  21. const PhoneEventDescription = props => {
  22. console.log(props);
  23. const {
  24. event,
  25. handleSelectPrice,
  26. individualPrices,
  27. selectedPrice,
  28. tablePrices,
  29. } = props;
  30.  
  31. const displayPrices =
  32. !event.IsRestricted &&
  33. !event.IsFree &&
  34. (individualPrices.length > 0 || tablePrices.length > 0);
  35.  
  36. return (
  37. <View style={{flex: 1}}>
  38. <Card style={styles.cardStyles} tappable={false}>
  39. <Text style={styles.contentTitle}>{'Description'}</Text>
  40. {event.LongDescription ? (
  41. <WebViewAutoHeight
  42. source={{
  43. html: getHTML(event),
  44. }}
  45. />
  46. ) : (
  47. <Text style={feedContentStyles.parragraph}>
  48. {event.ShortDescription}
  49. </Text>
  50. )}
  51. </Card>
  52. {displayPrices && (
  53. <Card style={styles.cardStyles} tappable={false}>
  54. <Text style={styles.contentTitle}>{'Event Pricing'}</Text>
  55. {individualPrices.length > 0 && (
  56. <View style={styles.table}>
  57. <Text style={styles.subtitle}>{'Individual'}</Text>
  58. {individualPrices.map(item => {
  59. const isSelected =
  60. selectedPrice && item.Key === selectedPrice.Key;
  61. return (
  62. <PriceRow
  63. key={item.Key}
  64. isSelected={isSelected}
  65. name={item.Name}
  66. price={item.Price}
  67. onPress={() => handleSelectPrice(item)}
  68. endDate={item.EndDate}
  69. isMemberPrice={item.IsMemberPrice}
  70. guestPrice={item.guestPrice}
  71. isEarly={item.IsEarly}
  72. />
  73. );
  74. })}
  75. </View>
  76. )}
  77. {tablePrices.length > 0 && (
  78. <View style={[styles.table, {marginTop: 16}]}>
  79. <Text style={styles.subtitle}>{'Table'}</Text>
  80. {tablePrices.map(item => {
  81. const isSelected =
  82. selectedPrice && item.Key === selectedPrice.Key;
  83. return (
  84. <PriceRow
  85. key={item.Key}
  86. isSelected={isSelected}
  87. name={item.TableName}
  88. price={item.Price}
  89. onPress={() => handleSelectPrice(item)}
  90. endDate={item.EndDate}
  91. isMemberPrice={item.IsMemberPrice}
  92. isTable={true}
  93. isEarly={item.IsEarly}
  94. />
  95. );
  96. })}
  97. </View>
  98. )}
  99. </Card>
  100. )}
  101. </View>
  102. );
  103. };
  104.  
  105. PhoneEventDescription.propTypes = propTypes;
  106. export default PhoneEventDescription;
  107.  
  108. <Text style={styles.contentTitle}>{'Event Pricing'}</Text>
  109. {individualPrices.length > 0 && (
  110. <View style={styles.table}>
  111. <Text style={styles.subtitle}>{'Individual'}</Text>
  112.  
  113. import React from 'react';
  114. import {View, Text, TouchableOpacity} from 'react-native';
  115. import {Divider} from 'common-components';
  116. import styles from 'events/styles';
  117. import PropTypes from 'prop-types';
  118. import {format, compareAsc} from 'date-fns';
  119.  
  120. const PriceRow = ({
  121. name,
  122. price,
  123. isSelected,
  124. onPress,
  125. endDate,
  126. guestPrice,
  127. isEarly,
  128. isMemberPrice,
  129. isTable,
  130. }) => {
  131. const selectedPriceStyle = isSelected ? styles.selectedOuterCircle : null;
  132. const text =
  133. isEarly && endDate
  134. ? `${name} - Early pricing ends ${format(endDate, 'MM/DD/YYYY')}`
  135. : name;
  136.  
  137. const now = new Date();
  138. const visible =
  139. endDate === null ||
  140. (isEarly && compareAsc(now, endDate) < 0) ||
  141. (!isEarly && compareAsc(now, endDate) >= 0);
  142.  
  143. if (visible) {
  144. return (
  145. <View>
  146. <TouchableOpacity style={styles.tableRow} onPress={onPress}>
  147. <View style={styles.radioButton}>
  148. <View style={[styles.outerRadioCircle, selectedPriceStyle]}>
  149. {isSelected && <View style={styles.innerRadioCircle} />}
  150. </View>
  151. <View style={styles.priceLabelWrapper}>
  152. {!isTable && (
  153. <Text style={styles.priceLabel} numberOfLines={3}>
  154. {text}
  155. </Text>
  156. )}
  157. {guestPrice && (
  158. <Text style={styles.priceSubLabel} numberOfLines={3}>
  159. {guestPrice.Name}
  160. </Text>
  161. )}
  162. {isTable && (
  163. <Text style={styles.priceLabel} numberOfLines={3}>
  164. {`${text} - ${isMemberPrice ? '' : 'Non '}Member`}
  165. </Text>
  166. )}
  167. </View>
  168. </View>
  169. <View style={styles.priceContent}>
  170. <Text style={styles.blackText}>{`$${price}`}</Text>
  171. {guestPrice && (
  172. <Text style={styles.priceSubLabelTotal}>{`$${
  173. guestPrice.Price
  174. }`}</Text>
  175. )}
  176. </View>
  177. </TouchableOpacity>
  178. <Divider />
  179. </View>
  180. );
  181. }
  182. return <View />;
  183. };
  184.  
  185. PriceRow.propTypes = {
  186. endDate: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.string]),
  187. guestPrice: PropTypes.object,
  188. isEarly: PropTypes.bool,
  189. isMemberPrice: PropTypes.bool,
  190. isSelected: PropTypes.bool,
  191. isTable: PropTypes.bool,
  192. name: PropTypes.string.isRequired,
  193. onPress: PropTypes.func.isRequired,
  194. price: PropTypes.number.isRequired,
  195. };
  196.  
  197. export default PriceRow;
  198.  
  199. const PhoneEventDescription = props => {
  200. console.log(props);
  201. const {
  202. event,
  203. handleSelectPrice,
  204. individualPrices,
  205. selectedPrice,
  206. tablePrices,
  207. } = props;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement