Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/pages/workspace/companyCards/addNew/AddNewCardPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, {useEffect} from 'react';
import {useOnyx} from 'react-native-onyx';
import DelegateNoAccessWrapper from '@components/DelegateNoAccessWrapper';
import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
import ScreenWrapper from '@components/ScreenWrapper';
import useWorkspaceAccountID from '@hooks/useWorkspaceAccountID';
import BankConnection from '@pages/workspace/companyCards/BankConnection';
Expand All @@ -9,6 +10,7 @@ import type {WithPolicyAndFullscreenLoadingProps} from '@pages/workspace/withPol
import {openPolicyAddCardFeedPage} from '@userActions/CompanyCards';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue';
import AmexCustomFeed from './AmexCustomFeed';
import CardInstructionsStep from './CardInstructionsStep';
import CardNameStep from './CardNameStep';
Expand All @@ -20,11 +22,13 @@ import SelectFeedType from './SelectFeedType';
function AddNewCardPage({policy}: WithPolicyAndFullscreenLoadingProps) {
const policyID = policy?.id;
const workspaceAccountID = useWorkspaceAccountID(policyID);
const [addNewCardFeed] = useOnyx(ONYXKEYS.ADD_NEW_COMPANY_CARD, {canBeMissing: false});
const [addNewCardFeed, addNewCardFeedMetadata] = useOnyx(ONYXKEYS.ADD_NEW_COMPANY_CARD, {canBeMissing: false});
const {currentStep} = addNewCardFeed ?? {};

const [isActingAsDelegate] = useOnyx(ONYXKEYS.ACCOUNT, {selector: (account) => !!account?.delegatedAccess?.delegate, canBeMissing: false});

const isAddCardFeedLoading = isLoadingOnyxValue(addNewCardFeedMetadata);

useEffect(() => {
// If the user only has a domain feed, a workspace account may not have been created yet.
// However, adding a workspace feed requires a workspace account.
Expand All @@ -35,6 +39,10 @@ function AddNewCardPage({policy}: WithPolicyAndFullscreenLoadingProps) {
openPolicyAddCardFeedPage(policyID);
}, [workspaceAccountID, policyID]);

if (isAddCardFeedLoading) {
return <FullScreenLoadingIndicator />;
}

if (isActingAsDelegate) {
return (
<ScreenWrapper
Expand Down