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/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/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/api/QuestionSetApi.js b/src/api/QuestionSetApi.js index a820ce9..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 }); @@ -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 }); @@ -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/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/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/QuestionSetTable.js b/src/components/questionset/QuestionSetTable.js new file mode 100644 index 0000000..3d92933 --- /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 = { + questionSets: 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..92547ae --- /dev/null +++ b/src/components/questionset/QuestionSetTablePage.js @@ -0,0 +1,57 @@ +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'; + + +class QuestionSetTablePage extends React.Component { + 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..8f8b930 --- /dev/null +++ b/src/components/questionset/QuestionSetTableRow.js @@ -0,0 +1,46 @@ +import RaisedButton from 'material-ui/RaisedButton' +import {TableRow, TableRowColumn} from 'material-ui/Table' +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; + const isNotSetOwner = (questionSet.organization === null); + + return ( + + {questionSet.title} + {(questionSet.organization&&questionSet.organization.name) || 'Cemartian'} + + this.props.deleteQuestionSet(questionSet)} + /> + + + + + + ); + } +} + +QuestionSetTableRow.propTypes = { + questionSet: PropTypes.object.isRequired +}; + +export default QuestionSetTableRow; diff --git a/src/data.js b/src/data.js index 3ee158d..2caa9a0 100644 --- a/src/data.js +++ b/src/data.js @@ -10,7 +10,8 @@ const data = { menus: [ {text: 'Welcome', icon: , 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 17c1abc..6ebb03f 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 questionSets from './questionSetReducer'; +import questions 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, + questionSets, + questions }); export default rootReducer; diff --git a/src/reducers/initialState.js b/src/reducers/initialState.js index 49810e0..c960054 100755 --- a/src/reducers/initialState.js +++ b/src/reducers/initialState.js @@ -19,5 +19,7 @@ export default { properties: [] }, form: [] }, + questions: [], + questionSets: [], session: !!localStorage.jwt }; diff --git a/src/routes.js b/src/routes.js index e3f1c3a..92cea9d 100644 --- a/src/routes.js +++ b/src/routes.js @@ -8,8 +8,10 @@ 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 QuestionSetQuestionsPage from './components/questionset/QuestionSetQuestionsPage'; import AuthService from './utils/AuthService'; -import {dashPath, employeePath, homePath, intakePath} 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'); @@ -45,6 +47,11 @@ 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/';