From 69b9f2c7d816ff5d6dbd52ec2bb1a6e7da6d1227 Mon Sep 17 00:00:00 2001 From: Yusmardianto Date: Mon, 22 Feb 2021 11:18:42 +0700 Subject: [PATCH] api /product --- api/latest_news/news.js | 28 ++-- api/product/product.js | 220 +++++++++++++++++++++++++++-- components/Header/HeaderLinks.js | 2 +- package.json | 1 + pages-sections/latest_news/news.js | 30 +++- pages-sections/latest_news/news_details.js | 0 pages-sections/product/product.js | 215 ++++++++++++++++++++++++++-- pages-sections/product/product_details.js | 17 +-- pages/latestnews_details.js | 0 pages/product.js | 54 ++++++- yarn.lock | 7 + 11 files changed, 517 insertions(+), 57 deletions(-) create mode 100644 pages-sections/latest_news/news_details.js create mode 100644 pages/latestnews_details.js diff --git a/api/latest_news/news.js b/api/latest_news/news.js index 459e949..92c0dd4 100644 --- a/api/latest_news/news.js +++ b/api/latest_news/news.js @@ -1,20 +1,24 @@ import apollo from "../../lib/apollo.js"; -async function GetNews(token="") { +async function GetNews(token="", start = 0) { var res = await apollo.query( - ` - query{ - latestNews - { - title - description - img{ - url - } + ` + query($start: Int!) { + latestNews(limit:6,start:$start) + { + id + title + description + img{ + url } } - `, - token + } + `, + token, + { + start: start, + } ); return res; } diff --git a/api/product/product.js b/api/product/product.js index 610b358..7eff69a 100644 --- a/api/product/product.js +++ b/api/product/product.js @@ -1,11 +1,38 @@ import apollo from "../../lib/apollo.js"; -async function GetProduct(token="") { +// async function GetProduct(token="", start = 0) { +// var res = await apollo.query( +// ` +// query($start: Int!) { +// products(limit:1,start:$start) +// { +// id +// name +// price +// description +// img{ +// url +// } +// business_partner +// { +// name +// } +// } +// }`, +// token, +// { +// start: start, +// } +// ); +// return res; +// } + +async function GetDetailProduct(token="") { var res = await apollo.query( ` query{ - products{ - id + products + { name price description @@ -23,15 +50,40 @@ async function GetProduct(token="") { return res; } -async function GetDetailProduct(token="") { +async function GetProductYamaha(token="") { var res = await apollo.query( ` - query{ - products + query { + products(where: {business_partner: "1"}) { + id name + description price + img{ + url + } + business_partner + { + name + } + } + }`, + token + ); + return res; +} + +async function GetProductSuzuki(token="") { + var res = await apollo.query( + ` + query { + products(where: {business_partner: "2"}) + { + id + name description + price img{ url } @@ -40,13 +92,165 @@ async function GetDetailProduct(token="") { name } } - } `, + }`, + token + ); + return res; +} + +async function GetProductHonda(token="") { + var res = await apollo.query( + ` + query { + products(where: {business_partner: "3"}) + { + id + name + description + price + img{ + url + } + business_partner + { + name + } + } + }`, + token + ); + return res; +} + +async function GetProductHino(token="") { + var res = await apollo.query( + ` + query { + products(where: {business_partner: "4"}) + { + id + name + description + price + img{ + url + } + business_partner + { + name + } + } + }`, + token + ); + return res; +} + +async function GetProductMercedes(token="") { + var res = await apollo.query( + ` + query { + products(where: {business_partner: "5"}) + { + id + name + description + price + img{ + url + } + business_partner + { + name + } + } + }`, + token + ); + return res; +} + +async function GetProductBPR(token="") { + var res = await apollo.query( + ` + query { + products(where: {business_partner: "6"}) + { + id + name + description + price + img{ + url + } + business_partner + { + name + } + } + }`, + token + ); + return res; +} + +async function GetProductEmilia(token="") { + var res = await apollo.query( + ` + query { + products(where: {business_partner: "8"}) + { + id + name + description + price + img{ + url + } + business_partner + { + name + } + } + }`, + token + ); + return res; +} + +async function GetProductHomes(token="") { + var res = await apollo.query( + ` + query { + products(where: {business_partner: "9"}) + { + id + name + description + price + img{ + url + } + business_partner + { + name + } + } + }`, token ); return res; } module.exports = { - GetProduct: GetProduct, + // GetProduct: GetProduct, GetDetailProduct:GetDetailProduct, + GetProductYamaha:GetProductYamaha, + GetProductSuzuki:GetProductSuzuki, + GetProductHonda:GetProductHonda, + GetProductHino:GetProductHino, + GetProductMercedes:GetProductMercedes, + GetProductBPR:GetProductBPR, + GetProductEmilia:GetProductEmilia, + GetProductHomes:GetProductHomes, }; \ No newline at end of file diff --git a/components/Header/HeaderLinks.js b/components/Header/HeaderLinks.js index a1b2599..21e4e1f 100644 --- a/components/Header/HeaderLinks.js +++ b/components/Header/HeaderLinks.js @@ -40,7 +40,7 @@ export default function HeaderLinks(props) { setLoading(true); + const stopLoading = () => setLoading(false); + useEffect(() => { //After the component is mounted set router event handlers + Router.events.on('routeChangeStart', startLoading); + Router.events.on('routeChangeComplete', stopLoading); + + return () => { + Router.events.off('routeChangeStart', startLoading); + Router.events.off('routeChangeComplete', stopLoading); + } + }, []) + const pagginationHandler = (page) => { + const currentPath = props.router.pathname; + const currentQuery = props.router.query; + currentQuery.page = page.selected + 1; + + props.router.push({ + pathname: currentPath, + query: currentQuery, + }); + }; + const classes = useStyles(); const latnews = news.map((data) => { return ( @@ -43,6 +68,7 @@ const DataLatestNews = function ({ backend, news, ...props }) {
{latnews} + {latnews}
@@ -61,7 +87,7 @@ const DataLatestNews = function ({ backend, news, ...props }) { ]} />
- + ); } diff --git a/pages-sections/latest_news/news_details.js b/pages-sections/latest_news/news_details.js new file mode 100644 index 0000000..e69de29 diff --git a/pages-sections/product/product.js b/pages-sections/product/product.js index c383420..9272f5b 100644 --- a/pages-sections/product/product.js +++ b/pages-sections/product/product.js @@ -8,7 +8,6 @@ import { makeStyles } from "@material-ui/core/styles"; // @material-ui/icons import Dashboard from "@material-ui/icons/Dashboard"; -import LocalGroceryStoreIcon from "@material-ui/icons/LocalGroceryStore"; // Component import GridContainer from "components/Grid/GridContainer.js"; @@ -20,9 +19,10 @@ import CardHeader from "components/Card/CardHeader.js"; import CardFooter from "components/Card/CardFooter.js"; import Button from "components/CustomButtons/Button.js"; import styles from "assets/jss/nextjs-material-kit/pages/profilePage.js"; +import Icon from "@material-ui/core/Icon"; const useStyles = makeStyles(styles); -const DataProduct = function ({ backend, product, ...props }) { +const DataProduct = function ({ backend, yamaha, suzuki, honda, hino, mercedes, bpr, emilia, homes, ...props }) { const classes = useStyles(); const { ...rest } = props; const imageClasses = classNames( @@ -31,8 +31,7 @@ const DataProduct = function ({ backend, product, ...props }) { classes.imgFluid ); const navImageClasses = classNames(classes.imgRounded, classes.imgGallery); - const Product = product.map((data) => { - console.log(data); + const Productyamaha = yamaha.map((data) => { return (
-

