|
| 1 | +import React, { useState } from "react"; |
| 2 | +import "./Contact.css"; |
| 3 | +import msg_icon from "../../assets/msg-icon.png"; |
| 4 | +import mail_icon from "../../assets/mail-icon.png"; |
| 5 | +import phone_icon from "../../assets/phone-icon.png"; |
| 6 | +import location_icon from "../../assets/location-icon.png"; |
| 7 | +import white_arrow from "../../assets/white-arrow.png"; |
| 8 | + |
| 9 | +const Contact = () => { |
| 10 | + const [result, setResult] = useState(""); |
| 11 | + const [sending, setSending] = useState(false); |
| 12 | + |
| 13 | + const onSubmit = async (event) => { |
| 14 | + event.preventDefault(); |
| 15 | + setSending(true); |
| 16 | + setResult(""); |
| 17 | + |
| 18 | + try { |
| 19 | + const formData = new FormData(event.target); |
| 20 | + formData.append("access_key", "f6aa4535-abbe-4360-98a4-641edc5c3a26"); |
| 21 | + |
| 22 | + const response = await fetch("https://api.web3forms.com/submit", { |
| 23 | + method: "POST", |
| 24 | + body: formData, |
| 25 | + }); |
| 26 | + |
| 27 | + const data = await response.json(); |
| 28 | + if (data.success) { |
| 29 | + setResult("Success! Your message has been sent."); |
| 30 | + event.target.reset(); |
| 31 | + } else { |
| 32 | + setResult("Error: Unable to send message. Please try again later."); |
| 33 | + } |
| 34 | + } catch (err) { |
| 35 | + setResult("Error: Network or server problem."); |
| 36 | + console.error(err); |
| 37 | + } finally { |
| 38 | + setSending(false); |
| 39 | + } |
| 40 | + }; |
| 41 | + |
| 42 | + return ( |
| 43 | + <div className="contact"> |
| 44 | + <div className="contact-col"> |
| 45 | + <h3> |
| 46 | + Send us a message <img src={msg_icon} alt="message icon" /> |
| 47 | + </h3> |
| 48 | + <p> |
| 49 | + Feel free to reach out through the contact form or find our contact |
| 50 | + information below. Your feedback, questions, and suggestions are |
| 51 | + important to us as we strive to provide exceptional service to our |
| 52 | + university community. |
| 53 | + </p> |
| 54 | + <ul> |
| 55 | + <li> |
| 56 | + <img src={mail_icon} alt="mail icon" /> contact@sakibdeveloper.com |
| 57 | + </li> |
| 58 | + <li> |
| 59 | + <img src={phone_icon} alt="phone icon" /> 0123456789 |
| 60 | + </li> |
| 61 | + <li> |
| 62 | + <img src={location_icon} alt="location icon" /> Dhaka, Tajgaon, |
| 63 | + Bangladesh |
| 64 | + </li> |
| 65 | + </ul> |
| 66 | + </div> |
| 67 | + |
| 68 | + <div className="contact-col"> |
| 69 | + <form onSubmit={onSubmit}> |
| 70 | + <label htmlFor="name">Your name</label> |
| 71 | + <input |
| 72 | + id="name" |
| 73 | + type="text" |
| 74 | + name="name" |
| 75 | + placeholder="Enter your name" |
| 76 | + required |
| 77 | + /> |
| 78 | + |
| 79 | + <label htmlFor="phone">Phone Number</label> |
| 80 | + <input |
| 81 | + id="phone" |
| 82 | + type="tel" |
| 83 | + name="phone" |
| 84 | + placeholder="Enter your phone number" |
| 85 | + required |
| 86 | + /> |
| 87 | + |
| 88 | + <label htmlFor="message">Write your message here</label> |
| 89 | + <textarea |
| 90 | + id="message" |
| 91 | + name="message" |
| 92 | + rows="6" |
| 93 | + placeholder="Enter your message" |
| 94 | + required |
| 95 | + /> |
| 96 | + |
| 97 | + <button type="submit" className="dark-btn" disabled={sending}> |
| 98 | + {sending ? "Sending..." : "Submit now"}{" "} |
| 99 | + <img src={white_arrow} alt="arrow" /> |
| 100 | + </button> |
| 101 | + </form> |
| 102 | + |
| 103 | + <div |
| 104 | + role="status" |
| 105 | + aria-live="polite" |
| 106 | + style={{ marginTop: "12px", minHeight: "1.2em" }} |
| 107 | + > |
| 108 | + {result && <span>{result}</span>} |
| 109 | + </div> |
| 110 | + </div> |
| 111 | + </div> |
| 112 | + ); |
| 113 | +}; |
| 114 | + |
| 115 | +export default Contact; |
0 commit comments