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