-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Added working animation to switch in accounting page #55412
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
Changes from all commits
50a5f90
e83ddb6
07bdd50
abe3617
b529661
688df4f
ab7e7f2
6519991
8711e60
5d8f8f2
562ee23
a0a2843
dc6671f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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'; | ||
|
|
@@ -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'; | ||
|
|
@@ -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
|
||
| 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( | ||
| () => [ | ||
| { | ||
|
|
@@ -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'), | ||
|
|
@@ -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); | ||
| }, | ||
| }, | ||
| { | ||
|
|
@@ -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
|
||
| 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); | ||
| }, | ||
| }, | ||
| ], | ||
|
|
@@ -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> | ||
| ); | ||
| } | ||
|
|
||
| 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
|
||
| 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 | ||
|
|
@@ -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
|
||
| 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, | ||
| }, | ||
| ]; | ||
|
|
||
|
|
@@ -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> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.