@zeniai/client-epic-state 5.1.81-betaAK1 → 5.1.81-betaAK2

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.
@@ -1,6 +1,7 @@
1
- import { of } from 'rxjs';
1
+ import { from } from 'rxjs';
2
2
  import { catchError, filter, mergeMap } from 'rxjs/operators';
3
3
  import { updateInvoicingCreditNotes } from '../../../entity/invoicing/creditNote/creditNoteReducer';
4
+ import { openSnackbar } from '../../../entity/snackbar/snackbarReducer';
4
5
  import { createZeniAPIStatus, isSuccessResponse } from '../../../responsePayload';
5
6
  import { localDataToCreateCreditNotePayload, } from './createCreditNotePayload';
6
7
  import { createCreditNoteFailure, createCreditNoteSuccess, submitCreateCreditNote, } from './createCreditNoteReducer';
@@ -15,9 +16,28 @@ export const createCreditNoteEpic = (actions$, state$, zeniAPI) => actions$.pipe
15
16
  return [
16
17
  updateInvoicingCreditNotes([response.data], 'merge'),
17
18
  createCreditNoteSuccess({ creditNoteId: response.data.id }),
19
+ openSnackbar({
20
+ messageSection: 'invoicing_credit_note_saved',
21
+ messageText: 'success',
22
+ type: 'success',
23
+ }),
18
24
  ];
19
25
  }
20
- return of(createCreditNoteFailure(response.status));
21
- }), catchError((error) => of(createCreditNoteFailure(createZeniAPIStatus('Unexpected Error', 'Create credit note REST API call errored out ' +
22
- JSON.stringify(error))))));
26
+ return from([
27
+ createCreditNoteFailure(response.status),
28
+ openSnackbar({
29
+ messageSection: 'invoicing_credit_note_saved',
30
+ messageText: 'failed',
31
+ type: 'error',
32
+ }),
33
+ ]);
34
+ }), catchError((error) => from([
35
+ createCreditNoteFailure(createZeniAPIStatus('Unexpected Error', 'Create credit note REST API call errored out ' +
36
+ JSON.stringify(error))),
37
+ openSnackbar({
38
+ messageSection: 'invoicing_credit_note_saved',
39
+ messageText: 'failed',
40
+ type: 'error',
41
+ }),
42
+ ])));
23
43
  }));
@@ -1,8 +1,9 @@
1
- import { of } from 'rxjs';
1
+ import { from } from 'rxjs';
2
2
  import { catchError, filter, mergeMap } from 'rxjs/operators';
3
3
  import { updateAddresses } from '../../../entity/address/addressReducer';
4
4
  import { extractInvoicingInvoiceAddresses } from '../../../entity/invoicing/invoice/invoicePayload';
5
5
  import { updateInvoices } from '../../../entity/invoicing/invoice/invoiceReducer';
6
+ import { openSnackbar } from '../../../entity/snackbar/snackbarReducer';
6
7
  import { createZeniAPIStatus, isSuccessResponse } from '../../../responsePayload';
7
8
  import { addInvoiceToList } from '../invoiceList/invoiceListReducer';
8
9
  import { createInvoice, createInvoiceFailure, createInvoiceSuccess, } from './createInvoiceReducer';
@@ -22,9 +23,28 @@ export const createInvoiceEpic = (actions$, _state$, zeniAPI) => actions$.pipe(f
22
23
  status: response.data.status,
23
24
  }),
24
25
  createInvoiceSuccess({ invoiceId: response.data.id }),
26
+ openSnackbar({
27
+ messageSection: 'invoicing_invoice_saved',
28
+ messageText: 'success',
29
+ type: 'success',
30
+ }),
25
31
  ];
26
32
  }
27
- return of(createInvoiceFailure(response.status));
28
- }), catchError((error) => of(createInvoiceFailure(createZeniAPIStatus('Unexpected Error', 'Create invoice REST API call errored out ' +
29
- JSON.stringify(error))))));
33
+ return from([
34
+ createInvoiceFailure(response.status),
35
+ openSnackbar({
36
+ messageSection: 'invoicing_invoice_saved',
37
+ messageText: 'failed',
38
+ type: 'error',
39
+ }),
40
+ ]);
41
+ }), catchError((error) => from([
42
+ createInvoiceFailure(createZeniAPIStatus('Unexpected Error', 'Create invoice REST API call errored out ' +
43
+ JSON.stringify(error))),
44
+ openSnackbar({
45
+ messageSection: 'invoicing_invoice_saved',
46
+ messageText: 'failed',
47
+ type: 'error',
48
+ }),
49
+ ])));
30
50
  }));
