umami/components/input/RefreshButton.js

29 lines
802 B
JavaScript
Raw Normal View History

2023-06-16 05:15:31 +02:00
import { LoadingButton, Icon, TooltipPopup } 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';
2023-04-21 17:00:42 +02:00
export 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) {
setWebsiteDateRange(websiteId, dateRange);
2020-08-31 23:11:30 +02:00
}
}
return (
2023-06-16 05:15:31 +02:00
<TooltipPopup label={formatMessage(labels.refresh)}>
<LoadingButton loading={isLoading} onClick={handleClick}>
2023-02-04 17:59:52 +01:00
<Icon>
<Icons.Refresh />
</Icon>
</LoadingButton>
2023-06-16 05:15:31 +02:00
</TooltipPopup>
);
}
export default RefreshButton;