Skip to content

Commit

Permalink
Merge pull request #40435 from software-mansion-labs/hold-interstitia…
Browse files Browse the repository at this point in the history
…l/backend-fix

[Held requests] Hold Request education modal reappears after relogin
  • Loading branch information
robertjchen authored Jun 19, 2024
2 parents 904d49d + 6873dd9 commit d938880
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ const ONYXKEYS = {
/** Whether the user has tried focus mode yet */
NVP_TRY_FOCUS_MODE: 'nvp_tryFocusMode',

/** Whether the user has been shown the hold educational interstitial yet */
NVP_HOLD_USE_EXPLAINED: 'holdUseExplained',
/** Whether the user has dismissed the hold educational interstitial */
NVP_DISMISSED_HOLD_USE_EXPLANATION: 'nvp_dismissedHoldUseExplanation',

/** Store the state of the subscription */
NVP_PRIVATE_SUBSCRIPTION: 'nvp_private_subscription',
Expand Down Expand Up @@ -635,7 +635,7 @@ type OnyxValuesMapping = {
[ONYXKEYS.NVP_BLOCKED_FROM_CHAT]: string;
[ONYXKEYS.NVP_PRIVATE_PUSH_NOTIFICATION_ID]: string;
[ONYXKEYS.NVP_TRY_FOCUS_MODE]: boolean;
[ONYXKEYS.NVP_HOLD_USE_EXPLAINED]: boolean;
[ONYXKEYS.NVP_DISMISSED_HOLD_USE_EXPLANATION]: boolean;
[ONYXKEYS.FOCUS_MODE_NOTIFICATION]: boolean;
[ONYXKEYS.NVP_LAST_PAYMENT_METHOD]: OnyxTypes.LastPaymentMethod;
[ONYXKEYS.NVP_RECENT_WAYPOINTS]: OnyxTypes.RecentWaypoint[];
Expand Down
11 changes: 5 additions & 6 deletions src/components/MoneyRequestHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ function MoneyRequestHeader({report, parentReportAction, policy, shouldUseNarrow
const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${(parentReportAction as ReportAction & OriginalMessageIOU)?.originalMessage?.IOUTransactionID ?? -1}`);
const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS);
const [session] = useOnyx(ONYXKEYS.SESSION);
const [holdUseExplained, holdUseExplainedResult] = useOnyx(ONYXKEYS.NVP_HOLD_USE_EXPLAINED);
const isLoadingHoldUseExplained = isLoadingOnyxValue(holdUseExplainedResult);

const [dismissedHoldUseExplanation, dismissedHoldUseExplanationResult] = useOnyx(ONYXKEYS.NVP_DISMISSED_HOLD_USE_EXPLANATION, {initialValue: true});
const isLoadingHoldUseExplained = isLoadingOnyxValue(dismissedHoldUseExplanationResult);
const styles = useThemeStyles();
const theme = useTheme();
const {translate} = useLocalize();
Expand Down Expand Up @@ -180,8 +179,8 @@ function MoneyRequestHeader({report, parentReportAction, policy, shouldUseNarrow
if (isLoadingHoldUseExplained) {
return;
}
setShouldShowHoldMenu(isOnHold && !holdUseExplained);
}, [isOnHold, holdUseExplained, isLoadingHoldUseExplained]);
setShouldShowHoldMenu(isOnHold && !dismissedHoldUseExplanation);
}, [dismissedHoldUseExplanation, isLoadingHoldUseExplained, isOnHold]);

useEffect(() => {
if (!shouldShowHoldMenu) {
Expand All @@ -198,7 +197,7 @@ function MoneyRequestHeader({report, parentReportAction, policy, shouldUseNarrow
}, [isSmallScreenWidth, shouldShowHoldMenu]);

const handleHoldRequestClose = () => {
IOU.setShownHoldUseExplanation();
IOU.dismissHoldUseExplanation();
};

if (canDeleteRequest) {
Expand Down
24 changes: 20 additions & 4 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import type {
RequestMoneyParams,
SendInvoiceParams,
SendMoneyParams,
SetNameValuePairParams,
SplitBillParams,
StartSplitBillParams,
SubmitReportParams,
Expand Down Expand Up @@ -6677,8 +6678,23 @@ function setMoneyRequestTaxAmount(transactionID: string, taxAmount: number | nul
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {taxAmount});
}

function setShownHoldUseExplanation() {
Onyx.set(ONYXKEYS.NVP_HOLD_USE_EXPLAINED, true);
function dismissHoldUseExplanation() {
const parameters: SetNameValuePairParams = {
name: ONYXKEYS.NVP_DISMISSED_HOLD_USE_EXPLANATION,
value: true,
};

const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.NVP_DISMISSED_HOLD_USE_EXPLANATION,
value: true,
},
];

API.write(WRITE_COMMANDS.SET_NAME_VALUE_PAIR, parameters, {
optimisticData,
});
}

/**
Expand Down Expand Up @@ -6977,7 +6993,8 @@ export {
setMoneyRequestTag,
setMoneyRequestTaxAmount,
setMoneyRequestTaxRate,
setShownHoldUseExplanation,
dismissHoldUseExplanation,
updateMoneyRequestDate,
setSplitShares,
resetSplitShares,
setIndividualShare,
Expand All @@ -6993,7 +7010,6 @@ export {
updateMoneyRequestAmountAndCurrency,
updateMoneyRequestBillable,
updateMoneyRequestCategory,
updateMoneyRequestDate,
updateMoneyRequestDescription,
updateMoneyRequestDistance,
updateMoneyRequestMerchant,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/ProcessMoneyRequestHoldPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function ProcessMoneyRequestHoldPage() {
const {translate} = useLocalize();

const onConfirm = useCallback(() => {
IOU.setShownHoldUseExplanation();
IOU.dismissHoldUseExplanation();
Navigation.goBack();
}, []);

Expand Down

0 comments on commit d938880

Please sign in to comment.