vademecum-domiciliario.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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-10">
  11. <h4>{ product.name }</h4>
  12. <p>{ product.shortDesc || product.fullDesc}</p>
  13. <div className="tags">
  14. {
  15. product.ph && Tag(`PH ${product.ph}`, null, 'is-ph')
  16. }
  17. {
  18. product.actives.map(a => Tag(a))
  19. }
  20. </div>
  21. </div>
  22. <div className="column is-2">
  23. <div className="price-tag">
  24. <h5>
  25. <span className="price-symbol">$</span>
  26. <span className="price-total">{product.variants[0].sellPrice}</span>
  27. <sup className="price-decimal">00</sup>
  28. </h5>
  29. </div>
  30. <div className="product-size">Cont. {product.variants[0].content}</div>
  31. </div>
  32. </div>
  33. </div>
  34. );
  35. const ProductList = (products, categories) => (
  36. <div>
  37. {
  38. categories.map(category => (
  39. <table id={category[TAG]}>
  40. <thead>
  41. <tr><th>
  42. <h2>{category[LABEL]}</h2>
  43. </th></tr>
  44. </thead>
  45. <tbody>
  46. {
  47. products[category[LABEL]].map(product => (
  48. <tr><td>
  49. { Product(product) }
  50. </td></tr>
  51. ))
  52. }
  53. </tbody>
  54. </table>
  55. ))
  56. }
  57. </div>
  58. );
  59. class VademecumDomiciliario extends React.Component {
  60. constructor(props) {
  61. super(props);
  62. this.state = {
  63. categories: [
  64. [ "Higiene", "higiene" ],
  65. [ "Ácido Hialurónico", "acido-hialuronico" ],
  66. [ "Corporales", "corporales" ],
  67. [ "Hombres", "hombres" ],
  68. [ "Protección Intensiva", "proteccion-intensiva" ],
  69. [ "Monodosis", "monodosis" ],
  70. [ "Activos Concentrados", "activos-concentrados" ],
  71. [ "Protección Solar", "proteccion-solar" ]
  72. ],
  73. products: null,
  74. }
  75. }
  76. componentDidMount() {
  77. fetch('data/products-home.json')
  78. .then(response => response.json())
  79. .then(data => {
  80. this.setState({
  81. products: data,
  82. })
  83. })
  84. }
  85. render() {
  86. const { categories, products } = this.state;
  87. if (products) {
  88. return (
  89. <div>
  90. { ProductList(products, categories) }
  91. </div>
  92. )
  93. } else {
  94. return (<div></div>);
  95. }
  96. }
  97. }
  98. const domContainer = document.querySelector('#vademecum-domiciliario');
  99. ReactDOM.render(React.createElement(VademecumDomiciliario), domContainer);