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

470 lines
20 KiB

  1. import React, { Component, Fragment } from 'react';
  2. import { withStyles, makeStyles } from '@material-ui/core/styles';
  3. import clsx from 'clsx';
  4. import Selects from 'react-select';
  5. import SnackbarContent from "components/Snackbar/SnackbarContent.js";
  6. import Button1 from "components/CustomButtons/Button.js";
  7. import image1 from "../../../assets/img/mail.png"
  8. import GridContainer from "components/Grid/GridContainer.js";
  9. import Carousel from "react-slick";
  10. import GridItem from "components/Grid/GridItem.js";
  11. import classNames from "classnames";
  12. import swal from 'sweetalert';
  13. import Icon from "@material-ui/core/Icon";
  14. import Grid from '@material-ui/core/Grid';
  15. import TextField from '@material-ui/core/TextField';
  16. import Typography from '@material-ui/core/Typography';
  17. import Slide from '@material-ui/core/Slide';
  18. import Select from '@material-ui/core/Select';
  19. import Card from "components/Card/Card.js";
  20. import CardBody from "components/Card/CardBody.js";
  21. import FormControl from '@material-ui/core/FormControl';
  22. import { Form, FormGroup, ControlLabel, SelectPicker } from "rsuite";
  23. import InputLabel from '@material-ui/core/InputLabel';
  24. import OutlinedInput from '@material-ui/core/OutlinedInput';
  25. import NumberFormat from 'react-number-format';
  26. import Table from '@material-ui/core/Table';
  27. import TableBody from '@material-ui/core/TableBody';
  28. import TableCell from '@material-ui/core/TableCell';
  29. import TableContainer from '@material-ui/core/TableContainer';
  30. import TableHead from '@material-ui/core/TableHead';
  31. import TableRow from '@material-ui/core/TableRow';
  32. import Paper from '@material-ui/core/Paper';
  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 StyledTableCell = withStyles((theme) => ({
  98. head: {
  99. backgroundColor: theme.palette.common.black,
  100. color: theme.palette.common.white,
  101. },
  102. body: {
  103. fontSize: 14,
  104. },
  105. }))(TableCell);
  106. const StyledTableRow = withStyles((theme) => ({
  107. root: {
  108. '&:nth-of-type(odd)': {
  109. backgroundColor: theme.palette.action.hover,
  110. },
  111. },
  112. }))(TableRow);
  113. const settings = {
  114. dots: true,
  115. infinite: true,
  116. speed: 500,
  117. slidesToShow: 1,
  118. slidesToScroll: 1,
  119. autoplay: false,
  120. time: 5
  121. };
  122. const classes = useStyles();
  123. const { ...rest } = props;
  124. const imageClasses = classNames(
  125. classes.imgRaised,
  126. classes.imgRoundedCircle,
  127. classes.imgFluid
  128. );
  129. const navImageClasses = classNames(classes.imgRounded, classes.imgGallery);
  130. const [formValue, setFormValue] = React.useState({
  131. order_id: GenerateID(),
  132. cust_name: "",
  133. cust_telp: "",
  134. cust_address: "",
  135. product_img: "",
  136. product_name: "",
  137. product_color: "",
  138. product_quantity: "",
  139. product_price: "",
  140. product_courier: "",
  141. note: "",
  142. status: 1,
  143. });
  144. // const [formValue, setFormValue] = React.useState({
  145. // order_id: "Trx-Ord-9ab8ab88",
  146. // cust_name: "Yusmar",
  147. // cust_telp: "087797315685",
  148. // 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",
  149. // product_img: null,
  150. // product_name: "NMAX 155",
  151. // product_color: "Red",
  152. // product_quantity: "1",
  153. // product_price: "28545000",
  154. // product_courier: "JNE",
  155. // note: "Tes",
  156. // });
  157. function GenerateID() {
  158. var dt = new Date().getTime();
  159. var uuid = 'Trx-Ord-yyyyyyyy'.replace(/[y]/g, function (c) {
  160. var r = (dt + Math.random() * 16) % 16 | 0;
  161. dt = Math.floor(dt / 16);
  162. return (c == 'x' ? r : (r & 0x3 | 0x8)).toString(16);
  163. });
  164. return uuid;
  165. }
  166. const CheckoutAlamat = checkoutprofile.map((data) => {
  167. return (
  168. <Card className={classes.textCenter} align="center">
  169. <TableContainer>
  170. <Table className={classes.table} aria-label="customized table">
  171. <TableHead>
  172. <TableRow>
  173. <StyledTableCell align="center">Nama Customer</StyledTableCell>
  174. <StyledTableCell align="center">Email Customer</StyledTableCell>
  175. <StyledTableCell align="center">No.Telp Customer</StyledTableCell>
  176. <StyledTableCell align="center">Alamat Customer</StyledTableCell>
  177. </TableRow>
  178. </TableHead>
  179. <TableBody>
  180. <StyledTableRow>
  181. <StyledTableCell align="center"><b>{data.username}</b></StyledTableCell>
  182. <StyledTableCell align="center"><b>{data.email}</b></StyledTableCell>
  183. <StyledTableCell align="center"><b>{data.telp}</b></StyledTableCell>
  184. <StyledTableCell align="center"><b>{data.address}</b></StyledTableCell>
  185. </StyledTableRow>
  186. </TableBody>
  187. </Table>
  188. </TableContainer>
  189. </Card>
  190. );
  191. })
  192. const CheckoutProdukPesanan = checkoutproduct.map((data) => {
  193. const [state, setState] = React.useState({
  194. warna: '',
  195. name: 'hai',
  196. });
  197. const handleChange = (event) => {
  198. const name = event.target.name;
  199. setState({
  200. ...state,
  201. [name]: event.target.value,
  202. });
  203. };
  204. return (
  205. <div align="center">
  206. <Card className={classes.textCenter} align="center">
  207. <TableContainer>
  208. <Table className={classes.table} aria-label="customized table">
  209. <TableHead>
  210. <TableRow>
  211. <StyledTableCell align="center">Produk Dipesan</StyledTableCell>
  212. <StyledTableCell align="center">Nama Produk</StyledTableCell>
  213. <StyledTableCell align="center">Warna</StyledTableCell>
  214. <StyledTableCell align="center">Harga Per Unit</StyledTableCell>
  215. <StyledTableCell align="center">Jumlah Unit</StyledTableCell>
  216. <StyledTableCell align="center">Subtotal Harga</StyledTableCell>
  217. </TableRow>
  218. </TableHead>
  219. <TableBody>
  220. <StyledTableRow>
  221. <StyledTableCell>
  222. <img className={navImageClasses} width="200px" alt="First slide" src={`${backend}${data.img[0]["url"]}`} />
  223. </StyledTableCell>
  224. <StyledTableCell align="center"><b>{data.name}</b></StyledTableCell>
  225. <StyledTableCell align="center">
  226. <FormControl variant="outlined" className={classes.formControl}>
  227. <InputLabel htmlFor="outlined-age-native-simple">Warna</InputLabel>
  228. <Select
  229. native
  230. value={state.warna}
  231. onChange={handleChange}
  232. label="Warna"
  233. name="product_color"
  234. inputProps={{
  235. name: 'warna',
  236. id: 'outlined-age-native-simple',
  237. }}
  238. onInput={(e)=>{
  239. setFormValue({
  240. ...formValue,
  241. product_color: e.target.value.toString()
  242. })
  243. }}
  244. >
  245. <option aria-label="None" value="" />
  246. <option value={"Hitam"}>Hitam</option>
  247. <option value={"Putih"}>Putih</option>
  248. <option value={"Merah"}>Merah</option>
  249. </Select>
  250. </FormControl>
  251. </StyledTableCell>
  252. <StyledTableCell align="center">
  253. <h5>
  254. <b><NumberFormat value={data.price} displayType={'text'} thousandSeparator={true} prefix={'Rp.'} /></b>
  255. </h5>
  256. </StyledTableCell>
  257. <StyledTableCell align="center">
  258. <TextField
  259. id="outlined-number"
  260. label="Number"
  261. type="number"
  262. name="quantity"
  263. InputLabelProps={{
  264. shrink: true,
  265. }}
  266. onInput={(e)=>{
  267. setFormValue({
  268. ...formValue,
  269. product_quantity: e.target.value
  270. })
  271. }}
  272. variant="outlined"
  273. />
  274. </StyledTableCell>
  275. <StyledTableCell align="center">
  276. <h5>
  277. <b><NumberFormat value={data.price} displayType={'text'} thousandSeparator={true} prefix={'Rp.'} /></b>
  278. </h5>
  279. </StyledTableCell>
  280. </StyledTableRow>
  281. </TableBody>
  282. </Table>
  283. </TableContainer>
  284. <TableContainer>
  285. <Table>
  286. <TableBody>
  287. <TableRow>
  288. <StyledTableCell align="center">
  289. <TextField
  290. id="outlined-full-width"
  291. label="Pesan"
  292. style={{ width: "550px" }}
  293. placeholder="( Opsional ) Tinggalkan Pesan Kepada Dealer"
  294. margin="normal"
  295. variant="outlined"
  296. onInput={(e)=>{
  297. setFormValue({
  298. ...formValue,
  299. note: e.target.value
  300. })
  301. }}
  302. />
  303. </StyledTableCell>
  304. <StyledTableCell align="center">
  305. <FormControl variant="outlined" className={classes.formControl}>
  306. <InputLabel htmlFor="outlined-age-native-simple">Pilih Ekspedisi Pengiriman</InputLabel>
  307. <Select
  308. native
  309. style={{ width: "550px" }}
  310. value={state.age}
  311. onChange={handleChange}
  312. label="Pilih Ekspedisi Pengiriman"
  313. inputProps={{
  314. name: 'age',
  315. id: 'outlined-age-native-simple',
  316. }}
  317. onInput={(e)=>{
  318. setFormValue({
  319. ...formValue,
  320. product_courier: e.target.value
  321. })
  322. }}
  323. >
  324. <option aria-label="None" value="" />
  325. <option value={"JNE"}>JNE</option>
  326. <option value={"Antar Aja"}>Antar Aja</option>
  327. <option value={"TIKI"}>TIKI</option>
  328. </Select>
  329. </FormControl>
  330. </StyledTableCell>
  331. </TableRow>
  332. </TableBody>
  333. </Table>
  334. </TableContainer>
  335. </Card>
  336. </div>
  337. );
  338. })
  339. return (
  340. <div style={{ padding: "50px" }}>
  341. <div align="center" className={classes.section} id="notifications">
  342. <SnackbarContent
  343. message={
  344. <h2><b>Checkout</b></h2>
  345. }
  346. align="center"
  347. color="info"
  348. />
  349. </div>
  350. <Form
  351. onSubmit={async (value) => {
  352. var newformValue = {
  353. ...formValue,
  354. cust_name: checkoutprofile[0].username,
  355. cust_telp: checkoutprofile[0].telp.toString(),
  356. cust_address: checkoutprofile[0].address,
  357. product_img: checkoutproduct.img,
  358. product_name: checkoutproduct[0].name,
  359. product_price: checkoutproduct[0].price,
  360. }
  361. setFormValue(newformValue)
  362. const response = await fetch(
  363. "/api/transaction/create",
  364. {
  365. method: "POST",
  366. headers: {
  367. 'Content-Type': 'application/json'
  368. },
  369. body: JSON.stringify(newformValue),
  370. }
  371. );
  372. if (response.ok) {
  373. var res = await response.json();
  374. if (res["STATUS"] === 1) {
  375. res["DATA"]["transaction"];
  376. swal("Produk Berhasil Ditambah ke Keranjang", "Silahkan Cek Keranjang Belanja Anda", "success");
  377. }
  378. else {
  379. swal("Produk Gagal Ditambah ke Keranjang", "Silahkan Coba Lagi", "error");
  380. }
  381. } else {
  382. swal("Transaksi Gagal", "Silahkan Coba Lagi", "error");
  383. }
  384. }}
  385. >
  386. <div>
  387. {CheckoutAlamat}
  388. </div>
  389. <div>
  390. {CheckoutProdukPesanan}
  391. </div>
  392. <div>
  393. <GridContainer>
  394. <Grid item xs={6} style={{ padding: "20px" }}>
  395. <Button1 color="info" style={{ width: "100%" }}
  396. type="submit"
  397. // onClick={async function (e) {
  398. // // setFormValue({
  399. // // cust_name : data.username,
  400. // // ... formValue
  401. // // });
  402. //
  403. // }}
  404. >
  405. <Icon className={classes.icons}>attach_money</Icon>
  406. Buat Pesanan
  407. </Button1>
  408. </Grid>
  409. <Grid item xs={6} style={{ padding: "20px" }}>
  410. <Button1 color="danger" style={{ width: "100%" }}
  411. // swal({
  412. // title: "Anda Ingin Menghapus Pesanan ?",
  413. // icon: "warning",
  414. // buttons: true,
  415. // dangerMode: true,
  416. // })
  417. // .then((willDelete) => {
  418. // if (willDelete) {
  419. // swal("Pesanan Anda Berhasil Dihapus", {
  420. // icon: "success",
  421. // });
  422. // } else {
  423. // swal("Selamat Belanja Kembali");
  424. // }
  425. // });
  426. >
  427. <Icon className={classes.icons}>attach_money</Icon>
  428. Batalkan Pesanan
  429. </Button1>
  430. </Grid>
  431. </GridContainer>
  432. {/* <GridContainer>
  433. <Grid item xs={6} style={{padding:"20px"}}>
  434. <Button1 color="info" onClick={(e)=>{snap.pay(transactionToken);}} style={{width:"100%"}}>
  435. <Icon className={classes.icons}>attach_money</Icon>
  436. Bayar Pesanan
  437. </Button1>
  438. </Grid>
  439. </GridContainer> */}
  440. </div>
  441. </Form>
  442. </div>
  443. );
  444. }
  445. export default DataCheckout;