mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 06:10:31 +00:00
feat: validate before move to full and partial transactions locking.
This commit is contained in:
@@ -4,7 +4,7 @@ import { Intent } from '@blueprintjs/core';
|
||||
import styled from 'styled-components';
|
||||
import * as R from 'ramda';
|
||||
|
||||
import { Alert, ButtonLink } from 'components';
|
||||
import { Alert, ButtonLink, AppToaster, Join } from 'components';
|
||||
import { TransactionsLockingProvider } from './TransactionsLockingProvider';
|
||||
import {
|
||||
TransactionLockingContent,
|
||||
@@ -12,6 +12,10 @@ import {
|
||||
} from './components';
|
||||
import { useTransactionsLockingContext } from './TransactionsLockingProvider';
|
||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||
import {
|
||||
validateMoveToFullLocking,
|
||||
validateMoveToPartialLocking,
|
||||
} from './utils';
|
||||
|
||||
function Paragraph({ className, children }) {
|
||||
return <p className={clsx('paragraph', className)}>{children}</p>;
|
||||
@@ -59,16 +63,49 @@ function TransactionLockingSkeletonList() {
|
||||
}
|
||||
|
||||
function TransactionsLockingAlert() {
|
||||
const { transactionLockingType, setTransactionLockingType } =
|
||||
useTransactionsLockingContext();
|
||||
const {
|
||||
transactionsLocking,
|
||||
transactionLockingType,
|
||||
setTransactionLockingType,
|
||||
} = useTransactionsLockingContext();
|
||||
|
||||
// Handle all lock link click.
|
||||
const handleAllLockClick = () => {
|
||||
setTransactionLockingType('all');
|
||||
const activeModules = validateMoveToFullLocking(
|
||||
transactionsLocking.modules,
|
||||
);
|
||||
const modulesStrong = activeModules.map((module) => (
|
||||
<strong>{module.formatted_module}</strong>
|
||||
));
|
||||
if (activeModules.length > 0) {
|
||||
AppToaster.show({
|
||||
message: (
|
||||
<span>
|
||||
You should unlock <Join items={modulesStrong} sep={', '} /> modules
|
||||
first, than you can lock all transactions at once.
|
||||
</span>
|
||||
),
|
||||
intent: Intent.DANGER,
|
||||
});
|
||||
} else {
|
||||
setTransactionLockingType('all');
|
||||
}
|
||||
};
|
||||
|
||||
const handleUndividualLockClick = () => {
|
||||
setTransactionLockingType('partial');
|
||||
const isAllLockingActive = validateMoveToPartialLocking(
|
||||
transactionsLocking.all,
|
||||
);
|
||||
|
||||
if (isAllLockingActive) {
|
||||
AppToaster.show({
|
||||
message:
|
||||
'You should unlock all transactions at once before, than lock transactions partially on each module.',
|
||||
intent: Intent.DANGER,
|
||||
});
|
||||
} else {
|
||||
setTransactionLockingType('partial');
|
||||
}
|
||||
};
|
||||
|
||||
return transactionLockingType !== 'all' ? (
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
Intent,
|
||||
Divider,
|
||||
Classes,
|
||||
Tag,
|
||||
} from '@blueprintjs/core';
|
||||
import { Hint, Icon, If, FormattedMessage as T } from 'components';
|
||||
import { Popover2 } from '@blueprintjs/popover2';
|
||||
@@ -40,6 +41,7 @@ export const TransactionLockingContent = ({
|
||||
description,
|
||||
module,
|
||||
isEnabled,
|
||||
isPartialUnlock,
|
||||
onLock,
|
||||
onEditLock,
|
||||
onUnlockFull,
|
||||
@@ -70,6 +72,12 @@ export const TransactionLockingContent = ({
|
||||
<TransLockingItemTitle>
|
||||
{name}
|
||||
<Hint content={description} position={Position.BOTTOM_LEFT} />
|
||||
|
||||
{isPartialUnlock && (
|
||||
<Tag small={true} minimal={true} intent={Intent.PRIMARY}>
|
||||
Partial unlocked
|
||||
</Tag>
|
||||
)}
|
||||
</TransLockingItemTitle>
|
||||
<TransLockingItemDesc>
|
||||
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
|
||||
|
||||
9
src/containers/TransactionsLocking/utils.js
Normal file
9
src/containers/TransactionsLocking/utils.js
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
|
||||
export const validateMoveToPartialLocking = (all) => {
|
||||
return all.is_enabled;
|
||||
}
|
||||
|
||||
export const validateMoveToFullLocking = (modules) => {
|
||||
return modules.filter((module) => module.is_enabled);
|
||||
}
|
||||
Reference in New Issue
Block a user