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

Swap from withPolicy to withPolicyConnections for advanced Quickbooks pages #40718

Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
827b1f2
swap withPolicy to withPolicyConnections for advanced page
teneeto Apr 22, 2024
c648855
Merge branch 'main' of github.com:teneeto/Expensify into qbo-hoc-with…
teneeto Apr 24, 2024
9ae3099
remove drafts
teneeto Apr 24, 2024
213aef4
update selected qbo and invoice collection name
teneeto Apr 24, 2024
fea4550
Merge branch 'main' of github.com:teneeto/Expensify into qbo-hoc-with…
teneeto Apr 25, 2024
1bf7048
Merge branch 'main' of github.com:teneeto/Expensify into qbo-hoc-with…
teneeto Apr 25, 2024
a310abb
use WithPolicyConnectionsProps
teneeto Apr 25, 2024
c064fc6
use WithPolicyConnectionsProps
teneeto Apr 25, 2024
bd5f257
use WithPolicyConnectionsProps
teneeto Apr 25, 2024
83561ec
add sync reimbursed to qboToggleSettingItems
teneeto Apr 25, 2024
d0ff87e
remove all horizontal line spacer view
teneeto Apr 25, 2024
3301d0a
move sync reimbursed items to syncReimbursedSubMenuItems
teneeto Apr 25, 2024
21d3840
update translations
teneeto Apr 25, 2024
b9decde
use new translations
teneeto Apr 25, 2024
730ec7b
remove collectionAccountDescription
teneeto Apr 25, 2024
2cab80f
remove menuItem
teneeto Apr 25, 2024
b50e330
add vertical margins
teneeto Apr 25, 2024
786321f
enable sync reimbursed accounts for any available account
teneeto Apr 25, 2024
99bf390
set isActive to isSyncReimbursedSwitchOn
teneeto Apr 25, 2024
20f439a
use updated translation string
teneeto Apr 25, 2024
d0b770c
use updated translation string
teneeto Apr 25, 2024
6749014
Update src/languages/es.ts
teneeto Apr 25, 2024
7339458
Update src/languages/es.ts
teneeto Apr 25, 2024
9235dec
Update src/languages/es.ts
teneeto Apr 25, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,33 @@ import Navigation from '@libs/Navigation/Navigation';
import AdminPolicyAccessOrNotFoundWrapper from '@pages/workspace/AdminPolicyAccessOrNotFoundWrapper';
import FeatureEnabledAccessOrNotFoundWrapper from '@pages/workspace/FeatureEnabledAccessOrNotFoundWrapper';
import PaidPolicyAccessOrNotFoundWrapper from '@pages/workspace/PaidPolicyAccessOrNotFoundWrapper';
import withPolicy from '@pages/workspace/withPolicy';
import type {WithPolicyProps} from '@pages/workspace/withPolicy';
import withPolicyConnections from '@pages/workspace/withPolicyConnections';
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';

type SelectorType = ListItem & {
value: string;
};

// TODO: remove once UI is approved
const DRAFT = [
{name: 'Croissant Co Payroll Account', id: 'Croissant Co Payroll Account'},
{name: 'Croissant Co Money in Clearing', id: 'Croissant Co Money in Clearing'},
{name: 'Croissant Co Debts and Loans', id: 'Croissant Co Debts and Loans'},
];

