import downIcon from '@fortawesome/fontawesome-free-solid/faAngleDoubleDown'; import upIcon from '@fortawesome/fontawesome-free-solid/faAngleDoubleUp'; import FontAwesomeIcon from '@fortawesome/react-fontawesome'; import { assoc, dissoc, isNil, pick, pipe, replace, trim } from 'ramda'; import React from 'react'; import { connect } from 'react-redux'; import { Collapse } from 'reactstrap'; import DateInput from '../common/DateInput'; import CreateShortUrlResult from './helpers/CreateShortUrlResult'; import { createShortUrl, resetCreateShortUrl } from './reducers/shortUrlCreationResult'; import TagsSelector from '../utils/TagsSelector'; export class CreateShortUrl extends React.Component { state = { longUrl: '', tags: [], customSlug: undefined, validSince: undefined, validUntil: undefined, maxVisits: undefined, moreOptionsVisible: false }; render() { const { createShortUrl, shortUrlCreationResult, resetCreateShortUrl } = this.props; const changeTags = tags => this.setState({ tags: tags.map(pipe(trim, replace(/ /g, '-'))) }); const renderOptionalInput = (id, placeholder, type = 'text', props = {}) => this.setState({ [id]: e.target.value })} {...props} />; const createDateInput = (id, placeholder, props = {}) => this.setState({ [id]: date })} isClearable {...props} />; const formatDate = date => isNil(date) ? date : date.format(); const save = e => { e.preventDefault(); createShortUrl(pipe( dissoc('moreOptionsVisible'), // Remove moreOptionsVisible property assoc('validSince', formatDate(this.state.validSince)), assoc('validUntil', formatDate(this.state.validUntil)) )(this.state)); }; return (
this.setState({ longUrl: e.target.value })} />
{renderOptionalInput('customSlug', 'Custom slug')}
{renderOptionalInput('maxVisits', 'Maximum number of visits allowed', 'number', { min: 1 })}
{createDateInput('validSince', 'Enabled since...', { maxDate: this.state.validUntil })}
{createDateInput('validUntil', 'Enabled until...', { minDate: this.state.validSince })}
); } } export default connect(pick(['shortUrlCreationResult']), { createShortUrl, resetCreateShortUrl })(CreateShortUrl);