{data.name}

+

{data.name}

Rp.{data.price}

- +
+
+ ); + }) + const Productsuzuki = suzuki.map((data) => { + return ( +
+ ... +
+

{data.name}

+

Rp.{data.price}

+ +
+
+ ); + }) + const Producthonda = honda.map((data) => { + return ( +
+ ... +
+

{data.name}

+

Rp.{data.price}

+ +
+
+ ); + }) + const Producthino = hino.map((data) => { + return ( +
+ ... +
+

{data.name}

+

Rp.{data.price}

+ +
+
+ ); + }) + const Productmercedes = mercedes.map((data) => { + return ( +
+ ... +
+

{data.name}

+

Rp.{data.price}

+ +
+
+ ); + }) + const Productbpr = bpr.map((data) => { + return ( +
+ ... +
+

{data.name}

+

Rp.{data.price}

+ +
+
+ ); + }) + const Productemilia = emilia.map((data) => { + return ( +
+ ... +
+

{data.name}

+

Rp.{data.price}

+ +
+
+ ); + }) + const Producthomes = homes.map((data) => { + return ( +
+ ... +
+

{data.name}

+

Rp.{data.price}

+
@@ -72,7 +227,7 @@ const DataProduct = function ({ backend, product, ...props }) { tabIcon: Dashboard, tabContent: ( - {Product} + {Productyamaha} ), }, @@ -81,7 +236,7 @@ const DataProduct = function ({ backend, product, ...props }) { tabIcon: Dashboard, tabContent: ( - {Product} + {Productsuzuki} ), }, @@ -90,7 +245,16 @@ const DataProduct = function ({ backend, product, ...props }) { tabIcon: Dashboard, tabContent: ( - + {Producthonda} + + ), + }, + { + tabButton: "Hino", + tabIcon: Dashboard, + tabContent: ( + + {Producthino} ), }, @@ -99,7 +263,34 @@ const DataProduct = function ({ backend, product, ...props }) { tabIcon: Dashboard, tabContent: ( - + {Productmercedes} + + ), + }, + { + tabButton: "BPR Berkat Sejati", + tabIcon: Dashboard, + tabContent: ( + + {Productmercedes} + + ), + }, + { + tabButton: "Emilia Hotel", + tabIcon: Dashboard, + tabContent: ( + + {Productemilia} + + ), + }, + { + tabButton: "Thamrin Homes", + tabIcon: Dashboard, + tabContent: ( + + {Producthomes} ), }, diff --git a/pages-sections/product/product_details.js b/pages-sections/product/product_details.js index 3479b3c..dd7d181 100644 --- a/pages-sections/product/product_details.js +++ b/pages-sections/product/product_details.js @@ -22,12 +22,6 @@ import CardFooter from "components/Card/CardFooter.js"; import Button from "components/CustomButtons/Button.js"; import styles from "assets/jss/nextjs-material-kit/pages/profilePage.js"; import Carousel from "react-slick"; -import Paper from '@material-ui/core/Paper'; - - -import image1 from "assets/img/bg.jpg"; -import image2 from "assets/img/bg2.png"; -import image3 from "assets/img/bg3.jpg"; const useStyles = makeStyles(styles); @@ -59,6 +53,7 @@ const DataProduct = function ({ backend, detailproduct, ...props }) {

{data.name}

Rp.{data.price}


+

{data.description}

); @@ -127,16 +122,6 @@ const DataProduct = function ({ backend, detailproduct, ...props }) { ), }, - { - tabButton: "Test Drive", - tabIcon: Dashboard, - tabContent: ( - - - - - ), - }, ]} /> diff --git a/pages/latestnews_details.js b/pages/latestnews_details.js new file mode 100644 index 0000000..e69de29 diff --git a/pages/product.js b/pages/product.js index d9216e4..dac13dc 100644 --- a/pages/product.js +++ b/pages/product.js @@ -20,7 +20,7 @@ import Getproduct from "../api/product/product.js" const useStyles = makeStyles(styles); -const Product = function ({ backend, product, ...props }) { +const Product = function ({ backend, yamaha, suzuki, honda, hino, mercedes, bpr, emilia, homes, ...props }) { const classes = useStyles(); const { ...rest } = props; return ( @@ -50,7 +50,7 @@ const Product = function ({ backend, product, ...props }) {
- +