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 @@ -28,7 +28,7 @@ function SelectBankStep() {
const {isOffline} = useNetwork();

const [addNewPersonalCard] = useOnyx(ONYXKEYS.ADD_NEW_PERSONAL_CARD);
const [bankSelected, setBankSelected] = useState<ValueOf<typeof CONST.PERSONAL_CARDS.BANKS> | null | undefined>(addNewPersonalCard?.data.selectedBank);
const [bankSelected, setBankSelected] = useState<ValueOf<typeof CONST.PERSONAL_CARDS.BANKS> | null | undefined>(addNewPersonalCard?.data?.selectedBank);
const [hasError, setHasError] = useState(false);
const isOtherBankSelected = bankSelected === CONST.PERSONAL_CARDS.BANKS.OTHER;

Expand Down Expand Up @@ -85,7 +85,7 @@ function SelectBankStep() {
setBankSelected(value);
setHasError(false);
}}
initiallyFocusedItemKey={addNewPersonalCard?.data.selectedBank ?? undefined}
initiallyFocusedItemKey={addNewPersonalCard?.data?.selectedBank ?? undefined}
confirmButtonOptions={{
showButton: true,
text: translate('common.next'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function SelectCountryStep({disableAutoFocus}: {disableAutoFocus?: boolean}) {
if (!currentCountry || !CONST.PLAID_SUPPORT_COUNTRIES.includes(currentCountry)) {
setHasError(true);
} else {
if (addNewPersonalCard?.data.selectedCountry !== currentCountry) {
if (addNewPersonalCard?.data?.selectedCountry !== currentCountry) {
clearAddNewPersonalCardFlow();
}
setAddNewPersonalCardStepAndData({
Expand Down
4 changes: 2 additions & 2 deletions src/pages/workspace/companyCards/addNew/AmexCustomFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function AmexCustomFeed() {
const styles = useThemeStyles();
const [addNewCard] = useOnyx(ONYXKEYS.ADD_NEW_COMPANY_CARD);
const [localTypeSelected, setLocalTypeSelected] = useState<ValueOf<typeof CONST.COMPANY_CARDS.AMEX_CUSTOM_FEED>>();
const typeSelected = localTypeSelected ?? addNewCard?.data.selectedAmexCustomFeed;
const typeSelected = localTypeSelected ?? addNewCard?.data?.selectedAmexCustomFeed;
const [hasError, setHasError] = useState(false);

const submit = () => {
Expand Down Expand Up @@ -96,7 +96,7 @@ function AmexCustomFeed() {
confirmButtonOptions={confirmButtonOptions}
shouldSingleExecuteRowSelect
alternateNumberOfSupportedLines={3}
initiallyFocusedItemKey={addNewCard?.data.selectedAmexCustomFeed ?? undefined}
initiallyFocusedItemKey={addNewCard?.data?.selectedAmexCustomFeed ?? undefined}
shouldUpdateFocusedIndex
addBottomSafeAreaPadding
>
Expand Down
6 changes: 3 additions & 3 deletions src/pages/workspace/companyCards/addNew/CardTypeStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function CardTypeStep() {
const companyCardBankIcons = useCompanyCardBankIcons();
const [addNewCard] = useOnyx(ONYXKEYS.ADD_NEW_COMPANY_CARD);
const [localTypeSelected, setLocalTypeSelected] = useState<CardFeedProvider>();
const typeSelected = localTypeSelected ?? addNewCard?.data.feedType;
const typeSelected = localTypeSelected ?? addNewCard?.data?.feedType;
const [isError, setIsError] = useState(false);
const data = getAvailableCompanyCardTypes({
translate,
Expand All @@ -95,7 +95,7 @@ function CardTypeStep() {
const {bankName, selectedBank, feedType} = addNewCard?.data ?? {};
const isOtherBankSelected = selectedBank === CONST.COMPANY_CARDS.BANKS.OTHER;
const isNewCardTypeSelected = typeSelected !== feedType;
const doesCountrySupportPlaid = isPlaidSupportedCountry(addNewCard?.data.selectedCountry);
const doesCountrySupportPlaid = isPlaidSupportedCountry(addNewCard?.data?.selectedCountry);

const submit = useCallback(() => {
if (!typeSelected) {
Expand Down Expand Up @@ -155,7 +155,7 @@ function CardTypeStep() {
}}
confirmButtonOptions={confirmButtonOptions}
shouldSingleExecuteRowSelect
initiallyFocusedItemKey={addNewCard?.data.feedType}
initiallyFocusedItemKey={addNewCard?.data?.feedType}
shouldUpdateFocusedIndex
addBottomSafeAreaPadding
>
Expand Down
10 changes: 5 additions & 5 deletions src/pages/workspace/companyCards/addNew/DetailsStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,23 +128,23 @@ function DetailsStep({policyID, cardFeeds, workspaceAccountID}: DetailsStepProps
role={CONST.ROLE.PRESENTATION}
containerStyles={[styles.mb6]}
ref={inputCallbackRef}
defaultValue={addNewCard?.data.feedDetails?.processorID}
defaultValue={addNewCard?.data?.feedDetails?.processorID}
/>
<InputWrapper
InputComponent={TextInput}
inputID={INPUT_IDS.BANK_ID}
label={translate('workspace.companyCards.addNewCard.feedDetails.vcf.bankLabel')}
role={CONST.ROLE.PRESENTATION}
containerStyles={[styles.mb6]}
defaultValue={addNewCard?.data.feedDetails?.bankID}
defaultValue={addNewCard?.data?.feedDetails?.bankID}
/>
<InputWrapper
InputComponent={TextInput}
inputID={INPUT_IDS.COMPANY_ID}
label={translate('workspace.companyCards.addNewCard.feedDetails.vcf.companyLabel')}
role={CONST.ROLE.PRESENTATION}
containerStyles={[styles.mb6]}
defaultValue={addNewCard?.data.feedDetails?.companyID}
defaultValue={addNewCard?.data?.feedDetails?.companyID}
/>
</>
);
Expand All @@ -157,7 +157,7 @@ function DetailsStep({policyID, cardFeeds, workspaceAccountID}: DetailsStepProps
role={CONST.ROLE.PRESENTATION}
containerStyles={[styles.mb6]}
ref={inputCallbackRef}
defaultValue={addNewCard?.data.feedDetails?.distributionID}
defaultValue={addNewCard?.data?.feedDetails?.distributionID}
/>
);
case CONST.COMPANY_CARD.FEED_BANK_NAME.AMEX:
Expand All @@ -169,7 +169,7 @@ function DetailsStep({policyID, cardFeeds, workspaceAccountID}: DetailsStepProps
role={CONST.ROLE.PRESENTATION}
containerStyles={[styles.mb6]}
ref={inputCallbackRef}
defaultValue={addNewCard?.data.feedDetails?.deliveryFileName}
defaultValue={addNewCard?.data?.feedDetails?.deliveryFileName}
/>
);
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function SelectBankStep() {
const [addNewCard] = useOnyx(ONYXKEYS.ADD_NEW_COMPANY_CARD);
const [shouldUseStagingServer = isUsingStagingApi()] = useOnyx(ONYXKEYS.SHOULD_USE_STAGING_SERVER);
const [localBankSelected, setLocalBankSelected] = useState<ValueOf<typeof CONST.COMPANY_CARDS.BANKS> | null>();
const bankSelected = localBankSelected ?? addNewCard?.data.selectedBank;
const bankSelected = localBankSelected ?? addNewCard?.data?.selectedBank;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve selectedCountry before opening Plaid

When the company-card add flow is opened in the missing-data state this change is meant to tolerate (for example currentStep: SELECT_BANK with no data) and the user selects Other, this now renders and routes to PLAID_CONNECTION while merging only selectedBank/cardTitle. PlaidConnectionStep only starts Plaid when addNewCard?.data?.selectedCountry is present, so this path lands on an empty connection screen instead of recovering; redirect back to country selection or carry a valid country before allowing the Plaid path.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think we need that behaviour since this isn't the crash scenario. We only added ?. as a safeguard to prevent potential feature crashes, but that's not the root cause of the reported crash.

The actual crash is caused by the issue discussed here: #94687 (comment)

const [hasError, setHasError] = useState(false);
const isOtherBankSelected = bankSelected === CONST.COMPANY_CARDS.BANKS.OTHER;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function SelectCountryStep({policyID}: CountryStepProps) {
if (!currentCountry) {
setHasError(true);
} else {
if (addNewCard?.data.selectedCountry !== currentCountry) {
if (addNewCard?.data?.selectedCountry !== currentCountry) {
clearAddNewCardFlow();
}
setAddNewCompanyCardStepAndData({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function SelectFeedType() {
const [hasError, setHasError] = useState(false);
const doesCountrySupportPlaid = isPlaidSupportedCountry(addNewCard?.data?.selectedCountry);
const isUSCountry = addNewCard?.data?.selectedCountry === CONST.COUNTRY.US;
const defaultTypeSelected = addNewCard?.data.selectedFeedType ?? (doesCountrySupportPlaid ? CONST.COMPANY_CARDS.FEED_TYPE.DIRECT : CONST.COMPANY_CARDS.FEED_TYPE.CUSTOM);
const defaultTypeSelected = addNewCard?.data?.selectedFeedType ?? (doesCountrySupportPlaid ? CONST.COMPANY_CARDS.FEED_TYPE.DIRECT : CONST.COMPANY_CARDS.FEED_TYPE.CUSTOM);
const typeSelected = localTypeSelected ?? defaultTypeSelected;

const submit = useCallback(() => {
Expand Down
Loading