-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[NoQA] [HR Import] Rename and parameterize the sync results modal #91285
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
Changes from 3 commits
13b81ae
be8e00d
ce001bb
27c8d45
8973c5e
0eecf30
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import {useEffect} from 'react'; | ||
| import type {OnyxEntry} from 'react-native-onyx'; | ||
| import type {TupleToUnion} from 'type-fest'; | ||
| import HRSyncResultsModal from '@components/HRSyncResultsModal'; | ||
| import {useModal} from '@components/Modal/Global/ModalContext'; | ||
| import {getConnectedHRProvider} from '@libs/PolicyUtils'; | ||
| import CONST from '@src/CONST'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import {policyConnectionsSelector} from '@src/selectors/Policy'; | ||
| import type {PolicyConnectionSyncProgress} from '@src/types/onyx/Policy'; | ||
| import useOnyx from './useOnyx'; | ||
| import usePrevious from './usePrevious'; | ||
|
|
||
| /** | ||
| * Watches an HR provider's sync progress and automatically opens the `HRSyncResultsModal` | ||
| * when the sync transitions to the `JOB_DONE` stage with a result payload. | ||
| */ | ||
| function useHRSyncResultsModal(policyID: string, connectionSyncProgress: OnyxEntry<PolicyConnectionSyncProgress>, isFocused: boolean) { | ||
|
mhawryluk marked this conversation as resolved.
|
||
| const modal = useModal(); | ||
| const previousSyncProgress = usePrevious(connectionSyncProgress); | ||
| const [policyConnections] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {selector: policyConnectionsSelector}); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ PERF-11 (docs)The The hook only needs to determine which HR provider is connected and its display name. Replace the broad selector with one that computes and returns just the const [providerDisplayName] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {
selector: (policy) => {
const hrProvider = getConnectedHRProvider(policy);
return hrProvider?.displayName
?? CONST.POLICY.CONNECTIONS.NAME_USER_FRIENDLY[connectionName as keyof typeof CONST.POLICY.CONNECTIONS.NAME_USER_FRIENDLY]
?? connectionName;
},
});Reviewed at: ce001bb | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency. |
||
|
|
||
| const connectionName = connectionSyncProgress?.connectionName; | ||
| const providerDisplayName = | ||
| getConnectedHRProvider({connections: policyConnections})?.displayName ?? | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this be in a useeffect?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it could. but actually I moved it to the |
||
| CONST.POLICY.CONNECTIONS.NAME_USER_FRIENDLY[connectionName as keyof typeof CONST.POLICY.CONNECTIONS.NAME_USER_FRIENDLY] ?? | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Use of Useful? React with 👍 / 👎.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, it would be better to have the merge hr integration slug in policyConnections, so that we ensure there is no mismatch, but I'm not sure if the backend will send it, and we can get that information from policy data, so that is what we do. and I don't think the mismatch is plausible in this scenario and having consistent Onyx data between policy and policyConnections is enough to make the modal render correct data |
||
| connectionName; | ||
|
|
||
| useEffect(() => { | ||
| const syncResult = connectionSyncProgress?.result; | ||
| const isHRSyncDoneWithResult = | ||
| CONST.POLICY.CONNECTIONS.HR_CONNECTION_NAMES.includes(connectionName as TupleToUnion<typeof CONST.POLICY.CONNECTIONS.HR_CONNECTION_NAMES>) && | ||
| connectionSyncProgress?.stageInProgress === CONST.POLICY.CONNECTIONS.SYNC_STAGE_NAME.JOB_DONE && | ||
| !!syncResult; | ||
| const didTransitionToJobDone = previousSyncProgress?.connectionName === connectionName && previousSyncProgress?.stageInProgress !== CONST.POLICY.CONNECTIONS.SYNC_STAGE_NAME.JOB_DONE; | ||
| const didHRSyncComplete = isFocused && isHRSyncDoneWithResult && didTransitionToJobDone; | ||
|
|
||
| if (!didHRSyncComplete || !syncResult || !connectionName) { | ||
| return; | ||
| } | ||
|
|
||
| modal.showModal({ | ||
| component: HRSyncResultsModal, | ||
| props: {result: syncResult, providerDisplayName}, | ||
| id: `${connectionName}-sync-results-${policyID}`, | ||
| }); | ||
| }, [ | ||
| connectionName, | ||
| connectionSyncProgress?.result, | ||
| connectionSyncProgress?.stageInProgress, | ||
| connectionSyncProgress?.timestamp, | ||
| isFocused, | ||
| providerDisplayName, | ||
| policyID, | ||
| previousSyncProgress?.connectionName, | ||
| previousSyncProgress?.stageInProgress, | ||
| modal, | ||
| ]); | ||
| } | ||
|
|
||
| export default useHRSyncResultsModal; | ||
Uh oh!
There was an error while loading. Please reload this page.