import calendarIcon from '@fortawesome/fontawesome-free-regular/faCalendarAlt'; import downIcon from '@fortawesome/fontawesome-free-solid/faAngleDoubleDown'; import upIcon from '@fortawesome/fontawesome-free-solid/faAngleDoubleUp'; import FontAwesomeIcon from '@fortawesome/react-fontawesome'; import { assoc, replace } from 'ramda'; import React from 'react'; import DatePicker from 'react-datepicker'; import ReactTags from 'react-tag-autocomplete'; import { Collapse } from 'reactstrap'; import '../../node_modules/react-datepicker/dist/react-datepicker.css'; import './CreateShortUrl.scss'; export default class CreateShortUrl extends React.Component { state = { longUrl: '', tags: [], customSlug: undefined, validSince: undefined, validUntil: undefined, maxVisits: undefined, moreOptionsVisible: false }; render() { const addTag = tag => this.setState({ tags: [].concat(this.state.tags, assoc('name', replace(/ /g, '-', tag.name), tag)) }); const removeTag = i => { const tags = this.state.tags.slice(0); tags.splice(i, 1); this.setState({ tags }); }; const renderOptionalInput = (id, placeholder, type = 'text', props = {}) => this.setState({ [id]: e.target.value })} {...props} />; const createDateInput = (id, placeholder, props = {}) => this.setState({ [id]: date })} dateFormat="YYYY-MM-DD" readOnly {...props} />; return (
e.preventDefault()}>
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 })}
); } }