Add from address authorization modal
[MAILPOET-2681]
This commit is contained in:
committed by
Veljko V
parent
2557586e86
commit
655ce8e649
@@ -1,5 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import jQuery from 'jquery';
|
import jQuery from 'jquery';
|
||||||
|
import 'parsleyjs';
|
||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
import { HashRouter } from 'react-router-dom';
|
import { HashRouter } from 'react-router-dom';
|
||||||
import { GlobalContext, useGlobalContextValue } from 'context';
|
import { GlobalContext, useGlobalContextValue } from 'context';
|
||||||
|
@@ -1,9 +1,11 @@
|
|||||||
import React, { useContext } from 'react';
|
import React, { useContext } from 'react';
|
||||||
import MailPoet from 'mailpoet';
|
import MailPoet from 'mailpoet';
|
||||||
import { useSelector, useAction } from 'settings/store/hooks';
|
import { useSelector, useAction, useSetting } from 'settings/store/hooks';
|
||||||
import { GlobalContext } from 'context';
|
import { GlobalContext } from 'context';
|
||||||
import { t } from 'common/functions';
|
import { t } from 'common/functions';
|
||||||
|
import { MssStatus } from 'settings/store/types';
|
||||||
import { Label, Inputs } from 'settings/components';
|
import { Label, Inputs } from 'settings/components';
|
||||||
|
import SetFromAddressModal from 'common/set_from_address_modal';
|
||||||
import { KeyMessages, MssMessages, PremiumMessages } from './messages';
|
import { KeyMessages, MssMessages, PremiumMessages } from './messages';
|
||||||
|
|
||||||
export default function KeyActivation() {
|
export default function KeyActivation() {
|
||||||
@@ -14,6 +16,8 @@ export default function KeyActivation() {
|
|||||||
const verifyPremiumKey = useAction('verifyPremiumKey');
|
const verifyPremiumKey = useAction('verifyPremiumKey');
|
||||||
const installPremiumPlugin = useAction('installPremiumPlugin');
|
const installPremiumPlugin = useAction('installPremiumPlugin');
|
||||||
const activatePremiumPlugin = useAction('activatePremiumPlugin');
|
const activatePremiumPlugin = useAction('activatePremiumPlugin');
|
||||||
|
const [senderAddress] = useSetting('sender', 'address');
|
||||||
|
const [unauthorizedAddresses] = useSetting('authorized_emails_addresses_check');
|
||||||
|
|
||||||
const verifyKey = async (event) => {
|
const verifyKey = async (event) => {
|
||||||
if (!state.key) {
|
if (!state.key) {
|
||||||
@@ -27,9 +31,15 @@ export default function KeyActivation() {
|
|||||||
premiumInstallationStatus: null,
|
premiumInstallationStatus: null,
|
||||||
});
|
});
|
||||||
MailPoet.Modal.loading(true);
|
MailPoet.Modal.loading(true);
|
||||||
await verifyMssKey(state.key, isTrusted);
|
const mssStatus: MssStatus = (await verifyMssKey(state.key, isTrusted)) as any;
|
||||||
await verifyPremiumKey(state.key);
|
await verifyPremiumKey(state.key);
|
||||||
MailPoet.Modal.loading(false);
|
MailPoet.Modal.loading(false);
|
||||||
|
if (isTrusted) {
|
||||||
|
const authorizedAddressNeeded = !senderAddress || unauthorizedAddresses;
|
||||||
|
if (mssStatus === 'valid_mss_active' && authorizedAddressNeeded) {
|
||||||
|
setState({ showFromAddressModal: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -81,6 +91,11 @@ export default function KeyActivation() {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</Inputs>
|
</Inputs>
|
||||||
|
{state.showFromAddressModal && (
|
||||||
|
<SetFromAddressModal
|
||||||
|
onRequestClose={() => setState({ showFromAddressModal: false })}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import { select } from '@wordpress/data';
|
import { select } from '@wordpress/data';
|
||||||
import MailPoet from 'mailpoet';
|
import MailPoet from 'mailpoet';
|
||||||
import { STORE_NAME } from '.';
|
import { STORE_NAME } from '.';
|
||||||
import { Action, KeyActivationState } from './types';
|
import { Action, KeyActivationState, MssStatus } from './types';
|
||||||
|
|
||||||
export function setSetting(path: string[], value: any): Action {
|
export function setSetting(path: string[], value: any): Action {
|
||||||
return { type: 'SET_SETTING', path, value };
|
return { type: 'SET_SETTING', path, value };
|
||||||
@@ -88,7 +88,8 @@ export function* verifyMssKey(key: string, activateMssIfKeyValid: boolean) {
|
|||||||
} else {
|
} else {
|
||||||
fields.mssStatus = 'valid_mss_not_active';
|
fields.mssStatus = 'valid_mss_not_active';
|
||||||
}
|
}
|
||||||
return updateKeyActivationState(fields);
|
yield updateKeyActivationState(fields);
|
||||||
|
return fields.mssStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function* verifyPremiumKey(key: string) {
|
export function* verifyPremiumKey(key: string) {
|
||||||
|
@@ -27,6 +27,7 @@ export default function makeDefaultState(window: any): State {
|
|||||||
premiumStatus,
|
premiumStatus,
|
||||||
mssMessage: null,
|
mssMessage: null,
|
||||||
premiumMessage: null,
|
premiumMessage: null,
|
||||||
|
showFromAddressModal: false,
|
||||||
premiumInstallationStatus: null,
|
premiumInstallationStatus: null,
|
||||||
key: data.premium.premium_key || data.mta.mailpoet_api_key,
|
key: data.premium.premium_key || data.mta.mailpoet_api_key,
|
||||||
};
|
};
|
||||||
|
@@ -163,6 +163,7 @@ export default function normalizeSettings(data: any): Settings {
|
|||||||
data: asIs,
|
data: asIs,
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
|
authorized_emails_addresses_check: asIs,
|
||||||
});
|
});
|
||||||
return settingsSchema(data) as Settings;
|
return settingsSchema(data) as Settings;
|
||||||
}
|
}
|
||||||
|
@@ -162,6 +162,14 @@ export type Settings = {
|
|||||||
data: any
|
data: any
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
authorized_emails_addresses_check: null | {
|
||||||
|
invalid_sender_address?: string
|
||||||
|
invalid_senders_in_newsletters?: Array<{
|
||||||
|
'subject': string
|
||||||
|
'sender_address': string
|
||||||
|
'newsletter_id': number | string
|
||||||
|
}>
|
||||||
|
}
|
||||||
}
|
}
|
||||||
type Segment = {
|
type Segment = {
|
||||||
id: string
|
id: string
|
||||||
@@ -209,6 +217,7 @@ export type KeyActivationState = {
|
|||||||
mssStatus: MssStatus
|
mssStatus: MssStatus
|
||||||
mssMessage: string
|
mssMessage: string
|
||||||
premiumInstallationStatus: PremiumInstallationStatus
|
premiumInstallationStatus: PremiumInstallationStatus
|
||||||
|
showFromAddressModal: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export type State = {
|
export type State = {
|
||||||
|
Reference in New Issue
Block a user