Skip to content

Commit

Permalink
Merge pull request Expensify#51719 from callstack-internal/fix/51567-…
Browse files Browse the repository at this point in the history
…navigate-to-the-newly-created-feed
  • Loading branch information
mountiny authored Nov 5, 2024
2 parents 596671b + 4b9edae commit 6778419
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
28 changes: 26 additions & 2 deletions src/libs/actions/CompanyCards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,45 @@ function clearAddNewCardFlow() {
});
}

function addNewCompanyCardsFeed(policyID: string, feedType: string, feedDetails: string) {
function addNewCompanyCardsFeed(policyID: string, feedType: CompanyCardFeed, feedDetails: string, lastSelectedFeed?: CompanyCardFeed) {
const authToken = NetworkStore.getAuthToken();

if (!authToken) {
return;
}

const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.LAST_SELECTED_FEED}${policyID}`,
value: feedType,
},
];

const failureData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.LAST_SELECTED_FEED}${policyID}`,
value: lastSelectedFeed ?? null,
},
];

const successData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.LAST_SELECTED_FEED}${policyID}`,
value: feedType,
},
];

const parameters: RequestFeedSetupParams = {
policyID,
authToken,
feedType,
feedDetails,
};

API.write(WRITE_COMMANDS.REQUEST_FEED_SETUP, parameters);
API.write(WRITE_COMMANDS.REQUEST_FEED_SETUP, parameters, {optimisticData, failureData, successData});
}

function setWorkspaceCompanyCardFeedName(policyID: string, workspaceAccountID: number, bankName: string, userDefinedName: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ function WorkspaceCompanyCardsListHeaderButtons({policyID, selectedFeed}: Worksp
const workspaceAccountID = PolicyUtils.getWorkspaceAccountID(policyID);
const [cardFeeds] = useOnyx(`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER}${workspaceAccountID}`);
const shouldChangeLayout = isMediumScreenWidth || shouldUseNarrowLayout;
const feedName = cardFeeds?.settings?.companyCardNicknames?.[selectedFeed] ?? CardUtils.getCardFeedName(selectedFeed);
const feedName = CardUtils.getCardFeedName(selectedFeed);
const formattedFeedName = translate('workspace.companyCards.feedName', {feedName});
const isCustomFeed =
CONST.COMPANY_CARD.FEED_BANK_NAME.MASTER_CARD === selectedFeed || CONST.COMPANY_CARD.FEED_BANK_NAME.VISA === selectedFeed || CONST.COMPANY_CARD.FEED_BANK_NAME.AMEX === selectedFeed;
const currentFeedData = cardFeeds?.settings?.companyCards?.[selectedFeed] ?? {pending: true, errors: {}};

return (
<OfflineWithFeedback
Expand Down Expand Up @@ -78,7 +79,7 @@ function WorkspaceCompanyCardsListHeaderButtons({policyID, selectedFeed}: Worksp
<View style={[styles.flexRow, styles.gap2]}>
<Button
success
isDisabled={!!cardFeeds?.settings?.companyCards?.[selectedFeed].pending || !!cardFeeds?.settings?.companyCards?.[selectedFeed].errors}
isDisabled={currentFeedData.pending || !!currentFeedData.errors}
onPress={() => Navigation.navigate(ROUTES.WORKSPACE_COMPANY_CARDS_ASSIGN_CARD.getRoute(policyID, selectedFeed))}
icon={Expensicons.Plus}
text={translate('workspace.companyCards.assignCard')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import * as CompanyCards from '@userActions/CompanyCards';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type SCREENS from '@src/SCREENS';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import WorkspaceCompanyCardPageEmptyState from './WorkspaceCompanyCardPageEmptyState';
import WorkspaceCompanyCardsFeedPendingPage from './WorkspaceCompanyCardsFeedPendingPage';
import WorkspaceCompanyCardsList from './WorkspaceCompanyCardsList';
Expand All @@ -37,7 +38,7 @@ function WorkspaceCompanyCardPage({route}: WorkspaceCompanyCardPageProps) {
const isLoading = !cardFeeds || !!(cardFeeds.isLoading && !cardFeeds.settings);
const companyCards = CardUtils.removeExpensifyCardFromCompanyCards(cardFeeds?.settings?.companyCards);
const selectedCompanyCard = companyCards[selectedFeed ?? ''] ?? null;
const isNoFeed = !selectedCompanyCard;
const isNoFeed = isEmptyObject(companyCards) && !selectedCompanyCard;
const isPending = !!selectedCompanyCard?.pending;
const isFeedAdded = !isPending && !isNoFeed;

Expand Down
3 changes: 2 additions & 1 deletion src/pages/workspace/companyCards/addNew/DetailsStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function DetailsStep({policyID}: DetailsStepProps) {
const {inputCallbackRef} = useAutoFocusInput();
const {canUseDirectFeeds} = usePermissions();
const [addNewCard] = useOnyx(ONYXKEYS.ADD_NEW_COMPANY_CARD);
const [lastSelectedFeed] = useOnyx(`${ONYXKEYS.COLLECTION.LAST_SELECTED_FEED}${policyID}`);
const feedProvider = addNewCard?.data?.feedType;
const isStripeFeedProvider = feedProvider === CONST.COMPANY_CARD.FEED_BANK_NAME.STRIPE;
const bank = addNewCard?.data?.selectedBank;
Expand All @@ -55,7 +56,7 @@ function DetailsStep({policyID}: DetailsStepProps) {
.map(([key, value]) => `${key}: ${value}`)
.join(', ');

CompanyCards.addNewCompanyCardsFeed(policyID, addNewCard.data.feedType, feedDetails);
CompanyCards.addNewCompanyCardsFeed(policyID, addNewCard.data.feedType, feedDetails, lastSelectedFeed);
Navigation.navigate(ROUTES.WORKSPACE_COMPANY_CARDS.getRoute(policyID));
};

Expand Down

0 comments on commit 6778419

Please sign in to comment.