Skip to content

Commit

Permalink
Move captcha field to the end.
Browse files Browse the repository at this point in the history
  • Loading branch information
robgietema committed Oct 5, 2024
1 parent 275286a commit 38cd999
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 4 deletions.
5 changes: 4 additions & 1 deletion frontend/packages/volto-form-block/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ import {
import { schemaFormBlockSchema } from 'volto-form-block/schemaFormBlock/schema';
import schemaFormBlockEdit from 'volto-form-block/schemaFormBlock/EditSchemaForm';
import schemaFormBlockView from 'volto-form-block/schemaFormBlock/ViewSchemaForm';
import HoneypotCaptchaWidget from 'volto-form-block/schemaFormBlock/HoneypotCaptchaWidget';

import HoneypotCaptchaWidget from 'volto-form-block/schemaFormBlock/Widgets/HoneypotCaptchaWidget';
import NorobotsCaptchaWidget from 'volto-form-block/schemaFormBlock/Widgets/NorobotsCaptchaWidget';

export {
submitForm,
Expand Down Expand Up @@ -78,6 +80,7 @@ defineMessages({

const applyConfig = (config) => {
config.widgets.widget.honeypot = HoneypotCaptchaWidget;
config.widgets.widget['norobots-captcha'] = NorobotsCaptchaWidget;

config.blocks.blocksConfig = {
...config.blocks.blocksConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { toast } from 'react-toastify';
import { Toast } from '@plone/volto/components';
import { useLocation } from 'react-router-dom';
import qs from 'query-string';
import { includes, keys, pickBy } from 'lodash';
import { includes, keys, map, pickBy, without } from 'lodash';
import config from '@plone/volto/registry';

const messages = defineMessages({
Expand Down Expand Up @@ -88,7 +88,15 @@ const FormBlockView = ({ data, id, properties, metadata, path }) => {
<p className="documentDescription">{data.description}</p>
)}
<Form
schema={data.schema}
schema={{
...data.schema,
fieldsets: map(data.schema.fieldsets, (fieldset) => ({
...fieldset,
fields: includes(fieldset.fields, 'captchaWidget')
? [...without(fieldset.fields, 'captchaWidget'), 'captchaWidget']
: fieldset.fields,
})),
}}
formData={initialData}
onSubmit={onSubmit}
resetOnCancel={true}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ const HoneypotCaptchaWidget = ({ id, value, onChange, captcha_props }) => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

return (
return onEdit ? (

Check failure on line 22 in frontend/packages/volto-form-block/src/schemaFormBlock/Widgets/HoneypotCaptchaWidget.jsx

View workflow job for this annotation

GitHub Actions / frontend / code-analysis

'onEdit' is not defined
<></>
) : (
<div className="honey-wrapper2" key={'honeypot-captcha'}>
<TextWidget
id={captcha_props.id}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { useEffect, useRef } from 'react';

Check warning on line 1 in frontend/packages/volto-form-block/src/schemaFormBlock/Widgets/NorobotsCaptchaWidget.jsx

View workflow job for this annotation

GitHub Actions / frontend / code-analysis

'useEffect' is defined but never used

Check warning on line 1 in frontend/packages/volto-form-block/src/schemaFormBlock/Widgets/NorobotsCaptchaWidget.jsx

View workflow job for this annotation

GitHub Actions / frontend / code-analysis

'useRef' is defined but never used
import PropTypes from 'prop-types';

const NorobotsCaptchaWidget = (props) => {
const {
id,

Check warning on line 6 in frontend/packages/volto-form-block/src/schemaFormBlock/Widgets/NorobotsCaptchaWidget.jsx

View workflow job for this annotation

GitHub Actions / frontend / code-analysis

'id' is assigned a value but never used
value,

Check warning on line 7 in frontend/packages/volto-form-block/src/schemaFormBlock/Widgets/NorobotsCaptchaWidget.jsx

View workflow job for this annotation

GitHub Actions / frontend / code-analysis

'value' is assigned a value but never used
onChange,

Check warning on line 8 in frontend/packages/volto-form-block/src/schemaFormBlock/Widgets/NorobotsCaptchaWidget.jsx

View workflow job for this annotation

GitHub Actions / frontend / code-analysis

'onChange' is assigned a value but never used
onBlur,

Check warning on line 9 in frontend/packages/volto-form-block/src/schemaFormBlock/Widgets/NorobotsCaptchaWidget.jsx

View workflow job for this annotation

GitHub Actions / frontend / code-analysis

'onBlur' is assigned a value but never used
onClick,

Check warning on line 10 in frontend/packages/volto-form-block/src/schemaFormBlock/Widgets/NorobotsCaptchaWidget.jsx

View workflow job for this annotation

GitHub Actions / frontend / code-analysis

'onClick' is assigned a value but never used
icon,

Check warning on line 11 in frontend/packages/volto-form-block/src/schemaFormBlock/Widgets/NorobotsCaptchaWidget.jsx

View workflow job for this annotation

GitHub Actions / frontend / code-analysis

'icon' is assigned a value but never used
iconAction,

Check warning on line 12 in frontend/packages/volto-form-block/src/schemaFormBlock/Widgets/NorobotsCaptchaWidget.jsx

View workflow job for this annotation

GitHub Actions / frontend / code-analysis

'iconAction' is assigned a value but never used
isDisabled,

Check warning on line 13 in frontend/packages/volto-form-block/src/schemaFormBlock/Widgets/NorobotsCaptchaWidget.jsx

View workflow job for this annotation

GitHub Actions / frontend / code-analysis

'isDisabled' is assigned a value but never used
focus,
onEdit,
} = props;

return onEdit ? <></> : <></>;
};

export default NorobotsCaptchaWidget;

NorobotsCaptchaWidget.propTypes = {
id: PropTypes.string.isRequired,
title: PropTypes.string.isRequired,
description: PropTypes.string,
required: PropTypes.bool,
error: PropTypes.arrayOf(PropTypes.string),
value: PropTypes.string,
focus: PropTypes.bool,
onChange: PropTypes.func,
onBlur: PropTypes.func,
onClick: PropTypes.func,
onEdit: PropTypes.func,
onDelete: PropTypes.func,
icon: PropTypes.shape({
xmlns: PropTypes.string,
viewBox: PropTypes.string,
content: PropTypes.string,
}),
iconAction: PropTypes.func,
wrapped: PropTypes.bool,
placeholder: PropTypes.string,
};

NorobotsCaptchaWidget.defaultProps = {
description: null,
required: false,
error: [],
value: null,
onChange: () => {},
onBlur: () => {},
onClick: () => {},
onEdit: null,
onDelete: null,
focus: false,
icon: null,
iconAction: null,
};

0 comments on commit 38cd999

Please sign in to comment.