)
}
}
Preview.propTypes = {
- questions: PropTypes.array.isRequired
+ questions: PropTypes.array.isRequired,
+ feedback: PropTypes.array.isRequired
};
const mapStateToProps = state => ({
questions: state.questions.questions,
- questionerror: state.questions.questionerror
+ questionerror: state.questions.questionerror,
+ answererror: state.answer.answererror,
+ feedback: state.answer.answers
})
export default connect(
mapStateToProps,
- { getQuestions }
+ { getQuestions, postAnswers, getAnswers }
)(Preview)
diff --git a/src/components/Questions.js b/src/components/Questions.js
index 9e1ef70..8b515bd 100644
--- a/src/components/Questions.js
+++ b/src/components/Questions.js
@@ -33,7 +33,7 @@ class Questions extends Component {
{
label: '',
description: '',
- order: null,
+ order: undefined,
required: false,
data_type: '',
options: [],
@@ -149,7 +149,7 @@ class Questions extends Component {
// function to add a new field
createForm = () => {
return this.state.newfields.map((object, index) => (
- <>
+
+
{/* check for the published status of the form */}
{
form.published_status === 'unpublished' ?
@@ -327,6 +328,7 @@ class Questions extends Component {
>
Copy Link
+
{/* domain name of the site + pathname */}
@@ -358,7 +360,7 @@ class Questions extends Component {
(
questions && questions.length !== 0 ?
this.state.fields.map((object, index) =>
- <>
+
Updated {moment(new Date(this.state.fields[index].updated_on), "YYYYMMDD").fromNow()}
- >
+
)
: null
)
@@ -480,7 +482,6 @@ class Questions extends Component {
Questions.propTypes = {
questions: PropTypes.array.isRequired,
- form: PropTypes.object.isRequired,
userinfo: PropTypes.array.isRequired
};
diff --git a/src/components/Upload.js b/src/components/Upload.js
deleted file mode 100644
index ff5f2ee..0000000
--- a/src/components/Upload.js
+++ /dev/null
@@ -1,72 +0,0 @@
-import React, { Component } from 'react'
-import AWS from 'aws-sdk'
-require('dotenv').config();
-
-export default class Upload extends Component {
- // This component shows a demo of how the uploading feature will work with file uploads in form responses
- constructor(props) {
- super(props)
- this.state = {
- success: false,
- url: '',
- file: ''
- }
- }
-
- handleChange = (e) => {
- this.setState({
- success: false,
- url: '',
- file: e.target.files[0].name
- })
- }
-
- // the function which handles the file upload to the AWS S3 bucket
- uploadFile = (file) => {
- AWS.config.update({
- region: 'ap-south-1',
- accessKeyId: process.env.REACT_APP_AWSAccessKeyId,
- secretAccessKey: process.env.REACT_APP_AWSSecretKey,
- })
- const send_file = file
- file = file.split('.')
- const params = {
- ACL: 'public-read',
- Key: file[0],
- ContentType: 'application/octet-stream',
- Body: send_file,
- Bucket: process.env.REACT_APP_Bucket
- }
- var myBucket = new AWS.S3()
- myBucket.putObject(params)
- .on('httpUploadProgress', (evt) => {
- this.setState({
- url: `https://${process.env.REACT_APP_Bucket}.s3.amazonaws.com/${file[0]}`,
- progress: Math.round((evt.loaded / evt.total) * 100),
- })
- })
- .send((err) => {
- if (err) {
- }
- })
- }
-
-render() {
- return (
-
-
- UPLOAD A FILE
- (this.fileInput = fileInput)}
- />
-
- this.uploadFile(this.state.file)}>UPLOAD
- {this.state.url}
-
-
- );
-}
-
-}
diff --git a/src/reducers/answer.js b/src/reducers/answer.js
new file mode 100644
index 0000000..4a89390
--- /dev/null
+++ b/src/reducers/answer.js
@@ -0,0 +1,36 @@
+import {
+ GET_ANSWERS,
+ POST_ANSWERS,
+ ANSWER_ERROR
+} from '../actions/types';
+
+const initialState = {
+ answers: [],
+ postanswers: [],
+ answererror: null
+}
+
+const answerReducer = (state = initialState, action) => {
+ switch(action.type) {
+ case GET_ANSWERS:
+ return {
+ ...state,
+ answers: action.payload,
+ };
+ case POST_ANSWERS:
+ return {
+ ...state,
+ postanswers: action.payload,
+ answers: action.payload
+ };
+ case ANSWER_ERROR:
+ return {
+ ...state,
+ answererror: action.payload,
+ }
+ default:
+ return state
+ }
+}
+
+export default answerReducer
\ No newline at end of file
diff --git a/src/reducers/index.js b/src/reducers/index.js
index 444dfac..27ff51f 100644
--- a/src/reducers/index.js
+++ b/src/reducers/index.js
@@ -5,6 +5,7 @@ import userReducer from './user'
import formReducer from './form'
import questionReducer from './question'
import zulipReducer from './zulip'
+import answerReducer from './answer'
const rootReducers = combineReducers ({
login: loginReducer,
@@ -12,6 +13,7 @@ const rootReducers = combineReducers ({
user: userReducer,
form: formReducer,
questions: questionReducer,
+ answer: answerReducer,
zulip: zulipReducer
})
diff --git a/src/urls.js b/src/urls.js
index f6d14ef..d2d8abf 100644
--- a/src/urls.js
+++ b/src/urls.js
@@ -24,11 +24,7 @@ export function form(id) {
}
export function submission() {
- return `${urlBaseFrontend()}submissions`
-}
-
-export function upload() {
- return `${urlBaseFrontend()}upload`
+ return `${urlBaseFrontend()}submission`
}
// backend URLs
@@ -78,3 +74,22 @@ export function urlPatchQuestions() {
export function urlZulipStats() {
return `${urlBaseBackend()}/zulip_stat/`
}
+
+export function urlAnswers() {
+ return `${urlBaseBackend()}/answers/`
+}
+
+export function urlFormFeedback() {
+ return `${urlBaseBackend()}/feedback/`
+}
+
+export function urlSubmissions(user_name, form_id) {
+ if(user_name === undefined && form_id === undefined)
+ return `${urlBaseBackend()}/feedback/`
+ else if(user_name === undefined)
+ return `${urlBaseBackend()}/feedback/?form_id=${form_id}`
+ else if(form_id === undefined)
+ return `${urlBaseBackend()}/feedback/?user_name=${user_name}`
+ else
+ return `${urlBaseBackend()}/feedback/?user_name=${user_name}&form_id=${form_id}`
+}