From a5fc614c920f928d2a8629fb06edd0cdbac52eab Mon Sep 17 00:00:00 2001 From: yusmar Date: Tue, 9 Nov 2021 13:27:54 +0700 Subject: [PATCH] fixed login --- components/Sales/Sales_Detail.js | 10 +-- components/Yamaha/Login.js | 68 ++++++++++++++++++++ components/Yamaha/Shop/Checkout.js | 99 ++++++++++++----------------- components/_App/NavbarYamaha.js | 89 ++++++++++++++++---------- pages/yamaha/AboutUs/index.js | 23 ++++++- pages/yamaha/ContactUs/index.js | 28 +++++++- pages/yamaha/LatestNews/LatestNewsDetail.js | 23 ++++++- pages/yamaha/LatestNews/index.js | 23 ++++++- pages/yamaha/Product/Accessories_Detail.js | 2 +- pages/yamaha/Product/Apparel_Detail.js | 2 +- pages/yamaha/Product/Helmet_Detail.js | 2 +- pages/yamaha/Product/Motor.js | 2 +- pages/yamaha/Product/Motor_Detail.js | 2 +- pages/yamaha/Product/Sparepart.js | 20 +++++- pages/yamaha/Product/Yamalube_Detail.js | 2 +- pages/yamaha/Product/Ygp_Detail.js | 6 +- pages/yamaha/Shop/Cart.js | 24 +++++-- pages/yamaha/Shop/Checkout.js | 25 ++++++-- pages/yamaha/index.js | 4 +- 19 files changed, 326 insertions(+), 128 deletions(-) create mode 100644 components/Yamaha/Login.js diff --git a/components/Sales/Sales_Detail.js b/components/Sales/Sales_Detail.js index dc44721..73f7557 100644 --- a/components/Sales/Sales_Detail.js +++ b/components/Sales/Sales_Detail.js @@ -2,7 +2,9 @@ import React from 'react'; import Link from 'next/link'; import * as Icon from 'react-feather'; -// import FaWhatsapp from "react-icons/fa"; +import { FaWhatsapp } from "react-icons/fa"; +import { FaRegEnvelope } from "react-icons/fa"; +import { FaPhoneAlt } from "react-icons/fa"; const Sales = function ({ backend, sales, ...props }) { @@ -27,13 +29,13 @@ const Sales = function ({ backend, sales, ...props }) {
- Call Us + Call Us - Email Us + Email Us - WA Us + WA Us

diff --git a/components/Yamaha/Login.js b/components/Yamaha/Login.js new file mode 100644 index 0000000..6ddd181 --- /dev/null +++ b/components/Yamaha/Login.js @@ -0,0 +1,68 @@ +import React from 'react'; +import Link from 'next/link'; +import * as Icon from 'react-feather'; + +const Login = function ({ backend, dealers, ...props }) { + return ( +
+
+
+
+ logo +

+

Tidak Punya Akun ? Silahkan Register

+
+ +
+
+ + setEmail(event.target.value), + }} + /> +
+ +
+ + setPass(event.target.value), + type: "password", + autoComplete: "off", + }} + /> +
+ + + + +
+ +
+

or connect with

