Skip to content

Commit

Permalink
update CI cookie flag to auto-validate input to bypass onchange event…
Browse files Browse the repository at this point in the history
… issue
  • Loading branch information
dallen4 committed Oct 20, 2023
1 parent 35f5009 commit fbf3a4a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
9 changes: 1 addition & 8 deletions web/atoms/Captcha.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
11 changes: 11 additions & 0 deletions web/molecules/steps/SecretInputCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<PayloadInputMode>('text');
Expand All @@ -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);
Expand Down

0 comments on commit fbf3a4a

Please sign in to comment.