import { useInput } from "../hooks/useInput";
import { send } from "emailjs-com";
export const useId = process.env.REACT_APP_USER_ID;
export const templateId = process.env.REACT_APP_TEMPLATE_ID;
export const serviceID = process.env.REACT_APP_SERVICE_ID;
function MessageForm() {
const [{ name, email, message }, onChange, reset] = useInput({
name: "",
email: "",
message: "",
});
const onSubmit = (e) => {
e.preventDefault();
send(serviceID, templateId, { name, email, message }, useId)
.then(() => {
alert("๋ฉ์ผ์ด ์ ์์ ์ผ๋ก ์ ์ก๋์ต๋๋ค.๐");
})
.catch(() => {
alert("๋ฉ์ผ ์ ์ก์ ์คํจํ์ต๋๋ค.๐");
});
reset();
};
return (
<FormBox onSubmit={onSubmit}>
<label htmlFor="name">Name</label>
<input
type="text"
name="name"
value={name}
onChange={onChange}
required
placeholder="์ฑํจ์ ์
๋ ฅํด์ฃผ์ธ์."
/>
<label htmlFor="email">Mail</label>
<input
type="text"
name="email"
value={email}
onChange={onChange}
required
placeholder="๋ฉ์ผ ์ฃผ์๋ฅผ ์
๋ ฅํด์ฃผ์ธ์."
/>
<label htmlFor="message">Message</label>
<MessageInput
name="message"
rows="10"
value={message}
onChange={onChange}
required
placeholder="๋ด์ฉ์ ์
๋ ฅํด์ฃผ์ธ์."
></MessageInput>
<SendButton type="submit">๋ฉ์ผ ๋ณด๋ด๊ธฐ</SendButton>
</FormBox>
);
}
export default React.memo(MessageForm);