import React, { FC, useState } from "react"; import Title from "./../../core/Title"; import ReactTooltip from "react-tooltip"; import { toBoolean, isCF7Loaded, isCF7Installed, getAjaxNonce, getNonce, } from "./../../Helpers"; import Icons from "../../icons"; import CForm from "../../images/cf_integration.png"; type Props = { store: any; setStore: any; }; const ContactForm7: FC = ({ store, setStore }) => { const [installed, setInstall] = useState(isCF7Installed()); const [loaded, setLoad] = useState(isCF7Loaded()); const [loader, setLoader] = useState(false); const [copy, setCopy] = useState("[easy_cloudflare_turnstile]"); const [showTooltip, setShowTooltip] = useState(false); const handleStatus = (e): void => { setStore({ ...store, integrations: { ...store.integrations, [e.target.name]: e.target.checked, }, }); }; const handlePluginInstall = (e) => { e.preventDefault(); setLoader(true); wp.ajax.send("wp_ajax_install_plugin", { data: { _ajax_nonce: getAjaxNonce(), slug: "contact-form-7", }, success() { setLoader(false); setInstall(true); }, error() { setInstall(false); }, }); }; const handlePluginActive = (e) => { e.preventDefault(); setLoader(true); wp.ajax.send("active_plugin", { data: { nonce: getNonce(), slug: "contact-form-7", }, success() { setLoader(false); setLoad(true); }, error() { setLoad(true); setLoader(false); }, }); }; const handleCopy = () => { const el = document.createElement("textarea"); el.value = copy; document.body.appendChild(el); el.select(); document.execCommand("copy"); document.body.removeChild(el); setShowTooltip(true); setTimeout(() => { setShowTooltip(false); }, 800); }; return ( <>
Contact Form Logo
<h3>Contact Form 7</h3> {!installed && (
{Icons.info_icon} Please install Contact Form 7 first!
)} {installed && !loaded && (
{Icons.info_icon} Please activate Contact Form 7 first!
)} {installed && loaded && toBoolean( store?.integrations?.cf7 && store.integrations.cf7.toString() ) && ( )}
{installed && loaded && ( )} {!installed && (
handlePluginInstall(e)}> {loader ? ( ) : ( )}
)} {installed && !loaded && (
{loader ? ( ) : null} {installed && !loaded && !loader && ( )}
)}
); }; export default ContactForm7;