-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'arc-themes-release-version-2.3.0' into THEMES-1466
- Loading branch information
Showing
19 changed files
with
1,010 additions
and
296 deletions.
There are no files selected for viewing
183 changes: 101 additions & 82 deletions
183
blocks/algolia-assortment-content-source-block/package-lock.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 42 additions & 49 deletions
91
blocks/identity-block/components/bot-challenge-protection/index.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,57 @@ | ||
import React, { useState, useEffect } from "react"; | ||
import { useFusionContext } from "fusion:context"; | ||
import getProperties from "fusion:properties"; | ||
import getTranslatedPhrases from "fusion:intl"; | ||
import { Paragraph, useIdentity, useSales } from "@wpmedia/arc-themes-components"; | ||
import React from "react"; | ||
import ReCAPTCHA from "react-google-recaptcha"; | ||
import { GoogleReCaptchaProvider } from "react-google-recaptcha-v3"; | ||
|
||
const BotChallengeProtection = ({ challengeIn, setCaptchaToken, className, captchaError, setCaptchaError }) => { | ||
const { Identity, isInitialized } = useIdentity(); | ||
const { Sales } = useSales(); | ||
const [siteKey, setSiteKey] = useState(); | ||
import { usePhrases, useIdentity, Paragraph } from "@wpmedia/arc-themes-components"; | ||
import useRecaptcha, { RECAPTCHA_V2, RECAPTCHA_V3 } from "../../utils/useRecaptcha"; | ||
|
||
// eslint-disable-next-line | ||
import RecaptchaV3 from "./reCaptchaV3"; | ||
|
||
export const ARCXP_CAPTCHA= "ArcXP_captchaToken" | ||
|
||
const BotChallengeProtection = ({ challengeIn, setCaptchaToken, className, captchaError, setCaptchaError, resetRecaptcha }) => { | ||
|
||
const { isInitialized } = useIdentity(); | ||
const { recaptchaVersion, siteKey, isRecaptchaEnabled } = useRecaptcha(challengeIn); | ||
const phrases = usePhrases(); | ||
|
||
const onChange = (value) => { | ||
setCaptchaToken(value); | ||
setCaptchaError(null); | ||
localStorage.setItem('ArcXP_captchaToken', value); | ||
localStorage.setItem(ARCXP_CAPTCHA, value); | ||
}; | ||
|
||
useEffect(() => { | ||
const checkCaptcha = async () => { | ||
const config = await Identity.getConfig(); | ||
const {recaptchaSiteKey, recaptchaScore } = config; | ||
const isIdentityCaptchaEnabled = config?.[`${challengeIn}Recaptcha`]; | ||
|
||
if(['signup', 'signin', 'magicLink'].includes(challengeIn)) { | ||
if (isIdentityCaptchaEnabled && recaptchaScore === '-1' && recaptchaSiteKey) { | ||
setSiteKey(recaptchaSiteKey); | ||
} | ||
} | ||
|
||
if (challengeIn === 'checkout') { | ||
const salesConfig = await Sales.getConfig(); | ||
const isSalesCaptchaEnabled = salesConfig?.checkoutRecaptchaEnabled; | ||
if (isSalesCaptchaEnabled && recaptchaScore === '-1' && recaptchaSiteKey) { | ||
setSiteKey(recaptchaSiteKey); | ||
} | ||
} | ||
|
||
}; | ||
checkCaptcha(); | ||
|
||
}, [Identity, Sales, challengeIn]); | ||
|
||
const { arcSite } = useFusionContext(); | ||
const { locale } = getProperties(arcSite); | ||
const phrases = getTranslatedPhrases(locale); | ||
|
||
if (!isInitialized) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<section className={`${className}__bot-protection-section`} data-testid="bot-challege-protection-container"> | ||
{!!siteKey && <ReCAPTCHA | ||
sitekey={siteKey} | ||
onChange={onChange} | ||
onExpired={() => {}} | ||
/>} | ||
{captchaError && <Paragraph data-testid="bot-challege-captcha-error">{phrases.t("identity-block.bot-protection-error")}</Paragraph>} | ||
</section> | ||
); | ||
if (isRecaptchaEnabled && !!siteKey && !!recaptchaVersion) { | ||
if (recaptchaVersion === RECAPTCHA_V2) { | ||
return ( | ||
/* istanbul ignore next */ | ||
<section | ||
className={`${className}__bot-protection-section`} | ||
data-testid="bot-challege-protection-container" | ||
> | ||
<ReCAPTCHA sitekey={siteKey} onChange={onChange} onExpired={() => {}}/> | ||
{captchaError && <Paragraph>{phrases.t("identity-block.bot-protection-error")}</Paragraph>} | ||
</section> | ||
); | ||
} | ||
if (recaptchaVersion === RECAPTCHA_V3) { | ||
return ( | ||
/* istanbul ignore next */ | ||
<GoogleReCaptchaProvider reCaptchaKey={siteKey} scriptProps={{ async: true }}> | ||
<RecaptchaV3 setCaptchaToken={setCaptchaToken} resetRecaptcha={resetRecaptcha} /> | ||
</GoogleReCaptchaProvider> | ||
); | ||
} | ||
} else { | ||
return null; | ||
} | ||
|
||
return null; | ||
}; | ||
|
||
export default BotChallengeProtection; |
Oops, something went wrong.