-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContactSection.jsx
More file actions
94 lines (88 loc) · 2.67 KB
/
ContactSection.jsx
File metadata and controls
94 lines (88 loc) · 2.67 KB
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
import styles from "./ContactSection.module.css";
import { useState } from "react";
import { TextField } from "@mui/material";
import { Button } from "@mui/material";
import InputAdornment from "@mui/material/InputAdornment";
import AccountCircle from "@mui/icons-material/AccountCircle";
export default function ContactSection() {
const template = process.env.REACT_APP_EMAILJS_TEMPLATE;
const publicKey = process.env.REACT_APP_EMAILJS_PUBLICKEY;
const serviceId = process.env.REACT_APP_EMAILJS_SERVICEID;
const [values, setValues] = useState({ name: "", subject: "", message: "" });
const handleSubmit = () => {
if (values.name == "" || values.subject == "" || values.message == "") {
alert("Please fill in your name, the subject, and message content!");
return;
}
emailjs.send(serviceId, template, values, publicKey).then(
(result) => {
alert("Message Sent Successfully :)");
console.log(result);
},
(error) => {
alert(
"We Ran Into An Error Sending Your Message. Please Try Again Later!",
);
console.log(error.text);
},
);
};
return (
<div className={styles.container}>
<h2 className={styles.header}>Contact Me:</h2>
<div className={styles.textInputWrapper}>
<TextField
name="name"
id="outlined-basic-name"
className="form-control"
label="Name"
fullWidth
variant="outlined"
onChange={(e) => setValues((v) => ({ ...v, name: e.target.value }))}
slotProps={{
input: {
startAdornment: (
<InputAdornment position="start">
<AccountCircle />
</InputAdornment>
),
},
}}
/>
<TextField
id="outlined-basic-subject"
className="form-control"
label="Subject"
fullWidth
variant="outlined"
onChange={(e) =>
setValues((v) => ({ ...v, subject: e.target.value }))
}
/>
</div>
<div className={styles.textInputWrapper}>
<TextField
id="outlined-multiline-flexible"
className="form-control"
label="Message"
multiline
fullWidth
maxRows={8}
minRows={4}
onChange={(e) =>
setValues((v) => ({ ...v, message: e.target.value }))
}
/>
</div>
<div className={styles.buttonWrapper}>
<Button
variant="contained"
style={{ width: "95%" }}
onClick={handleSubmit}
>
Send Message
</Button>
</div>
</div>
);
}