Skip to content

Commit 821a05b

Browse files
authored
Merge pull request #23 from MickyMik/dev
Update Contact.tsx adding emailjs
2 parents 25081b2 + 960af6d commit 821a05b

File tree

1 file changed

+32
-19
lines changed

1 file changed

+32
-19
lines changed

src/components/Contact.tsx

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { z } from "zod";
88
import { useForm } from "react-hook-form";
99
import { zodResolver } from "@hookform/resolvers/zod";
1010
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form";
11+
import emailjs from "emailjs-com";
1112

1213
// Form validation schema
1314
const contactFormSchema = z.object({
@@ -31,7 +32,7 @@ type ContactFormData = z.infer<typeof contactFormSchema>;
3132

3233
const Contact = () => {
3334
const { toast } = useToast();
34-
35+
3536
const form = useForm<ContactFormData>({
3637
resolver: zodResolver(contactFormSchema),
3738
defaultValues: {
@@ -44,8 +45,8 @@ const Contact = () => {
4445

4546
const handleSubmit = async (data: ContactFormData) => {
4647
try {
47-
// Rate limiting check (simple client-side implementation)
48-
const lastSubmission = localStorage.getItem('lastContactSubmission');
48+
// Empêche spam en vérifiant le délai // Rate limiting check (simple client-side implementation)
49+
const lastSubmission = localStorage.getItem("lastContactSubmission");
4950
const now = Date.now();
5051
if (lastSubmission && now - parseInt(lastSubmission) < 60000) {
5152
toast({
@@ -64,15 +65,28 @@ const Contact = () => {
6465
message: data.message.trim()
6566
};
6667

68+
// Appel EmailJS
69+
await emailjs.send(
70+
"service_t6so8r5", // Remplace par ton Service ID
71+
"template_meqf9bp", // Remplace par ton Template ID
72+
{
73+
name: data.name,
74+
email: data.email,
75+
subject: data.subject,
76+
message: data.message
77+
},
78+
"IobH6oMwMiIETnEVh" // Remplace par ta clé publique
79+
);
80+
6781
// Store submission timestamp
68-
localStorage.setItem('lastContactSubmission', now.toString());
69-
70-
// Here you would typically send the form data to your backend
82+
localStorage.setItem("lastContactSubmission", now.toString());
83+
84+
// Here you would typically send the form data to your backend
7185
toast({
7286
title: "Message sent!",
73-
description: "Thank you for your message. I'll get back to you soon.",
87+
description: "Thank you for your message. I'll get back to you soon."
7488
});
75-
89+
7690
form.reset();
7791
} catch (error) {
7892
toast({
@@ -172,7 +186,7 @@ const Contact = () => {
172186
)}
173187
/>
174188
</div>
175-
189+
176190
<FormField
177191
control={form.control}
178192
name="subject"
@@ -186,29 +200,29 @@ const Contact = () => {
186200
</FormItem>
187201
)}
188202
/>
189-
203+
190204
<FormField
191205
control={form.control}
192206
name="message"
193207
render={({ field }) => (
194208
<FormItem>
195209
<FormLabel>Message</FormLabel>
196210
<FormControl>
197-
<Textarea
211+
<Textarea
198212
rows={6}
199213
placeholder="Tell me about your project, challenges you're facing, or how we can work together..."
200-
{...field}
214+
{...field}
201215
/>
202216
</FormControl>
203217
<FormMessage />
204218
</FormItem>
205219
)}
206220
/>
207-
208-
<Button
209-
type="submit"
210-
variant="contact"
211-
size="lg"
221+
222+
<Button
223+
type="submit"
224+
variant="contact"
225+
size="lg"
212226
className="w-full"
213227
disabled={form.formState.isSubmitting}
214228
>
@@ -251,13 +265,12 @@ const Contact = () => {
251265
I'm passionate about solving complex data challenges and would love to hear about your project.
252266
Whether you need consultation, development, or just want to discuss ideas, I'm here to help.
253267
</p>
254-
255268
<div className="flex space-x-4">
256269
{socialLinks.map((social, index) => (
257270
<a
258271
key={index}
259272
href={social.href}
260-
className={`w-10 h-10 bg-white/20 rounded-full flex items-center justify-center text-white hover:bg-white hover:text-navy transition-all transform hover:scale-110 ${social.color}`}
273+
className={w-10 h-10 bg-white/20 rounded-full flex items-center justify-center text-white hover:bg-white hover:text-navy transition-all transform hover:scale-110 ${social.color}}
261274
aria-label={social.label}
262275
>
263276
<social.icon className="w-5 h-5" />

0 commit comments

Comments
 (0)