Clear captcha form when registration fails

This commit is contained in:
Alex Gleason 2021-03-26 15:30:14 -05:00
parent 4d1af4764f
commit eae309e150
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
2 changed files with 11 additions and 5 deletions

View File

@ -81,15 +81,14 @@ class CaptchaField extends React.Component {
render() {
const { captcha } = this.state;
const { onChange } = this.props;
const { onClick } = this.props;
const { onChange, onClick, ...props } = this.props;
switch(captcha.get('type')) {
case 'native':
return (
<div>
<p>{<FormattedMessage id='registration.captcha.hint' defaultMessage='Click the image to get a new captcha' />}</p>
<NativeCaptchaField captcha={captcha} onChange={onChange} onClick={onClick} />
<NativeCaptchaField captcha={captcha} onChange={onChange} onClick={onClick} {...props} />
</div>
);
case 'none':
@ -100,12 +99,13 @@ class CaptchaField extends React.Component {
}
export const NativeCaptchaField = ({ captcha, onChange, onClick }) => (
export const NativeCaptchaField = ({ captcha, onChange, onClick, name, value }) => (
<div className='captcha' >
<img alt='captcha' src={captcha.get('url')} onClick={onClick} />
<TextInput
placeholder='Enter the pictured text'
name='captcha_solution'
name={name}
value={value}
autoComplete='off'
onChange={onChange}
required
@ -117,4 +117,6 @@ NativeCaptchaField.propTypes = {
captcha: ImmutablePropTypes.map.isRequired,
onChange: PropTypes.func,
onClick: PropTypes.func,
name: PropTypes.string,
value: PropTypes.string,
};

View File

@ -132,10 +132,12 @@ class RegistrationForm extends ImmutablePureComponent {
refreshCaptcha = () => {
this.setState({ captchaIdempotencyKey: uuidv4() });
this.setParams({ captcha_solution: '' });
}
render() {
const { instance, intl } = this.props;
const { params } = this.state;
const isOpen = instance.get('registrations');
const isLoading = this.state.captchaLoading || this.state.submissionLoading;
@ -221,6 +223,8 @@ class RegistrationForm extends ImmutablePureComponent {
onChange={this.onInputChange}
onClick={this.onCaptchaClick}
idempotencyKey={this.state.captchaIdempotencyKey}
name='captcha_solution'
value={params.get('captcha_solution', '')}
/>
<div className='fields-group'>
<Checkbox