Skip to content

Commit

Permalink
Add new question in checkInForm
Browse files Browse the repository at this point in the history
  • Loading branch information
sarL3y committed Jan 22, 2020
1 parent 526fc55 commit b5d42ce
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 10 deletions.
75 changes: 70 additions & 5 deletions client/src/pages/CheckInForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const CheckInForm = (props) => {
const [month, setMonth] = useState("JAN");
const [year, setYear] = useState("2020");
const [reason, setReason] = useState("--SELECT ONE--");
const [project, setProject] = useState("--SELECT ONE--");

const fetchQuestions = async () => {
try {
Expand Down Expand Up @@ -63,6 +64,11 @@ const CheckInForm = (props) => {
setIsQuestionAnswered(true);
};

const handleProjectChange = (e) => {
setProject(e.currentTarget.value);
setIsQuestionAnswered(true);
};

const handleNewMemberChange = (e) => {
if (e.target.value === "true") {
setNewMember(true);
Expand All @@ -78,6 +84,7 @@ const CheckInForm = (props) => {
const months = ["JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"];
const years = ["2020", "2019", "2018", "2017", "2016", "2015", "2014", "2013"];
const reasons = ["--SELECT ONE--", "Open Data", "Homelessness", "Social Justice/Equity", "Transportation", "Mental Health", "Civic Engagement"];
const projects = ["--SELECT ONE--", "311 Data", "Engage", "Food Oasis", "HackforLA.org Website", "HelloGOV", "Lucky Parking", "Metro On-time", "New Schools Today", "Not Today", "Public Tree Map", "Record Clearance", "Shared Housing Project", "TDM Calculator", "Triage Tracker", "Undebate", "VRMS"];

const submitForm = (userForm) => {
// First, create a new user in the user collection
Expand Down Expand Up @@ -136,8 +143,14 @@ const CheckInForm = (props) => {
attendanceReason: reason
};

// const answer = {
// whichProject: project
// };

console.log(answer);

const answerJson = JSON.stringify(answer);

if (responseId === false) {
setIsError(true);
setErrorMessage("You haven't checked in with that email. Redirecting home to create a new profile...");
Expand All @@ -148,7 +161,7 @@ const CheckInForm = (props) => {
} else {
return fetch(`/api/users/${responseId}`, {
method: "PATCH",
body: JSON.stringify(answer),
body: answerJson,
headers: {
"Content-Type": "application/json"
}
Expand All @@ -159,7 +172,7 @@ const CheckInForm = (props) => {
.then(response => {
const checkInForm = { userId: `${response}`, eventId: new URLSearchParams(props.location.search).get('eventId') };

console.log(checkInForm.userId);
console.log(`Here's the form: ${checkInForm.toString()}`);

return fetch('/api/checkins', {
method: "POST",
Expand All @@ -169,8 +182,10 @@ const CheckInForm = (props) => {
}
})
.then(res => {
console.log(res);
props.history.push('/magicLink');
if (res.ok) {
console.log("That whole function ran successfully");
props.history.push('/magicLink');
}
})
.catch(err => console.log(err));
})
Expand Down Expand Up @@ -284,7 +299,6 @@ const CheckInForm = (props) => {
<div className="check-in-container">
<div className="check-in-headers">
<h3>Welcome back!</h3>
<h4>Answer a quick question to unlock the check-in button.</h4>
</div>
<div className="check-in-form">
<form className="form-check-in" autoComplete="off" onSubmit={e => e.preventDefault()}>
Expand Down Expand Up @@ -312,6 +326,29 @@ const CheckInForm = (props) => {
);
})}

{/* {questions.length !== 0 && questions.map((question) => {
return question.htmlName === 'whichProject' && (
<div key={question._id} className="form-row">
<div className="form-input-text">
<label htmlFor={question.htmlName}>{question.questionText}</label>
<div className="select-reason">
<select
name={question.htmlName}
value={project}
// aria-label="topic"
onChange={handleProjectChange}
required
>
{projects.map((project, index) => {
return <option key={index} value={project}>{project}</option>
})}
</select>
</div>
</div>
</div>
);
})} */}

<div className="form-row">
<div className="form-input-text">
<label htmlFor="email">What email address did you use to check-in last time?</label>
Expand Down Expand Up @@ -358,6 +395,34 @@ const CheckInForm = (props) => {
</div>
</div>
)}

{/* {isQuestionAnswered && project !== "--SELECT ONE--" && formInput.email && formInput.email !== "" ? (
!isLoading ? (
<div className="form-row">
<div className="form-input-button">
<button type="submit" className="form-check-in-submit" onClick={e => checkInReturningUser(e)}>
CHECK IN
</button>
</div>
</div>
) : (
<div className="form-row">
<div className="form-input-button">
<button type="submit" className="form-check-in-submit" onClick={e => e.preventDefault()}>
CHECKING IN...
</button>
</div>
</div>
)
) : (
<div className="form-row">
<div className="form-input-button block">
<button type="submit" className="form-check-in-submit block" onClick={e => e.preventDefault()}>
CHECK IN
</button>
</div>
</div>
)} */}
</form>
</div>
</div>
Expand Down
6 changes: 4 additions & 2 deletions models/user.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const userSchema = mongoose.Schema({
desiredRole: { type: String },
newMember: { type: Boolean },
firstAttended: { type: String },
attendanceReason: { type: String }
attendanceReason: { type: String },
whichProject: { type: String }
// password: { type: String, required: true }
});

Expand All @@ -33,7 +34,8 @@ userSchema.methods.serialize = () => {
desiredRole: this.desiredRole,
newMember: this.newMember,
firstAttended: this.firstAttended,
attendanceReason: this.attendanceReason
attendanceReason: this.attendanceReason,
whichProject: this.whichProject
};
};

Expand Down
7 changes: 4 additions & 3 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const path = require('path');
const app = express();

// Load config variables
const { TEST_DATABASE_URL, PORT } = require('./config/database');
const { DATABASE_URL, PORT } = require('./config/database');

// Required to view Request Body (req.body) in JSON
app.use(bodyParser.json());
Expand Down Expand Up @@ -66,7 +66,8 @@ async function runServer(databaseUrl, port = PORT) {
{
useNewUrlParser: true,
useCreateIndex: true,
useUnifiedTopology: true
useUnifiedTopology: true,
useFindAndModify: false
}
).catch(err => err);

Expand Down Expand Up @@ -95,7 +96,7 @@ async function closeServer() {
};

if (require.main === module) {
runServer(TEST_DATABASE_URL).catch(err => console.error(err));
runServer(DATABASE_URL).catch(err => console.error(err));
};

// app.listen(process.env.PORT || PORT, () => {
Expand Down

0 comments on commit b5d42ce

Please sign in to comment.