-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CM-930: added frontend improvements in terms of performance, digital …
…payment support (#52)
- Loading branch information
1 parent
28b09e6
commit 3deee25
Showing
11 changed files
with
471 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
import React, { useRef, useEffect } from 'react'; | ||
import { connect, useSelector } from 'react-redux'; | ||
import { bindActionCreators } from 'redux'; | ||
|
||
import { | ||
Searcher, | ||
useHistory, | ||
useModulesManager, | ||
useTranslations, | ||
coreConfirm, | ||
clearConfirm, | ||
journalize, | ||
} from '@openimis/fe-core'; | ||
import PayrollFilter from './PayrollFilter'; | ||
import { | ||
DEFAULT_PAGE_SIZE, MODULE_NAME, PAYROLL_PAYROLL_ROUTE, RIGHT_PAYROLL_SEARCH, ROWS_PER_PAGE_OPTIONS, PAYROLL_STATUS, | ||
} from '../../constants'; | ||
import { fetchPayrolls } from '../../actions'; | ||
import PayrollReconciliationFilesDialog from './dialogs/PayrollReconciliationFilesDialog'; | ||
import PayrollPendingPayrollSummary from './dialogs/PayrollPendingPayrollSummary'; | ||
|
||
function PayrollSearcherPending({ | ||
fetchingPayrolls, | ||
fetchedPayrolls, | ||
errorPayrolls, | ||
payrolls, | ||
pageInfo, | ||
totalCount, | ||
fetchPayrolls, | ||
submittingMutation, | ||
mutation, | ||
classes, | ||
}) { | ||
const history = useHistory(); | ||
const modulesManager = useModulesManager(); | ||
const { formatMessageWithValues } = useTranslations(MODULE_NAME, modulesManager); | ||
const rights = useSelector((store) => store.core.user.i_user.rights ?? []); | ||
|
||
const prevSubmittingMutationRef = useRef(); | ||
|
||
useEffect(() => { | ||
if (prevSubmittingMutationRef.current && !submittingMutation) { | ||
journalize(mutation); | ||
} | ||
}, [submittingMutation]); | ||
|
||
useEffect(() => { | ||
prevSubmittingMutationRef.current = submittingMutation; | ||
}); | ||
|
||
const headers = () => [ | ||
'payroll.name', | ||
'payroll.paymentPlan', | ||
'payroll.paymentPoint', | ||
'payroll.status', | ||
'payroll.paymentMethod', | ||
'emptyLabel', | ||
]; | ||
|
||
const sorts = () => [ | ||
['name', true], | ||
['paymentPlan', true], | ||
['paymentPoint', true], | ||
['status', true], | ||
['paymentMethod', true], | ||
]; | ||
|
||
const defaultFilters = () => ({ | ||
isDeleted: { | ||
value: false, | ||
filter: 'isDeleted: false', | ||
}, | ||
status: { | ||
value: PAYROLL_STATUS.PENDING_APPROVAL, | ||
filter: `status: ${PAYROLL_STATUS.PENDING_APPROVAL}`, | ||
}, | ||
}); | ||
|
||
const fetch = (params) => fetchPayrolls(modulesManager, params); | ||
|
||
const rowIdentifier = (payroll) => payroll.id; | ||
|
||
const openPayroll = (payroll) => rights.includes(RIGHT_PAYROLL_SEARCH) && history.push( | ||
`/${modulesManager.getRef(PAYROLL_PAYROLL_ROUTE)}/${payroll?.id}`, | ||
); | ||
|
||
const itemFormatters = () => [ | ||
(payroll) => payroll.name, | ||
(payroll) => (payroll.benefitPlan | ||
? `${payroll.benefitPlan.code} ${payroll.benefitPlan.name}` : ''), | ||
(payroll) => (payroll.paymentPoint | ||
? `${payroll.paymentPoint.name}` : ''), | ||
(payroll) => (payroll.status | ||
? `${payroll.status}` : ''), | ||
(payroll) => (payroll.paymentMethod | ||
? `${payroll.paymentMethod}` : ''), | ||
(payroll) => ( | ||
<PayrollReconciliationFilesDialog | ||
classes={classes} | ||
payroll={payroll} | ||
/> | ||
), | ||
(payroll) => ( | ||
<PayrollPendingPayrollSummary | ||
classes={classes} | ||
payrollDetail={payroll} | ||
/> | ||
), | ||
]; | ||
|
||
const onDoubleClick = (payroll) => openPayroll(payroll); | ||
|
||
const payrollFilter = ({ filters, onChangeFilters }) => ( | ||
<PayrollFilter filters={filters} onChangeFilters={onChangeFilters} statusReadOnly /> | ||
); | ||
|
||
return ( | ||
<Searcher | ||
module="payroll" | ||
FilterPane={payrollFilter} | ||
fetch={fetch} | ||
items={payrolls} | ||
itemsPageInfo={pageInfo} | ||
fetchedItems={fetchedPayrolls} | ||
fetchingItems={fetchingPayrolls} | ||
errorItems={errorPayrolls} | ||
tableTitle={formatMessageWithValues('payrollSearcher.results', { totalCount })} | ||
headers={headers} | ||
itemFormatters={itemFormatters} | ||
sorts={sorts} | ||
rowsPerPageOptions={ROWS_PER_PAGE_OPTIONS} | ||
defaultPageSize={DEFAULT_PAGE_SIZE} | ||
rowIdentifier={rowIdentifier} | ||
onDoubleClick={onDoubleClick} | ||
defaultFilters={defaultFilters()} | ||
/> | ||
); | ||
} | ||
|
||
const mapStateToProps = (state) => ({ | ||
fetchingPayrolls: state.payroll.fetchingPayrolls, | ||
fetchedPayrolls: state.payroll.fetchedPayrolls, | ||
errorPayrolls: state.payroll.errorPayrolls, | ||
payrolls: state.payroll.payrolls, | ||
pageInfo: state.payroll.payrollsPageInfo, | ||
totalCount: state.payroll.payrollsTotalCount, | ||
confirmed: state.core.confirmed, | ||
submittingMutation: state.payroll.submittingMutation, | ||
mutation: state.payroll.mutation, | ||
}); | ||
|
||
const mapDispatchToProps = (dispatch) => bindActionCreators({ | ||
fetchPayrolls, | ||
journalize, | ||
clearConfirm, | ||
coreConfirm, | ||
}, dispatch); | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(PayrollSearcherPending); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.