@@ -1,13 +1,30 @@
1
- import { of } from 'rxjs';
1
+ import { from } from 'rxjs';
2
2
  import { catchError, filter, mergeMap } from 'rxjs/operators';
3
3
  import { updateAddresses } from '../../../entity/address/addressReducer';
4
4
  import { extractInvoicingInvoiceAddresses } from '../../../entity/invoicing/invoice/invoicePayload';
5
5
  import { updateInvoices } from '../../../entity/invoicing/invoice/invoiceReducer';
6
+ import { openSnackbar } from '../../../entity/snackbar/snackbarReducer';
6
7
  import { createZeniAPIStatus, isSuccessResponse } from '../../../responsePayload';
7
8
  import { runInvoicingInvoiceAction, runInvoicingInvoiceActionFailure, runInvoicingInvoiceActionSuccess, updateInvoicingInvoice, } from './invoiceActionReducer';
9
+ /** Snackbar copy per action kind; unlisted kinds run without one. */
10
+ const SNACKBAR_SECTION_BY_KIND = {
11
+ regenerate: 'invoicing_invoice_regenerated',
12
+ 'send-reminder': 'invoicing_invoice_reminder_sent',
13
+ void: 'invoicing_invoice_voided',
14
+ };
8
15
  export const runInvoicingInvoiceActionEpic = (actions$, _state$, zeniAPI) => actions$.pipe(filter((action) => runInvoicingInvoiceAction.match(action) &&
9
16
  action.payload.action !== 'issue-credit-note'), mergeMap((action) => {
10
17
  const { action: kind, body, invoiceId } = action.payload;
18
+ const snackbarSection = SNACKBAR_SECTION_BY_KIND[kind];
19
+ const snackbar = (messageText) => snackbarSection == null
20
+ ? []
21
+ : [
22
+ openSnackbar({
23
+ messageSection: snackbarSection,
24
+ messageText,
25
+ type: messageText === 'success' ? 'success' : 'error',
26
+ }),
27
+ ];
11
28
  const apiUrl = `${zeniAPI.apiEndPoints.invoicingMicroServiceBaseUrl}/1.0/invoices/${encodeURIComponent(invoiceId)}/${kind}`;
12
29
  return zeniAPI
13
30
  .postAndGetJSON(apiUrl, (body ?? {}))
@@ -17,17 +34,24 @@ export const runInvoicingInvoiceActionEpic = (actions$, _state$, zeniAPI) => act
17
34
  updateInvoices([response.data], 'merge'),
18
35
  updateAddresses(extractInvoicingInvoiceAddresses([response.data])),
19
36
  runInvoicingInvoiceActionSuccess({ invoiceId }),
37
+ ...snackbar('success'),
20
38
  ];
21
39
  }
22
- return of(runInvoicingInvoiceActionFailure({
23
- error: response.status,
40
+ return from([
41
+ runInvoicingInvoiceActionFailure({
42
+ error: response.status,
43
+ invoiceId,
44
+ }),
45
+ ...snackbar('failed'),
46
+ ]);
47
+ }), catchError((error) => from([
48
+ runInvoicingInvoiceActionFailure({
49
+ error: createZeniAPIStatus('Unexpected Error', 'Invoice action REST API call errored out ' +
50
+ JSON.stringify(error)),
24
51
  invoiceId,
25
- }));
26
- }), catchError((error) => of(runInvoicingInvoiceActionFailure({
27
- error: createZeniAPIStatus('Unexpected Error', 'Invoice action REST API call errored out ' +
28
- JSON.stringify(error)),
29
- invoiceId,
30
- }))));
52
+ }),
53
+ ...snackbar('failed'),
54
+ ])));
31
55
  }));
