25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

505 lines
22 KiB

  1. import React from 'react';
  2. import { makeStyles } from '@material-ui/core/styles';
  3. import clsx from 'clsx';
  4. import SnackbarContent from "components/Snackbar/SnackbarContent.js";
  5. import Button1 from "components/CustomButtons/Button.js";
  6. import image1 from "../../../assets/img/mail.png"
  7. import GridContainer from "components/Grid/GridContainer.js";
  8. import Carousel from "react-slick";
  9. import GridItem from "components/Grid/GridItem.js";
  10. import classNames from "classnames";
  11. import swal from 'sweetalert';
  12. import Icon from "@material-ui/core/Icon";
  13. import Grid from '@material-ui/core/Grid';
  14. import TextField from '@material-ui/core/TextField';
  15. import Button from '@material-ui/core/Button';
  16. import Dialog from '@material-ui/core/Dialog';
  17. import ListItemText from '@material-ui/core/ListItemText';
  18. import ListItem from '@material-ui/core/ListItem';
  19. import List from '@material-ui/core/List';
  20. import Divider from '@material-ui/core/Divider';
  21. import AppBar from '@material-ui/core/AppBar';
  22. import Toolbar from '@material-ui/core/Toolbar';
  23. import IconButton from '@material-ui/core/IconButton';
  24. import Typography from '@material-ui/core/Typography';
  25. import CloseIcon from '@material-ui/icons/Close';
  26. import Slide from '@material-ui/core/Slide';
  27. import Select from '@material-ui/core/Select';
  28. import MenuItem from '@material-ui/core/MenuItem';
  29. import Card from "components/Card/Card.js";
  30. import CardBody from "components/Card/CardBody.js";
  31. import FormControl from '@material-ui/core/FormControl';
  32. import { Form, FormGroup } from "rsuite";
  33. const useStyles = makeStyles((theme) => ({
  34. root: {
  35. width: '100%',
  36. },
  37. button: {
  38. marginTop: theme.spacing(1),
  39. marginRight: theme.spacing(1),
  40. },
  41. actionsContainer: {
  42. marginBottom: theme.spacing(2),
  43. },
  44. resetContainer: {
  45. padding: theme.spacing(3),
  46. },
  47. appBar: {
  48. position: 'relative',
  49. },
  50. title: {
  51. marginLeft: theme.spacing(2),
  52. flex: 1,
  53. },
  54. root: {
  55. '&:hover': {
  56. backgroundColor: 'transparent',
  57. },
  58. },
  59. icon: {
  60. borderRadius: '50%',
  61. width: 16,
  62. height: 16,
  63. boxShadow: 'inset 0 0 0 1px rgba(16,22,26,.2), inset 0 -1px 0 rgba(16,22,26,.1)',
  64. backgroundColor: '#f5f8fa',
  65. backgroundImage: 'linear-gradient(180deg,hsla(0,0%,100%,.8),hsla(0,0%,100%,0))',
  66. '$root.Mui-focusVisible &': {
  67. outline: '2px auto rgba(19,124,189,.6)',
  68. outlineOffset: 2,
  69. },
  70. 'input:hover ~ &': {
  71. backgroundColor: '#ebf1f5',
  72. },
  73. 'input:disabled ~ &': {
  74. boxShadow: 'none',
  75. background: 'rgba(206,217,224,.5)',
  76. },
  77. },
  78. checkedIcon: {
  79. backgroundColor: '#137cbd',
  80. backgroundImage: 'linear-gradient(180deg,hsla(0,0%,100%,.1),hsla(0,0%,100%,0))',
  81. '&:before': {
  82. display: 'block',
  83. width: 16,
  84. height: 16,
  85. backgroundImage: 'radial-gradient(#fff,#fff 28%,transparent 32%)',
  86. content: '""',
  87. },
  88. 'input:hover ~ &': {
  89. backgroundColor: '#106ba3',
  90. },
  91. },
  92. }));
  93. const Transition = React.forwardRef(function Transition(props, ref) {
  94. return <Slide direction="up" ref={ref} {...props} />;
  95. });
  96. const DataCheckout = function ({ checkoutprofile, province, cities, backend, checkoutproduct, ...props }) {
  97. const settings = {
  98. dots: true,
  99. infinite: true,
  100. speed: 500,
  101. slidesToShow: 1,
  102. slidesToScroll: 1,
  103. autoplay: true,
  104. time: 5
  105. };
  106. const classes = useStyles();
  107. const [open, setOpen] = React.useState(false);
  108. const handleClickOpen = () => {
  109. setOpen(true);
  110. };
  111. const { ...rest } = props;
  112. const imageClasses = classNames(
  113. classes.imgRaised,
  114. classes.imgRoundedCircle,
  115. classes.imgFluid
  116. );
  117. const navImageClasses = classNames(classes.imgRounded, classes.imgGallery);
  118. const [formValue, setFormValue] = React.useState({
  119. order_id: GenerateID(),
  120. cust_name: "",
  121. cust_telp: "",
  122. cust_address: "",
  123. product_img: "",
  124. product_name: "",
  125. product_color: "",
  126. product_quantity: "",
  127. product_price: "",
  128. product_courier: "",
  129. note: "",
  130. });
  131. // const [formValue, setFormValue] = React.useState({
  132. // order_id: "Trx-Ord-9ab8ab88",
  133. // cust_name: "Yusmar",
  134. // cust_telp: "087797315685",
  135. // cust_address: "Thamrin Indrapura Jl.Aipda Karel Satsuit Tubun,17 Ilir, Kec.Ilir Tim.I, Palembang, KOTA PALEMBANG - ILIR TIMUR II, SUMATERA SELATAN, ID 30114",
  136. // product_img: null,
  137. // product_name: "NMAX 155",
  138. // product_color: "Red",
  139. // product_quantity: "1",
  140. // product_price: "28545000",
  141. // product_courier: "JNE",
  142. // note: "Tes",
  143. // });
  144. function GenerateID(){
  145. var dt = new Date().getTime();
  146. var uuid = 'Trx-Ord-yyyyyyyy'.replace(/[y]/g, function(c) {
  147. var r = (dt + Math.random()*16)%16 | 0;
  148. dt = Math.floor(dt/16);
  149. return (c=='x' ? r :(r&0x3|0x8)).toString(16);
  150. });
  151. return uuid;
  152. }
  153. const CheckoutAlamat = checkoutprofile.map((data) => {
  154. return (
  155. <div align="center">
  156. <Card className={classes.textCenter} align="center">
  157. <CardBody>
  158. <div style={{padding:"10px"}}>
  159. <Typography variant="h6" align="left" className={classes.title}>
  160. Alamat Pengiriman
  161. </Typography><br></br>
  162. <GridContainer>
  163. <GridItem className={classes.marginAuto}>
  164. <Carousel>
  165. <img src={image1} style={{width:"1100px"}}/><br></br>
  166. </Carousel>
  167. </GridItem>
  168. </GridContainer>
  169. <FormGroup>
  170. <FormControl name="cust_name" value={data.username} type="text"/>
  171. </FormGroup>
  172. <h5>{data.username}</h5>
  173. <FormGroup>
  174. <FormControl name="cust_telp" value={data.telp} type="text"/>
  175. </FormGroup>
  176. <h5>{data.telp}</h5>
  177. <FormGroup>
  178. <FormControl name="cust_address" value={data.address} type="text"/>
  179. </FormGroup>
  180. <h5>{data.address}</h5>
  181. <Button1 color="info" href={"/yamaha/profile/edit-profile"}>
  182. <Icon className={classes.icons}>cached</Icon>
  183. Ubah Alamat
  184. </Button1>
  185. </div>
  186. </CardBody>
  187. </Card>
  188. </div>
  189. );
  190. })
  191. const CheckoutProdukPesanan = checkoutproduct.map((data) => {
  192. const handleChange = (event) => {
  193. setColor(event.target.value);
  194. };
  195. const handleChanges = (event) => {
  196. setPengiriman(event.target.value);
  197. };
  198. const [color, setColor] = React.useState('');
  199. const [pengiriman, setPengiriman] = React.useState('');
  200. const handleClose = () => {
  201. setFormValue({
  202. ...formValue,
  203. product_courier: pengiriman,
  204. })
  205. setOpen(false);
  206. };
  207. return (
  208. <div align="center">
  209. <Card className={classes.textCenter} align="center">
  210. <CardBody>
  211. <div style={{padding:"10px"}}>
  212. <Typography variant="h6" align="left" className={classes.title}>
  213. Pesanan Produk
  214. </Typography><br></br><hr></hr>
  215. <GridContainer>
  216. <Grid item xs>
  217. <FormGroup>
  218. <FormControl name="product_img" value={`${backend}${data.img[0]["url"]}`} type="text"/>
  219. </FormGroup>
  220. <div align="center">
  221. <h4>Produk Dipesan</h4>
  222. <img className={navImageClasses} width="200px" alt="First slide" src={`${backend}${data.img[0]["url"]}`} />
  223. </div>
  224. </Grid>
  225. <Grid item xs>
  226. <div align="center">
  227. <h4></h4><br></br><br></br><br></br><br></br>
  228. <FormGroup>
  229. <FormControl name="product_name" value={data.name} type="text"/>
  230. </FormGroup>
  231. <h5>{data.name}</h5>
  232. </div>
  233. </Grid>
  234. <Grid item xs>
  235. <div align="center">
  236. <h4>Warna</h4><br></br><br></br><br></br>
  237. <FormGroup>
  238. <FormControl className={classes.formControl}>
  239. <Select
  240. labelId="demo-simple-select-label"
  241. id="demo-simple-select"
  242. value={color}
  243. name="product_color"
  244. onChange={(e)=>{
  245. setFormValue({
  246. ...formValue,
  247. product_color: e.target.value.toString()
  248. })
  249. }}
  250. >
  251. <MenuItem value={1}>Hitam</MenuItem>
  252. <MenuItem value={2}>Merah</MenuItem>
  253. <MenuItem value={3}>Biru</MenuItem>
  254. <MenuItem value={4}>Putih</MenuItem>
  255. </Select>
  256. </FormControl>
  257. </FormGroup>
  258. </div>
  259. </Grid>
  260. <Grid item xs>
  261. <div align="center">
  262. <h4>Harga Satuan</h4><br></br><br></br><br></br>
  263. <h5>Rp.{data.price}</h5>
  264. </div>
  265. </Grid>
  266. <Grid item xs>
  267. <div align="center">
  268. <h4>Jumlah Unit</h4><br></br><br></br><br></br>
  269. <FormGroup>
  270. <FormControl className={classes.formControl}>
  271. <TextField
  272. id="outlined-number"
  273. type="number"
  274. align="center"
  275. name="quantity"
  276. InputLabelProps={{
  277. shrink: false,
  278. }}
  279. onInput={(e)=>{
  280. setFormValue({
  281. ...formValue,
  282. product_quantity: e.target.value
  283. })
  284. }}
  285. />
  286. </FormControl>
  287. </FormGroup>
  288. </div>
  289. </Grid>
  290. <Grid item xs>
  291. <div align="center">
  292. <h4>Sub Total Produk</h4><br></br><br></br><br></br>
  293. <h5>Total Rp.{data.price}</h5>
  294. </div>
  295. </Grid>
  296. </GridContainer>
  297. <GridContainer style={{padding:"20px"}}>
  298. <Grid item xs style={{padding:"20px"}}>
  299. <TextField
  300. id="outlined-full-width"
  301. label="Pesan"
  302. style={{ margin: 8 }}
  303. placeholder="( Opsional ) Tinggalkan Pesan Kepada Dealer"
  304. fullWidth
  305. margin="normal"
  306. InputLabelProps={{
  307. shrink: true,
  308. }}
  309. variant="outlined"
  310. onInput={(e)=>{
  311. setFormValue({
  312. ...formValue,
  313. note: e.target.value
  314. })
  315. }}
  316. />
  317. </Grid>
  318. <Grid item xs style={{padding:"20px"}}><br></br>
  319. <Button variant="outlined" color="primary" onClick={handleClickOpen}>
  320. Pilih Opsi Pengiriman
  321. </Button>
  322. <span>{formValue.product_courier}</span>
  323. <Dialog fullScreen open={open} onClose={handleClose} TransitionComponent={Transition}>
  324. <AppBar className={classes.appBar}>
  325. <Toolbar>
  326. <IconButton edge="start" color="inherit" onClick={handleClose} aria-label="close">
  327. <CloseIcon />
  328. </IconButton>
  329. <Typography variant="h6" className={classes.title}>
  330. Pilih Opsi Pengiriman
  331. </Typography>
  332. <Button autoFocus color="inherit" onClick={handleClose}>
  333. Pilih
  334. </Button>
  335. </Toolbar>
  336. </AppBar>
  337. <List>
  338. <ListItem button
  339. id="POS"
  340. selected={(pengiriman=="POS")}
  341. onClick={(e)=>{
  342. setPengiriman("POS");
  343. }}
  344. >
  345. <ListItemText primary="POS" secondary="Akan diterima pada tanggal 2 Apr - 6 Apr" />
  346. </ListItem>
  347. <Divider />
  348. <ListItem button
  349. id="JNE"
  350. selected={(pengiriman=="JNE")}
  351. onClick={(e)=>{
  352. setPengiriman("JNE");
  353. }}
  354. >
  355. <ListItemText primary="JNE" secondary="Akan diterima pada tanggal 30 Mar - 2 Apr" />
  356. </ListItem>
  357. <ListItem button
  358. id="TIKI"
  359. selected={(pengiriman=="TIKI")}
  360. onClick={(e)=>{
  361. setPengiriman("TIKI");
  362. }}
  363. >
  364. <ListItemText primary="TIKI" secondary="Akan diterima pada tanggal 1 Apr - 4 Apr, COD (Bayar di Tempat) tidak didukung" />
  365. </ListItem>
  366. </List>
  367. </Dialog>
  368. </Grid>
  369. <Grid item xs align="right" style={{padding:"20px"}}><br></br>
  370. <h5>Total Rp. {data.price}</h5>
  371. <FormGroup>
  372. <FormControl name="product_price" value={data.price} type="text"/>
  373. </FormGroup>
  374. </Grid>
  375. </GridContainer>
  376. </div>
  377. </CardBody>
  378. </Card>
  379. </div>
  380. );
  381. })
  382. return (
  383. <div style={{padding:"50px"}}>
  384. <script type="text/javascript" src="https://app.sandbox.midtrans.com/snap/snap.js" data-client-key="SB-Mid-client-srx674LjNbEybd4-"/>
  385. <div align="center" className={classes.section} id="notifications">
  386. <SnackbarContent
  387. message={
  388. <h2><b>Checkout</b></h2>
  389. }
  390. align="center"
  391. color="info"
  392. />
  393. </div>
  394. <Form
  395. onSubmit={async(value) => {
  396. var newformValue = {
  397. ...formValue,
  398. cust_name: checkoutprofile[0].username,
  399. cust_telp: checkoutprofile[0].telp.toString(),
  400. cust_address: checkoutprofile[0].address,
  401. // product_img: checkoutproduct[0].img,
  402. product_name: checkoutproduct[0].name,
  403. product_price: checkoutproduct[0].price,
  404. }
  405. setFormValue(newformValue)
  406. const response = await fetch(
  407. "/api/transaction/create",
  408. {
  409. method: "POST",
  410. headers: {
  411. 'Content-Type': 'application/json'
  412. },
  413. body: JSON.stringify(newformValue),
  414. }
  415. );
  416. if (response.ok) {
  417. var res = await response.json();
  418. if (res["STATUS"] === 1) {
  419. res["DATA"]["transaction"];
  420. swal("Produk Berhasil Ditambah ke Keranjang", "Silahkan Cek Keranjang Belanja Anda", "success");
  421. }
  422. else {
  423. swal("Produk Gagal Ditambah ke Keranjang", "Silahkan Coba Lagi", "error");
  424. }
  425. } else {
  426. swal("Transaksi Gagal", "Silahkan Coba Lagi", "error");
  427. }
  428. }}
  429. >
  430. <div>
  431. {CheckoutAlamat}
  432. </div>
  433. <div>
  434. {CheckoutProdukPesanan}
  435. </div>
  436. <div>
  437. <GridContainer>
  438. <Grid item xs={6} style={{padding:"20px"}}>
  439. <Button1 color="info" style={{width:"100%"}}
  440. type="submit"
  441. // onClick={async function (e) {
  442. // // setFormValue({
  443. // // cust_name : data.username,
  444. // // ... formValue
  445. // // });
  446. //
  447. // }}
  448. >
  449. <Icon className={classes.icons}>attach_money</Icon>
  450. Buat Pesanan
  451. </Button1>
  452. </Grid>
  453. <Grid item xs={6} style={{padding:"20px"}}>
  454. <Button1 color="danger" style={{width:"100%"}}
  455. // swal({
  456. // title: "Anda Ingin Menghapus Pesanan ?",
  457. // icon: "warning",
  458. // buttons: true,
  459. // dangerMode: true,
  460. // })
  461. // .then((willDelete) => {
  462. // if (willDelete) {
  463. // swal("Pesanan Anda Berhasil Dihapus", {
  464. // icon: "success",
  465. // });
  466. // } else {
  467. // swal("Selamat Belanja Kembali");
  468. // }
  469. // });
  470. >
  471. <Icon className={classes.icons}>attach_money</Icon>
  472. Batalkan Pesanan
  473. </Button1>
  474. </Grid>
  475. </GridContainer>
  476. {/* <GridContainer>
  477. <Grid item xs={6} style={{padding:"20px"}}>
  478. <Button1 color="info" onClick={(e)=>{snap.pay(transactionToken);}} style={{width:"100%"}}>
  479. <Icon className={classes.icons}>attach_money</Icon>
  480. Bayar Pesanan
  481. </Button1>
  482. </Grid>
  483. </GridContainer> */}
  484. </div>
  485. </Form>
  486. </div>
  487. );
  488. }
  489. export default DataCheckout;