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
Next Next commit
Added working animation to switch in accounting page with configurabl…
…e first animation.
sumo-slonik committed Jan 17, 2025

Verified

This commit was signed with the committer’s verified signature.
BartoszGrajdek Bartosz Grajdek
commit 50a5f90cce820581913ae87e88946a22f3367b4d
21 changes: 21 additions & 0 deletions src/hooks/useAccordionAnimation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {useEffect} from 'react';
import {useSharedValue} from 'react-native-reanimated';

const useAccordionAnimation = (isExpanded: boolean) => {
const isAccordionExpanded = useSharedValue(isExpanded);
const shouldAnimateAccordionSection = useSharedValue(false);
const hasMounted = useSharedValue(false);

useEffect(() => {
isAccordionExpanded.set(isExpanded);
if (hasMounted.get()) {
shouldAnimateAccordionSection.set(true);
} else {
hasMounted.set(true);
}
}, [hasMounted, isAccordionExpanded, isExpanded, shouldAnimateAccordionSection]);

return {isAccordionExpanded, shouldAnimateAccordionSection};
};

export default useAccordionAnimation;
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React, {useMemo} from 'react';
import Accordion from '@components/Accordion';
import ConnectionLayout from '@components/ConnectionLayout';
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
import useAccordionAnimation from '@hooks/useAccordionAnimation';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import * as ErrorUtils from '@libs/ErrorUtils';
@@ -34,6 +36,8 @@ function SageIntacctAdvancedPage({policy}: WithPolicyProps) {
const {importEmployees, autoSync, sync, pendingFields, errorFields} = policy?.connections?.intacct?.config ?? {};
const {data, config} = policy?.connections?.intacct ?? {};

const {isAccordionExpanded, shouldAnimateAccordionSection} = useAccordionAnimation(!!sync?.syncReimbursedReports);

const toggleSections = useMemo(
() => [
{
@@ -113,20 +117,24 @@ function SageIntacctAdvancedPage({policy}: WithPolicyProps) {
/>
))}

{!!sync?.syncReimbursedReports && (
<Accordion
isExpanded={isAccordionExpanded}
style={styles.overflowHidden}
isToggleTriggered={shouldAnimateAccordionSection}
>
<OfflineWithFeedback
key={translate('workspace.sageIntacct.paymentAccount')}
pendingAction={settingsPendingAction([CONST.SAGE_INTACCT_CONFIG.REIMBURSEMENT_ACCOUNT_ID], pendingFields)}
>
<MenuItemWithTopDescription
title={getReimbursedAccountName(data?.bankAccounts ?? [], sync.reimbursementAccountID) ?? translate('workspace.sageIntacct.notConfigured')}
title={getReimbursedAccountName(data?.bankAccounts ?? [], sync?.reimbursementAccountID) ?? translate('workspace.sageIntacct.notConfigured')}
description={translate('workspace.sageIntacct.paymentAccount')}
shouldShowRightIcon
onPress={() => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_PAYMENT_ACCOUNT.getRoute(policyID))}
brickRoadIndicator={areSettingsInErrorFields([CONST.SAGE_INTACCT_CONFIG.REIMBURSEMENT_ACCOUNT_ID], errorFields) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined}
/>
</OfflineWithFeedback>
)}
</Accordion>
</ConnectionLayout>
);
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import React from 'react';
import Accordion from '@components/Accordion';
import ConnectionLayout from '@components/ConnectionLayout';
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
import useAccordionAnimation from '@hooks/useAccordionAnimation';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import * as ErrorUtils from '@libs/ErrorUtils';
import Navigation from '@libs/Navigation/Navigation';
import {areSettingsInErrorFields, getSageIntacctNonReimbursableActiveDefaultVendor, settingsPendingAction} from '@libs/PolicyUtils';
import type {MenuItem, ToggleItem} from '@pages/workspace/accounting/intacct/types';
import type {ExtendedMenuItemWithSubscribedSettings, MenuItemToRender} from '@pages/workspace/accounting/intacct/types';
import type {WithPolicyConnectionsProps} from '@pages/workspace/withPolicyConnections';
import withPolicyConnections from '@pages/workspace/withPolicyConnections';
import ToggleSettingOptionRow from '@pages/workspace/workflows/ToggleSettingsOptionRow';
@@ -17,10 +19,6 @@ import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';
import {getDefaultVendorName} from './utils';

