Alex преди 2 години
родител
ревизия
c933a33904

+ 12 - 19
src/actions/ActionCategory.js

@@ -58,27 +58,20 @@ export const actionCategoryCount = () => {
 }
 
 //CategoryUpsert
-export const actionCategoryUpsert = (category) => {
-    const mainTitleCategory = category[0]?.name || 'No name';
-    const mainGoodsCategory = []
-    if (category[0]?.goods && category[0]?.goods?.length > 0){
-        category[0].goods.forEach(item => {
-            mainGoodsCategory.push(...item)
-        })
-    }
-
-    console.log(mainTitleCategory, mainGoodsCategory)
-    return actionPromise('categoryUpsert', gql(`
-                mutation categoryUpsert($name: String!){
-                CategoryUpsert(category: {name: $name}) {
+export const actionCategoryUpsert = category =>
+    async dispatch => {
+        let value = await dispatch(actionPromise('categoryUpsert', gql(`
+                mutation categoryUpsert($category: CategoryInput){
+                CategoryUpsert(category: $category) {
                     _id
-                    createdAt
-                    name
                 }
-            }`,{name: mainTitleCategory}
-        )
-    )
-}
+            }`, {"category": {...category}}
+            )
+        ))
+        if (value) {
+            await dispatch(actionFullRootCats())
+        }
+    }
 
 //CategoryFind
 export const actionAllCategory = () => {

+ 8 - 31
src/actions/ActionUploadFile.js

@@ -14,9 +14,12 @@ export const actionUploadFile = file => {
 
 export const actionUploadFiles = array =>
     async dispatch => {
+        // let arrayDispatch = []
         for (const file of array) {
+            // arrayDispatch.push(dispatch(actionUploadFile(file)))
             await dispatch(actionUploadFile(file))
         }
+        // await Promise.all(arrayDispatch)
     }
 
 export const actionSetAvatar = file =>
@@ -40,40 +43,14 @@ export const actionSetAvatar = file =>
          }
      }
 
