@zeniai/client-epic-state 5.2.91 → 5.2.93

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.
Files changed (49) hide show
  1. package/lib/entity/snackbar/snackbarTypes.d.ts +1 -1
  2. package/lib/entity/snackbar/snackbarTypes.js +1 -0
  3. package/lib/entity/transaction/stateTypes/paymentType.d.ts +2 -2
  4. package/lib/entity/transaction/stateTypes/paymentType.js +9 -1
  5. package/lib/entity/transaction/stateTypes/printStatus.d.ts +4 -0
  6. package/lib/entity/transaction/stateTypes/printStatus.js +11 -0
  7. package/lib/epic.d.ts +5 -1
  8. package/lib/epic.js +8 -0
  9. package/lib/esm/entity/snackbar/snackbarTypes.js +1 -0
  10. package/lib/esm/entity/transaction/stateTypes/paymentType.js +9 -1
  11. package/lib/esm/entity/transaction/stateTypes/printStatus.js +7 -0
  12. package/lib/esm/epic.js +8 -0
  13. package/lib/esm/index.js +4 -2
  14. package/lib/esm/view/invoicing/invoicingOverview/invoicingOverviewPayload.js +3 -0
  15. package/lib/esm/view/transactionDetail/createTransaction/createTransactionLocalDataHelper.js +157 -0
  16. package/lib/esm/view/transactionDetail/createTransaction/createTransactionPayload.js +164 -0
  17. package/lib/esm/view/transactionDetail/createTransaction/createTransactionSelector.js +47 -0
  18. package/lib/esm/view/transactionDetail/createTransaction/createTransactionState.js +11 -0
  19. package/lib/esm/view/transactionDetail/createTransaction/epics/createTransactionAttachmentUploadFailureEpic.js +19 -0
  20. package/lib/esm/view/transactionDetail/createTransaction/epics/createTransactionEpic.js +81 -0
  21. package/lib/esm/view/transactionDetail/createTransaction/epics/fetchVendorRecommendationsForCreateTransactionEpic.js +53 -0
  22. package/lib/esm/view/transactionDetail/createTransaction/epics/initializeCreateTransactionLocalDataEpic.js +10 -0
  23. package/lib/esm/view/transactionDetail/transactionDetailReducer.js +196 -1
  24. package/lib/index.d.ts +6 -2
  25. package/lib/index.js +56 -37
  26. package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.d.ts +1 -1
  27. package/lib/view/invoicing/invoicingOverview/invoicingOverviewPayload.d.ts +7 -0
  28. package/lib/view/invoicing/invoicingOverview/invoicingOverviewPayload.js +3 -0
  29. package/lib/view/invoicing/invoicingOverview/invoicingOverviewState.d.ts +4 -0
  30. package/lib/view/transactionDetail/createTransaction/createTransactionLocalDataHelper.d.ts +56 -0
  31. package/lib/view/transactionDetail/createTransaction/createTransactionLocalDataHelper.js +172 -0
  32. package/lib/view/transactionDetail/createTransaction/createTransactionPayload.d.ts +95 -0
  33. package/lib/view/transactionDetail/createTransaction/createTransactionPayload.js +169 -0
  34. package/lib/view/transactionDetail/createTransaction/createTransactionSelector.d.ts +44 -0
  35. package/lib/view/transactionDetail/createTransaction/createTransactionSelector.js +53 -0
  36. package/lib/view/transactionDetail/createTransaction/createTransactionState.d.ts +82 -0
  37. package/lib/view/transactionDetail/createTransaction/createTransactionState.js +14 -0
  38. package/lib/view/transactionDetail/createTransaction/epics/createTransactionAttachmentUploadFailureEpic.d.ts +10 -0
  39. package/lib/view/transactionDetail/createTransaction/epics/createTransactionAttachmentUploadFailureEpic.js +23 -0
  40. package/lib/view/transactionDetail/createTransaction/epics/createTransactionEpic.d.ts +9 -0
  41. package/lib/view/transactionDetail/createTransaction/epics/createTransactionEpic.js +85 -0
  42. package/lib/view/transactionDetail/createTransaction/epics/fetchVendorRecommendationsForCreateTransactionEpic.d.ts +20 -0
  43. package/lib/view/transactionDetail/createTransaction/epics/fetchVendorRecommendationsForCreateTransactionEpic.js +57 -0
  44. package/lib/view/transactionDetail/createTransaction/epics/initializeCreateTransactionLocalDataEpic.d.ts +12 -0
  45. package/lib/view/transactionDetail/createTransaction/epics/initializeCreateTransactionLocalDataEpic.js +14 -0
  46. package/lib/view/transactionDetail/transactionDetailReducer.d.ts +39 -1
  47. package/lib/view/transactionDetail/transactionDetailReducer.js +198 -2
  48. package/lib/view/transactionDetail/transactionDetailState.d.ts +12 -0
  49. package/package.json +1 -1
