feat: Contact activate & inactivate.

This commit is contained in:
elforjani3
2021-08-06 17:30:07 +02:00
parent 7d07238c6a
commit 0dc8f43ac7
12 changed files with 276 additions and 17 deletions

View File

@@ -1,5 +1,15 @@
import { useMutation, useQueryClient } from 'react-query';
import useApiRequest from '../useRequest';
import { useQueryTenant } from '../useQueryRequest';
import t from './types';
// Common invalidate queries.
const commonInvalidateQueries = (queryClient) => {
// Invalidate vendors.
queryClient.invalidateQueries(t.VENDORS);
// Invalidate customers.
queryClient.invalidateQueries(t.CUSTOMERS);
};
/**
* Retrieve the contact duplicate.
@@ -33,3 +43,41 @@ export function useAutoCompleteContacts(props) {
},
);
}
/**
* Activate the given Contact.
*/
export function useActivateContact(props) {
const queryClient = useQueryClient();
const apiRequest = useApiRequest();
return useMutation((id) => apiRequest.post(`contacts/${id}/activate`), {
onSuccess: (res, id) => {
// Invalidate specific contact.
queryClient.invalidateQueries([t.CONTACT, id]);
// Common invalidate queries.
commonInvalidateQueries(queryClient);
},
...props,
});
}
/**
* Inactivate the given contact.
*/
export function useInactivateContact(props) {
const queryClient = useQueryClient();
const apiRequest = useApiRequest();
return useMutation((id) => apiRequest.post(`contacts/${id}/inactivate`), {
onSuccess: (res, id) => {
// Invalidate specific item.
queryClient.invalidateQueries([t.CONTACT, id]);
// Common invalidate queries.
commonInvalidateQueries(queryClient);
},
...props,
});
}

View File

@@ -126,6 +126,11 @@ const LANDED_COSTS = {
LANDED_COST_TRANSACTION: 'LANDED_COST_TRANSACTION',
};
const CONTACTS = {
CONTACTS: 'CONTACTS',
CONTACT: 'CONTACT',
};
export default {
...ACCOUNTS,
...BILLS,
@@ -147,4 +152,5 @@ export default {
...EXPENSES,
...MANUAL_JOURNALS,
...LANDED_COSTS,
...CONTACTS,
};