| 1 |
import apiFetch from '@wordpress/api-fetch'; |
| 2 |
|
| 3 |
const cfg = window.wpzfBuilder || {}; |
| 4 |
|
| 5 |
apiFetch.use( apiFetch.createNonceMiddleware( cfg.nonce || '' ) ); |
| 6 |
apiFetch.use( apiFetch.createRootURLMiddleware( cfg.apiRoot ? cfg.apiRoot.replace( /\/wpzf\/v1$/, '/' ) : '/wp-json/' ) ); |
| 7 |
|
| 8 |
const base = '/wpzf/v1'; |
| 9 |
|
| 10 |
export const api = { |
| 11 |
getForm: ( id ) => apiFetch( { path: `${ base }/forms/${ id }` } ), |
| 12 |
listForms: () => apiFetch( { path: `${ base }/forms` } ), |
| 13 |
createForm: ( opts = {} ) => apiFetch( { path: `${ base }/forms`, method: 'POST', data: opts } ), |
| 14 |
updateForm: ( id, payload ) => apiFetch( { path: `${ base }/forms/${ id }`, method: 'PUT', data: payload } ), |
| 15 |
deleteForm: ( id ) => apiFetch( { path: `${ base }/forms/${ id }`, method: 'DELETE' } ), |
| 16 |
duplicateForm: ( id ) => apiFetch( { path: `${ base }/forms/${ id }/duplicate`, method: 'POST' } ), |
| 17 |
getTemplates: () => apiFetch( { path: `${ base }/templates` } ), |
| 18 |
getOptionLists: () => apiFetch( { path: `${ base }/option-lists` } ), |
| 19 |
}; |
| 20 |
|