Skip to content

Commit

Permalink
Add feature to fill, edit and view forms
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaishpra committed Mar 1, 2021
1 parent 8e97e0f commit aacc1cb
Show file tree
Hide file tree
Showing 9 changed files with 340 additions and 138 deletions.
4 changes: 1 addition & 3 deletions src/Routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import Forms from './components/Forms'
import ErrorPage from './components/ErrorPage'
import Submission from './components/Submission'
import Questions from './components/Questions'
import { login, register, dashboard, forms, upload, submission, urlBaseFrontend } from './urls'
import Upload from './components/Upload'
import { login, register, dashboard, forms, submission, urlBaseFrontend } from './urls'
import {PrivateRoute} from './PrivateRoute'
import { AuthRoute } from './AuthRoute'

Expand All @@ -23,7 +22,6 @@ export default class Routes extends Component {
<PrivateRoute exact path={`${urlBaseFrontend()}form/:id`} component={Questions} />
<AuthRoute path={login()} component={Login} />
<AuthRoute path={register()} component={Register} />
<Route path={upload()} component={Upload} />
<AuthRoute component={ErrorPage} />
</Switch>
</>
Expand Down
53 changes: 53 additions & 0 deletions src/actions/answer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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
})
}
}
3 changes: 3 additions & 0 deletions src/actions/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,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

0 comments on commit aacc1cb

Please sign in to comment.