mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 21:30:31 +00:00
feat: add feature guard as hook and component.
This commit is contained in:
@@ -1,12 +1,17 @@
|
||||
import React from 'react';
|
||||
import { Tab } from '@blueprintjs/core';
|
||||
|
||||
import { DrawerMainTabs, FormattedMessage as T } from 'components';
|
||||
import { ItemPaymentTransactions } from './ItemPaymentTransactions';
|
||||
import ItemDetailHeader from './ItemDetailHeader';
|
||||
import WarehousesLocationsTable from './WarehousesLocations';
|
||||
|
||||
import { Features } from 'common';
|
||||
import { useFeatureCan } from 'hooks/state';
|
||||
|
||||
export default function ItemDetailTab() {
|
||||
const { featureCan } = useFeatureCan();
|
||||
|
||||
return (
|
||||
<DrawerMainTabs renderActiveTabPanelOnly={true}>
|
||||
<Tab
|
||||
@@ -19,11 +24,13 @@ export default function ItemDetailTab() {
|
||||
title={<T id={'transactions'} />}
|
||||
panel={<ItemPaymentTransactions />}
|
||||
/>
|
||||
<Tab
|
||||
id={'warehouses'}
|
||||
title={<T id={'warehouse_locations.label'} />}
|
||||
panel={<WarehousesLocationsTable />}
|
||||
/>
|
||||
{featureCan(Features.Warehouses) && (
|
||||
<Tab
|
||||
id={'warehouses'}
|
||||
title={<T id={'warehouse_locations.label'} />}
|
||||
panel={<WarehousesLocationsTable />}
|
||||
/>
|
||||
)}
|
||||
</DrawerMainTabs>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,48 +7,66 @@ import {
|
||||
NavbarDivider,
|
||||
} from '@blueprintjs/core';
|
||||
|
||||
import { Icon, FormattedMessage as T, CustomSelectList } from 'components';
|
||||
|
||||
import { useFeatureCan } from 'hooks/state';
|
||||
import {
|
||||
Icon,
|
||||
FormattedMessage as T,
|
||||
CustomSelectList,
|
||||
FeatureCan,
|
||||
} from 'components';
|
||||
import { useInvoiceFormContext } from './InvoiceFormProvider';
|
||||
import { Features } from 'common';
|
||||
|
||||
export default function InvoiceFormTopBar() {
|
||||
const { warehouses, branches } = useInvoiceFormContext();
|
||||
|
||||
const { featureCan } = useFeatureCan();
|
||||
|
||||
// Can't display the navigation bar if warehouses or branches feature is not enabled.
|
||||
if (!featureCan(Features.Warehouses) || !featureCan(Features.Branches)) {
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<Navbar className={'navbar--dashboard-topbar'}>
|
||||
<NavbarGroup align={Alignment.LEFT}>
|
||||
<FastField name={'branch_id'}>
|
||||
{({ form, field: { value }, meta: { error, touched } }) => (
|
||||
<CustomSelectList
|
||||
items={branches}
|
||||
text={'Branch'}
|
||||
onItemSelected={({ id }) => {
|
||||
form.setFieldValue('branch_id', id);
|
||||
}}
|
||||
selectedItemId={value}
|
||||
buttonProps={{
|
||||
icon: <Icon icon={'branch-16'} iconSize={20} />,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</FastField>
|
||||
<FeatureCan feature={Features.Warehouses}>
|
||||
<FastField name={'branch_id'}>
|
||||
{({ form, field: { value }, meta: { error, touched } }) => (
|
||||
<CustomSelectList
|
||||
items={branches}
|
||||
text={'Branch'}
|
||||
onItemSelected={({ id }) => {
|
||||
form.setFieldValue('branch_id', id);
|
||||
}}
|
||||
selectedItemId={value}
|
||||
buttonProps={{
|
||||
icon: <Icon icon={'branch-16'} iconSize={20} />,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</FastField>
|
||||
</FeatureCan>
|
||||
|
||||
<NavbarDivider />
|
||||
<FastField name={'warehouse_id'}>
|
||||
{({ form, field: { value }, meta: { error, touched } }) => (
|
||||
<CustomSelectList
|
||||
items={warehouses}
|
||||
text={'Warehosue'}
|
||||
onItemSelected={({ id }) => {
|
||||
form.setFieldValue('warehouse_id', id);
|
||||
}}
|
||||
selectedItemId={value}
|
||||
buttonProps={{
|
||||
icon: <Icon icon={'warehouse-16'} iconSize={20} />,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</FastField>
|
||||
{featureCan(Features.Warehouses) && featureCan(Features.Branches) && (
|
||||
<NavbarDivider />
|
||||
)}
|
||||
<FeatureCan feature={Features.Warehouses}>
|
||||
<FastField name={'warehouse_id'}>
|
||||
{({ form, field: { value }, meta: { error, touched } }) => (
|
||||
<CustomSelectList
|
||||
items={warehouses}
|
||||
text={'Warehosue'}
|
||||
onItemSelected={({ id }) => {
|
||||
form.setFieldValue('warehouse_id', id);
|
||||
}}
|
||||
selectedItemId={value}
|
||||
buttonProps={{
|
||||
icon: <Icon icon={'warehouse-16'} iconSize={20} />,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</FastField>
|
||||
</FeatureCan>
|
||||
</NavbarGroup>
|
||||
</Navbar>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user