Skip to content
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

Feat: Add a step to to Request Physical Card form that collects a magic code #51135

Merged
merged 32 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f001f00
Merge remote-tracking branch 'getusha/reuse-validate-code-action-moda…
hungvu193 Oct 20, 2024
6aa9281
Add validatecode modal when issuing Physical card
hungvu193 Oct 20, 2024
b1e52cc
adjust logic
hungvu193 Oct 20, 2024
2d1a57b
address linting
hungvu193 Oct 20, 2024
91bc9b1
revert .ruby-version
hungvu193 Oct 20, 2024
6eeabd4
merge main
hungvu193 Oct 21, 2024
9890494
Onyx migration
hungvu193 Oct 23, 2024
60a5c2a
Merge remote-tracking branch 'origin/main' into feat-50967
hungvu193 Oct 30, 2024
55187f4
handle generic error
hungvu193 Oct 30, 2024
340d3b1
update the error field
hungvu193 Nov 1, 2024
d4eb736
Merge remote-tracking branch 'origin/main' into feat-50967
hungvu193 Nov 1, 2024
23c5163
add loading field and other stuffs
hungvu193 Nov 1, 2024
6ce22aa
remove cardState optimistic
hungvu193 Nov 1, 2024
2224d58
prettier
hungvu193 Nov 1, 2024
60d0fdc
fix lint
hungvu193 Nov 1, 2024
c2528e8
Merge remote-tracking branch 'origin/main' into feat-50967
hungvu193 Nov 5, 2024
cf938e0
update successful condition
hungvu193 Nov 6, 2024
c3e9d85
Merge remote-tracking branch 'origin/main' into feat-50967
hungvu193 Nov 8, 2024
9c81e75
Merge remote-tracking branch 'origin/main' into feat-50967
hungvu193 Nov 11, 2024
33c65fc
addressing comment
hungvu193 Nov 11, 2024
14652ea
add code request status
hungvu193 Nov 12, 2024
982abf0
Update src/pages/settings/Wallet/Card/BaseGetPhysicalCard.tsx
hungvu193 Nov 12, 2024
55c4a0c
Update src/pages/settings/Wallet/Card/BaseGetPhysicalCard.tsx
hungvu193 Nov 12, 2024
cbf6a2b
address comment
hungvu193 Nov 13, 2024
58c2b39
merge main
hungvu193 Nov 14, 2024
0855d78
remove dupe props
hungvu193 Nov 14, 2024
5c75531
deprecate description props
hungvu193 Nov 14, 2024
fb7ee30
address comment
hungvu193 Nov 14, 2024
ceca20c
fix -1 value appears inside cardList
hungvu193 Nov 15, 2024
7b876d3
address comment
hungvu193 Nov 19, 2024
6d5eaa9
Merge remote-tracking branch 'origin/main' into feat-50967
hungvu193 Nov 19, 2024
4d96384
remove -1
hungvu193 Nov 19, 2024
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 @@ -8,6 +8,7 @@ type RequestPhysicalExpensifyCardParams = {
addressState: string;
addressStreet: string;
addressZip: string;
validateCode: string;
};

export default RequestPhysicalExpensifyCardParams;
3 changes: 2 additions & 1 deletion src/libs/actions/Wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ function answerQuestionsForWallet(answers: WalletQuestionAnswer[], idNumber: str
});
}

