@stssocialst-stp/fe-payroll 0.3.5 → 0.3.7

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: {
@@ -6336,11 +6489,93 @@ function useBeneficiarios() {
6336
6489
  _useState6 = _slicedToArray(_useState5, 2),
6337
6490
  error = _useState6[0],
6338
6491
  setError = _useState6[1];
6339
- function request(_x) {
6492
+ function poll(_x) {
6493
+ return _poll.apply(this, arguments);
6494
+ }
6495
+ function _poll() {
6496
+ _poll = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(clientMutationId) {
6497
+ var INTERVAL_MS, TIMEOUT_MS, started, _result$data, _node$jsonExt$output, _node$jsonExt, resp, result, node;
6498
+ return _regeneratorRuntime.wrap(function (_context) {
6499
+ while (1) switch (_context.prev = _context.next) {
6500
+ case 0:
6501
+ INTERVAL_MS = 5000;
6502
+ TIMEOUT_MS = 20 * 60 * 1000; // 20 minutos
6503
+ started = Date.now();
6504
+ case 1:
6505
+ if (!(Date.now() - started < TIMEOUT_MS)) {
6506
+ _context.next = 8;
6507
+ break;
6508
+ }
6509
+ _context.next = 2;
6510
+ return new Promise(function (resolve) {
6511
+ return setTimeout(resolve, INTERVAL_MS);
6512
+ });
6513
+ case 2:
6514
+ _context.next = 3;
6515
+ return fetch("".concat(baseApiUrl, "/graphql"), {
6516
+ method: 'POST',
6517
+ headers: buildHeaders(),
6518
+ credentials: 'same-origin',
6519
+ body: JSON.stringify({
6520
+ query: "\n query {\n mutationLogs(clientMutationId: \"".concat(clientMutationId, "\") {\n edges { node { status error jsonExt clientMutationLabel } }\n }\n }\n ")
6521
+ })
6522
+ });
6523
+ case 3:
6524
+ resp = _context.sent;
6525
+ _context.next = 4;
6526
+ return resp.json();
6527
+ case 4:
6528
+ result = _context.sent;
6529
+ node = result === null || result === void 0 || (_result$data = result.data) === null || _result$data === void 0 || (_result$data = _result$data.mutationLogs) === null || _result$data === void 0 || (_result$data = _result$data.edges) === null || _result$data === void 0 || (_result$data = _result$data[0]) === null || _result$data === void 0 ? void 0 : _result$data.node;
6530
+ if (node) {
6531
+ _context.next = 5;
6532
+ break;
6533
+ }
6534
+ return _context.abrupt("continue", 1);
6535
+ case 5:
6536
+ // Update UI with label if needed
6537
+ setOutput("A processar: ".concat(node.clientMutationLabel, "..."));
6538
+ if (!(node.status === 2)) {
6539
+ _context.next = 6;
6540
+ break;
6541
+ }
6542
+ return _context.abrupt("return", {
6543
+ success: true,
6544
+ output: (_node$jsonExt$output = (_node$jsonExt = node.jsonExt) === null || _node$jsonExt === void 0 ? void 0 : _node$jsonExt.output) !== null && _node$jsonExt$output !== void 0 ? _node$jsonExt$output : null,
6545
+ error: null
6546
+ });
6547
+ case 6:
6548
+ if (!(node.status === 1)) {
6549
+ _context.next = 7;
6550
+ break;
6551
+ }
6552
+ return _context.abrupt("return", {
6553
+ success: false,
6554
+ output: null,
6555
+ error: node.error
6556
+ });
6557
+ case 7:
6558
+ _context.next = 1;
6559
+ break;
6560
+ case 8:
6561
+ return _context.abrupt("return", {
6562
+ success: false,
6563
+ output: null,
6564
+ error: 'Timeout: operação excedeu 20 minutos'
6565
+ });
6566
+ case 9:
6567
+ case "end":
6568
+ return _context.stop();
6569
+ }
6570
+ }, _callee);
6571
+ }));
6572
+ return _poll.apply(this, arguments);
6573
+ }
6574
+ function request(_x2) {
6340
6575
  return _request.apply(this, arguments);
6341
6576
  }
6342
6577
  function _request() {
6343
- _request = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(path) {
6578
+ _request = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(path) {
6344
6579
  var _ref,
6345
6580
  _ref$multipart,
6346
6581
  multipart,
@@ -6352,15 +6587,15 @@ function useBeneficiarios() {
6352
6587
  contentType,
6353
6588
  _data,
6354
6589
  message,
6355
- _args = arguments,
6590
+ _args2 = arguments,
6356
6591
  _t;
6357
- return _regeneratorRuntime.wrap(function (_context) {
6358
- while (1) switch (_context.prev = _context.next) {
6592
+ return _regeneratorRuntime.wrap(function (_context2) {
6593
+ while (1) switch (_context2.prev = _context2.next) {
6359
6594
  case 0:
6360
- _ref = _args.length > 1 && _args[1] !== undefined ? _args[1] : {}, _ref$multipart = _ref.multipart, multipart = _ref$multipart === void 0 ? false : _ref$multipart, _ref$body = _ref.body, body = _ref$body === void 0 ? null : _ref$body;
6595
+ _ref = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : {}, _ref$multipart = _ref.multipart, multipart = _ref$multipart === void 0 ? false : _ref$multipart, _ref$body = _ref.body, body = _ref$body === void 0 ? null : _ref$body;
6361
6596
  setLoading(true);
6362
6597
  setError(null);
6363
- _context.prev = 1;
6598
+ _context2.prev = 1;
6364
6599
  init = {
6365
6600
  method: 'POST',
6366
6601
  credentials: 'same-origin'
@@ -6371,54 +6606,50 @@ function useBeneficiarios() {
6371
6606
  init.headers = buildHeaders();
6372
6607
  if (body) init.body = JSON.stringify(body);
6373
6608
  }
6374
- _context.next = 2;
6609
+ _context2.next = 2;
6375
6610
  return fetch("".concat(BASE).concat(path), init);
6376
6611
  case 2:
6377
- response = _context.sent;
6612
+ response = _context2.sent;
6378
6613
  data = null;
6379
6614
  contentType = response.headers.get('content-type') || '';
6380
6615
  if (!contentType.includes('application/json')) {
6381
- _context.next = 4;
6616
+ _context2.next = 4;
6382
6617
  break;
6383
6618
  }
6384
- _context.next = 3;
6619
+ _context2.next = 3;
6385
6620
  return response.json();
6386
6621
  case 3:
6387
- data = _context.sent;
6622
+ data = _context2.sent;
6388
6623
  case 4:
6389
6624
  if (response.ok) {
6390
- _context.next = 5;
6625
+ _context2.next = 5;
6391
6626
  break;
6392
6627
  }
6393
6628
  message = ((_data = data) === null || _data === void 0 ? void 0 : _data.message) || "HTTP ".concat(response.status);
6394
6629
  setError(message);
6395
- return _context.abrupt("return", {
6630
+ return _context2.abrupt("return", {
6396
6631
  ok: false,
6397
6632
  message: message,
6398
6633
  data: data
6399
6634
  });
6400
6635
  case 5:
6401
- return _context.abrupt("return", {
6636
+ return _context2.abrupt("return", {
6402
6637
  ok: true,
6403
6638
  data: data
6404
6639
  });
6405
6640
  case 6:
6406
- _context.prev = 6;
6407
- _t = _context["catch"](1);
6641
+ _context2.prev = 6;
6642
+ _t = _context2["catch"](1);
6408
6643
  setError(_t.message);
6409
- return _context.abrupt("return", {
6644
+ return _context2.abrupt("return", {
6410
6645
  ok: false,
6411
6646
  message: _t.message
6412
6647
  });
6413
6648
  case 7:
6414
- _context.prev = 7;
6415
- setLoading(false);
6416
- return _context.finish(7);
6417
- case 8:
6418
6649
  case "end":
6419
- return _context.stop();
6650
+ return _context2.stop();
6420
6651
  }
6421
- }, _callee, null, [[1, 6, 7, 8]]);
6652
+ }, _callee2, null, [[1, 6]]);
6422
6653
  }));
6423
6654
  return _request.apply(this, arguments);
6424
6655
  }
@@ -6426,50 +6657,53 @@ function useBeneficiarios() {
6426
6657
  return _backup.apply(this, arguments);
6427
6658
  }
6428
6659
  function _backup() {
6429
- _backup = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
6660
+ _backup = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
6430
6661
  var payrollId,
6431
6662
  _yield$request,
6432
6663
  ok,
6433
6664
  data,
6434
- blob,
6435
- a,
6436
- _args2 = arguments;
6437
- return _regeneratorRuntime.wrap(function (_context2) {
6438
- while (1) switch (_context2.prev = _context2.next) {
6665
+ pollResult,
6666
+ _args3 = arguments;
6667
+ return _regeneratorRuntime.wrap(function (_context3) {
6668
+ while (1) switch (_context3.prev = _context3.next) {
6439
6669
  case 0:
6440
- payrollId = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : null;
6441
- _context2.next = 1;
6670
+ payrollId = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : null;
6671
+ _context3.next = 1;
6442
6672
  return request('/backup/', {
6443
6673
  body: payrollId ? {
6444
6674
  payroll_id: payrollId
6445
6675
  } : {}
6446
6676
  });
6447
6677
  case 1:
6448
- _yield$request = _context2.sent;
6678
+ _yield$request = _context3.sent;
6449
6679
  ok = _yield$request.ok;
6450
6680
  data = _yield$request.data;
6451
- if (ok) {
6452
- blob = new Blob([JSON.stringify(data, null, 2)], {
6453
- type: 'application/json'
6454
- });
6455
- a = document.createElement('a');
6456
- a.href = URL.createObjectURL(blob);
6457
- a.download = "backup_beneficiarios_".concat(new Date().toISOString().slice(0, 19).replace(/:/g, '-'), ".json");
6458
- document.body.appendChild(a);
6459
- a.click();
6460
- document.body.removeChild(a);
6461
- URL.revokeObjectURL(a.href);
6462
- setOutput("Backup conclu\xEDdo: ".concat(JSON.stringify(data.counts)));
6681
+ if (!ok) {
6682
+ _context3.next = 3;
6683
+ break;
6463
6684
  }
6464
- return _context2.abrupt("return", {
6685
+ setOutput('Backup iniciado. A aguardar conclusão...');
6686
+ _context3.next = 2;
6687
+ return poll(data.clientMutationId);
6688
+ case 2:
6689
+ pollResult = _context3.sent;
6690
+ if (pollResult.success) {
6691
+ setOutput("Backup conclu\xEDdo: ".concat(pollResult.output));
6692
+ // Handle download trigger if file info is in jsonExt
6693
+ } else {
6694
+ setError(pollResult.error);
6695
+ }
6696
+ case 3:
6697
+ setLoading(false);
6698
+ return _context3.abrupt("return", {
6465
6699
  ok: ok,
6466
6700
  data: data
6467
6701
  });
6468
- case 2:
6702
+ case 4:
6469
6703
  case "end":
6470
- return _context2.stop();
6704
+ return _context3.stop();
6471
6705
  }
6472
- }, _callee2);
6706
+ }, _callee3);
6473
6707
  }));
6474
6708
  return _backup.apply(this, arguments);
6475
6709
  }
@@ -6477,7 +6711,7 @@ function useBeneficiarios() {
6477
6711
  return _limpar.apply(this, arguments);
6478
6712
  }
6479
6713
  function _limpar() {
6480
- _limpar = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
6714
+ _limpar = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
6481
6715
  var _ref2,
6482
6716
  _ref2$dryRun,
6483
6717
  dryRun,
@@ -6486,12 +6720,13 @@ function useBeneficiarios() {
6486
6720
  _yield$request2,
6487
6721
  ok,
6488
6722
  data,
6489
- _args3 = arguments;
6490
- return _regeneratorRuntime.wrap(function (_context3) {
6491
- while (1) switch (_context3.prev = _context3.next) {
6723
+ pollResult,
6724
+ _args4 = arguments;
6725
+ return _regeneratorRuntime.wrap(function (_context4) {
6726
+ while (1) switch (_context4.prev = _context4.next) {
6492
6727
  case 0:
6493
- _ref2 = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : {}, _ref2$dryRun = _ref2.dryRun, dryRun = _ref2$dryRun === void 0 ? true : _ref2$dryRun, _ref2$forceSkipFinanc = _ref2.forceSkipFinancial, forceSkipFinancial = _ref2$forceSkipFinanc === void 0 ? false : _ref2$forceSkipFinanc;
6494
- _context3.next = 1;
6728
+ _ref2 = _args4.length > 0 && _args4[0] !== undefined ? _args4[0] : {}, _ref2$dryRun = _ref2.dryRun, dryRun = _ref2$dryRun === void 0 ? true : _ref2$dryRun, _ref2$forceSkipFinanc = _ref2.forceSkipFinancial, forceSkipFinancial = _ref2$forceSkipFinanc === void 0 ? false : _ref2$forceSkipFinanc;
6729
+ _context4.next = 1;
6495
6730
  return request('/limpar/', {
6496
6731
  body: {
6497
6732
  username: 'admin',
@@ -6500,27 +6735,42 @@ function useBeneficiarios() {
6500
6735
  }
6501
6736
  });
6502
6737
  case 1:
6503
- _yield$request2 = _context3.sent;
6738
+ _yield$request2 = _context4.sent;
6504
6739
  ok = _yield$request2.ok;
6505
6740
  data = _yield$request2.data;
6506
- if (ok) setOutput(data.output);
6507
- return _context3.abrupt("return", {
6741
+ if (!ok) {
6742
+ _context4.next = 3;
6743
+ break;
6744
+ }
6745
+ setOutput('Limpeza iniciada. A aguardar conclusão...');
6746
+ _context4.next = 2;
6747
+ return poll(data.clientMutationId);
6748
+ case 2:
6749
+ pollResult = _context4.sent;
6750
+ if (pollResult.success) {
6751
+ setOutput(pollResult.output);
6752
+ } else {
6753
+ setError(pollResult.error);
6754
+ }
6755
+ case 3:
6756
+ setLoading(false);
6757
+ return _context4.abrupt("return", {
6508
6758
  ok: ok,
6509
6759
  data: data
6510
6760
  });
6511
- case 2:
6761
+ case 4:
6512
6762
  case "end":
6513
- return _context3.stop();
6763
+ return _context4.stop();
6514
6764
  }
6515
- }, _callee3);
6765
+ }, _callee4);
6516
6766
  }));
6517
6767
  return _limpar.apply(this, arguments);
6518
6768
  }
6519
- function importar(_x2) {
6769
+ function importar(_x3) {
6520
6770
  return _importar.apply(this, arguments);
6521
6771
  }
6522
6772
  function _importar() {
6523
- _importar = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(file) {
6773
+ _importar = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(file) {
6524
6774
  var _ref3,
6525
6775
  _ref3$dryRun,
6526
6776
  dryRun,
@@ -6532,11 +6782,12 @@ function useBeneficiarios() {
6532
6782
  _yield$request3,
6533
6783
  ok,
6534
6784
  data,
6535
- _args4 = arguments;
6536
- return _regeneratorRuntime.wrap(function (_context4) {
6537
- while (1) switch (_context4.prev = _context4.next) {
6785
+ pollResult,
6786
+ _args5 = arguments;
6787
+ return _regeneratorRuntime.wrap(function (_context5) {
6788
+ while (1) switch (_context5.prev = _context5.next) {
6538
6789
  case 0:
6539
- _ref3 = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : {}, _ref3$dryRun = _ref3.dryRun, dryRun = _ref3$dryRun === void 0 ? false : _ref3$dryRun, payrollId = _ref3.payrollId, benefitPlanId = _ref3.benefitPlanId, benefitType = _ref3.benefitType, sheet = _ref3.sheet;
6790
+ _ref3 = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : {}, _ref3$dryRun = _ref3.dryRun, dryRun = _ref3$dryRun === void 0 ? false : _ref3$dryRun, payrollId = _ref3.payrollId, benefitPlanId = _ref3.benefitPlanId, benefitType = _ref3.benefitType, sheet = _ref3.sheet;
6540
6791
  fd = new FormData();
6541
6792
  fd.append('file', file);
6542
6793
  fd.append('username', 'admin');
@@ -6545,33 +6796,48 @@ function useBeneficiarios() {
6545
6796
  if (benefitPlanId) fd.append('benefit_plan_id', benefitPlanId);
6546
6797
  if (benefitType) fd.append('benefit_type', benefitType);
6547
6798
  if (sheet) fd.append('sheet', sheet);
6548
- _context4.next = 1;
6799
+ _context5.next = 1;
6549
6800
  return request('/importar/', {
6550
6801
  multipart: true,
6551
6802
  body: fd
6552
6803
  });
6553
6804
  case 1:
6554
- _yield$request3 = _context4.sent;
6805
+ _yield$request3 = _context5.sent;
6555
6806
  ok = _yield$request3.ok;
6556
6807
  data = _yield$request3.data;
6557
- if (ok) setOutput(data.output);
6558
- return _context4.abrupt("return", {
6808
+ if (!ok) {
6809
+ _context5.next = 3;
6810
+ break;
6811
+ }
6812
+ setOutput('Importação iniciada. A aguardar conclusão...');
6813
+ _context5.next = 2;
6814
+ return poll(data.clientMutationId);
6815
+ case 2:
6816
+ pollResult = _context5.sent;
6817
+ if (pollResult.success) {
6818
+ setOutput(pollResult.output);
6819
+ } else {
6820
+ setError(pollResult.error);
6821
+ }
6822
+ case 3:
6823
+ setLoading(false);
6824
+ return _context5.abrupt("return", {
6559
6825
  ok: ok,
6560
6826
  data: data
6561
6827
  });
6562
- case 2:
6828
+ case 4:
6563
6829
  case "end":
6564
- return _context4.stop();
6830
+ return _context5.stop();
6565
6831
  }
6566
- }, _callee4);
6832
+ }, _callee5);
6567
6833
  }));
6568
6834
  return _importar.apply(this, arguments);
6569
6835
  }
6570
- function restore(_x3) {
6836
+ function restore(_x4) {
6571
6837
  return _restore.apply(this, arguments);
6572
6838
  }
6573
6839
  function _restore() {
6574
- _restore = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(file) {
6840
+ _restore = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6(file) {
6575
6841
  var _ref4,
6576
6842
  _ref4$dryRun,
6577
6843
  dryRun,
@@ -6581,35 +6847,51 @@ function useBeneficiarios() {
6581
6847
  _yield$request4,
6582
6848
  ok,
6583
6849
  data,
6584
- _args5 = arguments;
6585
- return _regeneratorRuntime.wrap(function (_context5) {
6586
- while (1) switch (_context5.prev = _context5.next) {
6850
+ pollResult,
6851
+ _args6 = arguments;
6852
+ return _regeneratorRuntime.wrap(function (_context6) {
6853
+ while (1) switch (_context6.prev = _context6.next) {
6587
6854
  case 0:
6588
- _ref4 = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : {}, _ref4$dryRun = _ref4.dryRun, dryRun = _ref4$dryRun === void 0 ? true : _ref4$dryRun, _ref4$skipPhases = _ref4.skipPhases, skipPhases = _ref4$skipPhases === void 0 ? [] : _ref4$skipPhases;
6855
+ _ref4 = _args6.length > 1 && _args6[1] !== undefined ? _args6[1] : {}, _ref4$dryRun = _ref4.dryRun, dryRun = _ref4$dryRun === void 0 ? true : _ref4$dryRun, _ref4$skipPhases = _ref4.skipPhases, skipPhases = _ref4$skipPhases === void 0 ? [] : _ref4$skipPhases;
6589
6856
  fd = new FormData();
6590
6857
  fd.append('file', file);
6591
6858
  fd.append('username', 'admin');
6592
6859
  fd.append('dry_run', String(dryRun));
6593
6860
  if (skipPhases.length) fd.append('skip_phases', skipPhases.join(','));
6594
- _context5.next = 1;
6861
+ _context6.next = 1;
6595
6862
  return request('/restore/', {
6596
6863
  multipart: true,
6597
6864
  body: fd
6598
6865
  });
6599
6866
  case 1:
6600
- _yield$request4 = _context5.sent;
6867
+ _yield$request4 = _context6.sent;
6601
6868
  ok = _yield$request4.ok;
6602
6869
  data = _yield$request4.data;
6603
- if (ok) setOutput(data.output);
6604
- return _context5.abrupt("return", {
6870
+ if (!ok) {
6871
+ _context6.next = 3;
6872
+ break;
6873
+ }
6874
+ setOutput('Restore iniciado. A aguardar conclusão...');
6875
+ _context6.next = 2;
6876
+ return poll(data.clientMutationId);
6877
+ case 2:
6878
+ pollResult = _context6.sent;
6879
+ if (pollResult.success) {
6880
+ setOutput(pollResult.output);
6881
+ } else {
6882
+ setError(pollResult.error);
6883
+ }
6884
+ case 3:
6885
+ setLoading(false);
6886
+ return _context6.abrupt("return", {
6605
6887
  ok: ok,
6606
6888
  data: data
6607
6889
  });
6608
- case 2:
6890
+ case 4:
6609
6891
  case "end":
6610
- return _context5.stop();
6892
+ return _context6.stop();
6611
6893
  }
6612
- }, _callee5);
6894
+ }, _callee6);
6613
6895
  }));
6614
6896
  return _restore.apply(this, arguments);
6615
6897
  }