Refactoring the control to be reusable

[MAILPOET-2676]
This commit is contained in:
Amine Ben hammou
2020-03-10 17:29:37 +01:00
committed by amine-mp
parent 1026b07495
commit 27bf71bad9
3 changed files with 29 additions and 19 deletions

View File

@@ -0,0 +1,16 @@
import MailPoet from 'mailpoet';
export default async function ({ endpoint, action, data }) {
try {
const res = await MailPoet.Ajax.post({
api_version: (window as any).mailpoet_api_version,
endpoint,
action,
data,
});
return { success: true, res };
} catch (res) {
const error = res.errors.map((e) => e.message);
return { success: false, error };
}
}