From 0d5f8e885e13c614044c8aa7479c74c958edbf86 Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 25 Oct 2024 17:41:37 -0400 Subject: [PATCH 1/5] worked on it --- backend/server.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/backend/server.js b/backend/server.js index 80539c5..74d2c8b 100644 --- a/backend/server.js +++ b/backend/server.js @@ -42,7 +42,14 @@ const User = mongoose.model("users", UserSchema) // Contact Schema // TODO (Frank & Madeline): Create a ContactSchema +const ContactSchema = new Schema ({ + name: { type: String, required: true}, + email: { type: String, required: true}, + subject: { type: String, required: true}, + message: { type: String, required: true} +}) +const Contact = mongoose.model("contact", ContactSchema) // Class Schema @@ -64,7 +71,21 @@ const User = mongoose.model("users", UserSchema) // Contact // TODO (Frank & Madeline): Create an endpoint to receive and upload contact inquiries to the database - +app.post('/contact', async (req, res) => { + try { + const newContact = new Contact ({ + name, + email, + subject, + message + }) + await newContact.save() + } + catch (err) { + console.error('Error saving contact data:', err); + process.exit(1); + } +}) // Classes From 3b3bfe210b0b8efd976827772df064836e980ec4 Mon Sep 17 00:00:00 2001 From: Frank Date: Sat, 26 Oct 2024 16:50:59 -0400 Subject: [PATCH 2/5] Update server.js --- backend/server.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/backend/server.js b/backend/server.js index 74d2c8b..26f6690 100644 --- a/backend/server.js +++ b/backend/server.js @@ -71,19 +71,20 @@ const Contact = mongoose.model("contact", ContactSchema) // Contact // TODO (Frank & Madeline): Create an endpoint to receive and upload contact inquiries to the database -app.post('/contact', async (req, res) => { +app.post('/api/contact', async (req, res) => { + const{ name, email, subject, message } = req.body try { - const newContact = new Contact ({ - name, - email, - subject, - message + await Contact.create({ + name: name, + email: email, + subject: subject, + message: message }) - await newContact.save() + res.status(201).json({message: 'Inquiry submitted successfully'}) } catch (err) { - console.error('Error saving contact data:', err); - process.exit(1); + console.error('Error submitting inquiry:', err); + res.status(500).json({message: 'Error submitting inquiry'}) } }) From e4be9e840adacc0b427068fb8ab0fa51681ba699 Mon Sep 17 00:00:00 2001 From: Frank Date: Mon, 28 Oct 2024 00:21:07 -0400 Subject: [PATCH 3/5] Update server.js changed .env file and made attempt at contact endpoint --- backend/server.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/backend/server.js b/backend/server.js index 26f6690..44f22d4 100644 --- a/backend/server.js +++ b/backend/server.js @@ -43,13 +43,14 @@ const User = mongoose.model("users", UserSchema) // TODO (Frank & Madeline): Create a ContactSchema const ContactSchema = new Schema ({ - name: { type: String, required: true}, + name: { type: String, required: false }, email: { type: String, required: true}, subject: { type: String, required: true}, message: { type: String, required: true} }) -const Contact = mongoose.model("contact", ContactSchema) +const Contact = mongoose.model('Contact', ContactSchema); +// export default Contact; // Class Schema @@ -71,6 +72,23 @@ const Contact = mongoose.model("contact", ContactSchema) // Contact // TODO (Frank & Madeline): Create an endpoint to receive and upload contact inquiries to the database +// async function uploadContact () { +// const article = new Contact({ +// name: 'test user', +// email: 'test@example.com', +// subject: 'Test Inquiry', +// message: 'Test message' + +// }); + +// await article.save(); +// const firstContact = await Contact.findOne({}); +// console.log(firstContact); +// } +// uploadContact().catch(console.error); + +// const firstArticle = await Contact.findOne({}); +// console.log(firstArticle); app.post('/api/contact', async (req, res) => { const{ name, email, subject, message } = req.body try { From 849a71558d8b740a211223902d8d1de0337caee8 Mon Sep 17 00:00:00 2001 From: madeline-lei Date: Thu, 31 Oct 2024 13:57:57 -0400 Subject: [PATCH 4/5] mostly finished? --- backend/server.js | 12 ++--- package-lock.json | 100 ++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + src/pages/Contact.jsx | 22 +++++----- 4 files changed, 120 insertions(+), 15 deletions(-) diff --git a/backend/server.js b/backend/server.js index 44f22d4..fbff9f8 100644 --- a/backend/server.js +++ b/backend/server.js @@ -92,12 +92,14 @@ const Contact = mongoose.model('Contact', ContactSchema); app.post('/api/contact', async (req, res) => { const{ name, email, subject, message } = req.body try { - await Contact.create({ - name: name, - email: email, - subject: subject, - message: message + const newContact = new Contact({ + name, + email, + subject, + message }) + await newContact.save() + res.status(201).json({message: 'Inquiry submitted successfully'}) } catch (err) { diff --git a/package-lock.json b/package-lock.json index 537ca8e..38b7d50 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,7 @@ "name": "dillar-academy", "version": "0.0.0", "dependencies": { + "axios": "^1.7.7", "react": "^18.3.1", "react-dom": "^18.3.1", "wouter": "^3.3.5" @@ -1523,6 +1524,12 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", + "license": "MIT" + }, "node_modules/autoprefixer": { "version": "10.4.20", "resolved": "https://registry.npmjs.org/autoprefixer/-/autoprefixer-10.4.20.tgz", @@ -1575,6 +1582,17 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/axios": { + "version": "1.7.7", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.7.tgz", + "integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==", + "license": "MIT", + "dependencies": { + "follow-redirects": "^1.15.6", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -1769,6 +1787,18 @@ "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==", "dev": true }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "license": "MIT", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, "node_modules/commander": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/commander/-/commander-4.1.1.tgz", @@ -1930,6 +1960,15 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "license": "MIT", + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/didyoumean": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/didyoumean/-/didyoumean-1.2.2.tgz", @@ -2584,6 +2623,26 @@ "integrity": "sha512-X8cqMLLie7KsNUDSdzeN8FYK9rEt4Dt67OsG/DNGnYTSDBG4uFAJFBnUeiV+zCVAvwFy56IjM9sH51jVaEhNxw==", "dev": true }, + "node_modules/follow-redirects": { + "version": "1.15.9", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz", + "integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "license": "MIT", + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, "node_modules/for-each": { "version": "0.3.3", "resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz", @@ -2609,6 +2668,20 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/form-data": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.1.tgz", + "integrity": "sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==", + "license": "MIT", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/fraction.js": { "version": "4.3.7", "resolved": "https://registry.npmjs.org/fraction.js/-/fraction.js-4.3.7.tgz", @@ -3535,6 +3608,27 @@ "node": ">=8.6" } }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "license": "MIT", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, "node_modules/minimatch": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", @@ -4080,6 +4174,12 @@ "react-is": "^16.13.1" } }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==", + "license": "MIT" + }, "node_modules/punycode": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", diff --git a/package.json b/package.json index d8170bf..680f73b 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "preview": "vite preview" }, "dependencies": { + "axios": "^1.7.7", "react": "^18.3.1", "react-dom": "^18.3.1", "wouter": "^3.3.5" diff --git a/src/pages/Contact.jsx b/src/pages/Contact.jsx index ddc393f..033858f 100644 --- a/src/pages/Contact.jsx +++ b/src/pages/Contact.jsx @@ -1,5 +1,6 @@ import { useState } from 'react'; +import axios from 'axios'; export default function Contact( ) { @@ -14,17 +15,18 @@ export default function Contact( ) { setFormData({ ...formData, [e.target.name]: e.target.value }); }; - const handleSubmit = (e) => { + const handleSubmit = async (e) => { + const { name, email, subject, message } = formData + e.preventDefault(); - - const alertMessage = ` - Name: ${formData.name} - Email: ${formData.email} - Subject: ${formData.subject} - Message: ${formData.message} - `; - - alert(alertMessage); + try { + const response = await axios.post(`${import.meta.env.VITE_API_URL}/api/contact`, formData) + if(response.status == 201) { + alert("Inquiry submitted successfully!") + } + } catch (err) { + alert("There was an error submitting the inquiry.") + } console.log('Form submitted:', formData); }; From de9ec68d61c7dd756d474887b09a1f8a91a9c6ff Mon Sep 17 00:00:00 2001 From: madeline-lei Date: Sat, 2 Nov 2024 14:18:50 -0400 Subject: [PATCH 5/5] changes --- package-lock.json | 100 ------------------------------------------ package.json | 1 - src/pages/Contact.jsx | 21 ++++++--- 3 files changed, 15 insertions(+), 107 deletions(-) diff --git a/package-lock.json b/package-lock.json index 38b7d50..537ca8e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,7 +8,6 @@ "name": "dillar-academy", "version": "0.0.0", "dependencies": { - "axios": "^1.7.7", "react": "^18.3.1", "react-dom": "^18.3.1", "wouter": "^3.3.5" @@ -1524,12 +1523,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/asynckit": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", - "license": "MIT" - }, "node_modules/autoprefixer": { "version": "10.4.20", "resolved": "https://registry.npmjs.org/autoprefixer/-/autoprefixer-10.4.20.tgz", @@ -1582,17 +1575,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/axios": { - "version": "1.7.7", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.7.tgz", - "integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==", - "license": "MIT", - "dependencies": { - "follow-redirects": "^1.15.6", - "form-data": "^4.0.0", - "proxy-from-env": "^1.1.0" - } - }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -1787,18 +1769,6 @@ "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==", "dev": true }, - "node_modules/combined-stream": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", - "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "license": "MIT", - "dependencies": { - "delayed-stream": "~1.0.0" - }, - "engines": { - "node": ">= 0.8" - } - }, "node_modules/commander": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/commander/-/commander-4.1.1.tgz", @@ -1960,15 +1930,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/delayed-stream": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", - "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", - "license": "MIT", - "engines": { - "node": ">=0.4.0" - } - }, "node_modules/didyoumean": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/didyoumean/-/didyoumean-1.2.2.tgz", @@ -2623,26 +2584,6 @@ "integrity": "sha512-X8cqMLLie7KsNUDSdzeN8FYK9rEt4Dt67OsG/DNGnYTSDBG4uFAJFBnUeiV+zCVAvwFy56IjM9sH51jVaEhNxw==", "dev": true }, - "node_modules/follow-redirects": { - "version": "1.15.9", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz", - "integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==", - "funding": [ - { - "type": "individual", - "url": "https://github.com/sponsors/RubenVerborgh" - } - ], - "license": "MIT", - "engines": { - "node": ">=4.0" - }, - "peerDependenciesMeta": { - "debug": { - "optional": true - } - } - }, "node_modules/for-each": { "version": "0.3.3", "resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz", @@ -2668,20 +2609,6 @@ "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/form-data": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.1.tgz", - "integrity": "sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==", - "license": "MIT", - "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "mime-types": "^2.1.12" - }, - "engines": { - "node": ">= 6" - } - }, "node_modules/fraction.js": { "version": "4.3.7", "resolved": "https://registry.npmjs.org/fraction.js/-/fraction.js-4.3.7.tgz", @@ -3608,27 +3535,6 @@ "node": ">=8.6" } }, - "node_modules/mime-db": { - "version": "1.52.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", - "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/mime-types": { - "version": "2.1.35", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", - "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", - "license": "MIT", - "dependencies": { - "mime-db": "1.52.0" - }, - "engines": { - "node": ">= 0.6" - } - }, "node_modules/minimatch": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", @@ -4174,12 +4080,6 @@ "react-is": "^16.13.1" } }, - "node_modules/proxy-from-env": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", - "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==", - "license": "MIT" - }, "node_modules/punycode": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", diff --git a/package.json b/package.json index 680f73b..d8170bf 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,6 @@ "preview": "vite preview" }, "dependencies": { - "axios": "^1.7.7", "react": "^18.3.1", "react-dom": "^18.3.1", "wouter": "^3.3.5" diff --git a/src/pages/Contact.jsx b/src/pages/Contact.jsx index 033858f..94f7d57 100644 --- a/src/pages/Contact.jsx +++ b/src/pages/Contact.jsx @@ -1,6 +1,5 @@ import { useState } from 'react'; -import axios from 'axios'; export default function Contact( ) { @@ -20,15 +19,25 @@ export default function Contact( ) { e.preventDefault(); try { - const response = await axios.post(`${import.meta.env.VITE_API_URL}/api/contact`, formData) - if(response.status == 201) { - alert("Inquiry submitted successfully!") + const response = await fetch("http://localhost:4000/api/contact", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({name, email, subject, message}) + }) + + if(!response.ok) { + throw new Error(`Response status: ${response.status}`); } + const json = await response.json() + console.log(json) + alert("Inquiry submitted successfully!") + } catch (err) { + console.error(error.message) alert("There was an error submitting the inquiry.") } - - console.log('Form submitted:', formData); };