BlockTotal.jsx 2.5 KB

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