mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 04:10:32 +00:00
53 lines
1.3 KiB
JavaScript
53 lines
1.3 KiB
JavaScript
import intl from 'react-intl-universal';
|
|
|
|
import withDrawerActions from '../Drawer/withDrawerActions';
|
|
|
|
import { AbilitySubject, AccountAction } from '../../common/abilityOption';
|
|
import { RESOURCES_TYPES } from '../../common/resourcesTypes';
|
|
|
|
function AccountUniversalSearchItemSelectComponent({
|
|
// #ownProps
|
|
resourceType,
|
|
resourceId,
|
|
onAction,
|
|
|
|
// #withDrawerActions
|
|
openDrawer,
|
|
}) {
|
|
if (resourceType === RESOURCES_TYPES.ACCOUNT) {
|
|
openDrawer('account-drawer', { accountId: resourceId });
|
|
onAction && onAction();
|
|
}
|
|
return null;
|
|
}
|
|
|
|
export const AccountUniversalSearchItemSelect = withDrawerActions(
|
|
AccountUniversalSearchItemSelectComponent,
|
|
);
|
|
|
|
/**
|
|
* Transformes account item to search item.
|
|
* @param {*} account
|
|
* @returns
|
|
*/
|
|
const accountToSearch = (account) => ({
|
|
id: account.id,
|
|
text: `${account.name} - ${account.code}`,
|
|
label: account.formatted_amount,
|
|
reference: account,
|
|
});
|
|
|
|
/**
|
|
* Binds universal search account configure.
|
|
*/
|
|
export const universalSearchAccountBind = () => ({
|
|
resourceType: RESOURCES_TYPES.ACCOUNT,
|
|
optionItemLabel: intl.get('accounts'),
|
|
selectItemAction: AccountUniversalSearchItemSelect,
|
|
itemSelect: accountToSearch,
|
|
permission: {
|
|
ability: AccountAction.View,
|
|
subject: AbilitySubject.Account,
|
|
},
|
|
});
|