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.
 
 

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