Skip to content

Commit 2230966

Browse files
authored
Merge pull request said7388#43 from kansaok/fix-send-mail
[FIX] - 2024-09-02
2 parents d98f845 + 62801df commit 2230966

File tree

2 files changed

+24
-32
lines changed

2 files changed

+24
-32
lines changed

.env.example

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ NEXT_PUBLIC_EMAILJS_PUBLIC_KEY =
44
NEXT_PUBLIC_GTM =
55
NEXT_PUBLIC_APP_URL = "http://127.0.0.1:3000"
66
NEXT_PUBLIC_RECAPTCHA_SECRET_KEY =
7-
NEXT_PUBLIC_RECAPTCHA_SITE_KEY =
7+
NEXT_PUBLIC_RECAPTCHA_SITE_KEY =
8+
TELEGRAM_BOT_TOKEN =
9+
TELEGRAM_CHAT_ID =

app/components/homepage/contact/contact-without-captcha.jsx

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
"use client";
22
// @flow strict
3-
import { isValidEmail } from '@/utils/check-email';
4-
import axios from 'axios';
5-
import { useState } from 'react';
3+
import { isValidEmail } from "@/utils/check-email";
4+
import axios from "axios";
5+
import { useState } from "react";
66
import { TbMailForward } from "react-icons/tb";
7-
import { toast } from 'react-toastify';
7+
import { toast } from "react-toastify";
8+
import emailjs from "@emailjs/browser";
89

910
function ContactWithoutCaptcha() {
1011
const [error, setError] = useState({ email: false, required: false });
1112
const [userInput, setUserInput] = useState({
12-
name: '',
13-
email: '',
14-
message: '',
13+
name: "",
14+
email: "",
15+
message: "",
1516
});
1617

1718
const checkRequired = () => {
@@ -29,7 +30,7 @@ function ContactWithoutCaptcha() {
2930
return;
3031
} else {
3132
setError({ ...error, required: false });
32-
};
33+
}
3334

3435
const serviceID = process.env.NEXT_PUBLIC_EMAILJS_SERVICE_ID;
3536
const templateID = process.env.NEXT_PUBLIC_EMAILJS_TEMPLATE_ID;
@@ -38,29 +39,24 @@ function ContactWithoutCaptcha() {
3839
try {
3940
const res = await emailjs.send(serviceID, templateID, userInput, options);
4041
const teleRes = await axios.post(`${process.env.NEXT_PUBLIC_APP_URL}/api/contact`, userInput);
41-
4242
if (res.status === 200 || teleRes.status === 200) {
43-
toast.success('Message sent successfully!');
43+
toast.success("Message sent successfully!");
4444
setUserInput({
45-
name: '',
46-
email: '',
47-
message: '',
45+
name: "",
46+
email: "",
47+
message: "",
4848
});
49-
};
49+
}
5050
} catch (error) {
5151
toast.error(error?.text || error);
52-
};
52+
}
5353
};
5454

5555
return (
5656
<div className="">
57-
<p className="font-medium mb-5 text-[#16f2b3] text-xl uppercase">
58-
Contact with me
59-
</p>
57+
<p className="font-medium mb-5 text-[#16f2b3] text-xl uppercase">Contact with me</p>
6058
<div className="max-w-3xl text-white rounded-lg border border-[#464c6a] p-3 lg:p-5">
61-
<p className="text-sm text-[#d3d8e8]">
62-
{"If you have any questions or concerns, please don't hesitate to contact me. I am open to any work opportunities that align with my skills and interests."}
63-
</p>
59+
<p className="text-sm text-[#d3d8e8]">{"If you have any questions or concerns, please don't hesitate to contact me. I am open to any work opportunities that align with my skills and interests."}</p>
6460
<div className="mt-6 flex flex-col gap-4">
6561
<div className="flex flex-col gap-2">
6662
<label className="text-base">Your Name: </label>
@@ -89,9 +85,7 @@ function ContactWithoutCaptcha() {
8985
setError({ ...error, email: !isValidEmail(userInput.email) });
9086
}}
9187
/>
92-
{error.email &&
93-
<p className="text-sm text-red-400">Please provide a valid email!</p>
94-
}
88+
{error.email && <p className="text-sm text-red-400">Please provide a valid email!</p>}
9589
</div>
9690

9791
<div className="flex flex-col gap-2">
@@ -108,11 +102,7 @@ function ContactWithoutCaptcha() {
108102
/>
109103
</div>
110104
<div className="flex flex-col items-center gap-2">
111-
{error.required &&
112-
<p className="text-sm text-red-400">
113-
Email and Message are required!
114-
</p>
115-
}
105+
{error.required && <p className="text-sm text-red-400">Email and Message are required!</p>}
116106
<button
117107
className="flex items-center gap-1 hover:gap-3 rounded-full bg-gradient-to-r from-pink-500 to-violet-600 px-5 md:px-12 py-2.5 md:py-3 text-center text-xs md:text-sm font-medium uppercase tracking-wider text-white no-underline transition-all duration-200 ease-out hover:text-white hover:no-underline md:font-semibold"
118108
role="button"
@@ -126,6 +116,6 @@ function ContactWithoutCaptcha() {
126116
</div>
127117
</div>
128118
);
129-
};
119+
}
130120

131-
export default ContactWithoutCaptcha;
121+
export default ContactWithoutCaptcha;

0 commit comments

Comments
 (0)