@zeniai/client-epic-state 5.2.84 → 5.2.85-beta1KB
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/lib/entity/snackbar/snackbarTypes.d.ts +1 -1
- package/lib/entity/snackbar/snackbarTypes.js +1 -0
- package/lib/entity/transaction/stateTypes/paymentType.d.ts +2 -2
- package/lib/entity/transaction/stateTypes/paymentType.js +9 -1
- package/lib/entity/transaction/stateTypes/printStatus.d.ts +4 -0
- package/lib/entity/transaction/stateTypes/printStatus.js +11 -0
- package/lib/epic.d.ts +5 -1
- package/lib/epic.js +8 -0
- package/lib/esm/entity/snackbar/snackbarTypes.js +1 -0
- package/lib/esm/entity/transaction/stateTypes/paymentType.js +9 -1
- package/lib/esm/entity/transaction/stateTypes/printStatus.js +7 -0
- package/lib/esm/epic.js +8 -0
- package/lib/esm/index.js +5 -2
- package/lib/esm/view/transactionDetail/createTransaction/createTransactionLocalDataHelper.js +157 -0
- package/lib/esm/view/transactionDetail/createTransaction/createTransactionPayload.js +162 -0
- package/lib/esm/view/transactionDetail/createTransaction/createTransactionSelector.js +47 -0
- package/lib/esm/view/transactionDetail/createTransaction/createTransactionState.js +11 -0
- package/lib/esm/view/transactionDetail/createTransaction/epics/createTransactionAttachmentUploadFailureEpic.js +19 -0
- package/lib/esm/view/transactionDetail/createTransaction/epics/createTransactionEpic.js +81 -0
- package/lib/esm/view/transactionDetail/createTransaction/epics/fetchVendorRecommendationsForCreateTransactionEpic.js +53 -0
- package/lib/esm/view/transactionDetail/createTransaction/epics/initializeCreateTransactionLocalDataEpic.js +14 -0
- package/lib/esm/view/transactionDetail/transactionDetailReducer.js +196 -1
- package/lib/index.d.ts +6 -2
- package/lib/index.js +58 -37
- package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.d.ts +1 -1
- package/lib/view/transactionDetail/createTransaction/createTransactionLocalDataHelper.d.ts +56 -0
- package/lib/view/transactionDetail/createTransaction/createTransactionLocalDataHelper.js +172 -0
- package/lib/view/transactionDetail/createTransaction/createTransactionPayload.d.ts +95 -0
- package/lib/view/transactionDetail/createTransaction/createTransactionPayload.js +167 -0
- package/lib/view/transactionDetail/createTransaction/createTransactionSelector.d.ts +44 -0
- package/lib/view/transactionDetail/createTransaction/createTransactionSelector.js +53 -0
- package/lib/view/transactionDetail/createTransaction/createTransactionState.d.ts +82 -0
- package/lib/view/transactionDetail/createTransaction/createTransactionState.js +14 -0
- package/lib/view/transactionDetail/createTransaction/epics/createTransactionAttachmentUploadFailureEpic.d.ts +10 -0
- package/lib/view/transactionDetail/createTransaction/epics/createTransactionAttachmentUploadFailureEpic.js +23 -0
- package/lib/view/transactionDetail/createTransaction/epics/createTransactionEpic.d.ts +9 -0
- package/lib/view/transactionDetail/createTransaction/epics/createTransactionEpic.js +85 -0
- package/lib/view/transactionDetail/createTransaction/epics/fetchVendorRecommendationsForCreateTransactionEpic.d.ts +20 -0
- package/lib/view/transactionDetail/createTransaction/epics/fetchVendorRecommendationsForCreateTransactionEpic.js +57 -0
- package/lib/view/transactionDetail/createTransaction/epics/initializeCreateTransactionLocalDataEpic.d.ts +12 -0
- package/lib/view/transactionDetail/createTransaction/epics/initializeCreateTransactionLocalDataEpic.js +18 -0
- package/lib/view/transactionDetail/transactionDetailReducer.d.ts +39 -1
- package/lib/view/transactionDetail/transactionDetailReducer.js +198 -2
- package/lib/view/transactionDetail/transactionDetailState.d.ts +12 -0
- package/package.json +1 -1
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Amount } from '../../../commonStateTypes/amount';
|
|
2
|
+
import { ID } from '../../../commonStateTypes/common';
|
|
3
|
+
import { RecommendationWithCOT } from '../../../commonStateTypes/recommendationBase';
|
|
4
|
+
import { PaymentType } from '../../../entity/transaction/stateTypes/paymentType';
|
|
5
|
+
import { PrintStatus } from '../../../entity/transaction/stateTypes/printStatus';
|
|
6
|
+
import { TransactionCategory, TransactionType } from '../../../entity/transaction/stateTypes/transactionType';
|
|
7
|
+
import { ZeniDate } from '../../../zeniDayJS';
|
|
8
|
+
/**
|
|
9
|
+
* The transaction types the Create Transaction flow can originate. A narrow subset of
|
|
10
|
+
* TransactionType -- everything else is read-only and arrives via sync.
|
|
11
|
+
*/
|
|
12
|
+
export declare const ALL_CREATABLE_TRANSACTION_TYPES: readonly ["expense", "check", "credit_card_credit", "transfer", "journal_entry"];
|
|
13
|
+
export type CreatableTransactionType = (typeof ALL_CREATABLE_TRANSACTION_TYPES)[number];
|
|
14
|
+
/**
|
|
15
|
+
* The wire shape the create endpoint expects for a check's remit-to address. Deliberately not
|
|
16
|
+
* the CES AddressPayload, which carries `street: string[]` plus address_id/create_time/
|
|
17
|
+
* update_time that the create endpoint does not accept.
|
|
18
|
+
*/
|
|
19
|
+
export interface RemitToAddress {
|
|
20
|
+
city?: string;
|
|
21
|
+
country?: string;
|
|
22
|
+
line1?: string;
|
|
23
|
+
postalCode?: string;
|
|
24
|
+
state?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface CreateTransactionLineLocalData {
|
|
27
|
+
/** Client-side row key only -- never sent. */
|
|
28
|
+
id: string;
|
|
29
|
+
accountName?: string;
|
|
30
|
+
accountQboId?: ID;
|
|
31
|
+
amount?: Amount;
|
|
32
|
+
classId?: ID;
|
|
33
|
+
className?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Tracked per field, not per line. A line can have a hand-picked account and a prefilled
|
|
36
|
+
* class at the same time, and clearing the vendor must undo only the latter.
|
|
37
|
+
*/
|
|
38
|
+
isAccountPreFilled?: boolean;
|
|
39
|
+
isClassPreFilled?: boolean;
|
|
40
|
+
lineDescription?: string;
|
|
41
|
+
/** journal_entry only. */
|
|
42
|
+
postingType?: TransactionCategory;
|
|
43
|
+
projectId?: ID;
|
|
44
|
+
/**
|
|
45
|
+
* Backs the "Recommended" group in the category/class dropdowns. Carries the COT shape the
|
|
46
|
+
* line-table row already expects, with empty cot/reasoning -- chain-of-thought needs an
|
|
47
|
+
* existing transaction, which a create does not have.
|
|
48
|
+
*/
|
|
49
|
+
recommendationsWithCOT?: RecommendationWithCOT[];
|
|
50
|
+
/** journal_entry only -- the per-line name. */
|
|
51
|
+
vendorQboId?: ID;
|
|
52
|
+
}
|
|
53
|
+
export interface CreateTransactionLocalData {
|
|
54
|
+
/** Empty for transfer, which has no lines at all. */
|
|
55
|
+
lines: CreateTransactionLineLocalData[];
|
|
56
|
+
transactionType: CreatableTransactionType;
|
|
57
|
+
/** journal_entry reference number. */
|
|
58
|
+
documentId?: string;
|
|
59
|
+
/** check / credit_card_credit reference number. */
|
|
60
|
+
documentNumber?: string;
|
|
61
|
+
/** transfer */
|
|
62
|
+
fromAccountId?: ID;
|
|
63
|
+
paymentType?: PaymentType;
|
|
64
|
+
/** check only. */
|
|
65
|
+
printStatus?: PrintStatus;
|
|
66
|
+
qboAccountId?: ID;
|
|
67
|
+
/** check only. */
|
|
68
|
+
remitToAddress?: RemitToAddress;
|
|
69
|
+
toAccountId?: ID;
|
|
70
|
+
/** transfer only -- every other type derives its total from the lines. */
|
|
71
|
+
totalAmount?: Amount;
|
|
72
|
+
transactionDate?: ZeniDate;
|
|
73
|
+
transactionMemo?: string;
|
|
74
|
+
vendorId?: ID;
|
|
75
|
+
}
|
|
76
|
+
export type CreateTransactionLocalDataByType = Record<CreatableTransactionType, CreateTransactionLocalData>;
|
|
77
|
+
/**
|
|
78
|
+
* Type-level guarantee that CreatableTransactionType stays a subset of TransactionType. If a
|
|
79
|
+
* value is ever added here that the entity layer does not know about, this line fails to
|
|
80
|
+
* compile rather than failing at the payload boundary.
|
|
81
|
+
*/
|
|
82
|
+
export type CreatableTransactionTypeIsTransactionType = CreatableTransactionType extends TransactionType ? true : never;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ALL_CREATABLE_TRANSACTION_TYPES = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* The transaction types the Create Transaction flow can originate. A narrow subset of
|
|
6
|
+
* TransactionType -- everything else is read-only and arrives via sync.
|
|
7
|
+
*/
|
|
8
|
+
exports.ALL_CREATABLE_TRANSACTION_TYPES = [
|
|
9
|
+
'expense',
|
|
10
|
+
'check',
|
|
11
|
+
'credit_card_credit',
|
|
12
|
+
'transfer',
|
|
13
|
+
'journal_entry',
|
|
14
|
+
];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ActionsObservable } from 'redux-observable';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import { openSnackbar } from '../../../../entity/snackbar/snackbarReducer';
|
|
4
|
+
import { createTransactionAttachmentUploadFailure } from '../../transactionDetailReducer';
|
|
5
|
+
export type ActionType = ReturnType<typeof createTransactionAttachmentUploadFailure> | ReturnType<typeof openSnackbar>;
|
|
6
|
+
/**
|
|
7
|
+
* Attachments upload from the page after the create succeeds, so a failure is reported back here
|
|
8
|
+
* rather than by createTransactionEpic.
|
|
9
|
+
*/
|
|
10
|
+
export declare const createTransactionAttachmentUploadFailureEpic: (actions$: ActionsObservable<ActionType>) => Observable<ActionType>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createTransactionAttachmentUploadFailureEpic = void 0;
|
|
4
|
+
const operators_1 = require("rxjs/operators");
|
|
5
|
+
const snackbarReducer_1 = require("../../../../entity/snackbar/snackbarReducer");
|
|
6
|
+
const transactionDetailReducer_1 = require("../../transactionDetailReducer");
|
|
7
|
+
/**
|
|
8
|
+
* Attachments upload from the page after the create succeeds, so a failure is reported back here
|
|
9
|
+
* rather than by createTransactionEpic.
|
|
10
|
+
*/
|
|
11
|
+
const createTransactionAttachmentUploadFailureEpic = (actions$) => actions$.pipe((0, operators_1.filter)(transactionDetailReducer_1.createTransactionAttachmentUploadFailure.match), (0, operators_1.filter)((action) => action.payload.failedAttachmentFileNames.length > 0), (0, operators_1.map)((action) => (0, snackbarReducer_1.openSnackbar)({
|
|
12
|
+
messageSection: 'missing_receipts_attachment',
|
|
13
|
+
messageText: 'failed',
|
|
14
|
+
type: 'error',
|
|
15
|
+
showStatusIcon: true,
|
|
16
|
+
variables: [
|
|
17
|
+
{
|
|
18
|
+
variableName: '__message__',
|
|
19
|
+
variableValue: ` - ${action.payload.failedAttachmentFileNames.join(', ')},`,
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
})));
|
|
23
|
+
exports.createTransactionAttachmentUploadFailureEpic = createTransactionAttachmentUploadFailureEpic;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ActionsObservable, StateObservable } from 'redux-observable';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import { openSnackbar } from '../../../../entity/snackbar/snackbarReducer';
|
|
4
|
+
import { updateTransaction } from '../../../../entity/transaction/transactionReducer';
|
|
5
|
+
import { RootState } from '../../../../rootStateTypes';
|
|
6
|
+
import { ZeniAPI } from '../../../../zeniAPI';
|
|
7
|
+
import { createTransaction, createTransactionSuccessOrFailure, initializeTransactionDetailLocalData } from '../../transactionDetailReducer';
|
|
8
|
+
export type ActionType = ReturnType<typeof createTransaction> | ReturnType<typeof createTransactionSuccessOrFailure> | ReturnType<typeof initializeTransactionDetailLocalData> | ReturnType<typeof updateTransaction> | ReturnType<typeof openSnackbar>;
|
|
9
|
+
export declare const createTransactionEpic: (actions$: ActionsObservable<ActionType>, state$: StateObservable<RootState>, zeniAPI: ZeniAPI) => Observable<ActionType>;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createTransactionEpic = void 0;
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
5
|
+
const operators_1 = require("rxjs/operators");
|
|
6
|
+
const snackbarReducer_1 = require("../../../../entity/snackbar/snackbarReducer");
|
|
7
|
+
const transactionIDPayload_1 = require("../../../../entity/transaction/payloadTypes/transactionIDPayload");
|
|
8
|
+
const transactionReducer_1 = require("../../../../entity/transaction/transactionReducer");
|
|
9
|
+
const responsePayload_1 = require("../../../../responsePayload");
|
|
10
|
+
const transactionDetailReducer_1 = require("../../transactionDetailReducer");
|
|
11
|
+
const transactionDetailState_1 = require("../../transactionDetailState");
|
|
12
|
+
const createTransactionPayload_1 = require("../createTransactionPayload");
|
|
13
|
+
const createTransactionEpic = (actions$, state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(transactionDetailReducer_1.createTransaction.match),
|
|
14
|
+
// exhaustMap, not mergeMap: a second submit while one is in flight is dropped here rather
|
|
15
|
+
// than relying only on the disabled Save button, so it cannot create a duplicate in QBO.
|
|
16
|
+
(0, operators_1.exhaustMap)((action) => {
|
|
17
|
+
const { transactionType } = action.payload;
|
|
18
|
+
const state = state$.value;
|
|
19
|
+
const localData = state.transactionDetailState.createTransactionsState
|
|
20
|
+
.newTransactionState[transactionType];
|
|
21
|
+
// Deferred so a payload that cannot be built (an id with no QBO id) lands in catchError
|
|
22
|
+
// below as a failure, instead of throwing out of the epic.
|
|
23
|
+
return (0, rxjs_1.defer)(() => zeniAPI.postAndGetJSON(`${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/transactions/manage`, (0, createTransactionPayload_1.prepareCreateTransactionPayload)(state, localData))).pipe((0, operators_1.mergeMap)((response) => {
|
|
24
|
+
const created = (0, responsePayload_1.isSuccessResponse)(response)
|
|
25
|
+
? response.data?.transactions[0]
|
|
26
|
+
: undefined;
|
|
27
|
+
if (created == null) {
|
|
28
|
+
const status = (0, responsePayload_1.isSuccessResponse)(response)
|
|
29
|
+
? (0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', 'Transaction was created but returned no details.')
|
|
30
|
+
: response.status;
|
|
31
|
+
return (0, rxjs_1.from)([
|
|
32
|
+
(0, transactionDetailReducer_1.createTransactionSuccessOrFailure)('Error', undefined, status),
|
|
33
|
+
(0, snackbarReducer_1.openSnackbar)({
|
|
34
|
+
messageSection: 'create_transaction',
|
|
35
|
+
messageText: 'failed',
|
|
36
|
+
type: 'error',
|
|
37
|
+
// This variable is how the server's own message reaches the user. Per-type
|
|
38
|
+
// required fields live in the QBO entity classes, so a rejection comes back as a
|
|
39
|
+
// QBO error with no field name -- the message text is the only useful content.
|
|
40
|
+
variables: [
|
|
41
|
+
{ variableName: '_api-error_', variableValue: status.message },
|
|
42
|
+
],
|
|
43
|
+
}),
|
|
44
|
+
]);
|
|
45
|
+
}
|
|
46
|
+
const newTransactionId = (0, transactionIDPayload_1.toTransactionID)(created);
|
|
47
|
+
// The write is QBO-only: transaction_write_handler.py touches no local storage, and
|
|
48
|
+
// Zeni's mirror is populated by the delta sync that runs afterwards. Refetching here
|
|
49
|
+
// would come back without the new row, so the 200 body is inserted optimistically
|
|
50
|
+
// instead -- the same approach createTransferEntryEpic takes.
|
|
51
|
+
return (0, rxjs_1.from)([
|
|
52
|
+
(0, transactionReducer_1.updateTransaction)((0, transactionDetailState_1.getTransactionDetailKey)(newTransactionId), created),
|
|
53
|
+
// No reset here: it would clear createdTransactionId in the same tick, before the
|
|
54
|
+
// screen renders it to upload pending attachments and navigate. The screen resets
|
|
55
|
+
// the working copy on unmount instead.
|
|
56
|
+
// Before the local-data init: it seeds the detail entry that init writes into.
|
|
57
|
+
(0, transactionDetailReducer_1.createTransactionSuccessOrFailure)('Completed', newTransactionId),
|
|
58
|
+
(0, transactionDetailReducer_1.initializeTransactionDetailLocalData)({
|
|
59
|
+
transactionId: newTransactionId,
|
|
60
|
+
vendorId: created.vendor_id ?? undefined,
|
|
61
|
+
}),
|
|
62
|
+
(0, snackbarReducer_1.openSnackbar)({
|
|
63
|
+
messageSection: 'create_transaction',
|
|
64
|
+
messageText: 'success',
|
|
65
|
+
type: 'success',
|
|
66
|
+
}),
|
|
67
|
+
]);
|
|
68
|
+
}), (0, operators_1.catchError)((error) => {
|
|
69
|
+
const message = error instanceof createTransactionPayload_1.UnresolvedCreateTransactionIdError
|
|
70
|
+
? error.message
|
|
71
|
+
: JSON.stringify(error);
|
|
72
|
+
return (0, rxjs_1.from)([
|
|
73
|
+
(0, transactionDetailReducer_1.createTransactionSuccessOrFailure)('Error', undefined, (0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', `Create Transaction REST API call errored out ${message}`)),
|
|
74
|
+
(0, snackbarReducer_1.openSnackbar)({
|
|
75
|
+
messageSection: 'create_transaction',
|
|
76
|
+
messageText: 'failed',
|
|
77
|
+
type: 'error',
|
|
78
|
+
variables: [
|
|
79
|
+
{ variableName: '_api-error_', variableValue: message },
|
|
80
|
+
],
|
|
81
|
+
}),
|
|
82
|
+
]);
|
|
83
|
+
}));
|
|
84
|
+
}));
|
|
85
|
+
exports.createTransactionEpic = createTransactionEpic;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ActionsObservable, StateObservable } from 'redux-observable';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import { RootState } from '../../../../rootStateTypes';
|
|
4
|
+
import { fetchRecommendationByEntityId, fetchRecommendationByEntityName, indicateReadyToInitializeRecommendation } from '../../../recommendation/recommendationReducer';
|
|
5
|
+
import { clearRecommendationsForCreateTransactionLines, fetchVendorRecommendationsForCreateTransaction, setRecommendationsForCreateTransactionLines } from '../../transactionDetailReducer';
|
|
6
|
+
export type ActionType = ReturnType<typeof fetchVendorRecommendationsForCreateTransaction> | ReturnType<typeof setRecommendationsForCreateTransactionLines> | ReturnType<typeof clearRecommendationsForCreateTransactionLines> | ReturnType<typeof fetchRecommendationByEntityId> | ReturnType<typeof fetchRecommendationByEntityName> | ReturnType<typeof indicateReadyToInitializeRecommendation>;
|
|
7
|
+
/**
|
|
8
|
+
* On vendor select, populates the category/class dropdowns from that vendor's recommendations.
|
|
9
|
+
*
|
|
10
|
+
* Deliberately NOT the detail page's fetchEntityRecommendationsForLineUpdate: that one sends
|
|
11
|
+
* transaction_id / line_ids and writes into transactionDetailById[key], which no-ops when the
|
|
12
|
+
* entry does not exist. A transaction being created has neither.
|
|
13
|
+
*
|
|
14
|
+
* Two differences from the reimbursement epic this is modelled on:
|
|
15
|
+
* 1. the wait filters on the matching entityIdOrName before take(1), so an unrelated
|
|
16
|
+
* recommendation landing first cannot satisfy this request, and
|
|
17
|
+
* 2. switchMap, so changing the vendor again cancels the earlier wait rather than letting a
|
|
18
|
+
* stale result overwrite the newer vendor's prefill.
|
|
19
|
+
*/
|
|
20
|
+
export declare const fetchVendorRecommendationsForCreateTransactionEpic: (actions$: ActionsObservable<ActionType>, state$: StateObservable<RootState>) => Observable<ActionType>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchVendorRecommendationsForCreateTransactionEpic = void 0;
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
5
|
+
const operators_1 = require("rxjs/operators");
|
|
6
|
+
const tenantSelector_1 = require("../../../../entity/tenant/tenantSelector");
|
|
7
|
+
const recommendationReducer_1 = require("../../../recommendation/recommendationReducer");
|
|
8
|
+
const recommendationSelector_1 = require("../../../recommendation/recommendationSelector");
|
|
9
|
+
const transactionDetailReducer_1 = require("../../transactionDetailReducer");
|
|
10
|
+
/**
|
|
11
|
+
* The entity-level recommendation fetch, keyed by whatever identifier the endpoint can resolve.
|
|
12
|
+
*
|
|
13
|
+
* A vendor that has not synced to QBO carries `qboId === name`; the id endpoint has nothing to
|
|
14
|
+
* look up in that case, so the by-name variant is used instead.
|
|
15
|
+
*/
|
|
16
|
+
const toEntityIdOrName = (entity) => entity.qboId && entity.qboId !== entity.name ? entity.qboId : entity.name;
|
|
17
|
+
const isUnsyncedVendor = (entity) => !entity.qboId || entity.qboId === entity.name;
|
|
18
|
+
/**
|
|
19
|
+
* On vendor select, populates the category/class dropdowns from that vendor's recommendations.
|
|
20
|
+
*
|
|
21
|
+
* Deliberately NOT the detail page's fetchEntityRecommendationsForLineUpdate: that one sends
|
|
22
|
+
* transaction_id / line_ids and writes into transactionDetailById[key], which no-ops when the
|
|
23
|
+
* entry does not exist. A transaction being created has neither.
|
|
24
|
+
*
|
|
25
|
+
* Two differences from the reimbursement epic this is modelled on:
|
|
26
|
+
* 1. the wait filters on the matching entityIdOrName before take(1), so an unrelated
|
|
27
|
+
* recommendation landing first cannot satisfy this request, and
|
|
28
|
+
* 2. switchMap, so changing the vendor again cancels the earlier wait rather than letting a
|
|
29
|
+
* stale result overwrite the newer vendor's prefill.
|
|
30
|
+
*/
|
|
31
|
+
const fetchVendorRecommendationsForCreateTransactionEpic = (actions$, state$) => actions$.pipe((0, operators_1.filter)(transactionDetailReducer_1.fetchVendorRecommendationsForCreateTransaction.match), (0, operators_1.switchMap)((action) => {
|
|
32
|
+
const { transactionType, entity, lineIds } = action.payload;
|
|
33
|
+
if (entity == null) {
|
|
34
|
+
return (0, rxjs_1.of)((0, transactionDetailReducer_1.clearRecommendationsForCreateTransactionLines)(transactionType, lineIds));
|
|
35
|
+
}
|
|
36
|
+
const entityIdOrName = toEntityIdOrName(entity);
|
|
37
|
+
const state = state$.value;
|
|
38
|
+
const isAccountingClassesEnabled = (0, tenantSelector_1.getIsAccountingClassesEnabled)(state);
|
|
39
|
+
const cached = (0, recommendationSelector_1.getRecommendationsForEntity)(state, entityIdOrName, 'vendor');
|
|
40
|
+
// Cache hit: apply straight away, no request and no wait.
|
|
41
|
+
if (cached.fetchState === 'Completed') {
|
|
42
|
+
return (0, rxjs_1.of)((0, transactionDetailReducer_1.setRecommendationsForCreateTransactionLines)(transactionType, lineIds, cached.recommendations ?? [], isAccountingClassesEnabled));
|
|
43
|
+
}
|
|
44
|
+
const waitThenApply = actions$.pipe((0, operators_1.filter)(recommendationReducer_1.indicateReadyToInitializeRecommendation.match), (0, operators_1.filter)((ready) => ready.payload.entityType === 'vendor' &&
|
|
45
|
+
ready.payload.entityIdOrName === entityIdOrName), (0, operators_1.take)(1), // don't listen forever! IMPORTANT!
|
|
46
|
+
(0, operators_1.mergeMap)(() => (0, rxjs_1.from)([
|
|
47
|
+
(0, transactionDetailReducer_1.setRecommendationsForCreateTransactionLines)(transactionType, lineIds, (0, recommendationSelector_1.getRecommendationsForEntity)(state$.value, entityIdOrName, 'vendor').recommendations ?? [], (0, tenantSelector_1.getIsAccountingClassesEnabled)(state$.value)),
|
|
48
|
+
])));
|
|
49
|
+
// A fetch already in flight needs no second request, only the wait.
|
|
50
|
+
if (cached.fetchState === 'In-Progress') {
|
|
51
|
+
return waitThenApply;
|
|
52
|
+
}
|
|
53
|
+
return (0, rxjs_1.concat)((0, rxjs_1.of)((isUnsyncedVendor(entity)
|
|
54
|
+
? (0, recommendationReducer_1.fetchRecommendationByEntityName)(entityIdOrName, 'vendor')
|
|
55
|
+
: (0, recommendationReducer_1.fetchRecommendationByEntityId)(entityIdOrName, 'vendor'))), waitThenApply);
|
|
56
|
+
}));
|
|
57
|
+
exports.fetchVendorRecommendationsForCreateTransactionEpic = fetchVendorRecommendationsForCreateTransactionEpic;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ActionsObservable } from 'redux-observable';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import { initializeCreateTransactionLocalData, updateCreateTransactionLocalData } from '../../transactionDetailReducer';
|
|
4
|
+
export type ActionType = ReturnType<typeof initializeCreateTransactionLocalData> | ReturnType<typeof updateCreateTransactionLocalData>;
|
|
5
|
+
/**
|
|
6
|
+
* Seeds the working copy when the Create form opens: today's date, the default line set for the
|
|
7
|
+
* type, and a check's mandatory payment_type.
|
|
8
|
+
*
|
|
9
|
+
* Mirrors the `else` branch of initializeScheduleDetailLocalDataEpic -- a create has no
|
|
10
|
+
* existing entity to read from, so there is nothing to merge, only defaults to apply.
|
|
11
|
+
*/
|
|
12
|
+
export declare const initializeCreateTransactionLocalDataEpic: (actions$: ActionsObservable<ActionType>) => Observable<ActionType>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initializeCreateTransactionLocalDataEpic = void 0;
|
|
4
|
+
const operators_1 = require("rxjs/operators");
|
|
5
|
+
const transactionDetailReducer_1 = require("../../transactionDetailReducer");
|
|
6
|
+
const createTransactionLocalDataHelper_1 = require("../createTransactionLocalDataHelper");
|
|
7
|
+
/**
|
|
8
|
+
* Seeds the working copy when the Create form opens: today's date, the default line set for the
|
|
9
|
+
* type, and a check's mandatory payment_type.
|
|
10
|
+
*
|
|
11
|
+
* Mirrors the `else` branch of initializeScheduleDetailLocalDataEpic -- a create has no
|
|
12
|
+
* existing entity to read from, so there is nothing to merge, only defaults to apply.
|
|
13
|
+
*/
|
|
14
|
+
const initializeCreateTransactionLocalDataEpic = (actions$) => actions$.pipe((0, operators_1.filter)(transactionDetailReducer_1.initializeCreateTransactionLocalData.match), (0, operators_1.map)((action) => {
|
|
15
|
+
const { transactionType } = action.payload;
|
|
16
|
+
return (0, transactionDetailReducer_1.updateCreateTransactionLocalData)(transactionType, (0, createTransactionLocalDataHelper_1.getSeededCreateTransactionLocalData)(transactionType));
|
|
17
|
+
}));
|
|
18
|
+
exports.initializeCreateTransactionLocalDataEpic = initializeCreateTransactionLocalDataEpic;
|
|
@@ -9,6 +9,7 @@ import { TransactionID } from '../../entity/transaction/stateTypes/transactionID
|
|
|
9
9
|
import { SupportedTransaction, SupportedTransactionPayload } from '../../entity/transaction/transactionState';
|
|
10
10
|
import { ZeniAPIStatus } from '../../responsePayload';
|
|
11
11
|
import { UncategorizedAccounts } from '../accountList/accountListSelector';
|
|
12
|
+
import { CreateTransactionLineLocalData, CreateTransactionLocalData } from './createTransaction/createTransactionState';
|
|
12
13
|
import { TransactionDetailState, TransactionSaveUpdates } from './transactionDetailState';
|
|
13
14
|
import { TransactionDetailLineItemData, TransactionDetailLocalData, TransactionVendorUpdates } from './transactionDetailTypes';
|
|
14
15
|
export declare const initialState: TransactionDetailState;
|
|
@@ -176,6 +177,43 @@ export declare const downloadAccountingProviderAttachment: import("@reduxjs/tool
|
|
|
176
177
|
}, "transactionDetail/deleteSplitLine", never, never>, toggleSplitEditMode: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[transactionId: TransactionID, editMode: boolean], {
|
|
177
178
|
transactionId: TransactionID;
|
|
178
179
|
editMode: boolean;
|
|
179
|
-
}, "transactionDetail/toggleSplitEditMode", never, never
|
|
180
|
+
}, "transactionDetail/toggleSplitEditMode", never, never>, initializeCreateTransactionLocalData: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[transactionType: "expense" | "check" | "credit_card_credit" | "transfer" | "journal_entry"], {
|
|
181
|
+
transactionType: "expense" | "check" | "credit_card_credit" | "transfer" | "journal_entry";
|
|
182
|
+
}, "transactionDetail/initializeCreateTransactionLocalData", never, never>, updateCreateTransactionLocalData: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[transactionType: "expense" | "check" | "credit_card_credit" | "transfer" | "journal_entry", localData: Partial<CreateTransactionLocalData>], {
|
|
183
|
+
transactionType: "expense" | "check" | "credit_card_credit" | "transfer" | "journal_entry";
|
|
184
|
+
localData: Partial<CreateTransactionLocalData>;
|
|
185
|
+
}, "transactionDetail/updateCreateTransactionLocalData", never, never>, updateCreateTransactionLineLocalData: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[transactionType: "expense" | "check" | "credit_card_credit" | "transfer" | "journal_entry", lineId: string, lineUpdates: Partial<CreateTransactionLineLocalData>], {
|
|
186
|
+
transactionType: "expense" | "check" | "credit_card_credit" | "transfer" | "journal_entry";
|
|
187
|
+
lineId: string;
|
|
188
|
+
lineUpdates: Partial<CreateTransactionLineLocalData>;
|
|
189
|
+
}, "transactionDetail/updateCreateTransactionLineLocalData", never, never>, addCreateTransactionLine: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[transactionType: "expense" | "check" | "credit_card_credit" | "transfer" | "journal_entry", line?: Partial<CreateTransactionLineLocalData> | undefined], {
|
|
190
|
+
transactionType: "expense" | "check" | "credit_card_credit" | "transfer" | "journal_entry";
|
|
191
|
+
line: Partial<CreateTransactionLineLocalData> | undefined;
|
|
192
|
+
}, "transactionDetail/addCreateTransactionLine", never, never>, removeCreateTransactionLine: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[transactionType: "expense" | "check" | "credit_card_credit" | "transfer" | "journal_entry", lineId: string], {
|
|
193
|
+
transactionType: "expense" | "check" | "credit_card_credit" | "transfer" | "journal_entry";
|
|
194
|
+
lineId: string;
|
|
195
|
+
}, "transactionDetail/removeCreateTransactionLine", never, never>, resetCreateTransactionLocalData: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[transactionType: "expense" | "check" | "credit_card_credit" | "transfer" | "journal_entry"], {
|
|
196
|
+
transactionType: "expense" | "check" | "credit_card_credit" | "transfer" | "journal_entry";
|
|
197
|
+
}, "transactionDetail/resetCreateTransactionLocalData", never, never>, createTransaction: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[transactionType: "expense" | "check" | "credit_card_credit" | "transfer" | "journal_entry"], {
|
|
198
|
+
transactionType: "expense" | "check" | "credit_card_credit" | "transfer" | "journal_entry";
|
|
199
|
+
}, "transactionDetail/createTransaction", never, never>, createTransactionSuccessOrFailure: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[fetchState: FetchState, createdTransactionId?: TransactionID | undefined, error?: ZeniAPIStatus<Record<string, unknown>> | undefined], {
|
|
200
|
+
fetchState: FetchState;
|
|
201
|
+
createdTransactionId: TransactionID | undefined;
|
|
202
|
+
error: ZeniAPIStatus<Record<string, unknown>> | undefined;
|
|
203
|
+
}, "transactionDetail/createTransactionSuccessOrFailure", never, never>, setRecommendationsForCreateTransactionLines: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[transactionType: "expense" | "check" | "credit_card_credit" | "transfer" | "journal_entry", lineIds: string[], recommendations: Recommendation[], isAccountingClassesEnabled: boolean], {
|
|
204
|
+
transactionType: "expense" | "check" | "credit_card_credit" | "transfer" | "journal_entry";
|
|
205
|
+
lineIds: string[];
|
|
206
|
+
recommendations: Recommendation[];
|
|
207
|
+
isAccountingClassesEnabled: boolean;
|
|
208
|
+
}, "transactionDetail/setRecommendationsForCreateTransactionLines", never, never>, clearRecommendationsForCreateTransactionLines: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[transactionType: "expense" | "check" | "credit_card_credit" | "transfer" | "journal_entry", lineIds: string[]], {
|
|
209
|
+
transactionType: "expense" | "check" | "credit_card_credit" | "transfer" | "journal_entry";
|
|
210
|
+
lineIds: string[];
|
|
211
|
+
}, "transactionDetail/clearRecommendationsForCreateTransactionLines", never, never>, fetchVendorRecommendationsForCreateTransaction: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[transactionType: "expense" | "check" | "credit_card_credit" | "transfer" | "journal_entry", lineIds: string[], entity?: Entity | undefined], {
|
|
212
|
+
transactionType: "expense" | "check" | "credit_card_credit" | "transfer" | "journal_entry";
|
|
213
|
+
lineIds: string[];
|
|
214
|
+
entity: Entity | undefined;
|
|
215
|
+
}, "transactionDetail/fetchVendorRecommendationsForCreateTransaction", never, never>, createTransactionAttachmentUploadFailure: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[failedAttachmentFileNames: string[]], {
|
|
216
|
+
failedAttachmentFileNames: string[];
|
|
217
|
+
}, "transactionDetail/createTransactionAttachmentUploadFailure", never, never>;
|
|
180
218
|
declare const _default: import("redux").Reducer<TransactionDetailState>;
|
|
181
219
|
export default _default;
|