Skip to content

Commit

Permalink
fix: fix captcha widget manage token
Browse files Browse the repository at this point in the history
  • Loading branch information
giuliaghisini committed Sep 9, 2022
1 parent b4d990c commit 1a3c19b
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/components/Widget/HoneypotCaptchaWidget.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @module components/manage/Widgets/HoneypotCaptchaWidget
*/

import React, { useState } from 'react';
import React, { useState, useEffect } from 'react';

import TextWidget from '@plone/volto/components/manage/Widgets/TextWidget';
import './HoneypotCaptchaWidget.css';
Expand All @@ -13,6 +13,9 @@ import './HoneypotCaptchaWidget.css';
* @function HoneypotCaptchaWidget
* @returns {string} Markup of the component.
*/

/*By default, captcha token is setted, and becames empty if user/bot fills the field.
*/
const HoneypotCaptchaWidget = ({ id, title, captchaToken }) => {
const createToken = (id, value) => {
const token = {
Expand All @@ -21,6 +24,11 @@ const HoneypotCaptchaWidget = ({ id, title, captchaToken }) => {
};
return JSON.stringify(token);
};

useEffect(() => {
captchaToken.current = createToken(id, new Date().toString());
}, [captchaToken, id]);

const [value, setValue] = useState();
return (
<div className="honey-wrapper" key={'honeypot-captcha'}>
Expand All @@ -30,7 +38,8 @@ const HoneypotCaptchaWidget = ({ id, title, captchaToken }) => {
label={title}
title={title}
onChange={(field, value) => {
captchaToken.current = createToken(id, value);
//captchaToken.current = createToken(id, value);
captchaToken.current = undefined;
setValue(value);
}}
value={value}
Expand Down

0 comments on commit 1a3c19b

Please sign in to comment.