2023-02-04 17:59:52 +01:00
|
|
|
import { useIntl } from 'react-intl';
|
2023-02-15 02:23:20 +01:00
|
|
|
import { LoadingButton, Icon, Tooltip } from 'react-basics';
|
2023-03-09 01:37:43 +01:00
|
|
|
import { setWebsiteDateRange } from 'store/websites';
|
2020-09-18 07:52:20 +02:00
|
|
|
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';
|
2020-08-31 12:53:39 +02:00
|
|
|
|
2023-02-15 02:23:20 +01:00
|
|
|
function RefreshButton({ websiteId, isLoading }) {
|
2023-02-04 17:59:52 +01:00
|
|
|
const { formatMessage } = useIntl();
|
2020-09-19 19:35:05 +02:00
|
|
|
const [dateRange] = useDateRange(websiteId);
|
2020-08-31 23:11:30 +02:00
|
|
|
|
|
|
|
function handleClick() {
|
2023-02-15 02:23:20 +01:00
|
|
|
if (!isLoading && dateRange) {
|
2023-01-31 06:44:07 +01:00
|
|
|
if (/^\d+/.test(dateRange.value)) {
|
2023-03-09 01:37:43 +01:00
|
|
|
setWebsiteDateRange(websiteId, dateRange.value);
|
2022-03-02 06:13:15 +01:00
|
|
|
} else {
|
2023-03-09 01:37:43 +01:00
|
|
|
setWebsiteDateRange(websiteId, dateRange);
|
2022-03-02 06:13:15 +01:00
|
|
|
}
|
2020-08-31 23:11:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-16 05:34:30 +02:00
|
|
|
return (
|
2023-02-04 17:59:52 +01:00
|
|
|
<Tooltip label={formatMessage(labels.refresh)}>
|
2023-02-15 02:23:20 +01:00
|
|
|
<LoadingButton loading={isLoading} onClick={handleClick}>
|
2023-02-04 17:59:52 +01:00
|
|
|
<Icon>
|
|
|
|
<Icons.Refresh />
|
|
|
|
</Icon>
|
2023-02-15 02:23:20 +01:00
|
|
|
</LoadingButton>
|
2023-02-04 17:59:52 +01:00
|
|
|
</Tooltip>
|
2020-09-16 05:34:30 +02:00
|
|
|
);
|
2020-08-31 12:53:39 +02:00
|
|
|
}
|
2021-02-16 13:35:16 +01:00
|
|
|
|
|
|
|
export default RefreshButton;
|