mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 14:50:32 +00:00
refactoring(invoice drawer): invoice drawer.
This commit is contained in:
@@ -5,9 +5,7 @@ import withDrawerActions from 'containers/Drawer/withDrawerActions';
|
|||||||
import { Drawer, DrawerSuspense } from 'components';
|
import { Drawer, DrawerSuspense } from 'components';
|
||||||
import { compose } from 'utils';
|
import { compose } from 'utils';
|
||||||
|
|
||||||
const InvoicesDrawerContent = lazy(() =>
|
const InvoicesDrawerContent = lazy(() => import('./InvoiceDrawerContent'));
|
||||||
import('containers/Drawers/PaperTemplate/PaperTemplate'),
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* invoice drawer.
|
* invoice drawer.
|
||||||
@@ -16,7 +14,7 @@ function InvoiceDrawer({
|
|||||||
name,
|
name,
|
||||||
//#withDrawer
|
//#withDrawer
|
||||||
isOpen,
|
isOpen,
|
||||||
payload,
|
payload: { invoiceId },
|
||||||
|
|
||||||
closeDrawer,
|
closeDrawer,
|
||||||
}) {
|
}) {
|
||||||
@@ -25,22 +23,10 @@ function InvoiceDrawer({
|
|||||||
closeDrawer(name);
|
closeDrawer(name);
|
||||||
};
|
};
|
||||||
|
|
||||||
const propLabels = {
|
|
||||||
labels: {
|
|
||||||
name: 'Invoice',
|
|
||||||
billedTo: 'Billed to',
|
|
||||||
date: 'Invoice date',
|
|
||||||
refNo: 'Invoice No.',
|
|
||||||
billedFrom: 'Billed from',
|
|
||||||
amount: 'Invoice amount',
|
|
||||||
dueDate: 'Due date',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Drawer isOpen={isOpen} isClose={handleDrawerClose}>
|
<Drawer isOpen={isOpen} isClose={handleDrawerClose}>
|
||||||
<DrawerSuspense>
|
<DrawerSuspense>
|
||||||
<InvoicesDrawerContent labels={propLabels.labels} />
|
<InvoicesDrawerContent invoiceId={invoiceId} />
|
||||||
</DrawerSuspense>
|
</DrawerSuspense>
|
||||||
</Drawer>
|
</Drawer>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { InvoiceDrawerProvider } from './InvoiceDrawerProvider';
|
||||||
|
import InvoicePaper from './InvoicePaper';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoice drawer content.
|
||||||
|
*/
|
||||||
|
export default function InvoiceDrawerContent({
|
||||||
|
// #ownProp
|
||||||
|
invoiceId,
|
||||||
|
}) {
|
||||||
|
|
||||||
|
return (
|
||||||
|
<InvoiceDrawerProvider invoiceId={invoiceId}>
|
||||||
|
<InvoicePaper />
|
||||||
|
</InvoiceDrawerProvider>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
import React, { createContext, useContext } from 'react';
|
||||||
|
import { useInvoice } from 'hooks/query';
|
||||||
|
import DashboardInsider from 'components/Dashboard/DashboardInsider';
|
||||||
|
|
||||||
|
const InvoiceDrawerContext = createContext();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoice drawer provider.
|
||||||
|
*/
|
||||||
|
function InvoiceDrawerProvider({ invoiceId, ...props }) {
|
||||||
|
// Fetch sale invoice details.
|
||||||
|
const {
|
||||||
|
data: { entries, ...invoice },
|
||||||
|
isLoading: isInvoiceLoading,
|
||||||
|
} = useInvoice(invoiceId, {
|
||||||
|
enabled: !!invoiceId,
|
||||||
|
});
|
||||||
|
// Provider payload.
|
||||||
|
const provider = {
|
||||||
|
invoiceId,
|
||||||
|
invoice,
|
||||||
|
entries,
|
||||||
|
|
||||||
|
isInvoiceLoading,
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DashboardInsider loading={isInvoiceLoading}>
|
||||||
|
<InvoiceDrawerContext.Provider value={provider} {...props} />
|
||||||
|
</DashboardInsider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const useInvoiceDrawerContext = () => useContext(InvoiceDrawerContext);
|
||||||
|
|
||||||
|
export { InvoiceDrawerProvider, useInvoiceDrawerContext };
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { useInvoiceDrawerContext } from './InvoiceDrawerProvider';
|
||||||
|
import PaperTemplate from 'containers/Drawers/PaperTemplate/PaperTemplate';
|
||||||
|
|
||||||
|
export default function InvoicePaper() {
|
||||||
|
const { invoice, entries } = useInvoiceDrawerContext();
|
||||||
|
|
||||||
|
const propLabels = {
|
||||||
|
labels: {
|
||||||
|
name: 'Invoice',
|
||||||
|
billedTo: 'Billed to',
|
||||||
|
date: 'Invoice date',
|
||||||
|
refNo: 'Invoice No.',
|
||||||
|
billedFrom: 'Billed from',
|
||||||
|
amount: 'Invoice amount',
|
||||||
|
dueDate: 'Due date',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const defaultValues = {
|
||||||
|
billedTo: invoice.customer.display_name,
|
||||||
|
date: invoice.invoice_date,
|
||||||
|
amount: invoice.balance,
|
||||||
|
billedFrom: '',
|
||||||
|
dueDate: invoice.due_date,
|
||||||
|
referenceNo: invoice.invoice_no,
|
||||||
|
...invoice,
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<PaperTemplate
|
||||||
|
labels={propLabels.labels}
|
||||||
|
paperData={defaultValues}
|
||||||
|
entries={entries}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -67,8 +67,8 @@ function InvoicesDataTable({
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Handle drawer invoice.
|
// Handle drawer invoice.
|
||||||
const handleDrawerInvoice = () => {
|
const handleDrawerInvoice = ({ id }) => {
|
||||||
openDrawer('invoice-drawer', {});
|
openDrawer('invoice-drawer', { invoiceId: id });
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handles fetch data once the table state change.
|
// Handles fetch data once the table state change.
|
||||||
|
|||||||
@@ -90,6 +90,18 @@ export const handleDeleteErrors = (errors) => {
|
|||||||
intent: Intent.DANGER,
|
intent: Intent.DANGER,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (
|
||||||
|
errors.find(
|
||||||
|
(error) => error.type === 'INVOICE_AMOUNT_SMALLER_THAN_PAYMENT_AMOUNT',
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
AppToaster.show({
|
||||||
|
message: formatMessage({
|
||||||
|
id: 'the_payment_amount_that_received',
|
||||||
|
}),
|
||||||
|
intent: Intent.DANGER,
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export function ActionsMenu({
|
export function ActionsMenu({
|
||||||
@@ -120,7 +132,7 @@ export function ActionsMenu({
|
|||||||
<MenuItem
|
<MenuItem
|
||||||
icon={<Icon icon={'receipt-24'} iconSize={16} />}
|
icon={<Icon icon={'receipt-24'} iconSize={16} />}
|
||||||
text={formatMessage({ id: 'invoice_paper' })}
|
text={formatMessage({ id: 'invoice_paper' })}
|
||||||
onClick={() => onDrawer()}
|
onClick={safeCallback(onDrawer, original)}
|
||||||
/>
|
/>
|
||||||
<MenuItem
|
<MenuItem
|
||||||
text={formatMessage({ id: 'delete_invoice' })}
|
text={formatMessage({ id: 'delete_invoice' })}
|
||||||
|
|||||||
Reference in New Issue
Block a user