|
@@ -1,45 +1,81 @@
|
|
|
import { Input, Card, Button, Space, Image, Row } from 'antd';
|
|
|
-import { useEffect, useState } from 'react';
|
|
|
+import { useEffect, useRef, useState } from 'react';
|
|
|
import { connect } from 'react-redux';
|
|
|
import { InputUpLoadFile } from '.';
|
|
|
import { backURL } from '../api';
|
|
|
|
|
|
const { TextArea } = Input;
|
|
|
|
|
|
-const CharacterfGood =({ good, good:{ _id, name, description, images, price }, upLoad, changeGood }) => { console.log('gooood',good)
|
|
|
+const CharacterfGood =({ good, good:{ _id, name, description, images, price }, upLoad, changeGood, number, changeIndexGoodInSer }) => {
|
|
|
const [ inputIdImg, setInputIdImg] = useState('');
|
|
|
const [ inputName, setInputName ] = useState(name);
|
|
|
const [ inputDescrip, setInputDescrip] = useState(description);
|
|
|
- const [ img, setImg ] = useState('');
|
|
|
+ const [ imag, setImag ] = useState('');
|
|
|
const [ cost, setCost ] = useState(price);
|
|
|
+ const [inputNumber, setInputNumber] = useState(number);
|
|
|
|
|
|
useEffect( () => {
|
|
|
setInputName(name);
|
|
|
setInputDescrip(description);
|
|
|
|
|
|
- if(images && images[0].url) {
|
|
|
- setImg(images[0].url);
|
|
|
+ if (images && images[0].url) {
|
|
|
+ setImag(images[0].url);
|
|
|
+ setInputIdImg(images[0]._id);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (Object.keys(good).length === 0) { console.log('gfergergrthetrhrthyrty')
|
|
|
+ setImag('');
|
|
|
+ setInputIdImg('');
|
|
|
+ }
|
|
|
+ if(images && !images[0].url) {
|
|
|
+ setImag('');
|
|
|
+ setInputIdImg('');
|
|
|
}
|
|
|
|
|
|
- setCost(price);
|
|
|
+ setCost(price);
|
|
|
+ setInputNumber(number);
|
|
|
+
|
|
|
|
|
|
}, [good])
|
|
|
|
|
|
+
|
|
|
+
|
|
|
useEffect(() => {
|
|
|
- if(upLoad && upLoad.status === 'RESOLVED' ) { console.log('',)
|
|
|
- setImg(upLoad.payload.url);
|
|
|
- setInputIdImg(upLoad.payload._id); //61e304d8f9be102f49b2aa5c
|
|
|
+ if(upLoad && upLoad.status === 'RESOLVED' ) {
|
|
|
+ setImag(upLoad.payload.url); console.log('39', imag)
|
|
|
+ setInputIdImg(upLoad.payload._id);
|
|
|
}
|
|
|
+
|
|
|
}, [upLoad])
|
|
|
+
|
|
|
// onChange = ({ target: { value } }) => {
|
|
|
// setInputDescrip(value);
|
|
|
// };
|
|
|
|
|
|
+ const clearInput = () => {
|
|
|
+ setInputName('');
|
|
|
+ setInputDescrip('');
|
|
|
+ setCost('');
|
|
|
+ setImag ('');
|
|
|
+ setInputIdImg('');
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ const saveChange = () => {
|
|
|
+ changeGood(inputName, inputDescrip, cost, inputIdImg );
|
|
|
+ changeIndexGoodInSer(inputNumber);
|
|
|
+ clearInput();
|
|
|
+ }
|
|
|
+ console.log('imag', imag); console.log('good',good)
|
|
|
return (
|
|
|
<div >
|
|
|
+ <div>№ в категории</div>
|
|
|
+ <Input value={inputNumber} onChange={(e) => setInputNumber(e.target.value)}/>
|
|
|
+ <Button type="primary" onClick={() => setInputNumber('')}>Очистить поле</Button>
|
|
|
+
|
|
|
<div>Название</div>
|
|
|
<Input value={inputName} onChange={(e) => setInputName(e.target.value)}/>
|
|
|
- <Button type="primary" >Очистить поле</Button>
|
|
|
+ <Button type="primary" onClick={() => setInputName('')}>Очистить поле</Button>
|
|
|
<div>Характеристика</div>
|
|
|
<TextArea
|
|
|
value={inputDescrip}
|
|
@@ -47,11 +83,11 @@ const CharacterfGood =({ good, good:{ _id, name, description, images, price }, u
|
|
|
|
|
|
autoSize={{ minRows: 3, maxRows: 5 }}
|
|
|
/>
|
|
|
- <Button type="primary" >Очистить поле</Button>
|
|
|
+ <Button type="primary" onClick={() => setInputDescrip('')}>Очистить поле</Button>
|
|
|
<div>Цена</div>
|
|
|
<Row>
|
|
|
<Input value={cost} onChange={(e) => setCost(e.target.value)}/>
|
|
|
- <Button type="primary" >Очистить поле</Button>
|
|
|
+ <Button type="primary" onClick={() => setCost('')}>Очистить поле</Button>
|
|
|
</Row>
|
|
|
|
|
|
|
|
@@ -62,12 +98,12 @@ const CharacterfGood =({ good, good:{ _id, name, description, images, price }, u
|
|
|
{Object.keys(good).length === 0 ?
|
|
|
<div style={{height:"150px", width:"150px"}}> </div>
|
|
|
:
|
|
|
- <Image width={150} height={150} src={`${backURL}/${img}`} style={{ objectFit: 'cover' }}/>}
|
|
|
+ <Image width={150} height={150} src={`${backURL}/${imag}`} style={{ objectFit: 'cover' }}/>}
|
|
|
<InputUpLoadFile/>
|
|
|
{/* </div> */}
|
|
|
</Space>
|
|
|
<Space size={2}></Space>
|
|
|
- <Button type="primary" block onClick={() => changeGood(inputName, inputDescrip, cost, inputIdImg )}>
|
|
|
+ <Button type="primary" block onClick={saveChange}>
|
|
|
Сохранить изменения
|
|
|
</Button>
|
|
|
</div>
|