+ +
+
+
+
+ ); +} + +export default Login; \ No newline at end of file diff --git a/components/Yamaha/Shop/Checkout.js b/components/Yamaha/Shop/Checkout.js index 8b6490b..d71eb82 100644 --- a/components/Yamaha/Shop/Checkout.js +++ b/components/Yamaha/Shop/Checkout.js @@ -1,7 +1,17 @@ import React from 'react'; import * as Icon from 'react-feather'; - -const CheckoutContent = () => { + +//library yarn +import NumberFormat from 'react-number-format'; + +const CheckoutContent = function ({ backend, checkout_product, ...props }) { + + // const Checkout = checkout_product.map((data) => { + // return ( + + // ) + // }) + return ( <>
@@ -25,7 +35,7 @@ const CheckoutContent = () => {
- +
@@ -239,9 +220,9 @@ const CheckoutContent = () => {

-
+
*/} - Place Order + Lanjutkan Pembayaran
diff --git a/components/_App/NavbarYamaha.js b/components/_App/NavbarYamaha.js index bbd6bf1..a0dac49 100644 --- a/components/_App/NavbarYamaha.js +++ b/components/_App/NavbarYamaha.js @@ -117,15 +117,18 @@ export default function NavbarYamaha({ username, ...props }) { Contact + +
  • + + + + + +
  • - - - - - {!username || username == "" ? ( @@ -133,33 +136,55 @@ export default function NavbarYamaha({ username, ...props }) { Login ) : ( -
  • - - e.preventDefault()} className="nav-link"> - Product - - - - -
  • +
      +
    • + + e.preventDefault()} className="nav-link" > + {username} + + + +
        +
      • + + Profile + +
      • + +
      • + + Pesanan Saya + +
      • + +
      • +
        { + e.preventDefault(); + fetch("/api/auth/logout", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ p: "YAMAHA" }), + }).then((res) => { + //if (res.ok) { + window.location.href = "../yamaha"; + /*} + else{ + + }*/ + }); + }} + > + + Logout + +
        +
      • +
      +
    • +
    // - + @@ -32,12 +34,27 @@ export async function getServerSideProps(context) { news = res["DATA"]["latestNews"]; } + 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 GetLatestNews.GetOtherNewsYamaha(); if (res["STATUS"] === 1) { othernews = res["DATA"]["latestNews"]; } return { - props: { news, othernews, backend }, // will be passed to the page component as props + props: { news, othernews, backend, user }, // will be passed to the page component as props }; } \ No newline at end of file diff --git a/pages/yamaha/ContactUs/index.js b/pages/yamaha/ContactUs/index.js index a835bec..dbb9271 100644 --- a/pages/yamaha/ContactUs/index.js +++ b/pages/yamaha/ContactUs/index.js @@ -4,10 +4,12 @@ import Footer from "@/components/_App/FooterYamaha"; import PageBanner from '@/components/Common/PageBanner'; import ContactUs from '@/components/Yamaha/ContactUs/ContactUs'; -const Contact = () => { +import Cookies from "cookies"; + +const Contact = function ({ user, ...props }) { return ( <> - + @@ -18,4 +20,26 @@ const Contact = () => { ) } +export async function getServerSideProps(context) { + + 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"]; + } + + return { + props: { user }, // will be passed to the page component as props + }; +} + export default Contact; \ No newline at end of file diff --git a/pages/yamaha/LatestNews/LatestNewsDetail.js b/pages/yamaha/LatestNews/LatestNewsDetail.js index 4ddcafe..0515cff 100644 --- a/pages/yamaha/LatestNews/LatestNewsDetail.js +++ b/pages/yamaha/LatestNews/LatestNewsDetail.js @@ -6,10 +6,12 @@ import LatestNewsDetail from '@/components/Yamaha/LatestNews/LatestNewsDetail'; import GetLatestNews from "api/latest_news/news.js" -const NewsDetail = function ({ backend, news, othernews, ...props }) { +import Cookies from "cookies"; + +const NewsDetail = function ({ backend, news, othernews, user, ...props }) { return ( <> - + @@ -26,6 +28,21 @@ export async function getServerSideProps(context) { var othernews = []; const backend = process.env.BACKEND_SERVER_URI; + 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 GetLatestNews.GetDetailNews(query.s||0); if (res["STATUS"] === 1) { news = res["DATA"]["latestNews"]; @@ -37,6 +54,6 @@ export async function getServerSideProps(context) { } return { - props: { news, othernews, backend }, // will be passed to the page component as props + props: { news, othernews, backend, user }, // will be passed to the page component as props }; } \ No newline at end of file diff --git a/pages/yamaha/LatestNews/index.js b/pages/yamaha/LatestNews/index.js index ef79050..e8f4edb 100644 --- a/pages/yamaha/LatestNews/index.js +++ b/pages/yamaha/LatestNews/index.js @@ -6,10 +6,12 @@ import LatestNews from '@/components/Yamaha/LatestNews/LatestNews'; import GetLatestNews from "api/latest_news/news.js" -const News = function ({ backend, news, othernews, ...props }) { +import Cookies from "cookies"; + +const News = function ({ backend, news, othernews, user, ...props }) { return ( <> - + @@ -27,6 +29,21 @@ export async function getServerSideProps(context) { var othernews = []; const backend = process.env.BACKEND_SERVER_URI; + 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 GetLatestNews.GetNewsYamaha(); if (res["STATUS"] === 1) { news = res["DATA"]["latestNews"]; @@ -38,6 +55,6 @@ export async function getServerSideProps(context) { } return { - props: { news, othernews, backend }, // will be passed to the page component as props + props: { news, othernews, backend, user }, // will be passed to the page component as props }; } \ No newline at end of file diff --git a/pages/yamaha/Product/Accessories_Detail.js b/pages/yamaha/Product/Accessories_Detail.js index 617cdbb..964d6cf 100644 --- a/pages/yamaha/Product/Accessories_Detail.js +++ b/pages/yamaha/Product/Accessories_Detail.js @@ -10,7 +10,7 @@ import Cookies from "cookies"; const Shop = function ({ detailaccessories, backend, user, ...props }) { return ( <> - + diff --git a/pages/yamaha/Product/Apparel_Detail.js b/pages/yamaha/Product/Apparel_Detail.js index ea62e13..baff986 100644 --- a/pages/yamaha/Product/Apparel_Detail.js +++ b/pages/yamaha/Product/Apparel_Detail.js @@ -10,7 +10,7 @@ import Cookies from "cookies"; const Shop = function ({ detailapparel, backend, user, ...props }) { return ( <> - + diff --git a/pages/yamaha/Product/Helmet_Detail.js b/pages/yamaha/Product/Helmet_Detail.js index 9220fa5..af30da2 100644 --- a/pages/yamaha/Product/Helmet_Detail.js +++ b/pages/yamaha/Product/Helmet_Detail.js @@ -10,7 +10,7 @@ import Cookies from "cookies"; const Shop = function ({ detailhelmet, backend, user, ...props }) { return ( <> - + diff --git a/pages/yamaha/Product/Motor.js b/pages/yamaha/Product/Motor.js index beff594..1cd10b2 100644 --- a/pages/yamaha/Product/Motor.js +++ b/pages/yamaha/Product/Motor.js @@ -11,7 +11,7 @@ import Cookies from "cookies"; const Shop = function ({ product, backend, user, ...props }) { return ( <> - + diff --git a/pages/yamaha/Product/Motor_Detail.js b/pages/yamaha/Product/Motor_Detail.js index c810328..3da9f4d 100644 --- a/pages/yamaha/Product/Motor_Detail.js +++ b/pages/yamaha/Product/Motor_Detail.js @@ -10,7 +10,7 @@ import Cookies from "cookies"; const Shop = function ({ detailproduct, backend, user, ...props }) { return ( <> - + diff --git a/pages/yamaha/Product/Sparepart.js b/pages/yamaha/Product/Sparepart.js index 5da5a9d..a460352 100644 --- a/pages/yamaha/Product/Sparepart.js +++ b/pages/yamaha/Product/Sparepart.js @@ -8,10 +8,10 @@ import GetSparepart from "api/sparepart/sparepart.js"; import Cookies from "cookies"; -const Shop = function ({ ygp, yamalube, helmet, apparel, accessories, backend, ...props }) { +const Shop = function ({ ygp, yamalube, helmet, apparel, accessories, backend, user, ...props }) { return ( <> - + @@ -40,6 +40,21 @@ export async function getServerSideProps(context) { const backend = process.env.BACKEND_SERVER_URI; + 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 GetSparepart.GetSparepartYGP(); if (res["STATUS"] === 1) { ygp = res["DATA"]["ygParts"]; @@ -73,6 +88,7 @@ export async function getServerSideProps(context) { apparel, accessories, backend, + user, }, // will be passed to the page component as props }; } \ No newline at end of file diff --git a/pages/yamaha/Product/Yamalube_Detail.js b/pages/yamaha/Product/Yamalube_Detail.js index efc59fa..b22e5e8 100644 --- a/pages/yamaha/Product/Yamalube_Detail.js +++ b/pages/yamaha/Product/Yamalube_Detail.js @@ -10,7 +10,7 @@ import Cookies from "cookies"; const Shop = function ({ detailyamalube, backend, user, ...props }) { return ( <> - + diff --git a/pages/yamaha/Product/Ygp_Detail.js b/pages/yamaha/Product/Ygp_Detail.js index 530734c..451eabb 100644 --- a/pages/yamaha/Product/Ygp_Detail.js +++ b/pages/yamaha/Product/Ygp_Detail.js @@ -10,7 +10,7 @@ import Cookies from "cookies"; const Shop = function ({ detailygp, backend, user, ...props }) { return ( <> - + @@ -26,9 +26,7 @@ export async function getServerSideProps(context) { var detailygp = []; const backend = process.env.BACKEND_SERVER_URI; - - console.log("backend :", backend); - + var { req, resp } = context; const cookies = new Cookies(req, resp); var user = ""; diff --git a/pages/yamaha/Shop/Cart.js b/pages/yamaha/Shop/Cart.js index 0b56d54..f9c9640 100644 --- a/pages/yamaha/Shop/Cart.js +++ b/pages/yamaha/Shop/Cart.js @@ -5,12 +5,13 @@ import PageBanner from '@/components/Common/PageBanner' import CartContent from '@/components/Yamaha/Shop/Cart' import GetproductCart from 'api/shop/cart'; + import Cookies from "cookies"; -const Cart = function ({ cart_product, backend, ...props }) { +const Cart = function ({ cart_product, backend, user, ...props }) { return ( <> - + @@ -31,16 +32,31 @@ const Cart = function ({ cart_product, backend, ...props }) { export default Cart; -export async function getServerSideProps() { +export async function getServerSideProps(context) { var cart_product = []; const backend = process.env.BACKEND_SERVER_URI; + 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 GetproductCart.GetCartProduct(); if (res["STATUS"] === 1) { cart_product = res["DATA"]["carts"]; } return { - props: { cart_product, backend }, // will be passed to the page component as props + props: { cart_product, backend, user }, // will be passed to the page component as props }; } \ No newline at end of file diff --git a/pages/yamaha/Shop/Checkout.js b/pages/yamaha/Shop/Checkout.js index f0d57c5..ea91b5e 100644 --- a/pages/yamaha/Shop/Checkout.js +++ b/pages/yamaha/Shop/Checkout.js @@ -7,10 +7,12 @@ import * as Icon from 'react-feather'; import CheckoutProduct from "api/shop/checkout"; -const Checkout = function ({ backend, checkout_product, ...props }) { +import Cookies from "cookies"; + +const Checkout = function ({ backend, checkout_product, user, ...props }) { return ( <> - + @@ -23,10 +25,25 @@ const Checkout = function ({ backend, checkout_product, ...props }) { export default Checkout; -export async function getServerSideProps() { +export async function getServerSideProps(context) { var checkout_product = []; const backend = process.env.BACKEND_SERVER_URI; + 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 CheckoutProduct.GetCheckoutproduct(); if (res["STATUS"] === 1) { checkout_product = res["DATA"]["checkouts"]; @@ -34,6 +51,6 @@ export async function getServerSideProps() { console.log(checkout_product); return { - props: { checkout_product, backend }, // will be passed to the page component as props + props: { checkout_product, backend, user }, // will be passed to the page component as props }; } \ No newline at end of file diff --git a/pages/yamaha/index.js b/pages/yamaha/index.js index 8168535..f1680fc 100644 --- a/pages/yamaha/index.js +++ b/pages/yamaha/index.js @@ -21,12 +21,12 @@ const Index = function ({ }) { return ( <> - + - +