vademecum-domiciliario.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. const dom = React.createElement;
  2. const LABEL = 0,
  3. TAG = 1;
  4. const Tag = (label, key, className) => (
  5. <span className={`tag ${className||''}`} key={key}>{label}</span>
  6. );
  7. const Product = (product, withPrice) => (
  8. <div className="container sell-product-container">
  9. <div className="columns">
  10. <div className="column is-2">
  11. <img src={`images/_img/${product.variants[0].img || 'not-found'}.png`}/>
  12. </div>
  13. <div className="column is-8">
  14. <h4>{ product.name }</h4>
  15. <p>{ product.shortDesc || product.fullDesc}</p>
  16. <div className="tags">
  17. {
  18. product.ph && Tag(`PH ${product.ph}`, null, 'is-ph')
  19. }
  20. {
  21. product.actives.map(a => Tag(a))
  22. }
  23. </div>
  24. </div>
  25. <div className="column is-2">
  26. <div className="price-tag">
  27. <h5>
  28. <span className="price-symbol">$</span>
  29. <span className="price-total">{product.variants[0].sellPrice}</span>
  30. <sup className="price-decimal">00</sup>
  31. </h5>
  32. </div>
  33. <div className="product-size">Cont. {product.variants[0].content}</div>
  34. </div>
  35. </div>
  36. </div>
  37. );
  38. const ProductList = (products, categories) => (
  39. <div>
  40. {
  41. categories.map(category => (
  42. <table id={category[TAG]} className="domi-prod">
  43. <thead>
  44. <tr><th>
  45. <h2 className="domi-h2">{category[LABEL]}</h2>
  46. </th></tr>
  47. </thead>
  48. <tbody>
  49. {
  50. products[category[LABEL]].map(product => (
  51. <tr><td>
  52. { Product(product) }
  53. </td></tr>
  54. ))
  55. }
  56. </tbody>
  57. </table>
  58. ))
  59. }
  60. </div>
  61. );
  62. class VademecumDomiciliario extends React.Component {
  63. constructor(props) {
  64. super(props);
  65. this.state = {
  66. categories: [
  67. [ "Higiene", "higiene" ],
  68. [ "Ácido Hialurónico", "acido-hialuronico" ],
  69. [ "Corporales", "corporales" ],
  70. [ "Hombres", "hombres" ],
  71. [ "Protección Intensiva", "proteccion-intensiva" ],
  72. [ "Monodosis", "monodosis" ],
  73. [ "Protección Solar", "proteccion-solar" ]
  74. ],
  75. products: null,
  76. }
  77. }
  78. componentDidMount() {
  79. fetch('data/products-by-category.json')
  80. .then(response => response.json())
  81. .then(data => {
  82. const categories = Object.keys(data);
  83. return categories.reduce((products, categoryName) => {
  84. const filtered = data[categoryName].filter(product => {
  85. const valid = product.variants.filter(v => v.code < 2000);
  86. return valid.length || product.category.includes('Protección Solar'); // Sunscreens are also required for this Vademecum
  87. });
  88. return {
  89. ...products,
  90. [categoryName]: filtered
  91. }
  92. }, {})
  93. })
  94. .then(data => {
  95. this.setState({
  96. products: data,
  97. })
  98. })
  99. }
  100. render() {
  101. const { categories, products } = this.state;
  102. if (products) {
  103. return (
  104. <div>
  105. { ProductList(products, categories) }
  106. </div>
  107. )
  108. } else {
  109. return (<div></div>);
  110. }
  111. }
  112. }
  113. const domContainer = document.querySelector('#vademecum-domiciliario');
  114. ReactDOM.render(React.createElement(VademecumDomiciliario), domContainer);