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 May 15, 2021
1 parent 577e671 commit ac5f7cb
Show file tree
Hide file tree
Showing 9 changed files with 971 additions and 866 deletions.
82 changes: 38 additions & 44 deletions src/Routes.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,41 @@
import React, { Component } from 'react';
import { Route, Switch, Redirect } 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';
import Submission from './components/Submission';
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';
import React, { Component } from 'react'
import { Route, Switch, Redirect } from 'react-router-dom'
import Login from './components/Login'
import Register from './components/Register'
import Dashboard from './components/Dashboard'
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,
submission,
urlBaseFrontend
} from './urls'
import {PrivateRoute} from './PrivateRoute'
import { AuthRoute } from './AuthRoute'

export default class Routes extends Component {
render() {
return (
<>
<Switch>
<PrivateRoute exact path={dashboard()} component={Dashboard} />
<PrivateRoute exact path={forms()} component={Forms} />
<PrivateRoute exact path={submission()} component={Submission} />
<PrivateRoute
exact
path={`${urlBaseFrontend()}form/:id`}
component={Questions}
/>
<AuthRoute path={login()} component={Login} />
<AuthRoute path={register()} component={Register} />
<AuthRoute path={activate()} component={Activate} />
<Route path={upload()} component={Upload} />
<AuthRoute component={ErrorPage} />
</Switch>
</>
);
}
render() {
return (
<>
<Switch>
<PrivateRoute exact path={dashboard()} component={Dashboard} />
<PrivateRoute exact path={forms()} component={Forms} />
<PrivateRoute exact path={submission()} component={Submission} />
<PrivateRoute
exact
path={`${urlBaseFrontend()}form/:id`}
component={Questions}
/>
<AuthRoute path={login()} component={Login} />
<AuthRoute path={register()} component={Register} />
<AuthRoute component={ErrorPage} />
</Switch>
</>
)
}
}
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 @@ -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

0 comments on commit ac5f7cb

Please sign in to comment.