Update the store after setting an authorized address
[MAILPOET-2681]
This commit is contained in:
committed by
Veljko V
parent
9877ed3573
commit
af4225bc87
@@ -7,7 +7,7 @@ import { GlobalContext } from 'context';
|
||||
|
||||
const mailPoetApiVersion = (window as any).mailpoet_api_version as string;
|
||||
|
||||
const handleSave = async (address: string|null) => MailPoet.Ajax.post({
|
||||
const handleSave = async (address: string | null) => MailPoet.Ajax.post({
|
||||
api_version: mailPoetApiVersion,
|
||||
endpoint: 'settings',
|
||||
action: 'setAuthorizedFromAddress',
|
||||
@@ -16,7 +16,7 @@ const handleSave = async (address: string|null) => MailPoet.Ajax.post({
|
||||
},
|
||||
});
|
||||
|
||||
const getErrorMessage = (error: any|null): string => {
|
||||
const getErrorMessage = (error: any | null): string => {
|
||||
if (!error) {
|
||||
return MailPoet.I18n.t('setFromAddressEmailUnknownError');
|
||||
}
|
||||
@@ -33,7 +33,7 @@ const getErrorMessage = (error: any|null): string => {
|
||||
|
||||
const getSuccessMessage = (): JSX.Element => (
|
||||
<p>
|
||||
{ ReactStringReplace(
|
||||
{ReactStringReplace(
|
||||
MailPoet.I18n.t('setFromAddressEmailSuccess'),
|
||||
/\[link\](.*?)\[\/link\]/g,
|
||||
(match) => (
|
||||
@@ -66,9 +66,10 @@ const removeUnauthorizedEmailNotices = () => {
|
||||
|
||||
type Props = {
|
||||
onRequestClose: () => void,
|
||||
setAuthorizedAddress: (address: string) => any,
|
||||
};
|
||||
|
||||
const SetFromAddressModal = ({ onRequestClose }: Props) => {
|
||||
const SetFromAddressModal = ({ onRequestClose, setAuthorizedAddress }: Props) => {
|
||||
const [address, setAddress] = useState(null);
|
||||
const { notices } = React.useContext<any>(GlobalContext);
|
||||
|
||||
@@ -125,6 +126,7 @@ const SetFromAddressModal = ({ onRequestClose }: Props) => {
|
||||
}
|
||||
try {
|
||||
await handleSave(address);
|
||||
setAuthorizedAddress(address);
|
||||
onRequestClose();
|
||||
removeUnauthorizedEmailNotices();
|
||||
notices.success(getSuccessMessage(), { timeout: false });
|
||||
|
@@ -16,8 +16,13 @@ export default function KeyActivation() {
|
||||
const verifyPremiumKey = useAction('verifyPremiumKey');
|
||||
const installPremiumPlugin = useAction('installPremiumPlugin');
|
||||
const activatePremiumPlugin = useAction('activatePremiumPlugin');
|
||||
const [senderAddress] = useSetting('sender', 'address');
|
||||
const [unauthorizedAddresses] = useSetting('authorized_emails_addresses_check');
|
||||
const [senderAddress, setSenderAddress] = useSetting('sender', 'address');
|
||||
const [unauthorizedAddresses, setUnauthorizedAddresses] = useSetting('authorized_emails_addresses_check');
|
||||
|
||||
const setAuthorizedAddress = async (address: string) => {
|
||||
await setSenderAddress(address);
|
||||
await setUnauthorizedAddresses(null);
|
||||
};
|
||||
|
||||
const verifyKey = async (event) => {
|
||||
if (!state.key) {
|
||||
@@ -94,6 +99,7 @@ export default function KeyActivation() {
|
||||
{state.showFromAddressModal && (
|
||||
<SetFromAddressModal
|
||||
onRequestClose={() => setState({ showFromAddressModal: false })}
|
||||
setAuthorizedAddress={setAuthorizedAddress}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user