You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.5 KiB

  1. import React from 'react';
  2. import Navbar from "@/components/_App/NavbarYamaha";
  3. import Footer from "@/components/_App/FooterYamaha";
  4. import ProductCard from '@/components/Yamaha/Product/Motor_Detail';
  5. import GetDetailproduct from "api/product/product.js"
  6. import Cookies from "cookies";
  7. const Shop = function ({ detailproduct, backend, user, ...props }) {
  8. return (
  9. <>
  10. <Navbar username={user} />
  11. <ProductCard detailproduct={detailproduct} backend={backend} user={user}/>
  12. <Footer />
  13. </>
  14. )
  15. }
  16. export default Shop;
  17. export async function getServerSideProps(context) {
  18. var {query} = context;
  19. var detailproduct = [];
  20. const backend = process.env.BACKEND_SERVER_URI;
  21. var { req, resp } = context;
  22. const cookies = new Cookies(req, resp);
  23. var user = "";
  24. var userObj = (await cookies.get("user"))
  25. ? JSON.parse(await cookies.get("user"))
  26. : null;
  27. if (userObj) {
  28. let sessionId = userObj["partners_login_states"].filter(function (i) {
  29. return (
  30. i.business_partner && i.business_partner.name.toUpperCase() == "YAMAHA"
  31. );
  32. });
  33. if (sessionId.length != 0) user = userObj["username"];
  34. }
  35. var res = await GetDetailproduct.GetDetailProduct(query.s||0);
  36. if (res["STATUS"] === 1) {
  37. detailproduct = res["DATA"]["products"];
  38. }
  39. return {
  40. props: {
  41. detailproduct, backend, user,
  42. }, // will be passed to the page component as props
  43. };
  44. }