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.
 
 

408 line
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 classNames from "classnames";
  9. import swal from 'sweetalert';
  10. import Icon from "@material-ui/core/Icon";
  11. import Grid from '@material-ui/core/Grid';
  12. import TextField from '@material-ui/core/TextField';
  13. import Button from '@material-ui/core/Button';
  14. import Dialog from '@material-ui/core/Dialog';
  15. import ListItemText from '@material-ui/core/ListItemText';
  16. import ListItem from '@material-ui/core/ListItem';
  17. import List from '@material-ui/core/List';
  18. import Divider from '@material-ui/core/Divider';
  19. import AppBar from '@material-ui/core/AppBar';
  20. import Toolbar from '@material-ui/core/Toolbar';
  21. import IconButton from '@material-ui/core/IconButton';
  22. import Typography from '@material-ui/core/Typography';
  23. import CloseIcon from '@material-ui/icons/Close';
  24. import Slide from '@material-ui/core/Slide';
  25. import Select from '@material-ui/core/Select';
  26. import MenuItem from '@material-ui/core/MenuItem';
  27. import Card from "components/Card/Card.js";
  28. import CardBody from "components/Card/CardBody.js";
  29. import FormControl from '@material-ui/core/FormControl';
  30. import { FormGroup } from "rsuite";
  31. const useStyles = makeStyles((theme) => ({
  32. root: {
  33. width: '100%',
  34. },
  35. button: {
  36. marginTop: theme.spacing(1),
  37. marginRight: theme.spacing(1),
  38. },
  39. actionsContainer: {
  40. marginBottom: theme.spacing(2),
  41. },
  42. resetContainer: {
  43. padding: theme.spacing(3),
  44. },
  45. appBar: {
  46. position: 'relative',
  47. },
  48. title: {
  49. marginLeft: theme.spacing(2),
  50. flex: 1,
  51. },
  52. root: {
  53. '&:hover': {
  54. backgroundColor: 'transparent',
  55. },
  56. },
  57. icon: {
  58. borderRadius: '50%',
  59. width: 16,
  60. height: 16,
  61. boxShadow: 'inset 0 0 0 1px rgba(16,22,26,.2), inset 0 -1px 0 rgba(16,22,26,.1)',
  62. backgroundColor: '#f5f8fa',
  63. backgroundImage: 'linear-gradient(180deg,hsla(0,0%,100%,.8),hsla(0,0%,100%,0))',
  64. '$root.Mui-focusVisible &': {
  65. outline: '2px auto rgba(19,124,189,.6)',
  66. outlineOffset: 2,
  67. },
  68. 'input:hover ~ &': {
  69. backgroundColor: '#ebf1f5',
  70. },
  71. 'input:disabled ~ &': {
  72. boxShadow: 'none',
  73. background: 'rgba(206,217,224,.5)',
  74. },
  75. },
  76. checkedIcon: {
  77. backgroundColor: '#137cbd',
  78. backgroundImage: 'linear-gradient(180deg,hsla(0,0%,100%,.1),hsla(0,0%,100%,0))',
  79. '&:before': {
  80. display: 'block',
  81. width: 16,
  82. height: 16,
  83. backgroundImage: 'radial-gradient(#fff,#fff 28%,transparent 32%)',
  84. content: '""',
  85. },
  86. 'input:hover ~ &': {
  87. backgroundColor: '#106ba3',
  88. },
  89. },
  90. }));
  91. const Transition = React.forwardRef(function Transition(props, ref) {
  92. return <Slide direction="up" ref={ref} {...props} />;
  93. });
  94. const DataCheckout = function ({ province, cities, midtransClient, backend, checkoutproduct, transactionToken, ...props }) {
  95. console.log('Token :',transactionToken);
  96. const classes = useStyles();
  97. const [open, setOpen] = React.useState(false);
  98. const handleClickOpen = () => {
  99. setOpen(true);
  100. };
  101. const handleClose = () => {
  102. setOpen(false);
  103. };
  104. const { ...rest } = props;
  105. const imageClasses = classNames(
  106. classes.imgRaised,
  107. classes.imgRoundedCircle,
  108. classes.imgFluid
  109. );
  110. const navImageClasses = classNames(classes.imgRounded, classes.imgGallery);
  111. const [formValue, setFormValue] = React.useState({
  112. cust_name: "cust_name",
  113. cust_telp: null,
  114. cust_address: null,
  115. product_img: null,
  116. product_name: null,
  117. product_color: null,
  118. product_quantity: null,
  119. product_price: null,
  120. product_courier: null,
  121. });
  122. function create_UUID(){
  123. var dt = new Date().getTime();
  124. var uuid = 'Order-ID-xxxxxxxx'.replace(/[x]/g, function(c) {
  125. var r = (dt + Math.random()*16)%16 | 0;
  126. dt = Math.floor(dt/16);
  127. return (c=='x' ? r :(r&0x3|0x8)).toString(16);
  128. });
  129. return uuid;
  130. }
  131. console.log(create_UUID);
  132. const CheckoutAlamat = checkoutproduct.map((data) => {
  133. return (
  134. <div align="center">
  135. <Card className={classes.textCenter} align="center">
  136. <CardBody>
  137. <div style={{padding:"10px"}}>
  138. <Typography variant="h6" align="left" className={classes.title}>
  139. Alamat Pengiriman
  140. </Typography><br></br>
  141. <img src={image1} style={{width:"1100px"}}/><br></br>
  142. <FormGroup>
  143. <FormControl name="cust_name" type="text" value={data.name}/>
  144. </FormGroup>
  145. <h5>{data.name}</h5>
  146. <FormGroup>
  147. <FormControl name="cust_telp" type="text"/>
  148. </FormGroup>
  149. <h5>087797315685</h5>
  150. <FormGroup>
  151. <FormControl name="cust_address" type="text" value={data.name}/>
  152. </FormGroup>
  153. <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>
  154. <Button1 color="info" href={"/yamaha/profile/edit-profile"}>
  155. <Icon className={classes.icons}>cached</Icon>
  156. Ubah Alamat
  157. </Button1>
  158. </div>
  159. </CardBody>
  160. </Card>
  161. </div>
  162. );
  163. })
  164. const CheckoutProdukPesanan = checkoutproduct.map((data) => {
  165. const handleChange = (event) => {
  166. setAge(event.target.value);
  167. };
  168. const handleChanges = (event) => {
  169. setPengiriman(event.target.value);
  170. };
  171. const [age, setAge] = React.useState('');
  172. const [pengiriman, setPengiriman] = React.useState('');
  173. return (
  174. <div align="center">
  175. <Card className={classes.textCenter} align="center">
  176. <CardBody>
  177. <div style={{padding:"10px"}}>
  178. <Typography variant="h6" align="left" className={classes.title}>
  179. Pesanan Produk
  180. </Typography><br></br><hr></hr>
  181. <GridContainer>
  182. <FormGroup>
  183. <FormControl name="product_img" type="text" value={data.name}/>
  184. </FormGroup>
  185. <Grid item xs>
  186. <div align="center">
  187. <h4>Produk Dipesan</h4>
  188. <img className={navImageClasses} width="200px" alt="First slide" src={`${backend}${data.img[0]["url"]}`} />
  189. </div>
  190. </Grid>
  191. <FormGroup>
  192. <FormControl name="product_name" type="text" value={data.name}/>
  193. </FormGroup>
  194. <Grid item xs>
  195. <div align="center">
  196. <h4></h4><br></br><br></br><br></br><br></br>
  197. <h5>{data.name}</h5>
  198. </div>
  199. </Grid>
  200. <FormGroup>
  201. <FormControl name="product_color" type="text" value={data.name}/>
  202. </FormGroup>
  203. <Grid item xs>
  204. <div align="center">
  205. <h4>Warna</h4><br></br><br></br><br></br>
  206. <FormControl className={classes.formControl}>
  207. <Select
  208. labelId="demo-simple-select-label"
  209. id="demo-simple-select"
  210. value={age}
  211. onChange={handleChange}
  212. >
  213. <MenuItem value={10}>Hitam</MenuItem>
  214. <MenuItem value={20}>Merah</MenuItem>
  215. <MenuItem value={30}>Biru</MenuItem>
  216. <MenuItem value={30}>Putih</MenuItem>
  217. </Select>
  218. </FormControl>
  219. </div>
  220. </Grid>
  221. <Grid item xs>
  222. <div align="center">
  223. <h4>Harga Satuan</h4><br></br><br></br><br></br>
  224. <h5>Rp.{data.price}</h5>
  225. </div>
  226. </Grid>
  227. <FormGroup>
  228. <FormControl name="product_quantity" type="text" value={data.name}/>
  229. </FormGroup>
  230. <Grid item xs>
  231. <div align="center">
  232. <h4>Jumlah Unit</h4><br></br><br></br><br></br>
  233. <FormControl className={classes.formControl}>
  234. <TextField
  235. id="outlined-number"
  236. type="number"
  237. align="center"
  238. name="quantity"
  239. InputLabelProps={{
  240. shrink: true,
  241. }}
  242. />
  243. </FormControl>
  244. </div>
  245. </Grid>
  246. <FormGroup>
  247. <FormControl name="product_price" type="text"/>
  248. </FormGroup>
  249. <Grid item xs>
  250. <div align="center">
  251. <h4>Sub Total Produk</h4><br></br><br></br><br></br>
  252. <h5>Total Rp.{data.price}</h5>
  253. </div>
  254. </Grid>
  255. </GridContainer>
  256. <GridContainer style={{padding:"20px"}}>
  257. <Grid item xs style={{padding:"20px"}}>
  258. <TextField
  259. id="outlined-full-width"
  260. label="Pesan"
  261. style={{ margin: 8 }}
  262. placeholder="( Opsional ) Tinggalkan Pesan Kepada Dealer"
  263. fullWidth
  264. margin="normal"
  265. InputLabelProps={{
  266. shrink: true,
  267. }}
  268. variant="outlined"
  269. />
  270. </Grid>
  271. <FormGroup>
  272. <FormControl name="product_courier" type="text" value={data.name}/>
  273. </FormGroup>
  274. <Grid item xs style={{padding:"20px"}}><br></br>
  275. <Button variant="outlined" color="primary" onClick={handleClickOpen}>
  276. Pilih Opsi Pengiriman
  277. </Button>
  278. <Dialog fullScreen open={open} onClose={handleClose} TransitionComponent={Transition}>
  279. <AppBar className={classes.appBar}>
  280. <Toolbar>
  281. <IconButton edge="start" color="inherit" onClick={handleClose} aria-label="close">
  282. <CloseIcon />
  283. </IconButton>
  284. <Typography variant="h6" className={classes.title}>
  285. Pilih Opsi Pengiriman
  286. </Typography>
  287. <Button autoFocus color="inherit" onClick={handleClose}>
  288. Pilih
  289. </Button>
  290. </Toolbar>
  291. </AppBar>
  292. <List>
  293. <ListItem button
  294. id="POS"
  295. onChange={handleChanges}
  296. >
  297. <ListItemText primary="POS" secondary="Akan diterima pada tanggal 2 Apr - 6 Apr" />
  298. </ListItem>
  299. <Divider />
  300. <ListItem button
  301. id="JNE"
  302. onChange={handleChanges}
  303. >
  304. <ListItemText primary="JNE" secondary="Akan diterima pada tanggal 30 Mar - 2 Apr" />
  305. </ListItem>
  306. <ListItem button
  307. id="TIKI"
  308. onChange={handleChanges}
  309. >
  310. <ListItemText primary="TIKI" secondary="Akan diterima pada tanggal 1 Apr - 4 Apr, COD (Bayar di Tempat) tidak didukung" />
  311. </ListItem>
  312. </List>
  313. </Dialog>
  314. </Grid>
  315. <Grid item xs align="right" style={{padding:"20px"}}><br></br>
  316. Total Rp. {data.price}
  317. </Grid>
  318. </GridContainer>
  319. </div>
  320. </CardBody>
  321. </Card>
  322. </div>
  323. );
  324. })
  325. return (
  326. <div style={{padding:"50px"}}>
  327. <script type="text/javascript" src="https://app.sandbox.midtrans.com/snap/snap.js" data-client-key="SB-Mid-client-srx674LjNbEybd4-"/>
  328. <div align="center" className={classes.section} id="notifications">
  329. <SnackbarContent
  330. message={
  331. <h2><b>Checkout</b></h2>
  332. }
  333. align="center"
  334. color="danger"
  335. />
  336. </div>
  337. <div>
  338. {CheckoutAlamat}
  339. </div>
  340. <div>
  341. {CheckoutProdukPesanan}
  342. </div>
  343. <div>
  344. <GridContainer>
  345. <Grid item xs={6} style={{padding:"20px"}}>
  346. <Button1 color="info" style={{width:"100%"}}
  347. onClick={async function (e) {
  348. // setFormValue({cust_name:"tes"});
  349. const response = await fetch(
  350. "/api/transaction/create",
  351. {
  352. method: "POST",
  353. headers: {
  354. 'Content-Type': 'application/json'
  355. },
  356. body: JSON.stringify({formValue}),
  357. }
  358. );
  359. if (response.ok) {
  360. var res = await response.json();
  361. if (res["STATUS"] === 1) {
  362. res["DATA"]["transaction"];
  363. swal("Transaksi Berhasil", "success");
  364. }
  365. else {
  366. swal("Transaksi Gagal", `${res["DATA"].message || res["DATA"] }`, "error");
  367. }
  368. } else {
  369. alert(`Transaksi Gagal 2. ${response.statusText} `);
  370. }
  371. }}
  372. >
  373. <Icon className={classes.icons}>attach_money</Icon>
  374. Buat Pesanan
  375. </Button1>
  376. </Grid>
  377. <Grid item xs={6} style={{padding:"20px"}}>
  378. <Button1 color="danger" style={{width:"100%"}}>
  379. <Icon className={classes.icons}>attach_money</Icon>
  380. Batalkan Pesanan
  381. </Button1>
  382. </Grid>
  383. </GridContainer>
  384. {/* <GridContainer>
  385. <Grid item xs={6} style={{padding:"20px"}}>
  386. <Button1 color="info" onClick={(e)=>{snap.pay(transactionToken);}} style={{width:"100%"}}>
  387. <Icon className={classes.icons}>attach_money</Icon>
  388. Bayar Pesanan
  389. </Button1>
  390. </Grid>
  391. </GridContainer> */}
  392. </div>
  393. </div>
  394. );
  395. }
  396. export default DataCheckout;