From fbf3a4a880756078d676e260920e45583e44481a Mon Sep 17 00:00:00 2001 From: Nieky Allen Date: Fri, 20 Oct 2023 01:44:38 -0500 Subject: [PATCH] update CI cookie flag to auto-validate input to bypass onchange event issue --- web/atoms/Captcha.tsx | 9 +-------- web/molecules/steps/SecretInputCard.tsx | 11 +++++++++++ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/web/atoms/Captcha.tsx b/web/atoms/Captcha.tsx index 5adf500..c926baf 100644 --- a/web/atoms/Captcha.tsx +++ b/web/atoms/Captcha.tsx @@ -1,16 +1,9 @@ -import React, { useEffect } from 'react'; +import React from 'react'; import HCaptcha from '@hcaptcha/react-hcaptcha'; import { post } from '@shared/lib/fetch'; import { CAPTCHA_API_PATCH } from 'config/paths'; -import Cookies from 'js-cookie'; -import { DISABLE_CAPTCHA_COOKIE } from 'config/cookies'; export const Captcha = ({ onSuccess, onExpire }: CaptchaProps) => { - useEffect(() => { - const disableCaptcha = Cookies.get(DISABLE_CAPTCHA_COOKIE); - if (disableCaptcha) onSuccess(); - }, []); - const onVerify = async (token: string, _ekey: string) => { const resp = await post<{ success: boolean }, { token: string }>( CAPTCHA_API_PATCH, diff --git a/web/molecules/steps/SecretInputCard.tsx b/web/molecules/steps/SecretInputCard.tsx index f7f66de..5666e8d 100644 --- a/web/molecules/steps/SecretInputCard.tsx +++ b/web/molecules/steps/SecretInputCard.tsx @@ -17,6 +17,8 @@ import { Captcha } from 'atoms/Captcha'; import { ACCEPTED_FILE_TYPES, MAX_PAYLOAD_SIZE } from '@shared/config/files'; import { CONFIRM_PAYLOAD_BTN_ID } from 'lib/constants'; import { useUser } from '@auth0/nextjs-auth0/client'; +import Cookies from 'js-cookie'; +import { DISABLE_CAPTCHA_COOKIE } from 'config/cookies'; export const SecretInputCard = () => { const [mode, setMode] = useState('text'); @@ -39,6 +41,15 @@ export const SecretInputCard = () => { else setCanConfirm(false); }, [user]); + useEffect(() => { + const disableCaptcha = Cookies.get(DISABLE_CAPTCHA_COOKIE); + + if (disableCaptcha) { + setCanConfirm(true); + setIsValid(true); + } + }, []); + const isValidJson = (input: string) => { try { JSON.parse(input);