Skip to content
8 changes: 4 additions & 4 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,10 +465,6 @@ const ROUTES = {
return getUrlWithBackToParam(baseRoute, backTo);
},
},
SET_DEFAULT_WORKSPACE: {
route: 'set-default-workspace',
getRoute: (navigateTo?: string) => (navigateTo ? (`set-default-workspace?navigateTo=${encodeURIComponent(navigateTo)}` as const) : ('set-default-workspace' as const)),
},
REPORT: 'r',
REPORT_WITH_ID: {
route: 'r/:reportID?/:reportActionID?',
Expand Down Expand Up @@ -906,6 +902,10 @@ const ROUTES = {
return getUrlWithBackToParam(`${action as string}/${iouType as string}/report/${reportID}/edit${shouldTurnOffSelectionMode ? '?shouldTurnOffSelectionMode=true' : ''}`, backTo);
},
},
SET_DEFAULT_WORKSPACE: {
route: 'set-default-workspace',
getRoute: (navigateTo?: string) => (navigateTo ? (`set-default-workspace?navigateTo=${encodeURIComponent(navigateTo)}` as const) : ('set-default-workspace' as const)),
},
SETTINGS_TAGS_ROOT: {
route: 'settings/:policyID/tags',
getRoute: (policyID: string | undefined, backTo = '') => {
Expand Down
4 changes: 1 addition & 3 deletions src/SCREENS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,7 @@ const SCREENS = {
ROOT: 'NewReportWorkspaceSelection_Root',
},

SET_DEFAULT_WORKSPACE: {
ROOT: 'SetDefaultWorkspace_Root',
},
SET_DEFAULT_WORKSPACE: 'SetDefaultWorkspace',
Comment thread
MrMuzyk marked this conversation as resolved.

REPORT_DETAILS: {
ROOT: 'Report_Details_Root',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import type {
SearchAdvancedFiltersParamList,
SearchReportParamList,
SearchSavedSearchParamList,
SetDefaultWorkspaceNavigatorParamList,
SettingsNavigatorParamList,
ShareNavigatorParamList,
SignInNavigatorParamList,
Expand Down Expand Up @@ -185,6 +184,7 @@ const MoneyRequestModalStackNavigator = createModalStackNavigator<MoneyRequestNa
[SCREENS.MONEY_REQUEST.DISTANCE_CREATE]: () => require<ReactComponentModule>('../../../../pages/iou/request/DistanceRequestStartPage').default,
[SCREENS.MONEY_REQUEST.STEP_DISTANCE_MAP]: () => require<ReactComponentModule>('../../../../pages/iou/request/step/IOURequestStepDistanceMap').default,
[SCREENS.MONEY_REQUEST.STEP_DISTANCE_MANUAL]: () => require<ReactComponentModule>('../../../../pages/iou/request/step/IOURequestStepDistanceManual').default,
[SCREENS.SET_DEFAULT_WORKSPACE]: () => require<ReactComponentModule>('../../../../pages/SetDefaultWorkspacePage').default,
});

const TravelModalStackNavigator = createModalStackNavigator<TravelNavigatorParamList>({
Expand Down Expand Up @@ -213,10 +213,6 @@ const NewReportWorkspaceSelectionModalStackNavigator = createModalStackNavigator
[SCREENS.NEW_REPORT_WORKSPACE_SELECTION.ROOT]: () => require<ReactComponentModule>('../../../../pages/NewReportWorkspaceSelectionPage').default,
});

const SetDefaultWorkspaceModalStackNavigator = createModalStackNavigator<SetDefaultWorkspaceNavigatorParamList>({
[SCREENS.SET_DEFAULT_WORKSPACE.ROOT]: () => require<ReactComponentModule>('../../../../pages/SetDefaultWorkspacePage').default,
});

const ReportDetailsModalStackNavigator = createModalStackNavigator<ReportDetailsNavigatorParamList>({
[SCREENS.REPORT_DETAILS.ROOT]: () => require<ReactComponentModule>('../../../../pages/ReportDetailsPage').default,
[SCREENS.REPORT_DETAILS.SHARE_CODE]: () => require<ReactComponentModule>('../../../../pages/home/report/ReportDetailsShareCodePage').default,
Expand Down Expand Up @@ -933,7 +929,6 @@ export {
ReferralModalStackNavigator,
TravelModalStackNavigator,
NewReportWorkspaceSelectionModalStackNavigator,
SetDefaultWorkspaceModalStackNavigator,
ReportDescriptionModalStackNavigator,
ReportDetailsModalStackNavigator,
ReportChangeWorkspaceModalStackNavigator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,6 @@ function RightModalNavigator({navigation, route}: RightModalNavigatorProps) {
name={SCREENS.RIGHT_MODAL.NEW_REPORT_WORKSPACE_SELECTION}
component={ModalStackNavigators.NewReportWorkspaceSelectionModalStackNavigator}
/>
<Stack.Screen
name={SCREENS.RIGHT_MODAL.SET_DEFAULT_WORKSPACE}
component={ModalStackNavigators.SetDefaultWorkspaceModalStackNavigator}
/>
<Stack.Screen
name={SCREENS.RIGHT_MODAL.REPORT_DETAILS}
component={ModalStackNavigators.ReportDetailsModalStackNavigator}
Expand Down
6 changes: 1 addition & 5 deletions src/libs/Navigation/linkingConfig/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1119,11 +1119,6 @@ const config: LinkingOptions<RootNavigatorParamList>['config'] = {
[SCREENS.NEW_REPORT_WORKSPACE_SELECTION.ROOT]: ROUTES.NEW_REPORT_WORKSPACE_SELECTION.route,
},
},
[SCREENS.RIGHT_MODAL.SET_DEFAULT_WORKSPACE]: {
screens: {
[SCREENS.SET_DEFAULT_WORKSPACE.ROOT]: ROUTES.SET_DEFAULT_WORKSPACE.route,
},
},
[SCREENS.RIGHT_MODAL.REPORT_DETAILS]: {
screens: {
[SCREENS.REPORT_DETAILS.ROOT]: ROUTES.REPORT_WITH_ID_DETAILS.route,
Expand Down Expand Up @@ -1432,6 +1427,7 @@ const config: LinkingOptions<RootNavigatorParamList>['config'] = {
path: ROUTES.SPLIT_EXPENSE_EDIT.route,
exact: true,
},
[SCREENS.SET_DEFAULT_WORKSPACE]: ROUTES.SET_DEFAULT_WORKSPACE.route,
},
},
[SCREENS.RIGHT_MODAL.TRANSACTION_DUPLICATE]: {
Expand Down
11 changes: 3 additions & 8 deletions src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1359,12 +1359,6 @@ type NewReportWorkspaceSelectionNavigatorParamList = {
};
};

type SetDefaultWorkspaceNavigatorParamList = {
[SCREENS.SET_DEFAULT_WORKSPACE.ROOT]: {
navigateTo?: Routes;
};
};

type ReportDetailsNavigatorParamList = {
[SCREENS.REPORT_DETAILS.ROOT]: {
reportID: string;
Expand Down Expand Up @@ -1814,6 +1808,9 @@ type MoneyRequestNavigatorParamList = {
backToReport?: string;
reportActionID?: string;
};
[SCREENS.SET_DEFAULT_WORKSPACE]: {
navigateTo?: Routes;
};
};

type WorkspaceConfirmationNavigatorParamList = {
Expand Down Expand Up @@ -2052,7 +2049,6 @@ type RightModalNavigatorParamList = {
[SCREENS.RIGHT_MODAL.PROFILE]: NavigatorScreenParams<ProfileNavigatorParamList>;
[SCREENS.SETTINGS.SHARE_CODE]: undefined;
[SCREENS.RIGHT_MODAL.NEW_REPORT_WORKSPACE_SELECTION]: NavigatorScreenParams<NewReportWorkspaceSelectionNavigatorParamList>;
[SCREENS.RIGHT_MODAL.SET_DEFAULT_WORKSPACE]: NavigatorScreenParams<SetDefaultWorkspaceNavigatorParamList>;
[SCREENS.RIGHT_MODAL.REPORT_DETAILS]: NavigatorScreenParams<ReportDetailsNavigatorParamList>;
[SCREENS.RIGHT_MODAL.REPORT_CHANGE_WORKSPACE]: NavigatorScreenParams<ReportChangeWorkspaceNavigatorParamList>;
[SCREENS.RIGHT_MODAL.REPORT_SETTINGS]: NavigatorScreenParams<ReportSettingsNavigatorParamList>;
Expand Down Expand Up @@ -2746,7 +2742,6 @@ export type {
ReimbursementAccountNavigatorParamList,
ReimbursementAccountEnterSignerInfoNavigatorParamList,
NewReportWorkspaceSelectionNavigatorParamList,
SetDefaultWorkspaceNavigatorParamList,
ReportDescriptionNavigatorParamList,
ReportDetailsNavigatorParamList,
ReportChangeWorkspaceNavigatorParamList,
Expand Down
12 changes: 6 additions & 6 deletions src/pages/SetDefaultWorkspacePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ import useWorkspaceList from '@hooks/useWorkspaceList';
import Log from '@libs/Log';
import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
import type {SetDefaultWorkspaceNavigatorParamList} from '@libs/Navigation/types';
import {hasEnabledOptions} from '@libs/OptionsListUtils';
import {isPaidGroupPolicy} from '@libs/PolicyUtils';
import type {MoneyRequestNavigatorParamList} from '@navigation/types';
import {setNameValuePair} from '@userActions/User';
import ONYXKEYS from '@src/ONYXKEYS';
import type SCREENS from '@src/SCREENS';

type SetDefaultWorkspacePageProps = PlatformStackScreenProps<SetDefaultWorkspaceNavigatorParamList, typeof SCREENS.SET_DEFAULT_WORKSPACE.ROOT>;
type SetDefaultWorkspacePageProps = PlatformStackScreenProps<MoneyRequestNavigatorParamList, typeof SCREENS.SET_DEFAULT_WORKSPACE>;

function SetDefaultWorkspacePage({route}: SetDefaultWorkspacePageProps) {
const {navigateTo} = route.params ?? {};
Expand All @@ -32,7 +31,6 @@ function SetDefaultWorkspacePage({route}: SetDefaultWorkspacePageProps) {
const {translate, localeCompare} = useLocalize();

const [policies, fetchStatus] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {canBeMissing: false});
const [allPolicyCategories] = useOnyx(ONYXKEYS.COLLECTION.POLICY_CATEGORIES, {canBeMissing: false});
const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP, {canBeMissing: false});
const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID, {canBeMissing: false});

Expand All @@ -47,11 +45,13 @@ function SetDefaultWorkspacePage({route}: SetDefaultWorkspacePageProps) {
Log.hmmm(`[SetDefaultWorkspacePage] navigateTo is undefined. Cannot navigate after setting default workspace to ${selectedPolicyID}`);
return;
}
const policyCategories = allPolicyCategories?.[`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${selectedPolicyID}`];

const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${selectedPolicyID}`];

// eslint-disable-next-line rulesdir/no-default-id-values
setNameValuePair(ONYXKEYS.NVP_ACTIVE_POLICY_ID, selectedPolicyID, activePolicyID ?? '');
if (hasEnabledOptions(policyCategories ?? {})) {

if (policy?.areCategoriesEnabled) {
Comment thread
MrMuzyk marked this conversation as resolved.
Navigation.navigate(navigateTo);
return;
}
Expand Down
55 changes: 43 additions & 12 deletions src/pages/iou/request/step/IOURequestStepConfirmation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import HeaderWithBackButton from '@components/HeaderWithBackButton';
import * as Expensicons from '@components/Icon/Expensicons';
import LocationPermissionModal from '@components/LocationPermissionModal';
import MoneyRequestConfirmationList from '@components/MoneyRequestConfirmationList';
import {usePersonalDetails} from '@components/OnyxListItemProvider';
import {usePersonalDetails, usePolicyCategories} from '@components/OnyxListItemProvider';
import PrevNextButtons from '@components/PrevNextButtons';
import ScreenWrapper from '@components/ScreenWrapper';
import useArchivedReportsIdSet from '@hooks/useArchivedReportsIdSet';
Expand Down Expand Up @@ -116,6 +116,7 @@ function IOURequestStepConfirmation({
}: IOURequestStepConfirmationProps) {
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const personalDetails = usePersonalDetails();
const allPolicyCategories = usePolicyCategories();

const [isRemoveConfirmModalVisible, setRemoveConfirmModalVisible] = useState(false);
const [optimisticTransactions] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_DRAFT, {
Expand Down Expand Up @@ -175,7 +176,6 @@ function IOURequestStepConfirmation({
const policyID = isCreatingTrackExpense || isUnreported ? policyForMovingExpensesID : getIOURequestPolicyID(transaction, report);
const isDraftPolicy = policy === policyDraft;

const [policyCategoriesReal] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${realPolicyID}`, {canBeMissing: true});
const [policyCategoriesDraft] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES_DRAFT}${draftPolicyID}`, {canBeMissing: true});
const [policyRecentlyUsedCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES}${realPolicyID}`, {canBeMissing: true});
const [policyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${realPolicyID}`, {canBeMissing: true});
Expand All @@ -184,7 +184,18 @@ function IOURequestStepConfirmation({
const [reportAttributesDerived] = useOnyx(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES, {canBeMissing: true, selector: reportsSelector});
const [recentlyUsedDestinations] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_DESTINATIONS}${realPolicyID}`, {canBeMissing: true});

const policyCategories = policyCategoriesReal ?? policyCategoriesDraft;
const policyCategories = useMemo(() => {
if (isDraftPolicy && draftPolicyID) {
return policyCategoriesDraft;
}

if (realPolicyID) {
return allPolicyCategories?.[`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${realPolicyID}`];
}

return undefined;
}, [allPolicyCategories, realPolicyID, policyCategoriesDraft, draftPolicyID, isDraftPolicy]);

const receiverParticipant: Participant | InvoiceReceiver | undefined = transaction?.participants?.find((participant) => participant?.accountID) ?? report?.invoiceReceiver;
const receiverAccountID = receiverParticipant && 'accountID' in receiverParticipant && receiverParticipant.accountID ? receiverParticipant.accountID : CONST.DEFAULT_NUMBER_ID;
const receiverType = getReceiverType(receiverParticipant);
Expand Down Expand Up @@ -264,19 +275,30 @@ function IOURequestStepConfirmation({
}, []);

useEffect(() => {
if (isCreatingTrackExpense && policyForMovingExpensesID !== undefined && policy?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) {
openDraftWorkspaceRequest(policyForMovingExpensesID);
if (!isCreatingTrackExpense || policyForMovingExpensesID === undefined) {
return;
}

const policyExpenseChat = participants?.find((participant) => participant.isPolicyExpenseChat);
if (policyExpenseChat?.policyID && policy?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) {
openDraftWorkspaceRequest(policyExpenseChat.policyID);
openDraftWorkspaceRequest(policyForMovingExpensesID);
}, [isCreatingTrackExpense, policy?.pendingAction, policyForMovingExpensesID]);

const policyExpenseChatPolicyID = useMemo(() => {
return participants?.find((participant) => participant.isPolicyExpenseChat)?.policyID;
}, [participants]);

const senderPolicyID = useMemo(() => {
return participants?.find((participant) => !!participant && 'isSender' in participant && participant.isSender)?.policyID;
}, [participants]);
Comment thread
MrMuzyk marked this conversation as resolved.

useEffect(() => {
if (policyExpenseChatPolicyID && policy?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) {
openDraftWorkspaceRequest(policyExpenseChatPolicyID);
return;
}
const senderPolicyParticipant = participants?.find((participant) => !!participant && 'isSender' in participant && participant.isSender);
if (senderPolicyParticipant?.policyID && policy?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) {
openDraftWorkspaceRequest(senderPolicyParticipant.policyID);
if (senderPolicyID && policy?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) {
openDraftWorkspaceRequest(senderPolicyID);
}
}, [isCreatingTrackExpense, isOffline, participants, policy?.pendingAction, policyForMovingExpensesID]);
}, [isOffline, policy?.pendingAction, policyExpenseChatPolicyID, senderPolicyID]);

const defaultBillable = !!policy?.defaultBillable;
useEffect(() => {
Expand Down Expand Up @@ -324,6 +346,15 @@ function IOURequestStepConfirmation({
useEffect(() => {
transactions.forEach((item) => {
if (!item.category) {
// If the expense had his category cleared due to unsaved changes (i.e. changing to recipient to one that does not have category)
// then we should reset the category to it's last saved value
const existingCategory = existingTransaction?.category;
if (existingCategory) {
const isExistingCategoryEnabled = policyCategories?.[existingCategory]?.enabled;
if (isExistingCategoryEnabled) {
setMoneyRequestCategory(item.transactionID, existingCategory, policy?.id);
}
}
return;
}

Expand Down
Loading