Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 

425 lignes
18 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 { 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 ({ 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 handleClose = () => {
  112. setOpen(false);
  113. };
  114. const { ...rest } = props;
  115. const imageClasses = classNames(
  116. classes.imgRaised,
  117. classes.imgRoundedCircle,
  118. classes.imgFluid
  119. );
  120. const navImageClasses = classNames(classes.imgRounded, classes.imgGallery);
  121. const [formValue, setFormValue] = React.useState({
  122. cust_name: "cust_name",
  123. cust_telp: null,
  124. cust_address: null,
  125. product_img: null,
  126. product_name: null,
  127. product_color: null,
  128. product_quantity: null,
  129. product_price: null,
  130. product_courier: null,
  131. });
  132. function create_UUID(){
  133. var dt = new Date().getTime();
  134. var uuid = 'Order-ID-xxxxxxxx'.replace(/[x]/g, function(c) {
  135. var r = (dt + Math.random()*16)%16 | 0;
  136. dt = Math.floor(dt/16);
  137. return (c=='x' ? r :(r&0x3|0x8)).toString(16);
  138. });
  139. return uuid;
  140. }
  141. console.log(create_UUID);
  142. const CheckoutAlamat = checkoutproduct.map((data) => {
  143. return (
  144. <div align="center">
  145. <Card className={classes.textCenter} align="center">
  146. <CardBody>
  147. <div style={{padding:"10px"}}>
  148. <Typography variant="h6" align="left" className={classes.title}>
  149. Alamat Pengiriman
  150. </Typography><br></br>
  151. <GridContainer>
  152. <GridItem className={classes.marginAuto}>
  153. <Carousel>
  154. <img src={image1} style={{width:"1100px"}}/><br></br>
  155. </Carousel>
  156. </GridItem>
  157. </GridContainer>
  158. <FormGroup>
  159. <FormControl name="cust_name" type="text" value={data.name}/>
  160. </FormGroup>
  161. <h5>{data.name}</h5>
  162. <FormGroup>
  163. <FormControl name="cust_telp" type="text"/>
  164. </FormGroup>
  165. <h5>087797315685</h5>
  166. <FormGroup>
  167. <FormControl name="cust_address" type="text" value={data.name}/>
  168. </FormGroup>
  169. <h5>Thamrin Indrapura Jl.Aipda Karel Satsuit Tubun,17 Ilir, Kec.Ilir Tim.I, Palembang, KOTA PALEMBANG - ILIR TIMUR II, SUMATERA SELATAN, ID 30114</h5>
  170. <Button1 color="info" href={"/yamaha/profile/edit-profile"}>
  171. <Icon className={classes.icons}>cached</Icon>
  172. Ubah Alamat
  173. </Button1>
  174. </div>
  175. </CardBody>
  176. </Card>
  177. </div>
  178. );
  179. })
  180. const CheckoutProdukPesanan = checkoutproduct.map((data) => {
  181. const handleChange = (event) => {
  182. setAge(event.target.value);
  183. };
  184. const handleChanges = (event) => {
  185. setPengiriman(event.target.value);
  186. };
  187. const [age, setAge] = React.useState('');
  188. const [pengiriman, setPengiriman] = React.useState('');
  189. return (
  190. <div align="center">
  191. <Card className={classes.textCenter} align="center">
  192. <CardBody>
  193. <div style={{padding:"10px"}}>
  194. <Typography variant="h6" align="left" className={classes.title}>
  195. Pesanan Produk
  196. </Typography><br></br><hr></hr>
  197. <GridContainer>
  198. <FormGroup>
  199. <FormControl name="product_img" type="text" value={data.name}/>
  200. </FormGroup>
  201. <Grid item xs>
  202. <div align="center">
  203. <h4>Produk Dipesan</h4>
  204. <img className={navImageClasses} width="200px" alt="First slide" src={`${backend}${data.img[0]["url"]}`} />
  205. </div>
  206. </Grid>
  207. <FormGroup>
  208. <FormControl name="product_name" type="text" value={data.name}/>
  209. </FormGroup>
  210. <Grid item xs>
  211. <div align="center">
  212. <h4></h4><br></br><br></br><br></br><br></br>
  213. <h5>{data.name}</h5>
  214. </div>
  215. </Grid>
  216. <FormGroup>
  217. <FormControl name="product_color" type="text" value={data.name}/>
  218. </FormGroup>
  219. <Grid item xs>
  220. <div align="center">
  221. <h4>Warna</h4><br></br><br></br><br></br>
  222. <FormControl className={classes.formControl}>
  223. <Select
  224. labelId="demo-simple-select-label"
  225. id="demo-simple-select"
  226. value={age}
  227. onChange={handleChange}
  228. >
  229. <MenuItem value={10}>Hitam</MenuItem>
  230. <MenuItem value={20}>Merah</MenuItem>
  231. <MenuItem value={30}>Biru</MenuItem>
  232. <MenuItem value={30}>Putih</MenuItem>
  233. </Select>
  234. </FormControl>
  235. </div>
  236. </Grid>
  237. <Grid item xs>
  238. <div align="center">
  239. <h4>Harga Satuan</h4><br></br><br></br><br></br>
  240. <h5>Rp.{data.price}</h5>
  241. </div>
  242. </Grid>
  243. <FormGroup>
  244. <FormControl name="product_quantity" type="text" value={data.name}/>
  245. </FormGroup>
  246. <Grid item xs>
  247. <div align="center">
  248. <h4>Jumlah Unit</h4><br></br><br></br><br></br>
  249. <FormControl className={classes.formControl}>
  250. <TextField
  251. id="outlined-number"
  252. type="number"
  253. align="center"
  254. name="quantity"
  255. InputLabelProps={{
  256. shrink: true,
  257. }}
  258. />
  259. </FormControl>
  260. </div>
  261. </Grid>
  262. <FormGroup>
  263. <FormControl name="product_price" type="text"/>
  264. </FormGroup>
  265. <Grid item xs>
  266. <div align="center">
  267. <h4>Sub Total Produk</h4><br></br><br></br><br></br>
  268. <h5>Total Rp.{data.price}</h5>
  269. </div>
  270. </Grid>
  271. </GridContainer>
  272. <GridContainer style={{padding:"20px"}}>
  273. <Grid item xs style={{padding:"20px"}}>
  274. <TextField
  275. id="outlined-full-width"
  276. label="Pesan"
  277. style={{ margin: 8 }}
  278. placeholder="( Opsional ) Tinggalkan Pesan Kepada Dealer"
  279. fullWidth
  280. margin="normal"
  281. InputLabelProps={{
  282. shrink: true,
  283. }}
  284. variant="outlined"
  285. />
  286. </Grid>
  287. <FormGroup>
  288. <FormControl name="product_courier" type="text" value={data.name}/>
  289. </FormGroup>
  290. <Grid item xs style={{padding:"20px"}}><br></br>
  291. <Button variant="outlined" color="primary" onClick={handleClickOpen}>
  292. Pilih Opsi Pengiriman
  293. </Button>
  294. <Dialog fullScreen open={open} onClose={handleClose} TransitionComponent={Transition}>
  295. <AppBar className={classes.appBar}>
  296. <Toolbar>
  297. <IconButton edge="start" color="inherit" onClick={handleClose} aria-label="close">
  298. <CloseIcon />
  299. </IconButton>
  300. <Typography variant="h6" className={classes.title}>
  301. Pilih Opsi Pengiriman
  302. </Typography>
  303. <Button autoFocus color="inherit" onClick={handleClose}>
  304. Pilih
  305. </Button>
  306. </Toolbar>
  307. </AppBar>
  308. <List>
  309. <ListItem button
  310. id="POS"
  311. onChange={handleChanges}
  312. >
  313. <ListItemText primary="POS" secondary="Akan diterima pada tanggal 2 Apr - 6 Apr" />
  314. </ListItem>
  315. <Divider />
  316. <ListItem button
  317. id="JNE"
  318. onChange={handleChanges}
  319. >
  320. <ListItemText primary="JNE" secondary="Akan diterima pada tanggal 30 Mar - 2 Apr" />
  321. </ListItem>
  322. <ListItem button
  323. id="TIKI"
  324. onChange={handleChanges}
  325. >
  326. <ListItemText primary="TIKI" secondary="Akan diterima pada tanggal 1 Apr - 4 Apr, COD (Bayar di Tempat) tidak didukung" />
  327. </ListItem>
  328. </List>
  329. </Dialog>
  330. </Grid>
  331. <Grid item xs align="right" style={{padding:"20px"}}><br></br>
  332. Total Rp. {data.price}
  333. </Grid>
  334. </GridContainer>
  335. </div>
  336. </CardBody>
  337. </Card>
  338. </div>
  339. );
  340. })
  341. return (
  342. <div style={{padding:"50px"}}>
  343. <script type="text/javascript" src="https://app.sandbox.midtrans.com/snap/snap.js" data-client-key="SB-Mid-client-srx674LjNbEybd4-"/>
  344. <div align="center" className={classes.section} id="notifications">
  345. <SnackbarContent
  346. message={
  347. <h2><b>Checkout</b></h2>
  348. }
  349. align="center"
  350. color="danger"
  351. />
  352. </div>
  353. <div>
  354. {CheckoutAlamat}
  355. </div>
  356. <div>
  357. {CheckoutProdukPesanan}
  358. </div>
  359. <div>
  360. <GridContainer>
  361. <Grid item xs={6} style={{padding:"20px"}}>
  362. <Button1 color="info" style={{width:"100%"}}
  363. onClick={async function (e) {
  364. // setFormValue({cust_name:"tes"});
  365. const response = await fetch(
  366. "/api/transaction/create",
  367. {
  368. method: "POST",
  369. headers: {
  370. 'Content-Type': 'application/json'
  371. },
  372. body: JSON.stringify({formValue}),
  373. }
  374. );
  375. if (response.ok) {
  376. var res = await response.json();
  377. if (res["STATUS"] === 1) {
  378. res["DATA"]["transaction"];
  379. swal("Transaksi Berhasil", "success");
  380. }
  381. else {
  382. swal("Transaksi Gagal", `${res["DATA"].message || res["DATA"] }`, "error");
  383. }
  384. } else {
  385. alert(`Transaksi Gagal 2. ${response.statusText} `);
  386. }
  387. }}
  388. >
  389. <Icon className={classes.icons}>attach_money</Icon>
  390. Buat Pesanan
  391. </Button1>
  392. </Grid>
  393. <Grid item xs={6} style={{padding:"20px"}}>
  394. <Button1 color="danger" style={{width:"100%"}}>
  395. <Icon className={classes.icons}>attach_money</Icon>
  396. Batalkan Pesanan
  397. </Button1>
  398. </Grid>
  399. </GridContainer>
  400. {/* <GridContainer>
  401. <Grid item xs={6} style={{padding:"20px"}}>
  402. <Button1 color="info" onClick={(e)=>{snap.pay(transactionToken);}} style={{width:"100%"}}>
  403. <Icon className={classes.icons}>attach_money</Icon>
  404. Bayar Pesanan
  405. </Button1>
  406. </Grid>
  407. </GridContainer> */}
  408. </div>
  409. </div>
  410. );
  411. }
  412. export default DataCheckout;