2020-07-28 10:17:45 +02:00
|
|
|
import React, { useState } from 'react';
|
|
|
|
import { getDateRange } from 'lib/date';
|
|
|
|
|
2020-07-30 08:25:52 +02:00
|
|
|
const filterOptions = ['24hour', '7day', '30day', '60day', '90day'];
|
2020-07-28 10:17:45 +02:00
|
|
|
|
|
|
|
export default function DateFilter({ onChange }) {
|
2020-07-30 08:25:52 +02:00
|
|
|
const [selected, setSelected] = useState('7day');
|
2020-07-28 10:17:45 +02:00
|
|
|
|
|
|
|
function handleChange(e) {
|
|
|
|
const value = e.target.value;
|
|
|
|
setSelected(value);
|
|
|
|
onChange(getDateRange(value));
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<select value={selected} onChange={handleChange}>
|
|
|
|
{filterOptions.map(option => (
|
2020-07-30 08:25:52 +02:00
|
|
|
<option key={option} value={option}>
|
2020-07-29 04:04:45 +02:00
|
|
|
{option}
|
|
|
|
</option>
|
2020-07-28 10:17:45 +02:00
|
|
|
))}
|
|
|
|
</select>
|
|
|
|
);
|
|
|
|
}
|