Skip to content

Commit c2b4946

Browse files
Merge pull request #63 from codeXsit/codex-4-contact
feat: add form functionality
2 parents 76d0792 + 9c0f9b4 commit c2b4946

File tree

2 files changed

+56
-5
lines changed

2 files changed

+56
-5
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@ dist-ssr
2525

2626
# package resolution config
2727
package-lock.json
28-
yarn.lock
28+
yarn.lock
29+
30+
.env

src/pages/Contact/index.jsx

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,49 @@
1+
import { useState } from "react";
12
import PageTransition from "@/components/PageTransition";
23

34
function Contact() {
5+
const [result, setResult] = useState("");
6+
const [showBanner, setShowBanner] = useState(false);
7+
8+
const onSubmit = async (event) => {
9+
event.preventDefault();
10+
setResult("Sending....");
11+
setShowBanner(true);
12+
13+
const formData = new FormData(event.target);
14+
formData.append("access_key", import.meta.env.VITE_EMAIL_API_KEY);
15+
16+
const response = await fetch("https://api.web3forms.com/submit", {
17+
method: "POST",
18+
body: formData,
19+
});
20+
21+
const data = await response.json();
22+
23+
if (data.success) {
24+
setResult("Form Submitted Successfully");
25+
event.target.reset();
26+
} else {
27+
setResult(data.message);
28+
}
29+
30+
setTimeout(() => {
31+
setShowBanner(false);
32+
}, 3000);
33+
};
34+
435
return (
536
<PageTransition>
637
<div className="bg-background-dark h-[calc(100vh-4.6rem)]">
38+
<div
39+
className={`${
40+
showBanner
41+
? "opacity-100 translate-y-0"
42+
: "opacity-0 translate-y-[-20px]"
43+
} fixed top-5 right-5 max-w-xs w-full p-4 bg-primary text-text-light rounded-lg shadow-lg transition-all duration-300 ease-in-out z-50`}
44+
>
45+
{result}
46+
</div>
747
<div className="mt-8 flex gap-x-8 overflow-hidden">
848
<span className="text-outlined uppercase text-8xl font-black text-transparent whitespace-nowrap">
949
Contact Us
@@ -19,35 +59,44 @@ function Contact() {
1959
</span>
2060
</div>
2161
<div className="mx-10 mt-16">
22-
<form>
62+
<form onSubmit={onSubmit}>
2363
<div className="m-auto flex flex-col p-8 bg-background-elevation rounded-lg shadow-lg px-12 py-8 max-w-2xl">
2464
<span className=" text-secondary-light uppercase tracking-widest m-auto mb-3">
2565
Drop us a message
2666
</span>
67+
<input
68+
type="hidden"
69+
name="subject"
70+
value="New message from Codex Website"
71+
/>
2772
<input
2873
type="text"
74+
name="name"
2975
placeholder="Name"
3076
className="bg-background-elevation py-2 my-3 border-b-2 border-secondary-light text-text-light outline-none"
3177
required
3278
/>
3379
<input
3480
type="email"
81+
name="email"
3582
placeholder="Email"
3683
className="bg-background-elevation py-2 my-3 border-b-2 border-secondary-light text-text-light outline-none"
3784
required
3885
/>
3986
<textarea
4087
placeholder="Enter your message..."
88+
name="message"
4189
rows="4"
4290
className="bg-background-elevation py-2 my-3 border-b-2 border-secondary-light text-text-light outline-none"
4391
required
4492
/>
4593
<div className=" flex justify-end mt-4">
46-
<input
94+
<button
4795
type="submit"
48-
value="send"
4996
className="bg-transparent rounded-full border-2 border-secondary-light px-8 py-2 text-secondary-light cursor-pointer"
50-
/>
97+
>
98+
send
99+
</button>
51100
</div>
52101
</div>
53102
</form>

0 commit comments

Comments
 (0)