umami/components/input/RefreshButton.js

33 lines
904 B
JavaScript
Raw Normal View History

import { LoadingButton, Icon, Tooltip } from 'react-basics';
import { setWebsiteDateRange } from 'store/websites';
import useDateRange from 'hooks/useDateRange';
2023-01-31 06:44:07 +01:00
import Icons from 'components/icons';
2023-03-22 22:05:55 +01:00
import useMessages from 'hooks/useMessages';
function RefreshButton({ websiteId, isLoading }) {
2023-03-22 22:05:55 +01:00
const { formatMessage, labels } = useMessages();
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)) {
setWebsiteDateRange(websiteId, dateRange.value);
2022-03-02 06:13:15 +01:00
} else {
setWebsiteDateRange(websiteId, dateRange);
2022-03-02 06:13:15 +01:00
}
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;