Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NVP_HOLD_USE_EXPLAINED useOnyx wrong config #42819

Merged
merged 3 commits into from
Jun 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/components/MoneyRequestHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import ROUTES from '@src/ROUTES';
import type {Policy, Report, ReportAction} from '@src/types/onyx';
import type {OriginalMessageIOU} from '@src/types/onyx/OriginalMessage';
import type IconAsset from '@src/types/utils/IconAsset';
import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue';
import Button from './Button';
import ConfirmModal from './ConfirmModal';
import HeaderWithBackButton from './HeaderWithBackButton';
Expand Down Expand Up @@ -52,7 +53,8 @@ function MoneyRequestHeader({report, parentReportAction, policy, shouldUseNarrow
const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${(parentReportAction as ReportAction & OriginalMessageIOU)?.originalMessage?.IOUTransactionID ?? 0}`);
const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS);
const [session] = useOnyx(ONYXKEYS.SESSION);
const [shownHoldUseExplanation] = useOnyx(ONYXKEYS.NVP_HOLD_USE_EXPLAINED, {initWithStoredValues: false});
const [holdUseExplained, holdUseExplainedResult] = useOnyx(ONYXKEYS.NVP_HOLD_USE_EXPLAINED);
const isLoadingHoldUseExplained = isLoadingOnyxValue(holdUseExplainedResult);

const styles = useThemeStyles();
const theme = useTheme();
Expand Down Expand Up @@ -171,8 +173,11 @@ function MoneyRequestHeader({report, parentReportAction, policy, shouldUseNarrow
}

useEffect(() => {
setShouldShowHoldMenu(isOnHold && !shownHoldUseExplanation);
}, [isOnHold, shownHoldUseExplanation]);
if (isLoadingHoldUseExplained) {
return;
}
setShouldShowHoldMenu(isOnHold && !holdUseExplained);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have found the code that causes the issue and pushed a new fix. We can't set the prop default value as the onyx initial value because it will be used when the data is still loading by the onyx. Instead, I do an early return when the data is still loading.

}, [isOnHold, holdUseExplained, isLoadingHoldUseExplained]);

useEffect(() => {
if (!shouldShowHoldMenu) {
Expand Down
Loading