Skip to content

Commit ae9227b

Browse files
committed
introduce contact form
1 parent ac1a850 commit ae9227b

File tree

6 files changed

+150
-3
lines changed

6 files changed

+150
-3
lines changed

package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"preview": "vite preview"
1111
},
1212
"dependencies": {
13+
"@emailjs/browser": "^4.4.1",
1314
"react": "^19.0.0",
1415
"react-dom": "^19.0.0",
1516
"react-router-dom": "^7.3.0"

src/pages/Contact.jsx

Lines changed: 96 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,100 @@
1-
function Contact(){
1+
import React, { useState } from "react";
2+
import emailjs from "@emailjs/browser";
3+
import "../styles/Contact.css";
4+
5+
function Contact() {
6+
const [formData, setFormData] = useState({ name: "", email: "", message: "" });
7+
const [isSent, setIsSent] = useState(false);
8+
const [isLoading, setIsLoading] = useState(false);
9+
10+
const handleChange = (e) => {
11+
setFormData({ ...formData, [e.target.name]: e.target.value });
12+
};
13+
14+
const sendEmail = (e) => {
15+
e.preventDefault();
16+
setIsLoading(true);
17+
18+
const templateParams = {
19+
from_name: formData.name,
20+
from_email: formData.email,
21+
to_name: "Kodet Admin",
22+
message: formData.message,
23+
};
24+
25+
emailjs
26+
.send(
27+
"service_new", // Replace with your actual service ID
28+
"template_b0a3rji", // Replace with your actual template ID
29+
templateParams,
30+
"aWHCjDK-7vGvGOKcC" // Replace with your actual public key
31+
)
32+
.then(
33+
() => {
34+
setIsSent(true);
35+
setIsLoading(false);
36+
setFormData({ name: "", email: "", message: "" });
37+
},
38+
(error) => {
39+
console.error("Email sending failed:", error);
40+
setIsLoading(false);
41+
}
42+
);
43+
};
44+
245
return (
346
<>
47+
<div className="about-container">
48+
<div className="about-title">
49+
<h1 className="text-center">Get in touch!</h1>
50+
</div>
51+
</div>
52+
<div className="contact">
53+
<form onSubmit={sendEmail}>
54+
<h2>Contact Form</h2>
55+
<div className="input-box">
56+
<label htmlFor="name">Full Name</label>
57+
<input
58+
type="text"
59+
name="name"
60+
className="field"
61+
placeholder="Enter your name"
62+
required
63+
value={formData.name}
64+
onChange={handleChange}
65+
/>
66+
</div>
67+
<div className="input-box">
68+
<label htmlFor="email">Email Address</label>
69+
<input
70+
type="email"
71+
name="email"
72+
className="field"
73+
placeholder="Enter your email"
74+
required
75+
value={formData.email}
76+
onChange={handleChange}
77+
/>
78+
</div>
79+
<div className="input-box">
80+
<label htmlFor="message">Your Message</label>
81+
<textarea
82+
name="message"
83+
className="field mess"
84+
placeholder="Enter your message"
85+
required
86+
value={formData.message}
87+
onChange={handleChange}
88+
></textarea>
89+
</div>
90+
<button type="submit" disabled={isLoading}>
91+
{isLoading ? "Sending..." : "Send Message"}
92+
</button>
93+
{isSent && <p className="success-message">Message sent successfully!</p>}
94+
</form>
95+
</div>
496
</>
5-
)
97+
);
698
}
7-
export default Contact;
99+
100+
export default Contact;

src/styles/Card.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
text-align: center;
2222
/* border-radius: 40px; */
2323
padding-bottom: 15px;
24+
padding: 10px;
2425
height: 100%;
2526
}
2627

src/styles/Contact.css

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
.contact{
2+
display: flex;
3+
justify-content: center;
4+
align-items: center;
5+
min-height: 100vh;
6+
}
7+
.contact form {
8+
border: 1px dashed #000;
9+
max-width: 600px;
10+
width: 100%;
11+
background-color: #fff;
12+
padding: 25px 25px 30px;
13+
border-radius: 8px;
14+
box-shadow: 0 0 10px rgba (0,0,0,.1);
15+
color: #333;
16+
margin: 25px;
17+
}
18+
.contact form h2{
19+
font-size: 30px;
20+
text-align: center;
21+
}
22+
.contact form .input-box{
23+
margin-top: 20px;
24+
}
25+
.field{
26+
width: 100%;
27+
height: 50px;
28+
background-color: transparent;
29+
border: 2px solid #ddd;
30+
outline: none;
31+
border-radius: 6px;
32+
padding: 15px;
33+
font-size: 16px;
34+
color: #333;
35+
margin-top: 8px;
36+
}
37+
.mess{
38+
height: 200px;
39+
resize: none;
40+
}

src/sub_components/Card.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ function Card({ img,title, label, text, remark, button_text }) {
88
<img src={img || "https://avatars.githubusercontent.com/u/111997815?v=4"} alt="Card Image" />
99
<div className="container">
1010
<h2>{title}</h2>
11+
<br/>
1112
<p className="title">{label}</p>
13+
<br/>
1214
<p>{text}</p>
1315
<br/>
1416
{/* <p>{remark}</p> */}

0 commit comments

Comments
 (0)