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.
 
 

95 line
2.9 KiB

  1. import React from "react";
  2. import classNames from "classnames";
  3. import { makeStyles } from "@material-ui/core/styles";
  4. import Header from "components/Header/Header.js";
  5. import HeaderLinks from "components/Header/HeaderLinks.js";
  6. import Footer from "components/Footer/Footer.js";
  7. import OrderProduct from "pages-sections/yamaha/order/order.js";
  8. import Parallax from "components/Parallax/Parallax.js";
  9. import styles from "assets/jss/nextjs-material-kit/pages/components.js";
  10. import GetTransaction from "api/transaction/transaction.js";
  11. import Cookies from "cookies";
  12. const useStyles = makeStyles(styles);
  13. const Order = function ({ user, order, unpaid, prepared, sending, finished, backend, ...props }) {
  14. const classes = useStyles();
  15. const { ...rest } = props;
  16. return (
  17. <div>
  18. <Header
  19. rightLinks={<HeaderLinks username={user} />}
  20. fixed
  21. color="info"
  22. changeColorOnScroll={{
  23. height: 400,
  24. color: "white"
  25. }}
  26. {...rest}
  27. />
  28. <Parallax image={require("assets/img/Promotion_2-1.jpg")} width="200px"/>
  29. <div className={classNames(classes.main, classes.mainRaised)}>
  30. <OrderProduct order={order} unpaid={unpaid} prepared={prepared} sending={sending} finished={finished} backend={backend}/>
  31. </div>
  32. <Footer />
  33. </div>
  34. );
  35. }
  36. export default Order;
  37. export async function getServerSideProps(context) {
  38. var order = [];
  39. var res = await GetTransaction.getTransaction();
  40. if (res["STATUS"] === 1) {
  41. order = res["DATA"]["transactions"];
  42. }
  43. var unpaid = [];
  44. var res = await GetTransaction.getTransactionUnpaid();
  45. if (res["STATUS"] === 1) {
  46. unpaid = res["DATA"]["transactions"];
  47. }
  48. var prepared = [];
  49. var res = await GetTransaction.getTransactionPrepared();
  50. if (res["STATUS"] === 1) {
  51. prepared = res["DATA"]["transactions"];
  52. }
  53. var sending = [];
  54. var res = await GetTransaction.getTransactionSending();
  55. if (res["STATUS"] === 1) {
  56. sending = res["DATA"]["transactions"];
  57. }
  58. var finished = [];
  59. var res = await GetTransaction.getTransactionFinished();
  60. if (res["STATUS"] === 1) {
  61. finished = res["DATA"]["transactions"];
  62. }
  63. //backend
  64. const backend = process.env.BACKEND_SERVER_URI;
  65. //user
  66. var { req, resp } = context;
  67. const cookies = new Cookies(req, resp);
  68. var user = "";
  69. var userObj = (await cookies.get("user"))
  70. ? JSON.parse(await cookies.get("user"))
  71. : null;
  72. if (userObj) {
  73. let sessionId = userObj["partners_login_states"].filter(function (i) {
  74. return (
  75. i.business_partner && i.business_partner.name.toUpperCase() == "YAMAHA"
  76. );
  77. });
  78. if (sessionId.length != 0) user = userObj["username"];
  79. }
  80. return {
  81. props: { backend, user, unpaid, prepared, sending, finished, order, }, // will be passed to the page component as props
  82. };
  83. }