@stssocialst-stp/fe-payroll 0.3.5 → 0.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
2
- import React, { useState, useRef, useEffect, forwardRef } from 'react';
2
+ import React, { useState, useRef, useEffect, forwardRef, useCallback } from 'react';
3
3
  import { PinDrop } from '@material-ui/icons';
4
4
  import MonetizationOnIcon from '@material-ui/icons/MonetizationOn';
5
5
  import { dispatchMutationResp, dispatchMutationErr, dispatchMutationReq, formatServerError, formatGraphQLError, parseData, pageInfo, decodeId, formatPageQueryWithCount, graphql, formatQuery, formatGQLString, formatMutation, withModulesManager, PublishedComponent, TextInput, FormPanel, useModulesManager, useHistory, useTranslations, journalize, Form, coreConfirm, clearConfirm, ControlledField, Searcher, Helmet, withTooltip, CustomFilterFieldStatusPicker, CustomFilterTypeStatusPicker, NumberInput, SelectInput, formatMessage as formatMessage$1, fetchCustomFilter, ConstantBasedPicker, FormattedMessage, apiHeaders, baseApiUrl, createFieldsBasedOnJSON, renderInputComponent, Contributions, useGraphqlQuery, Autocomplete } from '@stssocialst-stp/fe-core';
6
6
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
7
7
  import { bindActionCreators } from 'redux';
8
- import { connect, useSelector } from 'react-redux';
8
+ import { connect, useSelector, useDispatch } from 'react-redux';
9
9
  import { makeStyles } from '@material-ui/styles';
10
10
  import DeleteIcon from '@material-ui/icons/Delete';
11
11
  import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
@@ -15,7 +15,7 @@ import _possibleConstructorReturn from '@babel/runtime/helpers/possibleConstruct
15
15
  import _getPrototypeOf from '@babel/runtime/helpers/getPrototypeOf';
16
16
  import _inherits from '@babel/runtime/helpers/inherits';
17
17
  import { injectIntl } from 'react-intl';
18
- import { Grid, FormControlLabel, Checkbox, Tooltip, IconButton, Fab, Divider, Typography, Input, Modal, Backdrop, Fade, Box, Button as Button$1, Paper, TextField, Tab, LinearProgress as LinearProgress$1 } from '@material-ui/core';
18
+ import { Grid, FormControlLabel, Checkbox, Tooltip, IconButton, Fab, Divider, Typography, Input, Modal, Backdrop, Fade, Box, Button as Button$1, Paper, LinearProgress, TextField, Tab } from '@material-ui/core';
19
19
  import { withTheme, withStyles } from '@material-ui/core/styles';
20
20
  import AddIcon from '@material-ui/icons/Add';
21
21
  import VisibilityIcon from '@material-ui/icons/Visibility';
@@ -34,7 +34,7 @@ import { useReactToPrint } from 'react-to-print';
34
34
  import PrintIcon from '@material-ui/icons/Print';
35
35
  import DialogContentText from '@material-ui/core/DialogContentText';
36
36
  import PhotoCameraOutlinedIcon from '@material-ui/icons/PhotoCameraOutlined';
37
- import LinearProgress from '@material-ui/core/LinearProgress';
37
+ import LinearProgress$1 from '@material-ui/core/LinearProgress';
38
38
  import DownloadIcon from '@material-ui/icons/CloudDownload';
39
39
  import Chip from '@material-ui/core/Chip';
40
40
  import Paper$1 from '@material-ui/core/Paper';
