Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added working animation to switch in accounting page #55412

Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Merge branch 'main' into feature/kuba_nowakowski/add_switch_animation…
…s_to_acounting
  • Loading branch information
sumo-slonik committed Jan 30, 2025
commit 8711e60fae8014a8bd66aff57ac524375e802bbf
40 changes: 19 additions & 21 deletions src/pages/workspace/WorkspaceInitialPage.tsx
Original file line number Diff line number Diff line change
@@ -38,30 +38,29 @@ import useSingleExecution from '@hooks/useSingleExecution';
import useThemeStyles from '@hooks/useThemeStyles';
import useWaitForNavigation from '@hooks/useWaitForNavigation';
import {isConnectionInProgress} from '@libs/actions/connections';
import {getCompanyFeeds} from '@libs/CardUtils';
import {clearErrors, openPolicyInitialPage, removeWorkspace, updateGeneralSettings} from '@libs/actions/Policy/Policy';
import {navigateToBankAccountRoute} from '@libs/actions/ReimbursementAccount';
import {checkIfFeedConnectionIsBroken, flatAllCardsList} from '@libs/CardUtils';
import {convertToDisplayString} from '@libs/CurrencyUtils';
import getTopmostRouteName from '@libs/Navigation/getTopmostRouteName';
import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
import {
shouldShowPolicy as checkIfShouldShowPolicy,
getWorkspaceAccountID,
goBackFromInvalidPolicy,
hasPolicyCategoriesError,
hasPolicyFeedsError,
isPaidGroupPolicy,
isPendingDeletePolicy,
isPolicyAdmin,
isPolicyFeatureEnabled,
shouldShowEmployeeListError,
shouldShowPolicy,
shouldShowSyncError,
shouldShowTaxRateError,
} from '@libs/PolicyUtils';
import {getDefaultWorkspaceAvatar, getIcons, getPolicyExpenseChat, getReportName, getReportOfflinePendingActionAndErrors} from '@libs/ReportUtils';
import type {FullScreenNavigatorParamList} from '@navigation/types';
import {confirmReadyToOpenApp} from '@userActions/App';
import {clearErrors, openPolicyInitialPage, removeWorkspace, updateGeneralSettings} from '@userActions/Policy/Policy';
import {navigateToBankAccountRoute} from '@userActions/ReimbursementAccount';
import CONST from '@src/CONST';
import type {TranslationPaths} from '@src/languages/types';
import ONYXKEYS from '@src/ONYXKEYS';
@@ -108,7 +107,9 @@ type PolicyFeatureStates = Record<PolicyFeatureName, boolean>;
function dismissError(policyID: string | undefined, pendingAction: PendingAction | undefined) {
if (!policyID || pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) {
goBackFromInvalidPolicy();
removeWorkspace(policyID);
if (policyID) {
removeWorkspace(policyID);
}
} else {
clearErrors(policyID);
}
@@ -195,8 +196,8 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, route}: Workspac
!isEmptyObject(policy?.errorFields?.ouputCurrency ?? {}) ||
!isEmptyObject(policy?.errorFields?.address ?? {});
const shouldShowProtectedItems = isPolicyAdmin(policy, login);
const isPaidGroupPolicyValue = isPaidGroupPolicy(policy);
const [featureStates, setFeatureStates] = useState(policyFeatureStates);

const [highlightedFeature, setHighlightedFeature] = useState<string | undefined>(undefined);

const workspaceMenuItems: WorkspaceMenuItem[] = useMemo(() => {
@@ -218,21 +219,19 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, route}: Workspac
icon: ExpensifyCard,
action: singleExecution(waitForNavigate(() => Navigation.navigate(ROUTES.WORKSPACE_EXPENSIFY_CARD.getRoute(policyID)))),
routeName: SCREENS.WORKSPACE.EXPENSIFY_CARD,
brickRoadIndicator:
!isEmptyObject(cardsList?.cardList?.errorFields ?? {}) || !isEmptyObject(cardSettings?.errors ?? {}) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined,
highlighted: highlightedFeature === CONST.POLICY.MORE_FEATURES.ARE_EXPENSIFY_CARDS_ENABLED,
});
}

