-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[No QA] feat: Add Zenefits action module and ConnectToZenefitsFlow component #90766
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
Merged
yuwenmemon
merged 2 commits into
Expensify:main
from
Krishna2323:krishna/trinet-actions-pr4
May 15, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,63 @@ | ||
| import React, {useRef, useState} from 'react'; | ||
| import {StyleSheet, View} from 'react-native'; | ||
| import {WebView} from 'react-native-webview'; | ||
| import ActivityIndicator from '@components/ActivityIndicator'; | ||
| import FullPageOfflineBlockingView from '@components/BlockingViews/FullPageOfflineBlockingView'; | ||
| import HeaderWithBackButton from '@components/HeaderWithBackButton'; | ||
| import Modal from '@components/Modal'; | ||
| import useLocalize from '@hooks/useLocalize'; | ||
| import useOnyx from '@hooks/useOnyx'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import getZenefitsSetupLink from '@libs/actions/connections/Zenefits'; | ||
| import CONST from '@src/CONST'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import type ConnectToZenefitsFlowProps from './types'; | ||
|
|
||
| function ConnectToZenefitsFlow({policyID}: ConnectToZenefitsFlowProps) { | ||
| const {translate} = useLocalize(); | ||
| const styles = useThemeStyles(); | ||
| const webViewRef = useRef<WebView>(null); | ||
| const [isWebViewOpen, setIsWebViewOpen] = useState(true); | ||
| const [session] = useOnyx(ONYXKEYS.SESSION); | ||
|
|
||
| const renderLoading = () => ( | ||
| <View style={[StyleSheet.absoluteFill, styles.fullScreenLoading]}> | ||
| <ActivityIndicator | ||
| size={CONST.ACTIVITY_INDICATOR_SIZE.LARGE} | ||
| reasonAttributes={{context: 'ConnectToZenefitsFlow'}} | ||
| /> | ||
| </View> | ||
| ); | ||
|
|
||
| const authToken = session?.authToken ?? null; | ||
| return ( | ||
| <Modal | ||
| onClose={() => setIsWebViewOpen(false)} | ||
| fullscreen | ||
| isVisible={isWebViewOpen} | ||
| type={CONST.MODAL.MODAL_TYPE.CENTERED_UNSWIPEABLE} | ||
| > | ||
| <HeaderWithBackButton | ||
| title={translate('workspace.common.hr')} | ||
| onBackButtonPress={() => setIsWebViewOpen(false)} | ||
| shouldDisplayHelpButton={false} | ||
| /> | ||
| <FullPageOfflineBlockingView> | ||
| <WebView | ||
| ref={webViewRef} | ||
| source={{ | ||
| uri: getZenefitsSetupLink(policyID), | ||
| headers: { | ||
| Cookie: `authToken=${authToken}`, | ||
| }, | ||
| }} | ||
| incognito | ||
| startInLoadingState | ||
| renderLoading={renderLoading} | ||
| /> | ||
| </FullPageOfflineBlockingView> | ||
| </Modal> | ||
| ); | ||
| } | ||
|
|
||
| export default ConnectToZenefitsFlow; |
This file contains hidden or 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,17 @@ | ||
| import {useEffect} from 'react'; | ||
| import useEnvironment from '@hooks/useEnvironment'; | ||
| import getZenefitsSetupLink from '@libs/actions/connections/Zenefits'; | ||
| import {openLink} from '@userActions/Link'; | ||
| import type ConnectToZenefitsFlowProps from './types'; | ||
|
|
||
| function ConnectToZenefitsFlow({policyID}: ConnectToZenefitsFlowProps) { | ||
| const {environmentURL} = useEnvironment(); | ||
|
|
||
| useEffect(() => { | ||
| openLink(getZenefitsSetupLink(policyID), environmentURL); | ||
| }, [environmentURL, policyID]); | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| export default ConnectToZenefitsFlow; |
This file contains hidden or 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 ConnectToZenefitsFlowProps = { | ||
| policyID: string; | ||
| }; | ||
|
|
||
| export default ConnectToZenefitsFlowProps; |
This file contains hidden or 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,147 @@ | ||
| import type {OnyxUpdate} from 'react-native-onyx'; | ||
| import Onyx from 'react-native-onyx'; | ||
| import type {ValueOf} from 'type-fest'; | ||
| import {write} from '@libs/API'; | ||
| import type {ConnectPolicyToZenefitsParams} from '@libs/API/parameters'; | ||
| import {READ_COMMANDS, WRITE_COMMANDS} from '@libs/API/types'; | ||
| import {getCommandURL} from '@libs/ApiUtils'; | ||
| import {getMicroSecondOnyxErrorWithTranslationKey} from '@libs/ErrorUtils'; | ||
| import CONST from '@src/CONST'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
|
|
||
| function getZenefitsSetupLink(policyID: string) { | ||
| const params: ConnectPolicyToZenefitsParams = {policyID}; | ||
| const commandURL = getCommandURL({ | ||
| command: READ_COMMANDS.CONNECT_POLICY_TO_ZENEFITS, | ||
| shouldSkipWebProxy: true, | ||
| }); | ||
| return commandURL + new URLSearchParams(params).toString(); | ||
| } | ||
|
|
||
| function updateZenefitsApprovalMode( | ||
| policyID: string | undefined, | ||
| approvalMode: ValueOf<typeof CONST.ZENEFITS.APPROVAL_MODE>, | ||
| currentApprovalMode?: ValueOf<typeof CONST.ZENEFITS.APPROVAL_MODE> | null, | ||
| ) { | ||
| if (!policyID) { | ||
| return; | ||
| } | ||
|
|
||
| const previousApprovalMode = currentApprovalMode ?? null; | ||
| const optimisticData: Array<OnyxUpdate<typeof ONYXKEYS.COLLECTION.POLICY>> = [ | ||
| { | ||
| onyxMethod: Onyx.METHOD.MERGE, | ||
| key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, | ||
| value: { | ||
| connections: { | ||
| zenefits: { | ||
| config: { | ||
| approvalMode, | ||
| pendingFields: {approvalMode: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE}, | ||
| errorFields: {approvalMode: null}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| ]; | ||
| const successData: Array<OnyxUpdate<typeof ONYXKEYS.COLLECTION.POLICY>> = [ | ||
| { | ||
| onyxMethod: Onyx.METHOD.MERGE, | ||
| key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, | ||
| value: { | ||
| connections: { | ||
| zenefits: { | ||
| config: { | ||
| pendingFields: {approvalMode: null}, | ||
| errorFields: {approvalMode: null}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| ]; | ||
| const failureData: Array<OnyxUpdate<typeof ONYXKEYS.COLLECTION.POLICY>> = [ | ||
| { | ||
| onyxMethod: Onyx.METHOD.MERGE, | ||
| key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, | ||
| value: { | ||
| connections: { | ||
| zenefits: { | ||
| config: { | ||
| approvalMode: previousApprovalMode, | ||
| pendingFields: {approvalMode: null}, | ||
| errorFields: {approvalMode: getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage')}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| ]; | ||
|
|
||
| write(WRITE_COMMANDS.UPDATE_ZENEFITS_APPROVAL_MODE, {policyID, approvalMode}, {optimisticData, successData, failureData}); | ||
| } | ||
|
|
||
| function updateZenefitsFinalApprover(policyID: string | undefined, finalApprover: string | null, currentFinalApprover?: string | null) { | ||
| if (!policyID) { | ||
| return; | ||
| } | ||
|
|
||
| const previousFinalApprover = currentFinalApprover ?? null; | ||
| const optimisticData: Array<OnyxUpdate<typeof ONYXKEYS.COLLECTION.POLICY>> = [ | ||
| { | ||
| onyxMethod: Onyx.METHOD.MERGE, | ||
| key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, | ||
| value: { | ||
| connections: { | ||
| zenefits: { | ||
| config: { | ||
| finalApprover, | ||
| pendingFields: {finalApprover: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE}, | ||
| errorFields: {finalApprover: null}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| ]; | ||
| const successData: Array<OnyxUpdate<typeof ONYXKEYS.COLLECTION.POLICY>> = [ | ||
| { | ||
| onyxMethod: Onyx.METHOD.MERGE, | ||
| key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, | ||
| value: { | ||
| connections: { | ||
| zenefits: { | ||
| config: { | ||
| pendingFields: {finalApprover: null}, | ||
| errorFields: {finalApprover: null}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| ]; | ||
| const failureData: Array<OnyxUpdate<typeof ONYXKEYS.COLLECTION.POLICY>> = [ | ||
| { | ||
| onyxMethod: Onyx.METHOD.MERGE, | ||
| key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, | ||
| value: { | ||
| connections: { | ||
| zenefits: { | ||
| config: { | ||
| finalApprover: previousFinalApprover, | ||
| pendingFields: {finalApprover: null}, | ||
| errorFields: {finalApprover: getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage')}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| ]; | ||
|
|
||
| write(WRITE_COMMANDS.UPDATE_ZENEFITS_FINAL_APPROVER, {policyID, finalApprover}, {optimisticData, successData, failureData}); | ||
| } | ||
|
|
||
| export {updateZenefitsApprovalMode, updateZenefitsFinalApprover}; | ||
|
|
||
| export default getZenefitsSetupLink; |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.