-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into fix/39559
- Loading branch information
Showing
12 changed files
with
162 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,7 +64,7 @@ | |
"@babel/plugin-proposal-private-methods": "^7.18.6", | ||
"@babel/plugin-proposal-private-property-in-object": "^7.21.11", | ||
"@dotlottie/react-player": "^1.6.3", | ||
"@expensify/react-native-live-markdown": "0.1.49", | ||
"@expensify/react-native-live-markdown": "0.1.62", | ||
"@expo/metro-runtime": "~3.1.1", | ||
"@formatjs/intl-datetimeformat": "^6.10.0", | ||
"@formatjs/intl-listformat": "^7.2.2", | ||
|
@@ -108,7 +108,7 @@ | |
"date-fns-tz": "^2.0.0", | ||
"dom-serializer": "^0.2.2", | ||
"domhandler": "^4.3.0", | ||
"expensify-common": "git+ssh://[email protected]/Expensify/expensify-common.git#13de5b0606662df33fa1392ad82cc11daadff52e", | ||
"expensify-common": "git+ssh://[email protected]/Expensify/expensify-common.git#c0f7f3b6558fbeda0527c80d68460d418afef219", | ||
"expo": "^50.0.3", | ||
"expo-av": "~13.10.4", | ||
"expo-image": "1.11.0", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
type OpenPolicyAccountingPageParams = { | ||
policyID: string; | ||
}; | ||
|
||
export default OpenPolicyAccountingPageParams; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import Onyx from 'react-native-onyx'; | ||
import type {OnyxUpdate} from 'react-native-onyx'; | ||
import * as API from '@libs/API'; | ||
import type {OpenPolicyAccountingPageParams} from '@libs/API/parameters'; | ||
import {READ_COMMANDS} from '@libs/API/types'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
|
||
function openPolicyAccountingPage(policyID: string) { | ||
const hasConnectionsDataBeenFetchedKey = `${ONYXKEYS.COLLECTION.POLICY_HAS_CONNECTIONS_DATA_BEEN_FETCHED}${policyID}` as const; | ||
|
||
const optimisticData: OnyxUpdate[] = [ | ||
{ | ||
onyxMethod: Onyx.METHOD.MERGE, | ||
key: hasConnectionsDataBeenFetchedKey, | ||
value: false, | ||
}, | ||
]; | ||
const finallyData: OnyxUpdate[] = [ | ||
{ | ||
onyxMethod: Onyx.METHOD.MERGE, | ||
key: hasConnectionsDataBeenFetchedKey, | ||
value: true, | ||
}, | ||
]; | ||
|
||
const parameters: OpenPolicyAccountingPageParams = { | ||
policyID, | ||
}; | ||
|
||
API.read(READ_COMMANDS.OPEN_POLICY_ACCOUNTING_PAGE, parameters, { | ||
optimisticData, | ||
finallyData, | ||
}); | ||
} | ||
|
||
// More action functions will be added later | ||
// eslint-disable-next-line import/prefer-default-export | ||
export {openPolicyAccountingPage}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import React, {useEffect} from 'react'; | ||
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 withPolicy from './withPolicy'; | ||
import type {WithPolicyProps} from './withPolicy'; | ||
|
||
type WithPolicyConnectionsProps = WithPolicyProps; | ||
|
||
/** | ||
* Higher-order component that fetches the connections data and populates | ||
* the corresponding field of the policy object if the field is empty. It then passes the policy object | ||
* to the wrapped component. | ||
* | ||
* Use this HOC when you need the policy object with its connections field populated. | ||
* | ||
* Only the active policy gets the complete policy data upon app start that includes the connections data. | ||
* For other policies, the connections data needs to be fetched when it's needed. | ||
*/ | ||
function withPolicyConnections(WrappedComponent: ComponentType<WithPolicyConnectionsProps>) { | ||
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, | ||
}); | ||
|
||
useEffect(() => { | ||
// When the accounting feature is not enabled, or if the connections data already exists, | ||
// there is no need to fetch the connections data. | ||
if (!policy || !policy.areConnectionsEnabled || !!hasConnectionsDataBeenFetched || !!policy.connections) { | ||
return; | ||
} | ||
|
||
openPolicyAccountingPage(policy.id); | ||
}, [hasConnectionsDataBeenFetched, policy]); | ||
|
||
if (status === 'loading' || !hasConnectionsDataBeenFetched) { | ||
if (isOffline) { | ||
return ( | ||
<FullPageOfflineBlockingView> | ||
<WrappedComponent | ||
policy={policy} | ||
policyDraft={policyDraft} | ||
route={route} | ||
/> | ||
</FullPageOfflineBlockingView> | ||
); | ||
} | ||
|
||
return <FullScreenLoadingIndicator />; | ||
} | ||
|
||
return ( | ||
<WrappedComponent | ||
policy={policy} | ||
policyDraft={policyDraft} | ||
route={route} | ||
/> | ||
); | ||
} | ||
|
||
return withPolicy(WithPolicyConnections); | ||
} | ||
|
||
export default withPolicyConnections; |