Skip to content

Commit

Permalink
Merge pull request #40136 from Krishna2323/krishna2323/issue/39492
Browse files Browse the repository at this point in the history
fix: Web - Persistence of Tax Selection When Navigating to Other Pages and Returning
  • Loading branch information
Hayata Suenaga authored Apr 16, 2024
2 parents 28fa0e8 + 5065abd commit dd9ca88
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 13 deletions.
11 changes: 10 additions & 1 deletion src/pages/ReportParticipantsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, {useCallback, useMemo, useRef, useState} from 'react';
import {useIsFocused} from '@react-navigation/native';
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
import {InteractionManager, View} from 'react-native';
import type {TextInput} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
Expand Down Expand Up @@ -58,6 +59,14 @@ function ReportParticipantsPage({report, personalDetails, session}: ReportPartic
const currentUserAccountID = Number(session?.accountID);
const isCurrentUserAdmin = ReportUtils.isGroupChatAdmin(report, currentUserAccountID);
const isGroupChat = useMemo(() => ReportUtils.isGroupChat(report), [report]);
const isFocused = useIsFocused();

useEffect(() => {
if (isFocused) {
return;
}
setSelectedMembers([]);
}, [isFocused]);

const getUsers = useCallback((): MemberOption[] => {
let result: MemberOption[] = [];
Expand Down
1 change: 1 addition & 0 deletions src/pages/workspace/WorkspaceMembersPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ function WorkspaceMembersPage({policyMembers, personalDetails, invitedEmailsToAc
// useFocusEffect would make getWorkspaceMembers get called twice on fresh login because policyMember is a dependency of getWorkspaceMembers.
useEffect(() => {
if (!isFocused) {
setSelectedEmployees([]);
return;
}
getWorkspaceMembers();
Expand Down
13 changes: 10 additions & 3 deletions src/pages/workspace/categories/WorkspaceCategoriesPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {useFocusEffect} from '@react-navigation/native';
import {useFocusEffect, useIsFocused} from '@react-navigation/native';
import type {StackScreenProps} from '@react-navigation/stack';
import React, {useCallback, useMemo, useRef, useState} from 'react';
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
import {ActivityIndicator, View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
Expand Down Expand Up @@ -63,6 +63,7 @@ function WorkspaceCategoriesPage({policy, policyCategories, route}: WorkspaceCat
const [selectedCategories, setSelectedCategories] = useState<Record<string, boolean>>({});
const dropdownButtonRef = useRef(null);
const [deleteCategoriesConfirmModalVisible, setDeleteCategoriesConfirmModalVisible] = useState(false);
const isFocused = useIsFocused();

const fetchCategories = useCallback(() => {
Policy.openPolicyCategoriesPage(route.params.policyID);
Expand All @@ -76,6 +77,13 @@ function WorkspaceCategoriesPage({policy, policyCategories, route}: WorkspaceCat
}, [fetchCategories]),
);

useEffect(() => {
if (isFocused) {
return;
}
setSelectedCategories({});
}, [isFocused]);

const categoryList = useMemo<PolicyOption[]>(
() =>
Object.values(policyCategories ?? {})
Expand Down Expand Up @@ -119,7 +127,6 @@ function WorkspaceCategoriesPage({policy, policyCategories, route}: WorkspaceCat
);

const navigateToCategorySettings = (category: PolicyOption) => {
setSelectedCategories({});
Navigation.navigate(ROUTES.WORKSPACE_CATEGORY_SETTINGS.getRoute(route.params.policyID, category.keyForList));
};

Expand Down
13 changes: 10 additions & 3 deletions src/pages/workspace/distanceRates/PolicyDistanceRatesPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {useFocusEffect} from '@react-navigation/native';
import {useFocusEffect, useIsFocused} from '@react-navigation/native';
import type {StackScreenProps} from '@react-navigation/stack';
import React, {useCallback, useMemo, useRef, useState} from 'react';
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
import {ActivityIndicator, View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
Expand Down Expand Up @@ -56,6 +56,7 @@ function PolicyDistanceRatesPage({policy, route}: PolicyDistanceRatesPageProps)
const [isDeleteModalVisible, setIsDeleteModalVisible] = useState(false);
const dropdownButtonRef = useRef(null);
const policyID = route.params.policyID;
const isFocused = useIsFocused();

const customUnit: CustomUnit | undefined = useMemo(
() => (policy?.customUnits !== undefined ? policy?.customUnits[Object.keys(policy?.customUnits)[0]] : undefined),
Expand Down Expand Up @@ -93,6 +94,13 @@ function PolicyDistanceRatesPage({policy, route}: PolicyDistanceRatesPageProps)
}, [fetchDistanceRates]),
);

useEffect(() => {
if (isFocused) {
return;
}
setSelectedDistanceRates([]);
}, [isFocused]);

const distanceRatesList = useMemo<RateForList[]>(
() =>
Object.values(customUnitRates).map((value) => ({
Expand All @@ -119,7 +127,6 @@ function PolicyDistanceRatesPage({policy, route}: PolicyDistanceRatesPageProps)
};

const openRateDetails = (rate: RateForList) => {
setSelectedDistanceRates([]);
Navigation.navigate(ROUTES.WORKSPACE_DISTANCE_RATE_DETAILS.getRoute(policyID, rate.value));
};

Expand Down
14 changes: 11 additions & 3 deletions src/pages/workspace/tags/WorkspaceTagsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {useFocusEffect} from '@react-navigation/native';
import {useFocusEffect, useIsFocused} from '@react-navigation/native';
import type {StackScreenProps} from '@react-navigation/stack';
import lodashSortBy from 'lodash/sortBy';
import React, {useCallback, useMemo, useRef, useState} from 'react';
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
import {ActivityIndicator, View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
Expand Down Expand Up @@ -70,6 +70,7 @@ function WorkspaceTagsPage({policyTags, route}: WorkspaceTagsPageProps) {
const [selectedTags, setSelectedTags] = useState<Record<string, boolean>>({});
const dropdownButtonRef = useRef(null);
const [deleteTagsConfirmModalVisible, setDeleteTagsConfirmModalVisible] = useState(false);
const isFocused = useIsFocused();

const fetchTags = useCallback(() => {
Policy.openPolicyTagsPage(route.params.policyID);
Expand All @@ -82,6 +83,14 @@ function WorkspaceTagsPage({policyTags, route}: WorkspaceTagsPageProps) {
fetchTags();
}, [fetchTags]),
);

useEffect(() => {
if (isFocused) {
return;
}
setSelectedTags({});
}, [isFocused]);

const policyTagLists = useMemo(() => PolicyUtils.getTagLists(policyTags), [policyTags]);
const tagList = useMemo<PolicyForList[]>(
() =>
Expand Down Expand Up @@ -140,7 +149,6 @@ function WorkspaceTagsPage({policyTags, route}: WorkspaceTagsPageProps) {
};

const navigateToTagSettings = (tag: PolicyOption) => {
setSelectedTags({});
Navigation.navigate(ROUTES.WORKSPACE_TAG_SETTINGS.getRoute(route.params.policyID, tag.keyForList));
};

Expand Down
13 changes: 10 additions & 3 deletions src/pages/workspace/taxes/WorkspaceTaxesPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {useFocusEffect} from '@react-navigation/native';
import {useFocusEffect, useIsFocused} from '@react-navigation/native';
import type {StackScreenProps} from '@react-navigation/stack';
import React, {useCallback, useMemo, useRef, useState} from 'react';
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
import {ActivityIndicator, View} from 'react-native';
import Button from '@components/Button';
import ButtonWithDropdownMenu from '@components/ButtonWithDropdownMenu';
Expand Down Expand Up @@ -54,6 +54,7 @@ function WorkspaceTaxesPage({
const defaultExternalID = policy?.taxRates?.defaultExternalID;
const foreignTaxDefault = policy?.taxRates?.foreignTaxDefault;
const dropdownButtonRef = useRef(null);
const isFocused = useIsFocused();

const fetchTaxes = useCallback(() => {
openPolicyTaxesPage(policyID);
Expand All @@ -67,6 +68,13 @@ function WorkspaceTaxesPage({
}, [fetchTaxes]),
);

useEffect(() => {
if (isFocused) {
return;
}
setSelectedTaxesIDs([]);
}, [isFocused]);

const textForDefault = useCallback(
(taxID: string, taxRate: TaxRate): string => {
let suffix;
Expand Down Expand Up @@ -162,7 +170,6 @@ function WorkspaceTaxesPage({
if (!taxRate.keyForList) {
return;
}
setSelectedTaxesIDs([]);
Navigation.navigate(ROUTES.WORKSPACE_TAX_EDIT.getRoute(policyID, taxRate.keyForList));
};

Expand Down

0 comments on commit dd9ca88

Please sign in to comment.