mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 14:50:32 +00:00
refactoring(estimate drawer): estimate drawer.
This commit is contained in:
@@ -1,19 +1,20 @@
|
|||||||
import React, { lazy } from 'react';
|
import React, { lazy } from 'react';
|
||||||
|
import { Drawer, DrawerSuspense } from 'components';
|
||||||
import withDrawers from 'containers/Drawer/withDrawers';
|
import withDrawers from 'containers/Drawer/withDrawers';
|
||||||
import withDrawerActions from 'containers/Drawer/withDrawerActions';
|
import withDrawerActions from 'containers/Drawer/withDrawerActions';
|
||||||
|
|
||||||
import { Drawer, DrawerSuspense } from 'components';
|
|
||||||
import { compose } from 'utils';
|
import { compose } from 'utils';
|
||||||
|
|
||||||
const EstimateDrawerContent = lazy(() =>
|
const EstimateDrawerContent = lazy(() => import('./EstimateDrawerContent'));
|
||||||
import('containers/Drawers/PaperTemplate/PaperTemplate'),
|
|
||||||
);
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Estimate drawer.
|
||||||
|
*/
|
||||||
function EstimateDrawer({
|
function EstimateDrawer({
|
||||||
name,
|
name,
|
||||||
//#withDrawer
|
//#withDrawer
|
||||||
isOpen,
|
isOpen,
|
||||||
payload,
|
payload: { estimateId },
|
||||||
|
|
||||||
closeDrawer,
|
closeDrawer,
|
||||||
}) {
|
}) {
|
||||||
@@ -24,7 +25,7 @@ function EstimateDrawer({
|
|||||||
return (
|
return (
|
||||||
<Drawer isOpen={isOpen} isClose={handleDrawerClose}>
|
<Drawer isOpen={isOpen} isClose={handleDrawerClose}>
|
||||||
<DrawerSuspense>
|
<DrawerSuspense>
|
||||||
<EstimateDrawerContent />
|
<EstimateDrawerContent estimateId={estimateId} />
|
||||||
</DrawerSuspense>
|
</DrawerSuspense>
|
||||||
</Drawer>
|
</Drawer>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { EstimateDrawerProvider } from './EstimateDrawerProvider';
|
||||||
|
import EstimatePaper from './EstimatePaper';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Estimate drawer content.
|
||||||
|
*/
|
||||||
|
export default function EstimateDrawerContent({
|
||||||
|
// #ownProp
|
||||||
|
estimateId,
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<EstimateDrawerProvider estimateId={estimateId}>
|
||||||
|
<EstimatePaper />
|
||||||
|
</EstimateDrawerProvider>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import React, { createContext } from 'react';
|
||||||
|
import { useEstimate } from 'hooks/query';
|
||||||
|
import DashboardInsider from 'components/Dashboard/DashboardInsider';
|
||||||
|
|
||||||
|
const EstimateDrawerContext = createContext();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Estimate drawer provider.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function EstimateDrawerProvider({ estimateId, ...props }) {
|
||||||
|
const {
|
||||||
|
data: { entries, ...estimate },
|
||||||
|
isLoading: isEstimateLoading,
|
||||||
|
} = useEstimate(estimateId, { enabled: !!estimateId });
|
||||||
|
|
||||||
|
// Provider payload.
|
||||||
|
const provider = {
|
||||||
|
estimateId,
|
||||||
|
estimate,
|
||||||
|
entries,
|
||||||
|
isEstimateLoading,
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DashboardInsider loading={isEstimateLoading}>
|
||||||
|
<EstimateDrawerContext.Provider value={provider} {...props} />
|
||||||
|
</DashboardInsider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const useEstimateDrawerContext = () => React.useContext(EstimateDrawerContext);
|
||||||
|
|
||||||
|
export { EstimateDrawerProvider, useEstimateDrawerContext };
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { useEstimateDrawerContext } from './EstimateDrawerProvider';
|
||||||
|
import PaperTemplate from 'containers/Drawers/PaperTemplate/PaperTemplate';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Estimate paper.
|
||||||
|
*/
|
||||||
|
export default function EstimatePaper() {
|
||||||
|
const { estimate, entries } = useEstimateDrawerContext();
|
||||||
|
return <PaperTemplate paperData={estimate} entries={entries} />;
|
||||||
|
}
|
||||||
@@ -68,8 +68,8 @@ function EstimatesDataTable({
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Handle drawer estimate.
|
// Handle drawer estimate.
|
||||||
const handleDrawerEstimate = () => {
|
const handleDrawerEstimate = ({ id }) => {
|
||||||
openDrawer('estimate-drawer', {});
|
openDrawer('estimate-drawer', { estimateId: id });
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle convent to invoice.
|
// Handle convent to invoice.
|
||||||
|
|||||||
@@ -49,7 +49,15 @@ export const statusAccessor = (row) => (
|
|||||||
*/
|
*/
|
||||||
export function ActionsMenu({
|
export function ActionsMenu({
|
||||||
row: { original },
|
row: { original },
|
||||||
payload: { onEdit, onDeliver, onReject, onApprove, onDelete, onDrawer ,onConvert },
|
payload: {
|
||||||
|
onEdit,
|
||||||
|
onDeliver,
|
||||||
|
onReject,
|
||||||
|
onApprove,
|
||||||
|
onDelete,
|
||||||
|
onDrawer,
|
||||||
|
onConvert,
|
||||||
|
},
|
||||||
}) {
|
}) {
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
|
|
||||||
@@ -108,7 +116,7 @@ export function ActionsMenu({
|
|||||||
<MenuItem
|
<MenuItem
|
||||||
icon={<Icon icon={'receipt-24'} iconSize={16} />}
|
icon={<Icon icon={'receipt-24'} iconSize={16} />}
|
||||||
text={formatMessage({ id: 'estimate_paper' })}
|
text={formatMessage({ id: 'estimate_paper' })}
|
||||||
onClick={() => onDrawer()}
|
onClick={safeCallback(onDrawer, original)}
|
||||||
/>
|
/>
|
||||||
<MenuItem
|
<MenuItem
|
||||||
text={formatMessage({ id: 'delete_estimate' })}
|
text={formatMessage({ id: 'delete_estimate' })}
|
||||||
|
|||||||
Reference in New Issue
Block a user