forked from StateVoicesNational/Spoke
-
Notifications
You must be signed in to change notification settings - Fork 0
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 #14 from MoveOnOrg/dynamicreplies
Add dynamic replies feature
- Loading branch information
Showing
12 changed files
with
375 additions
and
4 deletions.
There are no files selected for viewing
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
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,22 @@ | ||
import PropTypes from "prop-types"; | ||
import React from "react"; | ||
import DisplayLink from "./DisplayLink"; | ||
|
||
const OrganizationReassignLink = ({ joinToken, campaignId }) => { | ||
let baseUrl = "http://base"; | ||
if (typeof window !== "undefined") { | ||
baseUrl = window.location.origin; | ||
} | ||
|
||
const replyUrl = `${baseUrl}/${joinToken}/replies/${campaignId}`; | ||
const textContent = `Send your texting volunteers this link! Once they sign up, they\'ll be automatically assigned replies for this campaign.`; | ||
|
||
return <DisplayLink url={replyUrl} textContent={textContent} />; | ||
}; | ||
|
||
OrganizationReassignLink.propTypes = { | ||
joinToken: PropTypes.string, | ||
campaignId: PropTypes.string | ||
}; | ||
|
||
export default OrganizationReassignLink; |
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,88 @@ | ||
import PropTypes from "prop-types"; | ||
import React from "react"; | ||
import loadData from "./hoc/load-data"; | ||
import gql from "graphql-tag"; | ||
import { withRouter } from "react-router"; | ||
import { StyleSheet, css } from "aphrodite"; | ||
import theme from "../styles/theme"; | ||
|
||
const styles = StyleSheet.create({ | ||
greenBox: { | ||
...theme.layouts.greenBox | ||
} | ||
}); | ||
|
||
class AssignReplies extends React.Component { | ||
state = { | ||
errors: null | ||
}; | ||
|
||
async componentWillMount() { | ||
console.log("Props",this.props); | ||
try { | ||
|
||
const organizationId = (await this.props.mutations.dynamicReassign( | ||
this.props.params.joinToken, | ||
this.props.params.campaignId | ||
)).data.dynamicReassign; | ||
console.log("ID:", organizationId); | ||
|
||
this.props.router.push(`/app/${organizationId}`); | ||
} catch (err) { | ||
console.log("error assigning replies", err); | ||
const texterMessage = (err && | ||
err.message && | ||
err.message.match(/(Sorry,.+)$/)) || [ | ||
0, | ||
"Something went wrong trying to assign replies. Please contact your administrator." | ||
]; | ||
this.setState({ | ||
errors: texterMessage[1] | ||
}); | ||
} | ||
} | ||
renderErrors() { | ||
if (this.state.errors) { | ||
return <div className={css(styles.greenBox)}>{this.state.errors}</div>; | ||
} | ||
return <div />; | ||
} | ||
|
||
render() { | ||
return <div>{this.renderErrors()}</div>; | ||
} | ||
} | ||
|
||
AssignReplies.propTypes = { | ||
mutations: PropTypes.object, | ||
router: PropTypes.object, | ||
params: PropTypes.object, | ||
campaign: PropTypes.object | ||
}; | ||
|
||
export const dynamicReassignMutation = gql` | ||
mutation dynamicReassign( | ||
$joinToken: String! | ||
$campaignId: String! | ||
) { | ||
dynamicReassign( | ||
joinToken: $joinToken | ||
campaignId: $campaignId | ||
) | ||
} | ||
`; | ||
|
||
const mutations = { | ||
dynamicReassign: ownProps => ( | ||
joinToken, | ||
campaignId | ||
) => ({ | ||
mutation: dynamicReassignMutation, | ||
variables: { | ||
joinToken, | ||
campaignId | ||
} | ||
}) | ||
}; | ||
|
||
export default loadData({ mutations })(withRouter(AssignReplies)); |
Oops, something went wrong.