-
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 #50716 from narefyev91/company-cards-bank-ui
Company Cards - Bank UI
- Loading branch information
Showing
15 changed files
with
519 additions
and
1 deletion.
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.
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
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,34 @@ | ||
import {getApiRoot} from '@libs/ApiUtils'; | ||
import * as NetworkStore from '@libs/Network/NetworkStore'; | ||
import CONST from '@src/CONST'; | ||
|
||
type CompanyCardBankConnection = { | ||
authToken: string; | ||
domainName: string; | ||
scrapeMinDate: string; | ||
isCorporate: string; | ||
}; | ||
|
||
// TODO remove this when BE will support bank UI callbacks | ||
const bankUrl = 'https://secure.chase.com/web/auth/#/logon/logon/chaseOnline?redirect_url='; | ||
|
||
export default function getCompanyCardBankConnection(bankName?: string, domainName?: string, scrapeMinDate?: string) { | ||
const bankConnection = Object.keys(CONST.COMPANY_CARDS.BANKS).find((key) => CONST.COMPANY_CARDS.BANKS[key as keyof typeof CONST.COMPANY_CARDS.BANKS] === bankName); | ||
|
||
// TODO remove this when BE will support bank UI callbacks | ||
if (!domainName) { | ||
return bankUrl; | ||
} | ||
|
||
if (!bankName || !bankConnection) { | ||
return null; | ||
} | ||
const authToken = NetworkStore.getAuthToken(); | ||
const params: CompanyCardBankConnection = {authToken: authToken ?? '', domainName: domainName ?? '', isCorporate: 'true', scrapeMinDate: scrapeMinDate ?? ''}; | ||
const commandURL = getApiRoot({ | ||
shouldSkipWebProxy: true, | ||
command: '', | ||
}); | ||
const bank = CONST.COMPANY_CARDS.BANK_CONNECTIONS[bankConnection as keyof typeof CONST.COMPANY_CARDS.BANK_CONNECTIONS]; | ||
return `${commandURL}partners/banks/${bank}/oauth_callback.php?${new URLSearchParams(params).toString()}`; | ||
} |
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
79 changes: 79 additions & 0 deletions
79
src/pages/workspace/companyCards/addNew/BankConnection/index.native.tsx
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,79 @@ | ||
import React, {useEffect, useRef, useState} from 'react'; | ||
import {useOnyx} from 'react-native-onyx'; | ||
import {WebView} from 'react-native-webview'; | ||
import type {ValueOf} from 'type-fest'; | ||
import FullPageOfflineBlockingView from '@components/BlockingViews/FullPageOfflineBlockingView'; | ||
import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator'; | ||
import HeaderWithBackButton from '@components/HeaderWithBackButton'; | ||
import Modal from '@components/Modal'; | ||
import useLocalize from '@hooks/useLocalize'; | ||
import getUAForWebView from '@libs/getUAForWebView'; | ||
import * as CompanyCards from '@userActions/CompanyCards'; | ||
import getCompanyCardBankConnection from '@userActions/getCompanyCardBankConnection'; | ||
import CONST from '@src/CONST'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
|
||
function BankConnection() { | ||
const {translate} = useLocalize(); | ||
const webViewRef = useRef<WebView>(null); | ||
const [isWebViewOpen, setWebViewOpen] = useState(false); | ||
const [session] = useOnyx(ONYXKEYS.SESSION); | ||
const authToken = session?.authToken ?? null; | ||
const [addNewCard] = useOnyx(ONYXKEYS.ADD_NEW_COMPANY_CARD); | ||
const bankName: ValueOf<typeof CONST.COMPANY_CARDS.BANKS> | undefined = addNewCard?.data?.selectedBank; | ||
const url = getCompanyCardBankConnection(bankName); | ||
|
||
const renderLoading = () => <FullScreenLoadingIndicator />; | ||
|
||
const handleBackButtonPress = () => { | ||
setWebViewOpen(false); | ||
if (bankName === CONST.COMPANY_CARDS.BANKS.BREX) { | ||
CompanyCards.setAddNewCompanyCardStepAndData({step: CONST.COMPANY_CARDS.STEP.SELECT_BANK}); | ||
return; | ||
} | ||
if (bankName === CONST.COMPANY_CARDS.BANKS.AMEX) { | ||
CompanyCards.setAddNewCompanyCardStepAndData({step: CONST.COMPANY_CARDS.STEP.AMEX_CUSTOM_FEED}); | ||
return; | ||
} | ||
CompanyCards.setAddNewCompanyCardStepAndData({step: CONST.COMPANY_CARDS.STEP.SELECT_FEED_TYPE}); | ||
}; | ||
|
||
useEffect(() => { | ||
setWebViewOpen(true); | ||
}, []); | ||
|
||
return ( | ||
<Modal | ||
onClose={handleBackButtonPress} | ||
fullscreen | ||
isVisible={isWebViewOpen} | ||
type={CONST.MODAL.MODAL_TYPE.CENTERED_UNSWIPEABLE} | ||
> | ||
<HeaderWithBackButton | ||
title={translate('workspace.companyCards.addCardFeed')} | ||
onBackButtonPress={handleBackButtonPress} | ||
/> | ||
<FullPageOfflineBlockingView> | ||
{url && ( | ||
<WebView | ||
ref={webViewRef} | ||
source={{ | ||
uri: url, | ||
headers: { | ||
Cookie: `authToken=${authToken}`, | ||
}, | ||
}} | ||
userAgent={getUAForWebView()} | ||
incognito | ||
startInLoadingState | ||
renderLoading={renderLoading} | ||
/> | ||
)} | ||
</FullPageOfflineBlockingView> | ||
</Modal> | ||
); | ||
} | ||
|
||
BankConnection.displayName = 'BankConnection'; | ||
|
||
export default BankConnection; |
91 changes: 91 additions & 0 deletions
91
src/pages/workspace/companyCards/addNew/BankConnection/index.tsx
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,91 @@ | ||
import React, {useCallback, useEffect} from 'react'; | ||
import {useOnyx} from 'react-native-onyx'; | ||
import type {ValueOf} from 'type-fest'; | ||
import BlockingView from '@components/BlockingViews/BlockingView'; | ||
import HeaderWithBackButton from '@components/HeaderWithBackButton'; | ||
import * as Illustrations from '@components/Icon/Illustrations'; | ||
import ScreenWrapper from '@components/ScreenWrapper'; | ||
import Text from '@components/Text'; | ||
import TextLink from '@components/TextLink'; | ||
import useLocalize from '@hooks/useLocalize'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import getCurrentUrl from '@navigation/currentUrl'; | ||
import * as CompanyCards from '@userActions/CompanyCards'; | ||
import getCompanyCardBankConnection from '@userActions/getCompanyCardBankConnection'; | ||
import CONST from '@src/CONST'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import ROUTES from '@src/ROUTES'; | ||
import openBankConnection from './openBankConnection'; | ||
|
||
let customWindow: Window | null = null; | ||
|
||
function BankConnection() { | ||
const styles = useThemeStyles(); | ||
const {translate} = useLocalize(); | ||
const [addNewCard] = useOnyx(ONYXKEYS.ADD_NEW_COMPANY_CARD); | ||
const bankName: ValueOf<typeof CONST.COMPANY_CARDS.BANKS> | undefined = addNewCard?.data?.selectedBank; | ||
const currentUrl = getCurrentUrl(); | ||
const isBankConnectionCompleteRoute = currentUrl.includes(ROUTES.BANK_CONNECTION_COMPLETE); | ||
const url = getCompanyCardBankConnection(bankName); | ||
|
||
const onOpenBankConnectionFlow = useCallback(() => { | ||
if (!url) { | ||
return; | ||
} | ||
customWindow = openBankConnection(url); | ||
}, [url]); | ||
|
||
const handleBackButtonPress = () => { | ||
customWindow?.close(); | ||
if (bankName === CONST.COMPANY_CARDS.BANKS.BREX) { | ||
CompanyCards.setAddNewCompanyCardStepAndData({step: CONST.COMPANY_CARDS.STEP.SELECT_BANK}); | ||
return; | ||
} | ||
if (bankName === CONST.COMPANY_CARDS.BANKS.AMEX) { | ||
CompanyCards.setAddNewCompanyCardStepAndData({step: CONST.COMPANY_CARDS.STEP.AMEX_CUSTOM_FEED}); | ||
return; | ||
} | ||
CompanyCards.setAddNewCompanyCardStepAndData({step: CONST.COMPANY_CARDS.STEP.SELECT_FEED_TYPE}); | ||
}; | ||
|
||
const CustomSubtitle = ( | ||
<Text style={[styles.textAlignCenter, styles.textSupporting]}> | ||
{bankName && translate(`workspace.moreFeatures.companyCards.pendingBankDescription`, {bankName})} | ||
<TextLink onPress={onOpenBankConnectionFlow}>{translate('workspace.moreFeatures.companyCards.pendingBankLink')}</TextLink> | ||
</Text> | ||
); | ||
|
||
useEffect(() => { | ||
if (!url) { | ||
return; | ||
} | ||
if (isBankConnectionCompleteRoute) { | ||
customWindow?.close(); | ||
return; | ||
} | ||
customWindow = openBankConnection(url); | ||
}, [isBankConnectionCompleteRoute, url]); | ||
|
||
return ( | ||
<ScreenWrapper testID={BankConnection.displayName}> | ||
<HeaderWithBackButton | ||
title={translate('workspace.companyCards.addCardFeed')} | ||
onBackButtonPress={handleBackButtonPress} | ||
/> | ||
<BlockingView | ||
icon={Illustrations.PendingBank} | ||
iconWidth={styles.pendingBankCardIllustration.width} | ||
iconHeight={styles.pendingBankCardIllustration.height} | ||
title={translate('workspace.moreFeatures.companyCards.pendingBankTitle')} | ||
linkKey="workspace.moreFeatures.companyCards.pendingBankLink" | ||
CustomSubtitle={CustomSubtitle} | ||
shouldShowLink | ||
onLinkPress={onOpenBankConnectionFlow} | ||
/> | ||
</ScreenWrapper> | ||
); | ||
} | ||
|
||
BankConnection.displayName = 'BankConnection'; | ||
|
||
export default BankConnection; |
5 changes: 5 additions & 0 deletions
5
src/pages/workspace/companyCards/addNew/BankConnection/openBankConnection/index.tsx
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,5 @@ | ||
const handleOpenBankConnectionFlow = (url: string) => { | ||
return window.open(url, '_blank'); | ||
}; | ||
|
||
export default handleOpenBankConnectionFlow; |
14 changes: 14 additions & 0 deletions
14
src/pages/workspace/companyCards/addNew/BankConnection/openBankConnection/index.website.tsx
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,14 @@ | ||
const WINDOW_WIDTH = 700; | ||
const WINDOW_HEIGHT = 600; | ||
|
||
const handleOpenBankConnectionFlow = (url: string) => { | ||
const screenWidth = window.screen.width; | ||
const screenHeight = window.screen.height; | ||
const left = (screenWidth - WINDOW_WIDTH) / 2; | ||
const top = (screenHeight - WINDOW_HEIGHT) / 2; | ||
const popupFeatures = `width=${WINDOW_WIDTH},height=${WINDOW_HEIGHT},left=${left},top=${top},scrollbars=yes,resizable=yes`; | ||
|
||
return window.open(url, 'popupWindow', popupFeatures); | ||
}; | ||
|
||
export default handleOpenBankConnectionFlow; |
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