32
56
  export const updateInvoicingInvoiceEpic = (actions$, _state$, zeniAPI) => actions$.pipe(filter(updateInvoicingInvoice.match), mergeMap((action) => {
33
57
  const { data, invoiceId } = action.payload;
@@ -40,15 +64,34 @@ export const updateInvoicingInvoiceEpic = (actions$, _state$, zeniAPI) => action
40
64
  updateInvoices([response.data], 'merge'),
41
65
  updateAddresses(extractInvoicingInvoiceAddresses([response.data])),
42
66
  runInvoicingInvoiceActionSuccess({ invoiceId }),
67
+ openSnackbar({
68
+ messageSection: 'invoicing_invoice_saved',
69
+ messageText: 'success',
70
+ type: 'success',
71
+ }),
43
72
  ];
44
73
  }
45
- return of(runInvoicingInvoiceActionFailure({
46
- error: response.status,
74
+ return from([
75
+ runInvoicingInvoiceActionFailure({
76
+ error: response.status,
77
+ invoiceId,
78
+ }),
79
+ openSnackbar({
80
+ messageSection: 'invoicing_invoice_saved',
81
+ messageText: 'failed',
82
+ type: 'error',
83
+ }),
84
+ ]);
85
+ }), catchError((error) => from([
86
+ runInvoicingInvoiceActionFailure({
87
+ error: createZeniAPIStatus('Unexpected Error', 'Invoice update REST API call errored out ' +
88
+ JSON.stringify(error)),
47
89
  invoiceId,
48
- }));
49
- }), catchError((error) => of(runInvoicingInvoiceActionFailure({
50
- error: createZeniAPIStatus('Unexpected Error', 'Invoice update REST API call errored out ' +
51
- JSON.stringify(error)),
52
- invoiceId,
53
- }))));
90
+ }),
91
+ openSnackbar({
92
+ messageSection: 'invoicing_invoice_saved',
93
+ messageText: 'failed',
94
+ type: 'error',
95
+ }),
96
+ ])));
54
97
  }));
@@ -1,5 +1,6 @@
1
- import { of } from 'rxjs';
1
+ import { from, of } from 'rxjs';
2
2
  import { catchError, filter, mergeMap } from 'rxjs/operators';
3
+ import { openSnackbar } from '../../../../entity/snackbar/snackbarReducer';
3
4
  import { createZeniAPIStatus, isSuccessResponse, } from '../../../../responsePayload';
4
5
  import { fetchInvoicingQboSyncHealth, retryInvoicingQboSyncTask, retryInvoicingQboSyncTaskFailure, retryInvoicingQboSyncTaskSuccess, } from '../invoicingQboViewReducer';
5
6
  export const retryInvoicingQboSyncTaskEpic = (actions$, _state$, zeniAPI) => actions$.pipe(filter(retryInvoicingQboSyncTask.match), mergeMap((action) => {
@@ -12,15 +13,33 @@ export const retryInvoicingQboSyncTaskEpic = (actions$, _state$, zeniAPI) => act
12
13
  return of(retryInvoicingQboSyncTaskSuccess({
13
14
  status: response.data?.status ?? '',
14
15
  taskId: response.data?.task_id ?? taskId,
15
- }), fetchInvoicingQboSyncHealth());
16
+ }), fetchInvoicingQboSyncHealth(), openSnackbar({
17
+ messageSection: 'invoicing_qbo_sync_health_retry',
18
+ messageText: 'success',
19
+ type: 'success',
20
+ }));
16
21
  }
17
- return of(retryInvoicingQboSyncTaskFailure({
18
- status: response.status,
22
+ return from([
23
+ retryInvoicingQboSyncTaskFailure({
24
+ status: response.status,
25
+ taskId,
26
+ }),
27
+ openSnackbar({
28
+ messageSection: 'invoicing_qbo_sync_health_retry',
29
+ messageText: 'failed',
30
+ type: 'error',
31
+ }),
32
+ ]);
33
+ }), catchError((error) => from([
34
+ retryInvoicingQboSyncTaskFailure({
35
+ status: createZeniAPIStatus('Unexpected Error', 'Retry QBO sync task REST API call errored out ' +
36
+ JSON.stringify(error)),
19
37
  taskId,
20
- }));
21
- }), catchError((error) => of(retryInvoicingQboSyncTaskFailure({
22
- status: createZeniAPIStatus('Unexpected Error', 'Retry QBO sync task REST API call errored out ' +
23
- JSON.stringify(error)),
24
- taskId,
25
- }))));
38
+ }),
39
+ openSnackbar({
40
+ messageSection: 'invoicing_qbo_sync_health_retry',
41
+ messageText: 'failed',
42
+ type: 'error',
43
+ }),
44
+ ])));
26
45
  }));
@@ -1,5 +1,6 @@
1
- import { of } from 'rxjs';
1
+ import { from, of } from 'rxjs';
2
2
  import { catchError, filter, mergeMap, switchMap } from 'rxjs/operators';
