Skip to content

Commit

Permalink
mostly finished?
Browse files Browse the repository at this point in the history
  • Loading branch information
madeline-lei committed Oct 31, 2024
1 parent e4be9e8 commit 849a715
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 15 deletions.
12 changes: 7 additions & 5 deletions backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
100 changes: 100 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
22 changes: 12 additions & 10 deletions src/pages/Contact.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import { useState } from 'react';
import axios from 'axios';

export default function Contact( ) {

Expand All @@ -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);
};
Expand Down

0 comments on commit 849a715

Please sign in to comment.