"use client";
import React, { useState } from "react";
import ReCAPTCHA from "react-google-recaptcha";
import axios from "axios";
export default function ContactFloat() {
const [open, setOpen] = useState(false);
const [showChat, setShowChat] = useState(false);
const [showSocial, setShowSocial] = useState(false); // 👈 NEW: toggle social icons
/** Contact actions */
const extraIcons = [
{
href: "tel:647-722-3434",
src: "/assets/images/icons/call.png",
label: "Call",
newTab: true, // 👈 added
},
{
action: () => setShowChat(true),
src: "/assets/images/chat.png",
label: "Chat",
},
{
href: "https://www.instagram.com/elrapharehab/",
src: "/assets/images/insta.png",
label: "Instagram",
newTab: true,
},
{
href: "https://www.facebook.com/ELRaphaRehabCenter/",
src: "/assets/images/fb.png",
label: "Facebook",
newTab: true,
},
];
/** Social media list shown on Share click */
const socialIcons = [
{
href: "https://www.instagram.com/elrapharehab/",
iconClass: "icon-4",
label: "Instagram",
},
{
href: "https://www.facebook.com/ELRaphaRehabCenter/",
iconClass: "icon-7",
label: "Facebook",
},
];
return (
<>
{/* Floating Contact Buttons */}
{open && (
{extraIcons.map((icon, i) =>
icon.href ? (
) : (
)
)}
)}
{showSocial && (
{socialIcons.map((icon, i) => (
))}
)}
{showChat && setShowChat(false)} />}
>
);
}
function ChatForm({ onClose }) {
const [formData, setFormData] = useState({
username: "",
lname: "",
email: "",
phone: "",
subject: "",
message: "",
});
const [formErrors, setFormErrors] = useState({});
const [captchaToken, setCaptchaToken] = useState(null);
const [alert, setAlert] = useState({ show: false, type: "", message: "" });
const handleChange = (e) => {
const { name, value } = e.target;
setFormData((prev) => ({ ...prev, [name]: value }));
};
const handleCaptchaChange = (token) => {
setCaptchaToken(token);
};
const handleSubmit = async (e) => {
e.preventDefault();
const errors = {};
if (!formData.username.trim()) errors.username = "First Name is required.";
if (!formData.lname.trim()) errors.lname = "Last Name is required.";
if (!formData.email.trim()) errors.email = "Email is required.";
if (!formData.phone.trim()) errors.phone = "Phone is required.";
if (!formData.subject.trim()) errors.subject = "Subject is required.";
if (!formData.message.trim()) errors.message = "Message is required.";
if (!captchaToken) errors.captcha = "Please verify the CAPTCHA.";
setFormErrors(errors);
if (Object.keys(errors).length > 0) return;
const emailData = {
...formData,
message: `Subject: ${formData.subject}
Message: ${formData.message}`,
to: "bloor@rapharehab.ca",
senderName: "Rapha Rehab Chat Form",
recaptchaToken: captchaToken,
};
try {
const res = await axios.post("https://mailserver.metatronnest.com/send", emailData, {
headers: { "Content-Type": "application/json" },
});
setAlert({
show: true,
type: "success",
message: res?.data?.message || "Message sent successfully!",
});
setFormData({
username: "",
lname: "",
email: "",
phone: "",
subject: "",
message: "",
});
setCaptchaToken(null);
setFormErrors({});
} catch (error) {
setAlert({
show: true,
type: "danger",
message: "Failed to send message. Please try again later.",
});
}
};
return (
Chat with Us
{alert.show && (
{alert.message}
)}
);
}