From f8c81eab5aed290798ccd30302da35ef21a9b8df Mon Sep 17 00:00:00 2001 From: sniedzielski <52816247+sniedzielski@users.noreply.github.com> Date: Mon, 5 Feb 2024 16:33:32 +0100 Subject: [PATCH] CM-489: improve payroll task approve display (#21) * CM-495: improve payroll task approve display * CM-489: added adjustments in payroll accept/reject --------- Co-authored-by: Jan --- src/components/tasks/PayrollTasks.js | 17 ++++------------- src/pages/payroll/PayrollBillSearcher.js | 18 ++---------------- src/pages/payroll/PayrollBillTabPanel.js | 10 +--------- src/pages/payroll/PayrollPage.js | 13 ++++++++++--- 4 files changed, 17 insertions(+), 41 deletions(-) diff --git a/src/components/tasks/PayrollTasks.js b/src/components/tasks/PayrollTasks.js index 3801a8e..6b0388c 100644 --- a/src/components/tasks/PayrollTasks.js +++ b/src/components/tasks/PayrollTasks.js @@ -1,22 +1,13 @@ import React from 'react'; -import { FormattedMessage } from '@openimis/fe-core'; +import PayrollPage from '../../pages/payroll/PayrollPage'; +import { EMPTY_STRING } from '../../constants'; const PayrollTaskTableHeaders = () => [ - , - , - , - , - , - , + EMPTY_STRING, ]; const PayrollTaskItemFormatters = () => [ - (payroll) => payroll?.name, - (payroll) => payroll?.benefitPlan, - (payroll) => payroll?.status, - (payroll) => payroll?.date_valid_from, - (payroll) => payroll?.date_valid_to, - (payroll) => payroll?.paymentMethod, + (payroll) => , ]; export { PayrollTaskTableHeaders, PayrollTaskItemFormatters }; diff --git a/src/pages/payroll/PayrollBillSearcher.js b/src/pages/payroll/PayrollBillSearcher.js index 37451d3..cd13d24 100644 --- a/src/pages/payroll/PayrollBillSearcher.js +++ b/src/pages/payroll/PayrollBillSearcher.js @@ -33,6 +33,7 @@ function PayrollBillSearcher({ bills, billsPageInfo, billsTotalCount, + payrollUuid, }) { const history = useHistory(); const modulesManager = useModulesManager(); @@ -43,22 +44,7 @@ function PayrollBillSearcher({ ); const onDoubleClick = (bill) => openBill(bill); - - const [payrollUuid] = useState(''); - - const fetch = (params) => { - const currentPath = window.location.pathname; - const pathSegments = currentPath.split('/'); - const payrollIndex = pathSegments.indexOf('payroll'); - if (payrollIndex !== -1 && payrollIndex < pathSegments.length - 1) { - const uuid = pathSegments[payrollIndex + 1]; - const index = params.findIndex((element) => element.startsWith('payrollUuid:')); - if (index !== -1) { - params[index] = `payrollUuid: "${uuid}"`; - } - fetchPayrollBills(modulesManager, params); - } - }; + const fetch = (params) => fetchPayrollBills(modulesManager, params); const headers = () => { const headers = [ diff --git a/src/pages/payroll/PayrollBillTabPanel.js b/src/pages/payroll/PayrollBillTabPanel.js index b0b271e..469da84 100644 --- a/src/pages/payroll/PayrollBillTabPanel.js +++ b/src/pages/payroll/PayrollBillTabPanel.js @@ -20,14 +20,6 @@ function PayrollBillsTabLabel({ } function PayrollBillsTabPanel({ value, rights, payrollUuid }) { - let uuidPayroll = null; - const currentPath = window.location.pathname; - const pathSegments = currentPath.split('/'); - const payrollIndex = pathSegments.indexOf('payroll'); - if (payrollIndex !== -1 && payrollIndex < pathSegments.length - 1) { - const uuid = pathSegments[payrollIndex + 1]; - uuidPayroll = uuid; - } return ( { - rights.includes(RIGHT_BILL_SEARCH) && uuidPayroll && ( + rights.includes(RIGHT_BILL_SEARCH) && payrollUuid && ( ) } diff --git a/src/pages/payroll/PayrollPage.js b/src/pages/payroll/PayrollPage.js index 2fb8019..92d08cf 100644 --- a/src/pages/payroll/PayrollPage.js +++ b/src/pages/payroll/PayrollPage.js @@ -34,7 +34,8 @@ const useStyles = makeStyles((theme) => ({ })); function PayrollPage({ - payrollUuid, + statePayrollUuid, + taskPayrollUuid, rights, confirmed, submittingMutation, @@ -54,12 +55,17 @@ function PayrollPage({ const { formatMessage, formatMessageWithValues } = useTranslations(MODULE_NAME, modulesManager); const [editedPayroll, setEditedPayroll] = useState({}); + const [payrollUuid, setPayrollUuid] = useState(null); const [confirmedAction, setConfirmedAction] = useState(() => null); const prevSubmittingMutationRef = useRef(); const readOnly = Boolean(payroll?.id); const back = () => history.goBack(); + useEffect(() => { + setPayrollUuid(statePayrollUuid ?? taskPayrollUuid); + }, [taskPayrollUuid, statePayrollUuid]); + useEffect(() => { if (payrollUuid) { fetchPayroll(modulesManager, [`id: "${payrollUuid}"`]); @@ -67,7 +73,7 @@ function PayrollPage({ }, [payrollUuid]); useEffect(() => { - if (confirmed) confirmedAction(); + if (confirmed && typeof confirmed === 'function') confirmedAction(); return () => confirmed && clearConfirm(null); }, [confirmed]); @@ -149,6 +155,7 @@ function PayrollPage({ actions={actions} setConfirmedAction={setConfirmedAction} saveTooltip={formatMessage('tooltip.save')} + payrollUuid={payrollUuid} /> ) @@ -166,7 +173,7 @@ const mapDispatchToProps = (dispatch) => bindActionCreators({ }, dispatch); const mapStateToProps = (state, props) => ({ - payrollUuid: props.match.params.payroll_uuid, + statePayrollUuid: props?.match?.params.payroll_uuid, rights: state.core?.user?.i_user?.rights ?? [], confirmed: state.core.confirmed, submittingMutation: state.payroll.submittingMutation,