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

ShippingContent.jsx 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import { Checkbox, FormControlLabel, Grid, 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. const handleStripePayment = () => {
  33. stripe({
  34. lineItems: [
  35. {
  36. price: 'price_1Lg4MsDY7dvAcw2f1CGQaFFR',
  37. quantity: 1,
  38. },
  39. ],
  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. <Grid container spacing={2} sx={{ py: 10, height: '100%', width: '100%' }}>
  61. <StepTitle
  62. title="Shipping"
  63. breadcrumbsArray={['Cart', 'Checkout', 'Shipping']}
  64. />
  65. <Grid item xs={12} sx={{ mt: 1 }}>
  66. <Typography sx={{ pl: 12, fontSize: 20 }}>
  67. The following fields will be used as the shipping details for your
  68. order
  69. </Typography>
  70. </Grid>
  71. <Grid item xs={12} lg={8}>
  72. <ShippingData
  73. email={checkoutStorage?.userInfo?.email}
  74. address={checkoutStorage?.userInfo?.address}
  75. city={checkoutStorage?.userInfo?.city}
  76. postcode={checkoutStorage?.userInfo?.postcode}
  77. handleOpen={handleOpen}
  78. />
  79. <Box
  80. sx={{
  81. display: 'flex',
  82. justifyContent: 'space-between',
  83. backgroundColor: '#f2f2f2',
  84. alignItems: 'center',
  85. ml: 12,
  86. mb: 2,
  87. width: '30%',
  88. borderRadius: 2,
  89. p: 1,
  90. }}
  91. >
  92. <FormControlLabel
  93. control={<Checkbox checked disabled />}
  94. label="Free Shipping"
  95. sx={{ color: 'black', ml: 2 }}
  96. />
  97. </Box>
  98. <ButtonGroup
  99. handleStripePayment={handleStripePayment}
  100. handleBackToCart={handleBackToCart}
  101. />
  102. </Grid>
  103. <Grid item xs={12} lg={4}>
  104. <Box
  105. sx={{
  106. width: '80%',
  107. mt: 2,
  108. height: '100%',
  109. ml: { xs: 12, lg: 0 },
  110. display: { lg: 'block', xs: 'flex' },
  111. flexWrap: { xs: 'wrap', lg: 'none' },
  112. justifyContent: { xs: 'center', lg: 'none' },
  113. }}
  114. >
  115. {mapProductsToDom()}
  116. </Box>
  117. </Grid>
  118. <ShippingModal
  119. open={open}
  120. handleClose={handleClose}
  121. handleChangeShipping={handleChangeShipping}
  122. handleChangeContact={handleChangeContact}
  123. />
  124. </Grid>
  125. );
  126. };
  127. export default ShippingContent;