diff --git a/client/src/containers/Sales/Receipts/ReceiptDetails/ReceiptDrawer.js b/client/src/containers/Sales/Receipts/ReceiptDetails/ReceiptDrawer.js index e8308f0ea..d23e5773f 100644 --- a/client/src/containers/Sales/Receipts/ReceiptDetails/ReceiptDrawer.js +++ b/client/src/containers/Sales/Receipts/ReceiptDetails/ReceiptDrawer.js @@ -5,9 +5,7 @@ import withDrawerActions from 'containers/Drawer/withDrawerActions'; import { Drawer, DrawerSuspense } from 'components'; import { compose } from 'utils'; -const ReceiptDrawerContent = lazy(() => - import('containers/Drawers/PaperTemplate/PaperTemplate'), -); +const ReceiptDrawerContent = lazy(() => import('./ReceiptDrawerContent')); /** * receipt drawer. @@ -16,7 +14,7 @@ const ReceiptDrawer = ({ name, //#withDrawer isOpen, - payload, + payload: { receiptId }, closeDrawer, }) => { @@ -25,23 +23,11 @@ const ReceiptDrawer = ({ closeDrawer(name); }; - const propLabels = { - labels: { - name: 'Receipt', - billedTo: 'Billed to', - date: 'Receipt date', - refNo: 'Receipt No.', - billedFrom: 'Billed from', - amount: 'Receipt amount', - dueDate: 'Due date', - }, - }; - return (
- +
diff --git a/client/src/containers/Sales/Receipts/ReceiptDetails/ReceiptDrawerContent.js b/client/src/containers/Sales/Receipts/ReceiptDetails/ReceiptDrawerContent.js new file mode 100644 index 000000000..d7e176bed --- /dev/null +++ b/client/src/containers/Sales/Receipts/ReceiptDetails/ReceiptDrawerContent.js @@ -0,0 +1,17 @@ +import React from 'react'; +import { ReceiptDrawerProvider } from './ReceiptDrawerProvider'; +import ReceiptPaper from './ReceiptPaper'; + +/** + * Receipt drawer content. + */ +export default function ReceiptDrawerContent({ + // #ownProp + receiptId, +}) { + return ( + + + + ); +} diff --git a/client/src/containers/Sales/Receipts/ReceiptDetails/ReceiptDrawerProvider.js b/client/src/containers/Sales/Receipts/ReceiptDetails/ReceiptDrawerProvider.js new file mode 100644 index 000000000..9139170cd --- /dev/null +++ b/client/src/containers/Sales/Receipts/ReceiptDetails/ReceiptDrawerProvider.js @@ -0,0 +1,32 @@ +import React, { createContext, useContext } from 'react'; +import { useReceipt } from 'hooks/query'; +import DashboardInsider from 'components/Dashboard/DashboardInsider'; + +const ReceiptDrawerContext = createContext(); + +function ReceiptDrawerProvider({ receiptId, ...props }) { + // Fetch sale receipt details. + const { + data: { entries, ...receipt }, + isFetching: isReceiptLoading, + } = useReceipt(receiptId, { + enabled: !!receiptId, + }); + // Provider payload. + const provider = { + receiptId, + receipt, + entries, + + isReceiptLoading, + }; + + return ( + + + + ); +} +const useReceiptDrawerContext = () => useContext(ReceiptDrawerContext); + +export { ReceiptDrawerProvider, useReceiptDrawerContext }; diff --git a/client/src/containers/Sales/Receipts/ReceiptDetails/ReceiptPaper.js b/client/src/containers/Sales/Receipts/ReceiptDetails/ReceiptPaper.js new file mode 100644 index 000000000..80473cd1f --- /dev/null +++ b/client/src/containers/Sales/Receipts/ReceiptDetails/ReceiptPaper.js @@ -0,0 +1,37 @@ +import React from 'react'; +import { useReceiptDrawerContext } from './ReceiptDrawerProvider'; +import PaperTemplate from 'containers/Drawers/PaperTemplate/PaperTemplate'; + +export default function ReceiptPaper() { + const { receipt, entries } = useReceiptDrawerContext(); + + const propLabels = { + labels: { + name: 'Receipt', + billedTo: 'Billed to', + date: 'Receipt date', + refNo: 'Receipt No.', + billedFrom: 'Billed from', + amount: 'Receipt amount', + dueDate: 'Due date', + }, + }; + + const receipts = { + billedTo: receipt.customer.display_name, + date: receipt.receipt_date, + amount: '', + billedFrom: '', + dueDate: receipt.due_date, + referenceNo: receipt.receipt_number, + ...receipt, + }; + + return ( + + ); +} diff --git a/client/src/containers/Sales/Receipts/ReceiptsLanding/ReceiptsTable.js b/client/src/containers/Sales/Receipts/ReceiptsLanding/ReceiptsTable.js index a63f8de1b..9b8a55428 100644 --- a/client/src/containers/Sales/Receipts/ReceiptsLanding/ReceiptsTable.js +++ b/client/src/containers/Sales/Receipts/ReceiptsLanding/ReceiptsTable.js @@ -65,10 +65,10 @@ function ReceiptsDataTable({ openAlert('receipt-close', { receiptId: receipt.id }); }; - // Handle drawer receipts. - const handleDrawerReceipt = () => { - openDrawer('receipt-drawer', {}); - }; + // Handle drawer receipts. + const handleDrawerReceipt = ({ id }) => { + openDrawer('receipt-drawer', { receiptId: id }); + }; // Handles the datable fetch data once the state changing. const handleDataTableFetchData = useCallback( @@ -111,7 +111,7 @@ function ReceiptsDataTable({ onEdit: handleEditReceipt, onDelete: handleDeleteReceipt, onClose: handleCloseReceipt, - onDrawer:handleDrawerReceipt, + onDrawer: handleDrawerReceipt, baseCurrency, }} /> diff --git a/client/src/containers/Sales/Receipts/ReceiptsLanding/components.js b/client/src/containers/Sales/Receipts/ReceiptsLanding/components.js index 6e547f4f1..7527fd9e5 100644 --- a/client/src/containers/Sales/Receipts/ReceiptsLanding/components.js +++ b/client/src/containers/Sales/Receipts/ReceiptsLanding/components.js @@ -41,7 +41,7 @@ export function ActionsMenu({ } text={formatMessage({ id: 'receipt_paper' })} - onClick={() => onDrawer()} + onClick={safeCallback(onDrawer, receipt)} />