parent
f66ad9ddd9
commit
7675f5a315
@ -0,0 +1,101 @@
|
||||
import React from "react";
|
||||
import {List, message, Typography, Empty, Button, Row, Col} from "antd";
|
||||
import SingleReview from "./SingleReview";
|
||||
import axios from "axios";
|
||||
import config from "../../../../../public/conf/config.json";
|
||||
import AddReview from "./AddReview";
|
||||
|
||||
const {Text, Paragraph} = Typography;
|
||||
|
||||
class CurrentUsersReview extends React.Component {
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
data: []
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.fetchData();
|
||||
}
|
||||
|
||||
fetchData = () => {
|
||||
const {uuid} = this.props;
|
||||
|
||||
axios.get(
|
||||
config.serverConfig.protocol + "://" + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invoker.uri + config.serverConfig.invoker.store + "/reviews/app/user/" + uuid,
|
||||
).then(res => {
|
||||
if (res.status === 200) {
|
||||
const data = res.data.data.data;
|
||||
this.setState({data});
|
||||
}
|
||||
|
||||
}).catch((error) => {
|
||||
if (error.response.hasOwnProperty(status) && error.response.status === 401) {
|
||||
message.error('You are not logged in');
|
||||
window.location.href = config.serverConfig.protocol + "://" + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + '/store/login';
|
||||
} else {
|
||||
message.error('Something went wrong when trying to get your review... :(');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
render() {
|
||||
const {data} = this.state;
|
||||
const {uuid} = this.props;
|
||||
return (
|
||||
<div>
|
||||
<Text>MY REVIEW</Text>
|
||||
<div style={{
|
||||
overflow: "auto",
|
||||
paddingTop: 8,
|
||||
paddingLeft: 24
|
||||
}}>
|
||||
{data.length > 0 && (
|
||||
<div>
|
||||
<Row>
|
||||
<Col span={18}>
|
||||
<List
|
||||
dataSource={data}
|
||||
renderItem={item => (
|
||||
<List.Item key={item.id}>
|
||||
<SingleReview review={item}/>
|
||||
</List.Item>
|
||||
)}
|
||||
>
|
||||
</List>
|
||||
</Col>
|
||||
<Col span={6}>
|
||||
<Button type="primary" shape="circle" icon="search" />
|
||||
</Col>
|
||||
</Row>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{data.length === 0 && (
|
||||
<div>
|
||||
<Empty
|
||||
image={Empty.PRESENTED_IMAGE_DEFAULT}
|
||||
imagestyle={{
|
||||
height: 60,
|
||||
}}
|
||||
description={
|
||||
<span>Share your experience with your community by adding a review.</span>
|
||||
}
|
||||
>
|
||||
{/*<Button type="primary">Add review</Button>*/}
|
||||
<AddReview uuid={uuid}/>
|
||||
</Empty>
|
||||
</div>
|
||||
)}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default CurrentUsersReview;
|
@ -0,0 +1,164 @@
|
||||
import React from "react";
|
||||
import {Drawer, Button, Icon, Row, Col, Typography, Divider, Input, Spin, notification} from 'antd';
|
||||
import StarRatings from "react-star-ratings";
|
||||
import axios from "axios";
|
||||
import config from "../../../../../public/conf/config.json";
|
||||
|
||||
const {Title} = Typography;
|
||||
const {TextArea} = Input;
|
||||
|
||||
class EditReview extends React.Component {
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
visible: false,
|
||||
content: '',
|
||||
rating: 0,
|
||||
loading: false
|
||||
};
|
||||
}
|
||||
|
||||
showDrawer = () => {
|
||||
this.setState({
|
||||
visible: true,
|
||||
content: '',
|
||||
rating: 0,
|
||||
loading: false
|
||||
});
|
||||
};
|
||||
|
||||
onClose = () => {
|
||||
this.setState({
|
||||
visible: false,
|
||||
|
||||
});
|
||||
};
|
||||
changeRating = (newRating, name) => {
|
||||
this.setState({
|
||||
rating: newRating
|
||||
});
|
||||
};
|
||||
|
||||
onChange = (e) => {
|
||||
this.setState({content: e.target.value})
|
||||
};
|
||||
|
||||
onSubmit = () => {
|
||||
const {content, rating} = this.state;
|
||||
const {uuid} = this.props;
|
||||
this.setState({
|
||||
loading: true
|
||||
});
|
||||
|
||||
const payload = {
|
||||
content: content,
|
||||
rating: rating
|
||||
};
|
||||
|
||||
axios.post(
|
||||
config.serverConfig.protocol + "://" + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invoker.uri + config.serverConfig.invoker.store + "/reviews/" + uuid,
|
||||
payload,
|
||||
).then(res => {
|
||||
if (res.status === 201) {
|
||||
this.setState({
|
||||
loading: false,
|
||||
visible: false
|
||||
});
|
||||
notification["success"]({
|
||||
message: 'Done!',
|
||||
description:
|
||||
'Your review has been posted successfully.',
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
window.location.href = uuid;
|
||||
}, 2000)
|
||||
} else {
|
||||
this.setState({
|
||||
loading: false,
|
||||
visible: false
|
||||
});
|
||||
notification["error"]({
|
||||
message: 'Something went wrong',
|
||||
description:
|
||||
"We are unable to add your review right now.",
|
||||
});
|
||||
}
|
||||
|
||||
}).catch((error) => {
|
||||
if (error.response.status === 401) {
|
||||
window.location.href = config.serverConfig.protocol + "://" + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + '/store/login';
|
||||
} else {
|
||||
this.setState({
|
||||
loading: false,
|
||||
visible: false
|
||||
});
|
||||
notification["error"]({
|
||||
message: 'Something went wrong',
|
||||
description:
|
||||
"We are unable to add your review right now.",
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
};
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
<Button type="primary" onClick={this.showDrawer}>
|
||||
<Icon type="star"/> Add a review
|
||||
</Button>
|
||||
|
||||
<Drawer
|
||||
// title="Basic Drawer"
|
||||
placement="bottom"
|
||||
closable={false}
|
||||
onClose={this.onClose}
|
||||
visible={this.state.visible}
|
||||
height={400}
|
||||
>
|
||||
<Spin spinning={this.state.loading} tip="Posting your review...">
|
||||
<Row>
|
||||
<Col lg={8}/>
|
||||
<Col lg={8}>
|
||||
<Title level={4}>Add review</Title>
|
||||
<Divider/>
|
||||
<TextArea
|
||||
placeholder="Tell others what you think about this app. Would you recommend it, and why?"
|
||||
onChange={this.onChange}
|
||||
autosize={{minRows: 6, maxRows: 12}}
|
||||
value={this.state.content || ''}
|
||||
style={{marginBottom: 20}}
|
||||
/>
|
||||
<StarRatings
|
||||
rating={this.state.rating}
|
||||
changeRating={this.changeRating}
|
||||
starRatedColor="#777"
|
||||
starHoverColor="#444"
|
||||
starDimension="20px"
|
||||
starSpacing="2px"
|
||||
numberOfStars={5}
|
||||
name='rating'
|
||||
/>
|
||||
<br/><br/>
|
||||
<Button onClick={this.onClose} style={{marginRight: 8}}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button disabled={this.state.rating === 0} onClick={this.onSubmit} type="primary">
|
||||
Submit
|
||||
</Button>
|
||||
</Col>
|
||||
</Row>
|
||||
</Spin>
|
||||
</Drawer>
|
||||
|
||||
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default EditReview;
|
Loading…
Reference in new issue