import React from 'react'; import downIcon from '@fortawesome/fontawesome-free-solid/faAngleDoubleDown'; import upIcon from '@fortawesome/fontawesome-free-solid/faAngleDoubleUp'; import FontAwesomeIcon from '@fortawesome/react-fontawesome'; import DatePicker from 'react-datepicker'; import { Collapse } from 'reactstrap'; import ReactTags from 'react-tag-autocomplete'; import { assoc, replace } from 'ramda'; import './CreateShortUrl.scss'; import '../../node_modules/react-datepicker/dist/react-datepicker.css' export default class CreateShortUrl extends React.Component { state = { longUrl: '', tags: [], customSlug: null, validSince: null, validUntil: null, maxVisits: null, 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) => ; 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...')}
{createDateInput('validUntil', 'Enabled until...')}
); } }