BlockTotal.jsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import React from 'react';
  2. import {Box, Button, Divider, Typography} from "@mui/material";
  3. import {connect} from "react-redux";
  4. import {TotalPriceLine} from "./TotalPriceLine";
  5. const BlockTotal = ({auth ,cart, rows, onOrderUpsert, onCartClear}) => {
  6. return (
  7. <>
  8. <Typography
  9. padding='20px'
  10. variant='h4'
  11. fontFamily='sarif'
  12. letterSpacing='2px'
  13. textAlign='center'
  14. >
  15. TOTAL
  16. </Typography>
  17. <Divider/>
  18. <TotalPriceLine
  19. title={`${rows.length || 1} goods for the amount`}
  20. subtitle={`$${rows.reduce((a, i) => a + (i.good.price * i.count), 0)}`}
  21. />
  22. <TotalPriceLine
  23. title={'Cost of delivery'}
  24. subtitle={'according to the carrier\'s tariffs'}
  25. />
  26. <Divider/>
  27. <TotalPriceLine
  28. title={'To pay'}
  29. subtitle={`$${rows.reduce((a, i) => a + (i.good.price * i.count), 0)}`} sizeSubtitle={'h6'}
  30. />
  31. <Divider sx={{marginBottom: '20px'}}/>
  32. <Box
  33. display='flex'
  34. justifyContent='center'
  35. flexDirection='column'
  36. alignItems='center'
  37. >
  38. <Button
  39. sx={{
  40. borderRadius: '0',
  41. width:'80%',
  42. padding: '10px 20px',
  43. marginBottom: '20px'
  44. }}
  45. color='success'
  46. variant="outlined"
  47. onClick={() => {onOrderUpsert(cart); onCartClear()}}
  48. disabled={Object.entries(auth).length === 0}
  49. >
  50. {
  51. Object.entries(auth).length === 0 ?
  52. 'you need to log in'
  53. : 'confirm the order'
  54. }
  55. </Button>
  56. <Button
  57. sx={{
  58. borderRadius: '0',
  59. width:'80%',
  60. padding: '10px 20px'
  61. }}
  62. color='warning'
  63. variant="outlined"
  64. onClick={() => onCartClear()}
  65. >
  66. cart clear
  67. </Button>
  68. </Box>
  69. </>
  70. )
  71. }
  72. export const CBlockTotal = connect(state=>({auth: state.auth}))(BlockTotal)