@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.js CHANGED
@@ -762,7 +762,12 @@ var messages_en = {
762
762
  "payroll.bistp.status.pending": "Sent to Bank",
763
763
  "payroll.bistp.status.skippedNib": "No NIB",
764
764
  "payroll.bistp.status.sendFailed": "Send Failed",
765
+ "payroll.bistp.status.enviados": "Sent to BISTP",
765
766
  "payroll.bistp.progress": "BISTP Progress",
767
+ "payroll.async.generating": "Generating beneficiaries in background...",
768
+ "payroll.async.createdSoFar": "{benefitCount} created so far",
769
+ "payroll.async.note": "This process may take a few minutes. You can close this page - the process continues in the background.",
770
+ "payroll.async.timedOut": "The background generation process took too long. Please refresh this page to check the current status.",
766
771
  "payroll.route.beneficiariesManagement": "Beneficiary Management",
767
772
  "payroll.beneficiaries.management.title": "Beneficiary Management",
768
773
  "payroll.beneficiaries.management.noPermission": "You do not have permission to manage beneficiaries.",
@@ -3211,6 +3216,99 @@ var mapDispatchToProps$b = function mapDispatchToProps(dispatch) {
3211
3216
  };
3212
3217
  var PaymentApproveForPaymentSummary = reactRedux.connect(mapStateToProps$b, mapDispatchToProps$b)(PaymentApproveForPaymentDialog);
3213
3218
 
3219
+ var POLL_INTERVAL_MS = 5000;
3220
+ var TIMEOUT_MS = 600000;
3221
+ var COUNT_QUERY = function COUNT_QUERY(payrollUuid) {
3222
+ return "\n {\n benefitConsumptionByPayroll(payrollUuid: \"".concat(payrollUuid, "\", first: 0, isDeleted: false) {\n totalCount\n }\n }\n");
3223
+ };
3224
+ function useAsyncPayrollProgress(_ref) {
3225
+ var payrollUuid = _ref.payrollUuid,
3226
+ payrollStatus = _ref.payrollStatus;
3227
+ var dispatch = reactRedux.useDispatch();
3228
+ var _useState = React.useState(0),
3229
+ _useState2 = _slicedToArray__default["default"](_useState, 2),
3230
+ benefitCount = _useState2[0],
3231
+ setBenefitCount = _useState2[1];
3232
+ var _useState3 = React.useState(false),
3233
+ _useState4 = _slicedToArray__default["default"](_useState3, 2),
3234
+ isGenerating = _useState4[0],
3235
+ setIsGenerating = _useState4[1];
3236
+ var _useState5 = React.useState(false),
3237
+ _useState6 = _slicedToArray__default["default"](_useState5, 2),
3238
+ timedOut = _useState6[0],
3239
+ setTimedOut = _useState6[1];
3240
+ var pollRef = React.useRef(null);
3241
+ var startTimeRef = React.useRef(null);
3242
+ var prevCountRef = React.useRef(0);
3243
+ var stableCountRounds = React.useRef(0);
3244
+ var stopPolling = React.useCallback(function () {
3245
+ if (pollRef.current) {
3246
+ clearInterval(pollRef.current);
3247
+ pollRef.current = null;
3248
+ }
3249
+ }, []);
3250
+ var fetchCount = React.useCallback(function () {
3251
+ if (!payrollUuid) return;
3252
+ dispatch(feCore.graphql(COUNT_QUERY(payrollUuid), 'POLL_BENEFIT_COUNT')).then(function (response) {
3253
+ var _response$payload$dat, _response$payload;
3254
+ 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;
3255
+ if (count === 0) {
3256
+ setBenefitCount(count);
3257
+ setIsGenerating(true);
3258
+ stableCountRounds.current = 0;
3259
+ prevCountRef.current = count;
3260
+ return;
3261
+ }
3262
+ setBenefitCount(count);
3263
+ if (count === prevCountRef.current) {
3264
+ stableCountRounds.current += 1;
3265
+ } else {
3266
+ stableCountRounds.current = 0;
3267
+ }
3268
+ prevCountRef.current = count;
3269
+ if (stableCountRounds.current >= 2) {
3270
+ setIsGenerating(false);
3271
+ stopPolling();
3272
+ }
3273
+ })["catch"](function () {
3274
+ setBenefitCount(function (c) {
3275
+ return Math.max(c, 0);
3276
+ });
3277
+ });
3278
+ }, [payrollUuid, dispatch, stopPolling]);
3279
+ React.useEffect(function () {
3280
+ var shouldPoll = payrollUuid && payrollStatus === 'PENDING_APPROVAL';
3281
+ if (shouldPoll && !pollRef.current) {
3282
+ setTimedOut(false);
3283
+ startTimeRef.current = Date.now();
3284
+ stableCountRounds.current = 0;
3285
+ prevCountRef.current = 0;
3286
+ fetchCount();
3287
+ pollRef.current = setInterval(function () {
3288
+ if (Date.now() - startTimeRef.current >= TIMEOUT_MS) {
3289
+ setIsGenerating(false);
3290
+ setTimedOut(true);
3291
+ stopPolling();
3292
+ return;
3293
+ }
3294
+ fetchCount();
3295
+ }, POLL_INTERVAL_MS);
3296
+ }
3297
+ if (!shouldPoll && pollRef.current) {
3298
+ setIsGenerating(false);
3299
+ stopPolling();
3300
+ }
3301
+ return function () {
3302
+ return stopPolling();
3303
+ };
3304
+ }, [payrollUuid, payrollStatus, fetchCount, stopPolling]);
3305
+ return {
3306
+ isGenerating: isGenerating,
3307
+ benefitCount: benefitCount,
3308
+ timedOut: timedOut
3309
+ };
3310
+ }
3311
+
3214
3312
  var useStyles$b = styles$7.makeStyles(function (theme) {
3215
3313
  return {
3216
3314
  paper: theme.paper.paper,
@@ -3257,12 +3355,64 @@ function PayrollTab(_ref) {
3257
3355
  var modulesManager = feCore.useModulesManager();
3258
3356
  var _useTranslations = feCore.useTranslations(MODULE_NAME, modulesManager),
3259
3357
  formatMessage = _useTranslations.formatMessage;
3358
+ var _useAsyncPayrollProgr = useAsyncPayrollProgress({
3359
+ payrollUuid: payrollUuid,
3360
+ payrollStatus: payroll === null || payroll === void 0 ? void 0 : payroll.status
3361
+ }),
3362
+ isGenerating = _useAsyncPayrollProgr.isGenerating,
3363
+ benefitCount = _useAsyncPayrollProgr.benefitCount,
3364
+ timedOut = _useAsyncPayrollProgr.timedOut;
3365
+ var _useState3 = React.useState(false),
3366
+ _useState4 = _slicedToArray__default["default"](_useState3, 2),
3367
+ generationComplete = _useState4[0],
3368
+ setGenerationComplete = _useState4[1];
3369
+ var _useState5 = React.useState(0),
3370
+ _useState6 = _slicedToArray__default["default"](_useState5, 2),
3371
+ refreshBenefitsKey = _useState6[0],
3372
+ setRefreshBenefitsKey = _useState6[1];
3373
+ React.useEffect(function () {
3374
+ if (!isGenerating && benefitCount > 0 && !generationComplete) {
3375
+ setGenerationComplete(true);
3376
+ setRefreshBenefitsKey(function (k) {
3377
+ return k + 1;
3378
+ });
3379
+ }
3380
+ }, [isGenerating, benefitCount, generationComplete]);
3260
3381
  var downloadPayrollData = function downloadPayrollData(payrollUuid, payrollName) {
3261
3382
  downloadPayroll(payrollUuid, payrollName);
3262
3383
  };
3263
3384
  return /*#__PURE__*/React__default["default"].createElement(core.Paper, {
3264
3385
  className: classes.paper
3386
+ }, (isGenerating || timedOut) && payrollUuid && !isPayrollFromFailedInvoices && /*#__PURE__*/React__default["default"].createElement(core.Grid, {
3387
+ container: true,
3388
+ spacing: 2,
3389
+ style: {
3390
+ padding: '16px'
3391
+ }
3265
3392
  }, /*#__PURE__*/React__default["default"].createElement(core.Grid, {
3393
+ item: true,
3394
+ xs: 12
3395
+ }, /*#__PURE__*/React__default["default"].createElement(core.Typography, {
3396
+ variant: "body1"
3397
+ }, timedOut ? formatMessage('payroll.async.timedOut') : formatMessage('payroll.async.generating')), !timedOut && /*#__PURE__*/React__default["default"].createElement(core.LinearProgress, {
3398
+ variant: "indeterminate",
3399
+ style: {
3400
+ marginTop: '8px'
3401
+ }
3402
+ }), /*#__PURE__*/React__default["default"].createElement(core.Typography, {
3403
+ variant: "caption",
3404
+ style: {
3405
+ display: 'block',
3406
+ marginTop: '4px'
3407
+ }
3408
+ }, !timedOut && formatMessage('payroll.async.createdSoFar', {
3409
+ benefitCount: benefitCount
3410
+ })), /*#__PURE__*/React__default["default"].createElement(core.Typography, {
3411
+ variant: "caption",
3412
+ style: {
3413
+ display: 'block'
3414
+ }
3415
+ }, !timedOut && formatMessage('payroll.async.note')))), /*#__PURE__*/React__default["default"].createElement(core.Grid, {
3266
3416
  container: true,
3267
3417
  className: "".concat(classes.tableTitle, " ").concat(classes.tabs)
3268
3418
  }, /*#__PURE__*/React__default["default"].createElement("div", {
@@ -3313,7 +3463,8 @@ function PayrollTab(_ref) {
3313
3463
  payrollUuid: payrollUuid,
3314
3464
  isInTask: isInTask,
3315
3465
  isPayrollFromFailedInvoices: isPayrollFromFailedInvoices,
3316
- payroll: payroll
3466
+ payroll: payroll,
3467
+ refreshBenefitsKey: refreshBenefitsKey
3317
3468
  }));
3318
3469
  }
3319
3470
 
@@ -5706,13 +5857,15 @@ function BenefitConsumptionsTabPanel(_ref2) {
5706
5857
  var value = _ref2.value,
5707
5858
  rights = _ref2.rights,
5708
5859
  payrollUuid = _ref2.payrollUuid,
5709
- isPayrollFromFailedInvoices = _ref2.isPayrollFromFailedInvoices;
5860
+ isPayrollFromFailedInvoices = _ref2.isPayrollFromFailedInvoices,
5861
+ refreshBenefitsKey = _ref2.refreshBenefitsKey;
5710
5862
  return /*#__PURE__*/React__default["default"].createElement(feCore.PublishedComponent, {
5711
5863
  pubRef: "policyHolder.TabPanel",
5712
5864
  module: "payroll",
5713
5865
  index: BENEFIT_CONSUMPTION_LIST_TAB_VALUE,
5714
5866
  value: value
5715
5867
  }, rights.includes(RIGHT_PAYROLL_SEARCH) && payrollUuid && /*#__PURE__*/React__default["default"].createElement(BenefitConsumptionSearcher$1, {
5868
+ key: refreshBenefitsKey,
5716
5869
  rights: rights,
5717
5870
  payrollUuid: payrollUuid,
5718
5871
  isPayrollFromFailedInvoices: isPayrollFromFailedInvoices
@@ -6380,11 +6533,93 @@ function useBeneficiarios() {
6380
6533
  _useState6 = _slicedToArray__default["default"](_useState5, 2),
6381
6534
  error = _useState6[0],
6382
6535
  setError = _useState6[1];
6383
- function request(_x) {
6536
+ function poll(_x) {
6537
+ return _poll.apply(this, arguments);
6538
+ }
6539
+ function _poll() {
6540
+ _poll = _asyncToGenerator__default["default"](/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee(clientMutationId) {
6541
+ var INTERVAL_MS, TIMEOUT_MS, started, _result$data, _node$jsonExt$output, _node$jsonExt, resp, result, node;
6542
+ return _regeneratorRuntime__default["default"].wrap(function (_context) {
6543
+ while (1) switch (_context.prev = _context.next) {
6544
+ case 0:
6545
+ INTERVAL_MS = 5000;
6546
+ TIMEOUT_MS = 20 * 60 * 1000; // 20 minutos
6547
+ started = Date.now();
6548
+ case 1:
6549
+ if (!(Date.now() - started < TIMEOUT_MS)) {
6550
+ _context.next = 8;
6551
+ break;
6552
+ }
6553
+ _context.next = 2;
6554
+ return new Promise(function (resolve) {
6555
+ return setTimeout(resolve, INTERVAL_MS);
6556
+ });
6557
+ case 2:
6558
+ _context.next = 3;
6559
+ return fetch("".concat(feCore.baseApiUrl, "/graphql"), {
6560
+ method: 'POST',
6561
+ headers: buildHeaders(),
6562
+ credentials: 'same-origin',
6563
+ body: JSON.stringify({
6564
+ query: "\n query {\n mutationLogs(clientMutationId: \"".concat(clientMutationId, "\") {\n edges { node { status error jsonExt clientMutationLabel } }\n }\n }\n ")
6565
+ })
6566
+ });
6567
+ case 3:
6568
+ resp = _context.sent;
6569
+ _context.next = 4;
6570
+ return resp.json();
6571
+ case 4:
6572
+ result = _context.sent;
6573
+ 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;
6574
+ if (node) {
6575
+ _context.next = 5;
6576
+ break;
6577
+ }
6578
+ return _context.abrupt("continue", 1);
6579
+ case 5:
6580
+ // Update UI with label if needed
6581
+ setOutput("A processar: ".concat(node.clientMutationLabel, "..."));
6582
+ if (!(node.status === 2)) {
6583
+ _context.next = 6;
6584
+ break;
6585
+ }
6586
+ return _context.abrupt("return", {
6587
+ success: true,
6588
+ 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,
6589
+ error: null
6590
+ });
6591
+ case 6:
6592
+ if (!(node.status === 1)) {
6593
+ _context.next = 7;
6594
+ break;
6595
+ }
6596
+ return _context.abrupt("return", {
6597
+ success: false,
6598
+ output: null,
6599
+ error: node.error
6600
+ });
6601
+ case 7:
6602
+ _context.next = 1;
6603
+ break;
6604
+ case 8:
6605
+ return _context.abrupt("return", {
6606
+ success: false,
6607
+ output: null,
6608
+ error: 'Timeout: operação excedeu 20 minutos'
6609
+ });
6610
+ case 9:
6611
+ case "end":
6612
+ return _context.stop();
6613
+ }
6614
+ }, _callee);
6615
+ }));
6616
+ return _poll.apply(this, arguments);
6617
+ }
6618
+ function request(_x2) {
6384
6619
  return _request.apply(this, arguments);
6385
6620
  }
6386
6621
  function _request() {
6387
- _request = _asyncToGenerator__default["default"](/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee(path) {
6622
+ _request = _asyncToGenerator__default["default"](/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee2(path) {
6388
6623
  var _ref,
6389
6624
  _ref$multipart,
6390
6625
  multipart,
@@ -6396,15 +6631,15 @@ function useBeneficiarios() {
6396
6631
  contentType,
6397
6632
  _data,
6398
6633
  message,
6399
- _args = arguments,
6634
+ _args2 = arguments,
6400
6635
  _t;
6401
- return _regeneratorRuntime__default["default"].wrap(function (_context) {
6402
- while (1) switch (_context.prev = _context.next) {
6636
+ return _regeneratorRuntime__default["default"].wrap(function (_context2) {
6637
+ while (1) switch (_context2.prev = _context2.next) {
6403
6638
  case 0:
6404
- _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;
6639
+ _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;
6405
6640
  setLoading(true);
6406
6641
  setError(null);
6407
- _context.prev = 1;
6642
+ _context2.prev = 1;
6408
6643
  init = {
6409
6644
  method: 'POST',
6410
6645
  credentials: 'same-origin'
@@ -6415,54 +6650,50 @@ function useBeneficiarios() {
6415
6650
  init.headers = buildHeaders();
6416
6651
  if (body) init.body = JSON.stringify(body);
6417
6652
  }
6418
- _context.next = 2;
6653
+ _context2.next = 2;
6419
6654
  return fetch("".concat(BASE).concat(path), init);
6420
6655
  case 2:
6421
- response = _context.sent;
6656
+ response = _context2.sent;
6422
6657
  data = null;
6423
6658
  contentType = response.headers.get('content-type') || '';
6424
6659
  if (!contentType.includes('application/json')) {
6425
- _context.next = 4;
6660
+ _context2.next = 4;
6426
6661
  break;
6427
6662
  }
6428
- _context.next = 3;
6663
+ _context2.next = 3;
6429
6664
  return response.json();
6430
6665
  case 3:
6431
- data = _context.sent;
6666
+ data = _context2.sent;
6432
6667
  case 4:
6433
6668
  if (response.ok) {
6434
- _context.next = 5;
6669
+ _context2.next = 5;
6435
6670
  break;
6436
6671
  }
6437
6672
  message = ((_data = data) === null || _data === void 0 ? void 0 : _data.message) || "HTTP ".concat(response.status);
6438
6673
  setError(message);
6439
- return _context.abrupt("return", {
6674
+ return _context2.abrupt("return", {
6440
6675
  ok: false,
6441
6676
  message: message,
6442
6677
  data: data
6443
6678
  });
6444
6679
  case 5:
6445
- return _context.abrupt("return", {
6680
+ return _context2.abrupt("return", {
6446
6681
  ok: true,
6447
6682
  data: data
6448
6683
  });
6449
6684
  case 6:
6450
- _context.prev = 6;
6451
- _t = _context["catch"](1);
6685
+ _context2.prev = 6;
6686
+ _t = _context2["catch"](1);
6452
6687
  setError(_t.message);
6453
- return _context.abrupt("return", {
6688
+ return _context2.abrupt("return", {
6454
6689
  ok: false,
6455
6690
  message: _t.message
6456
6691
  });
6457
6692
  case 7:
6458
- _context.prev = 7;
6459
- setLoading(false);
6460
- return _context.finish(7);
6461
- case 8:
6462
6693
  case "end":
6463
- return _context.stop();
6694
+ return _context2.stop();
6464
6695
  }
6465
- }, _callee, null, [[1, 6, 7, 8]]);
6696
+ }, _callee2, null, [[1, 6]]);
6466
6697
  }));
6467
6698
  return _request.apply(this, arguments);
6468
6699
  }
@@ -6470,50 +6701,53 @@ function useBeneficiarios() {
6470
6701
  return _backup.apply(this, arguments);
6471
6702
  }
6472
6703
  function _backup() {
6473
- _backup = _asyncToGenerator__default["default"](/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee2() {
6704
+ _backup = _asyncToGenerator__default["default"](/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee3() {
6474
6705
  var payrollId,
6475
6706
  _yield$request,
6476
6707
  ok,
6477
6708
  data,
6478
- blob,
6479
- a,
6480
- _args2 = arguments;
6481
- return _regeneratorRuntime__default["default"].wrap(function (_context2) {
6482
- while (1) switch (_context2.prev = _context2.next) {
6709
+ pollResult,
6710
+ _args3 = arguments;
6711
+ return _regeneratorRuntime__default["default"].wrap(function (_context3) {
6712
+ while (1) switch (_context3.prev = _context3.next) {
6483
6713
  case 0:
6484
- payrollId = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : null;
6485
- _context2.next = 1;
6714
+ payrollId = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : null;
6715
+ _context3.next = 1;
6486
6716
  return request('/backup/', {
6487
6717
  body: payrollId ? {
6488
6718
  payroll_id: payrollId
6489
6719
  } : {}
6490
6720
  });
6491
6721
  case 1:
6492
- _yield$request = _context2.sent;
6722
+ _yield$request = _context3.sent;
6493
6723
  ok = _yield$request.ok;
6494
6724
  data = _yield$request.data;
6495
- if (ok) {
6496
- blob = new Blob([JSON.stringify(data, null, 2)], {
6497
- type: 'application/json'
6498
- });
6499
- a = document.createElement('a');
6500
- a.href = URL.createObjectURL(blob);
6501
- a.download = "backup_beneficiarios_".concat(new Date().toISOString().slice(0, 19).replace(/:/g, '-'), ".json");
6502
- document.body.appendChild(a);
6503
- a.click();
6504
- document.body.removeChild(a);
6505
- URL.revokeObjectURL(a.href);
6506
- setOutput("Backup conclu\xEDdo: ".concat(JSON.stringify(data.counts)));
6725
+ if (!ok) {
6726
+ _context3.next = 3;
6727
+ break;
6507
6728
  }
6508
- return _context2.abrupt("return", {
6729
+ setOutput('Backup iniciado. A aguardar conclusão...');
6730
+ _context3.next = 2;
6731
+ return poll(data.clientMutationId);
6732
+ case 2:
6733
+ pollResult = _context3.sent;
6734
+ if (pollResult.success) {
6735
+ setOutput("Backup conclu\xEDdo: ".concat(pollResult.output));
6736
+ // Handle download trigger if file info is in jsonExt
6737
+ } else {
6738
+ setError(pollResult.error);
6739
+ }
6740
+ case 3:
6741
+ setLoading(false);
6742
+ return _context3.abrupt("return", {
6509
6743
  ok: ok,
6510
6744
  data: data
6511
6745
  });
6512
- case 2:
6746
+ case 4:
6513
6747
  case "end":
6514
- return _context2.stop();
6748
+ return _context3.stop();
6515
6749
  }
6516
- }, _callee2);
6750
+ }, _callee3);
6517
6751
  }));
6518
6752
  return _backup.apply(this, arguments);
6519
6753
  }
@@ -6521,7 +6755,7 @@ function useBeneficiarios() {
6521
6755
  return _limpar.apply(this, arguments);
6522
6756
  }
6523
6757
  function _limpar() {
6524
- _limpar = _asyncToGenerator__default["default"](/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee3() {
6758
+ _limpar = _asyncToGenerator__default["default"](/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee4() {
6525
6759
  var _ref2,
6526
6760
  _ref2$dryRun,
6527
6761
  dryRun,
@@ -6530,12 +6764,13 @@ function useBeneficiarios() {
6530
6764
  _yield$request2,
6531
6765
  ok,
6532
6766
  data,
6533
- _args3 = arguments;
6534
- return _regeneratorRuntime__default["default"].wrap(function (_context3) {
6535
- while (1) switch (_context3.prev = _context3.next) {
6767
+ pollResult,
6768
+ _args4 = arguments;
6769
+ return _regeneratorRuntime__default["default"].wrap(function (_context4) {
6770
+ while (1) switch (_context4.prev = _context4.next) {
6536
6771
  case 0:
6537
- _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;
6538
- _context3.next = 1;
6772
+ _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;
6773
+ _context4.next = 1;
6539
6774
  return request('/limpar/', {
6540
6775
  body: {
6541
6776
  username: 'admin',
@@ -6544,27 +6779,42 @@ function useBeneficiarios() {
6544
6779
  }
6545
6780
  });
6546
6781
  case 1:
6547
- _yield$request2 = _context3.sent;
6782
+ _yield$request2 = _context4.sent;
6548
6783
  ok = _yield$request2.ok;
6549
6784
  data = _yield$request2.data;
6550
- if (ok) setOutput(data.output);
6551
- return _context3.abrupt("return", {
6785
+ if (!ok) {
6786
+ _context4.next = 3;
6787
+ break;
6788
+ }
6789
+ setOutput('Limpeza iniciada. A aguardar conclusão...');
6790
+ _context4.next = 2;
6791
+ return poll(data.clientMutationId);
6792
+ case 2:
6793
+ pollResult = _context4.sent;
6794
+ if (pollResult.success) {
6795
+ setOutput(pollResult.output);
6796
+ } else {
6797
+ setError(pollResult.error);
6798
+ }
6799
+ case 3:
6800
+ setLoading(false);
6801
+ return _context4.abrupt("return", {
6552
6802
  ok: ok,
6553
6803
  data: data
6554
6804
  });
6555
- case 2:
6805
+ case 4:
6556
6806
  case "end":
6557
- return _context3.stop();
6807
+ return _context4.stop();
6558
6808
  }
6559
- }, _callee3);
6809
+ }, _callee4);
6560
6810
  }));
6561
6811
  return _limpar.apply(this, arguments);
6562
6812
  }
6563
- function importar(_x2) {
6813
+ function importar(_x3) {
6564
6814
  return _importar.apply(this, arguments);
6565
6815
  }
6566
6816
  function _importar() {
6567
- _importar = _asyncToGenerator__default["default"](/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee4(file) {
6817
+ _importar = _asyncToGenerator__default["default"](/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee5(file) {
6568
6818
  var _ref3,
6569
6819
  _ref3$dryRun,
6570
6820
  dryRun,
@@ -6576,11 +6826,12 @@ function useBeneficiarios() {
6576
6826
  _yield$request3,
6577
6827
  ok,
6578
6828
  data,
6579
- _args4 = arguments;
6580
- return _regeneratorRuntime__default["default"].wrap(function (_context4) {
6581
- while (1) switch (_context4.prev = _context4.next) {
6829
+ pollResult,
6830
+ _args5 = arguments;
6831
+ return _regeneratorRuntime__default["default"].wrap(function (_context5) {
6832
+ while (1) switch (_context5.prev = _context5.next) {
6582
6833
  case 0:
6583
- _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;
6834
+ _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;
6584
6835
  fd = new FormData();
6585
6836
  fd.append('file', file);
6586
6837
  fd.append('username', 'admin');
@@ -6589,33 +6840,48 @@ function useBeneficiarios() {
6589
6840
  if (benefitPlanId) fd.append('benefit_plan_id', benefitPlanId);
6590
6841
  if (benefitType) fd.append('benefit_type', benefitType);
6591
6842
  if (sheet) fd.append('sheet', sheet);
6592
- _context4.next = 1;
6843
+ _context5.next = 1;
6593
6844
  return request('/importar/', {
6594
6845
  multipart: true,
6595
6846
  body: fd
6596
6847
  });
6597
6848
  case 1:
6598
- _yield$request3 = _context4.sent;
6849
+ _yield$request3 = _context5.sent;
6599
6850
  ok = _yield$request3.ok;
6600
6851
  data = _yield$request3.data;
6601
- if (ok) setOutput(data.output);
6602
- return _context4.abrupt("return", {
6852
+ if (!ok) {
6853
+ _context5.next = 3;
6854
+ break;
6855
+ }
6856
+ setOutput('Importação iniciada. A aguardar conclusão...');
6857
+ _context5.next = 2;
6858
+ return poll(data.clientMutationId);
6859
+ case 2:
6860
+ pollResult = _context5.sent;
6861
+ if (pollResult.success) {
6862
+ setOutput(pollResult.output);
6863
+ } else {
6864
+ setError(pollResult.error);
6865
+ }
6866
+ case 3:
6867
+ setLoading(false);
6868
+ return _context5.abrupt("return", {
6603
6869
  ok: ok,
6604
6870
  data: data
6605
6871
  });
6606
- case 2:
6872
+ case 4:
6607
6873
  case "end":
6608
- return _context4.stop();
6874
+ return _context5.stop();
6609
6875
  }
6610
- }, _callee4);
6876
+ }, _callee5);
6611
6877
  }));
6612
6878
  return _importar.apply(this, arguments);
6613
6879
  }
6614
- function restore(_x3) {
6880
+ function restore(_x4) {
6615
6881
  return _restore.apply(this, arguments);
6616
6882
  }
6617
6883
  function _restore() {
6618
- _restore = _asyncToGenerator__default["default"](/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee5(file) {
6884
+ _restore = _asyncToGenerator__default["default"](/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee6(file) {
6619
6885
  var _ref4,
6620
6886
  _ref4$dryRun,
6621
6887
  dryRun,
@@ -6625,35 +6891,51 @@ function useBeneficiarios() {
6625
6891
  _yield$request4,
6626
6892
  ok,
6627
6893
  data,
6628
- _args5 = arguments;
6629
- return _regeneratorRuntime__default["default"].wrap(function (_context5) {
6630
- while (1) switch (_context5.prev = _context5.next) {
6894
+ pollResult,
6895
+ _args6 = arguments;
6896
+ return _regeneratorRuntime__default["default"].wrap(function (_context6) {
6897
+ while (1) switch (_context6.prev = _context6.next) {
6631
6898
  case 0:
6632
- _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;
6899
+ _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;
6633
6900
  fd = new FormData();
6634
6901
  fd.append('file', file);
6635
6902
  fd.append('username', 'admin');
6636
6903
  fd.append('dry_run', String(dryRun));
6637
6904
  if (skipPhases.length) fd.append('skip_phases', skipPhases.join(','));
6638
- _context5.next = 1;
6905
+ _context6.next = 1;
6639
6906
  return request('/restore/', {
6640
6907
  multipart: true,
6641
6908
  body: fd
6642
6909
  });
6643
6910
  case 1:
6644
- _yield$request4 = _context5.sent;
6911
+ _yield$request4 = _context6.sent;
6645
6912
  ok = _yield$request4.ok;
6646
6913
  data = _yield$request4.data;
6647
- if (ok) setOutput(data.output);
6648
- return _context5.abrupt("return", {
6914
+ if (!ok) {
6915
+ _context6.next = 3;
6916
+ break;
6917
+ }
6918
+ setOutput('Restore iniciado. A aguardar conclusão...');
6919
+ _context6.next = 2;
6920
+ return poll(data.clientMutationId);
6921
+ case 2:
6922
+ pollResult = _context6.sent;
6923
+ if (pollResult.success) {
6924
+ setOutput(pollResult.output);
6925
+ } else {
6926
+ setError(pollResult.error);
6927
+ }
6928
+ case 3:
6929
+ setLoading(false);
6930
+ return _context6.abrupt("return", {
6649
6931
  ok: ok,
6650
6932
  data: data
6651
6933
  });
6652
- case 2:
6934
+ case 4:
6653
6935
  case "end":
6654
- return _context5.stop();
6936
+ return _context6.stop();
6655
6937
  }
6656
- }, _callee5);
6938
+ }, _callee6);
6657
6939
  }));
6658
6940
  return _restore.apply(this, arguments);
6659
6941
  }