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

[HOLD Expensify/issues/390731] Fix account menu item visibility + reset account values #41079

Closed
wants to merge 11 commits into from
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, {useEffect} from 'react';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
Expand All @@ -23,6 +23,18 @@ function QuickbooksCompanyCardExpenseAccountPage({policy}: WithPolicyConnections
const policyID = policy?.id ?? '';
const {exportCompanyCardAccount, exportAccountPayable, autoCreateVendor, errorFields, pendingFields, exportCompanyCard} = policy?.connections?.quickbooksOnline?.config ?? {};
const isVendorSelected = exportCompanyCard === CONST.QUICKBOOKS_EXPORT_COMPANY_CARD.VENDOR_BILL;
const showAccountSelection = Boolean(autoCreateVendor) || (!isVendorSelected && exportCompanyCard);
const {vendors} = policy?.connections?.quickbooksOnline?.data ?? {};
narefyev91 marked this conversation as resolved.
Show resolved Hide resolved

useEffect(() => {
if (!isVendorSelected) {
return;
}
if (Boolean(autoCreateVendor) && !exportCompanyCardAccount) {
Connections.updatePolicyConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.QBO, CONST.QUICK_BOOKS_CONFIG.EXPORT_COMPANY_CARD_ACCOUNT, vendors?.[0]?.name);
}
narefyev91 marked this conversation as resolved.
Show resolved Hide resolved
}, [autoCreateVendor, exportCompanyCardAccount, isVendorSelected, policyID, vendors]);

return (
<AdminPolicyAccessOrNotFoundWrapper policyID={policyID}>
<FeatureEnabledAccessOrNotFoundWrapper
Expand Down Expand Up @@ -67,23 +79,28 @@ function QuickbooksCompanyCardExpenseAccountPage({policy}: WithPolicyConnections
title={translate('workspace.qbo.defaultVendor')}
wrapperStyle={[styles.ph5, styles.mb3, styles.mt1]}
isActive={Boolean(autoCreateVendor)}
onToggle={(isOn) =>
Connections.updatePolicyConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.QBO, CONST.QUICK_BOOKS_CONFIG.AUTO_CREATE_VENDOR, isOn)
}
onToggle={(isOn) => {
if (!isOn) {
Connections.updatePolicyConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.QBO, CONST.QUICK_BOOKS_CONFIG.EXPORT_COMPANY_CARD_ACCOUNT);
}
narefyev91 marked this conversation as resolved.
Show resolved Hide resolved
Connections.updatePolicyConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.QBO, CONST.QUICK_BOOKS_CONFIG.AUTO_CREATE_VENDOR, isOn);
}}
pendingAction={pendingFields?.autoCreateVendor}
/>
narefyev91 marked this conversation as resolved.
Show resolved Hide resolved
</>
)}
<OfflineWithFeedback pendingAction={pendingFields?.exportCompanyCardAccount}>
<MenuItemWithTopDescription
title={exportCompanyCardAccount}
description={isVendorSelected ? translate('workspace.qbo.vendor') : translate('workspace.qbo.account')}
onPress={() => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_COMPANY_CARD_EXPENSE_ACCOUNT_SELECT.getRoute(policyID))}
brickRoadIndicator={errorFields?.exportCompanyCardAccount ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined}
shouldShowRightIcon
error={errorFields?.exportCompanyCardAccount ? translate('common.genericErrorMessage') : undefined}
/>
</OfflineWithFeedback>
{showAccountSelection && (
<OfflineWithFeedback pendingAction={pendingFields?.exportCompanyCardAccount}>
<MenuItemWithTopDescription
title={exportCompanyCardAccount}
description={isVendorSelected ? translate('workspace.qbo.vendor') : translate('workspace.qbo.account')}
onPress={() => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_COMPANY_CARD_EXPENSE_ACCOUNT_SELECT.getRoute(policyID))}
brickRoadIndicator={errorFields?.exportCompanyCardAccount ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined}
shouldShowRightIcon
error={errorFields?.exportCompanyCardAccount ? translate('common.genericErrorMessage') : undefined}
/>
</OfflineWithFeedback>
)}
</ScrollView>
</ScreenWrapper>
</FeatureEnabledAccessOrNotFoundWrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ type CardListItem = ListItem & {
function QuickbooksCompanyCardExpenseAccountPayableSelectPage({policy}: WithPolicyConnectionsProps) {
const {translate} = useLocalize();
const styles = useThemeStyles();
const {accountsPayable} = policy?.connections?.quickbooksOnline?.data ?? {};
const {accountPayable} = policy?.connections?.quickbooksOnline?.data ?? {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a memo for myself. Checked this field name is correct

Screenshot 2024-05-06 at 8 59 38 AM

const {exportAccountPayable} = policy?.connections?.quickbooksOnline?.config ?? {};

const policyID = policy?.id ?? '';
const data: CardListItem[] = useMemo(
() =>
accountsPayable?.map((account) => ({
accountPayable?.map((account) => ({
value: account.name,
text: account.name,
keyForList: account.name,
isSelected: account.name === exportAccountPayable,
})) ?? [],
[exportAccountPayable, accountsPayable],
[exportAccountPayable, accountPayable],
);

const selectAccountPayable = useCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function QuickbooksCompanyCardExpenseAccountSelectCardPage({policy}: WithPolicyC
const policyID = policy?.id ?? '';
const {exportCompanyCard, syncLocations} = policy?.connections?.quickbooksOnline?.config ?? {};
const isLocationEnabled = Boolean(syncLocations && syncLocations !== CONST.INTEGRATION_ENTITY_MAP_TYPES.NONE);
const {creditCards, bankAccounts, accountPayable} = policy?.connections?.quickbooksOnline?.data ?? {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

memo: checked that these field names are correct

Screenshot 2024-05-06 at 9 01 06 AM


const defaultCards = useMemo<Card[]>(
() => [
Expand Down Expand Up @@ -68,11 +69,18 @@ function QuickbooksCompanyCardExpenseAccountSelectCardPage({policy}: WithPolicyC
(row: CardListItem) => {
if (row.value !== exportCompanyCard) {
Connections.updatePolicyConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.QBO, CONST.QUICK_BOOKS_CONFIG.EXPORT_COMPANY_CARD, row.value);
Connections.updatePolicyConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.QBO, CONST.QUICK_BOOKS_CONFIG.EXPORT_COMPANY_CARD_ACCOUNT);
if (row.value === CONST.QUICKBOOKS_EXPORT_COMPANY_CARD.VENDOR_BILL) {
Connections.updatePolicyConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.QBO, CONST.QUICK_BOOKS_CONFIG.EXPORT_COMPANY_CARD_ACCOUNT);
Connections.updatePolicyConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.QBO, CONST.QUICK_BOOKS_CONFIG.EXPORT_ACCOUNT_PAYABLE, accountPayable?.[0]?.name);
Connections.updatePolicyConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.QBO, CONST.QUICK_BOOKS_CONFIG.AUTO_CREATE_VENDOR);
Comment on lines 70 to +74
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New record! 4 API calls 😅 cc @hayata-suenaga same question ^

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@s77rt is correct. This breaks the 1:1:1 API design and shouldn't be allowed.

Copy link
Contributor

@hayata-suenaga hayata-suenaga Apr 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@narefyev91

also, can you remind me why we added this field to the config object? 😄
Screenshot 2024-04-30 at 12 33 55 PM

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also this one
Screenshot 2024-04-30 at 12 36 15 PM

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

were these values there before your PR? 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes in the backend will be done in this GH issue to update several fields of the connections configuration object, but the issue description might need to be updated. cc: @aldo-expensify

There are fields I don't recognized, so I'd wait for @narefyev91's confirmation

Copy link
Contributor

@hayata-suenaga hayata-suenaga Apr 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes these values were added in the PR.

Screenshot 2024-04-30 at 12 41 59 PM

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these fields don't exist on the backend 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't be adding config fields that don't already exist. This is a sample working QBO config:

{
    "realmId": "2222",
    "credentials": {},
    "companyName": "Expensify",
    "autoSync": {
        "jobID": "11111111111",
        "enabled": true
    },
    "syncPeople": true,
    "syncItems": true,
    "markChecksToBePrinted": false,
    "reimbursableExpensesExportDestination": "bill",
    "nonReimbursableExpensesExportDestination": "credit_card",
    "reimbursableExpensesAccount": {
        "glCode": "",
        "name": "Accounts Payable",
        "currency": "USD",
        "id": "54"
    },
    "nonReimbursableExpensesAccount": {
        "glCode": "",
        "name": "Expensify Card Liability Account",
        "currency": "USD",
        "id": "135"
    },
    "autoCreateVendor": true,
    "hasChosenAutoSyncOption": true,
    "syncClasses": "REPORT_FIELD",
    "syncCustomers": "REPORT_FIELD",
    "syncLocations": "REPORT_FIELD",
    "exportDate": "LAST_EXPENSE",
    "lastConfigurationTime": 1714507864961,
    "syncTax": false,
    "enableNewCategories": true,
    "export": {
        "exporter": "aldo+testqbo56242@expensifail.com"
    },
    "nonReimbursableBillDefaultVendor": "NONE",
    "receivableAccount": {
        "glCode": "",
        "name": "Accounts Receivable",
        "currency": "USD",
        "id": "53"
    },
    "reimbursementAccountID": "93",
    "collectionAccountID": "93"
}

} else {
const accountName = row.value === CONST.QUICKBOOKS_EXPORT_COMPANY_CARD.CREDIT_CARD ? creditCards?.[0]?.name : bankAccounts?.[0]?.name;
Connections.updatePolicyConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.QBO, CONST.QUICK_BOOKS_CONFIG.EXPORT_COMPANY_CARD_ACCOUNT, accountName);
Comment on lines +76 to +77
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAB. Shouldn't we clear EXPORT_ACCOUNT_PAYABLE too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it's not really needed - when user will switch to debit/credit card - EXPORT_ACCOUNT_PAYABLE will not be used anywhere

}
}
Navigation.goBack(ROUTES.POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_COMPANY_CARD_EXPENSE_ACCOUNT.getRoute(policyID));
},
[exportCompanyCard, policyID],
[accountPayable, bankAccounts, creditCards, exportCompanyCard, policyID],
);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type CardListItem = ListItem & {
function QuickbooksOutOfPocketExpenseAccountSelectPage({policy}: WithPolicyConnectionsProps) {
const {translate} = useLocalize();
const styles = useThemeStyles();
const {bankAccounts, journalEntryAccounts, accountsPayable} = policy?.connections?.quickbooksOnline?.data ?? {};
const {bankAccounts, journalEntryAccounts, accountPayable} = policy?.connections?.quickbooksOnline?.data ?? {};

const {exportEntity, exportAccount} = policy?.connections?.quickbooksOnline?.config ?? {};

Expand All @@ -35,7 +35,7 @@ function QuickbooksOutOfPocketExpenseAccountSelectPage({policy}: WithPolicyConne
accounts = bankAccounts ?? [];
break;
case CONST.QUICKBOOKS_EXPORT_ENTITY.VENDOR_BILL:
accounts = accountsPayable ?? [];
accounts = accountPayable ?? [];
break;
case CONST.QUICKBOOKS_EXPORT_ENTITY.JOURNAL_ENTRY:
accounts = journalEntryAccounts ?? [];
Expand All @@ -50,7 +50,7 @@ function QuickbooksOutOfPocketExpenseAccountSelectPage({policy}: WithPolicyConne
keyForList: card.name,
isSelected: card.name === exportAccount,
}));
}, [accountsPayable, bankAccounts, exportAccount, exportEntity, journalEntryAccounts]);
}, [accountPayable, bankAccounts, exportAccount, exportEntity, journalEntryAccounts]);

const policyID = policy?.id ?? '';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function QuickbooksOutOfPocketExpenseConfigurationPage({policy}: WithPolicyConne
<Text style={[styles.ph5, styles.mutedNormalTextLabel, styles.pt1, styles.pb2]}>{translate('workspace.qbo.exportVendorBillDescription')}</Text>
)}
{isLocationEnabled && <Text style={[styles.ph5, styles.mutedNormalTextLabel, styles.pt1]}>{translate('workspace.qbo.outOfPocketLocationEnabledDescription')}</Text>}
{!isLocationEnabled && (
{!isLocationEnabled && exportEntity && (
narefyev91 marked this conversation as resolved.
Show resolved Hide resolved
<OfflineWithFeedback pendingAction={pendingFields?.exportAccount}>
<MenuItemWithTopDescription
title={exportAccount}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function QuickbooksOutOfPocketExpenseEntitySelectPage({policy}: WithPolicyConnec
const isTaxError = isTaxesEnabled && exportEntity === CONST.QUICKBOOKS_EXPORT_ENTITY.JOURNAL_ENTRY;
const isLocationError = isLocationsEnabled && exportEntity !== CONST.QUICKBOOKS_EXPORT_ENTITY.JOURNAL_ENTRY;
const policyID = policy?.id ?? '';
const {bankAccounts, journalEntryAccounts, accountPayable} = policy?.connections?.quickbooksOnline?.data ?? {};

useEffect(() => {
if (!isTaxError && !isLocationError) {
Expand Down Expand Up @@ -74,11 +75,26 @@ function QuickbooksOutOfPocketExpenseEntitySelectPage({policy}: WithPolicyConnec
const selectExportEntity = useCallback(
(row: CardListItem) => {
if (row.value !== exportEntity) {
let accountName;
switch (row.value) {
case CONST.QUICKBOOKS_EXPORT_ENTITY.CHECK:
accountName = bankAccounts?.[0]?.name;
break;
case CONST.QUICKBOOKS_EXPORT_ENTITY.VENDOR_BILL:
accountName = accountPayable?.[0]?.name;
break;
case CONST.QUICKBOOKS_EXPORT_ENTITY.JOURNAL_ENTRY:
accountName = journalEntryAccounts?.[0]?.name;
break;
default:
accountName = undefined;
}
Connections.updatePolicyConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.QBO, CONST.QUICK_BOOKS_CONFIG.EXPORT_ENTITY, row.value);
Connections.updatePolicyConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.QBO, CONST.QUICK_BOOKS_CONFIG.EXPORT_ACCOUNT, accountName);
Comment on lines 91 to +92
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
Navigation.goBack(ROUTES.POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_EXPORT_OUT_OF_POCKET_EXPENSES.getRoute(policyID));
},
[exportEntity, policyID],
[accountPayable, bankAccounts, exportEntity, journalEntryAccounts, policyID],
);

return (
Expand Down
2 changes: 1 addition & 1 deletion src/types/onyx/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ type QBOConnectionData = {
bankAccounts: Account[];
creditCards: Account[];
accountsReceivable: Account[];
accountsPayable: Account[];
accountPayable: Account[];
otherCurrentAssetAccounts: Account[];

taxCodes: TaxCode[];
Expand Down
Loading