-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43661 from software-mansion-labs/@szymczak/connec…
…t-to-sage-intacct Connect to sage intacct
- Loading branch information
Showing
32 changed files
with
924 additions
and
38 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions
23
assets/images/integrationicons/sage-intacct-icon-square.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,128 @@ | ||
import React, {useRef, useState} from 'react'; | ||
import type {View} from 'react-native'; | ||
import AccountingConnectionConfirmationModal from '@components/AccountingConnectionConfirmationModal'; | ||
import Button from '@components/Button'; | ||
import * as Expensicons from '@components/Icon/Expensicons'; | ||
import PopoverMenu from '@components/PopoverMenu'; | ||
import useLocalize from '@hooks/useLocalize'; | ||
import useNetwork from '@hooks/useNetwork'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import useWindowDimensions from '@hooks/useWindowDimensions'; | ||
import {removePolicyConnection} from '@libs/actions/connections'; | ||
import {getPoliciesConnectedToSageIntacct} from '@libs/actions/Policy/Policy'; | ||
import Navigation from '@libs/Navigation/Navigation'; | ||
import type {AnchorPosition} from '@styles/index'; | ||
import CONST from '@src/CONST'; | ||
import ROUTES from '@src/ROUTES'; | ||
import type {PolicyConnectionName} from '@src/types/onyx/Policy'; | ||
|
||
type ConnectToSageIntacctButtonProps = { | ||
policyID: string; | ||
shouldDisconnectIntegrationBeforeConnecting?: boolean; | ||
integrationToDisconnect?: PolicyConnectionName; | ||
}; | ||
|
||
function ConnectToSageIntacctButton({policyID, shouldDisconnectIntegrationBeforeConnecting, integrationToDisconnect}: ConnectToSageIntacctButtonProps) { | ||
const styles = useThemeStyles(); | ||
const {translate} = useLocalize(); | ||
const {isOffline} = useNetwork(); | ||
|
||
const [isDisconnectModalOpen, setIsDisconnectModalOpen] = useState(false); | ||
|
||
const hasPoliciesConnectedToSageIntacct = !!getPoliciesConnectedToSageIntacct().length; | ||
const {isSmallScreenWidth} = useWindowDimensions(); | ||
const [isReuseConnectionsPopoverOpen, setIsReuseConnectionsPopoverOpen] = useState(false); | ||
const [reuseConnectionPopoverPosition, setReuseConnectionPopoverPosition] = useState<AnchorPosition>({horizontal: 0, vertical: 0}); | ||
const threeDotsMenuContainerRef = useRef<View>(null); | ||
const connectionOptions = [ | ||
{ | ||
icon: Expensicons.LinkCopy, | ||
text: translate('workspace.intacct.createNewConnection'), | ||
onSelected: () => { | ||
Navigation.navigate(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_PREREQUISITES.getRoute(policyID)); | ||
setIsReuseConnectionsPopoverOpen(false); | ||
}, | ||
}, | ||
{ | ||
icon: Expensicons.Copy, | ||
text: translate('workspace.intacct.reuseExistingConnection'), | ||
onSelected: () => { | ||
Navigation.navigate(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_EXISTING_CONNECTIONS.getRoute(policyID)); | ||
setIsReuseConnectionsPopoverOpen(false); | ||
}, | ||
}, | ||
]; | ||
|
||
return ( | ||
<> | ||
<Button | ||
onPress={() => { | ||
if (shouldDisconnectIntegrationBeforeConnecting && integrationToDisconnect) { | ||
setIsDisconnectModalOpen(true); | ||
return; | ||
} | ||
if (!hasPoliciesConnectedToSageIntacct) { | ||
Navigation.navigate(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_PREREQUISITES.getRoute(policyID)); | ||
return; | ||
} | ||
if (!isSmallScreenWidth) { | ||
threeDotsMenuContainerRef.current?.measureInWindow((x, y, width, height) => { | ||
setReuseConnectionPopoverPosition({ | ||
horizontal: x + width, | ||
vertical: y + height, | ||
}); | ||
}); | ||
} | ||
setIsReuseConnectionsPopoverOpen(true); | ||
}} | ||
text={translate('workspace.accounting.setup')} | ||
style={styles.justifyContentCenter} | ||
small | ||
isDisabled={isOffline} | ||
ref={threeDotsMenuContainerRef} | ||
/> | ||
<PopoverMenu | ||
isVisible={isReuseConnectionsPopoverOpen} | ||
onClose={() => { | ||
setIsReuseConnectionsPopoverOpen(false); | ||
}} | ||
withoutOverlay | ||
menuItems={connectionOptions} | ||
onItemSelected={(item) => { | ||
if (!item?.onSelected) { | ||
return; | ||
} | ||
item.onSelected(); | ||
}} | ||
anchorPosition={reuseConnectionPopoverPosition} | ||
anchorAlignment={{horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.RIGHT, vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.TOP}} | ||
anchorRef={threeDotsMenuContainerRef} | ||
/> | ||
{shouldDisconnectIntegrationBeforeConnecting && isDisconnectModalOpen && integrationToDisconnect && ( | ||
<AccountingConnectionConfirmationModal | ||
onConfirm={() => { | ||
removePolicyConnection(policyID, integrationToDisconnect); | ||
setIsDisconnectModalOpen(false); | ||
if (!hasPoliciesConnectedToSageIntacct) { | ||
Navigation.navigate(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_PREREQUISITES.getRoute(policyID)); | ||
return; | ||
} | ||
if (!isSmallScreenWidth) { | ||
threeDotsMenuContainerRef.current?.measureInWindow((x, y, width, height) => { | ||
setReuseConnectionPopoverPosition({ | ||
horizontal: x + width, | ||
vertical: y + height, | ||
}); | ||
}); | ||
} | ||
setIsReuseConnectionsPopoverOpen(true); | ||
}} | ||
integrationToConnect={CONST.POLICY.CONNECTIONS.NAME.SAGE_INTACCT} | ||
onCancel={() => setIsDisconnectModalOpen(false)} | ||
/> | ||
)} | ||
</> | ||
); | ||
} | ||
|
||
export default ConnectToSageIntacctButton; |
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,8 @@ | ||
type ConnectPolicyToSageIntacctParams = { | ||
policyID: string; | ||
intacctCompanyID: string; | ||
intacctUserID: string; | ||
intacctPassword: string; | ||
}; | ||
|
||
export default ConnectPolicyToSageIntacctParams; |
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
Oops, something went wrong.