-export const actionSetLogin = login =>
+export const actionSetUserUpsert = newValue =>
     async (dispatch, getState) => {
-        let value = await dispatch(actionPromise('setNewLogin',
-            gql(`mutation setNewLogin($myid: String, $login: String){
-                    UserUpsert(user:{_id: $myid, login: $login}){
+        let value = await dispatch(actionPromise('setUserUpsert',
+            gql(`mutation setUserUpsert($user: UserInput){
+                    UserUpsert(user: $user){
                         _id
                     }
-                }`, {myid: getState().user._id, login: login})))
-        if (value){
-            await dispatch(actionFullUserFindOne(getState().user._id))
-        }
-    }
-
-export const actionSetNick = nick =>
-    async (dispatch, getState) => {
-        let value = await dispatch(actionPromise('setNewNick',
-            gql(`mutation setNewNick($myid: String, $nick: String){
-                    UserUpsert(user:{_id: $myid, nick: $nick}){
-                        _id
-                    }
-                }`, {myid: getState().user._id, nick: nick})))
-        if (value){
-            await dispatch(actionFullUserFindOne(getState().user._id))
-        }
-    }
-
-export const actionSetPassword = password =>
-    async (dispatch, getState) => {
-        let value = await dispatch(actionPromise('setNewPassword',
-            gql(`mutation setNewPassword($myid: String, $password: String){
-                    UserUpsert(user:{_id: $myid, password: $password}){
-                        _id
-                    }
-                }`, {myid: getState().user._id, password: password})))
+                }`, {"user": {_id: getState().user._id, ...newValue}})))
         if (value){
             await dispatch(actionFullUserFindOne(getState().user._id))
         }

+ 13 - 6
src/pages/AdminPage/AdminPage.jsx

@@ -11,17 +11,20 @@ import AppBar from '@mui/material/AppBar';
 import Tabs from '@mui/material/Tabs';
 import Tab from '@mui/material/Tab';
 import Box from '@mui/material/Box';
-import {useState} from "react";
+import {useEffect, useState} from "react";
 import PersonIcon from '@mui/icons-material/Person';
 import CategoryIcon from '@mui/icons-material/Category';
 import AutoAwesomeIcon from '@mui/icons-material/AutoAwesome';
 import BottomNavigation from '@mui/material/BottomNavigation';
 import AddCircleOutlineIcon from '@mui/icons-material/AddCircleOutline';
 import EditIcon from '@mui/icons-material/Edit';
-import {CCategoryEdit, CCategoryEditTree} from "./CateforyTab";
 import {CClients} from "./ClientsTab/ClientsTab";
 import {CGoodEdit} from "./GoodsTab/GoodEdit";
 import {CFindGoodEdit} from "./GoodsTab/FindGoodEdit";
+import {CCategoryEdit} from "./CategoriesTab/CategoryEdit";
+import {CCategoryEditTree, CCCategoryEditTree} from "./CategoriesTab/CCategoryEditTree";
+import {actionClearPromise} from "../../reducers/PromiseReducer";
+import {connect} from "react-redux";
 
 const defaultTabs = [
     {icon: PersonIcon, text: 'clients'},
@@ -64,8 +67,11 @@ function a11yProps(index) {
     };
 }
 
-const SelectBlock = ({Block, FindBlock}) => {
+const SelectBlock = ({Block, FindBlock, actionClear}) => {
     const [value, setValue] = useState('create');
+    useEffect(()=>{
+        actionClear('uploadFile')
+    }, [value])
     return (
         <>
             <Box
@@ -103,6 +109,7 @@ const SelectBlock = ({Block, FindBlock}) => {
         </>
     )
 }
+const CSelectBlock = connect(null, {actionClear: actionClearPromise})(SelectBlock)
 
 const FullWidthTabs = () => {
     const theme = useTheme();
@@ -157,13 +164,13 @@ const FullWidthTabs = () => {
                 onChangeIndex={handleChangeIndex}
             >
                 <TabPanel value={value} index={0} dir={theme.direction}>
-                    <CClients/>
+                    {/*<CClients/>*/}
                 </TabPanel>
                 <TabPanel value={value} index={1} dir={theme.direction}>
-                    <SelectBlock Block={CCategoryEdit} FindBlock={CCategoryEditTree}/>
+                    <CSelectBlock Block={CCategoryEdit} FindBlock={CCCategoryEditTree}/>
                 </TabPanel>
                 <TabPanel value={value} index={2} dir={theme.direction}>
-                    <SelectBlock Block={CGoodEdit} FindBlock={CFindGoodEdit}/>
+                    {/*<CSelectBlock Block={CGoodEdit} FindBlock={CFindGoodEdit}/>*/}
                 </TabPanel>
             </SwipeableViews>
         </Box>

+ 0 - 230
src/pages/AdminPage/CateforyTab.jsx

@@ -1,230 +0,0 @@
-import * as React from 'react';
-import {Button, Checkbox, Grid, Switch, TextField} from "@mui/material";
-import Autocomplete from "@mui/material/Autocomplete";
-import Box from "@mui/material/Box";
-import Typography from "@mui/material/Typography";
-import {SetCount} from "../../components/SetCount";
-import {connect} from "react-redux";
-import {actionCategoryCount, actionCategoryUpsert, actionFullRootCats} from "../../actions/ActionCategory";
-import {actionAllGoodFind} from "../../actions/ActionGoodFind";
-import { enableRipple } from '@syncfusion/ej2-base';
-import { TreeViewComponent } from '@syncfusion/ej2-react-navigations';
-import {useEffect, useState} from "react";
-enableRipple(true);
-
-const InputCategory = ({goods, setArray, countSubCat}) => {
-    const [name, setName] = useState('');
-    const [products, setProducts] = useState([]);
-    const [addSub, setAddSub] = useState(false);
-    const [subArray, setSubArray] = useState([]);
-
-    const [checked, setChecked] = useState(false);
-    const handleChange = (event) => {
-        setChecked(event.target.checked);
-        if (!checked){
-            setArray([{"name": name, "goods": products, "subcategory": subArray}])
-        }
-    };
-
-    return (
-        <>
-            <Grid container justifyContent='space-between'>
-                <Grid item xs={5}>
-                    <TextField fullWidth id="filled-basic" label="Title category" variant="standard" value={name} onChange={e => {setName(e.target.value); setChecked(false)}}/>
-                </Grid>
-                <Grid item xs={5}>
-                    {goods?.payload &&
-                        <Autocomplete
-                            multiple
-                            id="tags-standard"
-                            options={goods.payload}
-                            onChange={(event, newValue) => {
-                                setProducts([newValue]);
-                                setChecked(false)
-                            }}
-                            getOptionLabel={(option) => option?.name || 'no name'}
-                            key={option => option?.id}
-                            renderInput={(params) => (
-                                <TextField
-                                    {...params}
-                                    variant="standard"
-                                    label="Select goods"
-                                    placeholder="goods"
-                                />
-                            )}
-                        />
-                    }
-                </Grid>
-                <Grid item xs={1} display='flex' justifyContent='center' alignItems='flex-end'>
-                    <Checkbox
-                        checked={checked}
-                        onChange={handleChange}
-                        inputProps={{ 'aria-label': 'controlled' }}
-                    />
-                </Grid>
-            </Grid>
-            <Grid container justifyContent='space-between' marginTop='30px' marginBottom='10px'>
-                <Grid item xs={5.5}>
-                    {countSubCat < 2 &&
-                        <Box display='flex' alignItems='center'>
-                            <Typography color='#616161'>Add subcategories</Typography>
-                            <Switch onChange={() => {setAddSub(!addSub); setChecked(false)}}/>
-                        </Box>
-                    }
-                </Grid>
-            </Grid>
-            {addSub && <AddCategory goods={goods} setArray={value => setSubArray(value)} addCategory={true} countSubCat={countSubCat+1}/>}
-        </>
-    )
-}
-const AddCategory = ({goods, setArray, addCategory, countSubCat}) => {
-    const [name, setName] = useState('');
-    const [products, setProducts] = useState([]);
-    const [addSub, setAddSub] = useState(false);
-    const [subArray, setSubArray] = useState([]);
-    const [addCat, setAddCat] = useState(false);
-    const [catCount, setCatCount] = useState(0);
-    const [subCat, setSubCat] = useState([]);
-
-    useEffect(() => {
-        setArray([{"name": name, "goods": products, "subcategory": subArray}, {...subCat}])
-    }, [name, products, subArray, subCat])
-    console.log(subCat)
-
-    return (
-        <Box sx={{border: '1px dashed #616161', borderRadius: '20px', padding: '20px'}}>
-            <Grid container justifyContent='space-between'>
-                <Grid item xs={5.5}>
-                    <TextField fullWidth id="filled-basic" label="Title category" variant="standard" value={name} onChange={e => setName(e.target.value)}/>
-                </Grid>
-                <Grid item xs={5.5}>
-                    {goods?.payload &&
-                        <Autocomplete
-                            multiple
-                            id="tags-standard"
-                            options={goods.payload}
-                            onChange={(event, newValue) => {
-                                setProducts([newValue]);
-                            }}
-                            getOptionLabel={(option) => option?.name || 'no name'}
-                            key={option => option?.id}
-                            renderInput={(params) => (
-                                <TextField
-                                    {...params}
-                                    variant="standard"
-                                    label="Select goods"
-                                    placeholder="goods"
-                                />
-                            )}
-                        />
-                    }
-                </Grid>
-            </Grid>
-            <Grid container justifyContent='space-between' marginTop='30px' marginBottom='10px'>
-                <Grid item xs={5.5}>
-                    {countSubCat < 2  &&
-                        <Box display='flex' alignItems='center'>
-                            <Typography color='#616161'>Add subcategories</Typography>
-                            <Switch onChange={() => setAddSub(!addSub)}/>
-                        </Box>
-                    }
-                </Grid>
-                <Grid item xs={5.5} display='flex' justifyContent='space-between' alignItems='center'>
-                    {addCategory &&
-                        <Box display='flex' alignItems='center'>
-                            <Typography color='#616161'>Add categories</Typography>
-                            <Switch onChange={() => {setAddCat(!addCat); setCatCount(0)}}/>
-                        </Box>
-                    }
-                    {addCat && <SetCount defaultValue={1} width={40} height={40} onCount={value => setCatCount(value)}/>}
-                </Grid>
-            </Grid>
-            {addSub && <AddCategory goods={goods} setArray={value => setSubArray(value)} addCategory={true} countSubCat={countSubCat+1}/>}
-            {catCount >= 1 && new Array(catCount).fill(0).map(item => {
-                return <InputCategory goods={goods} setArray={value => setSubCat([...subCat, value])} countSubCat={countSubCat}/>
-            })
-            }
-        </Box>
-    )
-}
-const CategoryEdit = ({category, categoryCount, goods, variant='create', actionRootCat, getCountCategory, getGoodFind, onCreateCategory}) => {
-    const [array, setArray] = useState([])
-
-    useEffect(() => {
-        if(!goods) getGoodFind()
-        if(!category) actionRootCat()
-        if(!categoryCount) getCountCategory()
-    }, [actionRootCat, category, categoryCount, getCountCategory, getGoodFind, goods])
-
-    return(
-        <>
-            <Typography variant='h6' letterSpacing='2px' marginBottom='20px'>Total category: {categoryCount?.payload || 0}</Typography>
-            <AddCategory goods={goods} setArray={value => setArray(value)} countSubCat={0}/>
-            <Grid container justifyContent='center' marginTop='30px'>
-                <Grid item xs={4}>
-                    <Button disabled={array.length === 0} fullWidth variant="outlined" onClick={() => onCreateCategory(array)}>
-                        Save
-                    </Button>
-                </Grid>
-            </Grid>
-        </>
-    )
-}
-export const CCategoryEdit = connect(state => ({category: state.category, categoryCount: state.promise['categoryCount'], goods: state.promise['goodAllFind'] }), {actionRootCat: actionFullRootCats, getCountCategory: actionCategoryCount, getGoodFind: actionAllGoodFind, onCreateCategory: actionCategoryUpsert})(CategoryEdit)
-
-
-export class CCategoryEditTree extends React.Component {
-    constructor() {
-        super(...arguments);
-        this.productTeam = [
-            {
-                id: 1, name: 'ASP.NET MVC Team', expanded: true,
-                child: [
-                    { id: 2, pid: 1, name: 'Smith', isSelected: true },
-                    { id: 3, pid: 1, name: 'Johnson', isSelected: true },
-                    { id: 4, pid: 1, name: 'Anderson' },
-                ]
-            },
-            {
-                id: 5, name: 'Windows Team',
-                child: [
-                    { id: 6, pid: 5, name: 'Clark' },
-                    { id: 7, pid: 5, name: 'Wright' },
-                    { id: 8, pid: 5, name: 'Lopez' },
-                ]
-            },
-            {
-                id: 9, name: 'Web Team',
-                child: [
-                    { id: 11, pid: 9, name: 'Joshua' },
-                    { id: 12, pid: 9, name: 'Matthew' },
-                    { id: 13, pid: 9, name: 'David' },
-                ]
-            },
-            {
-                id: 14, name: 'Build Team',
-                child: [
-                    { id: 15, pid: 14, name: 'Ryan' },
-                    { id: 16, pid: 14, name: 'Justin' },
-                    { id: 17, pid: 14, name: 'Robert' },
-                ]
-            },
-            {
-                id: 18, name: 'WPF Team',
-                child: [
-                    { id: 19, pid: 18, name: 'Brown' },
-                    { id: 20, pid: 18, name: 'Johnson' },
-                    { id: 21, pid: 18, name: 'Miller' },
-                ]
-            }
-        ];
-        this.fields = { dataSource: this.productTeam, id: 'id', parentID: 'pid', text: 'name', hasChildren: 'hasChild', selected: 'isSelected' };
-        this.allowDragAndDrop = true;
-        this.allowMultiSelection = true;
-    }
-    render() {
-        return (
-            <TreeViewComponent fields={this.fields} allowMultiSelection={this.allowMultiSelection} allowDragAndDrop={this.allowDragAndDrop}/>
-        );
-    }
-}

+ 71 - 0
src/pages/AdminPage/CategoriesTab/CCategoryEditTree.jsx

@@ -0,0 +1,71 @@
+import * as React from "react";
+import {TreeViewComponent} from "@syncfusion/ej2-react-navigations";
+import {connect} from "react-redux";
+import {actionFullRootCats} from "../../../actions/ActionCategory";
+
+export class CCategoryEditTree extends React.Component {
+    constructor(category, onGetCategory) {
+        super(...arguments);
+        this.category = category
+        this.productTeam = [
+            {
+                id: 1, name: 'ASP.NET MVC Team',
+                child: [
+                    { id: 2, pid: 1, name: 'Smith'},
+                    { id: 3, pid: 1, name: 'Johnson'},
+                    { id: 4, pid: 1, name: 'Anderson' },
+                ]
+            },
+            {
+                id: 5, name: 'Windows Team',
+                child: [
+                    { id: 6, pid: 5, name: 'Clark' },
+                    { id: 7, pid: 5, name: 'Wright' },
+                    { id: 8, pid: 5, name: 'Lopez' },
+                ]
+            },
+            {
+                id: 9, name: 'Web Team',
+                child: [
+                    { id: 11, pid: 9, name: 'Joshua' },
+                    { id: 12, pid: 9, name: 'Matthew' },
+                    { id: 13, pid: 9, name: 'David' },
+                ]
+            },
+            {
+                id: 14, name: 'Build Team',
+                child: [
+                    { id: 15, pid: 14, name: 'Ryan' },
+                    { id: 16, pid: 14, name: 'Justin' },
+                    { id: 17, pid: 14, name: 'Robert' },
+                ]
+            },
+            {
+                id: 18, name: 'WPF Team',
+                child: [
+                    { id: 19, pid: 18, name: 'Brown' },
+                    { id: 20, pid: 18, name: 'Johnson' },
+                    { id: 21, pid: 18, name: 'Miller' },
+                ]
+            }
+        ];
+        this.fields = {
+            dataSource: this.productTeam,
+            id: 'id',
+            parentID: 'pid',
+            text: 'name',
+            hasChildren: 'hasChild',
+            selected: 'isSelected'
+        };
+        this.allowDragAndDrop = true;
+        this.allowMultiSelection = true;
+    }
+
+    render() {
+        return (
+            <TreeViewComponent fields={this.fields} allowMultiSelection={this.allowMultiSelection} allowDragAndDrop={this.allowDragAndDrop}/>
+        );
+    }
+}
+
+export const CCCategoryEditTree = connect(state => ({category: state.category}))(CCategoryEditTree)

+ 204 - 0
src/pages/AdminPage/CategoriesTab/CategoryEdit.jsx

@@ -0,0 +1,204 @@
+import {useEffect, useState} from "react";
+import Typography from "@mui/material/Typography";
+import {Button, Checkbox, Grid, Switch, TextField} from "@mui/material";
+import {connect} from "react-redux";
+import {actionCategoryCount, actionCategoryUpsert, actionFullRootCats} from "../../../actions/ActionCategory";
+import {actionAllGoodFind} from "../../../actions/ActionGoodFind";
+import * as React from "react";
+import Autocomplete from "@mui/material/Autocomplete";
+import Box from "@mui/material/Box";
+import CheckCircleOutlineIcon from "@mui/icons-material/CheckCircleOutline";
+import {AccordionItem} from "../../MyOrdersPage/AccordionItem";
+
+const AddSubCategory = ({goods, onCreate}) => {
+    const [subCategory, setSubCategory] = useState({});
+
+    useEffect(() => {
+        onCreate({...subCategory})
+    }, [subCategory])
+
+    return (
+        <>
+            <AddRootCategory goods={goods} onCreate={value => {setSubCategory({...value})}}/>
+        </>
+    )
+}
+const AddRootCategory = ({goods, onCreate}) => {
+    const [name, setName] = useState('');
+    const [products, setProducts] = useState([]);
+    const [addSub, setAddSub] = useState(false);
+    const [addCat, setAddCat] = useState(false);
+    const [subCategory, setSubCategory] = useState({});
+
+    useEffect(() => {
+        let obj = {}
+        if (Object.entries(subCategory).length > 0) {
+            obj['subCategories'] = [{...subCategory}]
+        }
+        if (products.length > 0){
+            obj["goods"] = [...products]
+        }
+        if (name) {
+            obj["name"] = name
+            onCreate(obj)
+        }
+    }, [name, products, subCategory])
+
+    return (
+        <>
+            <Grid
+                container
+                border='1px dashed #616161'
+                borderRadius='20px'
+                padding='20px'
+            >
+                <Grid
+                    container
+                    justifyContent='space-between'
+                    alignItems='flex-end'
+                >
+                    <Grid item xs={5}>
+                        <TextField
+                            fullWidth
+                            id="filled-basic"
+                            label="Title category"
+                            variant="standard"
+                            value={name}
+                            onChange={e => {
+                                setName(e.target.value);
+                            }}
+                        />
+                    </Grid>
+                    <Grid item xs={5}>
+                        {goods?.payload &&
+                            <Autocomplete
+                                multiple
+                                id="tags-standard"
+                                options={goods.payload}
+                                onChange={(event, newValue) => {
+                                    setProducts([...newValue]);
+                                }}
+                                getOptionLabel={(option) => option?.name || 'no name'}
+                                key={option => option?.id}
+                                renderInput={(params) => (
+                                    <TextField
+                                        {...params}
+                                        variant="standard"
+                                        label="Select goods"
+                                        placeholder="goods"
+                                    />
+                                )}
+                            />
+                        }
+                    </Grid>
+                </Grid>
+                <Grid
+                    container
+                    justifyContent='space-between'
+                    marginTop='30px'
+                    marginBottom='10px'
+                >
+                    <Grid item xs={5}>
+                        <Box
+                            display='flex'
+                            alignItems='center'
+                        >
+                            <Typography color='#616161'>Add subcategories</Typography>
+                            <Switch onChange={() =>
+                                setAddSub(!addSub)
+                            }/>
+                        </Box>
+                    </Grid>
+                </Grid>
+                {addSub &&
+                    <Grid
+                        container
+                        justifyContent='space-between'
+                        marginTop='30px'
+                        marginBottom='10px'
+                    >
+                        <AddSubCategory goods={goods} onCreate={value => setSubCategory({...value})}/>
+                    </Grid>
+                }
+            </Grid>
+        </>
+    )
+}
+
+const CategoryEdit = ({category,
+                          categoryCount,
+                          goods,
+                          actionRootCat,
+                          onCountCategory,
+                          onGoodFind,
+                          onCreateCategory,
+                          categoryUpsert}) => {
+    const [newCategory, setNewCategory] = useState({})
+    const [result, setResult] = useState(false)
+
+    useEffect(() => {
+        if(!goods) onGoodFind()
+        if(!category) actionRootCat()
+        if(!categoryCount) onCountCategory()
+        if(categoryUpsert) setResult(true)
+    }, [category, categoryCount, goods, categoryUpsert])
+
+    const handlerOnSave = () => {
+        onCreateCategory(newCategory)
+        onCountCategory()
+        actionRootCat()
+    }
+
+    return(
+        <>
+            <Typography
+                variant='h6'
+                letterSpacing='2px'
+                marginBottom='20px'
+            >
+                Total category: {categoryCount?.payload || 0}
+            </Typography>
+            {!result ?
+                <>
+                    {goods &&
+                        <AddRootCategory
+                            goods={goods}
+                            onCreate={value => setNewCategory({...value})}
+                        />
+                    }
+                    <Grid
+                        container
+                        justifyContent='center'
+                        marginTop='30px'
+                    >
+                        <Grid item xs={4}>
+                            <Button
+                                disabled={Object.entries(newCategory).length === 0}
+                                fullWidth
+                                variant="outlined"
+                                onClick={handlerOnSave}
+                            >
+                                Save
+                            </Button>
+                        </Grid>
+                    </Grid>
+                </>
+                :
+                <>
+                    <Typography
+                        variant='h5'
+                        textAlign='center'
+                        marginBottom='20px'
+                    >
+                        Category added successfully!!!
+                    </Typography>
+                </>
+            }
+        </>
+    )
+}
+export const CCategoryEdit = connect(state => ({category: state.category,
+    categoryCount: state.promise['categoryCount'], goods: state.promise['goodAllFind'],
+        categoryUpsert: state.promise['categoryUpsert'] }),
+    {actionRootCat: actionFullRootCats, onCountCategory: actionCategoryCount,
+        onGoodFind: actionAllGoodFind, onCreateCategory: actionCategoryUpsert})(CategoryEdit)

+ 3 - 0
src/pages/AdminPage/GoodsTab/GoodEdit.jsx

@@ -112,6 +112,7 @@ const GoodEdit = ({entity={images: [], categories: []},
         setState(entity)
     }
     const handleOnSave = () => {
+
         let query = {...state}
         state.images?.length > 0 ?
             query.images = state.images.map(item => {return {'_id': item['_id']}})
@@ -125,6 +126,7 @@ const GoodEdit = ({entity={images: [], categories: []},
         goodCount()
     }
     const handleFullClear = () => {
+        goodCount()
         setState(entity)
         actionClear('goodUpsert')
         actionClear('uploadFile')
@@ -140,6 +142,7 @@ const GoodEdit = ({entity={images: [], categories: []},
                 setState({...state, images: [fileStatus?.payload]})
         }
     },[categoryState, goods, fileStatus])
+
     return (
         <>
             {!result ?

+ 2 - 1
src/pages/CartPage/CartPage.jsx

@@ -120,7 +120,8 @@ const CartPage = ({order, cart, finalOrder, onCardChange, onCartClear, onCartRem
                                         }
                                     </>
                                 }
-                            </Box>:
+                            </Box>
+                            :
                             <Grid
                                 container
                                 justifyContent='space-between'

+ 11 - 7
src/pages/Catalog/CatalogPage.jsx

@@ -2,14 +2,15 @@ import {Container, Grid, useMediaQuery} from "@mui/material";
 import {useEffect} from "react";
 import Breadcrumb from "../../components/Breadcrumbs";
 import {connect} from "react-redux";
-import {actionFullAllCategory} from "../../actions/ActionCategory";
+import {actionFullAllCategory, actionFullRootCats} from "../../actions/ActionCategory";
 import {CategoryAside} from "./CategoryAside";
 import {Products} from "./Goods";
 
-const CatalogPage = ({category, actionRootCat}) => {
+const CatalogPage = ({category={}, actionRootCat}) => {
     const matches = useMediaQuery('(max-width:899px)')
+
     useEffect(() => {
-        if(!category) actionRootCat()
+        if(category && Object.entries(category).length === 0) actionRootCat()
     }, [category])
 
     return (
@@ -24,13 +25,16 @@ const CatalogPage = ({category, actionRootCat}) => {
             >
                 <Container maxWidth="lg">
                     <Grid container justifyContent='space-between'>
-                        {category?.payload && <CategoryAside category={category.payload}/>}
-                        <Products/>
+                        {category &&
+                            Object.entries(category).length > 0 &&
+                            <CategoryAside category={category}/>
+                        }
+                        <Products />
                     </Grid>
                 </Container>
             </main>
         </>
     )
 }
-export const CCatalogPage = connect(state => ({category: state.promise['allCategory']}),
-    {actionRootCat: actionFullAllCategory})(CatalogPage)
+export const CCatalogPage = connect(state => ({category: state.category}),
+    {actionRootCat: actionFullRootCats})(CatalogPage)

+ 17 - 3
src/pages/Catalog/CategoryAside.jsx

@@ -14,7 +14,10 @@ const CategoryItem = ({object: {_id, name, subCategories}={}}) => {
         <>
             {subCategories === null || !subCategories ?
                 <li>
-                    <Link style={{textDecoration: 'none'}} to={`/catalog/category/${_id}`}>
+                    <Link
+                        style={{textDecoration: 'none'}}
+                        to={`/catalog/category/${_id}`}
+                    >
                         <Typography
                             variant='body1'
                             color='#616161'
@@ -27,7 +30,12 @@ const CategoryItem = ({object: {_id, name, subCategories}={}}) => {
                 :
                 <li>
                     <Accordion
-                        style={{border: 'none', borderRadius: '0',marginTop: '-10px', boxShadow: 'none'}}
+                        style={{
+                            border: 'none',
+                            borderRadius: '0',
+                            marginTop: '-10px',
+                            boxShadow: 'none'
+                        }}
                         expanded={expanded === 'panel1'}
                         onChange={handleChange('panel1')}
                     >
@@ -51,7 +59,13 @@ const CategoryItem = ({object: {_id, name, subCategories}={}}) => {
                             </Link>
                         </AccordionSummary>
                         <AccordionDetails>
-                            <ul style={{listStyle: 'none', padding: '0 0 0 10px', marginBottom: '10px'}}>
+                            <ul
+                                style={{
+                                    listStyle: 'none',
+                                    padding: '0 0 0 10px',
+                                    marginBottom: '10px'
+                                }}
+                            >
                                 {subCategories && Object.values(subCategories).map(item =>
                                     <CategoryItem key={item['_id']} object={item}/>
                                 )}

+ 3 - 3
src/pages/Catalog/Goods.jsx

@@ -25,7 +25,6 @@ import {NotFoundBlock} from "../../components/NotFoundBlock";
 import {actionFullCatById} from "../../actions/ActionCategory";
 import Switch from "react-router-dom/es/Switch";
 import Route from "react-router-dom/es/Route";
-import {CRRoute} from "../../components/CPRoute";
 
 const GoodCard = ({good:{_id, name, description, price, images}={},
                       wishlist={},
@@ -215,6 +214,7 @@ const Goods = ({_id, category={}}) => {
         }).filter(item => item)
         setGoods(arr)
     }, [_id, category])
+
     return (
         <>
             {(goods.length > 0 ?
@@ -311,8 +311,8 @@ export const Products = () => {
     return (
         <Grid xs={12} lg={9} item>
             <Switch>
-                <CRRoute path="/catalog/category/:_id" component={CBlockGood} />
-                <CRRoute path="*" component={NotFoundBlock} />
+                <Route path="/catalog/category/:_id" component={CBlockGood} />
+                <Route path="*" component={NotFoundBlock} />
             </Switch>
         </Grid>
     )

+ 17 - 9
src/pages/ProfilePage/FormUpload.jsx

@@ -3,11 +3,14 @@ import {Button, Grid, TextField} from "@mui/material";
 import SendAndArchiveIcon from "@mui/icons-material/SendAndArchive";
 import CancelIcon from "@mui/icons-material/Cancel";
 import {connect} from "react-redux";
-import {actionSetAvatar, actionSetLogin, actionSetNick, actionSetPassword} from "../../actions/ActionUploadFile";
+import {
+    actionSetAvatar,
+    actionSetUserUpsert
+} from "../../actions/ActionUploadFile";
 import {actionFullUserFindOne} from "../../actions/ActionUserFind";
 import {MyDropzone} from "./MyDropzone";
 
-const FormUpload = ({user, setStatus, setLogin, setNick, setPassword, setImage}) => {
+const FormUpload = ({user, setStatus, setUserUpsert, setImage}) => {
     const [loginValue, setLoginValue] = useState(user?.login || '')
     const [nickValue, setNickValue] = useState(user?.nick || '')
     const [passwordValue, setPasswordValue] = useState('')
@@ -69,19 +72,24 @@ const FormUpload = ({user, setStatus, setLogin, setNick, setPassword, setImage})
                     fullWidth
                     type='submit'
                     onClick={() => {
+                        let obj = {}
                         if (loginValue !== user?.login) {
-                            setLogin(loginValue)
+                            obj.login = loginValue
                         }
                         if (nickValue !== user?.nick) {
-                            setNick(nickValue)
+                            obj.nick = nickValue
                         }
                         if (passwordValue){
-                            setPassword(passwordValue)
+                            obj.password = passwordValue
                         }
                         if (Array.isArray(fileValue) && fileValue[0]) {
                             setImage(fileValue[0]);
+                            setStatus(false)
+                        }
+                        if (Object.values(obj).length > 0){
+                            setUserUpsert(obj)
+                            setStatus(false)
                         }
-                        setStatus(false)
                     }}
                 >
                     <SendAndArchiveIcon style={{marginRight: '5px'}}/>
@@ -99,6 +107,6 @@ const FormUpload = ({user, setStatus, setLogin, setNick, setPassword, setImage})
         </Grid>
     )
 }
-export const CFormUpload = connect(null, {setLogin: actionSetLogin,
-    setNick: actionSetNick, setPassword: actionSetPassword, setImage: actionSetAvatar,
-    userUpdate: actionFullUserFindOne})(FormUpload)
+export const CFormUpload = connect(null,
+    {setUserUpsert: actionSetUserUpsert,
+        setImage: actionSetAvatar, userUpdate: actionFullUserFindOne})(FormUpload)