diff --git a/client/src/containers/Items/ItemsViewsTabs.js b/client/src/containers/Items/ItemsViewsTabs.js index ce3ece5cc..04959f9ff 100644 --- a/client/src/containers/Items/ItemsViewsTabs.js +++ b/client/src/containers/Items/ItemsViewsTabs.js @@ -40,6 +40,9 @@ function ItemsViewsTabs({ useEffect(() => { setTopbarEditView(customViewId); changePageSubtitle(customViewId && viewItem ? viewItem.name : ''); + addItemsTableQueries({ + custom_view_id: customViewId || null, + }); }, [customViewId]); const handleClickNewView = () => {}; diff --git a/client/src/containers/Sales/Receipt/ReceiptActionsBar.js b/client/src/containers/Sales/Receipt/ReceiptActionsBar.js index 12912af5c..26cff7239 100644 --- a/client/src/containers/Sales/Receipt/ReceiptActionsBar.js +++ b/client/src/containers/Sales/Receipt/ReceiptActionsBar.js @@ -37,12 +37,12 @@ function ReceiptActionsBar({ receiptview, //#withReceiptActions addReceiptsTableQueries, + changeReceiptView, //#OWn Props onFilterChanged, selectedRows = [], }) { - const { path } = useRouteMatch(); const history = useHistory(); const [filterCount, setFilterCount] = useState(0); const { formatMessage } = useIntl(); @@ -51,6 +51,17 @@ function ReceiptActionsBar({ history.push('/receipts/new'); }, [history]); + const hasSelectedRows = useMemo(() => selectedRows.length > 0, [ + selectedRows, + ]); + + const handleTabChange = (viewId) => { + changeReceiptView(viewId.id || -1); + addReceiptsTableQueries({ + custom_view_id: viewId.id || null, + }); + }; + // const filterDropdown = FilterDropdown({ // initialCondition: { // fieldKey: '', @@ -66,16 +77,13 @@ function ReceiptActionsBar({ // }, // }); - const hasSelectedRows = useMemo(() => selectedRows.length > 0, [ - selectedRows, - ]); - return ( diff --git a/client/src/containers/Sales/Receipt/ReceiptList.js b/client/src/containers/Sales/Receipt/ReceiptList.js index 1617bc748..283dc3f23 100644 --- a/client/src/containers/Sales/Receipt/ReceiptList.js +++ b/client/src/containers/Sales/Receipt/ReceiptList.js @@ -43,19 +43,15 @@ function ReceiptList({ const [closeReceipt, setCloseReceipt] = useState(false); const [selectedRows, setSelectedRows] = useState([]); - const fetchReceipts = useQuery(['receipts-table', receiptTableQuery], () => - requestFetchReceiptsTable(), + const fetchReceipts = useQuery( + ['receipts-table', receiptTableQuery], + (key, query) => requestFetchReceiptsTable({ ...query }), ); - // const fetchResourceViews = useQuery( - // ['resource-views', 'sales_receipts'], - // (key, resourceName) => requestFetchResourceViews(resourceName), - // ); - - // const fetchResourceFields = useQuery( - // ['resource-fields', 'sales_receipts'], - // (key, resourceName) => requestFetchResourceFields(resourceName), - // ); + const fetchResourceViews = useQuery( + ['resource-views', 'sale_receipt'], + (key, resourceName) => requestFetchResourceViews(resourceName), + ); useEffect(() => { changePageTitle(formatMessage({ id: 'receipt_list' })); @@ -150,7 +146,7 @@ function ReceiptList({ return ( { - changeReceiptView(customViewId || -1); setTopbarEditView(customViewId); changePageSubtitle(customViewId && viewItem ? viewItem.name : ''); + // changeReceiptView(customViewId || -1); + // addReceiptsTableQueries({ + // custom_view_id: customViewId || null, + // }); + }, [customViewId, addReceiptsTableQueries]); - addReceiptsTableQueries({ - custom_view_id: customViewId, - }); - return () => { - setTopbarEditView(null); - changePageSubtitle(''); - changeReceiptView(null); - }; - }, [customViewId, addReceiptsTableQueries, changeReceiptView]); - - useUpdateEffect(() => { - onViewChanged && onViewChanged(customViewId); - }, [customViewId]); - - const debounceChangeHistory = useRef( - debounce((toUrl) => { - history.push(toUrl); - }, 250), - ); - - const handleTabsChange = (viewId) => { - const toPath = viewId ? `${viewId}/custom_view` : ''; - debounceChangeHistory.current(`/receipts/${toPath}`); - setTopbarEditView(viewId); - }; const tabs = receiptview.map((view) => ({ ...pick(view, ['name', 'id']), })); + const handleTabsChange = (viewId) => { + changeReceiptView(viewId || -1); + addReceiptsTableQueries({ + custom_view_id: viewId || null, + }); + setTopbarEditView(viewId); + }; + // Handle click a new view tab. const handleClickNewView = () => { setTopbarEditView(null); history.push('/custom_views/receipts/new'); }; - console.log(receiptview, 'receiptview'); - return ( diff --git a/client/src/containers/Sales/Receipt/withReceipts.js b/client/src/containers/Sales/Receipt/withReceipts.js index e96128ddd..93ca707b8 100644 --- a/client/src/containers/Sales/Receipt/withReceipts.js +++ b/client/src/containers/Sales/Receipt/withReceipts.js @@ -18,7 +18,7 @@ export default (mapState) => { const mapped = { receiptsCurrentPage: getReceiptsItems(state, props, tableQuery), - receiptview: getResourceViews(state, props, 'sales_receipts'), + receiptview: getResourceViews(state, props, 'sale_receipt'), receiptItems: state.salesReceipts.items, receiptTableQuery: tableQuery, receiptsPagination: getReceiptPaginationMeta(state, props, tableQuery), diff --git a/client/src/store/receipt/receipt.actions.js b/client/src/store/receipt/receipt.actions.js index 03e101c42..ea8d00a23 100644 --- a/client/src/store/receipt/receipt.actions.js +++ b/client/src/store/receipt/receipt.actions.js @@ -87,7 +87,8 @@ export const fetchReceiptsTable = ({ query = {} }) => { payload: { sales_receipts: response.data.sale_receipts, pagination: response.data.pagination, - customViewId: response.data.customViewId || -1, + customViewId: + response.data?.filter_meta?.view?.custom_view_id || -1, }, }); dispatch({ @@ -100,7 +101,8 @@ export const fetchReceiptsTable = ({ query = {} }) => { type: t.RECEIPTS_PAGINATION_SET, payload: { pagination: response.data.pagination, - customViewId: response.data.customViewId || -1, + customViewId: + response.data?.filter_meta?.view?.custom_view_id || -1, }, }); dispatch({ @@ -119,4 +121,4 @@ export const fetchReceiptsTable = ({ query = {} }) => { export const closeReceipt = ({ id }) => { return (dispatch) => ApiService.post(`sales/receipts/${id}/close`); -}; \ No newline at end of file +};