-
Notifications
You must be signed in to change notification settings - Fork 903
/
Copy pathContact.jsx
138 lines (124 loc) · 4.08 KB
/
Contact.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import React, { useRef, useState } from "react";
import { motion } from "framer-motion";
import emailjs from "@emailjs/browser";
import { styles } from "../styles";
import { EarthCanvas } from "./canvas";
import { SectionWrapper } from "../hoc";
import { slideIn } from "../utils/motion";
const Contact = () => {
const formRef = useRef();
const [form, setForm] = useState({
name: "",
email: "",
message: "",
});
const [loading, setLoading] = useState(false);
const handleChange = (e) => {
const { target } = e;
const { name, value } = target;
setForm({
...form,
[name]: value,
});
};
const handleSubmit = (e) => {
e.preventDefault();
setLoading(true);
emailjs
.send(
import.meta.env.VITE_APP_EMAILJS_SERVICE_ID,
import.meta.env.VITE_APP_EMAILJS_TEMPLATE_ID,
{
from_name: form.name,
to_name: "Web Dev Freelancer",
from_email: form.email,
to_email: "unknownbot411@gmail.com",
message: form.message,
},
import.meta.env.VITE_APP_EMAILJS_PUBLIC_KEY
)
.then(
() => {
setLoading(false);
alert("Thank you. I will get back to you as soon as possible.");
setForm({
name: "",
email: "",
message: "",
});
},
(error) => {
setLoading(false);
console.error(error);
alert("Ahh, something went wrong. Please try again.");
}
);
};
return (
<>
<div
className={`xl:mt-12 flex xl:flex-row flex-col-reverse gap-10 overflow-hidden`}
>
<motion.div
variants={slideIn("left", "tween", 0.2, 1)}
className='flex-[0.75] bg-black-100 p-8 rounded-2xl'
>
<p className={styles.sectionSubText}>Get in touch</p>
<h3 className={styles.sectionHeadText}>Contact.</h3>
<form
ref={formRef}
onSubmit={handleSubmit}
className='mt-12 flex flex-col gap-8'
>
<label className='flex flex-col'>
<span className='text-white font-medium mb-4'>Your Name</span>
<input
type='text'
name='name'
value={form.name}
onChange={handleChange}
placeholder="What's your good name?"
className='bg-tertiary py-4 px-6 placeholder:text-secondary text-white rounded-lg outline-none border-none font-medium'
/>
</label>
<label className='flex flex-col'>
<span className='text-white font-medium mb-4'>Your email</span>
<input
type='email'
name='email'
value={form.email}
onChange={handleChange}
placeholder="What's your web address?"
className='bg-tertiary py-4 px-6 placeholder:text-secondary text-white rounded-lg outline-none border-none font-medium'
/>
</label>
<label className='flex flex-col'>
<span className='text-white font-medium mb-4'>Your Message</span>
<textarea
rows={7}
name='message'
value={form.message}
onChange={handleChange}
placeholder='What you want to say?'
className='bg-tertiary py-4 px-6 placeholder:text-secondary text-white rounded-lg outline-none border-none font-medium'
/>
</label>
<button
type='submit'
className='bg-tertiary py-3 px-8 rounded-xl outline-none w-fit text-white font-bold shadow-md shadow-primary'
>
{loading ? "Sending..." : "Send"}
</button>
</form>
</motion.div>
<motion.div
variants={slideIn("right", "tween", 0.2, 1)}
className='xl:flex-1 xl:h-auto md:h-[550px] h-[350px]'
>
<EarthCanvas />
</motion.div>
</div>
</>
);
};
export default SectionWrapper(Contact, "contact");