From eb4da389ef0d860714061f70cea05df74a66ea59 Mon Sep 17 00:00:00 2001 From: Darius Calliet Date: Sat, 10 Jun 2017 09:40:01 -0700 Subject: [PATCH 1/5] intiial commit --- src/api/QuestionApi.js | 14 ++++++++++++++ src/routes.js | 7 ++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/api/QuestionApi.js b/src/api/QuestionApi.js index 44f6e0a..5630049 100644 --- a/src/api/QuestionApi.js +++ b/src/api/QuestionApi.js @@ -2,6 +2,20 @@ import {questionUrl, requestHeaders} from './apiBase'; class QuestionApi { + static getQuestionSchema() { + const headers = requestHeaders; + const request = new Request(questionUrl + 'schema', { + method: 'GET', + headers: headers + }); + + return fetch(request).then(response => { + return response.json(); + }).catch(error => { + throw(error); + }); + } + static getAllQuestions() { const headers = requestHeaders; const request = new Request(questionUrl, { diff --git a/src/routes.js b/src/routes.js index e3f1c3a..ef5ff67 100644 --- a/src/routes.js +++ b/src/routes.js @@ -8,8 +8,9 @@ import WelcomePage from './components/base/WelcomePage'; import EmployeeTablePage from './components/employee/EmployeeTablePage'; import IntakePage from './components/intake/IntakePage'; import IntakeTablePage from './components/intake/IntakeTablePage'; +import QuestionSetTablePage from './components/questionset/QuestionSetTablePage'; import AuthService from './utils/AuthService'; -import {dashPath, employeePath, homePath, intakePath} from './utils/pathsHelper'; +import {dashPath, employeePath, homePath, intakePath, questionPath} from './utils/pathsHelper'; const auth = new AuthService(`${process.env.REACT_APP_AUTH0CLIENTID}`, `${process.env.REACT_APP_AUTH0DOMAIN}`, 'login'); @@ -45,6 +46,10 @@ export const makeMainRoutes = () => { + + + + From 0c5fedf9097deaadfc40bf637254db497a161df7 Mon Sep 17 00:00:00 2001 From: Darius Calliet Date: Sat, 10 Jun 2017 09:49:03 -0700 Subject: [PATCH 2/5] adding in new files lol --- .../questionset/QuestionSetTable.js | 32 +++++++++ .../questionset/QuestionSetTablePage.js | 68 +++++++++++++++++++ .../questionset/QuestionSetTableRow.js | 39 +++++++++++ 3 files changed, 139 insertions(+) create mode 100644 src/components/questionset/QuestionSetTable.js create mode 100644 src/components/questionset/QuestionSetTablePage.js create mode 100644 src/components/questionset/QuestionSetTableRow.js diff --git a/src/components/questionset/QuestionSetTable.js b/src/components/questionset/QuestionSetTable.js new file mode 100644 index 0000000..fc52fe2 --- /dev/null +++ b/src/components/questionset/QuestionSetTable.js @@ -0,0 +1,32 @@ +import {Table, TableBody, TableHeader, TableHeaderColumn, TableRow} from 'material-ui/Table'; +import PropTypes from 'prop-types'; +import React from 'react'; +import QuestionSetTableRow from './QuestionSetTableRow'; + +const QuestionSetTable = (props) => { + return ( +
+ + + + Name + Owner + + + + + + {props.questionSets.map(questionSet => + + )} + +
+
+ ); +}; + +QuestionSetTable.propTypes = { + questionSet: PropTypes.array.isRequired +}; + +export default QuestionSetTable diff --git a/src/components/questionset/QuestionSetTablePage.js b/src/components/questionset/QuestionSetTablePage.js new file mode 100644 index 0000000..dc0f9e6 --- /dev/null +++ b/src/components/questionset/QuestionSetTablePage.js @@ -0,0 +1,68 @@ +import Paper from 'material-ui/Paper'; +import RaisedButton from 'material-ui/RaisedButton'; +import {Toolbar, ToolbarGroup} from 'material-ui/Toolbar'; +import PropTypes from 'prop-types'; +import React from 'react'; +import {connect} from 'react-redux'; +import {bindActionCreators} from 'redux'; +import * as actions from '../../actions/questionSetActions'; +import globalStyles from '../../styles'; +import QuestionSetTable from './QuestionSetTable'; +import {questionSetUrl} from '../../api/apiBase'; +import Snackbar from 'material-ui/Snackbar'; + + +class QuestionSetTablePage extends React.Component { + + constructor(props) { + super(props); + } + componentWillMount() { + this.props.actions.loadQuestionSets(); + } + + deleteQuestionSet = (questionSet) => { + this.props.actions.deleteQuestionSet(questionSet); + } + + render() { + const questionSets = this.props.questionSets; + return ( + + + + + + + + + + ); + } +} + +QuestionSetTablePage.propTypes = { + questionSets: PropTypes.array.isRequired +}; + +function mapStateToProps(state, ownProps) { + return { + questionSets: state.questionSets + }; +} + +function mapDispatchToProps(dispatch){ + return { + actions: bindActionCreators(actions, dispatch) + }; +} + +export default connect(mapStateToProps, mapDispatchToProps)(QuestionSetTablePage) diff --git a/src/components/questionset/QuestionSetTableRow.js b/src/components/questionset/QuestionSetTableRow.js new file mode 100644 index 0000000..17f7ed3 --- /dev/null +++ b/src/components/questionset/QuestionSetTableRow.js @@ -0,0 +1,39 @@ +import RaisedButton from 'material-ui/RaisedButton' +import {TableRow, TableRowColumn} from 'material-ui/Table' +import moment from 'moment' +import PropTypes from 'prop-types' +import React from 'react'; +import {questionSetPath} from '../../api/apiBase' + +class QuestionSetTableRow extends React.Component { + + render(){ + const questionSet = this.props.questionSet; + return ( + + questionSet.title + questionSet.organization.name || 'Cemartian' + + this.props.deleteQuestionSet(questionSet)} + /> + + + + + + ); + } +} + +QuestionSetTableRow.propTypes = { + questionSet: PropTypes.object.isRequired +}; + +export default QuestionSetTableRow; From 0a441b960f9fe5f5b9344210b85dd10d0d349c21 Mon Sep 17 00:00:00 2001 From: Darius Calliet Date: Sun, 11 Jun 2017 16:30:00 -0700 Subject: [PATCH 3/5] starting on tying this into redux --- src/reducers/index.js | 6 +++++- src/reducers/initialState.js | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/reducers/index.js b/src/reducers/index.js index 17c1abc..5742a12 100755 --- a/src/reducers/index.js +++ b/src/reducers/index.js @@ -6,6 +6,8 @@ import messages from './messageReducer'; import notifications from './notificationReducer'; import organizations, {organizationReducer as organization} from './organizationReducer'; import {questionSetSchemaReducer as questionSetFormSchema} from './questionSetReducer'; +import {questionSetReducer as questionSet} from './questionSetReducer'; +import {questionReducer as question} from './questionReducer'; import tasks from './taskReducer'; import users, {userReducer as user} from './userReducer'; @@ -24,7 +26,9 @@ const rootReducer = combineReducers({ tasks, users, user, - questionSetFormSchema + questionSetFormSchema, + questionSet, + question }); export default rootReducer; diff --git a/src/reducers/initialState.js b/src/reducers/initialState.js index 49810e0..ac6cd00 100755 --- a/src/reducers/initialState.js +++ b/src/reducers/initialState.js @@ -19,5 +19,8 @@ export default { properties: [] }, form: [] }, + questions: [], + question: {}, + questionSets: [], session: !!localStorage.jwt }; From 8a5e8383a1831191f52e24d2664a9bf1ef48fc9e Mon Sep 17 00:00:00 2001 From: James Marlowe Date: Sun, 11 Jun 2017 21:30:46 -0500 Subject: [PATCH 4/5] fixing mismatches --- src/actions/actionTypes.js | 8 ++++---- src/api/QuestionSetApi.js | 2 +- src/components/App.js | 3 ++- src/components/questionset/QuestionSetTable.js | 2 +- .../questionset/QuestionSetTablePage.js | 15 ++------------- src/components/questionset/QuestionSetTableRow.js | 5 ++--- src/data.js | 3 ++- src/reducers/index.js | 8 ++++---- src/reducers/initialState.js | 1 - src/routes.js | 6 +++--- src/utils/pathsHelper.js | 1 + 11 files changed, 22 insertions(+), 32 deletions(-) diff --git a/src/actions/actionTypes.js b/src/actions/actionTypes.js index cbbeae2..91d36ca 100755 --- a/src/actions/actionTypes.js +++ b/src/actions/actionTypes.js @@ -64,11 +64,11 @@ export const CREATE_QUESTION_SUCCESS = 'CREATE_QUESTION_SUCCESS'; export const DELETE_QUESTION_SUCCESS = 'DELETE_QUESTION_SUCCESS'; // questionsets -export const LOAD_QUESTIONSETS_SUCCESS = 'LOAD_QUESTIONS_SUCCESS'; +export const LOAD_QUESTIONSETS_SUCCESS = 'LOAD_QUESTIONSETS_SUCCESS'; export const LOAD_QUESTIONSET_SCHEMA_SUCCESS = 'LOAD_QUESTIONSET_SCHEMA_SUCCESS'; -export const UPDATE_QUESTIONSET_SUCCESS = 'UPDATE_QUESTION_SUCCESS'; -export const CREATE_QUESTIONSET_SUCCESS = 'CREATE_QUESTION_SUCCESS'; -export const DELETE_QUESTIONSET_SUCCESS = 'DELETE_QUESTION_SUCCESS'; +export const UPDATE_QUESTIONSET_SUCCESS = 'UPDATE_QUESTIONSET_SUCCESS'; +export const CREATE_QUESTIONSET_SUCCESS = 'CREATE_QUESTIONSET_SUCCESS'; +export const DELETE_QUESTIONSET_SUCCESS = 'DELETE_QUESTIONSET_SUCCESS'; // tasks export const LOAD_TASKS_SUCCESS = 'LOAD_TASKS_SUCCESS'; diff --git a/src/api/QuestionSetApi.js b/src/api/QuestionSetApi.js index a820ce9..4241612 100644 --- a/src/api/QuestionSetApi.js +++ b/src/api/QuestionSetApi.js @@ -18,7 +18,7 @@ class QuestionSetApi { static getAllQuestionSets() { const headers = requestHeaders; - const request = new Request(questionSetUrl, { + const request = new Request(questionSetUrl + '?populate=true', { method: 'GET', headers: headers }); diff --git a/src/components/App.js b/src/components/App.js index f86d259..5a112b2 100644 --- a/src/components/App.js +++ b/src/components/App.js @@ -1,6 +1,6 @@ import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider'; import withWidth, {LARGE, SMALL} from 'material-ui/utils/withWidth'; -import React, {PropTypes} from 'react'; +import React from 'react'; import Data from '../data'; import ThemeDefault from '../theme-default'; import Header from './base/Header'; @@ -10,6 +10,7 @@ import {bindActionCreators} from 'redux'; import * as userActions from '../actions/userActions'; import * as employeeActions from '../actions/employeeActions'; import * as organizationActions from '../actions/organizationActions'; +import PropTypes from 'prop-types' class App extends React.Component { diff --git a/src/components/questionset/QuestionSetTable.js b/src/components/questionset/QuestionSetTable.js index fc52fe2..3d92933 100644 --- a/src/components/questionset/QuestionSetTable.js +++ b/src/components/questionset/QuestionSetTable.js @@ -26,7 +26,7 @@ const QuestionSetTable = (props) => { }; QuestionSetTable.propTypes = { - questionSet: PropTypes.array.isRequired + questionSets: PropTypes.array.isRequired }; export default QuestionSetTable diff --git a/src/components/questionset/QuestionSetTablePage.js b/src/components/questionset/QuestionSetTablePage.js index dc0f9e6..92547ae 100644 --- a/src/components/questionset/QuestionSetTablePage.js +++ b/src/components/questionset/QuestionSetTablePage.js @@ -8,22 +8,16 @@ import {bindActionCreators} from 'redux'; import * as actions from '../../actions/questionSetActions'; import globalStyles from '../../styles'; import QuestionSetTable from './QuestionSetTable'; -import {questionSetUrl} from '../../api/apiBase'; -import Snackbar from 'material-ui/Snackbar'; class QuestionSetTablePage extends React.Component { - - constructor(props) { - super(props); - } componentWillMount() { this.props.actions.loadQuestionSets(); } deleteQuestionSet = (questionSet) => { this.props.actions.deleteQuestionSet(questionSet); - } + }; render() { const questionSets = this.props.questionSets; @@ -37,13 +31,8 @@ class QuestionSetTablePage extends React.Component { href="/questionsets/new" /> - - + ); } diff --git a/src/components/questionset/QuestionSetTableRow.js b/src/components/questionset/QuestionSetTableRow.js index 17f7ed3..fde9b46 100644 --- a/src/components/questionset/QuestionSetTableRow.js +++ b/src/components/questionset/QuestionSetTableRow.js @@ -1,6 +1,5 @@ import RaisedButton from 'material-ui/RaisedButton' import {TableRow, TableRowColumn} from 'material-ui/Table' -import moment from 'moment' import PropTypes from 'prop-types' import React from 'react'; import {questionSetPath} from '../../api/apiBase' @@ -11,8 +10,8 @@ class QuestionSetTableRow extends React.Component { const questionSet = this.props.questionSet; return ( - questionSet.title - questionSet.organization.name || 'Cemartian' + {questionSet.title} + {(questionSet.organization&&questionSet.organization.name) || 'Cemartian'} , link: '/home'}, {text: 'Referrals', icon: , link: '/referrals'}, - {text: 'Intakes', icon: , link: '/intakes'} + {text: 'Intakes', icon: , link: '/intakes'}, + {text: 'Question Sets', icon: , link: '/questionsets/'} ], adminmenus: [ {text: 'Permissions', icon: , link: '/dash'}, diff --git a/src/reducers/index.js b/src/reducers/index.js index 5742a12..6ebb03f 100755 --- a/src/reducers/index.js +++ b/src/reducers/index.js @@ -6,8 +6,8 @@ import messages from './messageReducer'; import notifications from './notificationReducer'; import organizations, {organizationReducer as organization} from './organizationReducer'; import {questionSetSchemaReducer as questionSetFormSchema} from './questionSetReducer'; -import {questionSetReducer as questionSet} from './questionSetReducer'; -import {questionReducer as question} from './questionReducer'; +import questionSets from './questionSetReducer'; +import questions from './questionReducer'; import tasks from './taskReducer'; import users, {userReducer as user} from './userReducer'; @@ -27,8 +27,8 @@ const rootReducer = combineReducers({ users, user, questionSetFormSchema, - questionSet, - question + questionSets, + questions }); export default rootReducer; diff --git a/src/reducers/initialState.js b/src/reducers/initialState.js index ac6cd00..c960054 100755 --- a/src/reducers/initialState.js +++ b/src/reducers/initialState.js @@ -20,7 +20,6 @@ export default { }, form: [] }, questions: [], - question: {}, questionSets: [], session: !!localStorage.jwt }; diff --git a/src/routes.js b/src/routes.js index ef5ff67..df8eeb1 100644 --- a/src/routes.js +++ b/src/routes.js @@ -10,7 +10,7 @@ import IntakePage from './components/intake/IntakePage'; import IntakeTablePage from './components/intake/IntakeTablePage'; import QuestionSetTablePage from './components/questionset/QuestionSetTablePage'; import AuthService from './utils/AuthService'; -import {dashPath, employeePath, homePath, intakePath, questionPath} from './utils/pathsHelper'; +import {dashPath, employeePath, homePath, intakePath, questionSetPath} from './utils/pathsHelper'; const auth = new AuthService(`${process.env.REACT_APP_AUTH0CLIENTID}`, `${process.env.REACT_APP_AUTH0DOMAIN}`, 'login'); @@ -46,9 +46,9 @@ export const makeMainRoutes = () => { - + - + diff --git a/src/utils/pathsHelper.js b/src/utils/pathsHelper.js index 2033dc0..d8d7986 100644 --- a/src/utils/pathsHelper.js +++ b/src/utils/pathsHelper.js @@ -10,4 +10,5 @@ export const notificationPath = '/notifications/'; export const organizationPath = '/organizations/'; export const organizationrolePath = '/organizationroles/'; export const questionPath = '/questions/'; +export const questionSetPath = '/questionsets/'; export const taskPath = '/tasks/'; From e06bbf085928b2e5ce1275af939ab7079f00dd47 Mon Sep 17 00:00:00 2001 From: Darius Calliet Date: Mon, 12 Jun 2017 20:32:52 -0700 Subject: [PATCH 5/5] list question sets done, begin edit question set --- src/actions/questionSetActions.js | 4 +- src/api/QuestionSetApi.js | 16 ++++- .../questionset/QuestionSetQuestionsPage.js | 65 +++++++++++++++++++ .../questionset/QuestionSetTableRow.js | 8 +++ src/routes.js | 2 + 5 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 src/components/questionset/QuestionSetQuestionsPage.js diff --git a/src/actions/questionSetActions.js b/src/actions/questionSetActions.js index bd704f5..16cdf02 100644 --- a/src/actions/questionSetActions.js +++ b/src/actions/questionSetActions.js @@ -21,10 +21,10 @@ export function loadQuestionSetSchemaSuccess(questionSetFormSchema) { return {type: types.LOAD_QUESTIONSET_SCHEMA_SUCCESS, questionSetFormSchema}; } -export function loadQuestionSetSchema() { +export function loadQuestionSetSchema(questionSetId) { // make async call to api, handle promise, dispatch action when promise is resolved return function (dispatch) { - return questionSetApi.getQuestionSetSchema().then(questionSetFormSchema => { + return questionSetApi.getQuestionSetSchema(questionSetId).then(questionSetFormSchema => { dispatch(loadQuestionSetSchemaSuccess(questionSetFormSchema)); }).catch(error => { throw(error); diff --git a/src/api/QuestionSetApi.js b/src/api/QuestionSetApi.js index 4241612..b7266ed 100644 --- a/src/api/QuestionSetApi.js +++ b/src/api/QuestionSetApi.js @@ -2,9 +2,9 @@ import {questionSetUrl, requestHeaders} from './apiBase'; class QuestionSetApi { - static getQuestionSetSchema() { + static getQuestionSetSchema(questionSetId) { const headers = requestHeaders; - const request = new Request(questionSetUrl + 'schemaform?id=1', { + const request = new Request(questionSetUrl + 'schemaform?id=' + `${questionSetId}`, { method: 'GET', headers: headers }); @@ -73,6 +73,18 @@ class QuestionSetApi { return error; }); } + + static getQuestionSetQuestions(questionSet) { + return + } + + static addQuestionSetQuestion(questionSet, question) { + return + } + + static deleteQuestionSetQuestion(questionSet, question) { + return + } } export default QuestionSetApi; diff --git a/src/components/questionset/QuestionSetQuestionsPage.js b/src/components/questionset/QuestionSetQuestionsPage.js new file mode 100644 index 0000000..6c5abac --- /dev/null +++ b/src/components/questionset/QuestionSetQuestionsPage.js @@ -0,0 +1,65 @@ +import Paper from 'material-ui/Paper'; +import PropTypes from 'prop-types'; +import React from 'react'; +import {connect} from 'react-redux'; +import {withRouter} from 'react-router'; +import {bindActionCreators} from 'redux'; +import * as actions from '../../actions/questionSetActions'; +import globalStyles from '../../styles'; + +class QuestionSetQuestionsPage extends React.Component { + state = { + saved: true, + questionSetId: this.props.params.id + } + + componentWillMount() { + if (this.state.questionSetId) { + this.props.actions.loadQuestionSetSchema(this.state.questionSetId); + } + } + + saveQuestionSet = (questionSet) => { + this.setState({saved: true}); + if (questionSet.id) { + return this.props.actions.updateQuestionSet(questionSet).then(this.props.actions.loadQuestionSetSchema(questionSet.id)); + } else { + return this.props.actions.createQuestionSet(questionSet).then(this.props.actions.loadQuestionSetSchema(questionSet.id)); + } + } + + updateSaveQuestionSet = (saved) => { + this.setState({ + saved: saved + }); + }; + + render() { + let { questionSetFormSchema } = this.props; + console.log(questionSetFormSchema) + return ( + + + + ) + } + +} + +QuestionSetQuestionsPage.propTypes = { + questionSetFormSchema: PropTypes.object.isRequired +} + +function mapStateToProps(state, ownProps) { + return { + questionSetFormSchema: state.questionSetFormSchema + } +} + +function mapDispatchToProps(dispatch) { + return { + actions: bindActionCreators(actions, dispatch) + }; +} + +export default withRouter(connect(mapStateToProps, mapDispatchToProps)(QuestionSetQuestionsPage)); diff --git a/src/components/questionset/QuestionSetTableRow.js b/src/components/questionset/QuestionSetTableRow.js index fde9b46..8f8b930 100644 --- a/src/components/questionset/QuestionSetTableRow.js +++ b/src/components/questionset/QuestionSetTableRow.js @@ -8,6 +8,8 @@ class QuestionSetTableRow extends React.Component { render(){ const questionSet = this.props.questionSet; + const isNotSetOwner = (questionSet.organization === null); + return ( {questionSet.title} @@ -16,6 +18,9 @@ class QuestionSetTableRow extends React.Component { this.props.deleteQuestionSet(questionSet)} /> @@ -23,6 +28,9 @@ class QuestionSetTableRow extends React.Component { diff --git a/src/routes.js b/src/routes.js index df8eeb1..92cea9d 100644 --- a/src/routes.js +++ b/src/routes.js @@ -9,6 +9,7 @@ import EmployeeTablePage from './components/employee/EmployeeTablePage'; import IntakePage from './components/intake/IntakePage'; import IntakeTablePage from './components/intake/IntakeTablePage'; import QuestionSetTablePage from './components/questionset/QuestionSetTablePage'; +import QuestionSetQuestionsPage from './components/questionset/QuestionSetQuestionsPage'; import AuthService from './utils/AuthService'; import {dashPath, employeePath, homePath, intakePath, questionSetPath} from './utils/pathsHelper'; @@ -48,6 +49,7 @@ export const makeMainRoutes = () => { +