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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
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) => {
sumo-slonik marked this conversation as resolved.
Show resolved Hide resolved
sumo-slonik marked this conversation as resolved.
Show resolved Hide resolved
const isAccordionExpanded = useSharedValue(isExpanded);
const shouldAnimateAccordionSection = useSharedValue(false);
sumo-slonik marked this conversation as resolved.
Show resolved Hide resolved
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,10 +1,12 @@
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';

Check failure on line 9 in src/pages/workspace/accounting/intacct/advanced/SageIntacctAdvancedPage.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Namespace imports from @libs are not allowed. Use named imports instead. Example: import { method } from "@libs/module"
import {areSettingsInErrorFields, getCurrentSageIntacctEntityName, settingsPendingAction} from '@libs/PolicyUtils';
import Navigation from '@navigation/Navigation';
import type {WithPolicyProps} from '@pages/workspace/withPolicy';
Expand All @@ -17,7 +19,7 @@
updateSageIntacctSyncReimbursedReports,
updateSageIntacctSyncReimbursementAccountID,
} from '@userActions/connections/SageIntacct';
import * as Policy from '@userActions/Policy/Policy';

Check failure on line 22 in src/pages/workspace/accounting/intacct/advanced/SageIntacctAdvancedPage.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Namespace imports from @userActions are not allowed. Use named imports instead. Example: import { action } from "@userActions/module"
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';
import type {SageIntacctDataElement} from '@src/types/onyx/Policy';
Expand All @@ -28,12 +30,14 @@

function SageIntacctAdvancedPage({policy}: WithPolicyProps) {
const {translate} = useLocalize();
const policyID = policy?.id ?? '-1';

Check failure on line 33 in src/pages/workspace/accounting/intacct/advanced/SageIntacctAdvancedPage.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

const styles = useThemeStyles();

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(
() => [
{
Expand Down Expand Up @@ -70,7 +74,7 @@
updateSageIntacctSyncReimbursedReports(policyID, enabled);

if (enabled && !sync?.reimbursementAccountID) {
const reimbursementAccountID = data?.bankAccounts[0]?.id ?? '';

Check failure on line 77 in src/pages/workspace/accounting/intacct/advanced/SageIntacctAdvancedPage.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

updateSageIntacctSyncReimbursementAccountID(policyID, reimbursementAccountID);
}
},
Expand Down Expand Up @@ -113,20 +117,24 @@
/>
))}

{!!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>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,57 @@
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';

Check failure on line 9 in src/pages/workspace/accounting/intacct/export/SageIntacctNonReimbursableExpensesPage.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Namespace imports from @libs are not allowed. Use named imports instead. Example: import { method } from "@libs/module"
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';
import {updateSageIntacctDefaultVendor} from '@userActions/connections/SageIntacct';
import * as Policy from '@userActions/Policy/Policy';

Check failure on line 17 in src/pages/workspace/accounting/intacct/export/SageIntacctNonReimbursableExpensesPage.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Namespace imports from @userActions are not allowed. Use named imports instead. Example: import { action } from "@userActions/module"
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';

Check failure on line 24 in src/pages/workspace/accounting/intacct/export/SageIntacctNonReimbursableExpensesPage.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

const styles = useThemeStyles();
const {data: intacctData, config} = policy?.connections?.intacct ?? {};

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
Expand Down Expand Up @@ -60,29 +81,40 @@
isActive: !!config?.export.nonReimbursableCreditCardChargeDefaultVendor,
switchAccessibilityLabel: translate('workspace.sageIntacct.defaultVendor'),
onToggle: (enabled) => {
const vendor = enabled ? policy?.connections?.intacct?.data?.vendors?.[0].id ?? '' : '';

Check failure on line 84 in src/pages/workspace/accounting/intacct/export/SageIntacctNonReimbursableExpensesPage.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

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,
},
];

Expand Down Expand Up @@ -114,21 +146,18 @@
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>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
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';

Check failure on line 9 in src/pages/workspace/accounting/intacct/export/SageIntacctReimbursableExpensesPage.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Namespace imports from @libs are not allowed. Use named imports instead. Example: import { method } from "@libs/module"
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';
import {updateSageIntacctDefaultVendor} from '@userActions/connections/SageIntacct';
import * as Policy from '@userActions/Policy/Policy';

Check failure on line 17 in src/pages/workspace/accounting/intacct/export/SageIntacctReimbursableExpensesPage.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Namespace imports from @userActions are not allowed. Use named imports instead. Example: import { action } from "@userActions/module"
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';
Expand All @@ -30,7 +28,26 @@

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'),
Expand All @@ -50,21 +67,31 @@
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,
},
];

Expand Down Expand Up @@ -96,21 +123,18 @@
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>
Expand Down
Loading
Loading