PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.15.1
GiveWP – Donation Plugin and Fundraising Platform v4.15.1
4.17.0 4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 All 256 releases
give / src / MigrationLog / Admin / Migrations / api.js

api.js in GiveWP – Donation Plugin and Fundraising Platform 4.15.1, at src/MigrationLog/Admin/Migrations/api.js

49 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import axios from 'axios';
2 import useSWR from 'swr';
3
4 const API = axios.create({
5 baseURL: window.GiveMigrations.apiRoot,
6 headers: {
7 'Content-Type': 'application/json',
8 'X-WP-Nonce': window.GiveMigrations.apiNonce,
9 },
10 });
11
12 export default API;
13
14 export const CancelToken = axios.CancelToken.source();
15
16 // SWR Fetcher
17 export const Fetcher = (endpoint) =>
18 API.get(endpoint).then((res) => {
19 const {data, ...rest} = res.data;
20 return {
21 data,
22 response: rest,
23 };
24 });
25
26 export const useMigrationFetcher = (endpoint, params = {}) => {
27 const {data, error, mutate} = useSWR(endpoint, Fetcher, params);
28 return {
29 data: data ? data.data : undefined,
30 isLoading: !error && !data,
31 isError: error,
32 response: data ? data.response : undefined,
33 mutate,
34 };
35 };
36
37 // GET endpoint with additional parameters
38 export const getEndpoint = (endpoint, data) => {
39 if (data) {
40 const queryString = new URLSearchParams(data);
41 // pretty url?
42 const separator = window.GiveMigrations.apiRoot.indexOf('?') === -1 ? '?' : '&';
43
44 return endpoint + separator + queryString.toString();
45 }
46
47 return endpoint;
48 };
49