You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Prowlarr/frontend/src/Components/Form/CardigannCaptchaInputConnec...

78 lines
1.6 KiB

import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { createSelector } from 'reselect';
import { getCaptchaCookie, refreshCaptcha, resetCaptcha } from 'Store/Actions/captchaActions';
import CardigannCaptchaInput from './CardigannCaptchaInput';
function createMapStateToProps() {
return createSelector(
(state) => state.captcha,
(captcha) => {
return captcha;
}
);
}
const mapDispatchToProps = {
refreshCaptcha,
getCaptchaCookie,
resetCaptcha
};
class CardigannCaptchaInputConnector extends Component {
//
// Lifecycle
componentDidMount() {
this.onRefreshPress();
}
componentWillUnmount = () => {
this.props.resetCaptcha();
};
//
// Listeners
onRefreshPress = () => {
const {
provider,
providerData,
name,
onChange
} = this.props;
onChange({ name, value: '' });
this.props.resetCaptcha();
this.props.refreshCaptcha({ provider, providerData });
};
//
// Render
render() {
return (
<CardigannCaptchaInput
{...this.props}
onRefreshPress={this.onRefreshPress}
/>
);
}
}
CardigannCaptchaInputConnector.propTypes = {
provider: PropTypes.string.isRequired,
providerData: PropTypes.object.isRequired,
name: PropTypes.string.isRequired,
token: PropTypes.string,
onChange: PropTypes.func.isRequired,
refreshCaptcha: PropTypes.func.isRequired,
getCaptchaCookie: PropTypes.func.isRequired,
resetCaptcha: PropTypes.func.isRequired
};
export default connect(createMapStateToProps, mapDispatchToProps)(CardigannCaptchaInputConnector);