Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,20 @@ type WorkspaceCompanyCardStatementCloseDateSelectionListProps = {
onSubmit: (statementCloseDate: CompanyCardStatementCloseDate, statementCustomCloseDate: number | undefined) => void;
onBackButtonPress: () => void;
enabledWhenOffline: boolean;
defaultDate?: CompanyCardStatementCloseDate;
};

function WorkspaceCompanyCardStatementCloseDateSelectionList({confirmText, onSubmit, onBackButtonPress, enabledWhenOffline}: WorkspaceCompanyCardStatementCloseDateSelectionListProps) {
function WorkspaceCompanyCardStatementCloseDateSelectionList({
confirmText,
onSubmit,
onBackButtonPress,
enabledWhenOffline,
defaultDate,
}: WorkspaceCompanyCardStatementCloseDateSelectionListProps) {
const {translate} = useLocalize();
const styles = useThemeStyles();

const [selectedDate, setSelectedDate] = useState<CompanyCardStatementCloseDate | undefined>(undefined);
const [selectedDate, setSelectedDate] = useState<CompanyCardStatementCloseDate | undefined>(defaultDate);
const [selectedCustomDate, setSelectedCustomDate] = useState<number | undefined>(undefined);
const [error, setError] = useState<string | undefined>(undefined);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import HeaderWithBackButton from '@components/HeaderWithBackButton';
import PlaidLink from '@components/PlaidLink';
import ScreenWrapper from '@components/ScreenWrapper';
import Text from '@components/Text';
import useEnvironment from '@hooks/useEnvironment';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useOnyx from '@hooks/useOnyx';
Expand All @@ -25,6 +26,7 @@ import type {CompanyCardFeed} from '@src/types/onyx';
import {isEmptyObject} from '@src/types/utils/EmptyObject';

function PlaidConnectionStep({feed}: {feed?: CompanyCardFeed}) {
const {isDevelopment} = useEnvironment();
const {translate} = useLocalize();
const styles = useThemeStyles();
const theme = useTheme();
Expand All @@ -40,6 +42,9 @@ function PlaidConnectionStep({feed}: {feed?: CompanyCardFeed}) {
const plaidDataErrorMessage = !isEmptyObject(plaidErrors) ? (Object.values(plaidErrors).at(0) as string) : '';
const {isOffline} = useNetwork();

// s77rt remove DEV lock
const shouldSelectStatementCloseDate = isDevelopment;

const isAuthenticatedWithPlaid = useCallback(() => !!plaidData?.bankAccounts?.length || !isEmptyObject(plaidData?.errors), [plaidData]);

/**
Expand Down Expand Up @@ -130,8 +135,9 @@ function PlaidConnectionStep({feed}: {feed?: CompanyCardFeed}) {
});
return;
}

setAddNewCompanyCardStepAndData({
step: CONST.COMPANY_CARDS.STEP.BANK_CONNECTION,
step: shouldSelectStatementCloseDate ? CONST.COMPANY_CARDS.STEP.SELECT_STATEMENT_CLOSE_DATE : CONST.COMPANY_CARDS.STEP.BANK_CONNECTION,
data: {
publicToken,
plaidConnectedFeed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, {useCallback} from 'react';
import useOnyx from 'react-native-onyx/dist/useOnyx';
import useCardFeeds from '@hooks/useCardFeeds';
import useLocalize from '@hooks/useLocalize';
import usePermissions from '@hooks/usePermissions';
import {addNewCompanyCardsFeed, setAddNewCompanyCardStepAndData} from '@libs/actions/CompanyCards';
import Navigation from '@libs/Navigation/Navigation';
import WorkspaceCompanyCardStatementCloseDateSelectionList from '@pages/workspace/companyCards/WorkspaceCompanyCardStatementCloseDateSelectionList';
Expand All @@ -17,36 +18,43 @@ type StatementCloseDateStepProps = {

function StatementCloseDateStep({policyID}: StatementCloseDateStepProps) {
const {translate} = useLocalize();

const {isBetaEnabled} = usePermissions();
const [addNewCard] = useOnyx(ONYXKEYS.ADD_NEW_COMPANY_CARD, {canBeMissing: false});
const [lastSelectedFeed] = useOnyx(`${ONYXKEYS.COLLECTION.LAST_SELECTED_FEED}${policyID}`, {canBeMissing: true});

const [cardFeeds] = useCardFeeds(policyID);

const isPlaid = isBetaEnabled(CONST.BETAS.PLAID_COMPANY_CARDS) && !!addNewCard?.data?.publicToken;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We released this beta to everyone, so no need to check for it here

Copy link
Member Author

@s77rt s77rt Jul 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied this logic from src/pages/workspace/companyCards/BankConnection/index.tsx I think it's okay to keep it for consistency. Ideally I think there should be a PR that removes that beta.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there will be a separate PR to remove this logic. We could also remove this instance in this PR, but NAB.


const submit = useCallback(
// s77rt make use of statementCloseDate / statementCustomCloseDate and remove disable lint rule
// eslint-disable-next-line @typescript-eslint/no-unused-vars
(statementCloseDate: CompanyCardStatementCloseDate, statementCustomCloseDate: number | undefined) => {
if (!addNewCard?.data.feedDetails) {
if (isPlaid) {
setAddNewCompanyCardStepAndData({
step: CONST.COMPANY_CARDS.STEP.BANK_CONNECTION,
});
return;
}

addNewCompanyCardsFeed(policyID, addNewCard.data.feedType, addNewCard.data.feedDetails, cardFeeds, lastSelectedFeed);
Navigation.goBack(ROUTES.WORKSPACE_COMPANY_CARDS.getRoute(policyID));
if (addNewCard?.data.feedDetails) {
addNewCompanyCardsFeed(policyID, addNewCard.data.feedType, addNewCard.data.feedDetails, cardFeeds, lastSelectedFeed);
Navigation.goBack(ROUTES.WORKSPACE_COMPANY_CARDS.getRoute(policyID));
}
},
[policyID, addNewCard, cardFeeds, lastSelectedFeed],
[policyID, addNewCard, cardFeeds, lastSelectedFeed, isPlaid],
);

const goBack = useCallback(() => {
setAddNewCompanyCardStepAndData({step: CONST.COMPANY_CARDS.STEP.CARD_DETAILS});
}, []);
setAddNewCompanyCardStepAndData({step: isPlaid ? CONST.COMPANY_CARDS.STEP.PLAID_CONNECTION : CONST.COMPANY_CARDS.STEP.CARD_DETAILS});
}, [isPlaid]);

return (
<WorkspaceCompanyCardStatementCloseDateSelectionList
confirmText={translate('common.submit')}
onSubmit={submit}
onBackButtonPress={goBack}
enabledWhenOffline={false}
defaultDate={CONST.COMPANY_CARDS.STATEMENT_CLOSE_DATE.LAST_DAY_OF_MONTH}
/>
);
}
Expand Down
Loading