| 1 |
import { debounce } from 'throttle-debounce'; |
| 2 |
|
| 3 |
import apiFetch from '@wordpress/api-fetch'; |
| 4 |
import { ExternalLink, PanelBody, TextControl } from '@wordpress/components'; |
| 5 |
import { useState } from '@wordpress/element'; |
| 6 |
import { __ } from '@wordpress/i18n'; |
| 7 |
|
| 8 |
const { GHOSTKIT } = window; |
| 9 |
|
| 10 |
const initialOpen = |
| 11 |
!GHOSTKIT.googleReCaptchaAPISiteKey || |
| 12 |
!GHOSTKIT.googleReCaptchaAPISecretKey; |
| 13 |
|
| 14 |
const saveAPIKeys = debounce(1500, (newSiteKey, newSecretKey) => { |
| 15 |
apiFetch({ |
| 16 |
path: '/ghostkit/v1/update_google_recaptcha_keys', |
| 17 |
method: 'POST', |
| 18 |
data: { |
| 19 |
site_key: newSiteKey, |
| 20 |
secret_key: newSecretKey, |
| 21 |
}, |
| 22 |
}); |
| 23 |
}); |
| 24 |
|
| 25 |
/** |
| 26 |
* Block Settings Class. |
| 27 |
*/ |
| 28 |
export default function BlockSettings() { |
| 29 |
const [apiSiteKey, setApiSiteKey] = useState( |
| 30 |
GHOSTKIT.googleReCaptchaAPISiteKey |
| 31 |
); |
| 32 |
const [apiSecretKey, setApiSecretKey] = useState( |
| 33 |
GHOSTKIT.googleReCaptchaAPISecretKey |
| 34 |
); |
| 35 |
|
| 36 |
return ( |
| 37 |
<PanelBody |
| 38 |
title={__('Google reCAPTCHA', 'ghostkit')} |
| 39 |
initialOpen={initialOpen} |
| 40 |
> |
| 41 |
<TextControl |
| 42 |
label={__('Site Key', 'ghostkit')} |
| 43 |
value={apiSiteKey} |
| 44 |
onChange={(value) => { |
| 45 |
setApiSiteKey(value); |
| 46 |
saveAPIKeys(value, apiSecretKey); |
| 47 |
}} |
| 48 |
/> |
| 49 |
<TextControl |
| 50 |
label={__('Secret Key', 'ghostkit')} |
| 51 |
value={apiSecretKey} |
| 52 |
onChange={(value) => { |
| 53 |
setApiSecretKey(value); |
| 54 |
saveAPIKeys(apiSiteKey, value); |
| 55 |
}} |
| 56 |
/> |
| 57 |
<p> |
| 58 |
{__( |
| 59 |
'Protect your form from spam using Google reCAPTCHA v3.', |
| 60 |
'ghostkit' |
| 61 |
)} |
| 62 |
</p> |
| 63 |
<p> |
| 64 |
<ExternalLink href="https://www.google.com/recaptcha/about/"> |
| 65 |
{__('Generate Keys', 'ghostkit')} |
| 66 |
</ExternalLink> |
| 67 |
</p> |
| 68 |
</PanelBody> |
| 69 |
); |
| 70 |
} |
| 71 |
|