mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 23:00:34 +00:00
feat: control the multi-select switch
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
|||||||
} from '@blueprintjs/core';
|
} from '@blueprintjs/core';
|
||||||
import {
|
import {
|
||||||
useAddTransactionsToCategorizeSelected,
|
useAddTransactionsToCategorizeSelected,
|
||||||
|
useIsTransactionToCategorizeSelected,
|
||||||
useRemoveTransactionsToCategorizeSelected,
|
useRemoveTransactionsToCategorizeSelected,
|
||||||
} from '@/hooks/state/banking';
|
} from '@/hooks/state/banking';
|
||||||
import { Box, Icon } from '@/components';
|
import { Box, Icon } from '@/components';
|
||||||
@@ -19,7 +20,6 @@ import styles from './AccountTransactionsUncategorizedTable.module.scss';
|
|||||||
function statusAccessor(transaction) {
|
function statusAccessor(transaction) {
|
||||||
return transaction.is_recognized ? (
|
return transaction.is_recognized ? (
|
||||||
<Tooltip
|
<Tooltip
|
||||||
// compact
|
|
||||||
interactionKind={PopoverInteractionKind.HOVER}
|
interactionKind={PopoverInteractionKind.HOVER}
|
||||||
position={Position.RIGHT}
|
position={Position.RIGHT}
|
||||||
content={
|
content={
|
||||||
@@ -44,24 +44,42 @@ function statusAccessor(transaction) {
|
|||||||
) : null;
|
) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
interface TransactionSelectCheckboxProps {
|
||||||
* Retrieve account uncategorized transctions table columns.
|
transactionId: number;
|
||||||
*/
|
}
|
||||||
export function useAccountUncategorizedTransactionsColumns() {
|
|
||||||
|
function TransactionSelectCheckbox({
|
||||||
|
transactionId,
|
||||||
|
}: TransactionSelectCheckboxProps) {
|
||||||
const addTransactionsToCategorizeSelected =
|
const addTransactionsToCategorizeSelected =
|
||||||
useAddTransactionsToCategorizeSelected();
|
useAddTransactionsToCategorizeSelected();
|
||||||
|
|
||||||
const removeTransactionsToCategorizeSelected =
|
const removeTransactionsToCategorizeSelected =
|
||||||
useRemoveTransactionsToCategorizeSelected();
|
useRemoveTransactionsToCategorizeSelected();
|
||||||
|
|
||||||
const handleChange = (value) => (event) => {
|
const isTransactionSelected =
|
||||||
if (event.currentTarget.checked) {
|
useIsTransactionToCategorizeSelected(transactionId);
|
||||||
addTransactionsToCategorizeSelected(value.id);
|
|
||||||
} else {
|
const handleChange = (event) => {
|
||||||
removeTransactionsToCategorizeSelected(value.id);
|
isTransactionSelected
|
||||||
}
|
? removeTransactionsToCategorizeSelected(transactionId)
|
||||||
|
: addTransactionsToCategorizeSelected(transactionId);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Checkbox
|
||||||
|
large
|
||||||
|
checked={isTransactionSelected}
|
||||||
|
onChange={handleChange}
|
||||||
|
className={styles.categorizeCheckbox}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve account uncategorized transctions table columns.
|
||||||
|
*/
|
||||||
|
export function useAccountUncategorizedTransactionsColumns() {
|
||||||
return React.useMemo(
|
return React.useMemo(
|
||||||
() => [
|
() => [
|
||||||
{
|
{
|
||||||
@@ -125,17 +143,13 @@ export function useAccountUncategorizedTransactionsColumns() {
|
|||||||
id: 'categorize_include',
|
id: 'categorize_include',
|
||||||
Header: '',
|
Header: '',
|
||||||
accessor: (value) => (
|
accessor: (value) => (
|
||||||
<Checkbox
|
<TransactionSelectCheckbox transactionId={value.id} />
|
||||||
large
|
|
||||||
onChange={handleChange(value)}
|
|
||||||
className={styles.categorizeCheckbox}
|
|
||||||
/>
|
|
||||||
),
|
),
|
||||||
width: 20,
|
width: 20,
|
||||||
minWidth: 20,
|
minWidth: 20,
|
||||||
maxWidth: 20,
|
maxWidth: 20,
|
||||||
align: 'right',
|
align: 'right',
|
||||||
className: 'categorize_include',
|
className: 'categorize_include selection-checkbox',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
[],
|
[],
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
addTransactionsToCategorizeSelected,
|
addTransactionsToCategorizeSelected,
|
||||||
removeTransactionsToCategorizeSelected,
|
removeTransactionsToCategorizeSelected,
|
||||||
getOpenMatchingTransactionAside,
|
getOpenMatchingTransactionAside,
|
||||||
|
getTransactionsToCategorizeIdsSelected,
|
||||||
} from '@/store/banking/banking.reducer';
|
} from '@/store/banking/banking.reducer';
|
||||||
|
|
||||||
export const useSetBankingPlaidToken = () => {
|
export const useSetBankingPlaidToken = () => {
|
||||||
@@ -94,3 +95,18 @@ export const useGetOpenMatchingTransactionAside = () => {
|
|||||||
[openMatchingTransactionAside],
|
[openMatchingTransactionAside],
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the detarmined value whether the given transaction id is checked.
|
||||||
|
* @param {number} transactionId
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
export const useIsTransactionToCategorizeSelected = (transactionId: number) => {
|
||||||
|
const transactionsToCategorizeIdsSelected = useSelector(
|
||||||
|
getTransactionsToCategorizeIdsSelected,
|
||||||
|
);
|
||||||
|
return useMemo(
|
||||||
|
() => transactionsToCategorizeIdsSelected.indexOf(transactionId) !== -1,
|
||||||
|
[transactionsToCategorizeIdsSelected, transactionId],
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user