From 78548a85bb008d68f594127ac6736239252e47de Mon Sep 17 00:00:00 2001 From: Artem Makushov Date: Sat, 21 Dec 2024 03:18:40 +0100 Subject: [PATCH] add new step --- .../BankConnection/index.native.tsx | 90 ++++++++++++++++++ .../assignCard/BankConnection/index.tsx | 92 +++++++++++++++++++ .../openBankConnection/index.tsx | 5 + .../openBankConnection/index.website.tsx | 14 +++ 4 files changed, 201 insertions(+) create mode 100644 src/pages/workspace/companyCards/assignCard/BankConnection/index.native.tsx create mode 100644 src/pages/workspace/companyCards/assignCard/BankConnection/index.tsx create mode 100644 src/pages/workspace/companyCards/assignCard/BankConnection/openBankConnection/index.tsx create mode 100644 src/pages/workspace/companyCards/assignCard/BankConnection/openBankConnection/index.website.tsx diff --git a/src/pages/workspace/companyCards/assignCard/BankConnection/index.native.tsx b/src/pages/workspace/companyCards/assignCard/BankConnection/index.native.tsx new file mode 100644 index 000000000000..d9e622ebc08d --- /dev/null +++ b/src/pages/workspace/companyCards/assignCard/BankConnection/index.native.tsx @@ -0,0 +1,90 @@ +import React, {useEffect, useRef} from 'react'; +import {useOnyx} from 'react-native-onyx'; +import {WebView} from 'react-native-webview'; +import FullPageOfflineBlockingView from '@components/BlockingViews/FullPageOfflineBlockingView'; +import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator'; +import HeaderWithBackButton from '@components/HeaderWithBackButton'; +import ScreenWrapper from '@components/ScreenWrapper'; +import useLocalize from '@hooks/useLocalize'; +import * as CardUtils from '@libs/CardUtils'; +import getUAForWebView from '@libs/getUAForWebView'; +import Navigation from '@libs/Navigation/Navigation'; +import * as PolicyUtils from '@libs/PolicyUtils'; +import * as CompanyCards from '@userActions/CompanyCards'; +import getCompanyCardBankConnection from '@userActions/getCompanyCardBankConnection'; +import CONST from '@src/CONST'; +import ONYXKEYS from '@src/ONYXKEYS'; +import type {CompanyCardFeed} from '@src/types/onyx'; + +type BankConnectionStepProps = { + policyID?: string; + + /** Selected feed */ + feed: CompanyCardFeed; +}; + +function BankConnection({policyID, feed}: BankConnectionStepProps) { + const {translate} = useLocalize(); + const webViewRef = useRef(null); + const [session] = useOnyx(ONYXKEYS.SESSION); + const authToken = session?.authToken ?? null; + const bankName = CardUtils.getCardFeedName(feed); + const url = getCompanyCardBankConnection(policyID, bankName); + const workspaceAccountID = PolicyUtils.getWorkspaceAccountID(policyID ?? '-1'); + const [cardFeeds] = useOnyx(`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER}${workspaceAccountID}`); + const isFeedExpired = CardUtils.isSelectedFeedExpired(cardFeeds?.settings?.oAuthAccountDetails?.[feed]); + + const renderLoading = () => ; + + const handleBackButtonPress = () => { + Navigation.goBack(); + }; + + useEffect(() => { + if (!url) { + return; + } + if (!isFeedExpired) { + CompanyCards.setAssignCardStepAndData({ + currentStep: CONST.COMPANY_CARD.STEP.ASSIGNEE, + isEditing: false, + }); + } + }, [isFeedExpired, url]); + + return ( + + + + {!!url && ( + + )} + + + ); +} + +BankConnection.displayName = 'BankConnection'; + +export default BankConnection; diff --git a/src/pages/workspace/companyCards/assignCard/BankConnection/index.tsx b/src/pages/workspace/companyCards/assignCard/BankConnection/index.tsx new file mode 100644 index 000000000000..c29f24437791 --- /dev/null +++ b/src/pages/workspace/companyCards/assignCard/BankConnection/index.tsx @@ -0,0 +1,92 @@ +import React, {useCallback, useEffect} from 'react'; +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 * as CardUtils from '@libs/CardUtils'; +import Navigation from '@libs/Navigation/Navigation'; +import getCurrentUrl from '@navigation/currentUrl'; +import * as CompanyCards from '@userActions/CompanyCards'; +import getCompanyCardBankConnection from '@userActions/getCompanyCardBankConnection'; +import CONST from '@src/CONST'; +import ROUTES from '@src/ROUTES'; +import type {CompanyCardFeed} from '@src/types/onyx'; +import openBankConnection from './openBankConnection'; + +let customWindow: Window | null = null; + +type BankConnectionStepProps = { + policyID?: string; + + /** Selected feed */ + feed: CompanyCardFeed; +}; + +function BankConnection({policyID, feed}: BankConnectionStepProps) { + const styles = useThemeStyles(); + const {translate} = useLocalize(); + const bankName = CardUtils.getCardFeedName(feed); + const currentUrl = getCurrentUrl(); + const isBankConnectionCompleteRoute = currentUrl.includes(ROUTES.BANK_CONNECTION_COMPLETE); + const url = getCompanyCardBankConnection(policyID, bankName); + + const onOpenBankConnectionFlow = useCallback(() => { + if (!url) { + return; + } + customWindow = openBankConnection(url); + }, [url]); + + const handleBackButtonPress = () => { + Navigation.goBack(); + }; + + const CustomSubtitle = ( + + {bankName && translate(`workspace.moreFeatures.companyCards.pendingBankDescription`, {bankName})} + {translate('workspace.moreFeatures.companyCards.pendingBankLink')} + + ); + + useEffect(() => { + if (!url) { + return; + } + if (isBankConnectionCompleteRoute) { + customWindow?.close(); + CompanyCards.setAssignCardStepAndData({ + currentStep: CONST.COMPANY_CARD.STEP.ASSIGNEE, + isEditing: false, + }); + return; + } + customWindow = openBankConnection(url); + }, [isBankConnectionCompleteRoute, policyID, url]); + + return ( + + + + + ); +} + +BankConnection.displayName = 'BankConnection'; + +export default BankConnection; diff --git a/src/pages/workspace/companyCards/assignCard/BankConnection/openBankConnection/index.tsx b/src/pages/workspace/companyCards/assignCard/BankConnection/openBankConnection/index.tsx new file mode 100644 index 000000000000..91a81bdbd6c6 --- /dev/null +++ b/src/pages/workspace/companyCards/assignCard/BankConnection/openBankConnection/index.tsx @@ -0,0 +1,5 @@ +const handleOpenBankConnectionFlow = (url: string) => { + return window.open(url, '_blank'); +}; + +export default handleOpenBankConnectionFlow; diff --git a/src/pages/workspace/companyCards/assignCard/BankConnection/openBankConnection/index.website.tsx b/src/pages/workspace/companyCards/assignCard/BankConnection/openBankConnection/index.website.tsx new file mode 100644 index 000000000000..220404cee0e7 --- /dev/null +++ b/src/pages/workspace/companyCards/assignCard/BankConnection/openBankConnection/index.website.tsx @@ -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;