-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from collective/honeypot
feat: added honeypot field type
- Loading branch information
Showing
5 changed files
with
88 additions
and
3 deletions.
There are no files selected for viewing
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
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
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
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.public-ui .ui.grid > .row.honey-wrapper { | ||
display: none; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* HoneypotCaptchaWidget component. | ||
* @module components/manage/Widgets/HoneypotCaptchaWidget | ||
*/ | ||
|
||
import React, { useState, useEffect } from 'react'; | ||
|
||
import TextWidget from '@plone/volto/components/manage/Widgets/TextWidget'; | ||
import { Grid } from 'semantic-ui-react'; | ||
import './HoneypotCaptchaWidget.css'; | ||
|
||
/** | ||
* HoneypotCaptchaWidget component class. | ||
* @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, | ||
onChangeFormData, | ||
}) => { | ||
const createToken = (id, value) => { | ||
const token = { | ||
id: id, | ||
value: value, | ||
}; | ||
return JSON.stringify(token); | ||
}; | ||
|
||
useEffect(() => { | ||
captchaToken.current = createToken(id, new Date().toString()); | ||
}, [captchaToken, id]); | ||
|
||
useEffect(() => { | ||
onChangeFormData(id, id, '', { label: id }); | ||
}, []); | ||
|
||
const [value, setValue] = useState(); | ||
return ( | ||
<Grid.Row className="honey-wrapper" key={'honeypot-captcha'}> | ||
<TextWidget | ||
id={id} | ||
name={id} | ||
label={title} | ||
title={title} | ||
onChange={(field, value) => { | ||
//captchaToken.current = createToken(id, value); | ||
captchaToken.current = undefined; | ||
setValue(value); | ||
onChangeFormData(id, field, value, {}); | ||
}} | ||
value={value} | ||
/> | ||
</Grid.Row> | ||
); | ||
}; | ||
|
||
export default HoneypotCaptchaWidget; |