mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-22 15:50:32 +00:00
feat: validate before move to full and partial transactions locking.
This commit is contained in:
13
src/components/Utils/Join.js
Normal file
13
src/components/Utils/Join.js
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
export function Join({ items, sep }) {
|
||||||
|
return items.length > 0
|
||||||
|
? items.reduce((result, item) => (
|
||||||
|
<>
|
||||||
|
{result}
|
||||||
|
{sep}
|
||||||
|
{item}
|
||||||
|
</>
|
||||||
|
))
|
||||||
|
: null;
|
||||||
|
}
|
||||||
@@ -2,3 +2,4 @@
|
|||||||
|
|
||||||
export * from './FormatNumber';
|
export * from './FormatNumber';
|
||||||
export * from './FormatDate';
|
export * from './FormatDate';
|
||||||
|
export * from './Join';
|
||||||
@@ -87,6 +87,7 @@ export * from './Button';
|
|||||||
export * from './IntersectionObserver';
|
export * from './IntersectionObserver';
|
||||||
export * from './SMSPreview';
|
export * from './SMSPreview';
|
||||||
export * from './Contacts';
|
export * from './Contacts';
|
||||||
|
export * from './Utils/Join';
|
||||||
|
|
||||||
const Hint = FieldHint;
|
const Hint = FieldHint;
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { Intent } from '@blueprintjs/core';
|
|||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import * as R from 'ramda';
|
import * as R from 'ramda';
|
||||||
|
|
||||||
import { Alert, ButtonLink } from 'components';
|
import { Alert, ButtonLink, AppToaster, Join } from 'components';
|
||||||
import { TransactionsLockingProvider } from './TransactionsLockingProvider';
|
import { TransactionsLockingProvider } from './TransactionsLockingProvider';
|
||||||
import {
|
import {
|
||||||
TransactionLockingContent,
|
TransactionLockingContent,
|
||||||
@@ -12,6 +12,10 @@ import {
|
|||||||
} from './components';
|
} from './components';
|
||||||
import { useTransactionsLockingContext } from './TransactionsLockingProvider';
|
import { useTransactionsLockingContext } from './TransactionsLockingProvider';
|
||||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||||
|
import {
|
||||||
|
validateMoveToFullLocking,
|
||||||
|
validateMoveToPartialLocking,
|
||||||
|
} from './utils';
|
||||||
|
|
||||||
function Paragraph({ className, children }) {
|
function Paragraph({ className, children }) {
|
||||||
return <p className={clsx('paragraph', className)}>{children}</p>;
|
return <p className={clsx('paragraph', className)}>{children}</p>;
|
||||||
@@ -59,16 +63,49 @@ function TransactionLockingSkeletonList() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function TransactionsLockingAlert() {
|
function TransactionsLockingAlert() {
|
||||||
const { transactionLockingType, setTransactionLockingType } =
|
const {
|
||||||
useTransactionsLockingContext();
|
transactionsLocking,
|
||||||
|
transactionLockingType,
|
||||||
|
setTransactionLockingType,
|
||||||
|
} = useTransactionsLockingContext();
|
||||||
|
|
||||||
// Handle all lock link click.
|
// Handle all lock link click.
|
||||||
const handleAllLockClick = () => {
|
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 = () => {
|
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' ? (
|
return transactionLockingType !== 'all' ? (
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
Intent,
|
Intent,
|
||||||
Divider,
|
Divider,
|
||||||
Classes,
|
Classes,
|
||||||
|
Tag,
|
||||||
} from '@blueprintjs/core';
|
} from '@blueprintjs/core';
|
||||||
import { Hint, Icon, If, FormattedMessage as T } from 'components';
|
import { Hint, Icon, If, FormattedMessage as T } from 'components';
|
||||||
import { Popover2 } from '@blueprintjs/popover2';
|
import { Popover2 } from '@blueprintjs/popover2';
|
||||||
@@ -40,6 +41,7 @@ export const TransactionLockingContent = ({
|
|||||||
description,
|
description,
|
||||||
module,
|
module,
|
||||||
isEnabled,
|
isEnabled,
|
||||||
|
isPartialUnlock,
|
||||||
onLock,
|
onLock,
|
||||||
onEditLock,
|
onEditLock,
|
||||||
onUnlockFull,
|
onUnlockFull,
|
||||||
@@ -70,6 +72,12 @@ export const TransactionLockingContent = ({
|
|||||||
<TransLockingItemTitle>
|
<TransLockingItemTitle>
|
||||||
{name}
|
{name}
|
||||||
<Hint content={description} position={Position.BOTTOM_LEFT} />
|
<Hint content={description} position={Position.BOTTOM_LEFT} />
|
||||||
|
|
||||||
|
{isPartialUnlock && (
|
||||||
|
<Tag small={true} minimal={true} intent={Intent.PRIMARY}>
|
||||||
|
Partial unlocked
|
||||||
|
</Tag>
|
||||||
|
)}
|
||||||
</TransLockingItemTitle>
|
</TransLockingItemTitle>
|
||||||
<TransLockingItemDesc>
|
<TransLockingItemDesc>
|
||||||
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
|
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