Implemented first draft of issue modal
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import axios from 'axios';
|
||||
|
||||
import history from 'browserHistory';
|
||||
import toast from 'shared/utils/toast';
|
||||
import { objectToQueryString } from 'shared/utils/url';
|
||||
import { getStoredAuthToken, removeStoredAuthToken } from 'shared/utils/authToken';
|
||||
|
||||
@@ -17,14 +18,14 @@ const defaults = {
|
||||
},
|
||||
};
|
||||
|
||||
const api = (method, url, paramsOrData) =>
|
||||
const api = (method, url, variables) =>
|
||||
new Promise((resolve, reject) => {
|
||||
axios({
|
||||
url: `${defaults.baseURL}${url}`,
|
||||
method,
|
||||
headers: defaults.headers(),
|
||||
params: method === 'get' ? paramsOrData : undefined,
|
||||
data: method !== 'get' ? paramsOrData : undefined,
|
||||
params: method === 'get' ? variables : undefined,
|
||||
data: method !== 'get' ? variables : undefined,
|
||||
paramsSerializer: objectToQueryString,
|
||||
}).then(
|
||||
response => {
|
||||
@@ -45,10 +46,21 @@ const api = (method, url, paramsOrData) =>
|
||||
);
|
||||
});
|
||||
|
||||
const optimisticUpdate = async ({ url, updatedFields, currentFields, setLocalData }) => {
|
||||
try {
|
||||
setLocalData(updatedFields);
|
||||
await api('put', url, updatedFields);
|
||||
} catch (error) {
|
||||
setLocalData(currentFields);
|
||||
toast.error(error);
|
||||
}
|
||||
};
|
||||
|
||||
export default {
|
||||
get: (...args) => api('get', ...args),
|
||||
post: (...args) => api('post', ...args),
|
||||
put: (...args) => api('put', ...args),
|
||||
patch: (...args) => api('patch', ...args),
|
||||
delete: (...args) => api('delete', ...args),
|
||||
optimisticUpdate,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user