docbrown/app/javascript/listings/elements/expireDate.jsx
Hoang Vo 293ba5231b Fix eslint issues in app/javascript/listings (#4253)
* Fix some eslint and a11y issues

* Add a11y fixed to snapshot

* Fix missing whitespace that cause test fail

* Fix code duplicate

* Config eslint to allows the label as a sibling

* Use 'error' instead of 2 in eslintrc

* Correct propTypes in SingleListing

* Add missing id prop for select

* Add space between two functions

* onKeyPress only register Enter

* Allow space key also to activate action

* Use a common function for three event handlers
2019-10-14 14:23:20 -04:00

37 lines
1 KiB
JavaScript

import PropTypes from 'prop-types';
import { h } from 'preact';
const ExpireDate = ({ onChange, defaultValue }) => {
let tomorrow = new Date();
let monthFromToday = new Date();
tomorrow.setDate(new Date().getDate() + 1);
[tomorrow] = tomorrow.toISOString().split('T');
monthFromToday.setDate(new Date().getDate() + 30);
[monthFromToday] = monthFromToday.toISOString().split('T');
return (
<div className="field">
<label className="listingform__label" htmlFor="expires_at">
Custom Expire Date (if applicable for time sensitive events, deadlines,
etc.)
</label>
<input
type="date"
className="listingform__input"
id="expires_at"
name="classified_listing[expires_at]"
value={defaultValue}
onInput={onChange}
min={tomorrow}
max={monthFromToday}
/>
</div>
);
};
ExpireDate.propTypes = {
onChange: PropTypes.func.isRequired,
defaultValue: PropTypes.string.isRequired,
};
export default ExpireDate;