@zeniai/client-epic-state 4.19.99-betaRD3 → 4.19.99-betaRD5

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,9 +1,10 @@
1
1
  import { AiAccountantCustomerPayload, AiAccountantJobPayload } from './aiAccountantCustomerPayload';
2
2
  import { AiAccountantCustomerState } from './aiAccountantCustomerState';
3
3
  export declare const initialAiAccountantCustomerState: AiAccountantCustomerState;
4
- export declare const clearAllAiAccountantCustomers: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"aiAccountantCustomer/clearAllAiAccountantCustomers">, updateAiAccountantCustomers: import("@reduxjs/toolkit").ActionCreatorWithPayload<AiAccountantCustomerPayload[], "aiAccountantCustomer/updateAiAccountantCustomers">, updateAiAccountantCustomer: import("@reduxjs/toolkit").ActionCreatorWithPayload<AiAccountantCustomerPayload, "aiAccountantCustomer/updateAiAccountantCustomer">, updateAiAccountantJobs: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[tenantId: string, jobs: AiAccountantJobPayload[]], {
4
+ export declare const clearAllAiAccountantCustomers: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"aiAccountantCustomer/clearAllAiAccountantCustomers">, updateAiAccountantCustomers: import("@reduxjs/toolkit").ActionCreatorWithPayload<AiAccountantCustomerPayload[], "aiAccountantCustomer/updateAiAccountantCustomers">, updateAiAccountantCustomer: import("@reduxjs/toolkit").ActionCreatorWithPayload<AiAccountantCustomerPayload, "aiAccountantCustomer/updateAiAccountantCustomer">, updateAiAccountantJobs: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[tenantId: string, jobs: AiAccountantJobPayload[], append?: boolean | undefined], {
5
5
  tenantId: string;
6
6
  jobs: AiAccountantJobPayload[];
7
+ append: boolean;
7
8
  }, "aiAccountantCustomer/updateAiAccountantJobs", never, never>;
8
9
  declare const _default: import("redux").Reducer<AiAccountantCustomerState>;
9
10
  export default _default;
@@ -24,11 +24,20 @@ const aiAccountantCustomer = (0, toolkit_1.createSlice)({
24
24
  },
25
25
  updateAiAccountantJobs: {
26
26
  reducer(draft, action) {
27
- draft.jobsByTenantId[action.payload.tenantId] =
28
- action.payload.jobs.map(aiAccountantCustomerPayload_1.toAiAccountantJob);
27
+ const mappedJobs = action.payload.jobs.map(aiAccountantCustomerPayload_1.toAiAccountantJob);
28
+ if (action.payload.append) {
29
+ const existing = draft.jobsByTenantId[action.payload.tenantId] ?? [];
30
+ draft.jobsByTenantId[action.payload.tenantId] = [
31
+ ...existing,
32
+ ...mappedJobs,
33
+ ];
34
+ }
35
+ else {
36
+ draft.jobsByTenantId[action.payload.tenantId] = mappedJobs;
37
+ }
29
38
  },
30
- prepare(tenantId, jobs) {
31
- return { payload: { tenantId, jobs } };
39
+ prepare(tenantId, jobs, append = false) {
40
+ return { payload: { tenantId, jobs, append } };
32
41
  },
33
42
  },
34
43
  clearAllAiAccountantCustomers(draft) {
@@ -20,11 +20,20 @@ const aiAccountantCustomer = createSlice({
20
20
  },
21
21
  updateAiAccountantJobs: {
22
22
  reducer(draft, action) {
23
- draft.jobsByTenantId[action.payload.tenantId] =
24
- action.payload.jobs.map(toAiAccountantJob);
23
+ const mappedJobs = action.payload.jobs.map(toAiAccountantJob);
24
+ if (action.payload.append) {
25
+ const existing = draft.jobsByTenantId[action.payload.tenantId] ?? [];
26
+ draft.jobsByTenantId[action.payload.tenantId] = [
27
+ ...existing,
28
+ ...mappedJobs,
29
+ ];
30
+ }
31
+ else {
32
+ draft.jobsByTenantId[action.payload.tenantId] = mappedJobs;
33
+ }
25
34
  },
26
- prepare(tenantId, jobs) {
27
- return { payload: { tenantId, jobs } };
35
+ prepare(tenantId, jobs, append = false) {
36
+ return { payload: { tenantId, jobs, append } };
28
37
  },
29
38
  },
30
39
  clearAllAiAccountantCustomers(draft) {
@@ -38,8 +38,8 @@ const aiAccountantView = createSlice({
38
38
  customerView.jobsFetchStatus = { fetchState: 'In-Progress' };
39
39
  }
40
40
  },
41
- prepare(tenantId) {
42
- return { payload: { tenantId } };
41
+ prepare(tenantId, fetchNextPage) {
42
+ return { payload: { tenantId, fetchNextPage: fetchNextPage ?? false } };
43
43
  },
44
44
  },
45
45
  updateAiAccountantJobs: {
@@ -47,10 +47,11 @@ const aiAccountantView = createSlice({
47
47
  const customerView = draft.customersByTenantId[action.payload.tenantId];
48
48
  if (customerView != null) {
49
49
  customerView.jobsFetchStatus = { fetchState: 'Completed' };
50
+ customerView.jobsPageToken = action.payload.nextPageToken;
50
51
  }
51
52
  },
52
- prepare(tenantId) {
53
- return { payload: { tenantId } };
53
+ prepare(tenantId, nextPageToken) {
54
+ return { payload: { tenantId, nextPageToken: nextPageToken ?? null } };
54
55
  },
55
56
  },
56
57
  updateAiAccountantJobsFailure(draft, action) {
@@ -138,6 +139,7 @@ const toCustomersByTenantId = (customers) => {
138
139
  result[payload.tenant_id] = {
139
140
  cancelOnboardingStatus: { fetchState: 'Not-Started' },
140
141
  jobsFetchStatus: { fetchState: 'Not-Started' },
142
+ jobsPageToken: null,
141
143
  tenantId: payload.tenant_id,
142
144
  };
143
145
  }
@@ -1,5 +1,6 @@
1
- import { from, of } from 'rxjs';
1
+ import { from } 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 { cancelAiAccountantOnboarding, cancelAiAccountantOnboardingFailure, cancelAiAccountantOnboardingSuccess, fetchAiAccountantCustomers, } from '../aiAccountantViewReducer';
5
6
  export const cancelAiAccountantOnboardingEpic = (actions$, _, zeniAPI) => actions$.pipe(filter(cancelAiAccountantOnboarding.match), mergeMap((action) => {
@@ -16,11 +17,30 @@ export const cancelAiAccountantOnboardingEpic = (actions$, _, zeniAPI) => action
16
17
  return from([
17
18
  cancelAiAccountantOnboardingSuccess(tenantId),
18
19
  fetchAiAccountantCustomers(),
20
+ openSnackbar({
21
+ messageSection: 'common',
22
+ messageText: 'success',
23
+ type: 'success',
24
+ }),
19
25
  ]);
20
26
  }
21
27
  else {
22
- return of(cancelAiAccountantOnboardingFailure(tenantId, response.status));
28
+ return from([
29
+ cancelAiAccountantOnboardingFailure(tenantId, response.status),
30
+ openSnackbar({
31
+ messageSection: 'common',
32
+ messageText: 'failed',
33
+ type: 'error',
34
+ }),
35
+ ]);
23
36
  }
24
- }), catchError((error) => of(cancelAiAccountantOnboardingFailure(tenantId, createZeniAPIStatus('Unexpected error', 'AI Accountant cancel onboarding failed: ' +
25
- JSON.stringify(error))))));
37
+ }), catchError((error) => from([
38
+ cancelAiAccountantOnboardingFailure(tenantId, createZeniAPIStatus('Unexpected error', 'AI Accountant cancel onboarding failed: ' +
39
+ JSON.stringify(error))),
40
+ openSnackbar({
41
+ messageSection: 'common',
42
+ messageText: 'failed',
43
+ type: 'error',
44
+ }),
45
+ ])));
26
46
  }));
@@ -3,14 +3,21 @@ import { catchError, filter, mergeMap, switchMap } from 'rxjs/operators';
3
3
  import { updateAiAccountantJobs as updateAiAccountantJobEntities } from '../../../entity/aiAccountantCustomer/aiAccountantCustomerReducer';
4
4
  import { updateAllUsers } from '../../../entity/user/userReducer';
5
5
  import { createZeniAPIStatus, isSuccessResponse } from '../../../responsePayload';
6
- import { fetchAiAccountantJobs, updateAiAccountantJobsFailure, } from '../aiAccountantViewReducer';
7
- export const fetchAiAccountantJobsEpic = (actions$, _, zeniAPI) => actions$.pipe(filter(fetchAiAccountantJobs.match), switchMap((action) => {
8
- const { tenantId } = action.payload;
6
+ import { fetchAiAccountantJobs, updateAiAccountantJobs, updateAiAccountantJobsFailure, } from '../aiAccountantViewReducer';
7
+ export const fetchAiAccountantJobsEpic = (actions$, state$, zeniAPI) => actions$.pipe(filter(fetchAiAccountantJobs.match), switchMap((action) => {
8
+ const { tenantId, fetchNextPage } = action.payload;
9
+ const rootState = state$.value;
10
+ const customerView = rootState.aiAccountantViewState.customersByTenantId[tenantId];
11
+ const pageToken = fetchNextPage && customerView?.jobsPageToken != null
12
+ ? customerView.jobsPageToken
13
+ : null;
9
14
  const params = new URLSearchParams({
10
- page: '1',
11
15
  limit: '50',
12
16
  tenant_id: tenantId,
13
17
  });
18
+ if (pageToken != null) {
19
+ params.set('page_token', pageToken);
20
+ }
14
21
  const base = `${zeniAPI.apiEndPoints.tenantMicroServiceBaseUrl}/1.0/cockpit-panels`;
15
22
  const url = `${base}/ai-accountant/jobs?${params.toString()}`;
16
23
  return zeniAPI
@@ -19,9 +26,11 @@ export const fetchAiAccountantJobsEpic = (actions$, _, zeniAPI) => actions$.pipe
19
26
  if (isSuccessResponse(response)) {
20
27
  const jobs = response.data?.jobs ?? [];
21
28
  const users = response.data?.users ?? [];
29
+ const nextPageToken = response.data?.next_page_token ?? null;
22
30
  return from([
23
31
  updateAllUsers({ users }),
24
- updateAiAccountantJobEntities(tenantId, jobs),
32
+ updateAiAccountantJobEntities(tenantId, jobs, fetchNextPage),
33
+ updateAiAccountantJobs(tenantId, nextPageToken),
25
34
  ]);
26
35
  }
27
36
  else {
@@ -32,6 +41,7 @@ export const fetchAiAccountantJobsEpic = (actions$, _, zeniAPI) => actions$.pipe
32
41
  }
33
42
  }), catchError((error) => of(updateAiAccountantJobsFailure({
34
43
  tenantId,
35
- error: createZeniAPIStatus('Unexpected error', 'AI Accountant jobs fetch failed: ' + JSON.stringify(error)),
44
+ error: createZeniAPIStatus('Unexpected error', 'AI Accountant jobs fetch failed: ' +
45
+ JSON.stringify(error)),
36
46
  }))));
37
47
  }));
@@ -1,5 +1,6 @@
1
- import { from, of } from 'rxjs';
1
+ import { from } 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 { fetchAiAccountantCustomers, triggerAiAccountantJob, triggerAiAccountantJobFailure, triggerAiAccountantJobSuccess, } from '../aiAccountantViewReducer';
5
6
  export const triggerAiAccountantJobEpic = (actions$, state$, zeniAPI) => actions$.pipe(filter(triggerAiAccountantJob.match), mergeMap((action) => {
@@ -29,11 +30,30 @@ export const triggerAiAccountantJobEpic = (actions$, state$, zeniAPI) => actions
29
30
  return from([
30
31
  triggerAiAccountantJobSuccess(),
31
32
  fetchAiAccountantCustomers(),
33
+ openSnackbar({
34
+ messageSection: 'common',
35
+ messageText: 'success',
36
+ type: 'success',
37
+ }),
32
38
  ]);
33
39
  }
34
40
  else {
35
- return of(triggerAiAccountantJobFailure(response.status));
41
+ return from([
42
+ triggerAiAccountantJobFailure(response.status),
43
+ openSnackbar({
44
+ messageSection: 'common',
45
+ messageText: 'failed',
46
+ type: 'error',
47
+ }),
48
+ ]);
36
49
  }
37
- }), catchError((error) => of(triggerAiAccountantJobFailure(createZeniAPIStatus('Unexpected error', 'AI Accountant trigger job failed: ' +
38
- JSON.stringify(error))))));
50
+ }), catchError((error) => from([
51
+ triggerAiAccountantJobFailure(createZeniAPIStatus('Unexpected error', 'AI Accountant trigger job failed: ' +
52
+ JSON.stringify(error))),
53
+ openSnackbar({
54
+ messageSection: 'common',
55
+ messageText: 'failed',
56
+ type: 'error',
57
+ }),
58
+ ])));
39
59
  }));