Skip to content

Commit

Permalink
CM-489: improve payroll task approve display (#21)
Browse files Browse the repository at this point in the history
* CM-495: improve payroll task approve display

* CM-489: added adjustments in payroll accept/reject

---------

Co-authored-by: Jan <[email protected]>
  • Loading branch information
sniedzielski and Jan authored Feb 5, 2024
1 parent 845daec commit f8c81ea
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 41 deletions.
17 changes: 4 additions & 13 deletions src/components/tasks/PayrollTasks.js
Original file line number Diff line number Diff line change
@@ -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 = () => [
<FormattedMessage module="payroll" id="payroll.name" />,
<FormattedMessage module="payroll" id="payroll.benefitPlan" />,
<FormattedMessage module="payroll" id="payroll.status" />,
<FormattedMessage module="payroll" id="payroll.dateValidFrom" />,
<FormattedMessage module="payroll" id="payroll.dateValidTo" />,
<FormattedMessage module="payroll" id="payroll.paymentMethod" />,
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) => <PayrollPage taskPayrollUuid={payroll?.id} />,
];

export { PayrollTaskTableHeaders, PayrollTaskItemFormatters };
18 changes: 2 additions & 16 deletions src/pages/payroll/PayrollBillSearcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function PayrollBillSearcher({
bills,
billsPageInfo,
billsTotalCount,
payrollUuid,
}) {
const history = useHistory();
const modulesManager = useModulesManager();
Expand All @@ -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 = [
Expand Down
10 changes: 1 addition & 9 deletions src/pages/payroll/PayrollBillTabPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<PublishedComponent
pubRef="policyHolder.TabPanel"
Expand All @@ -36,7 +28,7 @@ function PayrollBillsTabPanel({ value, rights, payrollUuid }) {
value={value}
>
{
rights.includes(RIGHT_BILL_SEARCH) && uuidPayroll && (
rights.includes(RIGHT_BILL_SEARCH) && payrollUuid && (
<PayrollBillSearcher rights={rights} payrollUuid={payrollUuid} />
)
}
Expand Down
13 changes: 10 additions & 3 deletions src/pages/payroll/PayrollPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ const useStyles = makeStyles((theme) => ({
}));

function PayrollPage({
payrollUuid,
statePayrollUuid,
taskPayrollUuid,
rights,
confirmed,
submittingMutation,
Expand All @@ -54,20 +55,25 @@ 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}"`]);
}
}, [payrollUuid]);

useEffect(() => {
if (confirmed) confirmedAction();
if (confirmed && typeof confirmed === 'function') confirmedAction();
return () => confirmed && clearConfirm(null);
}, [confirmed]);

Expand Down Expand Up @@ -149,6 +155,7 @@ function PayrollPage({
actions={actions}
setConfirmedAction={setConfirmedAction}
saveTooltip={formatMessage('tooltip.save')}
payrollUuid={payrollUuid}
/>
</div>
)
Expand All @@ -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,
Expand Down

0 comments on commit f8c81ea

Please sign in to comment.