mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 22:30:31 +00:00
refactoring: migrating to react-query to manage service-side state.
This commit is contained in:
41
client/src/hooks/query/currencies.js
Normal file
41
client/src/hooks/query/currencies.js
Normal file
@@ -0,0 +1,41 @@
|
||||
import { useMutation, useQuery } from 'react-query';
|
||||
import ApiService from 'services/ApiService';
|
||||
|
||||
/**
|
||||
* Create a new currency.
|
||||
*/
|
||||
export function useCreateCurrency() {
|
||||
return useMutation((values) => ApiService.post('currencies', values));
|
||||
}
|
||||
|
||||
/**
|
||||
* Edits the given currency code.
|
||||
*/
|
||||
export function useEditCurrency() {
|
||||
return useMutation((currencyCode, values) =>
|
||||
ApiService.post(`currencies/${currencyCode}`, values),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the given currency.
|
||||
*/
|
||||
export function useDeleteCurrency() {
|
||||
return useMutation((currencyCode) =>
|
||||
ApiService.delete(`currencies/${currencyCode}`),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the currencies list.
|
||||
*/
|
||||
export function useCurrencies(props) {
|
||||
return useQuery(
|
||||
['CURRENCIES'],
|
||||
() => ApiService.get('currencies').then(res => res.data.currencies),
|
||||
{
|
||||
initialData: [],
|
||||
...props,
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user