mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 22:00:31 +00:00
chrone: sperate client and server to different repos.
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import React from 'react';
|
||||
|
||||
import ItemDetailActionsBar from './ItemDetailActionsBar';
|
||||
import ItemDetailHeader from './ItemDetailHeader';
|
||||
|
||||
import { Card } from 'components';
|
||||
|
||||
/**
|
||||
* Item detail.
|
||||
*/
|
||||
export default function ItemDetail() {
|
||||
return (
|
||||
<div className="item-drawer">
|
||||
<ItemDetailActionsBar />
|
||||
|
||||
<Card>
|
||||
<ItemDetailHeader />
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
import React from 'react';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import {
|
||||
Button,
|
||||
NavbarGroup,
|
||||
Classes,
|
||||
NavbarDivider,
|
||||
Intent,
|
||||
} from '@blueprintjs/core';
|
||||
import DashboardActionsBar from 'components/Dashboard/DashboardActionsBar';
|
||||
|
||||
import { useItemDetailDrawerContext } from './ItemDetailDrawerProvider';
|
||||
|
||||
import withAlertsActions from 'containers/Alert/withAlertActions';
|
||||
import withDrawerActions from 'containers/Drawer/withDrawerActions';
|
||||
|
||||
import { Icon, FormattedMessage as T } from 'components';
|
||||
|
||||
import { compose } from 'utils';
|
||||
|
||||
/**
|
||||
* Item action-bar of readonly details drawer.
|
||||
*/
|
||||
function ItemDetailActionsBar({
|
||||
// #withAlertsActions
|
||||
openAlert,
|
||||
|
||||
// #withDrawerActions
|
||||
closeDrawer,
|
||||
}) {
|
||||
// Item readonly drawer context.
|
||||
const { itemId } = useItemDetailDrawerContext();
|
||||
|
||||
const history = useHistory();
|
||||
|
||||
// Handle edit item.
|
||||
const handleEditItem = () => {
|
||||
history.push(`/items/${itemId}/edit`);
|
||||
closeDrawer('item-detail-drawer');
|
||||
};
|
||||
|
||||
// Handle delete item.
|
||||
const handleDeleteItem = () => {
|
||||
openAlert('item-delete', { itemId });
|
||||
};
|
||||
|
||||
return (
|
||||
<DashboardActionsBar>
|
||||
<NavbarGroup>
|
||||
<Button
|
||||
className={Classes.MINIMAL}
|
||||
icon={<Icon icon="pen-18" />}
|
||||
text={<T id={'edit_item'} />}
|
||||
onClick={handleEditItem}
|
||||
/>
|
||||
<NavbarDivider />
|
||||
<Button
|
||||
className={Classes.MINIMAL}
|
||||
icon={<Icon icon={'trash-16'} iconSize={16} />}
|
||||
text={<T id={'delete'} />}
|
||||
intent={Intent.DANGER}
|
||||
onClick={handleDeleteItem}
|
||||
/>
|
||||
</NavbarGroup>
|
||||
</DashboardActionsBar>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withDrawerActions,
|
||||
withAlertsActions,
|
||||
)(ItemDetailActionsBar);
|
||||
@@ -0,0 +1,23 @@
|
||||
import React from 'react';
|
||||
|
||||
import 'style/components/Drawers/ItemDrawer.scss';
|
||||
|
||||
import { DrawerBody } from 'components';
|
||||
import ItemContentDetails from './ItemContentDetails';
|
||||
import { ItemDetailDrawerProvider } from './ItemDetailDrawerProvider';
|
||||
|
||||
/**
|
||||
* Item detail drawer content.
|
||||
*/
|
||||
export default function ItemDetailDrawerContent({
|
||||
// #ownProp
|
||||
itemId,
|
||||
}) {
|
||||
return (
|
||||
<ItemDetailDrawerProvider itemId={itemId}>
|
||||
<DrawerBody>
|
||||
<ItemContentDetails />
|
||||
</DrawerBody>
|
||||
</ItemDetailDrawerProvider>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import React from 'react';
|
||||
import { DrawerHeaderContent, DrawerLoading } from 'components';
|
||||
import { useItem } from 'hooks/query';
|
||||
|
||||
const ItemDetailDrawerContext = React.createContext();
|
||||
|
||||
/**
|
||||
* Item detail provider
|
||||
*/
|
||||
function ItemDetailDrawerProvider({ itemId, ...props }) {
|
||||
// Fetches the given item detail.
|
||||
const { isLoading: isItemLoading, data: item } = useItem(itemId, {
|
||||
enabled: !!itemId,
|
||||
});
|
||||
|
||||
//provider.
|
||||
const provider = {
|
||||
item,
|
||||
itemId,
|
||||
isItemLoading,
|
||||
};
|
||||
|
||||
return (
|
||||
<DrawerLoading loading={isItemLoading}>
|
||||
<DrawerHeaderContent name="item-detail-drawer" title={item?.name} />
|
||||
<ItemDetailDrawerContext.Provider value={provider} {...props} />
|
||||
</DrawerLoading>
|
||||
);
|
||||
}
|
||||
const useItemDetailDrawerContext = () =>
|
||||
React.useContext(ItemDetailDrawerContext);
|
||||
|
||||
export { ItemDetailDrawerProvider, useItemDetailDrawerContext };
|
||||
82
src/containers/Drawers/ItemDetailDrawer/ItemDetailHeader.js
Normal file
82
src/containers/Drawers/ItemDetailDrawer/ItemDetailHeader.js
Normal file
@@ -0,0 +1,82 @@
|
||||
import React from 'react';
|
||||
import intl from 'react-intl-universal';
|
||||
import { defaultTo } from 'lodash';
|
||||
import classNames from 'classnames';
|
||||
|
||||
import { If, DetailsMenu, DetailItem } from 'components';
|
||||
import { useItemDetailDrawerContext } from './ItemDetailDrawerProvider';
|
||||
|
||||
/**
|
||||
* Item header drawer of readonly details.
|
||||
*/
|
||||
export default function ItemDetailHeader() {
|
||||
const { item } = useItemDetailDrawerContext();
|
||||
|
||||
return (
|
||||
<div class="item-drawer__content">
|
||||
<DetailsMenu direction={'vertical'}>
|
||||
<DetailItem
|
||||
name={'name'}
|
||||
label={intl.get('item_name')}
|
||||
children={item.name}
|
||||
/>
|
||||
<DetailItem
|
||||
label={intl.get('sell_price')}
|
||||
children={item.sell_price_formatted}
|
||||
align={'right'}
|
||||
/>
|
||||
<DetailItem
|
||||
label={intl.get('cost_price')}
|
||||
children={item.cost_price_formatted}
|
||||
align={'right'}
|
||||
/>
|
||||
</DetailsMenu>
|
||||
|
||||
<DetailsMenu direction={'horizantal'}>
|
||||
<DetailItem label={intl.get('item_type')} children={item.type} />
|
||||
<DetailItem
|
||||
label={intl.get('item_code')}
|
||||
children={defaultTo(item.code, '-')}
|
||||
/>
|
||||
<If condition={item.type === 'inventory'}>
|
||||
<DetailItem name={'quantity'} label={intl.get('quantity_on_hand')}>
|
||||
<span
|
||||
className={classNames({
|
||||
mines: item.quantity_on_hand <= 0,
|
||||
plus: item.quantity_on_hand > 0,
|
||||
})}
|
||||
>
|
||||
{defaultTo(item.quantity_on_hand, '-')}
|
||||
</span>
|
||||
</DetailItem>
|
||||
</If>
|
||||
<DetailItem
|
||||
label={intl.get('category_name')}
|
||||
children={defaultTo(item.category?.name, '-')}
|
||||
/>
|
||||
<DetailItem
|
||||
label={intl.get('cost_account_id')}
|
||||
children={defaultTo(item.cost_account?.name, '-')}
|
||||
/>
|
||||
<If condition={item.type === 'inventory'}>
|
||||
<DetailItem
|
||||
label={intl.get('inventory_account')}
|
||||
children={defaultTo(item?.inventory_account?.name, '-')}
|
||||
/>
|
||||
</If>
|
||||
<DetailItem
|
||||
label={intl.get('sell_account_id')}
|
||||
children={defaultTo(item?.sell_account?.name, '-')}
|
||||
/>
|
||||
<DetailItem
|
||||
label={intl.get('item.sell_description')}
|
||||
children={defaultTo(item.sell_description, '-')}
|
||||
/>
|
||||
<DetailItem
|
||||
label={intl.get('item.purchase_description')}
|
||||
children={defaultTo(item.cost_description, '-')}
|
||||
/>
|
||||
</DetailsMenu>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
29
src/containers/Drawers/ItemDetailDrawer/index.js
Normal file
29
src/containers/Drawers/ItemDetailDrawer/index.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import React from 'react';
|
||||
import { Drawer, DrawerSuspense } from 'components';
|
||||
import withDrawers from 'containers/Drawer/withDrawers';
|
||||
|
||||
import { compose } from 'utils';
|
||||
|
||||
const ItemDetailDrawerContent = React.lazy(() =>
|
||||
import('./ItemDetailDrawerContent'),
|
||||
);
|
||||
|
||||
/**
|
||||
* Item Detail drawer.
|
||||
*/
|
||||
function ItemDetailDrawer({
|
||||
name,
|
||||
|
||||
// #withDrawer
|
||||
isOpen,
|
||||
payload: { itemId },
|
||||
}) {
|
||||
return (
|
||||
<Drawer isOpen={isOpen} name={name} size={'750px'}>
|
||||
<DrawerSuspense>
|
||||
<ItemDetailDrawerContent itemId={itemId} />
|
||||
</DrawerSuspense>
|
||||
</Drawer>
|
||||
);
|
||||
}
|
||||
export default compose(withDrawers())(ItemDetailDrawer);
|
||||
Reference in New Issue
Block a user