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 Export Quickbooks pages #40713

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import * as Connections from '@libs/actions/connections';
import Navigation from '@navigation/Navigation';
import AdminPolicyAccessOrNotFoundWrapper from '@pages/workspace/AdminPolicyAccessOrNotFoundWrapper';
import FeatureEnabledAccessOrNotFoundWrapper from '@pages/workspace/FeatureEnabledAccessOrNotFoundWrapper';
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';

Expand All @@ -27,8 +27,6 @@ type Card = {name: string};
function QuickbooksCompanyCardExpenseAccountSelectPage({policy}: WithPolicyProps) {
const {translate} = useLocalize();
const styles = useThemeStyles();
const {creditCards} = policy?.connections?.quickbooksOnline?.data ?? {};

const {exportCompanyCard, syncLocations} = policy?.connections?.quickbooksOnline?.config ?? {};
const isLocationEnabled = Boolean(syncLocations && syncLocations !== CONST.INTEGRATION_ENTITY_MAP_TYPES.NONE);

Expand All @@ -46,12 +44,7 @@ function QuickbooksCompanyCardExpenseAccountSelectPage({policy}: WithPolicyProps
],
[translate],
);
const cards = useMemo<Card[]>(() => {
if (creditCards?.length) {
return creditCards;
}
return isLocationEnabled ? defaultCards.slice(0, -1) : defaultCards;
}, [creditCards, isLocationEnabled, defaultCards]);
const cards = useMemo<Card[]>(() => (isLocationEnabled ? defaultCards.slice(0, -1) : defaultCards), [isLocationEnabled, defaultCards]);

