mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 13:20:31 +00:00
refactoring: account form.
refactoring: expense form. refactoring: manual journal form. refactoring: invoice form.
This commit is contained in:
@@ -50,7 +50,10 @@ export function useAccountsTypes(props) {
|
||||
const states = useQuery(
|
||||
['ACCOUNTS_TYPES'],
|
||||
() => ApiService.get('account_types'),
|
||||
props,
|
||||
{
|
||||
select: (res) => res.data.account_types,
|
||||
...props,
|
||||
},
|
||||
);
|
||||
return {
|
||||
...states,
|
||||
@@ -79,7 +82,7 @@ export function useEditAccount(props) {
|
||||
const query = useQueryClient();
|
||||
|
||||
return useMutation(
|
||||
(values, id) => ApiService.post(`accounts/${id}`, values),
|
||||
([values, id]) => ApiService.post(`accounts/${id}`, values),
|
||||
{
|
||||
onSuccess: () => {
|
||||
query.invalidateQueries('ACCOUNTS');
|
||||
|
||||
@@ -34,6 +34,27 @@ export function useEditEstimate(props) {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve sale estimate details.
|
||||
*/
|
||||
export function useEstimate(id, props) {
|
||||
const states = useQuery(
|
||||
['SALE_ESTIMATE', id],
|
||||
() => ApiService.get(`sales/estimates/${id}`),
|
||||
{
|
||||
select: (res) => ({
|
||||
estimate: res.data.sale_estimate,
|
||||
}),
|
||||
...props,
|
||||
},
|
||||
);
|
||||
|
||||
return {
|
||||
...states,
|
||||
data: defaultTo(states.data, {}),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve sale invoices list with pagination meta.
|
||||
*/
|
||||
|
||||
@@ -41,7 +41,7 @@ export function useExpenses(query, props) {
|
||||
* @param {number} id - Expense id.
|
||||
*/
|
||||
export function useExpense(id, props) {
|
||||
const states = useQuery(['EXPENSES', id], () => ApiService.get(`expenses`), {
|
||||
const states = useQuery(['EXPENSE', id], () => ApiService.get(`expenses/${id}`), {
|
||||
select: (res) => res.data.expense,
|
||||
...props,
|
||||
});
|
||||
|
||||
@@ -24,7 +24,7 @@ export function useEditInvoice(props) {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation(
|
||||
(id, values) => ApiService.post(`sales/invoices/${id}`, values),
|
||||
([id, values]) => ApiService.post(`sales/invoices/${id}`, values),
|
||||
{
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries('SALE_INVOICES');
|
||||
@@ -102,8 +102,8 @@ export function useDeliverInvoice(props) {
|
||||
export function useInvoice(id, props) {
|
||||
const states = useQuery(['SALE_INVOICE', id], () =>
|
||||
ApiService.get(`sales/invoices/${id}`),
|
||||
{
|
||||
select: (res) => res.data.invoice,
|
||||
{
|
||||
select: (res) => res.data.sale_invoice,
|
||||
...props
|
||||
},
|
||||
);
|
||||
|
||||
@@ -27,10 +27,11 @@ export function useEditJournal(props) {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation(
|
||||
(values, id) => ApiService.post(`manual-journals/${id}`, values),
|
||||
([id, values]) => ApiService.post(`manual-journals/${id}`, values),
|
||||
{
|
||||
onSuccess: () => {
|
||||
onSuccess: (res, [id]) => {
|
||||
queryClient.invalidateQueries('JOURNALS');
|
||||
queryClient.invalidateQueries('JOURNAL', id);
|
||||
},
|
||||
...props
|
||||
},
|
||||
@@ -46,8 +47,9 @@ export function useDeleteJournal(props) {
|
||||
return useMutation(
|
||||
(id) => ApiService.delete(`manual-journals/${id}`),
|
||||
{
|
||||
onSuccess: () => {
|
||||
onSuccess: (res, id) => {
|
||||
queryClient.invalidateQueries('JOURNALS');
|
||||
queryClient.invalidateQueries('JOURNAL', id);
|
||||
},
|
||||
...props
|
||||
},
|
||||
@@ -63,8 +65,9 @@ export function usePublishJournal(props) {
|
||||
return useMutation(
|
||||
(id) => ApiService.post(`manual-journals/${id}/publish`),
|
||||
{
|
||||
onSuccess: () => {
|
||||
onSuccess: (res, id) => {
|
||||
queryClient.invalidateQueries('JOURNALS');
|
||||
queryClient.invalidateQueries('JOURNAL', id);
|
||||
},
|
||||
...props
|
||||
},
|
||||
@@ -104,12 +107,9 @@ export function useJournals(query, props) {
|
||||
export function useJournal(id, props) {
|
||||
return useQuery(
|
||||
['JOURNAL', id],
|
||||
async () => {
|
||||
const { data } = await ApiService.get(`manual-journals/${id}`);
|
||||
|
||||
return data.manual_journal;
|
||||
},
|
||||
() => ApiService.get(`manual-journals/${id}`),
|
||||
{
|
||||
select: (res) => res.data.manual_journal,
|
||||
...props,
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user