From dfc0fbbb71aa796a0ec8e393a27a2b1610fabab0 Mon Sep 17 00:00:00 2001 From: elforjani13 <39470382+elforjani13@users.noreply.github.com> Date: Sun, 12 Dec 2021 19:15:31 +0200 Subject: [PATCH] feat: add transactions locking query. --- .../TransactionsLockingList.js | 9 +- src/hooks/query/index.js | 1 + src/hooks/query/transactionsLocking.js | 87 +++++++++++++++++++ src/hooks/query/types.js | 7 +- src/lang/en/index.json | 25 ++++-- src/routes/dashboard.js | 14 +-- 6 files changed, 125 insertions(+), 18 deletions(-) create mode 100644 src/hooks/query/transactionsLocking.js diff --git a/src/containers/TransactionsLocking/TransactionsLockingList.js b/src/containers/TransactionsLocking/TransactionsLockingList.js index 6163b8daf..0ade6af12 100644 --- a/src/containers/TransactionsLocking/TransactionsLockingList.js +++ b/src/containers/TransactionsLocking/TransactionsLockingList.js @@ -39,7 +39,7 @@ function TransactionsLockingList({ }) { // Handle switch transactions locking. const handleSwitchTransactionsLocking = () => { - openDialog('transactions-locking', {}); + openDialog('locking-transactions', {}); }; return ( @@ -48,10 +48,11 @@ function TransactionsLockingList({ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do - eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do - eiusmod tempor incididunt ut labore et dolore magna aliqua. + eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem + ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod + tempor incididunt ut labore et dolore magna aliqua. - Lock All Transactions At Once. {' '} + Lock All Transactions At Once.{' '} {''}Lock All Transactions At Once → diff --git a/src/hooks/query/index.js b/src/hooks/query/index.js index b1dcf9d13..629f4f1b4 100644 --- a/src/hooks/query/index.js +++ b/src/hooks/query/index.js @@ -32,3 +32,4 @@ export * from './cashflowAccounts'; export * from './roles'; export * from './creditNote'; export * from './vendorCredit'; +export * from './transactionsLocking'; diff --git a/src/hooks/query/transactionsLocking.js b/src/hooks/query/transactionsLocking.js new file mode 100644 index 000000000..745a002de --- /dev/null +++ b/src/hooks/query/transactionsLocking.js @@ -0,0 +1,87 @@ +import { useQueryClient, useMutation } from 'react-query'; +import { useRequestQuery } from '../useQueryRequest'; +import { transformPagination } from 'utils'; +import useApiRequest from '../useRequest'; +import { useRequestPdf } from '../utils'; +import t from './types'; + +// Common invalidate queries. +const commonInvalidateQueries = (queryClient) => { + // Invalidate customers. + queryClient.invalidateQueries(t.TRANSACTIONS_LOCKING); +}; + +/** + * Create a locking transactions. + */ +export function useCreateLockingTransactoin(props) { + const queryClient = useQueryClient(); + const apiRequest = useApiRequest(); + + return useMutation( + (values) => apiRequest.put('transactions-locking/lock', values), + { + onSuccess: (res, values) => { + // Common invalidate queries. + commonInvalidateQueries(queryClient); + }, + ...props, + }, + ); +} + +/** + * Create cancle locking transactions + */ +export function useCancelLockingTransaction(props) { + const queryClient = useQueryClient(); + const apiRequest = useApiRequest(); + + return useMutation( + (values) => apiRequest.put('transactions-locking/cancel-lock', values), + { + onSuccess: (res, values) => { + // Common invalidate queries. + commonInvalidateQueries(queryClient); + }, + ...props, + }, + ); +} + +/** + * Create a unlocking partial transactions. + */ +export function useCreateUnlockingPartialTransactions(props) { + const queryClient = useQueryClient(); + const apiRequest = useApiRequest(); + return useMutation( + (values) => apiRequest.put('transactions-locking/unlock-partial', values), + { + onSuccess: (res, values) => { + // Common invalidate queries. + commonInvalidateQueries(queryClient); + }, + ...props, + }, + ); +} + +/** + * Create cancle unlocking partial transactions. + */ +export function useCancelUnlockingPartialTransactions(props) { + const queryClient = useQueryClient(); + const apiRequest = useApiRequest(); + return useMutation( + (values) => + apiRequest.put('transactions-locking/cancel-unlock-partial', values), + { + onSuccess: (res, values) => { + // Common invalidate queries. + commonInvalidateQueries(queryClient); + }, + ...props, + }, + ); +} diff --git a/src/hooks/query/types.js b/src/hooks/query/types.js index 23e921237..14172059d 100644 --- a/src/hooks/query/types.js +++ b/src/hooks/query/types.js @@ -119,7 +119,7 @@ const CREDIT_NOTES = { const VENDOR_CREDIT_NOTES = { VENDOR_CREDITS: 'VENDOR_CREDITS', VENDOR_CREDIT: 'VENDOR_CREDIT', - REFUND_VENDOR_CREDIT: 'REFUND_VENDOR_CREDIT', + REFUND_VENDOR_CREDIT: 'REFUND_VENDOR_CREDIT', RECONCILE_VENDOR_CREDIT: 'RECONCILE_VENDOR_CREDIT', RECONCILE_VENDOR_CREDITS: 'RECONCILE_VENDOR_CREDITS', }; @@ -178,6 +178,10 @@ const CASH_FLOW_ACCOUNTS = { 'CASHFLOW_ACCOUNT_TRANSACTIONS_INFINITY', }; +const TARNSACTIONS_LOCKING = { + TRANSACTIONS_LOCKING: 'TRANSACTIONS_LOCKING', +}; + export default { ...ACCOUNTS, ...BILLS, @@ -204,4 +208,5 @@ export default { ...ROLES, ...CREDIT_NOTES, ...VENDOR_CREDIT_NOTES, + ...TARNSACTIONS_LOCKING, }; diff --git a/src/lang/en/index.json b/src/lang/en/index.json index a51385822..ec305f533 100644 --- a/src/lang/en/index.json +++ b/src/lang/en/index.json @@ -1477,8 +1477,6 @@ "roles.label.role_name_": "Role name", "roles.error.role_is_predefined": "Role is predefined, you cannot delete predefined roles.", "roles.error.you_cannot_change_your_own_role": "You cannot change your own role.", - "sidebar.transactions_locaking": "Transactions Locaking", - "transactions_locking.dialog.label": "Transactions locking", "roles.permission_schema.success_message": "The role has been created successfully.", "roles.permission_schema.upload_message": "The given role has been updated successfully.", "roles.permission_schema.delete.alert_message": "The given role has been deleted successfully.", @@ -1503,7 +1501,6 @@ "credit_note.label_credit_note_date": "Credit Note date", "credit_note.label_credit_note": "Credit Note #", "credit_note.label_amount_to_credit": "Amount to credit", - "credit_note.label_credit_note_details": "Credit Note details", "credit_note.label_customer_note": "Customer notes", "credit_note.once_delete_this_credit_note": "Once you delete this credit note, you won't be able to restore it later. Are you sure you want to delete this credit note?", @@ -1550,8 +1547,8 @@ "vendor_credit.drawer.label_created_at": "Created at", "vendor_credit.drawer.label_total": "TOTAL", "vendor_credit.drawer.label_subtotal": "Subtotal", - "vendor_credit.drawer.label_refund_transactions":"Refund Transactions", - "vendor_credit.drawer.label_bills_reconciled":"Bills Reconciled", + "vendor_credit.drawer.label_refund_transactions": "Refund Transactions", + "vendor_credit.drawer.label_bills_reconciled": "Bills Reconciled", "landed_cost.dialog.label_select_transaction": "Select transaction", "landed_cost.dialog.label_select_transaction_entry": "Select transaction entry", "refund_credit_note.dialog.label": "Refund Credit Note", @@ -1605,5 +1602,21 @@ "vendor_credit.error.you_couldn_t_delete_vendor_credit_that_has_associated_refund": "You couldn't delete vendor credit that has associated refund transactions.", "bills.error.you_couldn_t_delete_bill_has_reconciled_with_vendor_credit": "You couldn't delete bill has reconciled with vendor credit transaction.", "reconcile_vendor_credit.alert.success_message": "The applied vendor credit to bill has been deleted successfully", - "reconcile_vendor_credit.alert.once_you_delete_this_reconcile_vendor_credit": "Once you delete this reconcile vendor credit note, you won't be able to restore it later. Are you sure you want to delete this reconcile vendor credit note?" + "reconcile_vendor_credit.alert.once_you_delete_this_reconcile_vendor_credit": "Once you delete this reconcile vendor credit note, you won't be able to restore it later. Are you sure you want to delete this reconcile vendor credit note?", + "sidebar.transactions_locaking": "Transactions Locaking", + "locking_transactions.dialog.label": "Locking transactions", + "locking_transactions.dialog.locking_date": "Locking date", + "locking_transactions.dialog.reason": "Locking reason", + "locking_transactions.dialog.success_message": "All transactions locking has been submit successfully.", + "unlocking_transactions.dialog.label": "transactions locking", + "unlocking_transactions.dialog.reason": "Unlocking reason", + "unlocking_transactions.dialog.success_message": "Transactions locking has been canceled successfully.", + "unlocking_partial_transactions.dialog.label": "Partial unlocking transactions", + "unlocking_partial_transactions.dialog.from_date": "Unlocking from date", + "unlocking_partial_transactions.dialog.to_date": "To date", + "unlocking_partial_transactions.dialog.reason": "Unlocking reason", + "unlocking_partial_transactions.dialog.success_message": "Transactions locking haas been unlocked partially successfully.", + "unlocking_full_transactions.dialog.label": "Full unlocking transactions", + "unlocking_full_transactions.dialog.reason": "Unlocking reason", + "unlocking_full_transactions.dialog.success_message": "Partial transaction unlocking has been canceled successfully." } \ No newline at end of file diff --git a/src/routes/dashboard.js b/src/routes/dashboard.js index d1e25dc84..c181b5e14 100644 --- a/src/routes/dashboard.js +++ b/src/routes/dashboard.js @@ -872,13 +872,13 @@ export const getDashboardRoutes = () => [ subscriptionActive: [SUBSCRIPTION_TYPE.MAIN], defaultSearchResource: RESOURCES_TYPES.ACCOUNT, }, - // { - // path: `/transactions-locking`, - // component: lazy(() => - // import('../containers/TransactionsLocking/TransactionsLockingList'), - // ), - // pageTitle: intl.get('sidebar.transactions_locaking'), - // }, + { + path: `/transactions-locking`, + component: lazy(() => + import('../containers/TransactionsLocking/TransactionsLockingList'), + ), + pageTitle: intl.get('sidebar.transactions_locaking'), + }, // Homepage { path: `/`,