From 90fd28208a2d2b8f2fcaa8ae614a797e4d595999 Mon Sep 17 00:00:00 2001 From: olewandowski1 Date: Thu, 7 Mar 2024 11:53:53 +0100 Subject: [PATCH] OM-134: clear and format bill searcher, add bill route to the moldova menu --- src/components/BillSearcher.js | 170 +++++++++++++-------------- src/menus/LegalAndFinanceMainMenu.js | 16 ++- 2 files changed, 95 insertions(+), 91 deletions(-) diff --git a/src/components/BillSearcher.js b/src/components/BillSearcher.js index 3adb06f..b011cab 100644 --- a/src/components/BillSearcher.js +++ b/src/components/BillSearcher.js @@ -1,5 +1,12 @@ import React, { useState, useCallback, useEffect, useRef } from "react"; +import { bindActionCreators } from "redux"; +import { connect } from "react-redux"; import { injectIntl } from "react-intl"; + +import { IconButton, Tooltip, Button, Dialog, DialogActions, DialogTitle } from "@material-ui/core"; +import EditIcon from "@material-ui/icons/Edit"; +import DeleteIcon from "@material-ui/icons/Delete"; + import { withModulesManager, formatMessage, @@ -10,10 +17,8 @@ import { journalize, withHistory, historyPush, - downloadExport + downloadExport, } from "@openimis/fe-core"; -import { bindActionCreators } from "redux"; -import { connect } from "react-redux"; import { fetchBills, deleteBill, fetchBillsExport } from "../actions"; import { DEFAULT_PAGE_SIZE, @@ -26,12 +31,6 @@ import { import BillFilter from "./BillFilter"; import InvoiceStatusPicker from "../pickers/InvoiceStatusPicker"; import { getSubjectAndThirdpartyTypePicker } from "../util/subject-and-thirdparty-picker"; -import { IconButton, Tooltip, Button, - Dialog, - DialogActions, - DialogTitle,} from "@material-ui/core"; -import EditIcon from "@material-ui/icons/Edit"; -import DeleteIcon from "@material-ui/icons/Delete"; const BillSearcher = ({ intl, @@ -53,15 +52,13 @@ const BillSearcher = ({ billsPageInfo, billsTotalCount, billsExport, - billsExportPageInfo, - billsExportTotalCount, errorBillsExport, actions, - actionsContributionKey + actionsContributionKey, }) => { const [billToDelete, setBillToDelete] = useState(null); const [deletedBillUuids, setDeletedBillUuids] = useState([]); - const [failedExport, setFailedExport] = useState(false) + const [failedExport, setFailedExport] = useState(false); const prevSubmittingMutationRef = useRef(); useEffect(() => billToDelete && openConfirmDialog(), [billToDelete]); @@ -75,14 +72,14 @@ const BillSearcher = ({ }, [confirmed]); useEffect(() => { - setFailedExport(true) - }, [errorBillsExport]) + setFailedExport(true); + }, [errorBillsExport]); useEffect(() => { if (billsExport) { - downloadExport(billsExport, 'bill_export.csv')(); + downloadExport(billsExport, "bill_export.csv")(); } - }, [billsExport]) + }, [billsExport]); useEffect(() => { prevSubmittingMutationRef.current && !submittingMutation && journalize(mutation); @@ -112,7 +109,7 @@ const BillSearcher = ({ formatMessage(intl, "bill", "delete.confirm.message"), ), [billToDelete], - ); + ); const fetch = (params) => fetchBills(params); @@ -136,8 +133,7 @@ const BillSearcher = ({ (bill) => getSubjectAndThirdpartyTypePicker(modulesManager, bill.subjectTypeName, bill.subject), (bill) => getSubjectAndThirdpartyTypePicker(modulesManager, bill.thirdpartyTypeName, bill.thirdparty), (bill) => bill.code, - (bill) => - !!bill.dateBill ? formatDateFromISO(modulesManager, intl, bill.dateBill) : EMPTY_STRING, + (bill) => (!!bill.dateBill ? formatDateFromISO(modulesManager, intl, bill.dateBill) : EMPTY_STRING), (bill) => bill.amountTotal, (bill) => , ]; @@ -198,74 +194,73 @@ const BillSearcher = ({ }, }); - const exportFields = () => ({ - 'id': 'ID', - 'userCreated.username': "User", - 'amount_total': "AmountTotal", - "subjectTypeName": "Subject", - 'thirdpartyTypeName': "SenderType", - 'thirdparty': "" - }) - return (
- + - {failedExport && ( - - {errorBillsExport} - - - - - )} + {failedExport && ( + + {errorBillsExport} + + + + + )}
); }; @@ -280,7 +275,6 @@ const mapStateToProps = (state) => ({ confirmed: state.core.confirmed, submittingMutation: state.invoice.submittingMutation, mutation: state.invoice.mutation, - fetchingBillsExport: state.invoice.fetchingBillsExport, fetchedBillsExport: state.invoice.fetchedBillsExport, billsExport: state.invoice.billsExport, @@ -302,6 +296,4 @@ const mapDispatchToProps = (dispatch) => { ); }; -export default withHistory( - withModulesManager(injectIntl(connect(mapStateToProps, mapDispatchToProps)(BillSearcher))), -); +export default withHistory(withModulesManager(injectIntl(connect(mapStateToProps, mapDispatchToProps)(BillSearcher)))); diff --git a/src/menus/LegalAndFinanceMainMenu.js b/src/menus/LegalAndFinanceMainMenu.js index c4adc21..9ed6743 100644 --- a/src/menus/LegalAndFinanceMainMenu.js +++ b/src/menus/LegalAndFinanceMainMenu.js @@ -22,10 +22,22 @@ const LegalAndFinanceMainMenu = (props) => { const { modulesManager, rights, intl } = props; const isWorker = modulesManager.getConf("fe-core", "isWorker", false); - if (isWorker) return null; - const entries = []; + if (isWorker) { + if (rights.includes(RIGHT_BILL_SEARCH || RIGHT_BILL_AMEND)) { + entries.push({ + text: formatMessage(intl, "invoice", "menu.bills"), + icon: , + route: "/bills", + }); + } + + if (!entries.length) return null; + + return ; + } + if (rights.filter((r) => r >= RIGHT_INVOICE_SEARCH && r <= RIGHT_INVOICE_AMEND).length) { // RIGHT_SEARCH is shared by HF & HQ staff) entries.push({