@@ -24,25 +24,28 @@ async function GetDealers(filter, token="") { | |||||
return res; | return res; | ||||
} | } | ||||
async function GetHomeDealer(token="") { | |||||
async function GetHomeDealer(token="", start = 0) { | |||||
var res = await apollo.query( | var res = await apollo.query( | ||||
` | ` | ||||
query{ | |||||
dealers{ | |||||
query($start: Int!) { | |||||
dealers(limit:6,start:$start){ | |||||
id | id | ||||
name | |||||
kota_dealer | |||||
address | |||||
telp | |||||
location | |||||
name | |||||
kota_dealer | |||||
address | |||||
telp | |||||
location | |||||
img{ | img{ | ||||
url | url | ||||
} | } | ||||
} | } | ||||
} | } | ||||
`, | `, | ||||
token | |||||
token, | |||||
{ | |||||
start: start, | |||||
} | |||||
); | ); | ||||
return res; | return res; | ||||
} | } | ||||
@@ -50,4 +53,4 @@ async function GetHomeDealer(token="") { | |||||
module.exports = { | module.exports = { | ||||
GetDealers: GetDealers, | GetDealers: GetDealers, | ||||
GetHomeDealer: GetHomeDealer, | GetHomeDealer: GetHomeDealer, | ||||
}; | |||||
}; |
@@ -11,7 +11,8 @@ async function GetDetailProduct(id, token = "") { | |||||
price | price | ||||
price1 | price1 | ||||
price2 | price2 | ||||
product_otrs{ | |||||
product_otrs { | |||||
id | |||||
name | name | ||||
price | price | ||||
} | } | ||||
@@ -75,6 +76,26 @@ async function GetDetailProduct(id, token = "") { | |||||
return res; | return res; | ||||
} | } | ||||
async function GetProductImgColor(id, token = "") { | |||||
var res = await apollo.query( | |||||
` | |||||
query($input: ID!) { | |||||
productImageColors(where:{id:$input}) { | |||||
id | |||||
name | |||||
img{ | |||||
url | |||||
} | |||||
} | |||||
} | |||||
`, | |||||
token, { | |||||
"input": id | |||||
} | |||||
); | |||||
return res; | |||||
} | |||||
async function GetProduct(token = "") { | async function GetProduct(token = "") { | ||||
var res = await apollo.query( | var res = await apollo.query( | ||||
` | ` | ||||
@@ -311,6 +332,7 @@ async function GetProductHino(token = "") { | |||||
module.exports = { | module.exports = { | ||||
GetProductImgColor: GetProductImgColor, | |||||
GetProduct: GetProduct, | GetProduct: GetProduct, | ||||
//yamaha | //yamaha | ||||
@@ -154,15 +154,6 @@ export default function HeaderLinks({ username, ...props }) { | |||||
</Button> | </Button> | ||||
</ListItem> | </ListItem> | ||||
<ListItem className={classes.listItem} style={{ marginTop: "10px" }}> | <ListItem className={classes.listItem} style={{ marginTop: "10px" }}> | ||||
<Button | |||||
href="/yamaha/order/order" | |||||
color="transparent" | |||||
className={classes.navLink} | |||||
> | |||||
<Chart className={classes.icons} /> | |||||
</Button> | |||||
</ListItem> | |||||
<ListItem className={classes.listItem} style={{ marginTop: "10px" }}> | |||||
{!username || username == "" ? ( | {!username || username == "" ? ( | ||||
<Button | <Button | ||||
href="/yamaha/login" | href="/yamaha/login" | ||||
@@ -29,7 +29,7 @@ const DataProduct = function ({ backend, maxi, matic, naked, sport, offroad, mop | |||||
<div style={{padding: "20px", marginTop:"-40px"}}> | <div style={{padding: "20px", marginTop:"-40px"}}> | ||||
<Card className={classes.textCenter} align="center" style={{width:"300px"}}> | <Card className={classes.textCenter} align="center" style={{width:"300px"}}> | ||||
<CardBody> | <CardBody> | ||||
<div style={{padding:"10px"}}> | |||||
<div> | |||||
<img style={{ width: "200px", display: "block" }} src={`${backend}${data.img[0]["url"]}`} className={navImageClasses} | <img style={{ width: "200px", display: "block" }} src={`${backend}${data.img[0]["url"]}`} className={navImageClasses} | ||||
/> | /> | ||||
<div align="center"> | <div align="center"> | ||||
@@ -24,7 +24,6 @@ import Carousel from "react-slick"; | |||||
const useStyles = makeStyles(styles); | const useStyles = makeStyles(styles); | ||||
const DataProduct = function ({ backend, detailproduct, ...props }) { | const DataProduct = function ({ backend, detailproduct, ...props }) { | ||||
console.log(detailproduct); | |||||
const classes = useStyles(); | const classes = useStyles(); | ||||
const { ...rest } = props; | const { ...rest } = props; | ||||
const imageClasses = classNames( | const imageClasses = classNames( | ||||
@@ -35,7 +34,7 @@ const DataProduct = function ({ backend, detailproduct, ...props }) { | |||||
const settings = { | const settings = { | ||||
dots: true, | dots: true, | ||||
infinite: true, | infinite: true, | ||||
speed: 500, | |||||
speed: 1000, | |||||
slidesToShow: 1, | slidesToShow: 1, | ||||
slidesToScroll: 1, | slidesToScroll: 1, | ||||
autoplay: true, | autoplay: true, | ||||
@@ -48,6 +47,12 @@ const DataProduct = function ({ backend, detailproduct, ...props }) { | |||||
const [value2, setValue2] = React.useState(2); | const [value2, setValue2] = React.useState(2); | ||||
const [value1, setValue1] = React.useState(1); | const [value1, setValue1] = React.useState(1); | ||||
const navImageClasses = classNames(classes.imgRounded, classes.imgGallery); | const navImageClasses = classNames(classes.imgRounded, classes.imgGallery); | ||||
const ProdcutImgColor = detailproduct.map((data) => { | |||||
return ( | |||||
<div> | |||||
</div> | |||||
); | |||||
}) | |||||
const Productdetails = detailproduct.map((data) => { | const Productdetails = detailproduct.map((data) => { | ||||
return ( | return ( | ||||
<div> | <div> | ||||
@@ -64,6 +69,8 @@ const DataProduct = function ({ backend, detailproduct, ...props }) { | |||||
<img src={`${backend}${data.img[1]["url"]}`}/> | <img src={`${backend}${data.img[1]["url"]}`}/> | ||||
<img src={`${backend}${data.img[2]["url"]}`}/> | <img src={`${backend}${data.img[2]["url"]}`}/> | ||||
<img src={`${backend}${data.img[3]["url"]}`}/> | <img src={`${backend}${data.img[3]["url"]}`}/> | ||||
<img src={`${backend}${data.img[4]["url"]}`}/> | |||||
<img src={`${backend}${data.img[5]["url"]}`}/> | |||||
</Carousel> | </Carousel> | ||||
</div> | </div> | ||||
<div align="center"> | <div align="center"> | ||||
@@ -137,7 +144,7 @@ const DataProduct = function ({ backend, detailproduct, ...props }) { | |||||
<Rating name="read-only" value={value} readOnly/> | <Rating name="read-only" value={value} readOnly/> | ||||
<div style={{marginTop:"-20px"}}> | <div style={{marginTop:"-20px"}}> | ||||
<h3><b> | <h3><b> | ||||
<NumberFormat value={data.price1} displayType={'text'} thousandSeparator={true} prefix={'Rp.'} /> s/d <NumberFormat value={data.price2} displayType={'text'} thousandSeparator={true} prefix={'Rp.'} /> | |||||
<NumberFormat value={data.price} displayType={'text'} thousandSeparator={true} prefix={'Rp.'} /> s/d <NumberFormat value={data.price2} displayType={'text'} thousandSeparator={true} prefix={'Rp.'} /> | |||||
</b></h3> | </b></h3> | ||||
</div><br/> | </div><br/> | ||||
<CustomTabs | <CustomTabs | ||||
@@ -191,8 +198,6 @@ const DataProduct = function ({ backend, detailproduct, ...props }) { | |||||
/> | /> | ||||
</Grid> | </Grid> | ||||
</GridContainer> | </GridContainer> | ||||
<GridContainer justify="center"> | |||||
<GridItem> | |||||
<NavPills | <NavPills | ||||
color="primary" | color="primary" | ||||
align="center" | align="center" | ||||
@@ -424,8 +429,6 @@ const DataProduct = function ({ backend, detailproduct, ...props }) { | |||||
}, | }, | ||||
]} | ]} | ||||
/> | /> | ||||
</GridItem> | |||||
</GridContainer> | |||||
</div> | </div> | ||||
); | ); | ||||
}) | }) | ||||
@@ -0,0 +1,41 @@ | |||||
import auth from "../../../api/auth/auth"; | |||||
import Cookies from "cookies"; | |||||
export default async function handler(req, res) { | |||||
if (req.method == "POST") { | |||||
const cookies = new Cookies(req, res); | |||||
var email = req.body.email; | |||||
var pass = req.body.pass; | |||||
var partner = req.body.partner; | |||||
var resp = await auth.login(partner, email, pass); | |||||
var login = resp["res"]; | |||||
// console.log(login["DATA"]); | |||||
if (login["STATUS"] == 0) { | |||||
return res | |||||
.status(400) | |||||
.send(login["DATA"] + ". Check user and password again."); | |||||
} | |||||
var userObj = resp["cookies"]["user"]; | |||||
await cookies.set("myToken", resp["cookies"]["token"], { | |||||
httpOnly: true, // true by default | |||||
}); | |||||
await cookies.set("user", JSON.stringify(userObj), { | |||||
httpOnly: true, // true by default | |||||
}); | |||||
let sessionId = userObj["partners_login_states"].filter( | |||||
(i) => | |||||
i.business_partner && | |||||
i.business_partner.name.toUpperCase() == partner.toUpperCase() | |||||
); | |||||
if (sessionId.length == 0) return res.status(400).send("Login Failed"); | |||||
return res.status(200).send("Success Login"); | |||||
// res.status(200).json(login); | |||||
// res.writeHead(200, { | |||||
// Location: "../home", | |||||
// //add other headers here... | |||||
// }); | |||||
// res.end(); | |||||
} else { | |||||
return res.status(400).send("NOT FOUND"); | |||||
} | |||||
} |
@@ -0,0 +1,36 @@ | |||||
import auth from "../../../api/auth/auth"; | |||||
import Cookies from "cookies"; | |||||
export default async function handler(req, res) { | |||||
if (req.method == "POST") { | |||||
const cookies = new Cookies(req, res); | |||||
const partner = req.body.p; | |||||
var user = await cookies.get("user"); | |||||
var token = await cookies.get("myToken"); | |||||
var userObj = user ? JSON.parse(user) : null; | |||||
let sessionId = userObj["partners_login_states"].filter( | |||||
(i) => | |||||
i.business_partner && | |||||
i.business_partner.name.toUpperCase() == partner.toUpperCase() | |||||
); | |||||
sessionId.forEach(async (i) => { | |||||
var resp = await auth.logout(i.id, token); | |||||
if (resp["STATUS"] == 0) { | |||||
return res.status(400).send(resp["DATA"]); | |||||
} | |||||
}); | |||||
userObj["partners_login_states"] = userObj[ | |||||
"partners_login_states" | |||||
].filter( | |||||
(i) => | |||||
i.business_partner && | |||||
i.business_partner.name.toUpperCase() != partner.toUpperCase() | |||||
); | |||||
await cookies.set("user", JSON.stringify(userObj), { | |||||
httpOnly: true, // true by default | |||||
}); | |||||
return res.status(200).send("Success Logout"); | |||||
} else { | |||||
return res.status(400).send("NOT FOUND"); | |||||
} | |||||
} |
@@ -9,7 +9,7 @@ import styles from "assets/jss/nextjs-material-kit/pages/components.js"; | |||||
import Footer from "components/Footer/Footer.js"; | import Footer from "components/Footer/Footer.js"; | ||||
import Getcarousels from "api/home/carousel.js"; | import Getcarousels from "api/home/carousel.js"; | ||||
import Getdealer from "../../api/dealer/dealer.js"; | |||||
import Getdealer from "api/dealer/dealer.js"; | |||||
import DataSnackbarContent from "pages-sections/yamaha/snackbar.js"; | import DataSnackbarContent from "pages-sections/yamaha/snackbar.js"; | ||||
import DataCarousel from "pages-sections/yamaha/home/carousel.js"; | import DataCarousel from "pages-sections/yamaha/home/carousel.js"; | ||||
import DataService from "pages-sections/yamaha/home/service.js"; | import DataService from "pages-sections/yamaha/home/service.js"; | ||||
@@ -13,7 +13,7 @@ import Cookies from "cookies"; | |||||
const useStyles = makeStyles(styles); | const useStyles = makeStyles(styles); | ||||
const ProductDetails = function ({ backend, detailproduct, user, ...props }) { | |||||
const ProductDetails = function ({ backend, detailproduct, user, color, ...props }) { | |||||
const classes = useStyles(); | const classes = useStyles(); | ||||
const { ...rest } = props; | const { ...rest } = props; | ||||
return ( | return ( | ||||
@@ -30,7 +30,7 @@ const ProductDetails = function ({ backend, detailproduct, user, ...props }) { | |||||
/> | /> | ||||
<Parallax image={require("assets/img/Promotion_2-1.jpg")} width="200px"/> | <Parallax image={require("assets/img/Promotion_2-1.jpg")} width="200px"/> | ||||
<div className={classNames(classes.main, classes.mainRaised)}> | <div className={classNames(classes.main, classes.mainRaised)}> | ||||
<ProductDetail detailproduct={detailproduct} backend={backend}/> | |||||
<ProductDetail detailproduct={detailproduct} backend={backend} color={color}/> | |||||
</div> | </div> | ||||
<Footer /> | <Footer /> | ||||
</div> | </div> | ||||
@@ -42,6 +42,8 @@ export default ProductDetails; | |||||
export async function getServerSideProps(context) { | export async function getServerSideProps(context) { | ||||
var {query} = context; | var {query} = context; | ||||
var detailproduct = []; | var detailproduct = []; | ||||
var color = []; | |||||
const backend = process.env.BACKEND_SERVER_URI; | const backend = process.env.BACKEND_SERVER_URI; | ||||
var { req, resp } = context; | var { req, resp } = context; | ||||
@@ -59,12 +61,17 @@ export async function getServerSideProps(context) { | |||||
if (sessionId.length != 0) user = userObj["username"]; | if (sessionId.length != 0) user = userObj["username"]; | ||||
} | } | ||||
var res = await GetDetailproduct.GetProductImgColor(query.s||0); | |||||
if (res["STATUS"] === 1) { | |||||
color = res["DATA"]["productImageColors"]; | |||||
} | |||||
var res = await GetDetailproduct.GetDetailProduct(query.s||0); | var res = await GetDetailproduct.GetDetailProduct(query.s||0); | ||||
if (res["STATUS"] === 1) { | if (res["STATUS"] === 1) { | ||||
detailproduct = res["DATA"]["products"]; | detailproduct = res["DATA"]["products"]; | ||||
} | } | ||||
return { | return { | ||||
props: { detailproduct, backend, user }, // will be passed to the page component as props | |||||
props: { detailproduct, backend, color, user }, // will be passed to the page component as props | |||||
}; | }; | ||||
} | |||||
} |