Merge branch 'main' of github.com:strapi/strapi into releases/4.12.1

This commit is contained in:
Convly 2023-08-02 17:17:57 +02:00
commit c0f90739d6
10 changed files with 121 additions and 126 deletions

View File

@ -1,44 +0,0 @@
import { useNotification } from '@strapi/helper-plugin';
import qs from 'qs';
import { useQuery } from 'react-query';
import { MARKETPLACE_API_URL } from '../constants';
const fetchMarketplacePlugins = async (params = {}) => {
try {
const queryString = qs.stringify(qs.parse(params));
const res = await fetch(`${MARKETPLACE_API_URL}/plugins?${queryString}`);
if (!res.ok) {
throw new Error('Failed to fetch marketplace plugins.');
}
const data = await res.json();
return data;
} catch (error) {
console.error(error);
}
return null;
};
const useFetchMarketplacePlugins = (notifyLoad, params) => {
const toggleNotification = useNotification();
return useQuery(['list-marketplace-plugins', params], () => fetchMarketplacePlugins(params), {
onSuccess() {
if (notifyLoad) {
notifyLoad();
}
},
onError() {
toggleNotification({
type: 'warning',
message: { id: 'notification.error', defaultMessage: 'An error occured' },
});
},
});
};
export default useFetchMarketplacePlugins;

View File

@ -1,44 +0,0 @@
import { useNotification } from '@strapi/helper-plugin';
import qs from 'qs';
import { useQuery } from 'react-query';
import { MARKETPLACE_API_URL } from '../constants';
const fetchMarketplaceProviders = async (params = {}) => {
try {
const queryString = qs.stringify(qs.parse(params));
const res = await fetch(`${MARKETPLACE_API_URL}/providers?${queryString}`);
if (!res.ok) {
throw new Error('Failed to fetch marketplace providers.');
}
const data = await res.json();
return data;
} catch (error) {
console.error(error);
}
return null;
};
const useFetchMarketplaceProviders = (notifyLoad, params) => {
const toggleNotification = useNotification();
return useQuery(['list-marketplace-providers', params], () => fetchMarketplaceProviders(params), {
onSuccess() {
if (notifyLoad) {
notifyLoad();
}
},
onError() {
toggleNotification({
type: 'warning',
message: { id: 'notification.error', defaultMessage: 'An error occured' },
});
},
});
};
export default useFetchMarketplaceProviders;

View File

@ -1,24 +0,0 @@
import { useNotification } from '@strapi/helper-plugin';
import { useQuery } from 'react-query';
import { fetchEnabledPlugins } from './utils/api';
const useFetchEnabledPlugins = (notifyLoad) => {
const toggleNotification = useNotification();
return useQuery('list-enabled-plugins', () => fetchEnabledPlugins(), {
onSuccess() {
if (notifyLoad) {
notifyLoad();
}
},
onError() {
toggleNotification({
type: 'warning',
message: { id: 'notification.error', defaultMessage: 'An error occured' },
});
},
});
};
export default useFetchEnabledPlugins;

View File

@ -1,10 +0,0 @@
import { getFetchClient } from '@strapi/helper-plugin';
const fetchEnabledPlugins = async () => {
const { get } = getFetchClient();
const { data } = await get('/admin/plugins');
return data;
};
export { fetchEnabledPlugins };

View File

@ -17,7 +17,7 @@ import {
import { LoadingIndicatorPage, useFocusWhenNavigate } from '@strapi/helper-plugin';
import { useIntl } from 'react-intl';
import useFetchEnabledPlugins from '../../hooks/useFetchEnabledPlugins';
import { usePlugins } from './hooks/usePlugins';
const Plugins = () => {
const { formatMessage } = useIntl();
@ -41,7 +41,7 @@ const Plugins = () => {
);
};
const { status, data } = useFetchEnabledPlugins(notifyPluginPageLoad);
const { status, data } = usePlugins(notifyPluginPageLoad);
const isLoading = status !== 'success' && status !== 'error';

View File

@ -0,0 +1,29 @@
import { useFetchClient, useNotification } from '@strapi/helper-plugin';
import { useQuery } from 'react-query';
export const usePlugins = (notifyLoad) => {
const toggleNotification = useNotification();
const { get } = useFetchClient();
return useQuery(
['plugins'],
async () => {
const { data } = await get('/admin/plugins');
return data;
},
{
onSuccess() {
if (notifyLoad) {
notifyLoad();
}
},
onError() {
toggleNotification({
type: 'warning',
message: { id: 'notification.error', defaultMessage: 'An error occured' },
});
},
}
);
};

View File

@ -0,0 +1,44 @@
import { useNotification } from '@strapi/helper-plugin';
import qs from 'qs';
import { useQuery } from 'react-query';
import { MARKETPLACE_API_URL } from '../../constants';
export const useFetchMarketplacePlugins = (notifyLoad, params = {}) => {
const toggleNotification = useNotification();
return useQuery(
['marketplace', 'plugins', params],
async () => {
try {
const queryString = qs.stringify(qs.parse(params));
const res = await fetch(`${MARKETPLACE_API_URL}/plugins?${queryString}`);
if (!res.ok) {
throw new Error('Failed to fetch marketplace plugins.');
}
const data = await res.json();
return data;
} catch (error) {
// silence
}
return null;
},
{
onSuccess() {
if (notifyLoad) {
notifyLoad();
}
},
onError() {
toggleNotification({
type: 'warning',
message: { id: 'notification.error', defaultMessage: 'An error occured' },
});
},
}
);
};

View File

@ -0,0 +1,44 @@
import { useNotification } from '@strapi/helper-plugin';
import qs from 'qs';
import { useQuery } from 'react-query';
import { MARKETPLACE_API_URL } from '../../constants';
export const useFetchMarketplaceProviders = (notifyLoad, params = {}) => {
const toggleNotification = useNotification();
return useQuery(
['marketplace', 'providers', params],
async () => {
try {
const queryString = qs.stringify(qs.parse(params));
const res = await fetch(`${MARKETPLACE_API_URL}/providers?${queryString}`);
if (!res.ok) {
throw new Error('Failed to fetch marketplace providers.');
}
const data = await res.json();
return data;
} catch (error) {
// silence
}
return null;
},
{
onSuccess() {
if (notifyLoad) {
notifyLoad();
}
},
onError() {
toggleNotification({
type: 'warning',
message: { id: 'notification.error', defaultMessage: 'An error occured' },
});
},
}
);
};

View File

@ -3,8 +3,8 @@ import { useEffect, useState } from 'react';
import { useNotifyAT } from '@strapi/design-system';
import { useIntl } from 'react-intl';
import useFetchMarketplacePlugins from '../../../hooks/marketplace/useFetchMarketplacePlugins';
import useFetchMarketplaceProviders from '../../../hooks/marketplace/useFetchMarketplaceProviders';
import { useFetchMarketplacePlugins } from '../hooks/useFetchMarketplacePlugins';
import { useFetchMarketplaceProviders } from '../hooks/useFetchMarketplaceProviders';
function useMarketplaceData({ npmPackageType, debouncedSearch, query, tabQuery }) {
const { notifyStatus } = useNotifyAT();