ilya_shyian 2 jaren geleden
bovenliggende
commit
2f38f06559

+ 19 - 18
src/actions/actionLogin.js

@@ -3,29 +3,30 @@ import { gql } from '../helpers';
 import { actionAuthLogin } from '../reducers';
 
 export const actionLogin = (login, password) => async (dispatch, getState) => {
+    const formData = new FormData();
+    console.log(login, password);
+    formData.append('username', login);
+    formData.append('password', password);
+
     const token = await dispatch(
         actionPromise(
             'login',
-            new Promise((resolve) => {
-                setTimeout(
-                    Math.random() > 0.01
-                        ? resolve({
-                              data: {
-                                  login: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOnsiaWQiOiI2MjYyY2I0MGJmOGIyMDY0MzNmNWIzZDIiLCJsb2dpbiI6InRlc3QxMTIxMSIsImFjbCI6WyI2MjYyY2I0MGJmOGIyMDY0MzNmNWIzZDIiLCJ1c2VyIl19LCJpYXQiOjE2NTIzNzcxNTF9.j462Ble3m-eycfY_QS_wBSQmR6UZ65FxrKUqkF3MBBY',
-                              },
-                          })
-                        : resolve({
-                              errors: [{ message: 'Error adsasdadas' }],
-                          }),
-                    400
-                );
-            }).then((data) => {
-                console.log(data);
-                if (data.errors) {
-                    throw new Error(JSON.stringify(data.errors));
-                } else return data.data;
+            fetch(`/auth/token/`, {
+                method: 'POST',
+                headers: {
+                    ...(localStorage.authToken ? { Authorization: 'Bearer ' + localStorage.authToken } : {}),
+                },
+                body: formData,
             })
+                .then((res) => res.json())
+                .then((data) => {
+                    console.log(data);
+                    if (data.errors) {
+                        throw new Error(JSON.stringify(data.errors));
+                    } else return data.access;
+                })
         )
     );
+
     dispatch(actionAuthLogin(token));
 };

+ 0 - 29
src/actions/actionNewOrder.js

@@ -1,29 +0,0 @@
-import { mock, query } from '../helpers';
-
-import { actionPromise } from '../reducers';
-
-export const actionNewOrder = () => async (dispatch, getState) => {
-    dispatch(
-        actionPromise(
-            'newOrder',
-            new Promise((resolve) => {
-                setTimeout(
-                    Math.random() > 0.01
-                        ? resolve({
-                              data: { _id: '12313' },
-                          })
-                        : resolve({
-                              errors: [{ message: 'Error adsasdadas' }],
-                          }),
-                    400
-                );
-            })
-                // .then((res) => res.json())
-                .then((data) => {
-                    if (data.errors) {
-                        throw new Error(JSON.stringify(data.errors));
-                    } else return Object.values(data.data);
-                })
-        )
-    );
-};

+ 19 - 46
src/actions/actionOrderById.js

@@ -2,49 +2,22 @@ import { mock, query } from '../helpers';
 
 import { actionPromise } from '../reducers';
 
-export const actionOrderById =
-    ({ _id, promiseName = 'orderById' }) =>
-    async (dispatch, getState) => {
-        dispatch(
-            actionPromise(
-                promiseName,
-                new Promise((resolve) => {
-                    setTimeout(
-                        Math.random() > 0.01
-                            ? resolve({
-                                  data: {
-                                      _id: 4,
-                                      email: 'example@gmail.com',
-                                      phoneNumber: '0667213260',
-                                      orderGoods: [
-                                          {
-                                              _id: 1,
-                                              price: 999,
-                                              count: 1,
-                                              good: {
-                                                  _id: 1,
-                                                  name: 'Good 1',
-                                                  price: '999',
-                                              },
-                                          },
-                                      ],
-                                      price: 999,
-                                      status: 3,
-                                  },
-                              })
-                            : resolve({
-                                  errors: [{ message: 'Error adsasdadas' }],
-                              }),
-                        400
-                    );
-                })
-                    // .then((res) => res.json())
-                    .then((data) => {
-                        console.log(data);
-                        if (data.errors) {
-                            throw new Error(JSON.stringify(data.errors));
-                        } else return data.data;
-                    })
-            )
-        );
-    };
+export const actionOrderById = ({ _id, promiseName = 'orderById' }) =>
+    actionPromise(
+        promiseName,
+        fetch(`/orders/${_id}/`, {
+            method: 'GET',
+            headers: {
+                'Content-Type': 'application/json',
+                Accept: 'application/json',
+
+                ...(localStorage.authToken ? { Authorization: 'Bearer ' + localStorage.authToken } : {}),
+            },
+        })
+            .then((res) => res.json())
+            .then((data) => {
+                if (data.errors) {
+                    throw new Error(JSON.stringify(data.errors));
+                } else return data.data;
+            })
+    );

+ 3 - 1
src/actions/actionOrderUpsert.js

@@ -3,13 +3,15 @@ import { actionPromise } from '../reducers';
 export const actionOrderUpsert = (order) => async (dispatch) => {
     const formData = new FormData();
     order._id && formData.append('_id', order._id);
-    formData.append('orderGoods', JSON.stringify(order.orderGoods));
+    formData.append('orderGoods', JSON.stringify(order.orderGoods || []));
     formData.append('email', order.email);
     formData.append('phoneNumber', order.phoneNumber);
     formData.append('address', order.address);
     formData.append('delivery', order.delivery);
     formData.append('name', order.name);
     formData.append('surname', order.surname);
+    formData.append('status', order.status);
+
     dispatch(
         actionPromise(
             'orderUpsert',

+ 12 - 132
src/actions/actionOrdersAll.js

@@ -7,139 +7,19 @@ export const actionOrdersAll =
         dispatch(
             actionPromise(
                 promiseName,
-                new Promise((resolve) => {
-                    setTimeout(
-                        Math.random() > 0.01
-                            ? resolve({
-                                  data: [
-                                      {
-                                          _id: 1,
-                                          email: 'example@gmail.com',
-                                          phoneNumber: '0667213260',
-                                          orderGoods: [
-                                              {
-                                                  _id: 1,
-                                                  price: 999,
-                                                  count: 1,
-                                                  good: {
-                                                      _id: 1,
-                                                      name: 'Good 1',
-                                                      price: '999',
-                                                      images: [
-                                                          {
-                                                              _id: 1,
-                                                              url: 'https://content2.rozetka.com.ua/goods/images/big/183546719.jpg',
-                                                          },
-                                                          {
-                                                              _id: 2,
-                                                              url: 'https://content2.rozetka.com.ua/goods/images/big/183546719.jpg',
-                                                          },
-                                                      ],
-                                                  },
-                                              },
-                                          ],
-                                          price: 999,
-                                          status: 1,
-                                      },
-                                      {
-                                          _id: 2,
-                                          email: 'example@gmail.com',
-                                          phoneNumber: '0667213260',
-                                          orderGoods: [
-                                              {
-                                                  _id: 1,
-                                                  price: 999,
-                                                  count: 1,
-                                                  good: {
-                                                      _id: 1,
-                                                      name: 'Good 1',
-                                                      price: '999',
-                                                      images: [
-                                                          {
-                                                              _id: 1,
-                                                              url: 'https://content2.rozetka.com.ua/goods/images/big/183546719.jpg',
-                                                          },
-                                                          {
-                                                              _id: 2,
-                                                              url: 'https://content2.rozetka.com.ua/goods/images/big/183546719.jpg',
-                                                          },
-                                                      ],
-                                                  },
-                                              },
-                                          ],
-                                          price: 999,
-                                          status: 2,
-                                      },
-                                      {
-                                          _id: 3,
-                                          email: 'example@gmail.com',
-                                          phoneNumber: '0667213260',
-                                          orderGoods: [
-                                              {
-                                                  _id: 1,
-                                                  price: 999,
-                                                  count: 1,
-                                                  good: {
-                                                      _id: 1,
-                                                      name: 'Good 1',
-                                                      price: '999',
-                                                      images: [
-                                                          {
-                                                              _id: 1,
-                                                              url: 'https://content2.rozetka.com.ua/goods/images/big/183546719.jpg',
-                                                          },
-                                                          {
-                                                              _id: 2,
-                                                              url: 'https://content2.rozetka.com.ua/goods/images/big/183546719.jpg',
-                                                          },
-                                                      ],
-                                                  },
-                                              },
-                                          ],
-                                          price: 999,
-                                          status: 3,
-                                      },
-                                      {
-                                          _id: 4,
-                                          email: 'example@gmail.com',
-                                          phoneNumber: '0667213260',
-                                          orderGoods: [
-                                              {
-                                                  _id: 1,
-                                                  price: 999,
-                                                  count: 1,
-                                                  good: {
-                                                      _id: 1,
-                                                      name: 'Good 1',
-                                                      price: '999',
-                                                      images: [
-                                                          {
-                                                              _id: 1,
-                                                              url: 'https://content2.rozetka.com.ua/goods/images/big/183546719.jpg',
-                                                          },
-                                                          {
-                                                              _id: 2,
-                                                              url: 'https://content2.rozetka.com.ua/goods/images/big/183546719.jpg',
-                                                          },
-                                                      ],
-                                                  },
-                                              },
-                                          ],
-                                          price: 999,
-                                          status: 4,
-                                      },
-                                  ],
-                              })
-                            : resolve({
-                                  errors: [{ message: 'Error adsasdadas' }],
-                              }),
-                        400
-                    );
-                }).then((data) => {
-                    if (data.errors) {
-                        throw new Error(JSON.stringify(data.errors));
-                    } else return data.data;
+                fetch(`/orders/?limit=${limit}&skip=${skip}`, {
+                    method: 'GET',
+                    headers: {
+                        'Content-Type': 'application/json',
+                        ...(localStorage.authToken ? { Authorization: 'Bearer ' + localStorage.authToken } : {}),
+                    },
                 })
+                    .then((res) => res.json())
+                    .then((data) => {
+                        if (data.errors) {
+                            throw new Error(JSON.stringify(data.errors));
+                        } else return data.data;
+                    })
             )
         );
     };

+ 43 - 4
src/components/AuthPage/AuthForm.js

@@ -1,19 +1,28 @@
 import { actionLogin } from '../../actions/actionLogin';
 
-import { useState, useEffect } from 'react';
-import { connect } from 'react-redux';
+import { useState, useEffect, useContext } from 'react';
+import { connect, useSelector } from 'react-redux';
 import { MdVisibility, MdVisibilityOff } from 'react-icons/md';
 import { Box, Button, IconButton, TextField, Stack } from '@mui/material';
 import { useFormik } from 'formik';
 import * as Yup from 'yup';
+import { UIContext } from '../UIContext';
+import { Navigate, useNavigate } from 'react-router-dom';
 
 const signInSchema = Yup.object().shape({
     username: Yup.string().required("Обов'язкове"),
     password: Yup.string().required("Обов'язкове"),
 });
 
-export const AuthForm = ({ onSubmit }) => {
+export const AuthForm = ({ onSubmit = null, promiseStatus, serverErrors = [] } = {}) => {
     const [showPassword, setShowPassword] = useState(false);
+    const { setAlert } = useContext(UIContext);
+    const navigate = useNavigate();
+    const token = useSelector((state) => state.auth?.token || null);
+
+    if (token) {
+        navigate('/admin');
+    }
 
     const formik = useFormik({
         initialValues: {
@@ -23,10 +32,31 @@ export const AuthForm = ({ onSubmit }) => {
         validationSchema: signInSchema,
         validateOnChange: true,
         onSubmit: () => {
+            console.log(formik.values.username, formik.values.password);
             onSubmit(formik.values.username, formik.values.password);
         },
     });
 
+    useEffect(() => {
+        if (promiseStatus === 'FULFILLED') {
+            formik.setSubmitting(false);
+            setAlert({
+                show: true,
+                severity: 'success',
+                message: 'Готово',
+            });
+        }
+        if (promiseStatus === 'REJECTED') {
+            const errorMessage = serverErrors.reduce((prev, curr) => prev + '\n' + curr.message, '');
+            formik.setSubmitting(false);
+            setAlert({
+                show: true,
+                severity: 'error',
+                message: errorMessage,
+            });
+        }
+    }, [promiseStatus]);
+
     return (
         <Box
             className="AuthForm"
@@ -34,6 +64,7 @@ export const AuthForm = ({ onSubmit }) => {
             flexDirection="column"
             onSubmit={formik.handleSubmit}
             justifyContent="center"
+            component="form"
         >
             <TextField
                 id="username"
@@ -84,4 +115,12 @@ export const AuthForm = ({ onSubmit }) => {
     );
 };
 
-export const CAuthForm = connect(null, { onAuth: (login, password) => actionLogin(login, password) })(AuthForm);
+export const CAuthForm = connect(
+    (state) => ({
+        promiseStatus: state.promise?.login?.status || null,
+        serverErrors: state.promise?.login?.error || [],
+    }),
+    {
+        onSubmit: (login, password) => actionLogin(login, password),
+    }
+)(AuthForm);

+ 2 - 2
src/components/AuthPage/index.js

@@ -2,12 +2,12 @@ import { Box, Container } from '@mui/material';
 import { useEffect } from 'react';
 import { useSelector } from 'react-redux';
 import { useNavigate } from 'react-router-dom';
-import { AuthForm } from './AuthForm';
+import { CAuthForm } from './AuthForm';
 
 export const AuthPage = () => {
     return (
         <Box className="AuthPage">
-            <AuthForm />
+            <CAuthForm />
         </Box>
     );
 };

+ 1 - 0
src/components/CartPage/OrderForm/index.js

@@ -157,6 +157,7 @@ export const OrderForm = ({ onSubmit = null, promiseStatus = null, serverErrors
                         extAlign="left"
                         select
                         value={formik.values.delivery}
+                        error={formik.touched.delivery && Boolean(formik.errors.delivery)}
                         onBlur={formik.handleBlur}
                         onChange={formik.handleChange}
                         helperText={formik.touched.delivery && formik.errors.delivery}

+ 2 - 2
src/components/CartPage/index.js

@@ -2,8 +2,8 @@ import { Box, Button, Stack, Table, TableBody, TableCell, TableRow, Typography }
 import { useEffect } from 'react';
 import { useDispatch, useSelector } from 'react-redux';
 import { useNavigate } from 'react-router-dom';
-import { actionNewOrder } from '../../actions/actionNewOrder';
 import { actionOrderUpdate } from '../../actions/actionOrderUpdate';
+import { actionOrderUpsert } from '../../actions/actionOrderUpsert';
 import { actionCartDelete } from '../../reducers';
 import { CartItem } from './CartItem';
 import { COrderForm, OrderForm } from './OrderForm';
@@ -57,7 +57,7 @@ export const CartPage = () => {
                         const orderToSubmit = order;
                         orderToSubmit.orderGoods = Object.values(cart);
                         console.log(orderToSubmit);
-                        dispatch(actionOrderUpdate(orderToSubmit));
+                        dispatch(actionOrderUpsert(orderToSubmit));
                     }}
                 />
             </Stack>

+ 2 - 2
src/components/admin/AdminCategoryPage/CategoryForm.js

@@ -14,12 +14,11 @@ const categorySchema = Yup.object().shape({
 });
 
 const CategoryForm = ({
-    serverErrors,
+    serverErrors = [],
     onSaveClick,
     onSave,
     onClose,
     promiseStatus,
-    goodsField = false,
     catList: initialCatList = [],
     goodList = [],
     category = {},
@@ -173,6 +172,7 @@ export const CCategoryForm = connect(
     (state) => ({
         catList: state.promise.catAll?.payload || [],
         promiseStatus: state.promise.categoryUpsert?.status || null,
+        serverErrors: state.promise.categoryUpsert?.error || null,
         goodList: state.promise.goodsAll?.payload || [],
     }),
     {

+ 1 - 1
src/components/admin/AdminGoodPage/GoodForm.js

@@ -43,7 +43,7 @@ const CGoodEditor = connect(
 )(EntityEditor);
 
 export const GoodForm = ({
-    serverErrors,
+    serverErrors = [],
     onSaveClick,
     onSave,
     onClose,

+ 4 - 2
src/components/admin/AdminLayoutPage/index.js

@@ -1,7 +1,7 @@
 import { Box, Container } from '@mui/material';
 import { useEffect } from 'react';
 import { connect, useDispatch, useSelector } from 'react-redux';
-import { Route, Routes, useParams } from 'react-router-dom';
+import { Navigate, Route, Routes, useParams } from 'react-router-dom';
 import { actionGoodById } from '../../../actions/actionGoodById';
 import { actionCatById } from '../../../actions/actionCatById';
 import { actionPromiseClear, store, actionFeedCats } from '../../../reducers';
@@ -134,6 +134,7 @@ const AdminOrdersPageContainer = ({ orders }) => {
 const AdminOrderPageContainer = () => {
     const params = useParams();
     const dispatch = useDispatch();
+    dispatch(actionPromiseClear('adminOrderById'));
     useEffect(() => {
         if (params._id) {
             dispatch(actionOrderById({ _id: params._id, promiseName: 'adminOrderById' }));
@@ -160,6 +161,7 @@ const AdminLayoutPage = () => {
     return (
         <Box className="AdminLayoutPage">
             <Routes>
+                <Route path="/" element={<Navigate to={'/admin/goods/'} />} exact />
                 <Route path="/goods/" element={<CAdminGoodsPageContainer />} />
                 <Route path="/good/" element={<AdminGoodPageContainer />} />
                 <Route path="/good/:_id" element={<AdminGoodPageContainer />} />
@@ -167,7 +169,7 @@ const AdminLayoutPage = () => {
                 <Route path="/category/" element={<AdminCategoryPageContainer />} />
                 <Route path="/category/:_id" element={<AdminCategoryPageContainer />} />
                 <Route path="/orders/" element={<CAdminOrdersPageContainer />} />
-                <Route path="/order/" element={<CAdminOrdersPageContainer />} />
+                <Route path="/order/" element={<AdminOrderPageContainer />} />
                 <Route path="/order/:_id" element={<AdminOrderPageContainer />} />
             </Routes>
         </Box>

+ 117 - 23
src/components/admin/AdminOrderPage/OrderForm.js

@@ -1,10 +1,11 @@
 import { connect } from 'react-redux';
-import React, { useState, useEffect } from 'react';
+import React, { useState, useEffect, useContext } from 'react';
 import { actionPromise, actionPromiseClear } from '../../../reducers';
 import Select from 'react-select';
 import { actionOrderUpdate } from '../../../actions/actionOrderUpdate';
 import { EntityEditor } from '../../common/EntityEditor';
 import { actionUploadFiles } from '../../../actions/actionUploadFiles';
+import { UIContext } from '../../UIContext';
 import {
     Box,
     Button,
@@ -24,33 +25,37 @@ import * as Yup from 'yup';
 import { Error } from '../../common/Error';
 import { statusNumber, statusOptions } from '../../../helpers';
 
+const deliveryOptions = [
+    { label: 'Нова пошта', value: 'nova-poshta' },
+    { label: 'Justin', value: 'justin' },
+];
+
 const orderSchema = Yup.object().shape({
     email: Yup.string().required("Обов'язкове"),
     phoneNumber: Yup.string().required("Обов'язкове"),
+    name: Yup.string(),
+    address: Yup.string().required("Обов'язкове"),
+    surname: Yup.string(),
+    delivery: Yup.string()
+        .required("обов'язкове")
+        .oneOf(
+            deliveryOptions.map((option) => option.value),
+            'не знайдено'
+        ),
 });
 
-export const OrderForm = ({
-    serverErrors,
-    onSaveClick,
-    onSave,
-    onClose,
-    promiseStatus,
-    catList = [],
-    order = {},
-} = {}) => {
-    const [inputCategories, setInputCategories] = useState([]);
+export const OrderForm = ({ serverErrors = [], onSaveClick, onSave, onClose, promiseStatus, order = {} } = {}) => {
     const [inputStatus, setInputStatus] = useState(null);
-
-    useEffect(() => {
-        console.log(inputStatus);
-    }, [inputStatus]);
+    const { setAlert } = useContext(UIContext);
 
     const formik = useFormik({
         initialValues: {
             email: '',
+            name: '',
+            surname: '',
             phoneNumber: '',
-            price: 0,
-            amount: 0,
+            delivery: '',
+            address: '',
         },
         validationSchema: orderSchema,
         validateOnChange: true,
@@ -58,11 +63,12 @@ export const OrderForm = ({
             let orderToSave = {};
             order?._id && (orderToSave._id = order._id);
             orderToSave.name = formik.values.name;
-            orderToSave.description = formik.values.description;
-            // orderToSave.price = +formik.values.price;
-            // orderToSave.amount = +formik.values.amount;
-            // orderToSave.categories = inputCategories;
-            // orderToSave.images = inputImages?.map(({ _id }) => ({ _id })) || [];
+            orderToSave.email = formik.values.email;
+            orderToSave.status = inputStatus;
+            orderToSave.surname = formik.values.surname;
+            orderToSave.phoneNumber = formik.values.phoneNumber;
+            orderToSave.address = formik.values.address;
+            orderToSave.deivery = formik.values.deivery;
 
             onSaveClick && onSaveClick();
             onSave(orderToSave);
@@ -73,9 +79,33 @@ export const OrderForm = ({
         // setInputCategories(order?.categories || []);
         setInputStatus(order?.status || null);
         formik.setFieldValue('email', order.email || '');
+        formik.setFieldValue('name', order.name || '');
+        formik.setFieldValue('address', order.address || '');
+        formik.setFieldValue('surname', order.surname || '');
         formik.setFieldValue('phoneNumber', order.phoneNumber || '');
+        formik.setFieldValue('delivery', order.delivery || '');
     }, [order]);
 
+    useEffect(() => {
+        if (promiseStatus === 'FULFILLED') {
+            formik.setSubmitting(false);
+            setAlert({
+                show: true,
+                severity: 'success',
+                message: 'Готово',
+            });
+        }
+        if (promiseStatus === 'REJECTED') {
+            const errorMessage = serverErrors.reduce((prev, curr) => prev + '\n' + curr.message, '');
+            formik.setSubmitting(false);
+            setAlert({
+                show: true,
+                severity: 'error',
+                message: errorMessage,
+            });
+        }
+    }, [promiseStatus]);
+
     useEffect(() => {
         return () => {
             onClose && onClose();
@@ -102,6 +132,20 @@ export const OrderForm = ({
                         fullWidth
                         sx={{ mt: 2 }}
                     />
+                    <TextField
+                        id="name"
+                        name="name"
+                        variant="outlined"
+                        label="Ім'я"
+                        size="small"
+                        error={formik.touched.name && Boolean(formik.errors.name)}
+                        value={formik.values.name}
+                        onBlur={formik.handleBlur}
+                        onChange={formik.handleChange}
+                        helperText={formik.touched.name && formik.errors.name}
+                        fullWidth
+                        sx={{ mt: 2 }}
+                    />
 
                     <Box sx={{ mt: 3 }}>
                         <InputLabel className="form-label">Статус</InputLabel>
@@ -142,6 +186,56 @@ export const OrderForm = ({
                         fullWidth
                         sx={{ mt: 2 }}
                     />
+                    <TextField
+                        id="surname"
+                        name="surname"
+                        variant="outlined"
+                        label="Прізвище"
+                        size="small"
+                        error={formik.touched.surname && Boolean(formik.errors.surname)}
+                        value={formik.values.surname}
+                        onBlur={formik.handleBlur}
+                        onChange={formik.handleChange}
+                        helperText={formik.touched.surname && formik.errors.surname}
+                        fullWidth
+                        sx={{ mt: 2 }}
+                    />
+                    <TextField
+                        id="address"
+                        name="address"
+                        variant="outlined"
+                        label="Адреса"
+                        size="small"
+                        error={formik.touched.address && Boolean(formik.errors.address)}
+                        value={formik.values.address}
+                        onBlur={formik.handleBlur}
+                        onChange={formik.handleChange}
+                        helperText={formik.touched.address && formik.errors.address}
+                        fullWidth
+                        sx={{ mt: 2 }}
+                    />
+                    <TextField
+                        id="delivery"
+                        name="delivery"
+                        variant="outlined"
+                        label="Тип доставкі"
+                        size="small"
+                        extAlign="left"
+                        select
+                        error={formik.touched.delivery && Boolean(formik.errors.delivery)}
+                        value={formik.values.delivery}
+                        onBlur={formik.handleBlur}
+                        onChange={formik.handleChange}
+                        helperText={formik.touched.delivery && formik.errors.delivery}
+                        fullWidth
+                        sx={{ mt: 2 }}
+                    >
+                        {deliveryOptions.map((option) => (
+                            <MenuItem key={option.value} value={option.value} t>
+                                {option.label}
+                            </MenuItem>
+                        ))}
+                    </TextField>
                 </Grid>
             </Grid>
         </Box>
@@ -150,8 +244,8 @@ export const OrderForm = ({
 
 export const COrderForm = connect(
     (state) => ({
-        catList: state.promise.catAll?.payload || [],
         promiseStatus: state.promise.orderUpsert?.status || null,
+        serverErrors: state.promise.orderUpsert?.error || null,
         order: state.promise?.adminOrderById?.payload || {},
     }),
     {

+ 1 - 1
src/components/admin/AdminOrdersPage/AdminOrderItem.js

@@ -18,7 +18,7 @@ const AdminOrderItem = ({ order }) => (
                 : '-'}
         </TableCell>
         <TableCell>{order.price ? order.price : '-'}</TableCell>
-        <TableCell>{'' + order?.status?.length ? statusNumber[order.status] : '-'}</TableCell>
+        <TableCell>{'' + order?.status?.length ? statusNumber[+order.status] : '-'}</TableCell>
         <TableCell className="edit">
             <Button component={Link} className="Link" to={`/admin/order/${order._id}/`} variant="contained">
                 Редагувати

+ 0 - 2
src/components/common/DrawerCart/DrawerCart.js

@@ -1,4 +1,3 @@
-import { actionNewOrder } from '../../../actions/actionNewOrder';
 import { Link, Navigate, useNavigate } from 'react-router-dom';
 import { actionCartDelete } from '../../../reducers';
 import { IoMdClose } from 'react-icons/io';
@@ -53,7 +52,6 @@ export const DrawerCart = ({ isOpen = false, onClose = null } = {}) => {
                         <Button
                             variant="text"
                             onClick={() => {
-                                dispatch(actionNewOrder([...Object.values(cart)]));
                                 onClose();
                                 navigate('/cart');
                             }}

+ 19 - 0
src/components/layout/Header/LogoutIcon/index.js

@@ -0,0 +1,19 @@
+import { Badge, Box, IconButton } from '@mui/material';
+import { useEffect, useState } from 'react';
+import { connect, useDispatch, useSelector } from 'react-redux';
+import { MdLogout, MdOutlineShoppingCart } from 'react-icons/md';
+import { useSelect } from '@mui/base';
+import { actionLogout } from '../../../../actions/actionLogout';
+
+export const LogoutIcon = () => {
+    const dispatch = useDispatch();
+    const token = useSelector((state) => state.auth?.token || null);
+
+    return token ? (
+        <Box className="LogoutIcon">
+            <IconButton onClick={() => dispatch(actionLogout())}>
+                <MdLogout className="LogoutLogo" />
+            </IconButton>
+        </Box>
+    ) : null;
+};

+ 2 - 1
src/components/layout/Header/index.js

@@ -8,6 +8,7 @@ import { DrawerCart } from '../../common/DrawerCart/DrawerCart';
 import { CSearchBar, SearchBar } from '../../common/SearchBar';
 import { CSearchResults } from '../../common/SearchBar/SearchResults';
 import { CCartIcon } from './CartIcon';
+import { LogoutIcon } from './LogoutIcon';
 
 const Header = () => {
     const rootCats = useSelector((state) => state?.promise?.rootCats?.payload || []);
@@ -44,7 +45,7 @@ const Header = () => {
                     <Box className="SearchBarWrapper">
                         <CSearchBar render={CSearchResults} renderParams={{ itemLink: '/good/' }} />
                     </Box>
-
+                    <LogoutIcon />
                     <IconButton color="inherit" className="CartLogoButton" onClick={() => setIsCartDrawerOpen(true)}>
                         <Box>
                             <CCartIcon />

+ 9 - 0
src/index.scss

@@ -136,6 +136,15 @@
             height:30px;
           }
         }
+
+        & .LogoutIcon{
+
+          & .LogoutLogo{
+            color:#6750A4;
+            width:30px;
+            height:30px;
+          }
+        }
       }
 
     }

+ 5 - 5
src/reducers/feedReducer.js

@@ -26,13 +26,13 @@ const actionFeedClear = () => ({ type: 'FEED_CLEAR' });
 const actionFeedGoods =
     (skip = 0) =>
     async (dispatch, getState) => {
-        await dispatch(actionGoodsAll({ skip, limit: 50, promiseName: 'feedGoodsAll' }));
+        await dispatch(actionGoodsAll({ skip, limit: 20, promiseName: 'feedGoodsAll' }));
     };
 
 const actionFeedGoodsFind =
     ({ skip = 0, text = '' }) =>
     async (dispatch, getState) => {
-        await dispatch(actionGoodsFind({ skip, limit: 50, promiseName: 'feedGoodsFind', text }));
+        await dispatch(actionGoodsFind({ skip, limit: 20, promiseName: 'feedGoodsFind', text }));
     };
 
 const actionFeedCatsFind =
@@ -44,19 +44,19 @@ const actionFeedCatsFind =
 const actionFeedCats =
     (skip = 0) =>
     async (dispatch, getState) => {
-        await dispatch(actionCatAll({ promiseName: 'feedCatAll', skip, limit: 50 }));
+        await dispatch(actionCatAll({ promiseName: 'feedCatAll', skip, limit: 20 }));
     };
 
 const actionFeedOrders =
     (skip = 0) =>
     async (dispatch, getState) => {
-        await dispatch(actionOrdersAll({ skip, limit: 50, promiseName: 'feedOrdersAll' }));
+        await dispatch(actionOrdersAll({ skip, limit: 20, promiseName: 'feedOrdersAll' }));
     };
 
 const actionFeedOrdersFind =
     ({ skip = 0, text = '' }) =>
     async (dispatch, getState) => {
-        await dispatch(actionOrdersFind({ skip, limit: 50, promiseName: 'feedOrdersFind', text }));
+        await dispatch(actionOrdersFind({ skip, limit: 20, promiseName: 'feedOrdersFind', text }));
     };
 
 export {