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.

61 lines
1.6 KiB

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