@@ -0,0 +1,44 @@
1
+ import { NestedAccountHierarchyForReport } from '../../../commonStateTypes/accountView/nestedAccountID';
2
+ import { NestedClassHierarchyForReport } from '../../../commonStateTypes/classesView/nestedClassID';
3
+ import { FetchState, FetchStateAndError } from '../../../commonStateTypes/common';
4
+ import { Recommendation } from '../../../commonStateTypes/recommendationBase';
5
+ import { SelectorView } from '../../../commonStateTypes/viewAndReport/viewAndReport';
6
+ import { AccountBase } from '../../../entity/account/accountState';
7
+ import { TransactionID } from '../../../entity/transaction/stateTypes/transactionID';
8
+ import { Vendor } from '../../../entity/vendor/vendorState';
9
+ import { RootState } from '../../../rootStateTypes';
10
+ import { CreatableTransactionType, CreateTransactionLocalData } from './createTransactionState';
11
+ export interface CreateTransactionView extends SelectorView {
12
+ /**
13
+ * COA and class trees for the header account and the line dropdowns. The hierarchies rather
14
+ * than flat lists, because the create page builds its grouped "Recommended" / "All" options
15
+ * with the same helpers the detail page uses.
16
+ */
17
+ accountListNestedAccountHierarchy: NestedAccountHierarchyForReport[];
18
+ classListNestedAccountHierarchy: NestedClassHierarchyForReport[];
19
+ createStatus: FetchStateAndError;
20
+ localData: CreateTransactionLocalData;
21
+ transactionType: CreatableTransactionType;
22
+ /** Populated for transfer only; the COA would offer ineligible accounts. */
23
+ transferAccountsList: AccountBase[];
24
+ vendorList: Vendor[];
25
+ createdTransactionId?: TransactionID;
26
+ }
27
+ export declare const getCreateTransactionLocalData: (state: RootState, transactionType: CreatableTransactionType) => CreateTransactionLocalData;
28
+ export declare const getCreateTransactionStatus: (state: RootState) => FetchStateAndError;
29
+ /**
30
+ * The vendor recommendations backing the category/class dropdowns on the create page.
31
+ *
32
+ * No new state field is needed for this: getRecommendationsForEntity already returns
33
+ * fetchState alongside recommendations, so composing it here is enough for the page to show a
34
+ * line skeleton and hold Save while a fetch is in flight.
35
+ */
36
+ export declare const getCreateTransactionVendorRecommendations: (state: RootState, vendorQboId?: string) => {
37
+ fetchState: FetchState;
38
+ recommendations?: Recommendation[];
39
+ };
40
+ /**
41
+ * Memoized: app-ui reads this straight from useSelector, and the vendor list and hierarchies are
42
+ * rebuilt on every call, so an unmemoized version re-renders the page on every store action.
43
+ */
44
+ export declare const getCreateTransactionView: (state: RootState, transactionType: CreatableTransactionType) => CreateTransactionView;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCreateTransactionView = exports.getCreateTransactionVendorRecommendations = exports.getCreateTransactionStatus = exports.getCreateTransactionLocalData = void 0;
4
+ const toolkit_1 = require("@reduxjs/toolkit");
5
+ const accountListSelector_1 = require("../../accountList/accountListSelector");
6
+ const classListSelector_1 = require("../../classList/classListSelector");
7
+ const createTransferEntrySelector_1 = require("../../createTransferEntry/createTransferEntrySelector");
8
+ const recommendationSelector_1 = require("../../recommendation/recommendationSelector");
9
+ const getCreateTransactionLocalData = (state, transactionType) => state.transactionDetailState.createTransactionsState.newTransactionState[transactionType];
10
+ exports.getCreateTransactionLocalData = getCreateTransactionLocalData;
11
+ const getCreateTransactionStatus = (state) => state.transactionDetailState.createTransactionsState.createStatus;
12
+ exports.getCreateTransactionStatus = getCreateTransactionStatus;
13
+ /**
14
+ * The vendor recommendations backing the category/class dropdowns on the create page.
15
+ *
16
+ * No new state field is needed for this: getRecommendationsForEntity already returns
17
+ * fetchState alongside recommendations, so composing it here is enough for the page to show a
18
+ * line skeleton and hold Save while a fetch is in flight.
19
+ */
20
+ const getCreateTransactionVendorRecommendations = (state, vendorQboId) => {
21
+ if (vendorQboId == null || vendorQboId === '') {
22
+ return { fetchState: 'Not-Started' };
23
+ }
24
+ const view = (0, recommendationSelector_1.getRecommendationsForEntity)(state, vendorQboId, 'vendor');
25
+ return {
26
+ fetchState: view.fetchState,
27
+ recommendations: view.recommendations,
28
+ };
29
+ };
30
+ exports.getCreateTransactionVendorRecommendations = getCreateTransactionVendorRecommendations;
31
+ /**
32
+ * Memoized: app-ui reads this straight from useSelector, and the vendor list and hierarchies are
33
+ * rebuilt on every call, so an unmemoized version re-renders the page on every store action.
34
+ */
35
+ exports.getCreateTransactionView = (0, toolkit_1.createSelector)([
36
+ (state) => state.transactionDetailState.createTransactionsState,
37
+ (state) => state.vendorState.vendorByID,
38
+ (state) => state.accountListState,
39
+ (state) => state.classListState,
40
+ (state) => (0, createTransferEntrySelector_1.getResolvedTransferAccounts)(state).transferAccountsList,
41
+ (_state, transactionType) => transactionType,
42
+ ], (createTransactionsState, vendorByID, accountListState, classListState, transferAccountsList, transactionType) => ({
43
+ transactionType,
44
+ localData: createTransactionsState.newTransactionState[transactionType],
45
+ createStatus: createTransactionsState.createStatus,
46
+ createdTransactionId: createTransactionsState.createdTransactionId,
47
+ vendorList: Object.values(vendorByID),
48
+ accountListNestedAccountHierarchy: (0, accountListSelector_1.getNestedAccountListHierarchy)(accountListState, 'accountList'),
49
+ classListNestedAccountHierarchy: (0, classListSelector_1.getNestedClassListHierarchy)(classListState),
50
+ transferAccountsList: transactionType === 'transfer' ? transferAccountsList : [],
51
+ fetchState: createTransactionsState.createStatus.fetchState,
52
+ error: createTransactionsState.createStatus.error,
53
+ }));
@@ -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, resetCreateTransactionLocalData } from '../../transactionDetailReducer';
4
+ export type ActionType = ReturnType<typeof initializeCreateTransactionLocalData> | ReturnType<typeof resetCreateTransactionLocalData>;
5
+ /**
6
+ * Seeds the working copy when the Create form opens: today's date, the default line set for the
7
+ * type, and the payment_type the backend insists on.
8
+ *
9
+ * The seed replaces the whole working copy rather than merging into it, so a second initialize
10
+ * for the same type can't leave the previous draft's vendor, memo or account behind.
11
+ */
12
+ export declare const initializeCreateTransactionLocalDataEpic: (actions$: ActionsObservable<ActionType>) => Observable<ActionType>;
@@ -0,0 +1,14 @@
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
+ /**
7
+ * Seeds the working copy when the Create form opens: today's date, the default line set for the
8
+ * type, and the payment_type the backend insists on.
9
+ *
10
+ * The seed replaces the whole working copy rather than merging into it, so a second initialize
11
+ * for the same type can't leave the previous draft's vendor, memo or account behind.
12
+ */
13
+ const initializeCreateTransactionLocalDataEpic = (actions$) => actions$.pipe((0, operators_1.filter)(transactionDetailReducer_1.initializeCreateTransactionLocalData.match), (0, operators_1.map)((action) => (0, transactionDetailReducer_1.resetCreateTransactionLocalData)(action.payload.transactionType)));
14
+ 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;