Refactoring the control to be reusable
[MAILPOET-2676]
This commit is contained in:
committed by
amine-mp
parent
1026b07495
commit
27bf71bad9
16
assets/js/src/common/controls/call_api.ts
Normal file
16
assets/js/src/common/controls/call_api.ts
Normal 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 };
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user