function requestPhysicalExpensifyCard(cardID: number, authToken: string, privatePersonalDetails: PrivatePersonalDetails) {
function requestPhysicalExpensifyCard(cardID: number, authToken: string, privatePersonalDetails: PrivatePersonalDetails, validateCode: string) {
const {legalFirstName = '', legalLastName = '', phoneNumber = ''} = privatePersonalDetails;
const {city = '', country = '', state = '', street = '', zip = ''} = PersonalDetailsUtils.getCurrentAddress(privatePersonalDetails) ?? {};

Expand All @@ -271,6 +271,7 @@ function requestPhysicalExpensifyCard(cardID: number, authToken: string, private
addressState: state,
addressStreet: street,
addressZip: zip,
validateCode,
};

const optimisticData: OnyxUpdate[] = [
Expand Down
48 changes: 41 additions & 7 deletions src/pages/settings/Wallet/Card/BaseGetPhysicalCard.tsx
hungvu193 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import React, {useCallback, useEffect, useRef} from 'react';
import React, {useCallback, useEffect, useRef, useState} from 'react';
import type {ReactNode} from 'react';
import {withOnyx} from 'react-native-onyx';
import {useOnyx, withOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import FormProvider from '@components/Form/FormProvider';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
import Text from '@components/Text';
import ValidateCodeActionModal from '@components/ValidateCodeActionModal';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import * as FormActions from '@libs/actions/FormActions';
import * as User from '@libs/actions/User';
import * as Wallet from '@libs/actions/Wallet';
import * as CardUtils from '@libs/CardUtils';
import * as GetPhysicalCardUtils from '@libs/GetPhysicalCardUtils';
Expand Down Expand Up @@ -108,7 +111,9 @@ function BaseGetPhysicalCard({
}: BaseGetPhysicalCardProps) {
const styles = useThemeStyles();
const isRouteSet = useRef(false);

const {translate} = useLocalize();
const [account] = useOnyx(ONYXKEYS.ACCOUNT);
const [isActionCodeModalVisible, setActionCodeModalVisible] = useState(false);
const domainCards = CardUtils.getDomainCards(cardList)[domain] || [];
const cardToBeIssued = domainCards.find((card) => !card?.nameValuePairs?.isVirtual && card?.state === CONST.EXPENSIFY_CARD.STATE.STATE_NOT_ISSUED);
const cardID = cardToBeIssued?.cardID.toString() ?? '-1';
Expand Down Expand Up @@ -146,17 +151,37 @@ function BaseGetPhysicalCard({

const onSubmit = useCallback(() => {
const updatedPrivatePersonalDetails = GetPhysicalCardUtils.getUpdatedPrivatePersonalDetails(draftValues, privatePersonalDetails);
// If the current step of the get physical card flow is the confirmation page
if (isConfirmation) {
Wallet.requestPhysicalExpensifyCard(cardToBeIssued?.cardID ?? -1, session?.authToken ?? '', updatedPrivatePersonalDetails);
setActionCodeModalVisible(true);
return;
}
GetPhysicalCardUtils.goToNextPhysicalCardRoute(domain, updatedPrivatePersonalDetails);
}, [isConfirmation, domain, draftValues, privatePersonalDetails]);

const handleIssuePhysicalCard = useCallback(
(validateCode: string) => {
const updatedPrivatePersonalDetails = GetPhysicalCardUtils.getUpdatedPrivatePersonalDetails(draftValues, privatePersonalDetails);
// If the current step of the get physical card flow is the confirmation page
Wallet.requestPhysicalExpensifyCard(cardToBeIssued?.cardID ?? -1, session?.authToken ?? '', updatedPrivatePersonalDetails, validateCode);
hungvu193 marked this conversation as resolved.
Show resolved Hide resolved
// Form draft data needs to be erased when the flow is complete,
hungvu193 marked this conversation as resolved.
Show resolved Hide resolved
// so that no stale data is left on Onyx
FormActions.clearDraftValues(ONYXKEYS.FORMS.GET_PHYSICAL_CARD_FORM);
Navigation.navigate(ROUTES.SETTINGS_WALLET_DOMAINCARD.getRoute(cardID.toString()));
},
[cardID, cardToBeIssued?.cardID, draftValues, session?.authToken, privatePersonalDetails],
);

const sendValidateCode = useCallback(() => {
const primaryLogin = account?.primaryLogin ?? '';
const loginData = loginList?.[primaryLogin];

if (loginData?.validateCodeSent) {
return;
}
GetPhysicalCardUtils.goToNextPhysicalCardRoute(domain, updatedPrivatePersonalDetails);
}, [cardID, cardToBeIssued?.cardID, domain, draftValues, isConfirmation, session?.authToken, privatePersonalDetails]);

User.requestValidateCodeAction();
}, [account, loginList]);

return (
<ScreenWrapper
shouldEnablePickerAvoiding={false}
Expand All @@ -169,6 +194,15 @@ function BaseGetPhysicalCard({
/>
<Text style={[styles.textHeadline, styles.mh5, styles.mb5]}>{headline}</Text>
{renderContent({onSubmit, submitButtonText, children, onValidate})}
<ValidateCodeActionModal
isVisible={isActionCodeModalVisible}
sendValidateCode={sendValidateCode}
clearError={() => {}}
handleSubmitForm={handleIssuePhysicalCard}
title={translate('cardPage.validateCardTitle')}
onClose={() => setActionCodeModalVisible(false)}
description={translate('cardPage.enterMagicCode', {contactMethod: account?.primaryLogin ?? ''})}
/>
</ScreenWrapper>
);
}
Expand Down
Loading