Complete edit release functionality

merge-requests/169/head
Jayasanka 5 years ago
parent aaefdb36fc
commit 2d2efb1b30

@ -42,13 +42,6 @@ class CurrentUsersReview extends React.Component {
}); });
}; };
updateCallback = (response) =>{
const {rating, content} = response;
this.setState({
rating,
content
});
};
render() { render() {
const {data} = this.state; const {data} = this.state;
@ -67,7 +60,7 @@ class CurrentUsersReview extends React.Component {
dataSource={data} dataSource={data}
renderItem={item => ( renderItem={item => (
<List.Item key={item.id}> <List.Item key={item.id}>
<SingleReview uuid={uuid} review={item} isDeletable={true} isEditable={true} updateCallback={this.updateCallback}/> <SingleReview uuid={uuid} review={item} isDeletable={true} isEditable={true}/>
</List.Item> </List.Item>
)} )}
> >

@ -10,16 +10,44 @@ const {Text, Paragraph} = Typography;
const colorList = ['#f0932b', '#badc58', '#6ab04c', '#eb4d4b', '#0abde3', '#9b59b6', '#3498db', '#22a6b3','#e84393','#f9ca24']; const colorList = ['#f0932b', '#badc58', '#6ab04c', '#eb4d4b', '#0abde3', '#9b59b6', '#3498db', '#22a6b3','#e84393','#f9ca24'];
class SingleReview extends React.Component { class SingleReview extends React.Component {
constructor(props) {
super(props);
this.state = {
content: '',
rating: 0,
color: '#f0932b'
}
}
componentDidMount() {
const {content, rating, username} = this.props.review;
const color = colorList[username.length%10];
this.setState({
content,
rating,
color
});
}
updateCallback = (response) =>{
console.log(response);
const {rating, content} = response;
this.setState({
rating,
content
});
};
render() { render() {
const {review, isEditable, isDeletable, uuid} = this.props; const {review, isEditable, isDeletable, uuid} = this.props;
const {content, rating, color} = this.state;
const {username} = review; const {username} = review;
const randomColor = colorList[username.length%10];
const avatarLetter = username.charAt(0).toUpperCase(); const avatarLetter = username.charAt(0).toUpperCase();
const content = ( const body = (
<div style={{marginTop: -5}}> <div style={{marginTop: -5}}>
<StarRatings <StarRatings
rating={review.rating} rating={rating}
starRatedColor="#777" starRatedColor="#777"
starDimension="12px" starDimension="12px"
starSpacing="2px" starSpacing="2px"
@ -29,7 +57,7 @@ class SingleReview extends React.Component {
<Text style={{fontSize: 12, color: "#aaa"}} type="secondary"> {review.createdAt}</Text><br/> <Text style={{fontSize: 12, color: "#aaa"}} type="secondary"> {review.createdAt}</Text><br/>
<Paragraph style={{color: "#777"}}> <Paragraph style={{color: "#777"}}>
<Twemoji options={{className: 'twemoji'}}> <Twemoji options={{className: 'twemoji'}}>
{review.content} {content}
</Twemoji> </Twemoji>
</Paragraph> </Paragraph>
</div> </div>
@ -38,7 +66,7 @@ class SingleReview extends React.Component {
const title = ( const title = (
<div> <div>
{review.username} {review.username}
{isEditable && (<EditReview uuid={uuid} review={review}/>)} {isEditable && (<EditReview uuid={uuid} review={review} updateCallback={this.updateCallback}/>)}
{isDeletable && (<span className="delete-button">delete</span>)} {isDeletable && (<span className="delete-button">delete</span>)}
</div> </div>
); );
@ -47,12 +75,12 @@ class SingleReview extends React.Component {
<div> <div>
<List.Item.Meta <List.Item.Meta
avatar={ avatar={
<Avatar style={{backgroundColor: randomColor, verticalAlign: 'middle'}} size="large"> <Avatar style={{backgroundColor: color, verticalAlign: 'middle'}} size="large">
{avatarLetter} {avatarLetter}
</Avatar> </Avatar>
} }
title={title} title={title}
description={content} description={body}
/> />
</div> </div>
); );

@ -80,6 +80,8 @@ class EditReview extends React.Component {
description: description:
'Your review has been update successfully.', 'Your review has been update successfully.',
}); });
this.props.updateCallback(res.data.data);
} else { } else {
this.setState({ this.setState({
loading: false, loading: false,
@ -93,7 +95,8 @@ class EditReview extends React.Component {
} }
}).catch((error) => { }).catch((error) => {
if (error.response.status === 401) { console.log(error);
if (error.hasOwnProperty("response") && error.response.status === 401) {
window.location.href = config.serverConfig.protocol + "://" + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + '/store/login'; window.location.href = config.serverConfig.protocol + "://" + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + '/store/login';
} else { } else {
this.setState({ this.setState({

Loading…
Cancel
Save