mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 22:30:31 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c3a4fe6b37 | ||
|
|
02be959461 |
@@ -3,6 +3,7 @@ import { useQuery } from 'react-query';
|
|||||||
import { castArray, defaultTo } from 'lodash';
|
import { castArray, defaultTo } from 'lodash';
|
||||||
import { useAuthOrganizationId } from './state';
|
import { useAuthOrganizationId } from './state';
|
||||||
import useApiRequest from './useRequest';
|
import useApiRequest from './useRequest';
|
||||||
|
import { normalizeApiPath } from '../utils';
|
||||||
import { useRef } from 'react';
|
import { useRef } from 'react';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -19,7 +20,11 @@ export function useRequestQuery(query, axios, props) {
|
|||||||
|
|
||||||
const states = useQuery(
|
const states = useQuery(
|
||||||
query,
|
query,
|
||||||
() => apiRequest.http({ ...axios, url: `/api/${axios.url}` }),
|
() =>
|
||||||
|
apiRequest.http({
|
||||||
|
...axios,
|
||||||
|
url: `/api/${normalizeApiPath(axios.url)}`,
|
||||||
|
}),
|
||||||
props,
|
props,
|
||||||
);
|
);
|
||||||
// Momerize the default data.
|
// Momerize the default data.
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import {
|
|||||||
useSetGlobalErrors,
|
useSetGlobalErrors,
|
||||||
useAuthToken,
|
useAuthToken,
|
||||||
} from './state';
|
} from './state';
|
||||||
import { getCookie } from '../utils';
|
import { getCookie, normalizeApiPath } from '../utils';
|
||||||
|
|
||||||
export default function useApiRequest() {
|
export default function useApiRequest() {
|
||||||
const setGlobalErrors = useSetGlobalErrors();
|
const setGlobalErrors = useSetGlobalErrors();
|
||||||
@@ -93,27 +93,27 @@ export default function useApiRequest() {
|
|||||||
http,
|
http,
|
||||||
|
|
||||||
get(resource, params) {
|
get(resource, params) {
|
||||||
return http.get(`/api/${resource}`, params);
|
return http.get(`/api/${normalizeApiPath(resource)}`, params);
|
||||||
},
|
},
|
||||||
|
|
||||||
post(resource, params, config) {
|
post(resource, params, config) {
|
||||||
return http.post(`/api/${resource}`, params, config);
|
return http.post(`/api/${normalizeApiPath(resource)}`, params, config);
|
||||||
},
|
},
|
||||||
|
|
||||||
update(resource, slug, params) {
|
update(resource, slug, params) {
|
||||||
return http.put(`/api/${resource}/${slug}`, params);
|
return http.put(`/api/${normalizeApiPath(resource)}/${slug}`, params);
|
||||||
},
|
},
|
||||||
|
|
||||||
put(resource, params) {
|
put(resource, params) {
|
||||||
return http.put(`/api/${resource}`, params);
|
return http.put(`/api/${normalizeApiPath(resource)}`, params);
|
||||||
},
|
},
|
||||||
|
|
||||||
patch(resource, params, config) {
|
patch(resource, params, config) {
|
||||||
return http.patch(`/api/${resource}`, params, config);
|
return http.patch(`/api/${normalizeApiPath(resource)}`, params, config);
|
||||||
},
|
},
|
||||||
|
|
||||||
delete(resource, params) {
|
delete(resource, params) {
|
||||||
return http.delete(`/api/${resource}`, params);
|
return http.delete(`/api/${normalizeApiPath(resource)}`, params);
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
[http],
|
[http],
|
||||||
@@ -130,22 +130,22 @@ export function useAuthApiRequest() {
|
|||||||
() => ({
|
() => ({
|
||||||
http,
|
http,
|
||||||
get(resource, params) {
|
get(resource, params) {
|
||||||
return http.get(`/api/${resource}`, params);
|
return http.get(`/api/${normalizeApiPath(resource)}`, params);
|
||||||
},
|
},
|
||||||
post(resource, params, config) {
|
post(resource, params, config) {
|
||||||
return http.post(`/api/${resource}`, params, config);
|
return http.post(`/api/${normalizeApiPath(resource)}`, params, config);
|
||||||
},
|
},
|
||||||
update(resource, slug, params) {
|
update(resource, slug, params) {
|
||||||
return http.put(`/api/${resource}/${slug}`, params);
|
return http.put(`/api/${normalizeApiPath(resource)}/${slug}`, params);
|
||||||
},
|
},
|
||||||
put(resource, params) {
|
put(resource, params) {
|
||||||
return http.put(`/api/${resource}`, params);
|
return http.put(`/api/${normalizeApiPath(resource)}`, params);
|
||||||
},
|
},
|
||||||
patch(resource, params, config) {
|
patch(resource, params, config) {
|
||||||
return http.patch(`/api/${resource}`, params, config);
|
return http.patch(`/api/${normalizeApiPath(resource)}`, params, config);
|
||||||
},
|
},
|
||||||
delete(resource, params) {
|
delete(resource, params) {
|
||||||
return http.delete(`/api/${resource}`, params);
|
return http.delete(`/api/${normalizeApiPath(resource)}`, params);
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
[http],
|
[http],
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ import jsCookie from 'js-cookie';
|
|||||||
import { deepMapKeys } from './map-key-deep';
|
import { deepMapKeys } from './map-key-deep';
|
||||||
export * from './deep';
|
export * from './deep';
|
||||||
|
|
||||||
|
/** Strips leading slash from a path segment to avoid double slashes when joining with a base (e.g. `/api/` + path). */
|
||||||
|
export const normalizeApiPath = (path) => (path || '').replace(/^\//, '');
|
||||||
|
|
||||||
export const getCookie = (name, defaultValue) =>
|
export const getCookie = (name, defaultValue) =>
|
||||||
_.defaultTo(jsCookie.get(name), defaultValue);
|
_.defaultTo(jsCookie.get(name), defaultValue);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user