mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 04:40:32 +00:00
fix(exchangeRate): fix pagination & add sorting.
This commit is contained in:
@@ -1,7 +1,13 @@
|
||||
import { useQuery, useMutation, useQueryClient } from 'react-query';
|
||||
import { defaultTo } from 'lodash';
|
||||
import { transformPagination, transformResponse } from 'utils';
|
||||
import useApiRequest from '../useRequest';
|
||||
|
||||
const defaultPagination = {
|
||||
pageSize: 12,
|
||||
page: 0,
|
||||
pagesCount: 0,
|
||||
};
|
||||
/**
|
||||
* Creates a new exchange rate.
|
||||
*/
|
||||
@@ -50,14 +56,6 @@ export function useDeleteExchangeRate(props) {
|
||||
});
|
||||
}
|
||||
|
||||
// Transforms items categories.
|
||||
const transformExchangesRates = (response) => {
|
||||
return {
|
||||
exchangesRates: response.data.exchange_rates.results,
|
||||
pagination: response.data.exchange_rates.pagination,
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieve the exchange rate list.
|
||||
*/
|
||||
@@ -66,18 +64,27 @@ export function useExchangeRates(query, props) {
|
||||
|
||||
const states = useQuery(
|
||||
['EXCHANGES_RATES', query],
|
||||
() =>
|
||||
apiRequest.get('exchange_rates', { params: { query } }).then(
|
||||
transformExchangesRates,
|
||||
),
|
||||
props,
|
||||
() => apiRequest.get('exchange_rates', { params: query }),
|
||||
{
|
||||
select: (res) => ({
|
||||
exchangesRates: res.data.exchange_rates.results,
|
||||
pagination: transformPagination(res.data.exchange_rates.pagination),
|
||||
filterMeta: res.data.filter_meta,
|
||||
}),
|
||||
...props,
|
||||
},
|
||||
);
|
||||
|
||||
return {
|
||||
...states,
|
||||
data: defaultTo(states.data, {
|
||||
exchangesRates: [],
|
||||
pagination: {},
|
||||
pagination: {
|
||||
page: 1,
|
||||
pageSize: 12,
|
||||
total: 0,
|
||||
},
|
||||
filterMeta: {},
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user