Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add feature to fill, edit and view form responses for users #103

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15,572 changes: 1,745 additions & 13,827 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"aws-sdk": "^2.734.0",
"axios": "^0.21.1",
"dotenv": "^8.2.0",
"eslint": "^7.26.0",
"format": "^0.2.2",
"moment": "^2.27.0",
"prop-types": "^15.7.2",
"react": "^16.13.1",
Expand Down Expand Up @@ -52,11 +54,12 @@
"extends": "react-app"
},
"devDependencies": {
"babel-eslint": "^10.1.0",
"eslint-config-prettier": "^8.0.0",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-react": "^7.22.0",
"eslint-plugin-react-hooks": "^1.7.0",
"prettier": "^2.2.1",
"miragejs": "^0.1.41"
"miragejs": "^0.1.41",
"prettier": "^2.2.1"
}
}
8 changes: 1 addition & 7 deletions src/Routes.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React, { Component } from 'react';
import { Route, Switch } from 'react-router-dom';
import { Switch } from 'react-router-dom';
import Login from './components/Login';
import Register from './components/Register';
import Activate from './components/Activate';
import Dashboard from './components/Dashboard';
import Forms from './components/Forms';
import ErrorPage from './components/ErrorPage';
Expand All @@ -11,14 +10,11 @@ import Questions from './components/Questions';
import {
login,
register,
activate,
dashboard,
forms,
upload,
submission,
urlBaseFrontend,
} from './urls';
import Upload from './components/Upload';
import { PrivateRoute } from './PrivateRoute';
import { AuthRoute } from './AuthRoute';

Expand All @@ -37,8 +33,6 @@ export default class Routes extends Component {
/>
<AuthRoute path={login()} component={Login} />
<AuthRoute path={register()} component={Register} />
<AuthRoute path={activate()} component={Activate} />
<Route path={upload()} component={Upload} />
<AuthRoute component={ErrorPage} />
</Switch>
</>
Expand Down
44 changes: 44 additions & 0 deletions src/actions/answer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import axios from 'axios';
import { urlFormFeedback, urlSubmissions } from '../urls';
import { GET_ANSWERS, POST_ANSWERS, ANSWER_ERROR } from './types';

export const getAnswers = (form_id) => async (dispatch) => {
try {
const config = {
headers: {
Authorization: `Bearer ${localStorage.token}`,
},
};
const res = await axios.get(urlSubmissions(undefined, form_id), config);
dispatch({
type: GET_ANSWERS,
payload: res.data,
});
} catch (err) {
dispatch({
type: ANSWER_ERROR,
payload: err.response.data,
});
}
};

export const postAnswers = (data, callback) => async (dispatch) => {
try {
const config = {
headers: {
Authorization: `Bearer ${localStorage.token}`,
},
};
const res = await axios.post(urlFormFeedback(), data, config);
dispatch({
type: POST_ANSWERS,
payload: res.data,
});
callback();
} catch (err) {
dispatch({
type: ANSWER_ERROR,
payload: err.response.data,
});
}
};
47 changes: 23 additions & 24 deletions src/actions/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,30 +167,29 @@ export const patchPublishedForm = (id, data, callback) => async (dispatch) => {
}
};

export const patchUnpublishedForm = (id, data, callback) => async (
dispatch
) => {
try {
const config = {
headers: {
'content-type': 'application/json',
Authorization: `Bearer ${localStorage.token}`,
},
};
const res = await axios.patch(urlFormId(id), data, config);
dispatch({
type: UPDATE_UNPUBLISHED_FORM,
payload: res.data,
});
callback();
} catch (err) {
dispatch({
type: FORM_ERRORS,
payload: err.response.data,
});
callback();
}
};
export const patchUnpublishedForm =
(id, data, callback) => async (dispatch) => {
try {
const config = {
headers: {
'content-type': 'application/json',
Authorization: `Bearer ${localStorage.token}`,
},
};
const res = await axios.patch(urlFormId(id), data, config);
dispatch({
type: UPDATE_UNPUBLISHED_FORM,
payload: res.data,
});
callback();
} catch (err) {
dispatch({
type: FORM_ERRORS,
payload: err.response.data,
});
callback();
}
};

export const deletePublishedForm = (id, callback) => async (dispatch) => {
try {
Expand Down
3 changes: 3 additions & 0 deletions src/actions/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ export const QUESTION_ERROR = 'QUESTION_ERROR';
export const GET_ZULIP_STAT = 'GET_ZULIP_STAT';
export const UPDATE_ZULIP_STAT = 'UPDATE_ZULIP_STAT';
export const ZULIP_STAT_ERROR = 'ZULIP_STAT_ERROR';
export const GET_ANSWERS = 'GET_ANSWERS';
export const POST_ANSWERS = 'POST_ANSWERS';
export const ANSWER_ERROR = 'ANSWER_ERROR';
Loading