Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ShippingContent.jsx 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. import { Checkbox, FormControlLabel, Typography } from '@mui/material';
  2. import { Box } from '@mui/system';
  3. import { useRouter } from 'next/router';
  4. import { setCookie } from 'nookies';
  5. import { useState } from 'react';
  6. import {
  7. useCheckoutData,
  8. useCheckoutDataUpdate,
  9. } from '../../store/checkout-context';
  10. import { stripe } from '../../utils/helpers/stripe';
  11. //import DataCardS from '../cards/data-card-shipping/DataCardS';
  12. import DataCard from '../cards/data-card/DataCard';
  13. import StepTitle from '../layout/steps-title/StepTitle';
  14. import ButtonGroup from './shipping-btnGroup/ButtonGroup';
  15. import ShippingData from './shipping-data/ShippingData';
  16. import ShippingModal from './shipping-modal/ShippingModal';
  17. const ShippingContent = () => {
  18. const { checkoutStorage } = useCheckoutData();
  19. const { changeContact, changeShippingData } = useCheckoutDataUpdate();
  20. const [open, setOpen] = useState({ isOpen: false, type: '' });
  21. const router = useRouter();
  22. const handleOpen = (type) => setOpen({ isOpen: true, type });
  23. const handleClose = () => setOpen({ isOpen: false, type: '' });
  24. const handleChangeShipping = (values) => {
  25. changeShippingData(values);
  26. handleClose();
  27. };
  28. const handleChangeContact = (values) => {
  29. changeContact(values);
  30. handleClose();
  31. };
  32. console.log(checkoutStorage);
  33. const handleStripePayment = () => {
  34. stripe({
  35. lineItems: checkoutStorage.products.map((el) => ({
  36. price: el.product.stripeID,
  37. quantity: el.quantity,
  38. })),
  39. userInfo: checkoutStorage.userInfo,
  40. });
  41. setCookie(null, 'review-session', 'active', {
  42. maxAge: 3600,
  43. expires: new Date(Date.now() + 3600),
  44. path: '/',
  45. });
  46. };
  47. const handleBackToCart = () => {
  48. router.replace('/cart');
  49. };
  50. const mapProductsToDom = () => {
  51. return checkoutStorage?.products?.map((entry, i) => (
  52. <DataCard
  53. key={i}
  54. data={entry.product}
  55. quantity={entry.quantity}
  56. ></DataCard>
  57. ));
  58. };
  59. return (
  60. <Box container spacing={2} sx={{ py: 10, height: '100%', width: '100%' }}>
  61. <StepTitle
  62. title="Shipping"
  63. breadcrumbsArray={['Cart', 'Checkout', 'Shipping']}
  64. />
  65. <Box sx={{ ml: { xs: 2, md: 12 }, my: 2 }}>
  66. <Typography sx={{ fontSize: 20 }}>
  67. The following fields will be used as the shipping details for your
  68. order
  69. </Typography>
  70. </Box>
  71. <Box
  72. sx={{
  73. display: 'flex',
  74. flexDirection: { xs: 'column', lg: 'row' },
  75. mr: { xs: 2, md: 12 },
  76. }}
  77. >
  78. <Box flexGrow={1} sx={{ minWidth: '65%', ml: { xs: 2, md: 12 } }}>
  79. <ShippingData
  80. email={checkoutStorage?.userInfo?.email}
  81. address={checkoutStorage?.userInfo?.address}
  82. city={checkoutStorage?.userInfo?.city}
  83. postcode={checkoutStorage?.userInfo?.postcode}
  84. handleOpen={handleOpen}
  85. />
  86. <Box
  87. sx={{
  88. display: 'flex',
  89. justifyContent: 'space-between',
  90. backgroundColor: '#f2f2f2',
  91. alignItems: 'center',
  92. mb: 2,
  93. width: { sm: '200px' },
  94. borderRadius: 2,
  95. p: 1,
  96. }}
  97. >
  98. <FormControlLabel
  99. control={<Checkbox checked disabled />}
  100. label="Free Shipping"
  101. sx={{ color: 'black', ml: 2 }}
  102. />
  103. </Box>
  104. <ButtonGroup
  105. handleStripePayment={handleStripePayment}
  106. handleBackToCart={handleBackToCart}
  107. />
  108. </Box>
  109. <Box
  110. sx={{
  111. ml: { xs: 2, md: 12, lg: 2 },
  112. mt: { xs: 5, md: 5, lg: 2 },
  113. display: 'flex',
  114. flexDirection: { xs: 'column', sm: 'row', lg: 'column' },
  115. justifyContent: { sm: 'flex-start' },
  116. flexWrap: 'wrap',
  117. }}
  118. >
  119. {mapProductsToDom()}
  120. </Box>
  121. </Box>
  122. <ShippingModal
  123. open={open}
  124. handleClose={handleClose}
  125. handleChangeShipping={handleChangeShipping}
  126. handleChangeContact={handleChangeContact}
  127. />
  128. </Box>
  129. );
  130. };
  131. export default ShippingContent;