-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Connect to sage intacct #43661
Connect to sage intacct #43661
Changes from all commits
75fd912
2baa77a
c223592
f17c09f
78e810d
9464001
b3867f7
fd12010
b28456e
096f9dd
f6c0528
dc01b0b
720e8a4
8f448b1
530a407
93b5aa0
277f574
722ceed
aa1ed19
1d85d00
7f1d7a4
29266a5
518dbce
3a55954
7fccce5
9db4670
5f37695
88bf2cd
cd814a9
73c4418
ef45f0e
5ca6e4f
6349f17
ed9e7f8
4d05367
984447a
3c0f992
173fcd8
510c45e
a84a85d
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 |
---|---|---|
@@ -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, | ||
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 enabled if 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. Modal containing these options will pop up only when |
||
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) { | ||
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. I am a little confused on why do we need this? 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. |
||
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; |
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; |
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.
NAB: Why move this it was in alphabetical order already 🤔