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
91 changes: 91 additions & 0 deletions src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,21 +195,40 @@ type SettingsNavigatorParamList = {
policyID: string;
backTo?: Routes;
};
[SCREENS.SETTINGS_CATEGORIES.SETTINGS_CATEGORY_CREATE]: {
policyID: string;
backTo?: Routes;
};
[SCREENS.WORKSPACE.CATEGORY_EDIT]: {
policyID: string;
categoryName: string;
backTo?: Routes;
};
[SCREENS.SETTINGS_CATEGORIES.SETTINGS_CATEGORY_EDIT]: {
policyID: string;
categoryName: string;
backTo?: Routes;
};
[SCREENS.WORKSPACE.CATEGORY_PAYROLL_CODE]: {
policyID: string;
categoryName: string;
backTo?: Routes;
};
[SCREENS.SETTINGS_CATEGORIES.SETTINGS_CATEGORY_PAYROLL_CODE]: {
policyID: string;
categoryName: string;
backTo?: Routes;
};
[SCREENS.WORKSPACE.CATEGORY_GL_CODE]: {
policyID: string;
categoryName: string;
backTo?: Routes;
};
[SCREENS.SETTINGS_CATEGORIES.SETTINGS_CATEGORY_GL_CODE]: {
policyID: string;
categoryName: string;
backTo?: Routes;
};
[SCREENS.WORKSPACE.CATEGORY_DEFAULT_TAX_RATE]: {
policyID: string;
categoryName: string;
Expand All @@ -235,6 +254,11 @@ type SettingsNavigatorParamList = {
categoryName: string;
backTo?: Routes;
};
[SCREENS.SETTINGS_CATEGORIES.SETTINGS_CATEGORY_SETTINGS]: {
policyID: string;
categoryName: string;
backTo?: Routes;
};
[SCREENS.WORKSPACE.UPGRADE]: {
policyID?: string;
featureName?: string;
Expand All @@ -252,18 +276,34 @@ type SettingsNavigatorParamList = {
policyID: string;
backTo?: Routes;
};
[SCREENS.SETTINGS_CATEGORIES.SETTINGS_CATEGORIES_SETTINGS]: {
policyID: string;
backTo?: Routes;
};
[SCREENS.WORKSPACE.CATEGORIES_IMPORT]: {
policyID: string;
backTo?: Routes;
};
[SCREENS.SETTINGS_CATEGORIES.SETTINGS_CATEGORIES_IMPORT]: {
policyID: string;
backTo?: Routes;
};
[SCREENS.WORKSPACE.CATEGORIES_IMPORTED]: {
policyID: string;
backTo?: Routes;
};
[SCREENS.SETTINGS_CATEGORIES.SETTINGS_CATEGORIES_IMPORTED]: {
policyID: string;
backTo?: Routes;
};
[SCREENS.WORKSPACE.TAG_CREATE]: {
policyID: string;
backTo?: Routes;
};
[SCREENS.SETTINGS_TAGS.SETTINGS_TAG_CREATE]: {
policyID: string;
backTo?: Routes;
};
[SCREENS.WORKSPACE.DISTANCE_RATE_DETAILS]: {
policyID: string;
rateID: string;
Expand All @@ -284,10 +324,18 @@ type SettingsNavigatorParamList = {
policyID: string;
backTo?: Routes;
};
[SCREENS.SETTINGS_TAGS.SETTINGS_TAGS_SETTINGS]: {
policyID: string;
backTo?: Routes;
};
[SCREENS.WORKSPACE.TAGS_IMPORT]: {
policyID: string;
backTo?: Routes;
};
[SCREENS.SETTINGS_TAGS.SETTINGS_TAGS_IMPORT]: {
policyID: string;
backTo?: Routes;
};
[SCREENS.WORKSPACE.TAGS_IMPORT_OPTIONS]: {
policyID: string;
backTo?: Routes;
Expand All @@ -300,6 +348,7 @@ type SettingsNavigatorParamList = {
policyID: string;
backTo?: Routes;
};
[SCREENS.SETTINGS_TAGS.SETTINGS_TAGS_IMPORTED]: {policyID: string; backTo?: Routes};
[SCREENS.WORKSPACE.TAGS_IMPORTED_MULTI_LEVEL]: {
policyID: string;
backTo?: Routes;
Expand All @@ -310,34 +359,68 @@ type SettingsNavigatorParamList = {
tagName: string;
backTo?: Routes;
};
[SCREENS.SETTINGS_TAGS.SETTINGS_TAG_SETTINGS]: {
policyID: string;
orderWeight: number;
tagName: string;
backTo?: Routes;
};
[SCREENS.WORKSPACE.TAG_LIST_VIEW]: {
policyID: string;
orderWeight: number;
backTo?: Routes;
};
[SCREENS.SETTINGS_TAGS.SETTINGS_TAG_LIST_VIEW]: {
policyID: string;
orderWeight: number;
backTo?: Routes;
};
[SCREENS.WORKSPACE.TAGS_EDIT]: {
policyID: string;
orderWeight: number;
backTo?: Routes;
};
[SCREENS.SETTINGS_TAGS.SETTINGS_TAGS_EDIT]: {
policyID: string;
orderWeight: number;
backTo?: Routes;
};
[SCREENS.WORKSPACE.TAG_EDIT]: {
policyID: string;
orderWeight: number;
tagName: string;
backTo?: Routes;
};
[SCREENS.SETTINGS_TAGS.SETTINGS_TAG_EDIT]: {
policyID: string;
orderWeight: number;
tagName: string;
backTo?: Routes;
};
[SCREENS.WORKSPACE.TAG_APPROVER]: {
policyID: string;
orderWeight: number;
tagName: string;
backTo?: Routes;
};
[SCREENS.SETTINGS_TAGS.SETTINGS_TAG_APPROVER]: {
policyID: string;
orderWeight: number;
tagName: string;
backTo?: Routes;
};
[SCREENS.WORKSPACE.TAG_GL_CODE]: {
policyID: string;
orderWeight: number;
tagName: string;
backTo?: Routes;
};
[SCREENS.SETTINGS_TAGS.SETTINGS_TAG_GL_CODE]: {
policyID: string;
orderWeight: number;
tagName: string;
backTo?: Routes;
};
[SCREENS.SETTINGS.SUBSCRIPTION.SIZE]: {
canChangeSize: 0 | 1;
};
Expand Down Expand Up @@ -1749,13 +1832,21 @@ type WorkspaceSplitNavigatorParamList = {
policyID: string;
backTo?: Routes;
};
[SCREENS.SETTINGS_CATEGORIES.SETTINGS_CATEGORIES_ROOT]: {
policyID: string;
backTo?: Routes;
};
[SCREENS.WORKSPACE.MORE_FEATURES]: {
policyID: string;
};
[SCREENS.WORKSPACE.TAGS]: {
policyID: string;
backTo?: Routes;
};
[SCREENS.SETTINGS_TAGS.SETTINGS_TAGS_ROOT]: {
policyID: string;
backTo?: Routes;
};
[SCREENS.WORKSPACE.TAXES]: {
policyID: string;
};
Expand Down
10 changes: 6 additions & 4 deletions src/pages/workspace/categories/CategoryGLCodePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,24 @@ import {setPolicyCategoryGLCode} from '@userActions/Policy/Category';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import SCREENS from '@src/SCREENS';
import INPUT_IDS from '@src/types/form/WorkspaceCategoryForm';

type EditCategoryPageProps = PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.CATEGORY_GL_CODE>;
type EditCategoryPageProps =
| PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.CATEGORY_GL_CODE>
| PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.SETTINGS_CATEGORIES.SETTINGS_CATEGORY_GL_CODE>;

function CategoryGLCodePage({route}: EditCategoryPageProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const policyID = route.params.policyID;
const backTo = route.params.backTo;
const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`);
const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`, {canBeMissing: true});

const categoryName = route.params.categoryName;
const glCode = policyCategories?.[categoryName]?.['GL Code'];
const {inputCallbackRef} = useAutoFocusInput();
const isQuickSettingsFlow = !!backTo;
const isQuickSettingsFlow = route.name === SCREENS.SETTINGS_CATEGORIES.SETTINGS_CATEGORY_GL_CODE;

const validate = useCallback(
(values: FormOnyxValues<typeof ONYXKEYS.FORMS.WORKSPACE_CATEGORY_FORM>) => {
Expand Down
10 changes: 6 additions & 4 deletions src/pages/workspace/categories/CategoryPayrollCodePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,24 @@ import {setPolicyCategoryPayrollCode} from '@userActions/Policy/Category';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import SCREENS from '@src/SCREENS';
import INPUT_IDS from '@src/types/form/WorkspaceCategoryForm';

type EditCategoryPageProps = PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.CATEGORY_PAYROLL_CODE>;
type EditCategoryPageProps =
| PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.CATEGORY_PAYROLL_CODE>
| PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.SETTINGS_CATEGORIES.SETTINGS_CATEGORY_PAYROLL_CODE>;

function CategoryPayrollCodePage({route}: EditCategoryPageProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const policyID = route.params.policyID;
const backTo = route.params.backTo;
const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`);
const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`, {canBeMissing: true});

const categoryName = route.params.categoryName;
const payrollCode = policyCategories?.[categoryName]?.['Payroll Code'];
const {inputCallbackRef} = useAutoFocusInput();
const isQuickSettingsFlow = !!backTo;
const isQuickSettingsFlow = route.name === SCREENS.SETTINGS_CATEGORIES.SETTINGS_CATEGORY_PAYROLL_CODE;

const editPayrollCode = useCallback(
(values: FormOnyxValues<typeof ONYXKEYS.FORMS.WORKSPACE_CATEGORY_FORM>) => {
Expand Down
9 changes: 6 additions & 3 deletions src/pages/workspace/categories/CategorySettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@ import {
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import SCREENS from '@src/SCREENS';

type CategorySettingsPageProps = PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.CATEGORY_SETTINGS>;
type CategorySettingsPageProps =
| PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.CATEGORY_SETTINGS>
| PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.SETTINGS_CATEGORIES.SETTINGS_CATEGORY_SETTINGS>;

function CategorySettingsPage({
route: {
params: {backTo, policyID, categoryName},
name,
},
navigation,
}: CategorySettingsPageProps) {
Expand All @@ -60,7 +63,7 @@ function CategorySettingsPage({
const [isCannotDeleteOrDisableLastCategoryModalVisible, setIsCannotDeleteOrDisableLastCategoryModalVisible] = useState(false);
const shouldPreventDisableOrDelete = isDisablingOrDeletingLastEnabledCategory(policy, policyCategories, [policyCategory]);
const areCommentsRequired = policyCategory?.areCommentsRequired ?? false;
const isQuickSettingsFlow = !!backTo;
const isQuickSettingsFlow = name === SCREENS.SETTINGS_CATEGORIES.SETTINGS_CATEGORY_SETTINGS;

const navigateBack = () => {
Navigation.goBack(isQuickSettingsFlow ? ROUTES.SETTINGS_CATEGORIES_ROOT.getRoute(policyID, backTo) : undefined);
Expand Down
14 changes: 8 additions & 6 deletions src/pages/workspace/categories/CreateCategoryPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,31 @@ import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import {createPolicyCategory} from '@libs/actions/Policy/Category';
import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
import type {SettingsNavigatorParamList} from '@navigation/types';
import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper';
import * as Category from '@userActions/Policy/Category';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import SCREENS from '@src/SCREENS';
import CategoryForm from './CategoryForm';

type CreateCategoryPageProps = PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.CATEGORY_CREATE>;
type CreateCategoryPageProps =
| PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.CATEGORY_CREATE>
| PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.SETTINGS_CATEGORIES.SETTINGS_CATEGORY_CREATE>;

function CreateCategoryPage({route}: CreateCategoryPageProps) {
const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${route.params.policyID}`);
const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${route.params.policyID}`, {canBeMissing: true});
const styles = useThemeStyles();
const {translate} = useLocalize();
const backTo = route.params?.backTo;
const isQuickSettingsFlow = !!backTo;
const isQuickSettingsFlow = route.name === SCREENS.SETTINGS_CATEGORIES.SETTINGS_CATEGORY_CREATE;

const createCategory = useCallback(
(values: FormOnyxValues<typeof ONYXKEYS.FORMS.WORKSPACE_CATEGORY_FORM>) => {
Category.createPolicyCategory(route.params.policyID, values.categoryName.trim());
createPolicyCategory(route.params.policyID, values.categoryName.trim());
Navigation.goBack(isQuickSettingsFlow ? ROUTES.SETTINGS_CATEGORIES_ROOT.getRoute(route.params.policyID, backTo) : undefined);
},
[isQuickSettingsFlow, route.params.policyID, backTo],
Expand Down
10 changes: 6 additions & 4 deletions src/pages/workspace/categories/EditCategoryPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,21 @@ import {renamePolicyCategory} from '@userActions/Policy/Category';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import SCREENS from '@src/SCREENS';
import CategoryForm from './CategoryForm';

type EditCategoryPageProps = PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.CATEGORY_EDIT>;
type EditCategoryPageProps =
| PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.CATEGORY_EDIT>
| PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.SETTINGS_CATEGORIES.SETTINGS_CATEGORY_EDIT>;

function EditCategoryPage({route}: EditCategoryPageProps) {
const policyID = route.params.policyID;
const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`);
const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`, {canBeMissing: true});
const styles = useThemeStyles();
const {translate} = useLocalize();
const currentCategoryName = route.params.categoryName;
const backTo = route.params?.backTo;
const isQuickSettingsFlow = !!backTo;
const isQuickSettingsFlow = route.name === SCREENS.SETTINGS_CATEGORIES.SETTINGS_CATEGORY_EDIT;

const validate = useCallback(
(values: FormOnyxValues<typeof ONYXKEYS.FORMS.WORKSPACE_CATEGORY_FORM>) => {
Expand Down
14 changes: 8 additions & 6 deletions src/pages/workspace/categories/ImportCategoriesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@ import ImportSpreadsheet from '@components/ImportSpreadsheet';
import usePolicy from '@hooks/usePolicy';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
import type {SettingsNavigatorParamList} from '@libs/Navigation/types';
import * as PolicyUtils from '@libs/PolicyUtils';
import {goBackFromInvalidPolicy, hasAccountingConnections as hasAccountingConnectionsUtil} from '@libs/PolicyUtils';
import NotFoundPage from '@pages/ErrorPage/NotFoundPage';
import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper';
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import SCREENS from '@src/SCREENS';
import {isEmptyObject} from '@src/types/utils/EmptyObject';

type ImportCategoriesPageProps = PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.CATEGORIES_IMPORT>;
type ImportCategoriesPageProps =
| PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.CATEGORIES_IMPORT>
| PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.SETTINGS_CATEGORIES.SETTINGS_CATEGORIES_IMPORT>;

function ImportCategoriesPage({route}: ImportCategoriesPageProps) {
const policyID = route.params.policyID;
const backTo = route.params.backTo;
const policy = usePolicy(policyID);
const hasAccountingConnections = PolicyUtils.hasAccountingConnections(policy);
const isQuickSettingsFlow = !!backTo;
const hasAccountingConnections = hasAccountingConnectionsUtil(policy);
const isQuickSettingsFlow = route.name === SCREENS.SETTINGS_CATEGORIES.SETTINGS_CATEGORIES_IMPORT;

if (hasAccountingConnections) {
return <NotFoundPage />;
Expand All @@ -28,7 +30,7 @@ function ImportCategoriesPage({route}: ImportCategoriesPageProps) {
<AccessOrNotFoundWrapper
policyID={policyID}
accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN]}
fullPageNotFoundViewProps={{subtitleKey: isEmptyObject(policy) ? undefined : 'workspace.common.notAuthorized', onLinkPress: PolicyUtils.goBackFromInvalidPolicy}}
fullPageNotFoundViewProps={{subtitleKey: isEmptyObject(policy) ? undefined : 'workspace.common.notAuthorized', onLinkPress: goBackFromInvalidPolicy}}
>
<ImportSpreadsheet
backTo={backTo}
Expand Down
Loading