Skip to content

Commit

Permalink
Merge pull request #49381 from nkdengineer/fix/48302-recreate
Browse files Browse the repository at this point in the history
fix: Split amount is not recalculated when entering 0 as input
  • Loading branch information
Beamanator authored Oct 1, 2024
2 parents def32f4 + 6ce0535 commit cba1457
Showing 1 changed file with 11 additions and 42 deletions.
53 changes: 11 additions & 42 deletions src/pages/iou/request/step/IOURequestStepDistance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {View} from 'react-native';
import type {ScrollView as RNScrollView} from 'react-native';
import type {RenderItemParams} from 'react-native-draggable-flatlist/lib/typescript/types';
import type {OnyxEntry} from 'react-native-onyx';
import {useOnyx, withOnyx} from 'react-native-onyx';
import {useOnyx} from 'react-native-onyx';
import Button from '@components/Button';
import DistanceRequestFooter from '@components/DistanceRequest/DistanceRequestFooter';
import DistanceRequestRenderItem from '@components/DistanceRequest/DistanceRequestRenderItem';
Expand All @@ -17,6 +17,7 @@ import type {WithCurrentUserPersonalDetailsProps} from '@components/withCurrentU
import useFetchRoute from '@hooks/useFetchRoute';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import usePolicy from '@hooks/usePolicy';
import usePrevious from '@hooks/usePrevious';
import useThemeStyles from '@hooks/useThemeStyles';
import DistanceRequestUtils from '@libs/DistanceRequestUtils';
Expand All @@ -42,44 +43,28 @@ import withFullTransactionOrNotFound from './withFullTransactionOrNotFound';
import type {WithWritableReportOrNotFoundProps} from './withWritableReportOrNotFound';
import withWritableReportOrNotFound from './withWritableReportOrNotFound';

type IOURequestStepDistanceOnyxProps = {
/** backup version of the original transaction */
transactionBackup: OnyxEntry<OnyxTypes.Transaction>;

/** The policy which the user has access to and which the report is tied to */
policy: OnyxEntry<OnyxTypes.Policy>;

/** Personal details of all users */
personalDetails: OnyxEntry<OnyxTypes.PersonalDetailsList>;

/** Whether the confirmation step should be skipped */
skipConfirmation: OnyxEntry<boolean>;
};

type IOURequestStepDistanceProps = IOURequestStepDistanceOnyxProps &
WithCurrentUserPersonalDetailsProps &
type IOURequestStepDistanceProps = WithCurrentUserPersonalDetailsProps &
WithWritableReportOrNotFoundProps<typeof SCREENS.MONEY_REQUEST.STEP_DISTANCE | typeof SCREENS.MONEY_REQUEST.CREATE> & {
/** The transaction object being modified in Onyx */
transaction: OnyxEntry<OnyxTypes.Transaction>;
};

function IOURequestStepDistance({
report,
policy,
route: {
params: {action, iouType, reportID, transactionID, backTo},
},
transaction,
transactionBackup,
personalDetails,
currentUserPersonalDetails,
skipConfirmation,
}: IOURequestStepDistanceProps) {
const styles = useThemeStyles();
const {isOffline} = useNetwork();
const {translate} = useLocalize();
const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID ?? -1}`);

const [transactionBackup] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_BACKUP}${transactionID}`);
const policy = usePolicy(report?.policyID);
const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST);
const [skipConfirmation] = useOnyx(`${ONYXKEYS.COLLECTION.SKIP_CONFIRMATION}${transactionID}`);
const [optimisticWaypoints, setOptimisticWaypoints] = useState<WaypointCollection | null>(null);
const waypoints = useMemo(
() =>
Expand Down Expand Up @@ -240,6 +225,9 @@ function IOURequestStepDistance({
}, [iouType, reportID, transactionID]);

const navigateToNextStep = useCallback(() => {
if (transaction?.splitShares) {
IOU.resetSplitShares(transaction);
}
if (backTo) {
Navigation.goBack(backTo);
return;
Expand Down Expand Up @@ -524,26 +512,7 @@ function IOURequestStepDistance({

IOURequestStepDistance.displayName = 'IOURequestStepDistance';

const IOURequestStepDistanceWithOnyx = withOnyx<IOURequestStepDistanceProps, IOURequestStepDistanceOnyxProps>({
transactionBackup: {
key: ({route}) => {
const transactionID = route.params.transactionID ?? -1;
return `${ONYXKEYS.COLLECTION.TRANSACTION_BACKUP}${transactionID}`;
},
},
policy: {
key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report ? report?.policyID : '-1'}`,
},
personalDetails: {
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
},
skipConfirmation: {
key: ({route}) => {
const transactionID = route.params.transactionID ?? -1;
return `${ONYXKEYS.COLLECTION.SKIP_CONFIRMATION}${transactionID}`;
},
},
})(IOURequestStepDistance);
const IOURequestStepDistanceWithOnyx = IOURequestStepDistance;

const IOURequestStepDistanceWithCurrentUserPersonalDetails = withCurrentUserPersonalDetails(IOURequestStepDistanceWithOnyx);
// eslint-disable-next-line rulesdir/no-negated-variables
Expand Down

0 comments on commit cba1457

Please sign in to comment.