Skip to content

Commit

Permalink
Merge pull request #50660 from Expensify/vit-useNewCommandForShipping…
Browse files Browse the repository at this point in the history
…Cards

Use SetPersonalDetailsAndShipExpensifyCards
  • Loading branch information
mountiny authored Oct 22, 2024
2 parents b91cbb9 + 58702e7 commit eba273e
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type SetMissingPersonalDetailsAndShipExpensifyCardParams = {
type SetPersonalDetailsAndShipExpensifyCardsParams = {
legalFirstName: string;
legalLastName: string;
phoneNumber: string;
Expand All @@ -9,7 +9,6 @@ type SetMissingPersonalDetailsAndShipExpensifyCardParams = {
addressCountry: string;
addressState: string;
dob: string;
cardID: number;
};

export default SetMissingPersonalDetailsAndShipExpensifyCardParams;
export default SetPersonalDetailsAndShipExpensifyCardsParams;
2 changes: 1 addition & 1 deletion src/libs/API/parameters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@ export type {default as UnassignCompanyCard} from './UnassignCompanyCard';
export type {default as UpdateCompanyCard} from './UpdateCompanyCard';
export type {default as UpdateCompanyCardNameParams} from './UpdateCompanyCardNameParams';
export type {default as SetCompanyCardExportAccountParams} from './SetCompanyCardExportAccountParams';
export type {default as SetPersonalDetailsAndShipExpensifyCardsParams} from './SetPersonalDetailsAndShipExpensifyCardsParams';
export type {default as RequestFeedSetupParams} from './RequestFeedSetupParams';
export type {default as SetMissingPersonalDetailsAndShipExpensifyCardParams} from './SetMissingPersonalDetailsAndShipExpensifyCardParams';
export type {default as SetInvoicingTransferBankAccountParams} from './SetInvoicingTransferBankAccountParams';
export type {default as ConnectPolicyToQuickBooksDesktopParams} from './ConnectPolicyToQuickBooksDesktopParams';
export type {default as UpdateQuickbooksDesktopExpensesExportDestinationTypeParams} from './UpdateQuickbooksDesktopExpensesExportDestinationTypeParams';
Expand Down
4 changes: 2 additions & 2 deletions src/libs/API/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ const WRITE_COMMANDS = {
UPDATE_COMPANY_CARD: 'SyncCard',
UPDATE_COMPANY_CARD_NAME: 'SetCardName',
SET_CARD_EXPORT_ACCOUNT: 'SetCardExportAccount',
SET_MISSING_PERSONAL_DETAILS_AND_SHIP_EXPENSIFY_CARD: 'SetMissingPersonalDetailsAndShipExpensifyCard',
SET_PERSONAL_DETAILS_AND_SHIP_EXPENSIFY_CARDS: 'SetPersonalDetailsAndShipExpensifyCards',
SET_INVOICING_TRANSFER_BANK_ACCOUNT: 'SetInvoicingTransferBankAccount',
} as const;

Expand Down Expand Up @@ -848,7 +848,7 @@ type WriteCommandParameters = {
[WRITE_COMMANDS.DELETE_SAVED_SEARCH]: Parameters.DeleteSavedSearchParams;
[WRITE_COMMANDS.UPDATE_CARD_SETTLEMENT_FREQUENCY]: Parameters.UpdateCardSettlementFrequencyParams;
[WRITE_COMMANDS.UPDATE_CARD_SETTLEMENT_ACCOUNT]: Parameters.UpdateCardSettlementAccountParams;
[WRITE_COMMANDS.SET_MISSING_PERSONAL_DETAILS_AND_SHIP_EXPENSIFY_CARD]: Parameters.SetMissingPersonalDetailsAndShipExpensifyCardParams;
[WRITE_COMMANDS.SET_PERSONAL_DETAILS_AND_SHIP_EXPENSIFY_CARDS]: Parameters.SetPersonalDetailsAndShipExpensifyCardsParams;

// Xero API
[WRITE_COMMANDS.UPDATE_XERO_TENANT_ID]: Parameters.UpdateXeroGenericTypeParams;
Expand Down
11 changes: 5 additions & 6 deletions src/libs/actions/PersonalDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {FormOnyxValues} from '@components/Form/types';
import * as API from '@libs/API';
import type {
OpenPublicProfilePageParams,
SetMissingPersonalDetailsAndShipExpensifyCardParams,
SetPersonalDetailsAndShipExpensifyCardsParams,
UpdateAutomaticTimezoneParams,
UpdateDateOfBirthParams,
UpdateDisplayNameParams,
Expand Down Expand Up @@ -428,8 +428,8 @@ function clearAvatarErrors() {
});
}

function updatePersonalDetailsAndShipExpensifyCard(values: FormOnyxValues<typeof ONYXKEYS.FORMS.PERSONAL_DETAILS_FORM>, cardID: number) {
const parameters: SetMissingPersonalDetailsAndShipExpensifyCardParams = {
function updatePersonalDetailsAndShipExpensifyCards(values: FormOnyxValues<typeof ONYXKEYS.FORMS.PERSONAL_DETAILS_FORM>) {
const parameters: SetPersonalDetailsAndShipExpensifyCardsParams = {
legalFirstName: values.legalFirstName?.trim() ?? '',
legalLastName: values.legalLastName?.trim() ?? '',
phoneNumber: LoginUtils.appendCountryCode(values.phoneNumber?.trim() ?? ''),
Expand All @@ -440,10 +440,9 @@ function updatePersonalDetailsAndShipExpensifyCard(values: FormOnyxValues<typeof
addressCountry: values.country,
addressState: values.state.trim(),
dob: values.dob,
cardID,
};

API.write(WRITE_COMMANDS.SET_MISSING_PERSONAL_DETAILS_AND_SHIP_EXPENSIFY_CARD, parameters, {
API.write(WRITE_COMMANDS.SET_PERSONAL_DETAILS_AND_SHIP_EXPENSIFY_CARDS, parameters, {
optimisticData: [
{
onyxMethod: Onyx.METHOD.MERGE,
Expand Down Expand Up @@ -483,5 +482,5 @@ export {
updateLegalName,
updatePronouns,
updateSelectedTimezone,
updatePersonalDetailsAndShipExpensifyCard,
updatePersonalDetailsAndShipExpensifyCards,
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import * as PersonalDetails from '@userActions/PersonalDetails';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {PersonalDetailsForm} from '@src/types/form';
import type {CardList, PrivatePersonalDetails} from '@src/types/onyx';
import type {PrivatePersonalDetails} from '@src/types/onyx';
import Address from './substeps/Address';
import Confirmation from './substeps/Confirmation';
import DateOfBirth from './substeps/DateOfBirth';
Expand All @@ -26,13 +26,12 @@ import {getInitialSubstep, getSubstepValues} from './utils';

type MissingPersonalDetailsContentProps = {
privatePersonalDetails: OnyxEntry<PrivatePersonalDetails>;
cardList: OnyxEntry<CardList>;
draftValues: OnyxEntry<PersonalDetailsForm>;
};

const formSteps = [LegalName, DateOfBirth, Address, PhoneNumber, Confirmation];

function MissingPersonalDetailsContent({privatePersonalDetails, cardList, draftValues}: MissingPersonalDetailsContentProps) {
function MissingPersonalDetailsContent({privatePersonalDetails, draftValues}: MissingPersonalDetailsContentProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const ref: ForwardedRef<InteractiveStepSubHeaderHandle> = useRef(null);
Expand All @@ -41,16 +40,14 @@ function MissingPersonalDetailsContent({privatePersonalDetails, cardList, draftV

const startFrom = useMemo(() => getInitialSubstep(values), [values]);

const firstUnissuedCard = useMemo(() => Object.values(cardList ?? {}).find((card) => card.state === CONST.EXPENSIFY_CARD.STATE.STATE_NOT_ISSUED), [cardList]);

const handleFinishStep = useCallback(() => {
if (!values) {
return;
}
PersonalDetails.updatePersonalDetailsAndShipExpensifyCard(values, firstUnissuedCard?.cardID ?? 0);
PersonalDetails.updatePersonalDetailsAndShipExpensifyCards(values);
FormActions.clearDraftValues(ONYXKEYS.FORMS.PERSONAL_DETAILS_FORM);
Navigation.goBack();
}, [firstUnissuedCard?.cardID, values]);
}, [values]);

const {
componentToRender: SubStep,
Expand Down
4 changes: 1 addition & 3 deletions src/pages/MissingPersonalDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import MissingPersonalDetailsContent from './MissingPersonalDetailsContent';

function MissingPersonalDetails() {
const [privatePersonalDetails, privatePersonalDetailsMetadata] = useOnyx(ONYXKEYS.PRIVATE_PERSONAL_DETAILS);
const [cardList, cardListMetadata] = useOnyx(ONYXKEYS.CARD_LIST);
const [draftValues, draftValuesMetadata] = useOnyx(ONYXKEYS.FORMS.PERSONAL_DETAILS_FORM_DRAFT);

const isLoading = isLoadingOnyxValue(privatePersonalDetailsMetadata, cardListMetadata, draftValuesMetadata);
const isLoading = isLoadingOnyxValue(privatePersonalDetailsMetadata, draftValuesMetadata);

if (isLoading) {
return <FullScreenLoadingIndicator />;
Expand All @@ -19,7 +18,6 @@ function MissingPersonalDetails() {
return (
<MissingPersonalDetailsContent
privatePersonalDetails={privatePersonalDetails}
cardList={cardList}
draftValues={draftValues}
/>
);
Expand Down

0 comments on commit eba273e

Please sign in to comment.