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

Add feature for viewing submissions and searching by name and form name #54

Closed
wants to merge 3 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
8 changes: 5 additions & 3 deletions src/Routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import Register from './components/Register'
import Dashboard from './components/Dashboard'
import Forms from './components/Forms'
import Submission from './components/Submission'
import SubmissionProfile from './components/SubmissionProfile'
import Questions from './components/Questions'
import { login, register, dashboard, forms, upload, submission, urlBaseFrontend } from './urls'
import Upload from './components/Upload'
import Preview from './components/Preview'
import { login, register, dashboard, forms, submission, urlBaseFrontend, urlBaseBackend } from './urls'
import {PrivateRoute} from './PrivateRoute'
import { AuthRoute } from './AuthRoute'

Expand All @@ -19,10 +20,11 @@ export default class Routes extends Component {
<PrivateRoute exact path={dashboard()} component={Dashboard} />
<PrivateRoute exact path={forms()} component={Forms} />
<PrivateRoute exact path={submission()} component={Submission} />
<PrivateRoute exact path={`${submission()}/:id`} component={SubmissionProfile} />
<PrivateRoute exact path={`${urlBaseFrontend()}form/:id`} component={Questions} />
<PrivateRoute exact path={`${urlBaseFrontend()}preview/:form_id/:user_id`} component={Preview} />
<AuthRoute path={login()} component={Login} />
<AuthRoute path={register()} component={Register} />
<Route path={upload()} component={Upload} />
<Route render={() => <Redirect to='/' />} />
</Switch>
</>
Expand Down
22 changes: 22 additions & 0 deletions src/actions/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
urlFormId
} from '../urls'
import {
GET_ALL_FORMS,
GET_PUBLISHED_FORMS,
GET_UNPUBLISHED_FORMS,
GET_FORM,
Expand All @@ -18,6 +19,27 @@ import {
FORM_ERRORS
} from './types'

export const getAllForms = () => async dispatch => {
try {
const config = {
headers: {
Authorization: `Bearer ${localStorage.token}`,
}
}
const res = await axios.get(urlPostForm(), config);
dispatch({
type: GET_ALL_FORMS,
payload: res.data
});
}
catch (err) {
dispatch({
type: FORM_ERRORS,
payload: err.response.data
})
}
}

export const getPublishedForm = (status) => async dispatch => {
try {
const config = {
Expand Down
22 changes: 22 additions & 0 deletions src/actions/info.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import axios from 'axios'
import {
urlInfo,
urlInfoId,
urlPatchInfo
} from '../urls'
import {
Expand Down Expand Up @@ -31,6 +32,27 @@ export const getInfo = () => async dispatch => {
}
}

export const getInfoId = (id) => async dispatch => {
try {
const config = {
headers: {
Authorization: `Bearer ${localStorage.token}`,
}
}
const res = await axios.get(urlInfoId(id), config);
dispatch({
type: GET_USER_INFO,
payload: res.data
});
}
catch (err) {
dispatch({
type: USER_INFO_ERRORS,
payload: err.response.data
})
}
}

export const postInfo = (data, callback) => async dispatch => {
try {
const config = {
Expand Down
100 changes: 100 additions & 0 deletions src/actions/submission.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import axios from 'axios'
import {
urlFormsFilled,
urlSubmissions,
urlFormsFilledId,
urlFormsFilledUser
} from '../urls'
import {
GET_FORMS,
GET_SUBMISSIONS,
UPDATE_SUBMISSION,
SUBMISSION_ERROR
} from './types'

export const getFormsFilled = () => async dispatch => {
try {
const config = {
headers: {
Authorization: `Bearer ${localStorage.token}`,
}
}
const res = await axios.get(urlFormsFilled(), config);
dispatch({
type: GET_FORMS,
payload: res.data
});
}
catch (err) {
dispatch({
type: SUBMISSION_ERROR,
payload: err.response.data
})
}
}

export const getFormsFilledUser = (id) => async dispatch => {
try {
const config = {
headers: {
Authorization: `Bearer ${localStorage.token}`,
}
}
const res = await axios.get(urlFormsFilledUser(id), config);
dispatch({
type: GET_FORMS,
payload: res.data
});
}
catch (err) {
dispatch({
type: SUBMISSION_ERROR,
payload: err.response.data
})
}
}

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

export const updateSubmission = (id, data, callback) => async dispatch => {
try {
const config = {
headers: {
Authorization: `Bearer ${localStorage.token}`,
}
}
const res = await axios.patch(urlFormsFilledId(id), data, config);
dispatch({
type: UPDATE_SUBMISSION,
payload: res.data
});
callback()
}
catch (err) {
console.log(err)
dispatch({
type: SUBMISSION_ERROR,
payload: err.response.data
})
callback()
}
}
6 changes: 6 additions & 0 deletions src/actions/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ export const FORM_ERRORS = 'FORM_ERRORS';
export const GET_QUESTIONS = 'GET_QUESTIONS';
export const POST_QUESTIONS = 'POST_QUESTIONS';
export const QUESTION_ERROR = 'QUESTION_ERROR';
export const GET_FORMS = 'GET_FORMS';
export const GET_ALL_FORMS = 'GET_ALL_FORMS';
export const GET_SUBMISSIONS = 'GET_SUBMISSIONS';
export const UPDATE_SUBMISSION = 'UPDATE_SUBMISSION';
export const SUBMISSION_ERROR = 'SUBMISSION_ERROR';

11 changes: 9 additions & 2 deletions src/components/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { Component } from 'react'
import '../styles/Dashboard.css'
import { Item, Card, Header, Divider, Icon } from 'semantic-ui-react'
import Profile from './Profile'
import FormsFilled from './FormsFilled'

export default class Dashboard extends Component {
constructor(props) {
Expand All @@ -27,18 +28,24 @@ export default class Dashboard extends Component {
<Item.Header>
<div className='head'>
<span>Profile</span>
<Icon name={this.state.edit ? 'x' : 'pencil'} color='grey' onClick={this.handleEdit} />
{
this.props.id ?
null
: <Icon name={this.state.edit ? 'x' : 'pencil'} color='grey' onClick={this.handleEdit} />
}

</div>
</Item.Header>
<Item.Description>
<Profile edit={this.state.edit}/>
<Profile edit={this.state.edit} id={this.props.id}/>
</Item.Description>
</Item.Content>
</Item>
<Divider/>
<Item>
<Item.Content>
<Header>Forms Filled</Header>
<FormsFilled id={this.props.id}/>
</Item.Content>
</Item>
</Item.Group>
Expand Down
82 changes: 82 additions & 0 deletions src/components/FormsFilled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import React, { Component } from 'react'
import { connect } from 'react-redux'
import { Link } from 'react-router-dom'
import { getFormsFilled, getFormsFilledUser } from '../actions/submission'
import PropTypes from 'prop-types'
import { preview } from '../urls'
import { Card, Button, Message, Modal, Icon, Header, Form, TextArea, Checkbox } from 'semantic-ui-react'
import moment from 'moment'
import '../styles/Dashboard.css'

class FormsFilled extends Component {
constructor(props) {
super(props)
}

componentDidMount() {
if(this.props.id){
this.props.getFormsFilledUser(this.props.id)
}
else{
this.props.getFormsFilled()
}
}

render() {
console.log(this.props.formsfilled)
const { formsfilled } = this.props
return(
<div className='formsfilled'>
<Card.Group>
{
formsfilled && formsfilled.length !== 0 ?
formsfilled.map(formsfilled =>
<Card fluid key={formsfilled.form.id} >
<Card.Content>
<Card.Header>{formsfilled.form.name}</Card.Header>
<Card.Meta>{formsfilled.form.description}</Card.Meta>
<div className='card'>
<div className='details'>
<div className='first'>
<span>Published Status: <span className='grey'>{formsfilled.form.published_status.toUpperCase()}</span></span>
<span>Fields: <span className='blue'>{formsfilled.form.questions.length}</span></span>
</div>
<div className='center'>
<span>Target User: <span className='blue'>{formsfilled.form.target_user.toUpperCase()}</span></span>
</div>
<div className='last'>
<span>Created: <span className='grey'>{moment(new Date(formsfilled.form.created_on), "YYYYMMDD").fromNow()}</span></span>
<span>Updated: <span className='grey'>{moment(new Date(formsfilled.form.updated_on), "YYYYMMDD").fromNow()}</span></span>
</div>
</div>
</div>
</Card.Content>
<Card.Content extra>
<Button icon basic color='grey' labelPosition='right' as={Link} to={preview(formsfilled.form.id, formsfilled.user.id)}>
<Icon name='arrow right' />
VIEW FORM
</Button>
</Card.Content>
</Card>
)
: <span>No forms filled yet.</span>
}
</Card.Group>
</div>
)
}
}

FormsFilled.propTypes = {
formsfilled: PropTypes.array.isRequired
};

const mapStateToProps = state => ({
formsfilled: state.submission.formsfilled,
submissionerror: state.submission.submissionerror
})

export default connect(
mapStateToProps,
{ getFormsFilled, getFormsFilledUser }
)(FormsFilled)
24 changes: 21 additions & 3 deletions src/components/Preview.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React, { Component } from 'react'
import { connect } from 'react-redux'
import { getQuestions } from '../actions/question'
import { Link } from 'react-router-dom'
import PropTypes from 'prop-types'
import '../styles/Questions.css'
import { DateInput, TimeInput } from 'semantic-ui-calendar-react';
import { Form, TextArea, Divider } from 'semantic-ui-react'
import { Form, TextArea, Divider, Item, Icon } from 'semantic-ui-react'
import { submissionprofile } from '../urls'

class Preview extends Component {
constructor(props) {
Expand All @@ -17,7 +19,12 @@ class Preview extends Component {
}

async componentDidMount() {
await this.props.getQuestions(this.props.id)
if(this.props.match.params.form_id){
await this.props.getQuestions(this.props.match.params.form_id)
}
else{
await this.props.getQuestions(this.props.id)
}
}

handleChange = (event, {name, value}) => {
Expand All @@ -30,7 +37,17 @@ class Preview extends Component {
const { questions } = this.props
const { value } = this.state
return (
<Form className='preview'>
<div className={this.props.id ? 'preview' : 'adminpreview'}>
{
this.props.id ?
null
:
<Item as={Link} to={submissionprofile(this.props.match.params.user_id)} className='back'>
<Icon name='arrow left' />
<Item.Content>Back to Profile</Item.Content>
</Item>
}
<Form>
{/* question type view based on each data type */}
{
questions && questions.length !== 0 ?
Expand Down Expand Up @@ -167,6 +184,7 @@ class Preview extends Component {
: null
}
</Form>
</div>
)
}
}
Expand Down
Loading