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

Assign false to the POLICY_HAS_CONNECTIONS_DATA_BEEN_FETCHED Onyx key when the fetching of connections data fails #40375

Merged
Merged
Show file tree
Hide file tree
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
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
Loading