-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from GSG-G7/34-feedback
34 feedback component
- Loading branch information
Showing
12 changed files
with
281 additions
and
17 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
import React from 'react'; | ||
import ReactStars from 'react-stars'; | ||
import propTypes from 'prop-types'; | ||
import Button from '../utils/Button'; | ||
import schemad from '../../validation/feedback'; | ||
import Pop from '../utils/PopUp'; | ||
import './style.css'; | ||
|
||
export default class FeedbackComponent extends React.Component { | ||
state = { | ||
rate: 2.5, | ||
email: '', | ||
content: '', | ||
feedbackDone: '', | ||
errorMessage: '', | ||
}; | ||
|
||
setFeedback = event => this.setState({ content: event.target.value }); | ||
|
||
setEmail = event => this.setState({ email: event.target.value }); | ||
|
||
newRate = newR => this.setState({ rate: newR }); | ||
|
||
sendFeedback = () => { | ||
const { | ||
location: { state }, | ||
} = this.props; | ||
|
||
const { history } = this.props; | ||
if (!state) { | ||
history.push('/'); | ||
return ''; | ||
} | ||
const { | ||
location: { | ||
state: { orderId }, | ||
}, | ||
} = this.props; | ||
const { email, content: feedback } = this.state; | ||
const data = { | ||
orderId, | ||
email, | ||
feedback, | ||
}; | ||
return schemad | ||
.validateAsync(data) | ||
.then(() => | ||
fetch('/api/v1/post-feedback', { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify(data), | ||
}) | ||
) | ||
.then(res => res.json()) | ||
.then(payload => { | ||
return payload.statusCode === 201 | ||
? this.setState({ feedbackDone: 'feedback sent successfully' }) | ||
: this.setState({ errorMessage: payload.error }); | ||
}) | ||
.catch(err => { | ||
if (err.details[0]) { | ||
this.setState({ errorMessage: err.details[0].message }); | ||
} else { | ||
history.push('/serverError'); | ||
} | ||
}); | ||
}; | ||
|
||
feedbackPopUp = () => { | ||
const { history } = this.props; | ||
const { feedbackDone } = this.state; | ||
if (feedbackDone) | ||
return ( | ||
<Pop | ||
message={feedbackDone} | ||
is2btnNeeded={false} | ||
onClick1={() => history.push('/')} | ||
btnName1="Home" | ||
/> | ||
); | ||
return ''; | ||
}; | ||
|
||
render() { | ||
const { history } = this.props; | ||
const { rate, errorMessage, email, content } = this.state; | ||
|
||
return ( | ||
<div> | ||
{this.feedbackPopUp()} | ||
<div className="bg"> | ||
<div className="card"> | ||
<h3 className="header-feedback"> feedback</h3> | ||
<div className="order-info"> | ||
<div className="order-number"> | ||
<p> 23</p> | ||
<h4>Order</h4> | ||
</div> | ||
<div className="table-number"> | ||
<p>5</p> | ||
<h4>Table</h4> | ||
</div> | ||
</div> | ||
<div className="error">{errorMessage}</div> | ||
<form className="feedback-form"> | ||
<input | ||
type="email" | ||
value={email} | ||
onChange={this.setEmail} | ||
className="email" | ||
placeholder="Email" | ||
/> | ||
|
||
<textarea | ||
className="feedback" | ||
value={content} | ||
onChange={this.setFeedback} | ||
placeholder="We are looking forward to hearing from you" | ||
></textarea> | ||
</form> | ||
<div className="container_star"> | ||
<ReactStars | ||
value={rate} | ||
count={5} | ||
onChange={this.newRate} | ||
size={24} | ||
color2="#F5C518" | ||
/> | ||
</div> | ||
<div className="All"> | ||
<div className="div-button"> | ||
<Button className="button" onClick={this.sendFeedback}> | ||
Send | ||
</Button> | ||
</div> | ||
<div className="div-button"> | ||
<Button className="button" onClick={() => history.push('/')}> | ||
Cancel | ||
</Button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
FeedbackComponent.propTypes = { | ||
history: propTypes.objectOf(propTypes.any).isRequired, | ||
orderId: propTypes.number.isRequired, | ||
location: propTypes.objectOf(propTypes.any).isRequired, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
:root{ | ||
--width-inputs:60vw; | ||
} | ||
.bg{ | ||
background: url('../../assets/images/feedback.png'); | ||
width: 100vw; | ||
height: 100vh; | ||
background-repeat: no-repeat; | ||
background-size: cover; | ||
padding: 1.4rem; | ||
} | ||
|
||
.card{ | ||
margin: 1rem auto; | ||
background: #000; | ||
font-family: Lato, sans-serif; | ||
color: white; | ||
opacity: .85; | ||
width: 75vw; | ||
height: 77vh; | ||
border-radius: .3rem; | ||
padding: 1rem; | ||
padding-top: 6vh; | ||
} | ||
.header-feedback{ | ||
text-align: center; | ||
margin-bottom: 3.4vh; | ||
font-size: 2.8vh; | ||
} | ||
.error{ | ||
text-align: center; | ||
color: red | ||
} | ||
.order-info{ | ||
margin-bottom: 2rem; | ||
background: #ED6707; | ||
margin: 1vh auto; | ||
width: 60vw; | ||
font-size: 14px; | ||
height: 3.5rem; | ||
border-radius: .2rem; | ||
display: flex; | ||
text-align: center; | ||
line-height: 1.4rem; | ||
padding: .45rem; | ||
} | ||
.order-number{ | ||
width: 40vw | ||
} | ||
.table-number{ | ||
width:40vw | ||
} | ||
.feedback-form{ | ||
text-align: center; | ||
padding-top: 1.6vh; | ||
} | ||
.email{ | ||
width: var(--width-inputs); | ||
border-radius: 3px; | ||
height: 45.33px; | ||
font-size: 0.75rem; | ||
padding: .2rem; | ||
position: unset; | ||
color:black; | ||
padding-left: .5rem; | ||
} | ||
.feedback{ | ||
width: var(--width-inputs); | ||
border-radius: 3px; | ||
height: 6rem; | ||
margin-top:.6rem; | ||
padding: .2rem; | ||
font-size: 0.75rem; | ||
padding-left: .5rem; | ||
} | ||
|
||
.container_star{ | ||
position: absolute; | ||
right: 50%; | ||
margin: 0 auto; | ||
transform: translate(50%, 19%); | ||
} | ||
.first{ | ||
margin-top: 4rem; | ||
} | ||
.div-button{ | ||
margin: .1rem auto 0 auto; | ||
width: 44.2vw; | ||
} | ||
|
||
.button{ | ||
width: 44.2vw; | ||
} | ||
.All{ | ||
margin-top: 8.5vh; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Joi from '@hapi/joi'; | ||
|
||
const feedbackSchema = Joi.object().keys({ | ||
orderId: Joi.number().required(), | ||
email: Joi.string() | ||
.email({ minDomainSegments: 2, tlds: { allow: ['com', 'net'] } }) | ||
.required(), | ||
feedback: Joi.string().required(), | ||
}); | ||
|
||
export default feedbackSchema; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.