if (featureStates?.[CONST.POLICY.MORE_FEATURES.ARE_COMPANY_CARDS_ENABLED]) {
const hasPolicyFeedsErrorValue = hasPolicyFeedsError(getCompanyFeeds(cardFeeds));
const hasBrokenFeedConnection = checkIfFeedConnectionIsBroken(flatAllCardsList(allFeedsCards, workspaceAccountID));

protectedMenuItems.push({
translationKey: 'workspace.common.companyCards',
icon: CreditCard,
action: singleExecution(waitForNavigate(() => Navigation.navigate(ROUTES.WORKSPACE_COMPANY_CARDS.getRoute(policyID)))),
routeName: SCREENS.WORKSPACE.COMPANY_CARDS,
brickRoadIndicator: hasPolicyFeedsErrorValue ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined,
brickRoadIndicator: hasBrokenFeedConnection ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined,
highlighted: highlightedFeature === CONST.POLICY.MORE_FEATURES.ARE_COMPANY_CARDS_ENABLED,
});
}
@@ -355,26 +354,24 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, route}: Workspac
brickRoadIndicator: hasMembersError ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined,
routeName: SCREENS.WORKSPACE.MEMBERS,
},
...(isPaidGroupPolicyValue && shouldShowProtectedItems ? protectedMenuItems : []),
...(isPaidGroupPolicy(policy) && shouldShowProtectedItems ? protectedMenuItems : []),
];

return menuItems;
}, [
cardFeeds,
cardSettings?.errors,
cardsList?.cardList?.errorFields,
featureStates,
hasGeneralSettingsError,
hasMembersError,
hasPolicyCategoryError,
hasSyncError,
highlightedFeature,
isPaidGroupPolicyValue,
policy,
policyID,
shouldShowProtectedItems,
singleExecution,
waitForNavigate,
allFeedsCards,
workspaceAccountID,
]);

// We only update feature states if they aren't pending.
@@ -401,11 +398,12 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, route}: Workspac
}, []);

const prevPolicy = usePrevious(policy);
const actualShouldShowPolicy = useMemo(() => shouldShowPolicy(policy, isOffline, currentUserLogin), [policy, isOffline, currentUserLogin]);
const prevShouldShowPolicy = useMemo(() => shouldShowPolicy(prevPolicy, isOffline, currentUserLogin), [prevPolicy, isOffline, currentUserLogin]);

const shouldShowPolicy = useMemo(() => checkIfShouldShowPolicy(policy, isOffline, currentUserLogin), [policy, isOffline, currentUserLogin]);
const prevShouldShowPolicy = useMemo(() => checkIfShouldShowPolicy(prevPolicy, isOffline, currentUserLogin), [prevPolicy, isOffline, currentUserLogin]);
// We check shouldShowPolicy and prevShouldShowPolicy to prevent the NotFound view from showing right after we delete the workspace
// eslint-disable-next-line rulesdir/no-negated-variables
const shouldShowNotFoundPage = isEmptyObject(policy) || (!actualShouldShowPolicy && !prevShouldShowPolicy);
const shouldShowNotFoundPage = isEmptyObject(policy) || (!shouldShowPolicy && !prevShouldShowPolicy);

useEffect(() => {
if (isEmptyObject(prevPolicy) || isPendingDeletePolicy(prevPolicy) || !isPendingDeletePolicy(policy)) {
@@ -455,7 +453,7 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, route}: Workspac
onBackButtonPress={Navigation.dismissModal}
onLinkPress={Navigation.resetToHome}
shouldShow={shouldShowNotFoundPage}
subtitleKey={actualShouldShowPolicy ? 'workspace.common.notAuthorized' : undefined}
subtitleKey={shouldShowPolicy ? 'workspace.common.notAuthorized' : undefined}
>
<HeaderWithBackButton
title={policyName}
@@ -483,7 +481,7 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, route}: Workspac
<View style={[styles.pb4, styles.mh3, styles.mt3]}>
{/*
Ideally we should use MenuList component for MenuItems with singleExecution/Navigation actions.
In this case where user can click on workspace avatar or menu items, we need to have a check for `isExecuting`. So, we are directly mapping workspaceMenuItems.
In this case where user can click on workspace avatar or menu items, we need to have a check for `isExecuting`. So, we are directly mapping menuItems.
*/}
{workspaceMenuItems.map((item) => (
<HighlightableMenuItem
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.