Move utility functions to common functions

[MAILPOET-2677]
This commit is contained in:
Amine Ben hammou
2020-03-18 16:45:31 +01:00
committed by Veljko V
parent 50ca3b7310
commit dc0fc44194
16 changed files with 19 additions and 18 deletions

View File

@@ -1,4 +1,3 @@
import MailPoet from 'mailpoet';
import { ChangeEvent } from 'react'; import { ChangeEvent } from 'react';
type Setter = (value: string) => any type Setter = (value: string) => any
@@ -7,7 +6,3 @@ type Event = ChangeEvent<any>
export const onChange = (setter: Setter) => (e: Event) => setter(e.target.value); export const onChange = (setter: Setter) => (e: Event) => setter(e.target.value);
export const onToggle = (setter: Setter) => (e: Event) => setter(e.target.checked ? '1' : '0'); export const onToggle = (setter: Setter) => (e: Event) => setter(e.target.checked ? '1' : '0');
export const t = ([word]: TemplateStringsArray) => MailPoet.I18n.t(word);
export const isEmail = (value: string): boolean => (window as any).mailpoet_email_regex.test(value);

View File

@@ -0,0 +1,3 @@
export * from './change_handlers';
export { default as t } from './t';
export { default as isEmail } from './is_email';

View File

@@ -0,0 +1 @@
export default (value: string): boolean => (window as any).mailpoet_email_regex.test(value);

View File

@@ -0,0 +1,3 @@
import MailPoet from 'mailpoet';
export default ([word]: TemplateStringsArray) => MailPoet.I18n.t(word);

View File

@@ -1,6 +1,6 @@
import React from 'react'; import React from 'react';
import { onChange, t } from 'settings/utils';
import { useSelector } from 'settings/store/hooks'; import { useSelector } from 'settings/store/hooks';
import { onChange, t } from 'common/functions';
type Props = { type Props = {
id?: string id?: string

View File

@@ -1,7 +1,7 @@
import React from 'react'; import React from 'react';
import { useLocation } from 'react-router-dom'; import { useLocation } from 'react-router-dom';
import { t } from 'common/functions';
import { useSelector } from 'settings/store/hooks'; import { useSelector } from 'settings/store/hooks';
import { t } from 'settings/utils';
import TabLink from './tab_link'; import TabLink from './tab_link';
export default () => { export default () => {

View File

@@ -1,6 +1,6 @@
import React from 'react'; import React from 'react';
import { t, onChange, isEmail } from 'settings/utils';
import { Label, Inputs } from 'settings/components'; import { Label, Inputs } from 'settings/components';
import { isEmail, t, onChange } from 'common/functions';
import { useSetting, useSelector, useAction } from 'settings/store/hooks'; import { useSetting, useSelector, useAction } from 'settings/store/hooks';
import SenderEmailAddressWarning from 'common/sender_email_address_warning.jsx'; import SenderEmailAddressWarning from 'common/sender_email_address_warning.jsx';

View File

@@ -1,5 +1,5 @@
import React from 'react'; import React from 'react';
import { t } from 'settings/utils'; import { t } from 'common/functions';
import { Label, Inputs } from 'settings/components'; import { Label, Inputs } from 'settings/components';
export default function GdprCompliant() { export default function GdprCompliant() {

View File

@@ -1,6 +1,6 @@
import React from 'react'; import React from 'react';
import { SaveButton } from 'settings/components'; import { SaveButton } from 'settings/components';
import { t } from 'settings/utils'; import { t } from 'common/functions';
import DefaultSender from './default_sender'; import DefaultSender from './default_sender';
import SubscribeOn from './subscribe_on'; import SubscribeOn from './subscribe_on';
import ManageSubscription from './manage_subscription'; import ManageSubscription from './manage_subscription';

View File

@@ -1,5 +1,5 @@
import React from 'react'; import React from 'react';
import { t } from 'settings/utils'; import { t } from 'common/functions';
import { useSetting } from 'settings/store/hooks'; import { useSetting } from 'settings/store/hooks';
import { import {
Label, Inputs, SegmentsSelect, PagesSelect, Label, Inputs, SegmentsSelect, PagesSelect,

View File

@@ -1,5 +1,5 @@
import React from 'react'; import React from 'react';
import { t, onChange, isEmail } from 'settings/utils'; import { t, onChange, isEmail } from 'common/functions';
import { useSetting, useAction } from 'settings/store/hooks'; import { useSetting, useAction } from 'settings/store/hooks';
import { Label, Inputs } from 'settings/components'; import { Label, Inputs } from 'settings/components';

View File

@@ -1,5 +1,5 @@
import React from 'react'; import React from 'react';
import { t } from 'settings/utils'; import { t } from 'common/functions';
import { Label, Inputs, SegmentsSelect } from 'settings/components'; import { Label, Inputs, SegmentsSelect } from 'settings/components';
type Props = { type Props = {

View File

@@ -1,7 +1,7 @@
import React from 'react'; import React from 'react';
import { import {
t, onToggle, onChange, isEmail, t, onToggle, onChange, isEmail,
} from 'settings/utils'; } from 'common/functions';
import { useSetting, useAction } from 'settings/store/hooks'; import { useSetting, useAction } from 'settings/store/hooks';
import { Label, Inputs } from 'settings/components'; import { Label, Inputs } from 'settings/components';

View File

@@ -1,5 +1,5 @@
import React from 'react'; import React from 'react';
import { t, onChange, onToggle } from 'settings/utils'; import { t, onChange, onToggle } from 'common/functions';
import { useSetting } from 'settings/store/hooks'; import { useSetting } from 'settings/store/hooks';
import { Label, Inputs, SegmentsSelect } from 'settings/components'; import { Label, Inputs, SegmentsSelect } from 'settings/components';

View File

@@ -1,5 +1,5 @@
import React from 'react'; import React from 'react';
import { t } from 'settings/utils'; import { t } from 'common/functions';
import { useSetting } from 'settings/store/hooks'; import { useSetting } from 'settings/store/hooks';
import { Label, Inputs, PagesSelect } from 'settings/components'; import { Label, Inputs, PagesSelect } from 'settings/components';

View File

@@ -1,8 +1,8 @@
import React from 'react'; import React from 'react';
import { Switch, Route, Redirect } from 'react-router-dom'; import { Switch, Route, Redirect } from 'react-router-dom';
import Notices from 'notices/notices.jsx'; import Notices from 'notices/notices.jsx';
import MailPoet from 'mailpoet';
import Loading from 'common/loading'; import Loading from 'common/loading';
import { t } from 'common/functions';
import { import {
Advanced, Advanced,
Basics, Basics,
@@ -12,7 +12,6 @@ import {
WooCommerce, WooCommerce,
} from './pages'; } from './pages';
import Tabs from './components/tabs'; import Tabs from './components/tabs';
import { t } from './utils';
import { useSelector } from './store/hooks'; import { useSelector } from './store/hooks';
export default function Settings() { export default function Settings() {