function QuickbooksAccountSelectPage({policy}: WithPolicyProps) {
teneeto marked this conversation as resolved.
Show resolved Hide resolved
const styles = useThemeStyles();
const {translate} = useLocalize();

const selectedAccount = DRAFT[0].id; // selected

const policyID = policy?.id ?? '';
const {bankAccounts, creditCards} = policy?.connections?.quickbooksOnline?.data ?? {};
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const accountOptions = useMemo(() => DRAFT || [...(bankAccounts ?? []), ...(creditCards ?? [])], [bankAccounts, creditCards]);
const {reimbursementAccountID} = policy?.connections?.quickbooksOnline?.config ?? {};
const accountOptions = useMemo(() => [...(bankAccounts ?? []), ...(creditCards ?? [])], [bankAccounts, creditCards]);

const qboOnlineSelectorOptions = useMemo<SelectorType[]>(
() =>
accountOptions?.map(({id, name}) => ({
value: id,
text: name,
keyForList: id,
isSelected: selectedAccount === id,
isSelected: reimbursementAccountID === id,
})),
[selectedAccount, accountOptions],
[reimbursementAccountID, accountOptions],
);
const listHeaderComponent = useMemo(
() => (
Expand Down Expand Up @@ -98,4 +89,4 @@ function QuickbooksAccountSelectPage({policy}: WithPolicyProps) {

QuickbooksAccountSelectPage.displayName = 'QuickbooksAccountSelectPage';

export default withPolicy(QuickbooksAccountSelectPage);
export default withPolicyConnections(QuickbooksAccountSelectPage);
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, {useMemo} from 'react';
import {View} from 'react-native';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import MenuItem from '@components/MenuItem';
Expand All @@ -16,8 +16,8 @@ import Navigation from '@libs/Navigation/Navigation';
import AdminPolicyAccessOrNotFoundWrapper from '@pages/workspace/AdminPolicyAccessOrNotFoundWrapper';
import FeatureEnabledAccessOrNotFoundWrapper from '@pages/workspace/FeatureEnabledAccessOrNotFoundWrapper';
import PaidPolicyAccessOrNotFoundWrapper from '@pages/workspace/PaidPolicyAccessOrNotFoundWrapper';
import withPolicy from '@pages/workspace/withPolicy';
import type {WithPolicyProps} from '@pages/workspace/withPolicy';
import withPolicyConnections from '@pages/workspace/withPolicyConnections';
import ToggleSettingOptionRow from '@pages/workspace/workflows/ToggleSettingsOptionRow';
import type {ToggleSettingOptionRowProps} from '@pages/workspace/workflows/ToggleSettingsOptionRow';
import * as Policy from '@userActions/Policy';
Expand All @@ -31,9 +31,19 @@ function QuickbooksAdvancedPage({policy}: WithPolicyProps) {

const policyID = policy?.id ?? '';
const qboConfig = policy?.connections?.quickbooksOnline?.config;
const {autoSync, syncPeople, autoCreateVendor, pendingFields, collectionAccountID, errorFields} = qboConfig ?? {};
const {autoSync, syncPeople, autoCreateVendor, pendingFields, collectionAccountID, reimbursementAccountID, errorFields} = qboConfig ?? {};
const {bankAccounts, creditCards, otherCurrentAssetAccounts} = policy?.connections?.quickbooksOnline?.data ?? {};

const qboAccountOptions = useMemo(() => [...(bankAccounts ?? []), ...(creditCards ?? [])], [bankAccounts, creditCards]);
const invoiceAccountCollectionOptions = useMemo(() => [...(bankAccounts ?? []), ...(otherCurrentAssetAccounts ?? [])], [bankAccounts, otherCurrentAssetAccounts]);

const isSyncReimbursedSwitchOn = !!collectionAccountID;
const selectedAccount = '92345'; // TODO: use fake selected account temporarily.

const selectedQboAccountName = useMemo(() => qboAccountOptions?.find(({id}) => id === reimbursementAccountID)?.name, [qboAccountOptions, reimbursementAccountID]);
const selectedInvoiceCollectionAccountName = useMemo(
() => invoiceAccountCollectionOptions?.find(({id}) => id === collectionAccountID)?.name,
[invoiceAccountCollectionOptions, collectionAccountID],
);

const qboToggleSettingItems: ToggleSettingOptionRowProps[] = [
{
Expand Down Expand Up @@ -119,7 +129,7 @@ function QuickbooksAdvancedPage({policy}: WithPolicyProps) {
policyID,
CONST.POLICY.CONNECTIONS.NAME.QBO,
CONST.QUICK_BOOKS_CONFIG.COLLECTION_ACCOUNT_ID,
isSyncReimbursedSwitchOn ? '' : selectedAccount,
isSyncReimbursedSwitchOn ? '' : bankAccounts?.[0].id,
)
}
/>
Expand All @@ -129,7 +139,7 @@ function QuickbooksAdvancedPage({policy}: WithPolicyProps) {
<OfflineWithFeedback pendingAction={pendingFields?.reimbursementAccountID}>
<MenuItemWithTopDescription
shouldShowRightIcon
title="Croissant Co Payroll Account" // TODO: set to the current selected value
title={selectedQboAccountName}
description={translate('workspace.qbo.advancedConfig.qboAccount')}
wrapperStyle={[styles.sectionMenuItemTopDescription]}
onPress={waitForNavigate(() => Navigation.navigate(ROUTES.WORKSPACE_ACCOUNTING_QUICKBOOKS_ONLINE_ACCOUNT_SELECTOR.getRoute(policyID)))}
Expand All @@ -154,7 +164,7 @@ function QuickbooksAdvancedPage({policy}: WithPolicyProps) {
interactive={false}
/>
<MenuItemWithTopDescription
title="Croissant Co Money in Clearing" // TODO: set to the current selected value
title={selectedInvoiceCollectionAccountName}
shouldShowRightIcon
wrapperStyle={[styles.sectionMenuItemTopDescription]}
onPress={waitForNavigate(() => Navigation.navigate(ROUTES.WORKSPACE_ACCOUNTING_QUICKBOOKS_ONLINE_INVOICE_ACCOUNT_SELECTOR.getRoute(policyID)))}
Expand All @@ -174,4 +184,4 @@ function QuickbooksAdvancedPage({policy}: WithPolicyProps) {

QuickbooksAdvancedPage.displayName = 'QuickbooksAdvancedPage';

export default withPolicy(QuickbooksAdvancedPage);
export default withPolicyConnections(QuickbooksAdvancedPage);
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,33 @@ import Navigation from '@libs/Navigation/Navigation';
import AdminPolicyAccessOrNotFoundWrapper from '@pages/workspace/AdminPolicyAccessOrNotFoundWrapper';
import FeatureEnabledAccessOrNotFoundWrapper from '@pages/workspace/FeatureEnabledAccessOrNotFoundWrapper';
import PaidPolicyAccessOrNotFoundWrapper from '@pages/workspace/PaidPolicyAccessOrNotFoundWrapper';
import withPolicy from '@pages/workspace/withPolicy';
import type {WithPolicyProps} from '@pages/workspace/withPolicy';
import withPolicyConnections from '@pages/workspace/withPolicyConnections';
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';

type SelectorType = ListItem & {
value: string;
};

// TODO: remove once UI is approved
const DRAFT = [
{name: 'Croissant Co Payroll Account', id: 'Croissant Co Payroll Account'},
{name: 'Croissant Co Money in Clearing', id: 'Croissant Co Money in Clearing'},
{name: 'Croissant Co Debts and Loans', id: 'Croissant Co Debts and Loans'},
];

function QuickbooksInvoiceAccountSelectPage({policy}: WithPolicyProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();

const selectedAccount = DRAFT[1].id; // selected

const policyID = policy?.id ?? '';
const {bankAccounts, otherCurrentAssetAccounts} = policy?.connections?.quickbooksOnline?.data ?? {};
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const accountOptions = useMemo(() => DRAFT || [...(bankAccounts ?? []), ...(otherCurrentAssetAccounts ?? [])], [bankAccounts, otherCurrentAssetAccounts]);
const accountOptions = useMemo(() => [...(bankAccounts ?? []), ...(otherCurrentAssetAccounts ?? [])], [bankAccounts, otherCurrentAssetAccounts]);
const {collectionAccountID} = policy?.connections?.quickbooksOnline?.config ?? {};

const qboOnlineSelectorOptions = useMemo<SelectorType[]>(
() =>
accountOptions?.map(({id, name}) => ({
value: id,
text: name,
keyForList: id,
isSelected: selectedAccount === id,
isSelected: collectionAccountID === id,
})),
[selectedAccount, accountOptions],
[collectionAccountID, accountOptions],
);

const listHeaderComponent = useMemo(
Expand Down Expand Up @@ -99,4 +90,4 @@ function QuickbooksInvoiceAccountSelectPage({policy}: WithPolicyProps) {

QuickbooksInvoiceAccountSelectPage.displayName = 'QuickbooksInvoiceAccountSelectPage';

export default withPolicy(QuickbooksInvoiceAccountSelectPage);
export default withPolicyConnections(QuickbooksInvoiceAccountSelectPage);
Loading