type MenuItemWithSubscribedSettings = Pick<MenuItem, 'type' | 'description' | 'title' | 'onPress' | 'shouldHide'> & {subscribedSettings?: string[]};

type ToggleItemWithKey = ToggleItem & {key: string};

function SageIntacctNonReimbursableExpensesPage({policy}: WithPolicyConnectionsProps) {
const {translate} = useLocalize();
const policyID = policy?.id ?? '-1';
@@ -29,8 +27,31 @@ function SageIntacctNonReimbursableExpensesPage({policy}: WithPolicyConnectionsP

const activeDefaultVendor = getSageIntacctNonReimbursableActiveDefaultVendor(policy);
const defaultVendorName = getDefaultVendorName(activeDefaultVendor, intacctData?.vendors);
const expandedCondition = !(
!config?.export.nonReimbursable ||
(config?.export.nonReimbursable === CONST.SAGE_INTACCT_NON_REIMBURSABLE_EXPENSE_TYPE.CREDIT_CARD_CHARGE && !config?.export.nonReimbursableCreditCardChargeDefaultVendor)
);

const {isAccordionExpanded, shouldAnimateAccordionSection} = useAccordionAnimation(expandedCondition);

const renderDefault = (item: MenuItemToRender) => {
return (
<OfflineWithFeedback
key={item.description}
pendingAction={settingsPendingAction(item.subscribedSettings, config?.pendingFields)}
>
<MenuItemWithTopDescription
title={item.title}
description={item.description}
shouldShowRightIcon
onPress={item?.onPress}
brickRoadIndicator={areSettingsInErrorFields(item.subscribedSettings, config?.errorFields) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined}
/>
</OfflineWithFeedback>
);
};

const menuItems: Array<MenuItemWithSubscribedSettings | ToggleItemWithKey> = [
const menuItems: ExtendedMenuItemWithSubscribedSettings[] = [
{
type: 'menuitem',
title: config?.export.nonReimbursable
@@ -62,27 +83,38 @@ function SageIntacctNonReimbursableExpensesPage({policy}: WithPolicyConnectionsP
onToggle: (enabled) => {
const vendor = enabled ? policy?.connections?.intacct?.data?.vendors?.[0].id ?? '' : '';
updateSageIntacctDefaultVendor(policyID, CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE_CREDIT_CARD_VENDOR, vendor, config?.export.nonReimbursableCreditCardChargeDefaultVendor);
isAccordionExpanded.set(enabled);
shouldAnimateAccordionSection.set(true);
},
onCloseError: () => Policy.clearSageIntacctErrorField(policyID, CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE_CREDIT_CARD_VENDOR),
pendingAction: settingsPendingAction([CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE_CREDIT_CARD_VENDOR], config?.pendingFields),
errors: ErrorUtils.getLatestErrorField(config, CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE_CREDIT_CARD_VENDOR),
shouldHide: config?.export.nonReimbursable !== CONST.SAGE_INTACCT_NON_REIMBURSABLE_EXPENSE_TYPE.CREDIT_CARD_CHARGE,
},
{
type: 'menuitem',
title: defaultVendorName && defaultVendorName !== '' ? defaultVendorName : translate('workspace.sageIntacct.notConfigured'),
description: translate('workspace.sageIntacct.defaultVendor'),
onPress: () => {
Navigation.navigate(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_DEFAULT_VENDOR.getRoute(policyID, CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE.toLowerCase()));
},
subscribedSettings: [
config?.export.nonReimbursable === CONST.SAGE_INTACCT_NON_REIMBURSABLE_EXPENSE_TYPE.VENDOR_BILL
? CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE_VENDOR
: CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE_CREDIT_CARD_VENDOR,
type: 'accordion',
children: [
{
type: 'menuitem',
title: defaultVendorName && defaultVendorName !== '' ? defaultVendorName : translate('workspace.sageIntacct.notConfigured'),
description: translate('workspace.sageIntacct.defaultVendor'),
onPress: () => {
Navigation.navigate(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_DEFAULT_VENDOR.getRoute(policyID, CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE.toLowerCase()));
},
subscribedSettings: [
config?.export.nonReimbursable === CONST.SAGE_INTACCT_NON_REIMBURSABLE_EXPENSE_TYPE.VENDOR_BILL
? CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE_VENDOR
: CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE_CREDIT_CARD_VENDOR,
],
shouldHide:
!config?.export.nonReimbursable ||
(config?.export.nonReimbursable === CONST.SAGE_INTACCT_NON_REIMBURSABLE_EXPENSE_TYPE.CREDIT_CARD_CHARGE &&
!config?.export.nonReimbursableCreditCardChargeDefaultVendor),
},
],
shouldHide:
!config?.export.nonReimbursable ||
(config?.export.nonReimbursable === CONST.SAGE_INTACCT_NON_REIMBURSABLE_EXPENSE_TYPE.CREDIT_CARD_CHARGE && !config?.export.nonReimbursableCreditCardChargeDefaultVendor),
shouldHide: false,
shouldExpand: isAccordionExpanded,
shouldAnimateSection: shouldAnimateAccordionSection,
},
];

@@ -114,21 +146,18 @@ function SageIntacctNonReimbursableExpensesPage({policy}: WithPolicyConnectionsP
wrapperStyle={[styles.mv3, styles.ph5]}
/>
);
default:
case 'accordion':
return (
<OfflineWithFeedback
key={item.description}
pendingAction={settingsPendingAction(item.subscribedSettings, config?.pendingFields)}
<Accordion
isExpanded={item.shouldExpand}
style={styles.overflowHidden}
isToggleTriggered={item.shouldAnimateSection}
>
<MenuItemWithTopDescription
title={item.title}
description={item.description}
shouldShowRightIcon
onPress={item?.onPress}
brickRoadIndicator={areSettingsInErrorFields(item.subscribedSettings, config?.errorFields) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined}
/>
</OfflineWithFeedback>
{item.children.map((child) => renderDefault(child))}
</Accordion>
);
default:
return renderDefault(item);
}
})}
</ConnectionLayout>
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import React from 'react';
import Accordion from '@components/Accordion';
import ConnectionLayout from '@components/ConnectionLayout';
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
import useAccordionAnimation from '@hooks/useAccordionAnimation';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import * as ErrorUtils from '@libs/ErrorUtils';
import Navigation from '@libs/Navigation/Navigation';
import {areSettingsInErrorFields, settingsPendingAction} from '@libs/PolicyUtils';
import type {MenuItem, ToggleItem} from '@pages/workspace/accounting/intacct/types';
import type {ExtendedMenuItemWithSubscribedSettings, MenuItemToRender} from '@pages/workspace/accounting/intacct/types';
import type {WithPolicyConnectionsProps} from '@pages/workspace/withPolicyConnections';
import withPolicyConnections from '@pages/workspace/withPolicyConnections';
import ToggleSettingOptionRow from '@pages/workspace/workflows/ToggleSettingsOptionRow';
@@ -17,10 +19,6 @@ import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';
import {getDefaultVendorName} from './utils';

type MenuItemWithSubscribedSettings = Pick<MenuItem, 'type' | 'description' | 'title' | 'onPress' | 'shouldHide'> & {subscribedSettings?: string[]};

type ToggleItemWithKey = ToggleItem & {key: string};

function SageIntacctReimbursableExpensesPage({policy}: WithPolicyConnectionsProps) {
const {translate} = useLocalize();
const policyID = policy?.id ?? '-1';
@@ -30,7 +28,26 @@ function SageIntacctReimbursableExpensesPage({policy}: WithPolicyConnectionsProp

const defaultVendorName = getDefaultVendorName(reimbursableExpenseReportDefaultVendor, intacctData?.vendors);

const menuItems: Array<MenuItemWithSubscribedSettings | ToggleItemWithKey> = [
const expandedCondition = !(reimbursable !== CONST.SAGE_INTACCT_REIMBURSABLE_EXPENSE_TYPE.EXPENSE_REPORT || !reimbursableExpenseReportDefaultVendor);
const {isAccordionExpanded, shouldAnimateAccordionSection} = useAccordionAnimation(expandedCondition);

const renderDefault = (item: MenuItemToRender) => {
return (
<OfflineWithFeedback
key={item.description}
pendingAction={settingsPendingAction(item.subscribedSettings, config?.pendingFields)}
>
<MenuItemWithTopDescription
title={item.title}
description={item.description}
shouldShowRightIcon
onPress={item?.onPress}
brickRoadIndicator={areSettingsInErrorFields(item.subscribedSettings, config?.errorFields) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined}
/>
</OfflineWithFeedback>
);
};
const menuItems: ExtendedMenuItemWithSubscribedSettings[] = [
{
type: 'menuitem',
title: reimbursable ? translate(`workspace.sageIntacct.reimbursableExpenses.values.${reimbursable}`) : translate('workspace.sageIntacct.notConfigured'),
@@ -50,21 +67,31 @@ function SageIntacctReimbursableExpensesPage({policy}: WithPolicyConnectionsProp
onToggle: (enabled) => {
const vendor = enabled ? policy?.connections?.intacct?.data?.vendors?.[0].id ?? '' : '';
updateSageIntacctDefaultVendor(policyID, CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE_VENDOR, vendor, config?.export.reimbursableExpenseReportDefaultVendor);
isAccordionExpanded.set(enabled);
shouldAnimateAccordionSection.set(true);
},
onCloseError: () => Policy.clearSageIntacctErrorField(policyID, CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE_VENDOR),
pendingAction: settingsPendingAction([CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE_VENDOR], config?.pendingFields),
errors: ErrorUtils.getLatestErrorField(config, CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE_VENDOR),
shouldHide: reimbursable !== CONST.SAGE_INTACCT_REIMBURSABLE_EXPENSE_TYPE.EXPENSE_REPORT,
},
{
type: 'menuitem',
title: defaultVendorName && defaultVendorName !== '' ? defaultVendorName : translate('workspace.sageIntacct.notConfigured'),
description: translate('workspace.sageIntacct.defaultVendor'),
onPress: () => {
Navigation.navigate(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_DEFAULT_VENDOR.getRoute(policyID, CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE));
},
subscribedSettings: [CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE_VENDOR],
shouldHide: reimbursable !== CONST.SAGE_INTACCT_REIMBURSABLE_EXPENSE_TYPE.EXPENSE_REPORT || !reimbursableExpenseReportDefaultVendor,
type: 'accordion',
children: [
{
type: 'menuitem',
title: defaultVendorName && defaultVendorName !== '' ? defaultVendorName : translate('workspace.sageIntacct.notConfigured'),
description: translate('workspace.sageIntacct.defaultVendor'),
onPress: () => {
Navigation.navigate(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_DEFAULT_VENDOR.getRoute(policyID, CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE));
},
subscribedSettings: [CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE_VENDOR],
shouldHide: reimbursable !== CONST.SAGE_INTACCT_REIMBURSABLE_EXPENSE_TYPE.EXPENSE_REPORT || !reimbursableExpenseReportDefaultVendor,
},
],
shouldHide: false,
shouldExpand: isAccordionExpanded,
shouldAnimateSection: shouldAnimateAccordionSection,
},
];

@@ -96,21 +123,18 @@ function SageIntacctReimbursableExpensesPage({policy}: WithPolicyConnectionsProp
wrapperStyle={[styles.mv3, styles.ph5]}
/>
);
default:
case 'accordion':
return (
<OfflineWithFeedback
key={item.description}
pendingAction={settingsPendingAction(item.subscribedSettings, config?.pendingFields)}
<Accordion
isExpanded={item.shouldExpand}
style={styles.overflowHidden}
isToggleTriggered={shouldAnimateAccordionSection}
>
<MenuItemWithTopDescription
title={item.title}
description={item.description}
shouldShowRightIcon
onPress={item?.onPress}
brickRoadIndicator={areSettingsInErrorFields(item.subscribedSettings, config?.errorFields) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined}
/>
</OfflineWithFeedback>
{item.children.map((child) => renderDefault(child))}
</Accordion>
);
default:
return renderDefault(item);
}
})}
</ConnectionLayout>
Loading