// @flow import React from 'react'; import moment from 'moment'; import Button from 'component/button'; import Card from 'component/common/card'; import { FormField } from 'component/common/form-components/form-field'; import FormFieldDuration from 'component/formFieldDuration'; import { Modal } from 'modal/modal'; const CHANNEL_AGE_LIMIT_MIN_DATE = new Date('February 8, 2022 00:00:00'); const LIMITATION_WARNING = 'The minimum duration must not exceed Feb 8th, 2022.'; type Props = { onConfirm: (limitInMinutes: number, closeModal: () => void) => void, doHideModal: () => void, }; export default function ModalMinChannelAge(props: Props) { const { onConfirm, doHideModal } = props; const [showLimitationWarning, setShowLimitationWarning] = React.useState(''); const [limitDisabled, setLimitDisabled] = React.useState(false); const [minChannelAgeInput, setMinChannelAgeInput] = React.useState(''); const [minChannelAgeMinutes, setMinChannelAgeMinutes] = React.useState(-1); const inputOk = limitDisabled || (minChannelAgeMinutes > 0 && !showLimitationWarning); function handleOnClick() { if (onConfirm) { onConfirm(limitDisabled ? 0 : minChannelAgeMinutes, doHideModal); } } function handleOnInputResolved(valueInSeconds) { if (valueInSeconds > 0) { const minCreationDate = moment().subtract(valueInSeconds, 'seconds').toDate(); setShowLimitationWarning(minCreationDate.getTime() < CHANNEL_AGE_LIMIT_MIN_DATE.getTime()); setMinChannelAgeMinutes(Math.ceil(valueInSeconds / 60)); } else { setShowLimitationWarning(false); setMinChannelAgeMinutes(-1); } } return ( setMinChannelAgeInput(e.target.value)} onResolve={handleOnInputResolved} /> {showLimitationWarning && !limitDisabled &&

{__(LIMITATION_WARNING)}

} setLimitDisabled(!limitDisabled)} /> } actions={
} />
); }