-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #275 from Isha1233/Isha_contributer
Contact us frontend with email functionality
- Loading branch information
Showing
12 changed files
with
269 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
const contactSchema = new mongoose.Schema({ | ||
name: { type: String, required: true }, | ||
email: { type: String, required: true }, | ||
message: { type: String, required: true }, | ||
}); | ||
|
||
const Contact = mongoose.model('Contact', contactSchema); | ||
|
||
module.exports = Contact; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const express = require('express'); | ||
const { saveContactMessage } = require('../controllers/Auth'); | ||
const router = express.Router(); | ||
|
||
router.post('/', saveContactMessage); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
import React, { useRef, useState } from "react"; | ||
import { motion } from "framer-motion"; | ||
import emailjs from "@emailjs/browser"; | ||
import axios from "axios"; | ||
|
||
|
||
const Contact = () => { | ||
const formRef = useRef(); | ||
const [form, setForm] = useState({ | ||
name: "", | ||
email: "", | ||
message: "", | ||
}); | ||
|
||
const [loading, setLoading] = useState(false); | ||
|
||
const handleChange = (e) => { | ||
const { target } = e; | ||
const { name, value } = target; | ||
|
||
setForm({ | ||
...form, | ||
[name]: value, | ||
}); | ||
}; | ||
|
||
const handleEmailSubmit = async (e) => { | ||
e.preventDefault(); | ||
setLoading(true); | ||
|
||
try { | ||
await emailjs.send( | ||
'process.env.SERVICE_ID',//write service id here | ||
'process.env.TEMPLETS_ID',//write templet id here | ||
{ | ||
from_name: form.name, | ||
to_name: "FoodiesWeb", | ||
from_email: form.email, | ||
to_email: "[email protected]", | ||
message: form.message, | ||
}, | ||
'process.env.PUBLIC_KEY' //write public_key here | ||
); | ||
|
||
|
||
|
||
|
||
setLoading(false); | ||
alert("Thank you. I will get back to you as soon as possible."); | ||
|
||
setForm({ | ||
name: "", | ||
email: "", | ||
message: "", | ||
}); | ||
} catch (error) { | ||
setLoading(false); | ||
console.error(error); | ||
|
||
alert("Sorry, something went wrong while sending your message. Please try again later."); | ||
} | ||
}; | ||
const handleSaveToDB = async (e) => { | ||
e.preventDefault(); | ||
setLoading(true); | ||
|
||
try { | ||
// Save to MongoDB | ||
await axios.post('http://localhost:3000/api/contact', form); | ||
|
||
setLoading(false); | ||
alert("Your message has been saved to the database."); | ||
|
||
setForm({ | ||
name: "", | ||
email: "", | ||
message: "", | ||
}); | ||
} catch (error) { | ||
setLoading(false); | ||
console.error(error); | ||
alert("Sorry, something went wrong while saving your message to the database. Please try again later."); | ||
} | ||
}; | ||
|
||
return ( | ||
<div className="absolute overflow-hidden w-screen h-screen bg-gradient-to-t from-blue-950 via-blue-950 to-gray-950 "> | ||
<p className="text-white font-medium text-4xl pl-10 pt-8">Get in touch</p> | ||
<h3 className="text-white font-medium text-4xl pl-20 pt-3">Contact Us.</h3> | ||
<div | ||
className={`xl:mt-12 pl-64 flex xl:flex-row flex-col-reverse gap-10 overflow-hidden `} | ||
> | ||
|
||
<div className="absolute -bottom-32 -left-40 w-80 h-80 border-4 rounded-full border-opacity-30 border-t-8"></div> | ||
<div className="absolute -bottom-40 -left-20 w-80 h-80 border-4 rounded-full border-opacity-30 border-t-8"></div> | ||
<div className="absolute -top-40 -right-0 w-80 h-80 border-4 rounded-full border-opacity-30 border-t-8"></div> | ||
<div className="absolute -top-20 -right-20 w-80 h-80 border-4 rounded-full border-opacity-30 border-t-8"></div> | ||
|
||
|
||
<div className="ml-20 w-96 h-[20%] px-7 text-black shadow-blue-900 shadow3xl bg-blue-900 bg-gradient-to-t from-gray-900 rounded-3xl"> | ||
|
||
<form | ||
ref={formRef} | ||
onSubmit={handleEmailSubmit} | ||
className='my-10 flex flex-col gap-8' | ||
> | ||
<label className='flex flex-col '> | ||
<span className=' font-medium mb-2'>Your Name</span> | ||
<input | ||
type='text' | ||
name='name' | ||
value={form.name} | ||
onChange={handleChange} | ||
placeholder="What's your good name?" | ||
className='bg-tertiary py-3 px-6 placeholder:text-secondary rounded-lg outline-none border-none font-medium ' | ||
/> | ||
</label> | ||
<label className='flex flex-col'> | ||
<span className=' font-medium mb-2'>Your email</span> | ||
<input | ||
type='email' | ||
name='email' | ||
value={form.email} | ||
onChange={handleChange} | ||
placeholder="What's your web address?" | ||
className='bg-tertiary py-3 px-6 placeholder:text-secondary rounded-lg outline-none border-none font-medium ' | ||
/> | ||
</label> | ||
<label className='flex flex-col'> | ||
<span className=' font-medium mb-2'>Your Message</span> | ||
<textarea | ||
rows={5} | ||
name='message' | ||
value={form.message} | ||
onChange={handleChange} | ||
placeholder='What you want to say?' | ||
className='bg-tertiary py-3 px-6 placeholder:text-secondary text-white rounded-lg outline-none border-none font-medium bg-gradient-to-t from-blue-950 via-blue-950 to-gray-900' | ||
/> | ||
</label> | ||
|
||
<div className='flex gap-8'> | ||
<button | ||
type='submit' | ||
className='bg-tertiary py-3 px-8 rounded-xl outline-none w-fit text-white font-bold shadow-md shadow-primary bg-cyan-700 hover:scale-[1.1]' | ||
> | ||
{loading ? "Sending..." : "Send_Mail"} | ||
</button> | ||
<button | ||
type='button' | ||
onClick={handleSaveToDB} | ||
className='bg-tertiary py-3 px-8 rounded-xl outline-none w-fit text-white font-bold shadow-md shadow-primary bg-cyan-800 hover:scale-[1.1]' | ||
> | ||
{loading ? "Saving..." : "Submit"} | ||
</button> | ||
</div> | ||
</form></div> | ||
<div className=" -mt-10 ml-10 "> | ||
<img src="/i9.png" className="w-full h-full"/> | ||
</div> | ||
|
||
</div><div className="p-10"></div> | ||
|
||
</div> | ||
); | ||
}; | ||
|
||
export default Contact; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters