|
@@ -1,5 +1,4 @@
|
|
|
-import { useEffect, useState } from 'react';
|
|
|
-import { Card, Image, Button, Alert } from 'antd';
|
|
|
+import { Card, Image, Button, Alert, Row } from 'antd';
|
|
|
import { connect } from 'react-redux';
|
|
|
import { backURL } from '../api';
|
|
|
import { actionCartAdd } from '../action';
|
|
@@ -7,15 +6,8 @@ import { useHistory } from 'react-router-dom';
|
|
|
|
|
|
const ContentSearch = ({ value, onAdd }) => {
|
|
|
console.log('value', value);
|
|
|
- const [good, setGood] = useState(value);
|
|
|
const history = useHistory();
|
|
|
|
|
|
- useEffect(() => {
|
|
|
- if (value.length) {
|
|
|
- setGood(value[0]);
|
|
|
- }
|
|
|
- }, [value]);
|
|
|
-
|
|
|
const onClose = (e) => {
|
|
|
console.log(e, 'I was closed.');
|
|
|
history.push('/');
|
|
@@ -23,20 +15,23 @@ const ContentSearch = ({ value, onAdd }) => {
|
|
|
|
|
|
return (
|
|
|
<> { value.length
|
|
|
- ? <Card title={good.name} style={{ width: 350 }} hoverable>
|
|
|
- {good.images &&
|
|
|
- good.images[0] &&
|
|
|
- good.images[0].url &&
|
|
|
- <Image width={300} src={backURL + '/' + good.images[0].url} />}
|
|
|
- <p>{good.description}</p>
|
|
|
- <p>{good.price} грн</p>
|
|
|
+ ? <Row >
|
|
|
+ {value.map((item) =>
|
|
|
+ <Card key={item._id} title={item.name} style={{ width: 350 }} hoverable>
|
|
|
+ {item.images &&
|
|
|
+ item.images[0] &&
|
|
|
+ item.images[0].url &&
|
|
|
+ <Image width={300} src={backURL + '/' + item.images[0].url} />}
|
|
|
+ <p>{item.description}</p>
|
|
|
+ <p>{item.price} грн</p>
|
|
|
<Button onClick={() => onAdd({
|
|
|
- _id: good._id,
|
|
|
- name: good.name,
|
|
|
- price: good.price,
|
|
|
- images: good.images
|
|
|
+ _id: item._id,
|
|
|
+ name: item.name,
|
|
|
+ price: item.price,
|
|
|
+ images: item.images
|
|
|
})}>Купить</Button>
|
|
|
- </Card>
|
|
|
+ </Card>)}
|
|
|
+ </Row>
|
|
|
: <>
|
|
|
<Alert
|
|
|
message="Товара с таким названием не существует"
|