mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 20:30:33 +00:00
Merge branch 'develop' of https://github.com/bigcapitalhq/client into develop
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
import React from 'react';
|
||||
import intl from 'react-intl-universal';
|
||||
import { FormattedMessage as T, FormattedHTMLMessage } from 'components';
|
||||
import { Intent, Alert } from '@blueprintjs/core';
|
||||
import { AppToaster } from 'components';
|
||||
|
||||
import { useCancelUnlockingPartialTransactions } from 'hooks/query';
|
||||
|
||||
import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
|
||||
import withAlertActions from 'containers/Alert/withAlertActions';
|
||||
|
||||
import { compose } from 'utils';
|
||||
|
||||
/**
|
||||
* Cancel Unlocking partial transactions alerts.
|
||||
*/
|
||||
function CancelUnlockingPartialTarnsactions({
|
||||
name,
|
||||
|
||||
// #withAlertStoreConnect
|
||||
isOpen,
|
||||
payload: { module },
|
||||
|
||||
// #withAlertActions
|
||||
closeAlert,
|
||||
}) {
|
||||
const { mutateAsync: cancelUnlockingPartial, isLoading } =
|
||||
useCancelUnlockingPartialTransactions();
|
||||
|
||||
// Handle cancel.
|
||||
const handleCancel = () => {
|
||||
closeAlert(name);
|
||||
};
|
||||
|
||||
// Handle confirm.
|
||||
const handleConfirm = () => {
|
||||
const values = {
|
||||
module: module,
|
||||
};
|
||||
cancelUnlockingPartial(values)
|
||||
.then(() => {
|
||||
AppToaster.show({
|
||||
message: intl.get(
|
||||
'unlocking_partial_transactions.alert.success_message',
|
||||
),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
})
|
||||
.catch(
|
||||
({
|
||||
response: {
|
||||
data: { errors },
|
||||
},
|
||||
}) => {},
|
||||
)
|
||||
.finally(() => {
|
||||
closeAlert(name);
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Alert
|
||||
cancelButtonText={<T id={'cancel'} />}
|
||||
confirmButtonText={<T id={'save'} />}
|
||||
icon="trash"
|
||||
intent={Intent.WARNING}
|
||||
isOpen={isOpen}
|
||||
onCancel={handleCancel}
|
||||
onConfirm={handleConfirm}
|
||||
loading={isLoading}
|
||||
>
|
||||
<p>
|
||||
<T id={'unlocking_partial_transactions.alert.message'} />
|
||||
</p>
|
||||
</Alert>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withAlertStoreConnect(),
|
||||
withAlertActions,
|
||||
)(CancelUnlockingPartialTarnsactions);
|
||||
@@ -19,6 +19,7 @@ import CurrenciesAlerts from '../Preferences/Currencies/CurrenciesAlerts';
|
||||
import RolesAlerts from '../Preferences/Users/Roles/RolesAlerts';
|
||||
import CreditNotesAlerts from '../Sales/CreditNotes/CreditNotesAlerts';
|
||||
import VendorCreditNotesAlerts from '../Purchases/CreditNotes/VendorCreditNotesAlerts';
|
||||
import TransactionsLockingAlerts from '../TransactionsLocking/TransactionsLockingAlerts'
|
||||
|
||||
export default [
|
||||
...AccountsAlerts,
|
||||
@@ -42,4 +43,5 @@ export default [
|
||||
...RolesAlerts,
|
||||
...CreditNotesAlerts,
|
||||
...VendorCreditNotesAlerts,
|
||||
...TransactionsLockingAlerts
|
||||
];
|
||||
|
||||
@@ -1,30 +1,26 @@
|
||||
import React from 'react';
|
||||
import { DialogContent } from 'components';
|
||||
import {
|
||||
useCancelLockingTransaction,
|
||||
useCancelUnlockingPartialTransactions,
|
||||
} from 'hooks/query';
|
||||
import { useCancelLockingTransaction } from 'hooks/query';
|
||||
|
||||
const UnlockingTransactionsContext = React.createContext();
|
||||
|
||||
/**
|
||||
* Unlocking transactions form provider.
|
||||
*/
|
||||
function UnlockingTransactionsFormProvider({ moduleName, dialogName, ...props }) {
|
||||
function UnlockingTransactionsFormProvider({
|
||||
moduleName,
|
||||
dialogName,
|
||||
...props
|
||||
}) {
|
||||
// Cancle locking transactions mutations.
|
||||
const { mutateAsync: cancelLockingTransactionMutate } =
|
||||
useCancelLockingTransaction();
|
||||
|
||||
// Cancel unlocking partial transactions mutations.
|
||||
const { mutateAsync: cancelUnLockingPartialTransactionMutate } =
|
||||
useCancelUnlockingPartialTransactions();
|
||||
|
||||
// State provider.
|
||||
const provider = {
|
||||
dialogName,
|
||||
moduleName,
|
||||
cancelLockingTransactionMutate,
|
||||
cancelUnLockingPartialTransactionMutate,
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@@ -16,6 +16,10 @@ const ItemBulkDeleteAlert = React.lazy(() =>
|
||||
import('containers/Alerts/Items/ItemBulkDeleteAlert'),
|
||||
);
|
||||
|
||||
const cancelUnlockingPartialAlert = React.lazy(() =>
|
||||
import('../Alerts/TransactionLocking/cancelUnlockingPartialAlert'),
|
||||
);
|
||||
|
||||
/**
|
||||
* Items alert.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import React from 'react';
|
||||
|
||||
const cancelUnlockingPartialAlert = React.lazy(() =>
|
||||
import('../Alerts/TransactionLocking/cancelUnlockingPartialAlert'),
|
||||
);
|
||||
|
||||
/**
|
||||
* Transactions alerts.
|
||||
*/
|
||||
export default [
|
||||
{
|
||||
name: 'cancel-unlocking-partail',
|
||||
component: cancelUnlockingPartialAlert,
|
||||
},
|
||||
];
|
||||
@@ -12,6 +12,8 @@ import {
|
||||
} from './components';
|
||||
import { useTransactionsLockingContext } from './TransactionsLockingProvider';
|
||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||
import withAlertsActions from 'containers/Alert/withAlertActions';
|
||||
|
||||
import {
|
||||
validateMoveToFullLocking,
|
||||
validateMoveToPartialLocking,
|
||||
@@ -21,18 +23,35 @@ function Paragraph({ className, children }) {
|
||||
return <p className={clsx('paragraph', className)}>{children}</p>;
|
||||
}
|
||||
|
||||
function TransactionsLockingList({ items, onlock, onUnlock, onUnlockPartial }) {
|
||||
return items.map(({ is_enabled, module, formatted_module, description }) => (
|
||||
<TransactionLockingContent
|
||||
name={formatted_module}
|
||||
module={module}
|
||||
description={description}
|
||||
isEnabled={is_enabled}
|
||||
onLock={onlock}
|
||||
onUnlockPartial={onUnlockPartial}
|
||||
onEditLock={onlock}
|
||||
/>
|
||||
));
|
||||
function TransactionsLockingList({
|
||||
items,
|
||||
onLock,
|
||||
onUnlock,
|
||||
onUnlockPartial,
|
||||
onCancel,
|
||||
}) {
|
||||
return items.map(
|
||||
({
|
||||
is_enabled,
|
||||
is_partial_unlock,
|
||||
module,
|
||||
formatted_module,
|
||||
description,
|
||||
}) => (
|
||||
<TransactionLockingContent
|
||||
name={formatted_module}
|
||||
module={module}
|
||||
description={description}
|
||||
isEnabled={is_enabled}
|
||||
isPartialUnlock={is_partial_unlock}
|
||||
onLock={onLock}
|
||||
onUnlockFull={onUnlock}
|
||||
onUnlockPartial={onUnlockPartial}
|
||||
onEditLock={onLock}
|
||||
onCancle={onCancel}
|
||||
/>
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
function TransactionsLockingFull({ onLock, onUnlock, onUnlockPartial }) {
|
||||
@@ -137,11 +156,13 @@ function TransactionsLockingAlert() {
|
||||
function TransactionsLockingBodyJsx({
|
||||
// #withDialogActions
|
||||
openDialog,
|
||||
|
||||
// #withAlertsActions
|
||||
openAlert,
|
||||
}) {
|
||||
const {
|
||||
transactionsLocking: { modules },
|
||||
isTransactionLockingLoading,
|
||||
|
||||
transactionLockingType,
|
||||
} = useTransactionsLockingContext();
|
||||
|
||||
@@ -159,25 +180,35 @@ function TransactionsLockingBodyJsx({
|
||||
openDialog('unlocking-partial-transactions', { module: module });
|
||||
};
|
||||
|
||||
// Handle cancel.
|
||||
const handleCancelUnlockingPartail = (module) => {
|
||||
openAlert('cancel-unlocking-partail', { module: module });
|
||||
};
|
||||
|
||||
return !isTransactionLockingLoading ? (
|
||||
transactionLockingType === 'partial' ? (
|
||||
<TransactionsLockingList
|
||||
items={modules}
|
||||
onlock={handleLockingTransactions}
|
||||
onLock={handleLockingTransactions}
|
||||
onUnlock={handleUnlockTransactions}
|
||||
onUnlockPartial={handleUnlockingPartial}
|
||||
onCancel={handleCancelUnlockingPartail}
|
||||
/>
|
||||
) : (
|
||||
<TransactionsLockingFull />
|
||||
<TransactionsLockingFull
|
||||
onLock={handleLockingTransactions}
|
||||
onUnlockPartial={handleUnlockingPartial}
|
||||
/>
|
||||
)
|
||||
) : (
|
||||
<TransactionLockingSkeletonList />
|
||||
);
|
||||
}
|
||||
|
||||
const TransactionsLockingBody = R.compose(withDialogActions)(
|
||||
TransactionsLockingBodyJsx,
|
||||
);
|
||||
const TransactionsLockingBody = R.compose(
|
||||
withAlertsActions,
|
||||
withDialogActions,
|
||||
)(TransactionsLockingBodyJsx);
|
||||
|
||||
/**
|
||||
* Transactions locking list.
|
||||
|
||||
@@ -46,6 +46,7 @@ export const TransactionLockingContent = ({
|
||||
onEditLock,
|
||||
onUnlockFull,
|
||||
onUnlockPartial,
|
||||
onCancle,
|
||||
}) => {
|
||||
const handleLockClick = (event) => {
|
||||
safeInvoke(onLock, module, event);
|
||||
@@ -60,6 +61,9 @@ export const TransactionLockingContent = ({
|
||||
const handleUnlockFull = (event) => {
|
||||
safeInvoke(onUnlockFull, module, event);
|
||||
};
|
||||
const handleCanclel = (event) => {
|
||||
safeInvoke(onCancle, module, event);
|
||||
};
|
||||
|
||||
return (
|
||||
<TransactionLockingWrapp isEnabled={isEnabled}>
|
||||
@@ -85,7 +89,7 @@ export const TransactionLockingContent = ({
|
||||
</TransLockingContent>
|
||||
|
||||
<TransLockingActions>
|
||||
<If condition={!isEnabled}>
|
||||
<If condition={!isEnabled && !isPartialUnlock}>
|
||||
<Button
|
||||
small={true}
|
||||
minimal={true}
|
||||
@@ -96,7 +100,7 @@ export const TransactionLockingContent = ({
|
||||
</Button>
|
||||
</If>
|
||||
|
||||
<If condition={isEnabled}>
|
||||
<If condition={isEnabled && !isPartialUnlock}>
|
||||
<Button
|
||||
small={true}
|
||||
minimal={true}
|
||||
@@ -110,6 +114,7 @@ export const TransactionLockingContent = ({
|
||||
content={
|
||||
<Menu>
|
||||
<MenuItem text="Full unlock" onClick={handleUnlockFull} />
|
||||
|
||||
<MenuItem
|
||||
text="Partial unlock"
|
||||
onClick={handleUnlockPartial}
|
||||
@@ -124,6 +129,17 @@ export const TransactionLockingContent = ({
|
||||
</Button>
|
||||
</Popover2>
|
||||
</If>
|
||||
|
||||
<If condition={isPartialUnlock}>
|
||||
<Button
|
||||
small={true}
|
||||
minimal={true}
|
||||
intent={Intent.PRIMARY}
|
||||
onClick={handleCanclel}
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
</If>
|
||||
</TransLockingActions>
|
||||
</TransLockingInner>
|
||||
</TransactionLockingWrapp>
|
||||
|
||||
@@ -1618,5 +1618,8 @@
|
||||
"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."
|
||||
"unlocking_partial_transactions.alert.success_message": "Partial transaction unlocking has been canceled successfully.",
|
||||
"unlocking_partial_transactions.alert.message": "Are you sure you want to cancel this ?"
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user