refactoring: migrating to react-query to manage service-side state.

This commit is contained in:
a.bouhuolia
2021-02-07 08:10:21 +02:00
parent e093be0663
commit adac2386bb
284 changed files with 8255 additions and 6610 deletions

View File

@@ -0,0 +1,91 @@
import { useMutation, useQuery, useQueryClient } from 'react-query';
import ApiService from 'services/ApiService';
const transformPaymentReceives = (response) => {
return {};
};
/**
* Retrieve accounts list.
*/
export function usePaymentReceives(query, props) {
return useQuery(
['PAYMENT_RECEIVES', query],
() =>
ApiService.get('sales/payment_receives', { params: query }).then(
transformPaymentReceives,
),
{
initialData: [],
...props,
},
);
}
/**
* Creates payment receive.
*/
export function useCreatePaymentReceive(props) {
const client = useQueryClient();
return useMutation(
(values) => ApiService.post('sales/payment_receives', values),
{
onSuccess: () => {
client.invalidateQueries('PAYMENT_RECEIVES');
},
...props,
},
);
}
/**
* Edits payment receive.
*/
export function useEditPaymentReceive(props) {
const client = useQueryClient();
return useMutation(
(id, values) => ApiService.post(`sales/payment_receives/${id}`, values),
{
onSuccess: () => {
client.invalidateQueries('PAYMENT_RECEIVES');
},
...props,
},
);
}
/**
* Deletes payment receive.
*/
export function useDeletePaymentReceive(props) {
const client = useQueryClient();
return useMutation(
(id, values) => ApiService.delete(`sales/payment_receives/${id}`, values),
{
onSuccess: () => {
client.invalidateQueries('PAYMENT_RECEIVES');
},
...props,
},
);
}
/**
* Retrieve specific payment receive.
*/
export function usePaymentReceive(id, props) {
return useQuery(
['PAYMENT_RECEIVE', id],
() =>
ApiService.get(`sales/payment_receives/${id}`).then(
transformPaymentReceives,
),
{
initialData: [],
...props,
},
);
}