|
- import React from "react";
- import Header from "@/components/Company/Header";
- import Footer from "@/components/Company/Footer";
- import PageBanner from "@/components/Common/PageBanner";
- import ProductCard from "@/components/Common/new/UnitList";
-
- import Products from "@/api/new/product";
- import Company from "@/api/new/company";
-
- import Cookies from "cookies";
- import { QueryClient, QueryClientProvider, useQuery } from 'react-query'
-
- import Router from 'next/router'
- import { Search } from "react-feather";
-
- const queryClient = new QueryClient();
- const handleName = values => {
- Router.push({
- pathname: '/yamaha/Product/Motor',
- query: (values&&values.length!=0)?{ filter: values[0]["name"] }:{},
- })
- }
-
- const Shop = function ({ companyData,company,total,page,pageCount,icon,desc,sosmed,selected, products, backend, user, ...props }) {
- return (
- <>
- <QueryClientProvider client={queryClient}>
-
- <Header company={company} icon={icon}/>
-
- <PageBanner pageTitle="Products" />
-
- <ProductCard company={company} total={total} current={page} pages={pageCount} handleName={handleName} product={products} />
-
- <Footer company={companyData} info={desc} social={sosmed} icon={icon}/>
-
- </QueryClientProvider>
- </>
- );
- };
-
- export default Shop;
-
- export async function getServerSideProps(context) {
- var companyName = process.env.NEXT_PUBLIC_COMPANY;
- var page = context.query.p||1;
- var props = {};
- try{var res = await Company.companyByName(companyName);
- if (res["STATUS"] === 1) {
- props["icon"] = res["DATA"]["companies"].data[0].attributes.Icon.data.attributes.url;
- props["companyData"] =res["DATA"]["companies"].data[0].attributes;
- props["desc"] = res["DATA"]["companies"].data[0].attributes.Description;
- props["sosmed"] = res["DATA"]["companies"].data[0].attributes.Social_Medias.data;
- }
- var products = await Products.GetProduct(res["DATA"]["companies"].data[0].id,'Unit',8,page);
- if(products['STATUS']==1){
- props["products"]= products["DATA"].products.data;
- props["pageCount"] = products["DATA"].products.meta.pagination.pageCount;
- props["total"] = products["DATA"].products.meta.pagination.total;
- }
- props["company"] = companyName;
- props["page"] = page;}catch(e){};
- return {props};
- // var product = [];
- // const backend = process.env.BACKEND_SERVER_URI;
- // var filter = context.query.filter||"";
- // var selected = "";
-
- // var { req, resp } = context;
- // const cookies = new Cookies(req, resp);
- // var user = "";
- // var userObj = (await cookies.get("user"))
- // ? JSON.parse(await cookies.get("user"))
- // : null;
- // if (userObj) {
- // let sessionId = userObj["partners_login_states"].filter(function (i) {
- // return (
- // i.business_partner &&
- // i.business_partner.name.toUpperCase() == "YAMAHA"
- // );
- // });
- // if (sessionId.length != 0) user = userObj["username"];
- // }
- // var res = await Getproduct.GetProduct(filter);
- // if (res["STATUS"] === 1) {
- // product = res["DATA"]["products"];
- // if (filter !=""){
- // selected = product.filter((i)=>i.name==filter);
- // }
-
- // }
-
- // return {
- // props: {
- // selected,
- // product,
- // backend,
- // user,
- // }, // will be passed to the page component as props
- // };
- }
|