Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { Grid, Typography } from '@mui/material';
  2. import { Box } from '@mui/system';
  3. import { signOut, useSession } from 'next-auth/react';
  4. import { useState } from 'react';
  5. import { updateUser } from '../../requests/user/userUpdateRequest';
  6. import OrderCard from '../cards/order-card/OrderCard';
  7. import ShippingDetailsForm from '../forms/shipping-details/ShippingDetailsForm';
  8. const ProfileContent = ({ orders }) => {
  9. const { data: session } = useSession();
  10. const [enableBtn, setEnableBtn] = useState(true);
  11. const updateUserHandler = async (values) => {
  12. try {
  13. setEnableBtn(false);
  14. await updateUser(values, session.user._id);
  15. signOut();
  16. } catch (error) {
  17. console.log(error);
  18. setTimeout(() => {
  19. setEnableBtn(true);
  20. }, 3000);
  21. }
  22. };
  23. const mapOrdersToDom = () =>
  24. orders.slice(-4).map((order, i) => (
  25. <OrderCard
  26. key={i}
  27. data={{
  28. date: order.time.split('T')[0],
  29. name: order.shippingAddress.fullName,
  30. totalPrice: order.totalPrice,
  31. }}
  32. ></OrderCard>
  33. ));
  34. return (
  35. <Grid container spacing={2} sx={{ py: 10, height: '100%', width: '100%' }}>
  36. <Grid item xs={12}>
  37. <Typography
  38. variant="h3"
  39. sx={{ pl: 12, mt: 12, height: '100%', color: 'primary.main' }}
  40. >
  41. Welcome to your user account
  42. </Typography>
  43. </Grid>
  44. <Grid item xs={8} sx={{ mt: 4 }}>
  45. <Typography sx={{ pl: 12, fontSize: 20 }}>
  46. Save details for later (user will be logged out)
  47. </Typography>
  48. </Grid>
  49. <Grid item xs={4} sx={{ mt: 4 }}>
  50. <Typography sx={{ fontSize: 20 }}>Previous Orders</Typography>
  51. </Grid>
  52. <Grid item xs={8}>
  53. <ShippingDetailsForm
  54. submitHandler={updateUserHandler}
  55. enableBtn={enableBtn}
  56. ></ShippingDetailsForm>
  57. </Grid>
  58. <Grid item xs={4}>
  59. <Box sx={{ width: '60%', mt: 2 }}>{mapOrdersToDom()}</Box>
  60. </Grid>
  61. </Grid>
  62. );
  63. };
  64. export default ProfileContent;