Advertisement
kernazhytskaya

DealCard.js

Nov 22nd, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.58 KB | None | 0 0
  1. import React, { Component, Fragment } from 'react'
  2. import moment from 'moment'
  3. import Countdown from 'react-countdown-moment'
  4. import { BASE_URL, getActualRibbons } from 'src/service'
  5. import share from 'src/assets/svg/shareInverted.svg'
  6. import timer from 'src/assets/svg/timer.svg'
  7. import DisabledContent from './DisabledContent'
  8. import HeartButton from './HeartButton'
  9. import SaveButton from './SaveButton'
  10. import Indicator from './Indicator'
  11.  
  12. import {
  13. StyledProgress,
  14. StyledTag,
  15. StyledShareLink,
  16. StyledDealScoreInfo,
  17. RibbonContainer,
  18. Wrapper,
  19. BluredWrapper,
  20. Blured,
  21. Button,
  22. Root,
  23. Header,
  24. Figure,
  25. ProductImage,
  26. StoreName,
  27. Reviews,
  28. Indicators,
  29. Warning,
  30. Heading,
  31. Price,
  32. NewPrice,
  33. OldPrice,
  34. Timer,
  35. TimerValue,
  36. Footer,
  37. Row,
  38. Icon,
  39. Info,
  40. Action,
  41. Circle,
  42. StyledStar,
  43. Slashed,
  44. Percentage,
  45. } from './DealCard.styled'
  46.  
  47. class DealCard extends Component {
  48. render() {
  49. const { data, type, disable, className } = this.props
  50. const now = moment()
  51. const endDate = moment(data.available_till).add(2, 'hours')
  52. const content = (
  53. <Fragment>
  54. <Root type={type} disable={disable} className={className}>
  55. {data.score > 50 && (
  56. <Fragment>
  57. <StyledProgress
  58. type="circle"
  59. percent={data.score}
  60. format={(percent) => `${percent} `}
  61. />
  62. <Circle background={data.score} />
  63. <StyledDealScoreInfo background={data.score} />
  64. </Fragment>
  65. )}
  66. <RibbonContainer>
  67. {getActualRibbons(data.tags).map((tag, index) => (
  68. <StyledTag key={tag.name} color={tag.color} index={`${index * 28}px`}>
  69. {tag.name}
  70. </StyledTag>
  71. ))}
  72. {/* {type === 'violet' && <Ribbon type="violet">Rare!</Ribbon>}
  73. <Ribbon type="red">Best. Price. Ever.</Ribbon> */}
  74. </RibbonContainer>
  75. <Header>
  76. <a href={data.url} target="_blank" rel="noopener noreferrer">
  77. <Figure>
  78. <ProductImage src={data.image} />
  79. </Figure>
  80. <Reviews>
  81. {data.store_logo_url ? <StoreName src={BASE_URL + data.store_logo_url} /> : <div />}
  82. <Indicators>
  83. {data.is_low_stock && (
  84. <Indicator content="This item may go out of stock soon" border="1">
  85. <Warning>!</Warning>
  86. </Indicator>
  87. )}
  88.  
  89. {data.best_selling && (
  90. <Indicator content={data.best_selling.label} border="2">
  91. <StyledStar rate={data.best_selling.score} />
  92. </Indicator>
  93. )}
  94. </Indicators>
  95. </Reviews>
  96. <Heading>{data.name}</Heading>
  97. <Row>
  98. <Price>
  99. {data.price && <NewPrice>${data.price.toFixed(2)}</NewPrice>}
  100.  
  101. <Slashed>
  102. {data.discount && (
  103. <Fragment>
  104. <Percentage>{data.discount} off</Percentage>
  105. <OldPrice>${data.msrp.toFixed(2)}</OldPrice>
  106. </Fragment>
  107. )}
  108. </Slashed>
  109. </Price>
  110. {endDate.diff(now) > 0 && (
  111. <Timer>
  112. <Icon src={timer} />
  113. <TimerValue>
  114. <Countdown endDate={endDate} />
  115. </TimerValue>
  116. </Timer>
  117. )}
  118. </Row>
  119. </a>
  120. </Header>
  121. <Footer>
  122. <a href={data.url} target="_blank" rel="noopener noreferrer">
  123. <Button>Check it out</Button>
  124. </a>
  125. <Row>
  126. <Action>
  127. <HeartButton data={data} />
  128. </Action>
  129. <Action>
  130. <SaveButton />
  131. </Action>
  132. <StyledShareLink to={`/deals/${data.id}`}>
  133. <Action>
  134. <Icon src={share} />
  135. <Info>Share</Info>
  136. </Action>
  137. </StyledShareLink>
  138. </Row>
  139. </Footer>
  140. </Root>
  141. </Fragment>
  142. )
  143. return disable ? (
  144. <BluredWrapper>
  145. <Blured>{content}</Blured>
  146. <DisabledContent />
  147. </BluredWrapper>
  148. ) : (
  149. <Wrapper>{content}</Wrapper>
  150. )
  151. }
  152. }
  153.  
  154. export default DealCard
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement