Skip to content

Commit

Permalink
Fix eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham1206agra committed Dec 27, 2024
1 parent 701ec8b commit 51b13bd
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 22 deletions.
6 changes: 5 additions & 1 deletion src/components/DestinationPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@ function DestinationPicker({selectedDestination, policyID, onSubmit}: Destinatio

const selectedRate = customUnit?.rates?.[selectedDestination];

if (!selectedRate?.customUnitRateID) {
return [];
}

return [
{
rateID: selectedRate?.customUnitRateID ?? '',
rateID: selectedRate.customUnitRateID,
name: selectedRate?.name ?? '',
currency: selectedRate?.currency ?? CONST.CURRENCY.USD,
isSelected: true,
Expand Down
14 changes: 10 additions & 4 deletions src/libs/PerDiemRequestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Onyx.connect({
function getCustomUnitID(reportID: string) {
const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`];
const policy = PolicyUtils.getPolicy(report?.policyID ?? parentReport?.policyID ?? '-1');
const policy = PolicyUtils.getPolicy(report?.policyID ?? parentReport?.policyID);
let customUnitID: string = CONST.CUSTOM_UNITS.FAKE_P2P_ID;
let category: string | undefined;

Expand Down Expand Up @@ -103,7 +103,7 @@ function getDestinationListSections({
}): DestinationTreeSection[] {
const sortedDestinations: Destination[] = lodashSortBy(destinations, 'name').map((rate) => ({
name: rate.name ?? '',
rateID: rate.customUnitRateID ?? '',
rateID: rate.customUnitRateID,
currency: rate.currency ?? CONST.CURRENCY.USD,
}));
const destinationSections: DestinationTreeSection[] = [];
Expand Down Expand Up @@ -187,13 +187,19 @@ function getDestinationListSections({
}

function getDestinationForDisplay(customUnit: CustomUnit | undefined, transaction: OnyxEntry<Transaction>) {
const customUnitRateID = transaction?.comment?.customUnit?.customUnitRateID ?? '';
const customUnitRateID = transaction?.comment?.customUnit?.customUnitRateID;
if (!customUnitRateID) {
return '';
}
const selectedDestination = customUnit?.rates?.[customUnitRateID];
return selectedDestination?.name ?? '';
}

function getSubratesFields(customUnit: CustomUnit | undefined, transaction: OnyxEntry<Transaction>) {
const customUnitRateID = transaction?.comment?.customUnit?.customUnitRateID ?? '';
const customUnitRateID = transaction?.comment?.customUnit?.customUnitRateID;
if (!customUnitRateID) {
return [];
}
const selectedDestination = customUnit?.rates?.[customUnitRateID];
const countSubrates = selectedDestination?.subRates?.length ?? 0;
const currentSubrates = transaction?.comment?.customUnit?.subRates ?? [];
Expand Down
2 changes: 1 addition & 1 deletion src/pages/iou/request/IOURequestStartPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function IOURequestStartPage({
const [session] = useOnyx(ONYXKEYS.SESSION);
const isLoadingSelectedTab = shouldUseTab ? isLoadingOnyxValue(selectedTabResult) : false;
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${route?.params.transactionID || -1}`);
const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${route?.params.transactionID || CONST.DEFAULT_NUMBER_ID}`);
const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY);
const {canUseCombinedTrackSubmit, canUsePerDiem} = usePermissions();

Expand Down
13 changes: 8 additions & 5 deletions src/pages/iou/request/step/IOURequestStepDestination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function IOURequestStepDestination({
}: IOURequestStepDestinationProps) {
const [policy, policyMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${explictPolicyID ?? IOU.getIOURequestPolicyID(transaction, report)}`);
const {accountID} = useCurrentUserPersonalDetails();
const policyExpenseReport = ReportUtils.getPolicyExpenseChat(accountID, policy?.id ?? '-1');
const policyExpenseReport = policy?.id ? ReportUtils.getPolicyExpenseChat(accountID, policy.id) : undefined;

const customUnit = PolicyUtils.getPerDiemCustomUnit(policy);
const selectedDestination = transaction?.comment?.customUnit?.customUnitRateID;
Expand All @@ -70,10 +70,13 @@ function IOURequestStepDestination({
};

const updateDestination = (destination: ListItem & {currency: string}) => {
if (isEmptyObject(customUnit)) {
return;
}
if (selectedDestination !== destination.keyForList) {
if (openedFromStartPage) {
IOU.setMoneyRequestParticipantsFromReport(transactionID, policyExpenseReport);
IOU.setCustomUnitID(transactionID, customUnit?.customUnitID ?? '');
IOU.setCustomUnitID(transactionID, customUnit.customUnitID);
IOU.setMoneyRequestCategory(transactionID, customUnit?.defaultCategory ?? '');
}
IOU.setCustomUnitRateID(transactionID, destination.keyForList ?? '');
Expand Down Expand Up @@ -132,7 +135,7 @@ function IOURequestStepDestination({
style={[styles.w100]}
onPress={() => {
InteractionManager.runAfterInteractions(() => {
Navigation.navigate(ROUTES.WORKSPACE_PER_DIEM.getRoute(policy?.id ?? '-1'));
Navigation.navigate(ROUTES.WORKSPACE_PER_DIEM.getRoute(policy.id));
});
}}
text={translate('workspace.perDiem.editPerDiemRates')}
Expand All @@ -142,10 +145,10 @@ function IOURequestStepDestination({
)}
</View>
)}
{!shouldShowEmptyState && !isLoading && !shouldShowOfflineView && (
{!shouldShowEmptyState && !isLoading && !shouldShowOfflineView && !!policy?.id && (
<DestinationPicker
selectedDestination={selectedDestination}
policyID={report?.policyID ?? policy?.id ?? '-1'}
policyID={policy.id}
onSubmit={updateDestination}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ function IOURequestStepPerDiemWorkspace({
}, [allPolicies, currentUserLogin, selectedWorkspace]);

const selectWorkspace = (item: WorkspaceListItem) => {
const policyExpenseReportID = ReportUtils.getPolicyExpenseChat(accountID, item.value)?.reportID ?? '-1';
const policyExpenseReportID = ReportUtils.getPolicyExpenseChat(accountID, item.value)?.reportID;
if (!policyExpenseReportID) {
return;
}
const selectedPolicy = PolicyUtils.getPolicy(item.value, allPolicies);
const perDiemUnit = PolicyUtils.getPerDiemCustomUnit(selectedPolicy);
IOU.setMoneyRequestParticipants(transactionID, [
Expand Down
8 changes: 4 additions & 4 deletions src/pages/iou/request/step/IOURequestStepSubrate.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {useNavigation} from '@react-navigation/native';
import React, {useState} from 'react';
import {View} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView';
import ConfirmModal from '@components/ConfirmModal';
Expand All @@ -18,6 +17,7 @@ import ValuePicker from '@components/ValuePicker';
import useAutoFocusInput from '@hooks/useAutoFocusInput';
import useLocalize from '@hooks/useLocalize';
import usePermissions from '@hooks/usePermissions';
import usePolicy from '@hooks/usePolicy';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import * as ErrorUtils from '@libs/ErrorUtils';
Expand Down Expand Up @@ -69,7 +69,7 @@ function IOURequestStepWaypoint({
}: IOURequestStepWaypointProps) {
const styles = useThemeStyles();
const {canUseCombinedTrackSubmit} = usePermissions();
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID ?? '-1'}`);
const policy = usePolicy(report?.policyID);
const customUnit = PolicyUtils.getPerDiemCustomUnit(policy);
const {windowWidth} = useWindowDimensions();
const [isDeleteStopModalOpen, setIsDeleteStopModalOpen] = useState(false);
Expand All @@ -79,9 +79,9 @@ function IOURequestStepWaypoint({
const {translate} = useLocalize();
const {inputCallbackRef} = useAutoFocusInput();
const parsedIndex = parseInt(pageIndex, 10);
const selectedDestination = transaction?.comment?.customUnit?.customUnitRateID ?? '';
const selectedDestination = transaction?.comment?.customUnit?.customUnitRateID;
const allSubrates = transaction?.comment?.customUnit?.subRates ?? [];
const allPossibleSubrates = customUnit?.rates?.[selectedDestination]?.subRates ?? [];
const allPossibleSubrates = selectedDestination ? customUnit?.rates?.[selectedDestination]?.subRates ?? [] : [];
const currentSubrate: CommentSubrate | undefined = allSubrates.at(parsedIndex) ?? undefined;
const totalSubrateCount = allPossibleSubrates.length;
const filledSubrateCount = allSubrates.length;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/iou/request/step/IOURequestStepTime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function IOURequestStepTime({
const newStart = DateUtils.combineDateAndTime(value.startTime, value.startDate);
const newEnd = DateUtils.combineDateAndTime(value.endTime, value.endDate);

IOU.setMoneyRequestDateAttribute(transaction?.transactionID ?? '-1', newStart, newEnd);
IOU.setMoneyRequestDateAttribute(transactionID, newStart, newEnd);

if (backTo) {
navigateBack();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default function <TProps extends WithFullTransactionOrNotFoundProps<Money
// eslint-disable-next-line rulesdir/no-negated-variables
function WithFullTransactionOrNotFound(props: Omit<TProps, keyof WithFullTransactionOrNotFoundOnyxProps>, ref: ForwardedRef<TRef>) {
const {route} = props;
const transactionID = route.params.transactionID ?? -1;
const transactionID = route.params.transactionID;
const userAction = 'action' in route.params && route.params.action ? route.params.action : CONST.IOU.ACTION.CREATE;

const shouldUseTransactionDraft = IOUUtils.shouldUseTransactionDraft(userAction);
Expand Down
4 changes: 2 additions & 2 deletions src/pages/iou/request/step/withWritableReportOrNotFound.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ export default function <TProps extends WithWritableReportOrNotFoundProps<MoneyR
// eslint-disable-next-line rulesdir/no-negated-variables
function WithWritableReportOrNotFound(props: Omit<TProps, keyof WithWritableReportOrNotFoundOnyxProps>, ref: ForwardedRef<TRef>) {
const {route} = props;
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${route.params.reportID ?? '-1'}`);
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${route.params.reportID}`);
const [isLoadingApp = true] = useOnyx(ONYXKEYS.IS_LOADING_APP);
const [reportDraft] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_DRAFT}${route.params.reportID ?? '-1'}`);
const [reportDraft] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_DRAFT}${route.params.reportID}`);

const iouTypeParamIsInvalid = !Object.values(CONST.IOU.TYPE)
.filter((type) => shouldIncludeDeprecatedIOUType || (type !== CONST.IOU.TYPE.REQUEST && type !== CONST.IOU.TYPE.SEND))
Expand Down
4 changes: 2 additions & 2 deletions src/pages/workspace/perDiem/ImportedPerDiemPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function ImportedPerDiemPage({route}: ImportedPerDiemPageProps) {
const importPerDiemRates = useCallback(() => {
setIsValidationEnabled(true);
const errors = validate();
if (Object.keys(errors).length > 0) {
if (Object.keys(errors).length > 0 || !perDiemCustomUnit?.customUnitID) {
return;
}

Expand All @@ -122,7 +122,7 @@ function ImportedPerDiemPage({route}: ImportedPerDiemPageProps) {

if (perDiemUnits) {
setIsImportingPerDiemRates(true);
PerDiem.importPerDiemRates(policyID, perDiemCustomUnit?.customUnitID ?? '', perDiemUnits, rowsLength);
PerDiem.importPerDiemRates(policyID, perDiemCustomUnit.customUnitID, perDiemUnits, rowsLength);
}
}, [validate, spreadsheet?.columns, spreadsheet?.data, containsHeader, policyID, perDiemCustomUnit?.customUnitID]);

Expand Down

0 comments on commit 51b13bd

Please sign in to comment.