1 | import React, {useEffect, useState} from 'react'
|
---|
2 | import {Button, Card, Input, List, Rate, Spin, Tooltip} from "antd";
|
---|
3 | import axios from "axios";
|
---|
4 | import env from "../env";
|
---|
5 | import moment from "moment";
|
---|
6 |
|
---|
7 | const Review = props => {
|
---|
8 | const [restaurant, setRestaurant] = useState({});
|
---|
9 | const [loading, setLoading] = useState(true);
|
---|
10 |
|
---|
11 | useEffect(()=> {
|
---|
12 | setLoading(true);
|
---|
13 | getRestaurant()
|
---|
14 | },[])
|
---|
15 | useEffect(()=> {
|
---|
16 | getRestaurant()
|
---|
17 | },[props.refresh])
|
---|
18 |
|
---|
19 | const getRestaurant = () => {
|
---|
20 | axios.get(env.api + 'Restaurants').then(res=>{
|
---|
21 | setRestaurant(res.data);
|
---|
22 | setLoading(false);
|
---|
23 | });
|
---|
24 | }
|
---|
25 |
|
---|
26 | return(
|
---|
27 | <div style={{padding: props.front ? 0 : '20px',textAlign:'start'}}>
|
---|
28 | <div style={{
|
---|
29 | width: '100%',
|
---|
30 | backgroundColor: 'white',
|
---|
31 | padding: '20px',
|
---|
32 | height:'75px',
|
---|
33 | border: '1px solid lightgray'
|
---|
34 | }} id={'expandMain'}>
|
---|
35 | <h2 style={{float: 'left'}}>Оценки</h2>
|
---|
36 | {props.front ?
|
---|
37 | (props.user?
|
---|
38 | <Button style={{float:'right'}} type={'primary'} onClick={()=>props.setVisible(true)}>Внеси оценка</Button>
|
---|
39 | : <Tooltip title={'Мора да се најавите за да оставите оценка'}><Button style={{float:'right'}} disabled type={'primary'} onClick={()=>props.setVisible(true)}>Внеси оценка</Button></Tooltip>)
|
---|
40 | : ''
|
---|
41 | }
|
---|
42 | </div>
|
---|
43 | {loading ? <Spin style={{margin: '20px'}}/> :
|
---|
44 | <div>
|
---|
45 | <div style={{backgroundColor: 'white',padding:'10px', border:'1px solid lightgray', borderTop: 'none'}}>
|
---|
46 | <h3>Средна оценка: <Rate disabled allowHalf value={restaurant.averageReview}/> од вкупно {restaurant.reviews.length} оценки</h3>
|
---|
47 | </div>
|
---|
48 | <List dataSource={restaurant.reviews} itemLayout={'horizontal'} locale={{emptyText:'Нема оставени оценки за овој ресторан'}}
|
---|
49 | renderItem={item => (
|
---|
50 | <Card title={item.title} style={{width:'98%',backgroundColor:'white',margin:'1%'}}>
|
---|
51 | <p>{item.description}</p>
|
---|
52 | <Rate disabled value={item.stars}/>
|
---|
53 | <p style={{color:'gray'}}>{item.username} / {moment(item.createdAt).format("DD.MM.yyyy")}</p>
|
---|
54 | </Card>
|
---|
55 | )}/>
|
---|
56 | </div>
|
---|
57 |
|
---|
58 | }
|
---|
59 | </div>
|
---|
60 | )
|
---|
61 | }
|
---|
62 |
|
---|
63 | export default Review; |
---|