Skip to content

Commit

Permalink
chore(helper-plugin)!: move Notifications to admin
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaellis committed Mar 18, 2024
1 parent 23d1b38 commit 8290fc5
Show file tree
Hide file tree
Showing 139 changed files with 859 additions and 1,168 deletions.
2 changes: 1 addition & 1 deletion packages/core/admin/admin/src/components/Form.tsx
Expand Up @@ -14,7 +14,7 @@ import {
import { TranslationMessage } from '@strapi/helper-plugin';
import { ExclamationMarkCircle } from '@strapi/icons';
import { generateNKeysBetween } from 'fractional-indexing';
import produce from 'immer';
import { produce } from 'immer';
import isEqual from 'lodash/isEqual';
import { useIntl } from 'react-intl';
import { useBlocker } from 'react-router-dom';
Expand Down
@@ -1,7 +1,7 @@
import * as React from 'react';

import { auth } from '@strapi/helper-plugin';
import produce from 'immer';
import { produce } from 'immer';
import get from 'lodash/get';
import set from 'lodash/set';

Expand Down
7 changes: 4 additions & 3 deletions packages/core/admin/admin/src/components/NpsSurvey.tsx
Expand Up @@ -13,14 +13,15 @@ import {
FieldInput,
VisuallyHidden,
} from '@strapi/design-system';
import { useNotification, useAppInfo, usePersistentState } from '@strapi/helper-plugin';
import { useAppInfo, usePersistentState } from '@strapi/helper-plugin';
import { Cross } from '@strapi/icons';
import { Formik, Form } from 'formik';
import { useIntl } from 'react-intl';
import styled, { useTheme } from 'styled-components';
import * as yup from 'yup';

import { useAuth } from '../features/Auth';
import { useNotification } from '../features/Notifications';

const FieldWrapper = styled(Field)`
height: ${32 / 16}rem;
Expand Down Expand Up @@ -134,7 +135,7 @@ const NpsSurvey = () => {
const { formatMessage } = useIntl();
const { npsSurveySettings, setNpsSurveySettings } = useNpsSurveySettings();
const [isFeedbackResponse, setIsFeedbackResponse] = React.useState(false);
const toggleNotification = useNotification();
const { toggleNotification } = useNotification();
const { currentEnvironment, strapiVersion } = useAppInfo();

interface NpsSurveyMutationBody {
Expand Down Expand Up @@ -215,7 +216,7 @@ const NpsSurvey = () => {
}, 3000);
} catch (err) {
toggleNotification({
type: 'warning',
type: 'danger',
message: formatMessage({ id: 'notification.error', defaultMessage: 'An error occurred' }),
});
}
Expand Down
7 changes: 4 additions & 3 deletions packages/core/admin/admin/src/components/PageHelpers.tsx
Expand Up @@ -9,11 +9,12 @@ import {
Loader,
Main,
} from '@strapi/design-system';
import { useNotification, useRBACProvider } from '@strapi/helper-plugin';
import { useRBACProvider } from '@strapi/helper-plugin';
import { EmptyPermissions, ExclamationMarkCircle, EmptyDocuments } from '@strapi/icons';
import { useIntl } from 'react-intl';

import { Permission } from '../../../shared/contracts/shared';
import { useNotification } from '../features/Notifications';
import { useAPIErrorHandler } from '../hooks/useAPIErrorHandler';
import { useCheckPermissionsQuery } from '../services/auth';

Expand Down Expand Up @@ -162,7 +163,7 @@ export interface ProtectProps {
*/
const Protect = ({ permissions = [], children }: ProtectProps) => {
const { allPermissions } = useRBACProvider();
const toggleNotification = useNotification();
const { toggleNotification } = useNotification();
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();

const matchingPermissions = allPermissions.filter(
Expand Down Expand Up @@ -191,7 +192,7 @@ const Protect = ({ permissions = [], children }: ProtectProps) => {
React.useEffect(() => {
if (error) {
toggleNotification({
type: 'warning',
type: 'danger',
message: formatAPIError(error),
});
}
Expand Down
@@ -1,6 +1,6 @@
import * as React from 'react';

import produce from 'immer';
import { produce } from 'immer';
import set from 'lodash/set';

import { Page } from '../components/PageHelpers';
Expand Down
2 changes: 1 addition & 1 deletion packages/core/admin/admin/src/components/Providers.tsx
@@ -1,12 +1,12 @@
import * as React from 'react';

import { NotificationsProvider } from '@strapi/helper-plugin';
import { QueryClient, QueryClientProvider } from 'react-query';
import { Provider } from 'react-redux';

import { AuthProvider } from '../features/Auth';
import { HistoryProvider } from '../features/BackButton';
import { ConfigurationProvider } from '../features/Configuration';
import { NotificationsProvider } from '../features/Notifications';
import { StrapiAppProvider } from '../features/StrapiApp';
import { TrackingProvider } from '../features/Tracking';

Expand Down
2 changes: 1 addition & 1 deletion packages/core/admin/admin/src/components/RBACProvider.tsx
@@ -1,7 +1,7 @@
import * as React from 'react';

import { Permission, RBACContext, RBACContextValue } from '@strapi/helper-plugin';
import produce from 'immer';
import { produce } from 'immer';

import { useTypedSelector, useTypedDispatch } from '../core/store/hooks';

Expand Down
Expand Up @@ -11,12 +11,12 @@ import {
ModalLayout,
Typography,
} from '@strapi/design-system';
import { useNotification } from '@strapi/helper-plugin';
import { useIntl } from 'react-intl';
import * as yup from 'yup';

import { Form, InputProps, useField } from '../../../components/Form';
import { InputRenderer } from '../../../components/FormInputs/Renderer';
import { useNotification } from '../../../features/Notifications';
import { capitalise } from '../../../utils/strings';
import { ATTRIBUTE_TYPES_THAT_CANNOT_BE_MAIN_FIELD } from '../../constants/attributes';
import { useGetInitialDataQuery } from '../../services/init';
Expand Down Expand Up @@ -52,7 +52,7 @@ interface EditFieldFormProps {
const EditFieldForm = ({ attribute, name, onClose }: EditFieldFormProps) => {
const { formatMessage } = useIntl();
const id = React.useId();
const toggleNotification = useNotification();
const { toggleNotification } = useNotification();

const { value, onChange } =
useField<ConfigurationFormData['layout'][number]['children'][number]>(name);
Expand Down Expand Up @@ -107,7 +107,7 @@ const EditFieldForm = ({ attribute, name, onClose }: EditFieldFormProps) => {
id: 'content-manager.containers.edit-settings.modal-form.error',
defaultMessage: 'An error occurred while trying to open the form.',
}),
type: 'warning',
type: 'danger',
});

return null;
Expand Down
@@ -1,18 +1,14 @@
import { useEffect } from 'react';

import { useNotifyAT } from '@strapi/design-system';
import {
Permission,
hasPermissions,
useNotification,
useRBACProvider,
} from '@strapi/helper-plugin';
import { Permission, hasPermissions, useRBACProvider } from '@strapi/helper-plugin';
import { Contracts } from '@strapi/plugin-content-manager/_internal/shared';
import { stringify } from 'qs';
import { useIntl } from 'react-intl';

import { HOOKS } from '../../constants';
import { useTypedDispatch, useTypedSelector } from '../../core/store/hooks';
import { useNotification } from '../../features/Notifications';
import { useStrapiApp } from '../../features/StrapiApp';
import { useAPIErrorHandler } from '../../hooks/useAPIErrorHandler';
import { COLLECTION_TYPES, SINGLE_TYPES } from '../constants/collections';
Expand All @@ -36,7 +32,7 @@ interface ContentManagerLink {

const useContentManagerInitData = (): ContentManagerAppState => {
const dispatch = useTypedDispatch();
const toggleNotification = useNotification();
const { toggleNotification } = useNotification();
const { allPermissions } = useRBACProvider();
const runHookWaterfall = useStrapiApp(
'useContentManagerInitData',
Expand Down Expand Up @@ -69,7 +65,7 @@ const useContentManagerInitData = (): ContentManagerAppState => {

useEffect(() => {
if (initialDataQuery.error) {
toggleNotification({ type: 'warning', message: formatAPIError(initialDataQuery.error) });
toggleNotification({ type: 'danger', message: formatAPIError(initialDataQuery.error) });
}
}, [formatAPIError, initialDataQuery.error, toggleNotification]);

Expand All @@ -78,7 +74,7 @@ const useContentManagerInitData = (): ContentManagerAppState => {
useEffect(() => {
if (contentTypeSettingsQuery.error) {
toggleNotification({
type: 'warning',
type: 'danger',
message: formatAPIError(contentTypeSettingsQuery.error),
});
}
Expand Down
@@ -1,7 +1,6 @@
import * as React from 'react';

import { useNotification } from '@strapi/helper-plugin';

import { useNotification } from '../../features/Notifications';
import { useAPIErrorHandler } from '../../hooks/useAPIErrorHandler';
import { useGetInitialDataQuery } from '../services/init';

Expand All @@ -23,7 +22,7 @@ type ComponentsDictionary = Record<string, Contracts.Components.Component>;
* If no model is provided, the hook will return all the schemas.
*/
const useContentTypeSchema = (model?: string) => {
const toggleNotification = useNotification();
const { toggleNotification } = useNotification();
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();

const { components, contentType, contentTypes, error, isLoading, isFetching } =
Expand Down Expand Up @@ -56,7 +55,7 @@ const useContentTypeSchema = (model?: string) => {
React.useEffect(() => {
if (error) {
toggleNotification({
type: 'warning',
type: 'danger',
message: formatAPIError(error),
});
}
Expand Down
Expand Up @@ -6,15 +6,11 @@

import * as React from 'react';

import {
TranslationMessage,
getYupInnerErrors,
useNotification,
useQueryParams,
} from '@strapi/helper-plugin';
import { TranslationMessage, getYupInnerErrors, useQueryParams } from '@strapi/helper-plugin';
import { useParams } from 'react-router-dom';
import { ValidationError } from 'yup';

import { useNotification } from '../../features/Notifications';
import { useAPIErrorHandler } from '../../hooks/useAPIErrorHandler';
import { SINGLE_TYPES } from '../constants/collections';
import { useGetDocumentQuery } from '../services/documents';
Expand Down Expand Up @@ -89,7 +85,7 @@ type UseDocument = (
* @see {@link https://contributor.strapi.io/docs/core/content-manager/hooks/use-document} for more information
*/
const useDocument: UseDocument = (args, opts) => {
const toggleNotification = useNotification();
const { toggleNotification } = useNotification();
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();

const {
Expand All @@ -104,7 +100,7 @@ const useDocument: UseDocument = (args, opts) => {
React.useEffect(() => {
if (error) {
toggleNotification({
type: 'warning',
type: 'danger',
message: formatAPIError(error),
});
}
Expand Down

0 comments on commit 8290fc5

Please sign in to comment.