3
+ import { openSnackbar } from '../../../../entity/snackbar/snackbarReducer';
3
4
  import { createZeniAPIStatus, isSuccessResponse, } from '../../../../responsePayload';
4
5
  import { fetchInvoicingQboSyncHealth, startInvoicingQboBackfill, startInvoicingQboBackfillFailure, startInvoicingQboBackfillSuccess, } from '../invoicingQboViewReducer';
5
6
  export const startInvoicingQboBackfillEpic = (actions$, _state$, zeniAPI) => actions$.pipe(filter(startInvoicingQboBackfill.match), switchMap((action) => {
@@ -10,9 +11,27 @@ export const startInvoicingQboBackfillEpic = (actions$, _state$, zeniAPI) => act
10
11
  })
11
12
  .pipe(mergeMap((response) => {
12
13
  if (isSuccessResponse(response)) {
13
- return of(startInvoicingQboBackfillSuccess(), fetchInvoicingQboSyncHealth());
14
+ return of(startInvoicingQboBackfillSuccess(), fetchInvoicingQboSyncHealth(), openSnackbar({
15
+ messageSection: 'invoicing_qbo_backfill',
16
+ messageText: 'success',
17
+ type: 'success',
18
+ }));
14
19
  }
15
- return of(startInvoicingQboBackfillFailure(response.status));
16
- }), catchError((error) => of(startInvoicingQboBackfillFailure(createZeniAPIStatus('Unexpected Error', 'Start QBO backfill REST API call errored out ' +
17
- JSON.stringify(error))))));
20
+ return from([
21
+ startInvoicingQboBackfillFailure(response.status),
22
+ openSnackbar({
23
+ messageSection: 'invoicing_qbo_backfill',
24
+ messageText: 'failed',
25
+ type: 'error',
26
+ }),
27
+ ]);
28
+ }), catchError((error) => from([
29
+ startInvoicingQboBackfillFailure(createZeniAPIStatus('Unexpected Error', 'Start QBO backfill REST API call errored out ' +
30
+ JSON.stringify(error))),
31
+ openSnackbar({
32
+ messageSection: 'invoicing_qbo_backfill',
33
+ messageText: 'failed',
34
+ type: 'error',
35
+ }),
36
+ ])));
18
37
  }));
@@ -1,6 +1,7 @@
1
- import { of } from 'rxjs';
1
+ import { from } from 'rxjs';
2
2
  import { catchError, filter, mergeMap } from 'rxjs/operators';
3
3
  import { updateInvoicingCreditNotes } from '../../../entity/invoicing/creditNote/creditNoteReducer';
4
+ import { openSnackbar } from '../../../entity/snackbar/snackbarReducer';
4
5
  import { createZeniAPIStatus, isSuccessResponse } from '../../../responsePayload';
5
6
  import { fetchInvoiceDetail } from '../invoiceDetail/invoiceDetailReducer';
6
7
  import { localDataToIssueCreditNotePayload, } from './issueCreditNotePayload';
@@ -18,9 +19,28 @@ export const issueCreditNoteEpic = (actions$, state$, zeniAPI) => actions$.pipe(
18
19
  updateInvoicingCreditNotes([response.data], 'merge'),
19
20
  fetchInvoiceDetail({ invoiceId }),
20
21
  issueCreditNoteSuccess({ creditNoteId: response.data.id }),
22
+ openSnackbar({
23
+ messageSection: 'invoicing_credit_note_saved',
24
+ messageText: 'success',
25
+ type: 'success',
26
+ }),
21
27
  ];
22
28
  }
23
- return of(issueCreditNoteFailure(response.status));
24
- }), catchError((error) => of(issueCreditNoteFailure(createZeniAPIStatus('Unexpected Error', 'Issue credit note REST API call errored out ' +
25
- JSON.stringify(error))))));
29
+ return from([
30
+ issueCreditNoteFailure(response.status),
31
+ openSnackbar({
32
+ messageSection: 'invoicing_credit_note_saved',
33
+ messageText: 'failed',
34
+ type: 'error',
35
+ }),
36
+ ]);
37
+ }), catchError((error) => from([
38
+ issueCreditNoteFailure(createZeniAPIStatus('Unexpected Error', 'Issue credit note REST API call errored out ' +
39
+ JSON.stringify(error))),
40
+ openSnackbar({
41
+ messageSection: 'invoicing_credit_note_saved',
42
+ messageText: 'failed',
43
+ type: 'error',
44
+ }),
45
+ ])));
26
46
  }));