umami/components/input/RefreshButton.js

34 lines
910 B
JavaScript
Raw Normal View History

2023-02-04 17:59:52 +01:00
import { useIntl } from 'react-intl';
import { LoadingButton, Icon, Tooltip } from 'react-basics';
import { setDateRange } from 'store/websites';
import useDateRange from 'hooks/useDateRange';
2023-01-31 06:44:07 +01:00
import Icons from 'components/icons';
2023-02-04 17:59:52 +01:00
import { labels } from 'components/messages';
function RefreshButton({ websiteId, isLoading }) {
2023-02-04 17:59:52 +01:00
const { formatMessage } = useIntl();
const [dateRange] = useDateRange(websiteId);
2020-08-31 23:11:30 +02:00
function handleClick() {
if (!isLoading && dateRange) {
2023-01-31 06:44:07 +01:00
if (/^\d+/.test(dateRange.value)) {
2022-03-02 06:13:15 +01:00
setDateRange(websiteId, dateRange.value);
} else {
setDateRange(websiteId, dateRange);
}
2020-08-31 23:11:30 +02:00
}
}
return (
2023-02-04 17:59:52 +01:00
<Tooltip label={formatMessage(labels.refresh)}>
<LoadingButton loading={isLoading} onClick={handleClick}>
2023-02-04 17:59:52 +01:00
<Icon>
<Icons.Refresh />
</Icon>
</LoadingButton>
2023-02-04 17:59:52 +01:00
</Tooltip>
);
}
export default RefreshButton;