-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[No QA][HR Import] Add MergeHRApprovalModePage #91202
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 6 commits
6585495
4f0f4a2
439f121
2d58e01
55446a2
d0b9302
c2a6f6c
fcc5cb2
f87f915
6827557
376ac5a
97bca8f
7eaf3a3
8be8e16
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| import type {OnyxUpdate} from 'react-native-onyx'; | ||
| import Onyx from 'react-native-onyx'; | ||
| import type {ValueOf} from 'type-fest'; | ||
| import type {TupleToUnion, ValueOf} from 'type-fest'; | ||
| import {read, write} from '@libs/API'; | ||
| import type {ConnectPolicyToMergeParams} from '@libs/API/parameters'; | ||
| import {READ_COMMANDS, WRITE_COMMANDS} from '@libs/API/types'; | ||
|
|
@@ -106,7 +106,7 @@ function updateMergeHRApprovalMode(policyID: string, approvalMode: ValueOf<typeo | |
| ]; | ||
|
|
||
| write( | ||
| WRITE_COMMANDS.UPDATE_MERGE_HR_APPROVAL_MODE, | ||
| WRITE_COMMANDS.UPDATE_MERGE_APPROVAL_MODE, | ||
| { | ||
| policyID, | ||
| approvalMode, | ||
|
|
@@ -184,6 +184,22 @@ function updateMergeHRFinalApprover(policyID: string, finalApprover: string | nu | |
| ); | ||
| } | ||
|
|
||
| export {syncMergeHR, updateMergeHRApprovalMode, updateMergeHRFinalApprover}; | ||
| type HRProviderName = TupleToUnion<typeof CONST.POLICY.CONNECTIONS.HR_CONNECTION_NAMES>; | ||
|
|
||
| function clearMergeHRErrorField(policyID?: string, provider?: HRProviderName) { | ||
| if (!policyID || !provider) { | ||
| return; | ||
| } | ||
| Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, { | ||
| connections: { | ||
| [provider]: { | ||
| config: { | ||
| errorFields: null, | ||
|
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. This clears the whole |
||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
| } | ||
| export {syncMergeHR, updateMergeHRApprovalMode, updateMergeHRFinalApprover, clearMergeHRErrorField}; | ||
|
|
||
| export default getMergeHRSetupLink; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| import React, {useState} from 'react'; | ||
| import {View} from 'react-native'; | ||
| import type {OnyxEntry} from 'react-native-onyx'; | ||
| import type {ValueOf} from 'type-fest'; | ||
| import Button from '@components/Button'; | ||
| import FixedFooter from '@components/FixedFooter'; | ||
| import HeaderWithBackButton from '@components/HeaderWithBackButton'; | ||
| import {ModalActions} from '@components/Modal/Global/ModalContext'; | ||
| import RenderHTML from '@components/RenderHTML'; | ||
| import ScreenWrapper from '@components/ScreenWrapper'; | ||
| import SelectionList from '@components/SelectionList'; | ||
| import SingleSelectListItem from '@components/SelectionList/ListItem/SingleSelectListItem'; | ||
| import type {ListItem} from '@components/SelectionList/types'; | ||
| import Text from '@components/Text'; | ||
| import useConfirmModal from '@hooks/useConfirmModal'; | ||
| import useLocalize from '@hooks/useLocalize'; | ||
| import useOnyx from '@hooks/useOnyx'; | ||
| import usePermissions from '@hooks/usePermissions'; | ||
| import usePolicy from '@hooks/usePolicy'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import Navigation from '@libs/Navigation/Navigation'; | ||
| import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; | ||
| import CONST from '@src/CONST'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import type Beta from '@src/types/onyx/Beta'; | ||
| import type Policy from '@src/types/onyx/Policy'; | ||
| import type {PolicyConnectionSyncProgress} from '@src/types/onyx/Policy'; | ||
|
|
||
| type ApprovalModeValue = ValueOf<typeof CONST.GUSTO.APPROVAL_MODE> | ValueOf<typeof CONST.MERGE_HR.APPROVAL_MODE>; | ||
|
|
||
| type HRApprovalModeProviderConfig<T extends ApprovalModeValue = ApprovalModeValue> = { | ||
| testID: string; | ||
| beta: Beta; | ||
| isConnected: (policy: OnyxEntry<Policy>) => boolean; | ||
| approvalModes: {BASIC: T; MANAGER: T; CUSTOM: T}; | ||
| getCurrentApprovalMode: (policy: OnyxEntry<Policy>) => T | null; | ||
| getProviderName: (policy: OnyxEntry<Policy>) => string; | ||
| getHeaderTitle: (providerName: string) => string; | ||
| handleSave: (params: {policyID: string; draftApprovalMode: T; currentApprovalMode: T | null; connectionSyncProgress?: OnyxEntry<PolicyConnectionSyncProgress>}) => void; | ||
| }; | ||
|
|
||
| type ApprovalModeListItem<T extends ApprovalModeValue = ApprovalModeValue> = ListItem & { | ||
| value: T; | ||
| }; | ||
|
|
||
| type HRApprovalModePageBaseProps<T extends ApprovalModeValue = ApprovalModeValue> = { | ||
| policyID: string; | ||
| config: HRApprovalModeProviderConfig<T>; | ||
| }; | ||
|
|
||
| function HRApprovalModePageBase<T extends ApprovalModeValue>({policyID, config}: HRApprovalModePageBaseProps<T>) { | ||
| const {translate} = useLocalize(); | ||
| const styles = useThemeStyles(); | ||
| const {showConfirmModal} = useConfirmModal(); | ||
| const {isBetaEnabled} = usePermissions(); | ||
| const policy = usePolicy(policyID); | ||
| const [connectionSyncProgress] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CONNECTION_SYNC_PROGRESS}${policyID}`); | ||
|
|
||
| const providerName = config.getProviderName(policy); | ||
| const currentApprovalMode = config.getCurrentApprovalMode(policy); | ||
| const [draftApprovalMode, setDraftApprovalMode] = useState<T | undefined>(); | ||
| const selectedApprovalMode = draftApprovalMode ?? currentApprovalMode; | ||
| const isSaveDisabled = !draftApprovalMode || draftApprovalMode === currentApprovalMode; | ||
|
|
||
| const approvalModeOptions: Array<ApprovalModeListItem<T>> = [ | ||
| { | ||
| text: translate('workspace.hr.approvalModes.basic.label'), | ||
| alternateText: translate('workspace.hr.approvalModes.basic.description'), | ||
| keyForList: config.approvalModes.BASIC, | ||
| value: config.approvalModes.BASIC, | ||
| isSelected: selectedApprovalMode === config.approvalModes.BASIC, | ||
| }, | ||
| { | ||
| text: translate('workspace.hr.approvalModes.manager.label'), | ||
| alternateText: translate('workspace.hr.approvalModes.manager.description', providerName), | ||
| keyForList: config.approvalModes.MANAGER, | ||
| value: config.approvalModes.MANAGER, | ||
| isSelected: selectedApprovalMode === config.approvalModes.MANAGER, | ||
| }, | ||
| { | ||
| text: translate('workspace.hr.approvalModes.custom.label'), | ||
| alternateText: translate('workspace.hr.approvalModes.custom.description'), | ||
| keyForList: config.approvalModes.CUSTOM, | ||
| value: config.approvalModes.CUSTOM, | ||
| isSelected: selectedApprovalMode === config.approvalModes.CUSTOM, | ||
| }, | ||
| ]; | ||
| const selectedApprovalModeKey = approvalModeOptions.find((option) => option.isSelected)?.keyForList; | ||
|
|
||
| const saveApprovalMode = () => { | ||
| if (!draftApprovalMode) { | ||
| return; | ||
| } | ||
|
|
||
| config.handleSave({policyID, draftApprovalMode, currentApprovalMode, connectionSyncProgress}); | ||
| Navigation.goBack(); | ||
| }; | ||
|
|
||
| const confirmSaveApprovalMode = () => { | ||
| showConfirmModal({ | ||
| title: translate('workspace.hr.approvalModeWarningTitle'), | ||
| prompt: <RenderHTML html={translate('workspace.hr.approvalModeWarningPrompt', providerName, CONST.CONFIGURE_APPROVAL_WORKFLOWS_HELP_URL)} />, | ||
| confirmText: translate('workspace.hr.approvalModeWarningConfirm'), | ||
| cancelText: translate('common.cancel'), | ||
| }).then((result) => { | ||
| if (result?.action !== ModalActions.CONFIRM) { | ||
| return; | ||
| } | ||
| saveApprovalMode(); | ||
| }); | ||
| }; | ||
|
|
||
| return ( | ||
| <AccessOrNotFoundWrapper | ||
| accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN, CONST.POLICY.ACCESS_VARIANTS.CONTROL]} | ||
| policyID={policyID} | ||
| featureName={CONST.POLICY.MORE_FEATURES.IS_HR_ENABLED} | ||
| shouldBeBlocked={!isBetaEnabled(config.beta) || (!!policy && !config.isConnected(policy))} | ||
| > | ||
| <ScreenWrapper | ||
| enableEdgeToEdgeBottomSafeAreaPadding | ||
| shouldEnableMaxHeight | ||
| testID={config.testID} | ||
| > | ||
| <HeaderWithBackButton | ||
| title={config.getHeaderTitle(providerName)} | ||
| onBackButtonPress={() => Navigation.goBack()} | ||
| /> | ||
| <View style={styles.flex1}> | ||
| <Text style={[styles.textSupporting, styles.ph5, styles.mt3, styles.mb3]}>{translate('workspace.hr.approvalModeDescription', providerName)}</Text> | ||
| <SelectionList | ||
| data={approvalModeOptions} | ||
| ListItem={SingleSelectListItem} | ||
| onSelectRow={(option) => setDraftApprovalMode(option.value)} | ||
| shouldSingleExecuteRowSelect | ||
| initiallyFocusedItemKey={selectedApprovalModeKey} | ||
| alternateNumberOfSupportedLines={3} | ||
| showScrollIndicator={false} | ||
| /> | ||
| <FixedFooter style={styles.mtAuto}> | ||
| <Button | ||
| large | ||
| success | ||
| text={translate('common.save')} | ||
| onPress={confirmSaveApprovalMode} | ||
| isDisabled={isSaveDisabled} | ||
| /> | ||
| </FixedFooter> | ||
| </View> | ||
| </ScreenWrapper> | ||
| </AccessOrNotFoundWrapper> | ||
| ); | ||
| } | ||
|
|
||
| export default HRApprovalModePageBase; | ||
| export type {HRApprovalModeProviderConfig}; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ import useLocalize from '@hooks/useLocalize'; | |
| import useNetwork from '@hooks/useNetwork'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import {removePolicyConnection, syncConnection} from '@libs/actions/connections'; | ||
| import {clearMergeHRErrorField} from '@libs/actions/connections/MergeHR'; | ||
| import Navigation from '@libs/Navigation/Navigation'; | ||
| import CONST from '@src/CONST'; | ||
| import type Policy from '@src/types/onyx/Policy'; | ||
|
|
@@ -133,7 +134,11 @@ function HRProviderCard({card, policy, handleConnect}: HRProviderCardProps) { | |
| fallbackIcon={fallbackIcon} | ||
| /> | ||
| {card.isConnected && !!approvalModeRoute && ( | ||
| <OfflineWithFeedback pendingAction={card.config?.pendingFields?.approvalMode}> | ||
| <OfflineWithFeedback | ||
| pendingAction={card.config?.pendingFields?.approvalMode} | ||
| errors={card.config?.errorFields?.approvalMode} | ||
| onClose={() => clearMergeHRErrorField(policy?.id)} | ||
|
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. ❌ CONSISTENCY-6 (docs)The Pass the provider name as the second argument. The onClose={() => clearMergeHRErrorField(policy?.id, card.providerName)}Reviewed at: d0b9302 | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.
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. @jmusial this one is always early returning 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.
Useful? React with 👍 / 👎.
jmusial marked this conversation as resolved.
Outdated
|
||
| > | ||
| <MenuItemWithTopDescription | ||
| description={translate('workspace.hr.approvalMode')} | ||
| title={card.approvalModeLabel} | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think instead of making the params optional, we should update the type to be undefined-able.
This will prevent unintended bug like the on caught by AI here