Skip to content

Commit 442ef41

Browse files
committed
Fixed bug in contact component
Changed all field values to required Added regex to make sure a valid email address is provided before sending the message
1 parent 25b6390 commit 442ef41

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/components/Contact.jsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,19 @@ const Contact = () => {
3030
[name]: value,
3131
});
3232
};
33+
const isValidEmail = (email) => {
34+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
35+
return emailRegex.test(email);
36+
};
3337

3438
const handleSubmit = (e) => {
3539
e.preventDefault();
40+
41+
if(!isValidEmail(form.email)){
42+
alert("Please enter a valid email address.");
43+
return;
44+
}
45+
3646
setLoading(true);
3747

3848
emailjs
@@ -93,6 +103,7 @@ const Contact = () => {
93103
onChange={handleChange}
94104
placeholder="What's your good name?"
95105
className='bg-tertiary py-4 px-6 placeholder:text-secondary text-white rounded-lg outline-none border-none font-medium'
106+
required
96107
/>
97108
</label>
98109
<label className='flex flex-col'>
@@ -104,6 +115,7 @@ const Contact = () => {
104115
onChange={handleChange}
105116
placeholder="What's your web address?"
106117
className='bg-tertiary py-4 px-6 placeholder:text-secondary text-white rounded-lg outline-none border-none font-medium'
118+
required
107119
/>
108120
</label>
109121
<label className='flex flex-col'>
@@ -115,6 +127,7 @@ const Contact = () => {
115127
onChange={handleChange}
116128
placeholder='What you want to say?'
117129
className='bg-tertiary py-4 px-6 placeholder:text-secondary text-white rounded-lg outline-none border-none font-medium'
130+
required
118131
/>
119132
</label>
120133

@@ -137,4 +150,4 @@ const Contact = () => {
137150
);
138151
};
139152

140-
export default SectionWrapper(Contact, "contact");
153+
export default SectionWrapper(Contact, "contact");

0 commit comments

Comments
 (0)