nameCategory.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { Input, Card, Button, Space } from 'antd';
  2. import { useEffect, useState } from 'react';
  3. import { connect } from 'react-redux';
  4. import { actionChangeCategName } from '../action';
  5. const CategoryAdmin = ({category, _id, changeCategName }) => {
  6. const [nameCat, setNameCat] = useState(category.name);
  7. useEffect ( () => {
  8. setNameCat(category.name)
  9. }, [category])
  10. const renewCategory = () => {
  11. changeCategName(_id, nameCat);// console.log('zzz', typeof _id)
  12. setNameCat('');
  13. }
  14. const clearInput = () => {
  15. setNameCat('');
  16. }
  17. return (
  18. <div >
  19. <Card type="inner" title="Изменить категорию товара">
  20. <Input value={nameCat} onChange={ (e) => setNameCat(e.target.value)}/>
  21. <Space>
  22. <Button type="primary" onClick={renewCategory}>Сохранить изменения</Button>
  23. <Button type="primary" onClick={clearInput} >Очистить поле</Button>
  24. </Space>
  25. </Card>
  26. </div>
  27. )
  28. }
  29. const mapStateToProps = (state) => ({
  30. category: state.promise. catById?.payload || {},
  31. allcategory: state.promise.rootCats?.payload || [],
  32. })
  33. const NameCategory = connect(mapStateToProps, { changeCategName :actionChangeCategName })(CategoryAdmin);
  34. export default NameCategory;