-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
22875 Add API Calls when clicking “Reveal details” buttons #29017
Merged
marcaaron
merged 24 commits into
Expensify:main
from
lukemorawski:22875-api_call_on_reveal_card_details
Oct 25, 2023
Merged
Changes from 9 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
f73d601
first commit
lukemorawski 5985ec1
move to reducer and error handling
lukemorawski df10ff7
removed unnecessary helper function
lukemorawski 36fb11a
formatting
lukemorawski bfdb546
var name change to isLoading
lukemorawski 9a8962c
better linting
lukemorawski c7dd8fa
moved action types to const
lukemorawski ccf8f4e
action types fix and cardID added to api call
lukemorawski ef623a4
address refactoring
lukemorawski f7ba68a
refactoring
lukemorawski 9f173af
Merge branch 'main' into 22875-api_call_on_reveal_card_details
lukemorawski 8361350
removed comment
lukemorawski 36a6d4e
revealCardDetails move
lukemorawski 28ca868
Merge branch 'main' into 22875-api_call_on_reveal_card_details
lukemorawski a7bcbb6
added offline disabling
lukemorawski f1aad79
Merge branch 'main' into 22875-api_call_on_reveal_card_details
lukemorawski 42cb473
reject with generic error message
lukemorawski 6dac4ca
Merge branch 'main' into 22875-api_call_on_reveal_card_details
lukemorawski dcb188b
Update src/libs/actions/Card.js
lukemorawski 8254860
linting
lukemorawski 586f20e
Merge branch 'main' into 22875-api_call_on_reveal_card_details
lukemorawski aaa7042
merging with latest changes
lukemorawski 95d4a43
Update src/languages/en.ts
lukemorawski 934344a
removed error handling
lukemorawski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import PropTypes from 'prop-types'; | ||
import React, {useState} from 'react'; | ||
import React, {useReducer} from 'react'; | ||
import {ScrollView, View} from 'react-native'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import _ from 'underscore'; | ||
|
@@ -18,6 +18,10 @@ import styles from '../../../styles/styles'; | |
import * as CardUtils from '../../../libs/CardUtils'; | ||
import Button from '../../../components/Button'; | ||
import CardDetails from './WalletPage/CardDetails'; | ||
// eslint-disable-next-line rulesdir/no-api-in-views | ||
import * as API from '../../../libs/API'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is here for a reason. If you want to call an API you need to create an "action" in the |
||
import CONST from '../../../CONST'; | ||
import * as revealCardDetailsUtils from './revealCardDetailsUtils'; | ||
|
||
const propTypes = { | ||
/* Onyx Props */ | ||
|
@@ -47,7 +51,7 @@ function ExpensifyCardPage({ | |
const virtualCard = _.find(domainCards, (card) => card.isVirtual) || {}; | ||
const physicalCard = _.find(domainCards, (card) => !card.isVirtual) || {}; | ||
|
||
const [shouldShowCardDetails, setShouldShowCardDetails] = useState(false); | ||
const [{isLoading, details, error}, dispatch] = useReducer(revealCardDetailsUtils.reducer, revealCardDetailsUtils.initialState); | ||
|
||
if (_.isEmpty(virtualCard) && _.isEmpty(physicalCard)) { | ||
return <NotFoundPage />; | ||
|
@@ -56,7 +60,19 @@ function ExpensifyCardPage({ | |
const formattedAvailableSpendAmount = CurrencyUtils.convertToDisplayString(physicalCard.availableSpend || virtualCard.availableSpend || 0); | ||
|
||
const handleRevealDetails = () => { | ||
setShouldShowCardDetails(true); | ||
dispatch({type: revealCardDetailsUtils.ACTION_TYPES.start}); | ||
// eslint-disable-next-line rulesdir/no-api-in-views,rulesdir/no-api-side-effects-method | ||
API.makeRequestWithSideEffects('RevealVirtualCardDetails', {cardID: virtualCard.cardID}) | ||
.then((response) => { | ||
if (response.jsonCode !== CONST.JSON_CODE.SUCCESS) { | ||
dispatch({type: revealCardDetailsUtils.ACTION_TYPES.FAIL, payload: response.message}); | ||
return; | ||
} | ||
dispatch({type: revealCardDetailsUtils.ACTION_TYPES.SUCCESS, payload: response}); | ||
}) | ||
.catch((err) => { | ||
dispatch({type: revealCardDetailsUtils.ACTION_TYPES.FAIL, payload: err.message}); | ||
}); | ||
}; | ||
|
||
return ( | ||
|
@@ -83,12 +99,12 @@ function ExpensifyCardPage({ | |
/> | ||
{!_.isEmpty(virtualCard) && ( | ||
<> | ||
{shouldShowCardDetails ? ( | ||
{details.pan ? ( | ||
<CardDetails | ||
// This is just a temporary mock, it will be replaced in this issue https://github.com/orgs/Expensify/projects/58?pane=issue&itemId=33286617 | ||
pan="1234123412341234" | ||
expiration="11/02/2024" | ||
cvv="321" | ||
pan={details.pan} | ||
expiration={details.expiration} | ||
cvv={details.cvv} | ||
privatePersonalDetails={{address: details.address}} | ||
/> | ||
) : ( | ||
<MenuItemWithTopDescription | ||
|
@@ -97,11 +113,14 @@ function ExpensifyCardPage({ | |
interactive={false} | ||
titleStyle={styles.walletCardNumber} | ||
shouldShowRightComponent | ||
error={error} | ||
rightComponent={ | ||
<Button | ||
medium | ||
text={translate('cardPage.cardDetails.revealDetails')} | ||
onPress={handleRevealDetails} | ||
isDisabled={isLoading} | ||
isLoading={isLoading} | ||
/> | ||
} | ||
/> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
const ACTION_TYPES = { | ||
START: 'START', | ||
SUCCESS: 'SUCCESS', | ||
FAIL: 'FAIL', | ||
} as const; | ||
|
||
type State = { | ||
details: { | ||
pan: string; | ||
expiration: string; | ||
cvv: string; | ||
address: { | ||
street: string; | ||
street2: string; | ||
city: string; | ||
state: string; | ||
zip: string; | ||
country: string; | ||
}; | ||
}; | ||
isLoading: boolean; | ||
error: string; | ||
}; | ||
|
||
type Action = {type: typeof ACTION_TYPES.START} | {type: typeof ACTION_TYPES.SUCCESS; payload: State['details']} | {type: typeof ACTION_TYPES.FAIL; payload: string}; | ||
|
||
const initialState: State = { | ||
details: { | ||
pan: '', | ||
expiration: '', | ||
cvv: '', | ||
address: { | ||
street: '', | ||
street2: '', | ||
city: '', | ||
state: '', | ||
zip: '', | ||
country: '', | ||
}, | ||
}, | ||
isLoading: false, | ||
error: '', | ||
}; | ||
|
||
const reducer = (state: State, action: Action): State => { | ||
switch (action.type) { | ||
case ACTION_TYPES.START: | ||
return {...state, isLoading: true}; | ||
case ACTION_TYPES.SUCCESS: | ||
return {details: action.payload, isLoading: false, error: ''}; | ||
case ACTION_TYPES.FAIL: { | ||
return {...state, error: action.payload, isLoading: false}; | ||
} | ||
default: | ||
return state; | ||
} | ||
}; | ||
|
||
export {initialState, reducer, ACTION_TYPES}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 should start with
useReducer
. We have avoided it until now and it looks like the incorrect pattern for what we are trying to achieve here.