2020-09-26 13:03:13 +02:00
|
|
|
import React from 'react';
|
|
|
|
import { FormattedMessage } from 'react-intl';
|
2020-09-30 01:25:44 +02:00
|
|
|
import useVersion from 'hooks/useVersion';
|
2020-09-26 13:03:13 +02:00
|
|
|
import styles from './UpdateNotice.module.css';
|
2020-09-30 01:25:44 +02:00
|
|
|
import ButtonLayout from '../layout/ButtonLayout';
|
|
|
|
import Button from './Button';
|
2020-09-30 06:22:08 +02:00
|
|
|
import useForceUpdate from '../../hooks/useForceUpdate';
|
2020-09-26 13:03:13 +02:00
|
|
|
|
|
|
|
export default function UpdateNotice() {
|
2020-09-30 06:22:08 +02:00
|
|
|
const forceUpdte = useForceUpdate();
|
|
|
|
const { hasUpdate, latest, updateCheck } = useVersion();
|
2020-09-30 01:25:44 +02:00
|
|
|
|
2020-09-30 06:22:08 +02:00
|
|
|
function handleViewClick() {
|
|
|
|
location.href = 'https://github.com/mikecao/umami/releases';
|
|
|
|
updateCheck();
|
|
|
|
forceUpdte();
|
2020-09-30 01:25:44 +02:00
|
|
|
}
|
2020-09-26 13:03:13 +02:00
|
|
|
|
2020-09-30 06:22:08 +02:00
|
|
|
function handleDismissClick() {
|
|
|
|
updateCheck();
|
|
|
|
forceUpdte();
|
|
|
|
}
|
2020-09-26 13:03:13 +02:00
|
|
|
|
2020-09-30 06:22:08 +02:00
|
|
|
if (!hasUpdate) {
|
2020-09-30 01:25:44 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-09-26 13:03:13 +02:00
|
|
|
return (
|
2020-09-30 01:25:44 +02:00
|
|
|
<div className={styles.notice}>
|
|
|
|
<div className={styles.message}>
|
2020-09-26 13:03:13 +02:00
|
|
|
<FormattedMessage
|
|
|
|
id="message.new-version-available"
|
2020-09-30 01:25:44 +02:00
|
|
|
defaultMessage="A new version of umami {version} is available!"
|
|
|
|
values={{ version: `v${latest}` }}
|
2020-09-26 13:03:13 +02:00
|
|
|
/>
|
|
|
|
</div>
|
2020-09-30 01:25:44 +02:00
|
|
|
<ButtonLayout>
|
2020-09-30 06:22:08 +02:00
|
|
|
<Button size="xsmall" variant="action" onClick={handleViewClick}>
|
2020-09-30 01:25:44 +02:00
|
|
|
<FormattedMessage id="button.view-details" defaultMessage="View details" />
|
|
|
|
</Button>
|
2020-09-30 06:22:08 +02:00
|
|
|
<Button size="xsmall" onClick={handleDismissClick}>
|
2020-09-30 01:25:44 +02:00
|
|
|
<FormattedMessage id="button.dismiss" defaultMessage="Dismiss" />
|
|
|
|
</Button>
|
|
|
|
</ButtonLayout>
|
2020-09-26 13:03:13 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|