mirror of
https://github.com/strapi/strapi.git
synced 2025-11-16 10:07:55 +00:00
Merge pull request #12813 from strapi/fix/release-notification
Fix / Release notification stacking
This commit is contained in:
commit
a2d4e966a4
@ -1,6 +1,12 @@
|
|||||||
import React, { useMemo, useState, useEffect, useRef } from 'react';
|
import React, { useMemo, useState, useEffect, useRef } from 'react';
|
||||||
// TODO: DS add loader
|
// TODO: DS add loader
|
||||||
import { auth, LoadingIndicatorPage, AppInfosContext, useGuidedTour } from '@strapi/helper-plugin';
|
import {
|
||||||
|
auth,
|
||||||
|
LoadingIndicatorPage,
|
||||||
|
AppInfosContext,
|
||||||
|
useGuidedTour,
|
||||||
|
useNotification,
|
||||||
|
} from '@strapi/helper-plugin';
|
||||||
import { useQueries } from 'react-query';
|
import { useQueries } from 'react-query';
|
||||||
import get from 'lodash/get';
|
import get from 'lodash/get';
|
||||||
import packageJSON from '../../../../package.json';
|
import packageJSON from '../../../../package.json';
|
||||||
@ -20,6 +26,7 @@ const strapiVersion = packageJSON.version;
|
|||||||
|
|
||||||
const AuthenticatedApp = () => {
|
const AuthenticatedApp = () => {
|
||||||
const { setGuidedTourVisibility } = useGuidedTour();
|
const { setGuidedTourVisibility } = useGuidedTour();
|
||||||
|
const toggleNotification = useNotification();
|
||||||
const setGuidedTourVisibilityRef = useRef(setGuidedTourVisibility);
|
const setGuidedTourVisibilityRef = useRef(setGuidedTourVisibility);
|
||||||
const userInfo = auth.getUserInfo();
|
const userInfo = auth.getUserInfo();
|
||||||
const userName = get(userInfo, 'username') || getFullName(userInfo.firstname, userInfo.lastname);
|
const userName = get(userInfo, 'username') || getFullName(userInfo.firstname, userInfo.lastname);
|
||||||
@ -34,7 +41,7 @@ const AuthenticatedApp = () => {
|
|||||||
{ queryKey: 'app-infos', queryFn: fetchAppInfo },
|
{ queryKey: 'app-infos', queryFn: fetchAppInfo },
|
||||||
{
|
{
|
||||||
queryKey: 'strapi-release',
|
queryKey: 'strapi-release',
|
||||||
queryFn: fetchStrapiLatestRelease,
|
queryFn: () => fetchStrapiLatestRelease(toggleNotification),
|
||||||
enabled: showReleaseNotification,
|
enabled: showReleaseNotification,
|
||||||
initialData: strapiVersion,
|
initialData: strapiVersion,
|
||||||
},
|
},
|
||||||
|
|||||||
@ -21,6 +21,9 @@ jest.mock('@strapi/helper-plugin', () => ({
|
|||||||
useGuidedTour: jest.fn(() => ({
|
useGuidedTour: jest.fn(() => ({
|
||||||
setGuidedTourVisibility: jest.fn(),
|
setGuidedTourVisibility: jest.fn(),
|
||||||
})),
|
})),
|
||||||
|
useNotification: jest.fn(() => ({
|
||||||
|
toggleNotification: jest.fn(),
|
||||||
|
})),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
jest.mock('../utils/api', () => ({
|
jest.mock('../utils/api', () => ({
|
||||||
|
|||||||
@ -1,15 +1,34 @@
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
import checkLatestStrapiVersion from './checkLatestStrapiVersion';
|
||||||
import { axiosInstance } from '../../../core/utils';
|
import { axiosInstance } from '../../../core/utils';
|
||||||
import packageJSON from '../../../../../package.json';
|
import packageJSON from '../../../../../package.json';
|
||||||
|
|
||||||
const strapiVersion = packageJSON.version;
|
const strapiVersion = packageJSON.version;
|
||||||
|
const showUpdateNotif = !JSON.parse(localStorage.getItem('STRAPI_UPDATE_NOTIF'));
|
||||||
|
|
||||||
const fetchStrapiLatestRelease = async () => {
|
const fetchStrapiLatestRelease = async toggleNotification => {
|
||||||
try {
|
try {
|
||||||
const {
|
const {
|
||||||
data: { tag_name },
|
data: { tag_name },
|
||||||
} = await axios.get('https://api.github.com/repos/strapi/strapi/releases/latest');
|
} = await axios.get('https://api.github.com/repos/strapi/strapi/releases/latest');
|
||||||
|
|
||||||
|
const shouldUpdateStrapi = checkLatestStrapiVersion(strapiVersion, tag_name);
|
||||||
|
|
||||||
|
if (shouldUpdateStrapi && showUpdateNotif) {
|
||||||
|
toggleNotification({
|
||||||
|
type: 'info',
|
||||||
|
message: { id: 'notification.version.update.message' },
|
||||||
|
link: {
|
||||||
|
url: `https://github.com/strapi/strapi/releases/tag/${tag_name}`,
|
||||||
|
label: {
|
||||||
|
id: 'notification.version.update.link',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
blockTransition: true,
|
||||||
|
onClose: () => localStorage.setItem('STRAPI_UPDATE_NOTIF', true),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return tag_name;
|
return tag_name;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// Don't throw an error
|
// Don't throw an error
|
||||||
|
|||||||
@ -12,7 +12,7 @@ import { DndProvider } from 'react-dnd';
|
|||||||
import { HTML5Backend } from 'react-dnd-html5-backend';
|
import { HTML5Backend } from 'react-dnd-html5-backend';
|
||||||
import LeftMenu from '../../components/LeftMenu';
|
import LeftMenu from '../../components/LeftMenu';
|
||||||
import AppLayout from '../../layouts/AppLayout';
|
import AppLayout from '../../layouts/AppLayout';
|
||||||
import { useMenu, useReleaseNotification } from '../../hooks';
|
import { useMenu } from '../../hooks';
|
||||||
import Onboarding from './Onboarding';
|
import Onboarding from './Onboarding';
|
||||||
import { createRoute } from '../../utils';
|
import { createRoute } from '../../utils';
|
||||||
import GuidedTourModal from '../../components/GuidedTour/Modal';
|
import GuidedTourModal from '../../components/GuidedTour/Modal';
|
||||||
@ -48,8 +48,6 @@ const useTrackUsage = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const Admin = () => {
|
const Admin = () => {
|
||||||
// Show a notification when the current version of Strapi is not the latest one
|
|
||||||
useReleaseNotification();
|
|
||||||
useTrackUsage();
|
useTrackUsage();
|
||||||
const { isLoading, generalSectionLinks, pluginsSectionLinks } = useMenu();
|
const { isLoading, generalSectionLinks, pluginsSectionLinks } = useMenu();
|
||||||
const { menu } = useStrapiApp();
|
const { menu } = useStrapiApp();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user