mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 22:30:31 +00:00
re-structure to monorepo.
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import clsx from 'classnames';
|
||||
|
||||
import { Card } from '@/components';
|
||||
|
||||
import VendorDetailsActionsBar from './VendorDetailsActionsBar';
|
||||
import VendorDetailsHeader from './VendorDetailsHeader';
|
||||
|
||||
import Style from './VendorDetailsDrawer.module.scss';
|
||||
|
||||
/**
|
||||
* contact detail.
|
||||
*/
|
||||
export default function CustomerDetails() {
|
||||
return (
|
||||
<div className={clsx(Style.root)}>
|
||||
<VendorDetailsActionsBar />
|
||||
|
||||
<Card>
|
||||
<VendorDetailsHeader />
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import {
|
||||
Button,
|
||||
NavbarGroup,
|
||||
Classes,
|
||||
NavbarDivider,
|
||||
Intent,
|
||||
PopoverInteractionKind,
|
||||
Position,
|
||||
MenuItem,
|
||||
Menu,
|
||||
Popover,
|
||||
} from '@blueprintjs/core';
|
||||
import clsx from 'classnames';
|
||||
|
||||
import { useVendorDetailsDrawerContext } from './VendorDetailsDrawerProvider';
|
||||
|
||||
import withAlertsActions from '@/containers/Alert/withAlertActions';
|
||||
import withDrawerActions from '@/containers/Drawer/withDrawerActions';
|
||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||
|
||||
import {
|
||||
Can,
|
||||
Icon,
|
||||
DashboardActionsBar,
|
||||
FormattedMessage as T,
|
||||
} from '@/components';
|
||||
import { VendorMoreMenuItem } from './utils';
|
||||
import {
|
||||
AbilitySubject,
|
||||
SaleInvoiceAction,
|
||||
PaymentMadeAction,
|
||||
VendorAction,
|
||||
} from '../../../constants/abilityOption';
|
||||
import { safeCallback, compose } from '@/utils';
|
||||
|
||||
/**
|
||||
* Vendor details actions bar.
|
||||
*/
|
||||
function VendorDetailsActionsBar({
|
||||
// #withDialogActions
|
||||
openDialog,
|
||||
|
||||
// #withAlertsActions
|
||||
openAlert,
|
||||
|
||||
// #withDrawerActions
|
||||
closeDrawer,
|
||||
}) {
|
||||
const { vendorId } = useVendorDetailsDrawerContext();
|
||||
const history = useHistory();
|
||||
|
||||
// Handle edit vendor.
|
||||
const onEditContact = () => {
|
||||
history.push(`/vendors/${vendorId}/edit`);
|
||||
closeDrawer('vendor-detail-drawer');
|
||||
};
|
||||
|
||||
// Handle delete vendor.
|
||||
const onDeleteContact = () => {
|
||||
openAlert(`vendor-delete`, { contactId: vendorId });
|
||||
};
|
||||
|
||||
const handleNewInvoiceClick = () => {
|
||||
history.push('/bills/new');
|
||||
closeDrawer('vendor-detail-drawer');
|
||||
};
|
||||
|
||||
const handleNewPaymentClick = () => {
|
||||
history.push('/payment-mades/new');
|
||||
closeDrawer('vendor-detail-drawer');
|
||||
};
|
||||
|
||||
const handleEditOpeningBalance = () => {
|
||||
openDialog('vendor-opening-balance', { vendorId });
|
||||
};
|
||||
|
||||
return (
|
||||
<DashboardActionsBar>
|
||||
<NavbarGroup>
|
||||
<Popover
|
||||
content={
|
||||
<Menu>
|
||||
<Can I={SaleInvoiceAction.Create} a={AbilitySubject.Invoice}>
|
||||
<MenuItem
|
||||
text={<T id={'vendor.drawer.action.new_invoice'} />}
|
||||
onClick={handleNewInvoiceClick}
|
||||
/>
|
||||
</Can>
|
||||
<Can I={PaymentMadeAction.Create} a={AbilitySubject.PaymentMade}>
|
||||
<MenuItem
|
||||
text={<T id={'vendor.drawer.action.new_payment'} />}
|
||||
onClick={handleNewPaymentClick}
|
||||
/>
|
||||
</Can>
|
||||
</Menu>
|
||||
}
|
||||
minimal={true}
|
||||
interactionKind={PopoverInteractionKind.CLICK}
|
||||
position={Position.BOTTOM_LEFT}
|
||||
>
|
||||
<Button
|
||||
className={clsx(Classes.MINIMAL)}
|
||||
text={<T id={'vendor.drawer.action.new_transaction'} />}
|
||||
icon={<Icon icon={'plus'} />}
|
||||
/>
|
||||
</Popover>
|
||||
<Can I={VendorAction.Edit} a={AbilitySubject.Vendor}>
|
||||
<NavbarDivider />
|
||||
<Button
|
||||
className={Classes.MINIMAL}
|
||||
icon={<Icon icon="pen-18" />}
|
||||
text={<T id={'vendor.drawer.action.edit'} />}
|
||||
onClick={safeCallback(onEditContact)}
|
||||
/>
|
||||
</Can>
|
||||
<Can I={VendorAction.Delete} a={AbilitySubject.Vendor}>
|
||||
<NavbarDivider />
|
||||
<Button
|
||||
className={Classes.MINIMAL}
|
||||
icon={<Icon icon={'trash-16'} iconSize={16} />}
|
||||
text={<T id={'vendor.drawer.action.delete'} />}
|
||||
intent={Intent.DANGER}
|
||||
onClick={safeCallback(onDeleteContact)}
|
||||
/>
|
||||
</Can>
|
||||
<NavbarDivider />
|
||||
<VendorMoreMenuItem
|
||||
payload={{
|
||||
onEditOpeningBalance: handleEditOpeningBalance,
|
||||
}}
|
||||
/>
|
||||
</NavbarGroup>
|
||||
</DashboardActionsBar>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withDrawerActions,
|
||||
withAlertsActions,
|
||||
withDialogActions,
|
||||
)(VendorDetailsActionsBar);
|
||||
@@ -0,0 +1,17 @@
|
||||
.root {
|
||||
|
||||
|
||||
&_content {
|
||||
|
||||
&_primary {
|
||||
padding-bottom: 15px;
|
||||
border-bottom: 1px solid #e2e2e2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
:global .card {
|
||||
margin: 15px;
|
||||
padding: 18px;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
|
||||
import { VendorDetailsDrawerProvider } from './VendorDetailsDrawerProvider';
|
||||
import { DrawerBody } from '@/components';
|
||||
import VendorDetails from './VendorDetails';
|
||||
|
||||
/**
|
||||
* Contact detail drawer content.
|
||||
*/
|
||||
export default function VendorDetailsDrawerContent({
|
||||
// #ownProp
|
||||
vendorId,
|
||||
}) {
|
||||
return (
|
||||
<VendorDetailsDrawerProvider vendorId={vendorId}>
|
||||
<DrawerBody>
|
||||
<VendorDetails />
|
||||
</DrawerBody>
|
||||
</VendorDetailsDrawerProvider>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import { DrawerHeaderContent, DrawerLoading } from '@/components';
|
||||
import { useVendor } from '@/hooks/query';
|
||||
|
||||
const VendorDetailDrawerContext = React.createContext();
|
||||
|
||||
/**
|
||||
* Contact detail provider.
|
||||
*/
|
||||
function VendorDetailsDrawerProvider({ vendorId, ...props }) {
|
||||
// Handle fetch vendor details.
|
||||
const { data: vendor, isLoading: isVendorLoading } = useVendor(vendorId, {
|
||||
enabled: !!vendorId,
|
||||
});
|
||||
// Provider.
|
||||
const provider = {
|
||||
vendor,
|
||||
vendorId,
|
||||
isVendorLoading,
|
||||
};
|
||||
|
||||
return (
|
||||
<DrawerLoading loading={isVendorLoading}>
|
||||
<DrawerHeaderContent
|
||||
name="vendor-detail-drawer"
|
||||
title={vendor?.display_name}
|
||||
/>
|
||||
<VendorDetailDrawerContext.Provider value={provider} {...props} />
|
||||
</DrawerLoading>
|
||||
);
|
||||
}
|
||||
|
||||
const useVendorDetailsDrawerContext = () =>
|
||||
React.useContext(VendorDetailDrawerContext);
|
||||
|
||||
export { VendorDetailsDrawerProvider, useVendorDetailsDrawerContext };
|
||||
@@ -0,0 +1,82 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import intl from 'react-intl-universal';
|
||||
import clsx from 'classnames';
|
||||
import { defaultTo } from 'lodash';
|
||||
|
||||
import { T, DetailsMenu, DetailItem } from '@/components';
|
||||
|
||||
import { useVendorDetailsDrawerContext } from './VendorDetailsDrawerProvider';
|
||||
|
||||
import Style from './VendorDetailsDrawer.module.scss';
|
||||
|
||||
/**
|
||||
* Vendor details header.
|
||||
*/
|
||||
export default function VendorDetailsHeader() {
|
||||
const { vendor } = useVendorDetailsDrawerContext();
|
||||
|
||||
return (
|
||||
<div className={clsx(Style.root_content)}>
|
||||
<DetailsMenu
|
||||
direction={'vertical'}
|
||||
className={clsx(Style.root_content_primary)}
|
||||
>
|
||||
<DetailItem
|
||||
name={'outstanding-payable'}
|
||||
label={<T id={'vendor.drawer.label.outstanding_payable'} />}
|
||||
>
|
||||
<h3 class="big-number">{vendor.formatted_balance}</h3>
|
||||
</DetailItem>
|
||||
|
||||
<DetailItem label={<T id={'vendor.drawer.label.unused_credits'} />}>
|
||||
0
|
||||
</DetailItem>
|
||||
</DetailsMenu>
|
||||
|
||||
<DetailsMenu direction={'horizantal'} minLabelSize={'175px'}>
|
||||
<DetailItem
|
||||
label={<T id={'vendor.drawer.label.vendor'} />}
|
||||
name={'name'}
|
||||
>
|
||||
<strong>{vendor?.display_name}</strong>
|
||||
</DetailItem>
|
||||
|
||||
<DetailItem
|
||||
label={<T id={'vendor.drawer.label.company_name'} />}
|
||||
children={defaultTo(vendor?.company_name, '--')}
|
||||
/>
|
||||
<DetailItem
|
||||
label={intl.get('email')}
|
||||
children={defaultTo(vendor.email, '--')}
|
||||
/>
|
||||
<DetailItem label={<T id={'vendor.drawer.label.phone_number'} />}>
|
||||
<div>{vendor?.personal_phone} </div>
|
||||
<div>{vendor?.work_phone} </div>
|
||||
</DetailItem>
|
||||
|
||||
<DetailItem
|
||||
label={<T id={'vendor.drawer.label.website'} />}
|
||||
children={defaultTo(vendor?.website, '--')}
|
||||
/>
|
||||
<DetailItem
|
||||
label={<T id={'vendor.drawer.label.opening_balance'} />}
|
||||
children={vendor?.formatted_opening_balance}
|
||||
/>
|
||||
<DetailItem
|
||||
label={<T id={'vendor.drawer.label.opening_balance_at'} />}
|
||||
children={vendor?.formatted_opening_balance_at}
|
||||
/>
|
||||
<DetailItem
|
||||
label={<T id={'vendor.drawer.label.currency'} />}
|
||||
children={vendor?.currency_code}
|
||||
/>
|
||||
<DetailItem
|
||||
label={<T id={'vendor.drawer.label.note'} />}
|
||||
children={defaultTo(vendor?.note, '--')}
|
||||
|
||||
/>
|
||||
</DetailsMenu>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import { Drawer, DrawerSuspense } from '@/components';
|
||||
import withDrawers from '@/containers/Drawer/withDrawers';
|
||||
|
||||
import { compose } from '@/utils';
|
||||
|
||||
const VendorDetailsDrawerContent = React.lazy(() =>
|
||||
import('./VendorDetailsDrawerContent'),
|
||||
);
|
||||
|
||||
/**
|
||||
* Vendor details drawer.
|
||||
*/
|
||||
function VendorDetailsDrawer({
|
||||
name,
|
||||
|
||||
// #withDrawer
|
||||
isOpen,
|
||||
payload: { vendorId },
|
||||
}) {
|
||||
return (
|
||||
<Drawer isOpen={isOpen} name={name} size={'750px'}>
|
||||
<DrawerSuspense>
|
||||
<VendorDetailsDrawerContent vendorId={vendorId} />
|
||||
</DrawerSuspense>
|
||||
</Drawer>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(withDrawers())(VendorDetailsDrawer);
|
||||
@@ -0,0 +1,38 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import {
|
||||
Button,
|
||||
Popover,
|
||||
PopoverInteractionKind,
|
||||
Position,
|
||||
MenuItem,
|
||||
Menu,
|
||||
} from '@blueprintjs/core';
|
||||
import { Icon, FormattedMessage as T } from '@/components';
|
||||
|
||||
/**
|
||||
* Vendor more actions menu items.
|
||||
* @param {*} param0
|
||||
*/
|
||||
export function VendorMoreMenuItem({ payload: { onEditOpeningBalance } }) {
|
||||
return (
|
||||
<Popover
|
||||
minimal={true}
|
||||
interactionKind={PopoverInteractionKind.CLICK}
|
||||
position={Position.BOTTOM_LEFT}
|
||||
modifiers={{
|
||||
offset: { offset: '0, 4' },
|
||||
}}
|
||||
content={
|
||||
<Menu>
|
||||
<MenuItem
|
||||
text={<T id={'vendor.drawer.action.edit_opening_balance'} />}
|
||||
onClick={onEditOpeningBalance}
|
||||
/>
|
||||
</Menu>
|
||||
}
|
||||
>
|
||||
<Button icon={<Icon icon="more-vert" iconSize={16} />} minimal={true} />
|
||||
</Popover>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user