Skip to content

Commit

Permalink
Merge branch 'master' into kyle/fileUploads
Browse files Browse the repository at this point in the history
  • Loading branch information
didvi committed May 20, 2020
2 parents 0267819 + b2baa5b commit 18f557a
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 82 deletions.
1 change: 0 additions & 1 deletion app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ def dashboard
end
@professional_questionnaire = ProfessionalQuestionnairesSerializer.new(professional_q)
@resumeURL = nil
@resumeURL = nil
if (professional_q.resume.attached?)
@resumeURL = url_for(professional_q.resume)
end
Expand Down
5 changes: 3 additions & 2 deletions app/javascript/components/ActionItemCard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ function ActionItemCard({
.then(() => {
if (userType === 'participant') {
setCompletedParticipant(true);
} else {
setCompletedStaff(true);
}
setCompletedStaff(true);
})
.catch(error => {
Sentry.configureScope(function(scope) {
Expand Down Expand Up @@ -183,7 +184,7 @@ function ActionItemCard({
<Grid
container
className={
completedParticipant && completedStaff
(completedParticipant && completedStaff)
? classes.disabledCardStyle
: classes.cardStyle
}
Expand Down
4 changes: 2 additions & 2 deletions app/javascript/components/ParticipantShowPage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class ParticipantShowPage extends React.Component {
resumeURL,
} = this.props;


return (
<Grid
container
Expand Down Expand Up @@ -157,7 +156,8 @@ ParticipantShowPage.propTypes = {
personalQuestionnaire: PropTypes.object.isRequired,
professionalQuestionnaire: PropTypes.object.isRequired,
studioAssessments: PropTypes.array.isRequired,
resumeURL: PropTypes.string.isRequired,
assignmentList: PropTypes.array,
};

export default withStyles(styles)(ParticipantShowPage);
export default withStyles(styles)(ParticipantShowPage);
108 changes: 58 additions & 50 deletions app/javascript/components/QuestionnaireForm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {
MenuItem,
InputLabel,
FormControl,
Input,
Typography,
} from '@material-ui/core/';
import DateFnsUtils from '@date-io/date-fns';
import {
Expand Down Expand Up @@ -49,47 +51,54 @@ class QuestionnaireForm extends React.Component {

handleSubmit() {
if (this.props.type === 'professional') {
const qType = `${this.props.type}_questionnaire`;
const formData = new FormData();

Object.keys(this.state.questionnaire).forEach(f => {
formData.append(`${qType}[${f}]`, this.state.questionnaire[f]);
if (this.state.questionnaire[f]) {
formData.append(
`professional_questionnaire[${f}]`,
this.state.questionnaire[f],
);
} else {
formData.append(`professional_questionnaire[${f}]`, '');
}
});
formData.append(`${qType}[resume]`, this.state.file);
formData.append(`${qType}[participant_id]`, this.props.participantId);
formData.append(`professional_questionnaire[resume]`, this.state.file);
formData.append(
`professional_questionnaire[participant_id]`,
this.props.participantId,
);
const { id } = this.props.questionnaire;
const request = `/api/${qType}s/${id}`;
const request = `/api/professional_questionnaires/${id}`;
apiPut(request, formData)
.then(() => window.location.reload())
.catch(error => {
Sentry.configureScope(function (scope) {
Sentry.configureScope(function(scope) {
scope.setExtra('file', 'QuestionnaireForm');
scope.setExtra('action', 'apiPut');
scope.setExtra('QuestionnaireForm', JSON.stringify(formData));
scope.setExtra('qType', qType);
scope.setExtra('qType', 'professional_questionnaire');
});
Sentry.captureException(error);
});
} else {
const qType = `${this.props.type}_questionnaire`;
const body = {};

Object.keys(this.state.questionnaire).forEach(f => {
body[f] = this.state.questionnaire[f];
});
body.participant_id = this.props.participantId;

const { id } = this.props.questionnaire;
const request = `/api/${qType}s/${id}`;
const request = `/api/personal_questionnaires/${id}`;

apiPut(request, { [qType]: body })
apiPut(request, { personal_questionnaire: body })
.then(() => window.location.reload())
.catch(error => {
Sentry.configureScope(function (scope) {
Sentry.configureScope(function(scope) {
scope.setExtra('file', 'QuestionnaireForm');
scope.setExtra('action', 'apiPut');
scope.setExtra('QuestionnaireForm', body);
scope.setExtra('qType', qType);
scope.setExtra('qType', 'Personal Questionnaire');
});
Sentry.captureException(error);
});
Expand Down Expand Up @@ -165,23 +174,6 @@ class QuestionnaireForm extends React.Component {
createTextForm(fieldName, fieldValue, contentText) {
// content text is prompt/title for the text box
// field name is the name of the field that will be filled in the database
if (fieldValue === null || fieldValue === 'null') {
return (
<div className={this.props.classes.questionnaireEntry}>
<DialogContentText>{contentText}</DialogContentText>
<TextField
className={`${this.props.classes.dialogContentTextField} ${this.props.classes.questionnaireTextField}`}
onChange={e => this.handleTextFormChange(e)}
variant="outlined"
id={fieldName}
multiline
type="text"
margin="dense"
maxRows={20}
/>
</div>
);
}
if (fieldName === 'DOC_status') {
return (
<div className={this.props.classes.questionnaireEntry}>
Expand Down Expand Up @@ -401,6 +393,7 @@ class QuestionnaireForm extends React.Component {
return this.createTextForm(f, questionnaire[f], sentenceCase);
});
if (this.props.type === 'professional') {
questionnaires.push(this.showUploadedFile());
questionnaires.push(this.getFileUpload());
}
return <div className={styles.container}>{questionnaires}</div>;
Expand All @@ -409,11 +402,9 @@ class QuestionnaireForm extends React.Component {

getFileUpload() {
return (
<div>
<DialogContentText>Upload Resume</DialogContentText>
{this.showUploadedFile()}
{this.showSelectedFile()}
<input
<div className={this.props.classes.questionnaireEntry}>
<DialogContentText>Upload New Resume</DialogContentText>
<Input
type="file"
onChange={event => {
this.setState({ file: event.target.files[0] });
Expand All @@ -424,26 +415,42 @@ class QuestionnaireForm extends React.Component {
}

showUploadedFile() {
if (this.props.resumeURL) {
const { file } = this.state;
if (file) {
const objectURL = window.URL.createObjectURL(file);
return (
<Button onClick={() => window.open(this.props.resumeURL, '_blank')}>
View Uploaded Resume
</Button>
<div className={this.props.classes.questionnaireEntry}>
<DialogContentText>View Resume</DialogContentText>
<Button
className={this.props.classes.buttonStyle}
onClick={() => window.open(objectURL, '_blank')}
>
View File
</Button>
</div>
);
}
return (<div>No Resume Uploaded</div>);
}

showSelectedFile() {
const { file } = this.state;
if (file) {
const objectURL = window.URL.createObjectURL(file);
if (this.props.resumeURL) {
return (
<Button onClick={() => window.open(objectURL, '_blank')}>
View Selected File
</Button>
<div className={this.props.classes.questionnaireEntry}>
<DialogContentText>View Resume</DialogContentText>
<Button
size="small"
className={this.props.classes.buttonStyle}
onClick={() => window.open(this.props.resumeURL, '_blank')}
>
View File
</Button>
</div>
);
}
return (
<div className={this.props.classes.questionnaireEntry}>
<DialogContentText>View Resume</DialogContentText>
<Typography variant="overline">No Resume Uploaded</Typography>
</div>
);
}

render() {
Expand Down Expand Up @@ -478,7 +485,8 @@ QuestionnaireForm.propTypes = {
type: PropTypes.oneOf(['personal', 'professional']).isRequired,
participantId: PropTypes.number.isRequired,
questionnaire: PropTypes.object.isRequired,
handleClose: PropTypes.func,
handleClose: PropTypes.func.isRequired,
resumeURL: PropTypes.string,
};

export default withStyles(styles)(QuestionnaireForm);
export default withStyles(styles)(QuestionnaireForm);
5 changes: 4 additions & 1 deletion app/javascript/components/QuestionnaireForm/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
* This contains all the styles for the QuestionnaireForm container.
*/

const styles = () => ({
const styles = theme => ({
dialogActions: {
padding: 30,
},
buttonContainer: {
padding: 15,
},
buttonStyle: {
color: theme.palette.common.r0,
},
questionnaireTextField: {
width: '100%',
},
Expand Down
4 changes: 2 additions & 2 deletions app/javascript/components/QuestionnaireModal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ function QuestionnaireModal({
<QuestionnaireView
type={questionnaireType}
questionnaire={questionnaire}
handleClose={() => setOpen(false)}
resumeURL={resumeURL}
/>
);
Expand Down Expand Up @@ -71,6 +70,7 @@ QuestionnaireModal.propTypes = {
participantId: PropTypes.number.isRequired,
questionnaireType: PropTypes.oneOf(['personal', 'professional']).isRequired,
userType: PropTypes.oneOf(['staff', 'participant']).isRequired,
resumeURL: PropTypes.string,
};

export default memo(withStyles(styles)(QuestionnaireModal));
export default memo(withStyles(styles)(QuestionnaireModal));
31 changes: 17 additions & 14 deletions app/javascript/components/QuestionnaireView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import React, { memo } from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import { DialogContent, Grid, Typography, Button } from '@material-ui/core';

import styles from './styles';

function QuestionnaireView({ classes, questionnaire, resumeURL }) {
function QuestionnaireView({ classes, questionnaire, type, resumeURL }) {
const renderField = (title, body) => {
if (
title === 'participant' ||
Expand All @@ -34,7 +33,7 @@ function QuestionnaireView({ classes, questionnaire, resumeURL }) {
titleRender = 'Second Emergency Contact Relationship (optional)';
}

const bodyRender = body === null ? 'N/A' : body;
const bodyRender = body || 'N/A';

return (
<Grid item key={title} className={classes.field}>
Expand All @@ -45,32 +44,34 @@ function QuestionnaireView({ classes, questionnaire, resumeURL }) {
};

const showUploadedFile = () => {

if (resumeURL) {
return (
<Grid item className={classes.field}>
<Typography variant="h6">Resume</Typography>
<Button onClick={() => window.open(resumeURL, '_blank')}>
<Button
className={classes.buttonStyle}
onClick={() => window.open(resumeURL, '_blank')}
>
View Uploaded Resume
</Button>
</Button>
</Grid>
);
}
return (<Grid item className={classes.field}>
<Typography variant="h6">Resume</Typography>
<Button >
No Resume Uploaded
</Button>
</Grid>);
}
return (
<Grid item className={classes.field}>
<Typography variant="h6">Resume</Typography>
<Typography variant="overline">No Resume Uploaded</Typography>
</Grid>
);
};

return (
<DialogContent>
<Grid container direction="column">
{Object.entries(questionnaire).map(field =>
renderField(field[0], field[1]),
)}
{showUploadedFile()}
{type === 'professional' ? showUploadedFile() : null}
</Grid>
</DialogContent>
);
Expand All @@ -79,6 +80,8 @@ function QuestionnaireView({ classes, questionnaire, resumeURL }) {
QuestionnaireView.propTypes = {
classes: PropTypes.object.isRequired,
questionnaire: PropTypes.object.isRequired,
type: PropTypes.string.isRequired,
resumeURL: PropTypes.string,
};

export default memo(withStyles(styles)(QuestionnaireView));
5 changes: 4 additions & 1 deletion app/javascript/components/QuestionnaireView/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
* This contains all the styles for the QuestionnaireView component.
*/

const styles = () => ({
const styles = theme => ({
field: {
padding: '12px 90px',
textTransform: 'capitalize',
},
buttonStyle: {
color: theme.palette.common.r0,
},
});

export default styles;
18 changes: 9 additions & 9 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,23 +152,23 @@ def create_studio_assesments
1.upto(NUM_STUDIO_ASSESSMENTS) do |i|
StudioAssessment.create!(
bigpicture_score: Faker::Number.between(from: 0, to: 3),
bigpicture_comment: Faker::Cannabis.buzzword,
bigpicture_comment: Faker::Hacker.say_something_smart,
progfundamentals_score: Faker::Number.between(from: 0, to: 3),
progfundamentals_comment: Faker::Cannabis.buzzword,
progfundamentals_comment: Faker::Hacker.say_something_smart,
versioncontrol_score: Faker::Number.between(from: 0, to: 3),
versioncontrol_comment: Faker::Cannabis.buzzword,
versioncontrol_comment: Faker::Hacker.say_something_smart,
react_score: Faker::Number.between(from: 0, to: 3),
react_comment: Faker::Cannabis.buzzword,
react_comment: Faker::Hacker.say_something_smart,
node_score: Faker::Number.between(from: 0, to: 3),
node_comment: Faker::Cannabis.buzzword,
node_comment: Faker::Hacker.say_something_smart,
db_score: Faker::Number.between(from: 0, to: 3),
db_comment: Faker::Cannabis.buzzword,
db_comment: Faker::Hacker.say_something_smart,
problemsolving_score: Faker::Number.between(from: 0, to: 3),
problemsolving_comment:Faker::Cannabis.buzzword,
problemsolving_comment:Faker::Hacker.say_something_smart,
problemsolvingalt_score: Faker::Number.between(from: 0, to: 3),
problemsolvingalt_comment:Faker::Cannabis.buzzword,
problemsolvingalt_comment:Faker::Hacker.say_something_smart,
capstone_passed: Faker::Boolean.boolean,
capstone_comment:Faker::Cannabis.buzzword,
capstone_comment:Faker::Hacker.say_something_smart,
assessment_type: Faker::Hacker.say_something_smart,
staff_id: Faker::Number.between(from: STAFF_START_ID, to: STAFF_END_ID),
participant_id: Faker::Number.between(from: PARTICIPANT_START_ID, to: PARTICIPANT_END_ID)
Expand Down

0 comments on commit 18f557a

Please sign in to comment.