Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

ShippingContent.jsx 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 DataCard from '../cards/data-card/DataCard';
  12. import StepTitle from '../layout/steps-title/StepTitle';
  13. import ButtonGroup from './shipping-btnGroup/ButtonGroup';
  14. import ShippingData from './shipping-data/ShippingData';
  15. import ShippingModal from './shipping-modal/ShippingModal';
  16. const ShippingContent = () => {
  17. const { checkoutStorage } = useCheckoutData();
  18. const { changeContact, changeShippingData } = useCheckoutDataUpdate();
  19. const [open, setOpen] = useState({ isOpen: false, type: '' });
  20. const router = useRouter();
  21. const handleOpen = (type) => setOpen({ isOpen: true, type });
  22. const handleClose = () => setOpen({ isOpen: false, type: '' });
  23. const handleChangeShipping = (values) => {
  24. changeShippingData(values);
  25. handleClose();
  26. };
  27. const handleChangeContact = (values) => {
  28. changeContact(values);
  29. handleClose();
  30. };
  31. const handleStripePayment = () => {
  32. stripe({
  33. lineItems: [
  34. {
  35. price: 'price_1Lg4MsDY7dvAcw2f1CGQaFFR',
  36. quantity: 1,
  37. },
  38. ],
  39. });
  40. setCookie(null, 'review-session', 'active', {
  41. maxAge: 3600,
  42. expires: new Date(Date.now() + 3600),
  43. path: '/',
  44. });
  45. };
  46. const handleBackToCart = () => {
  47. router.replace('/cart');
  48. };
  49. const mapProductsToDom = () => {
  50. return checkoutStorage?.products?.map((entry, i) => (
  51. <DataCard
  52. key={i}
  53. data={entry.product}
  54. quantity={entry.quantity}
  55. ></DataCard>
  56. ));
  57. };
  58. return (
  59. <Grid container spacing={2} sx={{ py: 10, height: '100%', width: '100%' }}>
  60. <StepTitle
  61. title="Shipping"
  62. breadcrumbsArray={['Cart', 'Checkout', 'Shipping']}
  63. />
  64. <Grid item xs={12} sx={{ mt: 1 }}>
  65. <Typography sx={{ pl: 12, fontSize: 20 }}>
  66. The following fields will be used as the shipping details for your
  67. order
  68. </Typography>
  69. </Grid>
  70. <Grid item xs={8}>
  71. <ShippingData
  72. email={checkoutStorage?.userInfo?.email}
  73. address={checkoutStorage?.userInfo?.address}
  74. city={checkoutStorage?.userInfo?.city}
  75. postcode={checkoutStorage?.userInfo?.postcode}
  76. handleOpen={handleOpen}
  77. />
  78. <Box
  79. sx={{
  80. display: 'flex',
  81. justifyContent: 'space-between',
  82. backgroundColor: '#f2f2f2',
  83. alignItems: 'center',
  84. ml: 12,
  85. mb: 2,
  86. width: '30%',
  87. borderRadius: 2,
  88. p: 1,
  89. }}
  90. >
  91. <FormControlLabel
  92. control={<Checkbox checked disabled />}
  93. label="Free Shipping"
  94. sx={{ color: 'black', ml: 2 }}
  95. />
  96. </Box>
  97. <ButtonGroup
  98. handleStripePayment={handleStripePayment}
  99. handleBackToCart={handleBackToCart}
  100. />
  101. </Grid>
  102. <Grid item xs={4}>
  103. <Box sx={{ width: '80%', mt: 2 }}>{mapProductsToDom()}</Box>
  104. </Grid>
  105. <ShippingModal
  106. open={open}
  107. handleClose={handleClose}
  108. handleChangeShipping={handleChangeShipping}
  109. handleChangeContact={handleChangeContact}
  110. />
  111. </Grid>
  112. );
  113. };
  114. export default ShippingContent;