diff --git a/client/src/pages/CheckInForm.js b/client/src/pages/CheckInForm.js index 62410828..f48cdf75 100644 --- a/client/src/pages/CheckInForm.js +++ b/client/src/pages/CheckInForm.js @@ -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 { @@ -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); @@ -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 @@ -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..."); @@ -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" } @@ -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", @@ -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)); }) @@ -284,7 +299,6 @@ const CheckInForm = (props) => {

Welcome back!

-

Answer a quick question to unlock the check-in button.

e.preventDefault()}> @@ -312,6 +326,29 @@ const CheckInForm = (props) => { ); })} + {/* {questions.length !== 0 && questions.map((question) => { + return question.htmlName === 'whichProject' && ( +
+
+ +
+ +
+
+
+ ); + })} */} +
@@ -358,6 +395,34 @@ const CheckInForm = (props) => {
)} + + {/* {isQuestionAnswered && project !== "--SELECT ONE--" && formInput.email && formInput.email !== "" ? ( + !isLoading ? ( +
+
+ +
+
+ ) : ( +
+
+ +
+
+ ) + ) : ( +
+
+ +
+
+ )} */}
diff --git a/models/user.model.js b/models/user.model.js index 1bff4d17..7a3360a7 100644 --- a/models/user.model.js +++ b/models/user.model.js @@ -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 } }); @@ -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 }; }; diff --git a/server.js b/server.js index 2aa1ffa8..84e3ce57 100644 --- a/server.js +++ b/server.js @@ -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()); @@ -66,7 +66,8 @@ async function runServer(databaseUrl, port = PORT) { { useNewUrlParser: true, useCreateIndex: true, - useUnifiedTopology: true + useUnifiedTopology: true, + useFindAndModify: false } ).catch(err => err); @@ -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, () => {