Skip to content

Commit

Permalink
Merge pull request #40375 from Expensify/hayata-fix-the-issue-with-co…
Browse files Browse the repository at this point in the history
…nnections-data-fetching

Assign `false` to the `POLICY_HAS_CONNECTIONS_DATA_BEEN_FETCHED` Onyx key when the fetching of `connections` data fails
  • Loading branch information
aldo-expensify authored Apr 22, 2024
2 parents 448982d + 76ec54a commit e17bf43
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/libs/actions/PolicyConnections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,29 @@ function openPolicyAccountingPage(policyID: string) {
value: false,
},
];
const finallyData: OnyxUpdate[] = [
const successData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: hasConnectionsDataBeenFetchedKey,
value: true,
},
];
const failureData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: hasConnectionsDataBeenFetchedKey,
value: false,
},
];

const parameters: OpenPolicyAccountingPageParams = {
policyID,
};

API.read(READ_COMMANDS.OPEN_POLICY_ACCOUNTING_PAGE, parameters, {
optimisticData,
finallyData,
successData,
failureData,
});
}

Expand Down
4 changes: 3 additions & 1 deletion src/pages/workspace/withPolicyConnections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {ComponentType} from 'react';
import {useOnyx} from 'react-native-onyx';
import FullPageOfflineBlockingView from '@components/BlockingViews/FullPageOfflineBlockingView';
import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
import useNetwork from '@hooks/useNetwork';
import {openPolicyAccountingPage} from '@libs/actions/PolicyConnections';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Policy} from '@src/types/onyx';
Expand All @@ -23,6 +24,7 @@ type WithPolicyConnectionsProps = WithPolicyProps;
*/
function withPolicyConnections(WrappedComponent: ComponentType<WithPolicyConnectionsProps & {policy: Policy}>) {
function WithPolicyConnections({policy, policyDraft, route}: WithPolicyConnectionsProps) {
const {isOffline} = useNetwork();
const [hasConnectionsDataBeenFetched, {status}] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_HAS_CONNECTIONS_DATA_BEEN_FETCHED}${policy?.id ?? '0'}`, {
initWithStoredValues: false,
});
Expand All @@ -35,7 +37,7 @@ function withPolicyConnections(WrappedComponent: ComponentType<WithPolicyConnect
}

openPolicyAccountingPage(policy.id);
}, [hasConnectionsDataBeenFetched, policy]);
}, [hasConnectionsDataBeenFetched, policy, isOffline]);

if (!policy || status === 'loading' || !hasConnectionsDataBeenFetched) {
return (
Expand Down

0 comments on commit e17bf43

Please sign in to comment.