Skip to content
Open
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 @@ -81,6 +81,9 @@ function WorkspaceCompanyCardFeedSelectorPage({route}: WorkspaceCompanyCardFeedS
const otherFeeds = useOtherFeedsForFeedSelector(policyID);
const primaryContactMethod = usePrimaryContactMethod();

const [draftFeed, setDraftFeed] = useState<CompanyCardFeedWithDomainID>();
const currentSelectedFeed = draftFeed ?? selectedFeedName;

const isUserFromPublicDomain = isEmailPublicDomain(primaryContactMethod);

const feeds: CardFeedListItem[] = (Object.entries(companyCardFeeds ?? {}) as Array<[CompanyCardFeedWithDomainID, CombinedCardFeed]>).map(([feedName, feedSettings]) => {
Expand All @@ -98,7 +101,7 @@ function WorkspaceCompanyCardFeedSelectorPage({route}: WorkspaceCompanyCardFeedS
alternateText: domainName ?? policyName,
text: getCustomOrFormattedFeedName(translate, feedSettings.feed, feedSettings.customFeedName),
keyForList: feedName,
isSelected: feedName === selectedFeedName,
isSelected: feedName === currentSelectedFeed,
isDisabled: feedSettings.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
pendingAction: feedSettings.pendingAction,
brickRoadIndicator: shouldShowRBR ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined,
Expand Down Expand Up @@ -137,10 +140,24 @@ function WorkspaceCompanyCardFeedSelectorPage({route}: WorkspaceCompanyCardFeedS
const goBack = () => Navigation.goBack(ROUTES.WORKSPACE_COMPANY_CARDS.getRoute(policyID));

const selectFeed = (feed: CardFeedListItem) => {
updateSelectedFeed(feed.value, policyID);
setDraftFeed(feed.value);
};

const saveFeed = () => {
if (!currentSelectedFeed) {
return;
}
updateSelectedFeed(currentSelectedFeed, policyID);
goBack();
};

const confirmButtonOptions = {
showButton: true,
text: translate('common.save'),
onConfirm: saveFeed,
isDisabled: !currentSelectedFeed || currentSelectedFeed === selectedFeedName,
};

const selectOtherFeed = (feed: CardFeedListItem) => {
if (isUserFromPublicDomain) {
Navigation.navigate(ROUTES.WORKSPACE_COMPANY_CARD_ADD_WORK_EMAIL.getRoute(policyID, feed.value));
Expand Down Expand Up @@ -233,6 +250,7 @@ function WorkspaceCompanyCardFeedSelectorPage({route}: WorkspaceCompanyCardFeedS
data={feeds}
alternateNumberOfSupportedLines={2}
initiallyFocusedItemKey={selectedFeedName}
confirmButtonOptions={confirmButtonOptions}
addBottomSafeAreaPadding
listFooterContent={otherMenuItemFeeds}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ function WorkspaceExpensifyCardFeedSelectorPage({route}: WorkspaceExpensifyCardF
const primaryContactMethod = usePrimaryContactMethod();
const defaultFundID = useDefaultFundID(policyID);
const lastSelectedExpensifyCardFeedID = lastSelectedExpensifyCardFeed ?? defaultFundID;
const [draftFundID, setDraftFundID] = useState<number>();
const currentSelectedFundID = draftFundID ?? lastSelectedExpensifyCardFeedID;
const [feedWithError, setFeedWithError] = useState<{fundID?: number; error?: Errors} | undefined>(undefined);
const {login: currentUserLogin = ''} = useCurrentUserPersonalDetails();

Expand Down Expand Up @@ -138,7 +140,7 @@ function WorkspaceExpensifyCardFeedSelectorPage({route}: WorkspaceExpensifyCardF
value: entry.fundID,
text: getExpensifyCardFeedDescription(entry.settings, policies, domains, entry.fundID, cardList),
keyForList: entry.fundID.toString(),
isSelected: entry.fundID === lastSelectedExpensifyCardFeedID,
isSelected: entry.fundID === currentSelectedFundID,
isDisabled: isFeedPendingDelete || (isOtherWorkspaceSection && isOffline),
pendingAction: entry.settings.pendingAction,
errors: feedWithError?.fundID === entry.fundID ? feedWithError.error : undefined,
Expand Down Expand Up @@ -193,11 +195,25 @@ function WorkspaceExpensifyCardFeedSelectorPage({route}: WorkspaceExpensifyCardF
};

const selectFeed = (feed: ExpensifyFeedListItem) => {
setDraftFundID(feed.value);
};
Comment on lines 197 to +199

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Apply the draft before starting card issuance

When multiple primary feeds exist, selecting feed B now only updates draftFundID, but the still-visible Issue card footer continues to derive issueCardFundID from lastSelectedExpensifyCardFeedID. If the user selects B and then taps Issue card without first pressing Save, handleAddCardPress writes the old feed A back to Onyx, and the issuance flow uses that old feed via useDefaultFundID, potentially issuing the card under the wrong program. Derive this footer action from currentSelectedFundID or disable it until the draft has been saved.

Useful? React with 👍 / 👎.


const saveFeed = () => {
if (!currentSelectedFundID) {
return;
}
resetCardFlowState();
updateSelectedExpensifyCardFeed(feed.value, policyID);
updateSelectedExpensifyCardFeed(currentSelectedFundID, policyID);
goBack();
};

const confirmButtonOptions = {
showButton: true,
text: translate('common.save'),
onConfirm: saveFeed,
isDisabled: !currentSelectedFundID || currentSelectedFundID === lastSelectedExpensifyCardFeedID,
};

const primaryListData = primaryFeeds.map((entry) => toListItem(entry, false));

const issueNewCardAndOtherFeedsFooter = canWriteExpensifyCard ? (
Expand Down Expand Up @@ -258,6 +274,7 @@ function WorkspaceExpensifyCardFeedSelectorPage({route}: WorkspaceExpensifyCardF
data={primaryListData}
alternateNumberOfSupportedLines={2}
initiallyFocusedItemKey={lastSelectedExpensifyCardFeedID.toString()}
confirmButtonOptions={confirmButtonOptions}
addBottomSafeAreaPadding
listFooterContent={issueNewCardAndOtherFeedsFooter}
onDismissError={onDismissError}
Expand Down
Loading