import React, { FC, useState, useEffect } from "react"; import { toBoolean, isWpDiscuzInstalled, isWpDiscuzLoaded, getNonce, getAjaxNonce, } from "./../../Helpers"; import Title from "./../../core/Title"; import Icons from "../../icons"; import WpDiscuzImage from "../../images/wpdiscuz.svg"; type Props = { store: any; setStore: any; }; const wpDiscuz: FC = ({ store, setStore }) => { const [installed, setInstall] = useState( isWpDiscuzInstalled() ); const [loaded, setLoad] = useState(isWpDiscuzLoaded()); const [loader, setLoader] = 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: "wpdiscuz", }, success() { setLoader(false); setInstall(true); }, error() { setInstall(false); }, }); }; const handlePluginActive = (e) => { e.preventDefault(); setLoader(true); wp.ajax.send("active_plugin", { data: { nonce: getNonce(), slug: "wpdiscuz", }, success() { setLoader(false); setLoad(true); }, error(err) { console.log(err); setLoad(true); setLoader(false); }, }); }; return ( <>
WpDiscuz Logo
<h3>wp Discuz</h3> <span>New</span> {!installed && (
{Icons.info_icon} Please install wp Discuz Form first!
)} {installed && !loaded && (
{Icons.info_icon} Please activate wp Discuz Form first!
)} {installed && loaded && toBoolean( store?.integrations?.wpdiscuz && store.integrations.wpdiscuz.toString() ) &&

Turnstile is enabled

}
{installed && loaded && ( )} {!installed && (
handlePluginInstall(e)}> {loader ? ( ) : ( )}
)} {installed && !loaded && (
{loader ? ( ) : null} {installed && !loaded && !loader && ( )}
)}
); }; export default wpDiscuz;