Skip to content

Commit

Permalink
Remove usage of withOnyx and other lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
youssef-lr committed Nov 7, 2024
1 parent e4af3c8 commit 1868fcb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 47 deletions.
58 changes: 13 additions & 45 deletions src/pages/settings/Wallet/ReportCardLostPage.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type {StackScreenProps} from '@react-navigation/stack';
import React, {useCallback, useEffect, useState} from 'react';
import {View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import {useOnyx, withOnyx} from 'react-native-onyx';
import {useOnyx} from 'react-native-onyx';
import FormAlertWithSubmitButton from '@components/FormAlertWithSubmitButton';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
Expand All @@ -27,8 +26,6 @@ import type {TranslationPaths} from '@src/languages/types';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import type {ReportPhysicalCardForm} from '@src/types/form';
import type {Card, PrivatePersonalDetails} from '@src/types/onyx';
import {isEmptyObject} from '@src/types/utils/EmptyObject';

const OPTIONS_KEYS = {
Expand All @@ -53,53 +50,31 @@ const OPTIONS: Option[] = [
},
];

type ReportCardLostPageOnyxProps = {
/** Onyx form data */
formData: OnyxEntry<ReportPhysicalCardForm>;

/** User's private personal details */
privatePersonalDetails: OnyxEntry<PrivatePersonalDetails>;

/** User's cards list */
cardList: OnyxEntry<Record<string, Card>>;
};

type ReportCardLostPageProps = ReportCardLostPageOnyxProps & StackScreenProps<SettingsNavigatorParamList, typeof SCREENS.SETTINGS.REPORT_CARD_LOST_OR_DAMAGED>;
type ReportCardLostPageProps = StackScreenProps<SettingsNavigatorParamList, typeof SCREENS.SETTINGS.REPORT_CARD_LOST_OR_DAMAGED>;

function ReportCardLostPage({
privatePersonalDetails = {
addresses: [
{
street: '',
street2: '',
city: '',
state: '',
zip: '',
country: '',
},
],
},
cardList = {},
route: {
params: {cardID = ''},
},
formData,
}: ReportCardLostPageProps) {
const styles = useThemeStyles();

const physicalCard = cardList?.[cardID];

const {translate} = useLocalize();

const [loginList] = useOnyx(ONYXKEYS.LOGIN_LIST);
const [account] = useOnyx(ONYXKEYS.ACCOUNT);
const [formData] = useOnyx(ONYXKEYS.FORMS.REPORT_PHYSICAL_CARD_FORM);
const [cardList] = useOnyx(ONYXKEYS.CARD_LIST);
const [privatePersonalDetails] = useOnyx(ONYXKEYS.PRIVATE_PERSONAL_DETAILS);

const [reason, setReason] = useState<Option>();
const [isReasonConfirmed, setIsReasonConfirmed] = useState(false);
const [shouldShowAddressError, setShouldShowAddressError] = useState(false);
const [shouldShowReasonError, setShouldShowReasonError] = useState(false);

const physicalCard = cardList?.[cardID];
const validateError = ErrorUtils.getLatestErrorMessageField(physicalCard);
const [isValidateCodeActionModalVisible, setIsValidateCodeActionModalVisible] = useState(formData?.isLoading ?? !isEmptyObject(physicalCard?.errors));
const [isValidateCodeActionModalVisible, setIsValidateCodeActionModalVisible] = useState(false);

const prevIsLoading = usePrevious(formData?.isLoading);

Expand All @@ -125,9 +100,12 @@ function ReportCardLostPage({

const handleValidateCodeEntered = useCallback(
(validateCode: string) => {
if (!physicalCard) {
return;
}
CardActions.requestReplacementExpensifyCard(physicalCard.cardID, reason?.key as ReplacementReason, validateCode);
},
[physicalCard.cardID, reason?.key],
[physicalCard, reason?.key],
);

if (isEmptyObject(physicalCard)) {
Expand Down Expand Up @@ -251,14 +229,4 @@ function ReportCardLostPage({

ReportCardLostPage.displayName = 'ReportCardLostPage';

export default withOnyx<ReportCardLostPageProps, ReportCardLostPageOnyxProps>({
privatePersonalDetails: {
key: ONYXKEYS.PRIVATE_PERSONAL_DETAILS,
},
cardList: {
key: ONYXKEYS.CARD_LIST,
},
formData: {
key: ONYXKEYS.FORMS.REPORT_PHYSICAL_CARD_FORM,
},
})(ReportCardLostPage);
export default ReportCardLostPage;
4 changes: 2 additions & 2 deletions src/pages/settings/Wallet/ReportVirtualCardFraudPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {StackScreenProps} from '@react-navigation/stack';
import React, {useCallback, useEffect, useRef, useState} from 'react';
import {InteractionManager, View} from 'react-native';
import React, {useCallback, useEffect, useState} from 'react';
import {View} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import FormAlertWithSubmitButton from '@components/FormAlertWithSubmitButton';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
Expand Down

0 comments on commit 1868fcb

Please sign in to comment.