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.

ProfileContent.jsx 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import { Alert, Snackbar, Typography } from '@mui/material';
  2. import { Box } from '@mui/system';
  3. import { useSession } from 'next-auth/react';
  4. import { useState } from 'react';
  5. import { updateUser } from '../../requests/user/userUpdateRequest';
  6. import { useUserUpdate } from '../../store/user-context';
  7. import OrderCard from '../cards/order-card/OrderCard';
  8. import ShippingDetailsForm from '../forms/shipping-details/ShippingDetailsForm';
  9. import StepTitle from '../layout/steps-title/StepTitle';
  10. const ProfileContent = ({ orders }) => {
  11. const { data: session } = useSession();
  12. const { updateUserInfo } = useUserUpdate();
  13. const [enableBtn, setEnableBtn] = useState(true);
  14. const [open, setOpen] = useState(false);
  15. const updateUserHandler = async (values) => {
  16. try {
  17. setEnableBtn(false);
  18. updateUserInfo(values);
  19. await updateUser(values, session.user._id);
  20. setOpen(true);
  21. setTimeout(() => {
  22. setEnableBtn(true);
  23. }, 5000);
  24. } catch (error) {
  25. console.log(error);
  26. setTimeout(() => {
  27. setEnableBtn(true);
  28. }, 3000);
  29. }
  30. };
  31. const handleCloseNotification = () => {
  32. setOpen(false);
  33. };
  34. const mapOrdersToDom = () =>
  35. orders.slice(-4).map((order, i) => (
  36. <OrderCard
  37. key={i}
  38. data={{
  39. date: order.time.split('T')[0],
  40. name: order.shippingAddress.fullName,
  41. totalPrice: order.totalPrice,
  42. }}
  43. ></OrderCard>
  44. ));
  45. return (
  46. <Box sx={{ py: 10, height: '100%', width: '100%' }}>
  47. <StepTitle title="Items in Your Cart" />
  48. <Snackbar
  49. anchorOrigin={{ vertical: 'top', horizontal: 'center' }}
  50. open={open}
  51. autoHideDuration={3000}
  52. onClose={handleCloseNotification}
  53. >
  54. <Alert
  55. onClose={handleCloseNotification}
  56. severity="success"
  57. sx={{ width: '100%', backgroundColor: 'green', color: 'white' }}
  58. >
  59. User profile updated!
  60. </Alert>
  61. </Snackbar>
  62. <Box
  63. sx={{
  64. display: 'flex',
  65. flexDirection: { xs: 'column', md: 'row' },
  66. mr: { xs: 2, md: 12 },
  67. ml: { xs: 2, md: 12 },
  68. }}
  69. >
  70. <Box
  71. sx={{
  72. width: { xs: '100%', md: '100%' },
  73. mt: 2,
  74. mr: { md: 2 },
  75. mb: { xs: 6 },
  76. }}
  77. >
  78. <Typography sx={{ fontSize: 20, mb: 3 }}>
  79. Save details for later
  80. </Typography>
  81. <ShippingDetailsForm
  82. submitHandler={updateUserHandler}
  83. enableBtn={enableBtn}
  84. ></ShippingDetailsForm>
  85. </Box>
  86. <Box
  87. sx={{
  88. mt: 2,
  89. maxWidth: { sm: '100%', lg: '10%' },
  90. minWidth: { md: '40%' },
  91. }}
  92. >
  93. <Typography sx={{ fontSize: 20, mb: 3 }}>Previous Orders</Typography>
  94. {mapOrdersToDom()}
  95. </Box>
  96. </Box>
  97. </Box>
  98. );
  99. };
  100. export default ProfileContent;