Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // containers/subcategory/SubCategory.jsx
- /* eslint-disable no-nested-ternary */
- import React, { Component, Fragment } from 'react';
- import { withRouter } from 'next/router';
- import { connect } from 'react-redux';
- import Link from 'next/link';
- import Breadcrumb from '@components/Breadcrumb';
- import { fetchData } from '@actions/sub-category.action';
- import { UncontrolledTooltip } from 'reactstrap';
- import ListingPrimaryProduct from './ListingPrimaryProduct';
- const queryString = require('query-string');
- // const Picture = ({ path }) => (
- // <div
- // className="mx-auto"
- // style={{
- // width: '60px',
- // height: '60px',
- // backgroundImage: `url('${path || ''}')`,
- // backgroundSize: 'cover',
- // backgroundPosition: 'center'
- // }}
- // />
- // );
- // const Category = ({ item, pathArray }) => (
- // <Link
- // href="/subcategory/SubCategory"
- // as={`/subcategory/id/${item.id}&path=${JSON.stringify([
- // ...pathArray,
- // { id: item.id, name: item.name }
- // ])}`}
- // key={item.id}
- // >
- // <div className="product-listing mt-5 mr-2">
- // <div className="thumb-wrapper w-100">
- // {item.picture && <Picture path={item.picture.path} />}
- // </div>
- // <div className="desc">{item.name}</div>
- // </div>
- // </Link>
- // );
- // const Product = ({ item, pathArray, data, dataCount }) => (
- // <Fragment key={item.id}>
- // {item.secondary === null && (
- // <Link
- // href="/primary-product/PrimaryProduct"
- // as={`/primary-product/id/${item.id}&path=${JSON.stringify([
- // ...pathArray,
- // { id: item.id, name: item.name }
- // ])}`}
- // key={item.id}
- // >
- // <div className="product-wrapper">
- // <div className="product-listing mt-5 mr-2 mx-auto">
- // <div className="thumb-wrapper w-100">
- // <Picture path={item.banner} />
- // </div>
- // <div className="desc">{item.name}</div>
- // </div>
- // </div>
- // </Link>
- // )}
- // {item.secondary !== null && dataCount < 2 ? (
- // <ListingPrimaryProduct data={data} retItem={item} />
- // ) : (
- // <Link
- // href="/primary-product/PrimaryProduct"
- // as={`/primary-product/id/${item.id}`}
- // key={item.id}
- // >
- // <div className="product-wrapper">
- // <div className="product-listing mt-5 mr-2 mx-auto">
- // <div className="thumb-wrapper w-100">
- // <Picture path={item.banner} />
- // </div>
- // <div className="desc">{item.name}</div>
- // </div>
- // </div>
- // </Link>
- // )}
- // </Fragment>
- // );
- class SubCategory extends Component {
- constructor(props) {
- super(props);
- const { router } = this.props;
- // const parsed = queryString.parse(router.asPath);
- // const pathArray = JSON.parse(parsed.path);
- let pathArray = null;
- let pathString = null;
- // get localstorage
- if (process.browser) {
- pathArray = JSON.parse(localStorage.getItem('path') || null);
- pathString = JSON.stringify(pathArray);
- }
- this.state = {
- pathArray,
- pathString
- };
- }
- componentDidMount() {
- const { pathString } = this.state;
- const { fetchData, router } = this.props;
- const id = router.query.id;
- setTimeout(() => {
- fetchData({
- id,
- path: pathString
- });
- }, 500);
- // console.log('id', id);
- // console.log('pathString', pathString);
- }
- render() {
- const { pathArray } = this.state;
- const { data } = this.props;
- const dataCount = data.product && data.product.length;
- const dataAllProduct = data.all_product && data.all_product.length;
- // console.log('data', data);
- console.log('dataAll', dataAllProduct);
- // console.log('pathArray', pathArray);
- return (
- <div id="page-content-wrapper" className="pl-3 pr-3 w-100">
- {/* <Breadcrumb /> */}
- <div className="container-fluid">
- <div className="row">
- <div className="col-md-12">
- <span className="d-block">
- About {data.meta && data.meta.name}
- </span>
- <span className="d-block text-dark">
- <i className="fa fa-caret-right pr-2 text-warning" />
- {data.meta && data.meta.name}
- </span>
- </div>
- </div>
- <div className="d-flex flex-wrap" style={{ cursor: 'pointer' }}>
- {/* WHEN FILTER ON */}
- {data.all_product === null &&
- data.category &&
- data.category.map(item => (
- <Link
- href="/subcategory/SubCategory"
- as={`/subcategory/id/${item.id}&path=${JSON.stringify([
- ...pathArray,
- { id: item.id, name: item.name }
- ])}`}
- key={item.id}
- >
- <div className="product-listing mt-5 mr-2">
- <div
- className="thumb-wrapper w-100"
- id={`Tooltip-${item.id}`}
- >
- {item.picture && (
- <>
- <div
- className="mx-auto"
- style={{
- width: '60px',
- height: '60px',
- backgroundImage: `url('${item.picture.path ||
- ''}')`,
- backgroundSize: 'cover',
- backgroundPosition: 'center'
- }}
- />
- </>
- )}
- </div>
- <UncontrolledTooltip
- innerClassName="mc-tooltip"
- placement="top"
- target={`Tooltip-${item.id}`}
- >
- {item.description}
- </UncontrolledTooltip>
- <div className="desc">{item.name}</div>
- </div>
- </Link>
- ))}
- {/* WHEN CATEGORY NOT NULL */}
- {data.category !== null ? (
- <>
- {/* WHEN FILTER OFF */}
- {data.all_product === null
- ? data.product &&
- data.product.map(item => (
- <React.Fragment key={item.id}>
- {item.secondary === null ? (
- <Link
- href="/primary-product/PrimaryProduct"
- as={`/primary-product/id/${
- item.id
- }&path=${JSON.stringify([
- ...pathArray,
- { id: item.id, name: item.name }
- ])}`}
- key={item.id}
- >
- <div className="product-wrapper">
- <div className="product-listing mt-5 mr-2 mx-auto">
- <div className="thumb-wrapper w-100">
- <div
- className="mx-auto"
- style={{
- width: '60px',
- height: '60px',
- backgroundImage: `url('${item.banner ||
- ''}')`,
- backgroundSize: 'cover',
- backgroundPosition: 'center'
- }}
- />
- </div>
- <div className="desc">{item.name}</div>
- </div>
- </div>
- </Link>
- ) : item.secondary !== null && dataCount < 2 ? (
- <ListingPrimaryProduct data={data} retItem={item} />
- ) : (
- <Link
- href="/primary-product/PrimaryProduct"
- as={`/primary-product/id/${
- item.id
- }&path=${JSON.stringify([
- ...pathArray,
- { id: item.id, name: item.name }
- ])}`}
- key={item.id}
- >
- <div className="product-wrapper">
- <div className="product-listing mt-5 mr-2 mx-auto">
- <div className="thumb-wrapper w-100">
- <div
- className="mx-auto"
- style={{
- width: '60px',
- height: '60px',
- backgroundImage: `url('${item.banner ||
- ''}')`,
- backgroundSize: 'cover',
- backgroundPosition: 'center'
- }}
- />
- </div>
- <div className="desc">{item.name}</div>
- </div>
- </div>
- </Link>
- )}
- </React.Fragment>
- ))
- : // WHEN FILTER ON
- data.all_product &&
- data.all_product.map(item => (
- <React.Fragment key={item.id}>
- {item.secondary === null ? (
- <Link
- href="/primary-product/PrimaryProduct"
- as={`/primary-product/id/${
- item.id
- }&path=${JSON.stringify([
- ...pathArray,
- { id: item.id, name: item.name }
- ])}`}
- key={item.id}
- >
- <div className="product-wrapper">
- <div className="product-listing mt-5 mr-2 mx-auto">
- <div className="thumb-wrapper w-100">
- <div
- className="mx-auto"
- style={{
- width: '60px',
- height: '60px',
- backgroundImage: `url('${item.banner ||
- ''}')`,
- backgroundSize: 'cover',
- backgroundPosition: 'center'
- }}
- />
- </div>
- <div className="desc">{item.name}</div>
- </div>
- </div>
- </Link>
- ) : item.secondary !== null && dataAllProduct < 3 ? (
- <ListingPrimaryProduct data={data} retItem={item} />
- ) : (
- <Link
- href="/primary-product/PrimaryProduct"
- as={`/primary-product/id/${
- item.id
- }&path=${JSON.stringify([
- ...pathArray,
- { id: item.id, name: item.name }
- ])}`}
- key={item.id}
- >
- <div className="product-wrapper">
- <div className="product-listing mt-5 mr-2 mx-auto">
- <div className="thumb-wrapper w-100">
- <div
- className="mx-auto"
- style={{
- width: '60px',
- height: '60px',
- backgroundImage: `url('${item.banner ||
- ''}')`,
- backgroundSize: 'cover',
- backgroundPosition: 'center'
- }}
- />
- </div>
- <div className="desc">{item.name}</div>
- </div>
- </div>
- </Link>
- )}
- </React.Fragment>
- ))}
- </>
- ) : data.category === null ? (
- <>
- {/* WHEN FILTER OFF */}
- {data.all_product === null
- ? data.product &&
- data.product.map(item => (
- <>
- {dataCount < 3 ? (
- <ListingPrimaryProduct data={data} retItem={item} />
- ) : (
- <Link
- href="/primary-product/PrimaryProduct"
- as={`/primary-product/id/${
- item.id
- }&path=${JSON.stringify([
- ...pathArray,
- { id: item.id, name: item.name }
- ])}`}
- key={item.id}
- >
- <div className="product-wrapper">
- <div className="product-listing mt-5 mr-2 mx-auto">
- <div className="thumb-wrapper w-100">
- <div
- className="mx-auto"
- style={{
- width: '60px',
- height: '60px',
- backgroundImage: `url('${item.banner ||
- ''}')`,
- backgroundSize: 'cover',
- backgroundPosition: 'center'
- }}
- />
- </div>
- <div className="desc">{item.name}</div>
- </div>
- </div>
- </Link>
- )}
- </>
- ))
- : // WHEN FILTER ON
- data.all_product &&
- data.all_product.map(item => (
- <>
- {dataAllProduct < 3 ? (
- <ListingPrimaryProduct data={data} retItem={item} />
- ) : (
- <Link
- href="/primary-product/PrimaryProduct"
- as={`/primary-product/id/${
- item.id
- }&path=${JSON.stringify([
- ...pathArray,
- { id: item.id, name: item.name }
- ])}`}
- key={item.id}
- >
- <div className="product-wrapper">
- <div className="product-listing mt-5 mr-2 mx-auto">
- <div className="thumb-wrapper w-100">
- <div
- className="mx-auto"
- style={{
- width: '60px',
- height: '60px',
- backgroundImage: `url('${item.banner ||
- ''}')`,
- backgroundSize: 'cover',
- backgroundPosition: 'center'
- }}
- />
- </div>
- <div className="desc">{item.name}</div>
- </div>
- </div>
- </Link>
- )}
- </>
- ))}
- </>
- ) : (
- <div>no datas</div>
- )}
- </div>
- </div>
- </div>
- );
- }
- }
- const mapStateToProps = state => ({
- data: state.subcategory.data
- });
- export default connect(mapStateToProps, { fetchData })(withRouter(SubCategory));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement