import React, { useEffect } from 'react'; import PropTypes from 'prop-types'; import { change, Field, formValueSelector, reduxForm, } from 'redux-form'; import { Trans, withTranslation } from 'react-i18next'; import flow from 'lodash/flow'; import { connect } from 'react-redux'; import { renderRadioField, toNumber, CheckboxField, renderTextareaField, toFloatNumber, renderInputField, } from '../../../helpers/form'; import { FORM_NAME, STATS_INTERVALS_DAYS, DAY, RETENTION_CUSTOM, RETENTION_CUSTOM_INPUT, CUSTOM_INTERVAL, RETENTION_RANGE, } from '../../../helpers/constants'; import '../FormButton.css'; const getIntervalTitle = (intervalMs, t) => { switch (intervalMs) { case RETENTION_CUSTOM: return t('settings_custom'); case DAY: return t('interval_24_hour'); default: return t('interval_days', { count: intervalMs / DAY }); } }; let Form = (props) => { const { handleSubmit, processing, submitting, invalid, handleReset, processingReset, t, interval, customInterval, dispatch, } = props; useEffect(() => { if (STATS_INTERVALS_DAYS.includes(interval)) { dispatch(change(FORM_NAME.STATS_CONFIG, CUSTOM_INTERVAL, null)); } }, [interval]); return (
statistics_retention_desc
{!STATS_INTERVALS_DAYS.includes(interval) && (
{t('custom_retention_input')}
)} {STATS_INTERVALS_DAYS.map((interval) => ( ))}
ignore_domains_desc_stats
); }; Form.propTypes = { handleSubmit: PropTypes.func.isRequired, handleReset: PropTypes.func.isRequired, change: PropTypes.func.isRequired, submitting: PropTypes.bool.isRequired, invalid: PropTypes.bool.isRequired, processing: PropTypes.bool.isRequired, processingReset: PropTypes.bool.isRequired, t: PropTypes.func.isRequired, interval: PropTypes.number, customInterval: PropTypes.number, dispatch: PropTypes.func.isRequired, }; const selector = formValueSelector(FORM_NAME.STATS_CONFIG); Form = connect((state) => { const interval = selector(state, 'interval'); const customInterval = selector(state, CUSTOM_INTERVAL); return { interval, customInterval, }; })(Form); export default flow([ withTranslation(), reduxForm({ form: FORM_NAME.STATS_CONFIG }), ])(Form);