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 1 commit
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
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
52 changes: 52 additions & 0 deletions src/actions/submission.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import axios from 'axios'
import {
urlFormsFilled,
urlSubmissions
} from '../urls'
import {
GET_FORMS,
GET_SUBMISSIONS,
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 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
})
}
}
5 changes: 5 additions & 0 deletions src/actions/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ 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 SUBMISSION_ERROR = 'SUBMISSION_ERROR';

2 changes: 2 additions & 0 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 Down Expand Up @@ -39,6 +40,7 @@ export default class Dashboard extends Component {
<Item>
<Item.Content>
<Header>Forms Filled</Header>
<FormsFilled />
</Item.Content>
</Item>
</Item.Group>
Expand Down
42 changes: 42 additions & 0 deletions src/components/FormsFilled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React, { Component } from 'react'
import { connect } from 'react-redux'
import { Link } from 'react-router-dom'
import { getFormsFilled } from '../actions/submission'
import PropTypes from 'prop-types'
import { form } from '../urls'
import { Card, Button, Message, Modal, Icon, Header, Form, TextArea, Checkbox } from 'semantic-ui-react'
import moment from 'moment'
import '../styles/Form.css'

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

componentDidMount() {
this.props.getFormsFilled()
}

render() {
console.log(this.props)
return(
<div>
hello works
</div>
)
}
}

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

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

export default connect(
mapStateToProps,
{ getFormsFilled }
)(FormsFilled)
122 changes: 118 additions & 4 deletions src/components/Submission.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,125 @@
import React, { Component } from 'react'
import { connect } from 'react-redux'
import { Link } from 'react-router-dom'
import { getAllSubmissions } from '../actions/submission'
import { getInfo } from '../actions/info'
import { getAllForms } from '../actions/form'
import PropTypes from 'prop-types'
import { form, submission } from '../urls'
import { Card, Button, Message, Modal, Icon, Header, Form, TextArea, Checkbox, Grid, Dropdown, Search, Input } from 'semantic-ui-react'
import moment from 'moment'
import '../styles/Submission.css'

export default class Submissions extends Component {
const options = [
{ key: 'accepted', text: 'Accepted', value: 'accepted'},
{ key: 'rejected', text: 'Rejected', value: 'rejected'},
{ key: 'waitlisted', text: 'Waitlisted', value: 'waitlisted'},
{ key: 'pending', text: 'Pending', value: 'pending'},
]

const colorStyles = {
option: (base, state) => ({
...base,
color: 'red'
})
}

class Submission extends Component {
constructor(props) {
super(props)
this.state = {
form_id: undefined,
user_name: undefined,
}
}

componentDidMount() {
this.props.getInfo()
this.props.getAllForms()
this.props.getAllSubmissions(this.state.user_name, this.state.form_id)
}

onSearchChange = (e) => {
this.setState({
user_name: e.target.value,
})
this.props.getAllSubmissions(this.state.user_name, this.state.form_id)
}

formChange = (e, data) => {
this.setState({
form_id: data.value.length !== 0 ? data.value : undefined
})
this.props.getAllSubmissions(this.state.user_name, this.state.form_id)
}

render() {
return (
<div>
submissions
const { submissions, forms } = this.props
const formOptions = forms.map(form => ({
key: form.id,
text: form.name,
value: form.id
}))
console.log(this.state)
bismitaguha marked this conversation as resolved.
Show resolved Hide resolved
return(
<div className='submission'>
<div className='searches'>
<Input
value={this.state.user_name}
onChange={this.onSearchChange}
/>
<Dropdown
multiple
selection
fluid
placeholder='Search by form...'
options={formOptions}
onChange={this.formChange}
/>
</div>
{
submissions && submissions.length !== 0 ?
<Grid celled>
{
submissions.map(submission =>
<Grid.Row>
<Grid.Column width={2}>{submission.user.user_name[0] ? submission.user.user_name[0] : submission.user.username}</Grid.Column>
<Grid.Column width={2}>{submission.form.name}</Grid.Column>
<Grid.Column width={10}>{submission.user.username}</Grid.Column>
<Grid.Column width={2} textAlign='center' >
<Dropdown
inline
options={options}
defaultValue={submission.acceptance_status}
styles={colorStyles}
/>
</Grid.Column>
</Grid.Row>

)
}
</Grid>
: <span>No submissions yet.</span>
}
</div>
)
}
}

Submission.propTypes = {
userinfo: PropTypes.func.isRequired,
submissions: PropTypes.array.isRequired,
forms: PropTypes.array.isRequired,
};

const mapStateToProps = state => ({
userinfo: state.info.userinfo,
submissions: state.submission.submissions,
forms: state.form.form,
submissionerror: state.submission.submissionerror
})

export default connect(
mapStateToProps,
{ getAllSubmissions, getInfo, getAllForms }
)(Submission)
7 changes: 7 additions & 0 deletions src/reducers/form.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
GET_ALL_FORMS,
GET_PUBLISHED_FORMS,
GET_UNPUBLISHED_FORMS,
GET_FORM,
Expand All @@ -13,6 +14,7 @@ import {
} from '../actions/types';

const initialState = {
form: [],
publishedform: [],
unpublishedform: [],
postform: [],
Expand All @@ -25,6 +27,11 @@ const initialState = {

const formReducer = (state = initialState, action) => {
switch(action.type) {
case GET_ALL_FORMS:
return {
...state,
form: action.payload,
};
case GET_PUBLISHED_FORMS:
return {
...state,
Expand Down
4 changes: 3 additions & 1 deletion src/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import infoReducer from './info'
import userReducer from './user'
import formReducer from './form'
import questionReducer from './question'
import submissionReducer from './submission'

const rootReducers = combineReducers ({
login: loginReducer,
info: infoReducer,
user: userReducer,
form: formReducer,
questions: questionReducer
questions: questionReducer,
submission: submissionReducer
})

export default rootReducers
35 changes: 35 additions & 0 deletions src/reducers/submission.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {
GET_FORMS,
GET_SUBMISSIONS,
SUBMISSION_ERROR
} from '../actions/types';

const initialState = {
formsfilled: [],
submissions: [],
submissionerror: null
}

const submissionReducer = (state = initialState, action) => {
switch(action.type) {
case GET_FORMS:
return {
...state,
formsfilled: action.payload,
};
case GET_SUBMISSIONS:
return {
...state,
submissions: action.payload,
};
case SUBMISSION_ERROR:
return {
...state,
submissionerror: action.payload,
}
default:
return state
}
}

export default submissionReducer
9 changes: 9 additions & 0 deletions src/styles/Submission.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.submission {
margin-left: 5vw;
margin-right: 5vw;
}

.searches {
display: flex;
flex-direction: row;
}
13 changes: 13 additions & 0 deletions src/urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,17 @@ export function urlPatchQuestions() {
return `${urlBaseBackend()}/questions/`
}

export function urlFormsFilled() {
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}`
}