mirror of
				https://github.com/strapi/strapi.git
				synced 2025-11-04 03:43:34 +00:00 
			
		
		
		
	Merge branch 'main' of github.com:strapi/strapi into releases/4.12.1
This commit is contained in:
		
						commit
						c0f90739d6
					
				@ -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;
 | 
			
		||||
@ -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;
 | 
			
		||||
@ -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;
 | 
			
		||||
@ -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 };
 | 
			
		||||
@ -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';
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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' },
 | 
			
		||||
        });
 | 
			
		||||
      },
 | 
			
		||||
    }
 | 
			
		||||
  );
 | 
			
		||||
};
 | 
			
		||||
@ -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' },
 | 
			
		||||
        });
 | 
			
		||||
      },
 | 
			
		||||
    }
 | 
			
		||||
  );
 | 
			
		||||
};
 | 
			
		||||
@ -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' },
 | 
			
		||||
        });
 | 
			
		||||
      },
 | 
			
		||||
    }
 | 
			
		||||
  );
 | 
			
		||||
};
 | 
			
		||||
@ -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();
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user