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
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
23 changes: 19 additions & 4 deletions src/components/Accordion/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type AccordionProps = {

function Accordion({isExpanded, children, duration = 300, isToggleTriggered, style}: AccordionProps) {
const height = useSharedValue(0);
const isAnimating = useSharedValue(false);

const derivedHeight = useDerivedValue(() => {
if (!isToggleTriggered.get()) {
Expand All @@ -41,23 +42,37 @@ function Accordion({isExpanded, children, duration = 300, isToggleTriggered, sty
return isExpanded.get() ? 1 : 0;
}

return withTiming(isExpanded.get() ? 1 : 0, {
duration,
easing: Easing.inOut(Easing.quad),
});
isAnimating.set(true);
return withTiming(
isExpanded.get() ? 1 : 0,
{
duration,
easing: Easing.inOut(Easing.quad),
},
(finished) => {
if (!finished || !isExpanded.get()) {
return;
}
isAnimating.set(false);
},
);
});

const animatedStyle = useAnimatedStyle(() => {
if (!isToggleTriggered.get() && !isExpanded.get()) {
return {
height: 0,
opacity: 0,
display: 'none',
};
}

return {
height: !isToggleTriggered.get() ? undefined : derivedHeight.get(),
maxHeight: !isToggleTriggered.get() ? undefined : derivedHeight.get(),
opacity: derivedOpacity.get(),
overflow: isAnimating.get() ? 'hidden' : 'visible',
display: isExpanded.get() ? 'inline' : 'none',
};
});

Expand Down
26 changes: 26 additions & 0 deletions src/hooks/useAccordionAnimation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {useEffect} from 'react';
import {useSharedValue} from 'react-native-reanimated';

/**
* @returns two values: isExpanded, which manages the expansion of the accordion component,
* and shouldAnimateAccordionSection, which determines whether we should animate
* the expanding and collapsing of the accordion based on changes in isExpanded.
*/
function 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,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';
import {getLatestErrorField} from '@libs/ErrorUtils';
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';
import {clearSageIntacctErrorField} from '@userActions/Policy/Policy';
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 All @@ -42,8 +46,8 @@
isActive: !!autoSync?.enabled,
onToggle: (enabled: boolean) => updateSageIntacctAutoSync(policyID, enabled),
subscribedSettings: [CONST.SAGE_INTACCT_CONFIG.AUTO_SYNC_ENABLED],
error: ErrorUtils.getLatestErrorField(config, CONST.SAGE_INTACCT_CONFIG.AUTO_SYNC_ENABLED),
onCloseError: () => Policy.clearSageIntacctErrorField(policyID, CONST.SAGE_INTACCT_CONFIG.AUTO_SYNC_ENABLED),
error: getLatestErrorField(config, CONST.SAGE_INTACCT_CONFIG.AUTO_SYNC_ENABLED),
onCloseError: () => clearSageIntacctErrorField(policyID, CONST.SAGE_INTACCT_CONFIG.AUTO_SYNC_ENABLED),
},
{
label: translate('workspace.sageIntacct.inviteEmployees'),
Expand All @@ -54,12 +58,10 @@
updateSageIntacctApprovalMode(policyID, enabled);
},
subscribedSettings: [CONST.SAGE_INTACCT_CONFIG.IMPORT_EMPLOYEES, CONST.SAGE_INTACCT_CONFIG.APPROVAL_MODE],
error:
ErrorUtils.getLatestErrorField(config ?? {}, CONST.SAGE_INTACCT_CONFIG.IMPORT_EMPLOYEES) ??
ErrorUtils.getLatestErrorField(config ?? {}, CONST.SAGE_INTACCT_CONFIG.APPROVAL_MODE),
error: getLatestErrorField(config ?? {}, CONST.SAGE_INTACCT_CONFIG.IMPORT_EMPLOYEES) ?? getLatestErrorField(config ?? {}, CONST.SAGE_INTACCT_CONFIG.APPROVAL_MODE),
onCloseError: () => {
Policy.clearSageIntacctErrorField(policyID, CONST.SAGE_INTACCT_CONFIG.IMPORT_EMPLOYEES);
Policy.clearSageIntacctErrorField(policyID, CONST.SAGE_INTACCT_CONFIG.APPROVAL_MODE);
clearSageIntacctErrorField(policyID, CONST.SAGE_INTACCT_CONFIG.IMPORT_EMPLOYEES);
clearSageIntacctErrorField(policyID, CONST.SAGE_INTACCT_CONFIG.APPROVAL_MODE);
},
},
{
Expand All @@ -70,14 +72,14 @@
updateSageIntacctSyncReimbursedReports(policyID, enabled);

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

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

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

updateSageIntacctSyncReimbursementAccountID(policyID, reimbursementAccountID);
}
},
subscribedSettings: [CONST.SAGE_INTACCT_CONFIG.SYNC_REIMBURSED_REPORTS],
error: ErrorUtils.getLatestErrorField(config ?? {}, CONST.SAGE_INTACCT_CONFIG.SYNC_REIMBURSED_REPORTS),
error: getLatestErrorField(config ?? {}, CONST.SAGE_INTACCT_CONFIG.SYNC_REIMBURSED_REPORTS),
onCloseError: () => {
Policy.clearSageIntacctErrorField(policyID, CONST.SAGE_INTACCT_CONFIG.SYNC_REIMBURSED_REPORTS);
clearSageIntacctErrorField(policyID, CONST.SAGE_INTACCT_CONFIG.SYNC_REIMBURSED_REPORTS);
},
},
],
Expand Down Expand Up @@ -113,20 +115,23 @@
/>
))}

{!!sync?.syncReimbursedReports && (
<Accordion
isExpanded={isAccordionExpanded}
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';
import {getLatestErrorField} 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';
import {updateSageIntacctDefaultVendor} from '@userActions/connections/SageIntacct';
import * as Policy from '@userActions/Policy/Policy';
import {clearSageIntacctErrorField} from '@userActions/Policy/Policy';
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),
onCloseError: () => 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),
errors: 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,17 @@
wrapperStyle={[styles.mv3, styles.ph5]}
/>
);
default:
case 'accordion':
return (
<OfflineWithFeedback
key={item.description}
pendingAction={settingsPendingAction(item.subscribedSettings, config?.pendingFields)}
<Accordion
isExpanded={item.shouldExpand}
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
Loading
Loading