@@ -718,7 +718,12 @@ var messages_en = {
718
718
  "payroll.bistp.status.pending": "Sent to Bank",
719
719
  "payroll.bistp.status.skippedNib": "No NIB",
720
720
  "payroll.bistp.status.sendFailed": "Send Failed",
721
+ "payroll.bistp.status.enviados": "Sent to BISTP",
721
722
  "payroll.bistp.progress": "BISTP Progress",
723
+ "payroll.async.generating": "Generating beneficiaries in background...",
724
+ "payroll.async.createdSoFar": "{benefitCount} created so far",
725
+ "payroll.async.note": "This process may take a few minutes. You can close this page - the process continues in the background.",
726
+ "payroll.async.timedOut": "The background generation process took too long. Please refresh this page to check the current status.",
722
727
  "payroll.route.beneficiariesManagement": "Beneficiary Management",
723
728
  "payroll.beneficiaries.management.title": "Beneficiary Management",
724
729
  "payroll.beneficiaries.management.noPermission": "You do not have permission to manage beneficiaries.",
@@ -3167,6 +3172,99 @@ var mapDispatchToProps$b = function mapDispatchToProps(dispatch) {
3167
3172
  };
3168
3173
  var PaymentApproveForPaymentSummary = connect(mapStateToProps$b, mapDispatchToProps$b)(PaymentApproveForPaymentDialog);
3169
3174
 
3175
+ var POLL_INTERVAL_MS = 5000;
3176
+ var TIMEOUT_MS = 600000;
3177
+ var COUNT_QUERY = function COUNT_QUERY(payrollUuid) {
3178
+ return "\n {\n benefitConsumptionByPayroll(payrollUuid: \"".concat(payrollUuid, "\", first: 0, isDeleted: false) {\n totalCount\n }\n }\n");
3179
+ };
3180
+ function useAsyncPayrollProgress(_ref) {
3181
+ var payrollUuid = _ref.payrollUuid,
3182
+ payrollStatus = _ref.payrollStatus;
3183
+ var dispatch = useDispatch();
3184
+ var _useState = useState(0),
3185
+ _useState2 = _slicedToArray(_useState, 2),
3186
+ benefitCount = _useState2[0],
3187
+ setBenefitCount = _useState2[1];
3188
+ var _useState3 = useState(false),
3189
+ _useState4 = _slicedToArray(_useState3, 2),
3190
+ isGenerating = _useState4[0],
3191
+ setIsGenerating = _useState4[1];
3192
+ var _useState5 = useState(false),
3193
+ _useState6 = _slicedToArray(_useState5, 2),
3194
+ timedOut = _useState6[0],
3195
+ setTimedOut = _useState6[1];
3196
+ var pollRef = useRef(null);
3197
+ var startTimeRef = useRef(null);
3198
+ var prevCountRef = useRef(0);
3199
+ var stableCountRounds = useRef(0);
3200
+ var stopPolling = useCallback(function () {
3201
+ if (pollRef.current) {
3202
+ clearInterval(pollRef.current);
3203
+ pollRef.current = null;
3204
+ }
3205
+ }, []);
3206
+ var fetchCount = useCallback(function () {
3207
+ if (!payrollUuid) return;
3208
+ dispatch(graphql(COUNT_QUERY(payrollUuid), 'POLL_BENEFIT_COUNT')).then(function (response) {
3209
+ var _response$payload$dat, _response$payload;
3210
+ var count = (_response$payload$dat = response === null || response === void 0 || (_response$payload = response.payload) === null || _response$payload === void 0 || (_response$payload = _response$payload.data) === null || _response$payload === void 0 || (_response$payload = _response$payload.benefitConsumptionByPayroll) === null || _response$payload === void 0 ? void 0 : _response$payload.totalCount) !== null && _response$payload$dat !== void 0 ? _response$payload$dat : 0;
3211
+ if (count === 0) {
3212
+ setBenefitCount(count);
3213
+ setIsGenerating(true);
3214
+ stableCountRounds.current = 0;
3215
+ prevCountRef.current = count;
3216
+ return;
3217
+ }
3218
+ setBenefitCount(count);
3219
+ if (count === prevCountRef.current) {
3220
+ stableCountRounds.current += 1;
3221
+ } else {
3222
+ stableCountRounds.current = 0;
3223
+ }
3224
+ prevCountRef.current = count;
3225
+ if (stableCountRounds.current >= 2) {
3226
+ setIsGenerating(false);
3227
+ stopPolling();
3228
+ }
3229
+ })["catch"](function () {
3230
+ setBenefitCount(function (c) {
3231
+ return Math.max(c, 0);
3232
+ });
3233
+ });
3234
+ }, [payrollUuid, dispatch, stopPolling]);
3235
+ useEffect(function () {
3236
+ var shouldPoll = payrollUuid && payrollStatus === 'PENDING_APPROVAL';
3237
+ if (shouldPoll && !pollRef.current) {
3238
+ setTimedOut(false);
3239
+ startTimeRef.current = Date.now();
3240
+ stableCountRounds.current = 0;
3241
+ prevCountRef.current = 0;
3242
+ fetchCount();
3243
+ pollRef.current = setInterval(function () {
3244
+ if (Date.now() - startTimeRef.current >= TIMEOUT_MS) {
3245
+ setIsGenerating(false);
3246
+ setTimedOut(true);
3247
+ stopPolling();
3248
+ return;
3249
+ }
3250
+ fetchCount();
3251
+ }, POLL_INTERVAL_MS);
3252
+ }
3253
+ if (!shouldPoll && pollRef.current) {
3254
+ setIsGenerating(false);
3255
+ stopPolling();
3256
+ }
3257
+ return function () {
3258
+ return stopPolling();
3259
+ };
3260
+ }, [payrollUuid, payrollStatus, fetchCount, stopPolling]);
3261
+ return {
3262
+ isGenerating: isGenerating,
3263
+ benefitCount: benefitCount,
3264
+ timedOut: timedOut
3265
+ };
3266
+ }
3267
+
3170
3268
  var useStyles$b = makeStyles(function (theme) {
3171
3269
  return {
3172
3270
  paper: theme.paper.paper,
@@ -3213,12 +3311,64 @@ function PayrollTab(_ref) {
3213
3311
  var modulesManager = useModulesManager();
3214
3312
  var _useTranslations = useTranslations(MODULE_NAME, modulesManager),
3215
3313
  formatMessage = _useTranslations.formatMessage;
3314
+ var _useAsyncPayrollProgr = useAsyncPayrollProgress({
3315
+ payrollUuid: payrollUuid,
3316
+ payrollStatus: payroll === null || payroll === void 0 ? void 0 : payroll.status
3317
+ }),
3318
+ isGenerating = _useAsyncPayrollProgr.isGenerating,
3319
+ benefitCount = _useAsyncPayrollProgr.benefitCount,
3320
+ timedOut = _useAsyncPayrollProgr.timedOut;
3321
+ var _useState3 = useState(false),
3322
+ _useState4 = _slicedToArray(_useState3, 2),
3323
+ generationComplete = _useState4[0],
3324
+ setGenerationComplete = _useState4[1];
3325
+ var _useState5 = useState(0),
3326
+ _useState6 = _slicedToArray(_useState5, 2),
3327
+ refreshBenefitsKey = _useState6[0],
3328
+ setRefreshBenefitsKey = _useState6[1];
3329
+ useEffect(function () {
3330
+ if (!isGenerating && benefitCount > 0 && !generationComplete) {
3331
+ setGenerationComplete(true);
3332
+ setRefreshBenefitsKey(function (k) {
3333
+ return k + 1;
3334
+ });
3335
+ }
3336
+ }, [isGenerating, benefitCount, generationComplete]);
3216
3337
  var downloadPayrollData = function downloadPayrollData(payrollUuid, payrollName) {
3217
3338
  downloadPayroll(payrollUuid, payrollName);
3218
3339
  };
3219
3340
  return /*#__PURE__*/React.createElement(Paper, {
3220
3341
  className: classes.paper
3342
+ }, (isGenerating || timedOut) && payrollUuid && !isPayrollFromFailedInvoices && /*#__PURE__*/React.createElement(Grid, {
3343
+ container: true,
3344
+ spacing: 2,
3345
+ style: {
3346
+ padding: '16px'
3347
+ }
3221
3348
  }, /*#__PURE__*/React.createElement(Grid, {
3349
+ item: true,
3350
+ xs: 12
3351
+ }, /*#__PURE__*/React.createElement(Typography, {
3352
+ variant: "body1"
3353
+ }, timedOut ? formatMessage('payroll.async.timedOut') : formatMessage('payroll.async.generating')), !timedOut && /*#__PURE__*/React.createElement(LinearProgress, {
3354
+ variant: "indeterminate",
3355
+ style: {
3356
+ marginTop: '8px'
3357
+ }
3358
+ }), /*#__PURE__*/React.createElement(Typography, {
3359
+ variant: "caption",
3360
+ style: {
3361
+ display: 'block',
3362
+ marginTop: '4px'
3363
+ }
3364
+ }, !timedOut && formatMessage('payroll.async.createdSoFar', {
3365
+ benefitCount: benefitCount
3366
+ })), /*#__PURE__*/React.createElement(Typography, {
3367
+ variant: "caption",
3368
+ style: {
3369
+ display: 'block'
3370
+ }
3371
+ }, !timedOut && formatMessage('payroll.async.note')))), /*#__PURE__*/React.createElement(Grid, {
3222
3372
  container: true,
3223
3373
  className: "".concat(classes.tableTitle, " ").concat(classes.tabs)
3224
3374
  }, /*#__PURE__*/React.createElement("div", {
@@ -3269,7 +3419,8 @@ function PayrollTab(_ref) {
3269
3419
  payrollUuid: payrollUuid,
3270
3420
  isInTask: isInTask,
3271
3421
  isPayrollFromFailedInvoices: isPayrollFromFailedInvoices,
3272
- payroll: payroll
3422
+ payroll: payroll,
3423
+ refreshBenefitsKey: refreshBenefitsKey
3273
3424
  }));
3274
3425
  }
3275
3426
 
@@ -3686,7 +3837,7 @@ function PayrollSearcher(_ref) {
3686
3837
  gap: 8,
3687
3838
  minWidth: 120
3688
3839
  }
3689
- }, /*#__PURE__*/React.createElement(LinearProgress, {
3840
+ }, /*#__PURE__*/React.createElement(LinearProgress$1, {
3690
3841
  variant: "determinate",
3691
3842
  value: progress,
3692
3843
  style: {
@@ -4056,7 +4207,7 @@ function PayrollSearcherApproved(_ref) {
4056
4207
  gap: 8,
4057
4208
  minWidth: 120
4058
4209
  }
4059
- }, /*#__PURE__*/React.createElement(LinearProgress, {
4210
+ }, /*#__PURE__*/React.createElement(LinearProgress$1, {
4060
4211
  variant: "determinate",
4061
4212
  value: progress,
4062
4213
  style: {
@@ -4465,7 +4616,7 @@ function PayrollSearcherReconciled(_ref) {
4465
4616
  gap: 8,
4466
4617
  minWidth: 120
4467
4618
  }
4468
- }, /*#__PURE__*/React.createElement(LinearProgress, {
4619
+ }, /*#__PURE__*/React.createElement(LinearProgress$1, {
4469
4620
  variant: "determinate",
4470
4621
  value: progress,
4471
4622
  style: {
@@ -5662,13 +5813,15 @@ function BenefitConsumptionsTabPanel(_ref2) {
5662
5813
  var value = _ref2.value,
5663
5814
  rights = _ref2.rights,
5664
5815
  payrollUuid = _ref2.payrollUuid,
5665
- isPayrollFromFailedInvoices = _ref2.isPayrollFromFailedInvoices;
5816
+ isPayrollFromFailedInvoices = _ref2.isPayrollFromFailedInvoices,
5817
+ refreshBenefitsKey = _ref2.refreshBenefitsKey;
5666
5818
  return /*#__PURE__*/React.createElement(PublishedComponent, {
5667
5819
  pubRef: "policyHolder.TabPanel",
5668
5820
  module: "payroll",
5669
5821
  index: BENEFIT_CONSUMPTION_LIST_TAB_VALUE,
5670
5822
  value: value
5671
5823
  }, rights.includes(RIGHT_PAYROLL_SEARCH) && payrollUuid && /*#__PURE__*/React.createElement(BenefitConsumptionSearcher$1, {
5824
+ key: refreshBenefitsKey,
5672
5825
  rights: rights,
5673
5826
  payrollUuid: payrollUuid,
5674
5827
  isPayrollFromFailedInvoices: isPayrollFromFailedInvoices
@@ -5891,7 +6044,7 @@ function BistpPaymentStatusPanel(_ref3) {
5891
6044
  className: classes.progress
5892
6045
  }, /*#__PURE__*/React.createElement(Typography, {
5893
6046
  variant: "body2"
5894
- }, formatMessage('payroll.bistp.progress'), ": ", confirmados, "/", total), /*#__PURE__*/React.createElement(LinearProgress$1, {
6047
+ }, formatMessage('payroll.bistp.progress'), ": ", confirmados, "/", total), /*#__PURE__*/React.createElement(LinearProgress, {
5895
6048
  variant: "determinate",
5896
6049
  value: progress
5897
6050
  })))));
@@ -6168,7 +6321,7 @@ function PayrollSearcherPending(_ref) {
6168
6321
  gap: 8,
6169
6322
  minWidth: 120
6170
6323
  }
6171
- }, /*#__PURE__*/React.createElement(LinearProgress, {
6324
+ }, /*#__PURE__*/React.createElement(LinearProgress$1, {
6172
6325
  variant: "determinate",
6173
6326
  value: progress,
6174
6327
  style: {