Move error messages from editor to form component
[MAILPOET-3649]
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import React, { useEffect } from 'react';
|
import React, { useEffect } from 'react';
|
||||||
import { useDispatch, useSelect } from '@wordpress/data';
|
import { useDispatch } from '@wordpress/data';
|
||||||
import { useRouteMatch, Link } from 'react-router-dom';
|
import { useRouteMatch, Link } from 'react-router-dom';
|
||||||
|
|
||||||
import MailPoet from 'mailpoet';
|
import MailPoet from 'mailpoet';
|
||||||
@@ -8,7 +8,6 @@ import Heading from 'common/typography/heading/heading';
|
|||||||
import HideScreenOptions from 'common/hide_screen_options/hide_screen_options';
|
import HideScreenOptions from 'common/hide_screen_options/hide_screen_options';
|
||||||
import { Form } from './form';
|
import { Form } from './form';
|
||||||
|
|
||||||
import APIErrorsNotice from '../../notices/api_errors_notice';
|
|
||||||
import { createStore } from './store/store';
|
import { createStore } from './store/store';
|
||||||
|
|
||||||
const Editor: React.FunctionComponent = () => {
|
const Editor: React.FunctionComponent = () => {
|
||||||
@@ -16,11 +15,6 @@ const Editor: React.FunctionComponent = () => {
|
|||||||
|
|
||||||
createStore();
|
createStore();
|
||||||
|
|
||||||
const errors: string[] = useSelect(
|
|
||||||
(select) => select('mailpoet-dynamic-segments-form').getErrors(),
|
|
||||||
[]
|
|
||||||
);
|
|
||||||
|
|
||||||
const { pageLoaded } = useDispatch('mailpoet-dynamic-segments-form');
|
const { pageLoaded } = useDispatch('mailpoet-dynamic-segments-form');
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -31,9 +25,6 @@ const Editor: React.FunctionComponent = () => {
|
|||||||
<>
|
<>
|
||||||
<Background color="#fff" />
|
<Background color="#fff" />
|
||||||
<HideScreenOptions />
|
<HideScreenOptions />
|
||||||
{(errors.length > 0 && (
|
|
||||||
<APIErrorsNotice errors={errors.map((error) => ({ message: error }))} />
|
|
||||||
))}
|
|
||||||
|
|
||||||
<Heading level={1} className="mailpoet-title">
|
<Heading level={1} className="mailpoet-title">
|
||||||
<span>{MailPoet.I18n.t('formPageTitle')}</span>
|
<span>{MailPoet.I18n.t('formPageTitle')}</span>
|
||||||
|
@@ -15,6 +15,7 @@ import { FormFilterFields } from './form_filter_fields';
|
|||||||
import { isFormValid } from './validator';
|
import { isFormValid } from './validator';
|
||||||
import { MinusIcon } from '../../common/button/icon/minus';
|
import { MinusIcon } from '../../common/button/icon/minus';
|
||||||
import plusIcon from '../../common/button/icon/plus';
|
import plusIcon from '../../common/button/icon/plus';
|
||||||
|
import APIErrorsNotice from '../../notices/api_errors_notice';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
FilterRow,
|
FilterRow,
|
||||||
@@ -53,6 +54,11 @@ export const Form: React.FunctionComponent<Props> = ({
|
|||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const errors: string[] = useSelect(
|
||||||
|
(select) => select('mailpoet-dynamic-segments-form').getErrors(),
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
const { updateSegment, updateSegmentFilter, handleSave } = useDispatch('mailpoet-dynamic-segments-form');
|
const { updateSegment, updateSegmentFilter, handleSave } = useDispatch('mailpoet-dynamic-segments-form');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -64,6 +70,9 @@ export const Form: React.FunctionComponent<Props> = ({
|
|||||||
{MailPoet.I18n.t('name')}
|
{MailPoet.I18n.t('name')}
|
||||||
</label>
|
</label>
|
||||||
</Heading>
|
</Heading>
|
||||||
|
{(errors.length > 0 && (
|
||||||
|
<APIErrorsNotice errors={errors.map((error) => ({ message: error }))} />
|
||||||
|
))}
|
||||||
<div className="mailpoet-form-field">
|
<div className="mailpoet-form-field">
|
||||||
<Input
|
<Input
|
||||||
isFullWidth
|
isFullWidth
|
||||||
|
Reference in New Issue
Block a user