const data = useMemo<CardListItem[]>(
() =>
Expand Down Expand Up @@ -106,4 +99,4 @@ function QuickbooksCompanyCardExpenseAccountSelectPage({policy}: WithPolicyProps

QuickbooksCompanyCardExpenseAccountSelectPage.displayName = 'QuickbooksCompanyCardExpenseAccountSelectPage';

export default withPolicy(QuickbooksCompanyCardExpenseAccountSelectPage);
export default withPolicyConnections(QuickbooksCompanyCardExpenseAccountSelectPage);
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@navigation/Navigation';
import AdminPolicyAccessOrNotFoundWrapper from '@pages/workspace/AdminPolicyAccessOrNotFoundWrapper';
import FeatureEnabledAccessOrNotFoundWrapper from '@pages/workspace/FeatureEnabledAccessOrNotFoundWrapper';
import withPolicy from '@pages/workspace/withPolicy';
import type {WithPolicyProps} from '@pages/workspace/withPolicy';
import withPolicyConnections from '@pages/workspace/withPolicyConnections';
import * as Link from '@userActions/Link';
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';
Expand Down Expand Up @@ -125,4 +125,4 @@ function QuickbooksExportConfigurationPage({policy}: WithPolicyProps) {

QuickbooksExportConfigurationPage.displayName = 'QuickbooksExportConfigurationPage';

export default withPolicy(QuickbooksExportConfigurationPage);
export default withPolicyConnections(QuickbooksExportConfigurationPage);
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import * as Connections from '@libs/actions/connections';
import Navigation from '@navigation/Navigation';
import AdminPolicyAccessOrNotFoundWrapper from '@pages/workspace/AdminPolicyAccessOrNotFoundWrapper';
import FeatureEnabledAccessOrNotFoundWrapper from '@pages/workspace/FeatureEnabledAccessOrNotFoundWrapper';
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';

Expand Down Expand Up @@ -69,4 +69,4 @@ function QuickbooksExportDateSelectPage({policy}: WithPolicyProps) {

QuickbooksExportDateSelectPage.displayName = 'QuickbooksExportDateSelectPage';

export default withPolicy(QuickbooksExportDateSelectPage);
export default withPolicyConnections(QuickbooksExportDateSelectPage);
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import * as Connections from '@libs/actions/connections';
import Navigation from '@navigation/Navigation';
import AdminPolicyAccessOrNotFoundWrapper from '@pages/workspace/AdminPolicyAccessOrNotFoundWrapper';
import FeatureEnabledAccessOrNotFoundWrapper from '@pages/workspace/FeatureEnabledAccessOrNotFoundWrapper';
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';

Expand All @@ -25,27 +25,17 @@ function QuickbooksExportInvoiceAccountSelectPage({policy}: WithPolicyProps) {
const styles = useThemeStyles();
const {accountsReceivable} = policy?.connections?.quickbooksOnline?.data ?? {};
const {exportInvoice} = policy?.connections?.quickbooksOnline?.config ?? {};
// TODO - should be removed after API fully working
const draft = [
{
name: translate(`workspace.qbo.receivable`),
},
{
name: translate(`workspace.qbo.archive`),
},
];
const result = accountsReceivable?.length ? accountsReceivable : draft;

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

const onSelectRow = useCallback(
Expand Down Expand Up @@ -81,4 +71,4 @@ function QuickbooksExportInvoiceAccountSelectPage({policy}: WithPolicyProps) {

QuickbooksExportInvoiceAccountSelectPage.displayName = 'QuickbooksExportInvoiceAccountSelectPage';

export default withPolicy(QuickbooksExportInvoiceAccountSelectPage);
export default withPolicyConnections(QuickbooksExportInvoiceAccountSelectPage);
narefyev91 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,11 @@ import * as Connections from '@libs/actions/connections';
import Navigation from '@navigation/Navigation';
import AdminPolicyAccessOrNotFoundWrapper from '@pages/workspace/AdminPolicyAccessOrNotFoundWrapper';
import FeatureEnabledAccessOrNotFoundWrapper from '@pages/workspace/FeatureEnabledAccessOrNotFoundWrapper';
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';

// TODO - should be removed after API fully working
const draft = [
{
name: 'Accounts Payable (A/P)',
},
{
name: 'Payroll Accounts',
},
];
import type {Account} from '@src/types/onyx/Policy';

type CardListItem = ListItem & {
value: string;
Expand All @@ -38,22 +29,22 @@ function QuickbooksOutOfPocketExpenseAccountSelectPage({policy}: WithPolicyProps
const {exportEntity, exportAccount} = policy?.connections?.quickbooksOnline?.config ?? {};

const data: CardListItem[] = useMemo(() => {
let result;
let accounts: Account[];
switch (exportEntity) {
case CONST.QUICKBOOKS_EXPORT_ENTITY.CHECK:
result = bankAccounts ?? [];
accounts = bankAccounts ?? [];
break;
case CONST.QUICKBOOKS_EXPORT_ENTITY.VENDOR_BILL:
result = accountsPayable ?? [];
accounts = accountsPayable ?? [];
break;
case CONST.QUICKBOOKS_EXPORT_ENTITY.JOURNAL_ENTRY:
result = journalEntryAccounts ?? [];
accounts = journalEntryAccounts ?? [];
break;
default:
result = draft;
accounts = [];
}

return (draft ?? result)?.map((card) => ({
return accounts.map((card) => ({
value: card.name,
text: card.name,
keyForList: card.name,
Expand Down Expand Up @@ -96,4 +87,4 @@ function QuickbooksOutOfPocketExpenseAccountSelectPage({policy}: WithPolicyProps

QuickbooksOutOfPocketExpenseAccountSelectPage.displayName = 'QuickbooksOutOfPocketExpenseAccountSelectPage';

export default withPolicy(QuickbooksOutOfPocketExpenseAccountSelectPage);
export default withPolicyConnections(QuickbooksOutOfPocketExpenseAccountSelectPage);
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@navigation/Navigation';
import AdminPolicyAccessOrNotFoundWrapper from '@pages/workspace/AdminPolicyAccessOrNotFoundWrapper';
import FeatureEnabledAccessOrNotFoundWrapper from '@pages/workspace/FeatureEnabledAccessOrNotFoundWrapper';
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';

Expand Down Expand Up @@ -76,4 +76,4 @@ function QuickbooksOutOfPocketExpenseConfigurationPage({policy}: WithPolicyProps

QuickbooksOutOfPocketExpenseConfigurationPage.displayName = 'QuickbooksExportOutOfPocketExpensesPage';

export default withPolicy(QuickbooksOutOfPocketExpenseConfigurationPage);
export default withPolicyConnections(QuickbooksOutOfPocketExpenseConfigurationPage);
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import * as Connections from '@libs/actions/connections';
import Navigation from '@navigation/Navigation';
import AdminPolicyAccessOrNotFoundWrapper from '@pages/workspace/AdminPolicyAccessOrNotFoundWrapper';
import FeatureEnabledAccessOrNotFoundWrapper from '@pages/workspace/FeatureEnabledAccessOrNotFoundWrapper';
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';

Expand Down Expand Up @@ -111,4 +111,4 @@ function QuickbooksOutOfPocketExpenseEntitySelectPage({policy}: WithPolicyProps)

QuickbooksOutOfPocketExpenseEntitySelectPage.displayName = 'QuickbooksOutOfPocketExpenseEntitySelectPage';

export default withPolicy(QuickbooksOutOfPocketExpenseEntitySelectPage);
export default withPolicyConnections(QuickbooksOutOfPocketExpenseEntitySelectPage);
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,11 @@ import {getAdminEmployees} from '@libs/PolicyUtils';
import Navigation from '@navigation/Navigation';
import AdminPolicyAccessOrNotFoundWrapper from '@pages/workspace/AdminPolicyAccessOrNotFoundWrapper';
import FeatureEnabledAccessOrNotFoundWrapper from '@pages/workspace/FeatureEnabledAccessOrNotFoundWrapper';
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';

// TODO - should be removed after API fully working
const draft = [
{name: '+14153166423@expensify.sms', currency: 'USD', id: '94', email: '+14153166423@expensify.sms'},
{name: 'Account Maintenance Fee', currency: 'USD', id: '141', email: 'alberto@expensify213.com'},
{name: 'Admin Test', currency: 'USD', id: '119', email: 'admin@qbocard.com'},
{name: 'Alberto Gonzalez-Cela', currency: 'USD', id: '104', email: 'alberto@expensify.com'},
{name: 'Aldo test QBO2 QBO2 Last name', currency: 'USD', id: '140', email: 'admin@qbo.com'},
];

type CardListItem = ListItem & {
value: string;
};
Expand All @@ -35,12 +26,11 @@ function QuickBooksExportPreferredExporterPage({policy}: WithPolicyProps) {
const styles = useThemeStyles();
const {exporter} = policy?.connections?.quickbooksOnline?.config ?? {};
const exporters = getAdminEmployees(policy);
const result = exporters?.length ? exporters : draft;

const policyID = policy?.id ?? '';
const data: CardListItem[] = useMemo(
() =>
result.reduce<CardListItem[]>((vendors, vendor) => {
exporters?.reduce<CardListItem[]>((vendors, vendor) => {
if (vendor.email) {
vendors.push({
value: vendor.email,
Expand All @@ -51,7 +41,7 @@ function QuickBooksExportPreferredExporterPage({policy}: WithPolicyProps) {
}
return vendors;
}, []),
[result, exporter],
[exporter, exporters],
);

const onSelectRow = useCallback(
Expand Down Expand Up @@ -92,4 +82,4 @@ function QuickBooksExportPreferredExporterPage({policy}: WithPolicyProps) {

QuickBooksExportPreferredExporterPage.displayName = 'QuickBooksExportPreferredExporterPage';

export default withPolicy(QuickBooksExportPreferredExporterPage);
export default withPolicyConnections(QuickBooksExportPreferredExporterPage);
1 change: 1 addition & 0 deletions src/types/onyx/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,4 +475,5 @@ export type {
PolicyConnectionSyncProgress,
Connections,
ConnectionName,
Account,
};
Loading