Guest User

Untitled

a guest
Jun 11th, 2020
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { useState, useEffect } from 'react';
  2. import { useParams } from 'react-router';
  3. import Tabs from '../Components/Tabs/Tabs';
  4. import Chart from '../Components/Chart/Chart';
  5.  
  6. const ProductView = (props) => {
  7.   const [product, setProduct] = useState({});
  8.   const { id } = useParams();
  9.  
  10.   const options = {
  11.     title: {
  12.       text: 'My stock chart',
  13.     },
  14.     series: [
  15.       {
  16.         data: [1,2,3,4,5,6],
  17.       },
  18.     ],
  19.   };
  20.  
  21.   var data = [
  22.     {
  23.       id: '1',
  24.       tabTitle: 'Product details',
  25.       tabContent: 'Some details about product',
  26.     },
  27.     {
  28.       id: '2',
  29.       tabTitle: 'Price history',
  30.       tabContent: <Chart options={options} />,
  31.     },
  32.     {
  33.       id: '3',
  34.       tabTitle: 'Quantity History',
  35.       tabContent: <Chart options={options} />,
  36.     },
  37.   ];
  38.  
  39.   useEffect(() => {
  40.     let productFromLocalStorage = localStorage.getItem(id);
  41.     setProduct(JSON.parse(productFromLocalStorage));
  42.   }, [id]);
  43.  
  44.   return (
  45.     <div style={styles.container}>
  46.       <h1 style={styles.title}>Product {product.name} View Page</h1>
  47.       {console.log(product.priceHistory)}
  48.       <Table product={product} />
  49.       <Tabs data={data} />
  50.     </div>
  51.   );
  52. };
  53.  
  54. const Table = (props) => {
  55.   return (
  56.     <table style={styles.table}>
  57.       <TableTitles></TableTitles>
  58.       <TableValues product={props.product}></TableValues>
  59.     </table>
  60.   );
  61. };
  62.  
  63. const TableValues = (props) => {
  64.   return (
  65.     <tr>
  66.       {Object.values(props.product).map((val, index) => {
  67.         if (index < 8) {
  68.           return <td style={styles.tableItem}>{val}</td>;
  69.         }
  70.       })}
  71.     </tr>
  72.   );
  73. };
  74.  
  75. const TableTitles = (props) => {
  76.   return (
  77.     <tr>
  78.       <th style={styles.tableItem}>Name</th>
  79.       <th style={styles.tableItem}>EAN</th>
  80.       <th style={styles.tableItem}>Type</th>
  81.       <th style={styles.tableItem}>Weight</th>
  82.       <th style={styles.tableItem}>Color</th>
  83.       <th style={styles.tableItem}>Price</th>
  84.       <th style={styles.tableItem}>Quantity</th>
  85.       <th style={styles.tableItem}>Active</th>
  86.     </tr>
  87.   );
  88. };
  89.  
  90. const styles = {
  91.   container: {
  92.     display: 'flex',
  93.     flexDirection: 'column',
  94.     alignItems: 'center',
  95.   },
  96.   title: {
  97.     color: 'gray',
  98.     fontWeight: '600',
  99.   },
  100.   table: {
  101.     border: '1px solid black',
  102.     borderCollapse: 'collapse',
  103.     padding: '20px',
  104.     margin: '10px',
  105.   },
  106.   tableItem: {
  107.     border: '1px solid black',
  108.     borderCollapse: 'collapse',
  109.     padding: '10px',
  110.   },
  111. };
  112.  
  113. export default ProductView;
Advertisement
Add Comment
Please, Sign In to add comment