-
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.
ngrox setup, survey recipents update
- Loading branch information
Showing
28 changed files
with
1,280 additions
and
13 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
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,17 @@ | ||
import React from "react"; | ||
import { Link } from "react-router-dom"; | ||
|
||
const Dashboard = () => { | ||
return ( | ||
<div> | ||
Dashboard | ||
<div className="fixed-action-btn"> | ||
<Link className="btn-floating btn-large red" to="/surveys/new"> | ||
<i className="material-icons">add</i> | ||
</Link> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Dashboard; |
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,13 @@ | ||
//contains logic to render a single text and label | ||
|
||
import React from "react"; | ||
|
||
export default ({ input, label, meta: { touched, error } }) => { | ||
return ( | ||
<div style={{ marginBottom: "10px" }}> | ||
<label>{label}</label> | ||
<input {...input} /> | ||
<div className="red-text"> {touched && error} </div> | ||
</div> | ||
); | ||
}; |
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,62 @@ | ||
import _ from "lodash"; | ||
import React, { Component } from "react"; | ||
import { reduxForm, Field } from "redux-form"; | ||
import { Link } from "react-router-dom"; | ||
|
||
import SurveyField from "./SurveyField"; | ||
import formFields from "./formFields"; | ||
import { deepFreeze } from "../../helpers/Array"; | ||
|
||
import validateEmails from "../../utils/validateEmails"; | ||
|
||
const FIELDS = deepFreeze(formFields); | ||
|
||
class SurveyForm extends Component { | ||
renderFields() { | ||
return FIELDS.map(({ label, name }) => ( | ||
<Field | ||
component={SurveyField} | ||
type="text" | ||
name={name} | ||
label={label} | ||
key={name} | ||
/> | ||
)); | ||
} | ||
|
||
render() { | ||
return ( | ||
<form | ||
onSubmit={this.props.handleSubmit(() => this.props.onSurveySubmit())} | ||
> | ||
{this.renderFields()} | ||
<Link to="/surveys" className="red btn-flat white-text"> | ||
Cancel | ||
</Link> | ||
<button type="submit" className="teal btn-flat right white-text"> | ||
Next | ||
<i className="material-icons right">done</i> | ||
</button> | ||
</form> | ||
); | ||
} | ||
} | ||
|
||
const validate = fields => values => { | ||
let errors = {}; | ||
errors.recipents = values.recipents && validateEmails(values.recipents); | ||
|
||
_.each(fields, ({ name }) => { | ||
if (!values[name]) { | ||
errors[name] = `You must provide a ${name}`; | ||
} | ||
}); | ||
|
||
return errors; | ||
}; | ||
|
||
export default reduxForm({ | ||
validate: validate(FIELDS), | ||
form: "surveyForm", | ||
destroyOnUnmount: false | ||
})(SurveyForm); |
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,33 @@ | ||
// Survey new has the responsibility to show survey form and survey review | ||
import React, { Component } from "react"; | ||
import { reduxForm } from "redux-form"; | ||
import SurveyForm from "./SurveyForm"; | ||
import SurveyReview from "./SurveyReview"; | ||
|
||
class SurveyNew extends Component { | ||
state = { | ||
reviewPage: false | ||
}; | ||
|
||
renderContent() { | ||
const { reviewPage } = this.state; | ||
if (reviewPage) { | ||
return ( | ||
<SurveyReview | ||
onBackReview={() => this.setState({ reviewPage: !reviewPage })} | ||
/> | ||
); | ||
} | ||
return ( | ||
<SurveyForm | ||
onSurveySubmit={() => this.setState({ reviewPage: !reviewPage })} | ||
/> | ||
); | ||
} | ||
|
||
render() { | ||
return <div>{this.renderContent()}</div>; | ||
} | ||
} | ||
|
||
export default reduxForm({ form: "surveyForm" })(SurveyNew); |
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,58 @@ | ||
import React, { Component } from "react"; | ||
import { withRouter } from "react-router-dom"; | ||
import { connect } from "react-redux"; | ||
import { sendSurvey } from "../../actions"; | ||
|
||
import formFields from "./formFields"; | ||
import { deepFreeze } from "../../helpers/Array"; | ||
|
||
class SurveyReview extends Component { | ||
renderContent() { | ||
const FIELDS = deepFreeze(formFields); | ||
return FIELDS.map(({ label, name }) => { | ||
return ( | ||
<div key={name}> | ||
<label>{label}</label> | ||
<div>{this.props.form[name]}</div> | ||
</div> | ||
); | ||
}); | ||
} | ||
|
||
render() { | ||
return ( | ||
<div> | ||
<h4>Please confirm your entries</h4> | ||
<div>{this.renderContent()}</div> | ||
<button | ||
className="yellow white-text darken-3 btn-flat" | ||
onClick={() => this.props.onBackReview()} | ||
> | ||
Back | ||
</button> | ||
<button | ||
className="right green btn-flat white-text" | ||
onClick={() => | ||
this.props.sendSurvey(this.props.form, this.props.history) | ||
} | ||
> | ||
Send Survey | ||
<i className="material-icons right">email</i> | ||
</button> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
const mapStateToProps = ({ form }) => { | ||
return { form: form.surveyForm.values }; | ||
}; | ||
|
||
const mapDispatchToProps = action => { | ||
return { action }; | ||
}; | ||
|
||
export default connect( | ||
mapStateToProps, | ||
{ sendSurvey } | ||
)(withRouter(SurveyReview)); |
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,6 @@ | ||
export default [ | ||
{ label: "Survey Title", name: "title" }, | ||
{ label: "Survey Subject", name: "subject" }, | ||
{ label: "Email Body", name: "body" }, | ||
{ label: "Recipients List", name: "recipents" } | ||
]; |
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,3 @@ | ||
export const freeze = x => Object.freeze(x); | ||
export const mapper = x => y => x.map(y); | ||
export const deepFreeze = array => mapper(array)(freeze); |
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 |
---|---|---|
@@ -1,6 +1,9 @@ | ||
import { combineReducers } from "redux"; | ||
import { reducer as formReducer } from "redux-form"; | ||
|
||
import authReducer from "./authReducer"; | ||
|
||
export default combineReducers({ | ||
auth: authReducer | ||
auth: authReducer, | ||
form: formReducer | ||
}); |
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,9 @@ | ||
export default emails => { | ||
const re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; | ||
const inValidEmails = emails | ||
.split(",") | ||
.map(email => email.trim()) | ||
.filter(email => (email ? !re.test(email) : false)); | ||
if (inValidEmails.length) return `These emails are invalid ${inValidEmails}`; | ||
return null; | ||
}; |
Oops, something went wrong.