Skip to content

Commit e7ef3a9

Browse files
authored
Merge pull request #91211 from dukenv0307/fix/66424-part-18
refactor updateMultipleMoneyRequests and getIouParamsForTransaction to use onboarding data from useOnyx
2 parents b72b9b7 + 4caae70 commit e7ef3a9

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/hooks/useTransactionInlineEdit.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* derivation, Onyx subscriptions, and edit handlers live in one place rather
44
* than being duplicated across every surface that renders a transaction.
55
*/
6+
import {guidedSetupAndTourStatusSelector} from '@selectors/Onboarding';
67
import {useCallback, useRef} from 'react';
78
// eslint-disable-next-line no-restricted-imports -- Need original useOnyx to avoid reading partial Search snapshot policy data.
89
import {useOnyx as originalUseOnyx} from 'react-native-onyx';
@@ -116,6 +117,7 @@ function useTransactionInlineEdit({transactionID, hash, linkedReportAction}: Use
116117
const [policyRecentlyUsedCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES}${getNonEmptyStringOnyxID(policyID)}`);
117118
const [policyRecentlyUsedTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_TAGS}${getNonEmptyStringOnyxID(policyID)}`);
118119
const [parentReportNextStep] = useOnyx(`${ONYXKEYS.COLLECTION.NEXT_STEP}${getNonEmptyStringOnyxID(effectiveParentReportID)}`);
120+
const [guidedSetupAndTourStatus] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: guidedSetupAndTourStatusSelector});
119121
// Use original Onyx here because the useOnyx wrapper can read partial Search snapshot policy data instead of the full policy object.
120122
const [completePolicy] = originalUseOnyx(`${ONYXKEYS.COLLECTION.POLICY}${getNonEmptyStringOnyxID(policyID)}`);
121123

@@ -157,6 +159,8 @@ function useTransactionInlineEdit({transactionID, hash, linkedReportAction}: Use
157159
policyRecentlyUsedCategories,
158160
policyRecentlyUsedTags,
159161
parentReportNextStep,
162+
isSelfTourViewed: guidedSetupAndTourStatus?.isSelfTourViewed ?? false,
163+
hasCompletedGuidedSetupFlow: guidedSetupAndTourStatus?.hasCompletedGuidedSetupFlow ?? false,
160164
};
161165
};
162166

src/libs/actions/TransactionInlineEdit.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ type GetIouParamsInput = {
175175
policyRecentlyUsedCategories: OnyxEntry<RecentlyUsedCategories>;
176176
policyRecentlyUsedTags: OnyxEntry<RecentlyUsedTags>;
177177
parentReportNextStep: OnyxEntry<ReportNextStepDeprecated>;
178+
isSelfTourViewed: boolean | undefined;
179+
hasCompletedGuidedSetupFlow: boolean | undefined;
178180
};
179181

180182
type TransactionInlineEditParams = GetIouParamsInput & {
@@ -199,6 +201,8 @@ function getIouParamsForTransaction({
199201
policyRecentlyUsedCategories,
200202
policyRecentlyUsedTags,
201203
parentReportNextStep,
204+
isSelfTourViewed,
205+
hasCompletedGuidedSetupFlow,
202206
}: GetIouParamsInput) {
203207
const transaction = allTransactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`];
204208
const transactionViolations = allTransactionViolations[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`];
@@ -244,6 +248,8 @@ function getIouParamsForTransaction({
244248
iouReportAction: resolvedParentReportAction,
245249
transaction,
246250
transactionViolations: transactionViolations ?? undefined,
251+
isSelfTourViewed,
252+
hasCompletedGuidedSetupFlow,
247253
});
248254
}
249255

src/selectors/Onboarding.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,16 @@ function wasInvitedToNewDotSelector(introSelected: OnyxValue<typeof ONYXKEYS.NVP
6767
return introSelected?.inviteType !== undefined;
6868
}
6969

70-
export {hasCompletedGuidedSetupFlowSelector, tryNewDotOnyxSelector, hasSeenTourSelector, wasInvitedToNewDotSelector};
70+
/**
71+
* Combined selector that derives both the self-tour status and the guided-setup
72+
* completion flag from a single NVP_ONBOARDING read, avoiding two subscriptions
73+
* to the same key from callers that need both.
74+
*/
75+
function guidedSetupAndTourStatusSelector(onboarding: OnyxValue<typeof ONYXKEYS.NVP_ONBOARDING>): {isSelfTourViewed: boolean | undefined; hasCompletedGuidedSetupFlow: boolean | undefined} {
76+
return {
77+
isSelfTourViewed: hasSeenTourSelector(onboarding),
78+
hasCompletedGuidedSetupFlow: hasCompletedGuidedSetupFlowSelector(onboarding),
79+
};
80+
}
81+
82+
export {hasCompletedGuidedSetupFlowSelector, tryNewDotOnyxSelector, hasSeenTourSelector, wasInvitedToNewDotSelector, guidedSetupAndTourStatusSelector};

0 commit comments

Comments
 (0)