Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 12 additions & 6 deletions src/pages/workspace/categories/ImportedCategoriesPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useCallback, useState} from 'react';
import React, {useCallback, useRef, useState} from 'react';
import {useOnyx} from 'react-native-onyx';
import ConfirmModal from '@components/ConfirmModal';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
Expand All @@ -20,17 +20,21 @@ import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import type {Errors} from '@src/types/onyx/OnyxCommon';
import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue';

type ImportedCategoriesPageProps = PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.CATEGORIES_IMPORTED>;
function ImportedCategoriesPage({route}: ImportedCategoriesPageProps) {
const {translate} = useLocalize();
const [spreadsheet] = useOnyx(ONYXKEYS.IMPORTED_SPREADSHEET);
const [spreadsheet, spreadsheetMetadata] = useOnyx(ONYXKEYS.IMPORTED_SPREADSHEET);
const [isImportingCategories, setIsImportingCategories] = useState(false);
const {containsHeader = true} = spreadsheet ?? {};
const [isValidationEnabled, setIsValidationEnabled] = useState(false);
const policyID = route.params.policyID;
const backTo = route.params.backTo;
const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`);

const isClosing = useRef(false);

const policy = usePolicy(policyID);
const columnNames = generateColumnNames(spreadsheet?.data?.length ?? 0);
const isQuickSettingsFlow = !!backTo;
Expand Down Expand Up @@ -116,16 +120,18 @@ function ImportedCategoriesPage({route}: ImportedCategoriesPageProps) {
}, [validate, spreadsheet, containsHeader, policyID, policyCategories]);

const hasAccountingConnections = hasAccountingConnectionsPolicyUtils(policy);
if (hasAccountingConnections) {
return <NotFoundPage />;
if (isClosing.current || (!spreadsheet && isLoadingOnyxValue(spreadsheetMetadata))) {
return;
}

const spreadsheetColumns = spreadsheet?.data;
if (!spreadsheetColumns) {
return;

if (hasAccountingConnections || !spreadsheetColumns) {
return <NotFoundPage />;
}

const closeImportPageAndModal = () => {
isClosing.current = true;
setIsImportingCategories(false);
closeImportPage();
Navigation.goBack(isQuickSettingsFlow ? ROUTES.SETTINGS_CATEGORIES_ROOT.getRoute(policyID, backTo) : ROUTES.WORKSPACE_CATEGORIES.getRoute(policyID));
Expand Down
11 changes: 9 additions & 2 deletions src/pages/workspace/members/ImportedMembersPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,22 @@ import {findDuplicate, generateColumnNames} from '@libs/importSpreadsheetUtils';
import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
import type {SettingsNavigatorParamList} from '@libs/Navigation/types';
import NotFoundPage from '@pages/ErrorPage/NotFoundPage';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue';

type ImportedMembersPageProps = PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.MEMBERS_IMPORTED>;

function ImportedMembersPage({route}: ImportedMembersPageProps) {
const {translate} = useLocalize();
const [spreadsheet] = useOnyx(ONYXKEYS.IMPORTED_SPREADSHEET);
const [spreadsheet, spreadsheetMetadata] = useOnyx(ONYXKEYS.IMPORTED_SPREADSHEET);
const [isImporting, setIsImporting] = useState(false);
const [isValidationEnabled, setIsValidationEnabled] = useState(false);
const policyID = route.params.policyID;

const columnNames = generateColumnNames(spreadsheet?.data?.length ?? 0);
const {containsHeader = true} = spreadsheet ?? {};

Expand Down Expand Up @@ -92,9 +95,13 @@ function ImportedMembersPage({route}: ImportedMembersPageProps) {
}
}, [validate, spreadsheet, containsHeader, policyID]);

if (!spreadsheet && isLoadingOnyxValue(spreadsheetMetadata)) {
return;
}

const spreadsheetColumns = spreadsheet?.data;
if (!spreadsheetColumns) {
return;
return <NotFoundPage />;
}

const closeImportPageAndModal = () => {
Expand Down
10 changes: 8 additions & 2 deletions src/pages/workspace/perDiem/ImportedPerDiemPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
import type {SettingsNavigatorParamList} from '@libs/Navigation/types';
import {getPerDiemCustomUnit} from '@libs/PolicyUtils';
import NotFoundPage from '@pages/ErrorPage/NotFoundPage';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import type {Errors} from '@src/types/onyx/OnyxCommon';
import type {Rate} from '@src/types/onyx/Policy';
import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue';

function generatePerDiemUnits(perDiemDestination: string[], perDiemSubRate: string[], perDiemCurrency: string[], perDiemAmount: string[]) {
const perDiemUnits: Record<string, Rate> = {};
Expand All @@ -46,7 +48,7 @@ function generatePerDiemUnits(perDiemDestination: string[], perDiemSubRate: stri
type ImportedPerDiemPageProps = PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.PER_DIEM_IMPORTED>;
function ImportedPerDiemPage({route}: ImportedPerDiemPageProps) {
const {translate} = useLocalize();
const [spreadsheet] = useOnyx(ONYXKEYS.IMPORTED_SPREADSHEET);
const [spreadsheet, spreadsheetMetadata] = useOnyx(ONYXKEYS.IMPORTED_SPREADSHEET);
const [isImportingPerDiemRates, setIsImportingPerDiemRates] = useState(false);
const {containsHeader = true} = spreadsheet ?? {};
const [isValidationEnabled, setIsValidationEnabled] = useState(false);
Expand Down Expand Up @@ -126,9 +128,13 @@ function ImportedPerDiemPage({route}: ImportedPerDiemPageProps) {
}
}, [validate, spreadsheet?.columns, spreadsheet?.data, containsHeader, policyID, perDiemCustomUnit?.customUnitID]);

if (!spreadsheet && isLoadingOnyxValue(spreadsheetMetadata)) {
return;
}

const spreadsheetColumns = spreadsheet?.data;
if (!spreadsheetColumns) {
return;
return <NotFoundPage />;
}

const closeImportPageAndModal = () => {
Expand Down
10 changes: 8 additions & 2 deletions src/pages/workspace/tags/ImportedTagsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@ import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
import type {SettingsNavigatorParamList} from '@libs/Navigation/types';
import {getTagLists, isControlPolicy} from '@libs/PolicyUtils';
import NotFoundPage from '@pages/ErrorPage/NotFoundPage';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import type {Errors} from '@src/types/onyx/OnyxCommon';
import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue';

type ImportedTagsPageProps = PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.TAGS_IMPORTED>;

function ImportedTagsPage({route}: ImportedTagsPageProps) {
const {translate} = useLocalize();
const [spreadsheet] = useOnyx(ONYXKEYS.IMPORTED_SPREADSHEET);
const [spreadsheet, spreadsheetMetadata] = useOnyx(ONYXKEYS.IMPORTED_SPREADSHEET);
const [isImportingTags, setIsImportingTags] = useState(false);
const {containsHeader = true} = spreadsheet ?? {};
const [isValidationEnabled, setIsValidationEnabled] = useState(false);
Expand Down Expand Up @@ -109,9 +111,13 @@ function ImportedTagsPage({route}: ImportedTagsPageProps) {
}
}, [validate, spreadsheet, containsHeader, policyTagLists, policyID]);

if (!spreadsheet && isLoadingOnyxValue(spreadsheetMetadata)) {
return;
}

const spreadsheetColumns = spreadsheet?.data;
if (!spreadsheetColumns) {
return;
return <NotFoundPage />;
}

const closeImportPageAndModal = () => {
Expand Down