-
Notifications
You must be signed in to change notification settings - Fork 10.3k
feat(www): add unbird feedback form component #10450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
amberleyromo
merged 7 commits into
gatsbyjs:master
from
amberleyromo:starters/add-unbird-form
Dec 14, 2018
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
58b5643
feat(www): add unbird feedback form component
amberleyromo 75be33b
Merge remote-tracking branch 'upstream/master' into starters/add-unbi…
amberleyromo a000e09
fix: prettier
amberleyromo ef84f5a
fix: mistaken event param
DSchau 0f82d4a
fix: input required
amberleyromo b72c9d1
fix: styling review edits from @greglobinski
amberleyromo 06f83a1
Merge branch 'starters/add-unbird-form' of https://github.com/amberle…
amberleyromo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
| "author": "Kyle Mathews <[email protected]>", | ||
| "dependencies": { | ||
| "@reach/skip-nav": "^0.1.1", | ||
| "axios": "^0.18.0", | ||
| "bluebird": "^3.5.1", | ||
| "dotenv": "^6.0.0", | ||
| "email-validator": "^1.1.1", | ||
|
|
||
This file contains hidden or 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,223 @@ | ||
| import React from "react" | ||
| import PropTypes from "prop-types" | ||
| import axios from "axios" | ||
| import styled from "react-emotion" | ||
| import { rhythm, options } from "../utils/typography" | ||
| import presets, { colors } from "../utils/presets" | ||
| import EnvelopeFaIcon from "react-icons/lib/fa/envelope-o" | ||
| import CancelMdIcon from "react-icons/lib/md/close" | ||
| import SendIcon from "react-icons/lib/io/paper-airplane" | ||
|
|
||
| const FeedbackComponent = styled(`section`)` | ||
| box-sizing: border-box; | ||
| position: relative; | ||
| ` | ||
|
|
||
| const FeedbackToggle = styled(`div`)` | ||
| width: 60px; | ||
| height: 60px; | ||
| bottom: 64px; | ||
| background-color: ${colors.gatsby}; | ||
| color: #fff; | ||
| border-radius: 100%; | ||
| box-shadow: 0 1px 6px rgba(0, 0, 0, 0.06), 0 2px 32px rgba(0, 0, 0, 0.16); | ||
| position: fixed; | ||
| right: 20px; | ||
| z-index: 99999; | ||
| cursor: pointer; | ||
|
|
||
| :hover { | ||
| background-color: ${colors.gatsbyDark}; | ||
| } | ||
|
|
||
| ${presets.Tablet} { | ||
| bottom: 30px; | ||
| right: 30px; | ||
| } | ||
| ` | ||
|
|
||
| const IconWrapper = styled(`div`)` | ||
| align-items: center; | ||
| display: flex; | ||
| height: 100%; | ||
| justify-content: center; | ||
| width: 100%; | ||
|
|
||
| svg { | ||
| height: auto; | ||
| } | ||
| ` | ||
|
|
||
| const EnvelopeIcon = styled(EnvelopeFaIcon)` | ||
| font-size: ${rhythm(1)}; | ||
| ` | ||
| const CancelIcon = styled(CancelMdIcon)` | ||
| font-size: ${rhythm(1.2)}; | ||
| ` | ||
|
|
||
| const StatusMessage = styled(`span`)` | ||
| position: absolute; | ||
| width: 100%; | ||
| background: ${colors.gray.dark}; | ||
| bottom: 60px; | ||
| color: #fff; | ||
| font-size: 16px; | ||
| padding: 0.4rem 0.8rem; | ||
| text-align: left; | ||
amberleyromo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| left: 0; | ||
| ` | ||
|
|
||
| const FeedbackForm = styled(`div`)` | ||
| position: fixed; | ||
amberleyromo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| right: 5%; | ||
| bottom: 134px; | ||
| width: 90%; | ||
| background-color: ${colors.gatsby}; | ||
| box-shadow: 0 0 40px 5px rgba(0, 0, 0, 0.2); | ||
| border-radius: ${presets.radiusLg}px; | ||
| font-family: ${options.systemFontFamily.join(`,`)}; | ||
|
|
||
| ${presets.Tablet} { | ||
| width: 350px; | ||
| right: 30px; | ||
| bottom: 100px; | ||
| } | ||
| ` | ||
|
|
||
| const Label = styled(`label`)` | ||
| font-family: ${options.headerFontFamily.join(`,`)}; | ||
| font-weight: 600; | ||
| height: 240px; | ||
| color: #fff; | ||
| display: flex; | ||
| justify-content: center; | ||
| align-items: center; | ||
| padding: 40px; | ||
| font-size: 22px; | ||
| float: left; | ||
| ` | ||
|
|
||
| const Form = styled(`form`)` | ||
| margin: 0; | ||
| ` | ||
|
|
||
| const Input = styled(`input`)` | ||
| float: left; | ||
| height: 60px; | ||
| width: calc(100% - 60px); | ||
| font-size: 14px; | ||
| padding: 20px; | ||
| border: none; | ||
| resize: none; | ||
| border-right: 1px solid #ddd; | ||
| border-radius: 0; | ||
| ` | ||
|
|
||
| const Send = styled(`button`)` | ||
| float: left; | ||
| width: 60px; | ||
| height: 60px; | ||
| cursor: pointer; | ||
| border: none; | ||
| background: #fff; | ||
| padding: 0; | ||
|
|
||
| svg { | ||
| width: 50%; | ||
| height: auto; | ||
| fill: ${colors.gatsby}; | ||
| } | ||
| ` | ||
|
|
||
| class Unbird extends React.Component { | ||
| state = { | ||
| visible: false, | ||
| feedbackInput: ``, | ||
| statusMessage: ``, | ||
| } | ||
|
|
||
| static defaultProps = { | ||
| feedbackPrompt: `How can we improve your experience?`, | ||
| feedbackPlaceholder: `Send feedback...`, | ||
| } | ||
|
|
||
| render() { | ||
| return ( | ||
| <FeedbackComponent> | ||
| <FeedbackToggle onClick={this.toggleFeedbackForm}> | ||
| <IconWrapper> | ||
amberleyromo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| {this.state.visible ? <CancelIcon /> : <EnvelopeIcon />} | ||
| </IconWrapper> | ||
| </FeedbackToggle> | ||
|
|
||
| {this.state.visible && ( | ||
| <FeedbackForm> | ||
| <Form autoComplete="off" onSubmit={this.submitFeedback}> | ||
| <Label htmlFor="unbird-feedback"> | ||
| {this.props.feedbackPrompt} | ||
| </Label> | ||
| {this.state.statusMessage && ( | ||
| <StatusMessage>{this.state.statusMessage}</StatusMessage> | ||
| )} | ||
| <Input | ||
| id="unbird-feedback" | ||
| type="text" | ||
| value={this.state.feedbackInput} | ||
| onChange={this.handleFeedbackInput} | ||
| placeholder={this.props.feedbackPlaceholder} | ||
amberleyromo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| required | ||
| /> | ||
| <Send> | ||
| <SendIcon /> | ||
| </Send> | ||
| </Form> | ||
| </FeedbackForm> | ||
| )} | ||
| </FeedbackComponent> | ||
| ) | ||
| } | ||
|
|
||
| toggleFeedbackForm = () => { | ||
| this.setState({ | ||
| visible: !this.state.visible, | ||
| statusMessage: ``, | ||
| feedbackInput: ``, | ||
| }) | ||
| } | ||
|
|
||
| handleFeedbackInput = e => { | ||
| this.setState({ feedbackInput: e.target.value }) | ||
| } | ||
|
|
||
| setStatusMessage = msg => { | ||
| this.setState({ statusMessage: msg }) | ||
| } | ||
|
|
||
| submitFeedback = async e => { | ||
| e.preventDefault() | ||
|
|
||
| const { dataSetId, publicKey } = this.props | ||
| const Unbird = `https://app.unbird.com/widget/entry/${dataSetId}/${publicKey}` | ||
|
|
||
| return axios | ||
| .post(Unbird, { | ||
| entry: this.state.feedbackInput, | ||
| }) | ||
| .then(_ => { | ||
| this.setStatusMessage(`Sent! Thanks :)`) | ||
| this.setState({ feedbackInput: `` }) | ||
| }) | ||
| .catch(_ => { | ||
| this.setStatusMessage(`Oops. Something went wrong...`) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| Unbird.propTypes = { | ||
| dataSetId: PropTypes.string.isRequired, | ||
| publicKey: PropTypes.string.isRequired, | ||
| feedbackPrompt: PropTypes.string, | ||
| feedbackPlaceholder: PropTypes.string, | ||
| } | ||
|
|
||
| export default Unbird | ||
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.