mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 13:50:31 +00:00
feat (*) : add referch button.
This commit is contained in:
@@ -160,3 +160,13 @@ export function useAccountTransactions(id, props) {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export function useRefreshAccounts() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return {
|
||||
refresh: () => {
|
||||
queryClient.invalidateQueries(t.ACCOUNTS);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ export function useDeleteBill(props) {
|
||||
});
|
||||
}
|
||||
|
||||
const transformBillsResponse = (response) => ({
|
||||
const transformBillsResponse = (response) => ({
|
||||
bills: response.data.bills,
|
||||
pagination: transformPagination(response.data.pagination),
|
||||
filterMeta: response.data.filter_meta,
|
||||
@@ -131,7 +131,7 @@ export function useBills(query, props) {
|
||||
export function useBill(id, props) {
|
||||
return useRequestQuery(
|
||||
[t.BILL, id],
|
||||
{ method: 'get', url: `/purchases/bills/${id}`, },
|
||||
{ method: 'get', url: `/purchases/bills/${id}` },
|
||||
{
|
||||
select: (res) => res.data.bill,
|
||||
defaultData: {},
|
||||
@@ -159,3 +159,13 @@ export function useDueBills(vendorId, props) {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export function useRefreshBills() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return {
|
||||
refresh: () => {
|
||||
queryClient.invalidateQueries(t.BILLS);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ const commonInvalidateQueries = (queryClient) => {
|
||||
const customersSelector = (response) => ({
|
||||
customers: response.data.customers,
|
||||
pagination: transformPagination(response.data.pagination),
|
||||
filterMeta: response.data.filter_meta,
|
||||
filterMeta: response.data.filter_meta,
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -66,7 +66,7 @@ export function useEditCustomer(props) {
|
||||
// Common invalidate queries.
|
||||
commonInvalidateQueries(queryClient);
|
||||
},
|
||||
...props
|
||||
...props,
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -78,19 +78,16 @@ export function useDeleteCustomer(props) {
|
||||
const queryClient = useQueryClient();
|
||||
const apiRequest = useApiRequest();
|
||||
|
||||
return useMutation(
|
||||
(id) => apiRequest.delete(`customers/${id}`),
|
||||
{
|
||||
onSuccess: (res, id) => {
|
||||
// Invalidate specific customer.
|
||||
queryClient.invalidateQueries([t.CUSTOMER, id]);
|
||||
return useMutation((id) => apiRequest.delete(`customers/${id}`), {
|
||||
onSuccess: (res, id) => {
|
||||
// Invalidate specific customer.
|
||||
queryClient.invalidateQueries([t.CUSTOMER, id]);
|
||||
|
||||
// Common invalidate queries.
|
||||
commonInvalidateQueries(queryClient);
|
||||
},
|
||||
...props,
|
||||
}
|
||||
);
|
||||
// Common invalidate queries.
|
||||
commonInvalidateQueries(queryClient);
|
||||
},
|
||||
...props,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,15 +97,13 @@ export function useCreateCustomer(props) {
|
||||
const queryClient = useQueryClient();
|
||||
const apiRequest = useApiRequest();
|
||||
|
||||
return useMutation(
|
||||
(values) => apiRequest.post('customers', values),
|
||||
{
|
||||
onSuccess: () => {
|
||||
// Common invalidate queries.
|
||||
commonInvalidateQueries(queryClient);
|
||||
},
|
||||
...props
|
||||
});
|
||||
return useMutation((values) => apiRequest.post('customers', values), {
|
||||
onSuccess: () => {
|
||||
// Common invalidate queries.
|
||||
commonInvalidateQueries(queryClient);
|
||||
},
|
||||
...props,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -121,7 +116,17 @@ export function useCustomer(id, props) {
|
||||
{
|
||||
select: (res) => res.data.customer,
|
||||
defaultData: {},
|
||||
...props
|
||||
...props,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export function useRefreshCustomers() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return {
|
||||
refresh: () => {
|
||||
queryClient.invalidateQueries(t.CUSTOMERS);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import useApiRequest from '../useRequest';
|
||||
import { transformPagination } from 'utils';
|
||||
import t from './types';
|
||||
|
||||
|
||||
const commonInvalidateQueries = (queryClient) => {
|
||||
// Invalidate estimates.
|
||||
queryClient.invalidateQueries(t.SALE_ESTIMATES);
|
||||
@@ -69,7 +68,7 @@ export function useEstimate(id, props) {
|
||||
const transformEstimates = (res) => ({
|
||||
estimates: res.data.sales_estimates,
|
||||
pagination: transformPagination(res.data.pagination),
|
||||
filterMeta: res.data.filter_meta,
|
||||
filterMeta: res.data.filter_meta,
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -121,19 +120,16 @@ export function useDeliverEstimate(props) {
|
||||
const queryClient = useQueryClient();
|
||||
const apiRequest = useApiRequest();
|
||||
|
||||
return useMutation(
|
||||
(id) => apiRequest.post(`sales/estimates/${id}/deliver`),
|
||||
{
|
||||
onSuccess: (res, id) => {
|
||||
// Common invalidate queries.
|
||||
commonInvalidateQueries(queryClient);
|
||||
return useMutation((id) => apiRequest.post(`sales/estimates/${id}/deliver`), {
|
||||
onSuccess: (res, id) => {
|
||||
// Common invalidate queries.
|
||||
commonInvalidateQueries(queryClient);
|
||||
|
||||
// Invalidate specific sale estimate.
|
||||
queryClient.invalidateQueries([t.SALE_ESTIMATE, id]);
|
||||
},
|
||||
...props,
|
||||
// Invalidate specific sale estimate.
|
||||
queryClient.invalidateQueries([t.SALE_ESTIMATE, id]);
|
||||
},
|
||||
);
|
||||
...props,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -143,19 +139,16 @@ export function useApproveEstimate(props) {
|
||||
const queryClient = useQueryClient();
|
||||
const apiRequest = useApiRequest();
|
||||
|
||||
return useMutation(
|
||||
(id) => apiRequest.post(`sales/estimates/${id}/approve`),
|
||||
{
|
||||
onSuccess: (res, id) => {
|
||||
// Common invalidate queries.
|
||||
commonInvalidateQueries(queryClient);
|
||||
return useMutation((id) => apiRequest.post(`sales/estimates/${id}/approve`), {
|
||||
onSuccess: (res, id) => {
|
||||
// Common invalidate queries.
|
||||
commonInvalidateQueries(queryClient);
|
||||
|
||||
// Invalidate specific sale estimate.
|
||||
queryClient.invalidateQueries([t.SALE_ESTIMATE, id]);
|
||||
},
|
||||
...props,
|
||||
// Invalidate specific sale estimate.
|
||||
queryClient.invalidateQueries([t.SALE_ESTIMATE, id]);
|
||||
},
|
||||
);
|
||||
...props,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -165,17 +158,24 @@ export function useRejectEstimate(props) {
|
||||
const queryClient = useQueryClient();
|
||||
const apiRequest = useApiRequest();
|
||||
|
||||
return useMutation(
|
||||
(id) => apiRequest.post(`sales/estimates/${id}/reject`),
|
||||
{
|
||||
onSuccess: (res, id) => {
|
||||
// Common invalidate queries.
|
||||
commonInvalidateQueries(queryClient);
|
||||
return useMutation((id) => apiRequest.post(`sales/estimates/${id}/reject`), {
|
||||
onSuccess: (res, id) => {
|
||||
// Common invalidate queries.
|
||||
commonInvalidateQueries(queryClient);
|
||||
|
||||
// Invalidate specific sale estimate.
|
||||
queryClient.invalidateQueries([t.SALE_ESTIMATE, id]);
|
||||
},
|
||||
...props,
|
||||
// Invalidate specific sale estimate.
|
||||
queryClient.invalidateQueries([t.SALE_ESTIMATE, id]);
|
||||
},
|
||||
);
|
||||
...props,
|
||||
});
|
||||
}
|
||||
|
||||
export function useRefreshEstimates() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return {
|
||||
refresh: () => {
|
||||
queryClient.invalidateQueries(t.SALE_ESTIMATES);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -89,3 +89,13 @@ export function useExchangeRates(query, props) {
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
export function useRefreshExchangeRate() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return {
|
||||
refresh: () => {
|
||||
queryClient.invalidateQueries('EXCHANGES_RATES');
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -146,3 +146,13 @@ export function usePublishExpense(props) {
|
||||
...props,
|
||||
});
|
||||
}
|
||||
|
||||
export function useRefreshExpenses() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return {
|
||||
refresh: () => {
|
||||
queryClient.invalidateQueries(t.EXPENSES);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -176,3 +176,13 @@ export function useDueInvoices(customerId, props) {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export function useRefreshInvoices() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return {
|
||||
refresh: () => {
|
||||
queryClient.invalidateQueries(t.SALE_INVOICES);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -31,16 +31,13 @@ export function useCreateJournal(props) {
|
||||
const queryClient = useQueryClient();
|
||||
const apiRequest = useApiRequest();
|
||||
|
||||
return useMutation(
|
||||
(values) => apiRequest.post('manual-journals', values),
|
||||
{
|
||||
onSuccess: () => {
|
||||
// Common invalidate queries.
|
||||
commonInvalidateQueries(queryClient);
|
||||
},
|
||||
...props
|
||||
return useMutation((values) => apiRequest.post('manual-journals', values), {
|
||||
onSuccess: () => {
|
||||
// Common invalidate queries.
|
||||
commonInvalidateQueries(queryClient);
|
||||
},
|
||||
);
|
||||
...props,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,7 +57,7 @@ export function useEditJournal(props) {
|
||||
// Common invalidate queries.
|
||||
commonInvalidateQueries(queryClient);
|
||||
},
|
||||
...props
|
||||
...props,
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -72,18 +69,15 @@ export function useDeleteJournal(props) {
|
||||
const queryClient = useQueryClient();
|
||||
const apiRequest = useApiRequest();
|
||||
|
||||
return useMutation(
|
||||
(id) => apiRequest.delete(`manual-journals/${id}`),
|
||||
{
|
||||
onSuccess: (res, id) => {
|
||||
// Invalidate specific manual journal.
|
||||
queryClient.invalidateQueries(t.MANUAL_JOURNAL, id);
|
||||
return useMutation((id) => apiRequest.delete(`manual-journals/${id}`), {
|
||||
onSuccess: (res, id) => {
|
||||
// Invalidate specific manual journal.
|
||||
queryClient.invalidateQueries(t.MANUAL_JOURNAL, id);
|
||||
|
||||
commonInvalidateQueries(queryClient);
|
||||
},
|
||||
...props
|
||||
commonInvalidateQueries(queryClient);
|
||||
},
|
||||
);
|
||||
...props,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,24 +87,21 @@ export function usePublishJournal(props) {
|
||||
const queryClient = useQueryClient();
|
||||
const apiRequest = useApiRequest();
|
||||
|
||||
return useMutation(
|
||||
(id) => apiRequest.post(`manual-journals/${id}/publish`),
|
||||
{
|
||||
onSuccess: (res, id) => {
|
||||
// Invalidate specific manual journal.
|
||||
queryClient.invalidateQueries(t.MANUAL_JOURNAL, id);
|
||||
return useMutation((id) => apiRequest.post(`manual-journals/${id}/publish`), {
|
||||
onSuccess: (res, id) => {
|
||||
// Invalidate specific manual journal.
|
||||
queryClient.invalidateQueries(t.MANUAL_JOURNAL, id);
|
||||
|
||||
commonInvalidateQueries(queryClient);
|
||||
},
|
||||
...props
|
||||
commonInvalidateQueries(queryClient);
|
||||
},
|
||||
);
|
||||
...props,
|
||||
});
|
||||
}
|
||||
|
||||
const transformJournals = (response) => ({
|
||||
manualJournals: response.data.manual_journals,
|
||||
pagination: transformPagination(response.data.pagination),
|
||||
filterMeta: response.data.filter_meta
|
||||
filterMeta: response.data.filter_meta,
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -146,3 +137,13 @@ export function useJournal(id, props) {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export function useRefreshJournals() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return {
|
||||
refresh: () => {
|
||||
queryClient.invalidateQueries(t.MANUAL_JOURNALS);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -4,11 +4,10 @@ import { transformPagination } from 'utils';
|
||||
import useApiRequest from '../useRequest';
|
||||
import t from './types';
|
||||
|
||||
|
||||
const commonInvalidateQueries = (client) => {
|
||||
// Invalidate payment mades.
|
||||
client.invalidateQueries(t.PAYMENT_MADES);
|
||||
|
||||
|
||||
// Invalidate payment made new entries.
|
||||
client.invalidateQueries(t.PAYMENT_MADE_NEW_ENTRIES);
|
||||
client.invalidateQueries(t.PAYMENT_MADE_EDIT_PAGE);
|
||||
@@ -158,3 +157,13 @@ export function usePaymentMadeNewPageEntries(vendorId, props) {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export function useRefreshPaymentMades() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return {
|
||||
refresh: () => {
|
||||
queryClient.invalidateQueries(t.PAYMENT_MADES);
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -30,7 +30,7 @@ const commonInvalidateQueries = (client) => {
|
||||
const transformPaymentReceives = (res) => ({
|
||||
paymentReceives: res.data.payment_receives,
|
||||
pagination: transformPagination(res.data.pagination),
|
||||
filterMeta: res.data.filter_meta,
|
||||
filterMeta: res.data.filter_meta,
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -160,3 +160,13 @@ export function usePaymentReceiveEditPage(id, props) {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export function useRefreshPaymentReceive() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return {
|
||||
refresh: () => {
|
||||
queryClient.invalidateQueries(t.PAYMENT_RECEIVES);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ export function useCloseReceipt(props) {
|
||||
return useMutation((id) => apiRequest.post(`sales/receipts/${id}/close`), {
|
||||
onSuccess: (res, id) => {
|
||||
queryClient.invalidateQueries([t.SALE_RECEIPT, id]);
|
||||
|
||||
|
||||
// Invalidate queries.
|
||||
commonInvalidateQueries(queryClient);
|
||||
},
|
||||
@@ -141,3 +141,13 @@ export function useReceipt(id, props) {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export function useRefreshReceipts() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return {
|
||||
refresh: () => {
|
||||
queryClient.invalidateQueries(t.SALE_RECEIPTS);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -114,3 +114,13 @@ export function useVendor(id, props) {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export function useRefreshVendors() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return {
|
||||
refresh: () => {
|
||||
queryClient.invalidateQueries(t.VENDORS);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user