From ab496ec966618014c63777b3f6d3c8164c7d2560 Mon Sep 17 00:00:00 2001 From: Nicolay Arefyeu Date: Thu, 7 Nov 2024 14:56:33 +0200 Subject: [PATCH 1/4] Workspace Feed - Fix export item issues --- src/CONST.ts | 10 - src/components/CategoryPicker.tsx | 2 +- src/components/TagPicker/index.tsx | 2 +- src/components/TaxPicker.tsx | 2 +- .../SetCompanyCardExportAccountParams.ts | 2 +- src/libs/OptionsListUtils.ts | 6 +- src/libs/actions/CompanyCards.ts | 10 +- src/pages/ReportParticipantsPage.tsx | 2 +- src/pages/RoomMembersPage.tsx | 2 +- src/pages/WorkspaceSwitcherPage/index.tsx | 2 +- .../NetSuiteCustomListSelectorModal.tsx | 2 +- ...kspaceCompanyCardAccountSelectCardPage.tsx | 4 +- .../WorkspaceCompanyCardDetailsPage.tsx | 201 +++++++++++++++++- src/pages/workspace/companyCards/utils.tsx | 32 ++- ...orkspaceWorkflowsApprovalsApproverPage.tsx | 2 +- 15 files changed, 241 insertions(+), 40 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index 72dff8c87b17..5af95a9abc61 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -1857,7 +1857,6 @@ const CONST = { JOBS: 'jobs', }, }, - NETSUITE_CUSTOM_LIST_LIMIT: 8, NETSUITE_ADD_CUSTOM_LIST_STEP_NAMES: ['1', '2,', '3', '4'], NETSUITE_ADD_CUSTOM_SEGMENT_STEP_NAMES: ['1', '2,', '3', '4', '5', '6,'], }, @@ -4545,9 +4544,6 @@ const CONST = { }, INDENTS: ' ', PARENT_CHILD_SEPARATOR: ': ', - CATEGORY_LIST_THRESHOLD: 8, - TAG_LIST_THRESHOLD: 8, - TAX_RATES_LIST_THRESHOLD: 8, COLON: ':', MAPBOX: { PADDING: 32, @@ -4631,11 +4627,6 @@ const CONST = { */ MAX_SELECTION_LIST_PAGE_LENGTH: 500, - /** - * We only include the members search bar when we have 8 or more members - */ - SHOULD_SHOW_MEMBERS_SEARCH_INPUT_BREAKPOINT: 8, - /** * Bank account names */ @@ -4809,7 +4800,6 @@ const CONST = { WORKSPACE_SWITCHER: { NAME: 'Expensify', SUBSCRIPT_ICON_SIZE: 8, - MINIMUM_WORKSPACES_TO_SHOW_SEARCH: 8, }, WELCOME_VIDEO_URL: `${CLOUDFRONT_URL}/videos/intro-1280.mp4`, diff --git a/src/components/CategoryPicker.tsx b/src/components/CategoryPicker.tsx index 33d97c6909f5..0c855507371a 100644 --- a/src/components/CategoryPicker.tsx +++ b/src/components/CategoryPicker.tsx @@ -56,7 +56,7 @@ function CategoryPicker({selectedCategory, policyID, onSubmit}: CategoryPickerPr const categoryData = categoryOptions?.at(0)?.data ?? []; const header = OptionsListUtils.getHeaderMessageForNonUserList(categoryData.length > 0, debouncedSearchValue); const categoriesCount = OptionsListUtils.getEnabledCategoriesCount(categories); - const isCategoriesCountBelowThreshold = categoriesCount < CONST.CATEGORY_LIST_THRESHOLD; + const isCategoriesCountBelowThreshold = categoriesCount < CONST.STANDARD_LIST_ITEM_LIMIT; const showInput = !isCategoriesCountBelowThreshold; return [categoryOptions, header, showInput]; diff --git a/src/components/TagPicker/index.tsx b/src/components/TagPicker/index.tsx index 9d3a70d4d50c..a64c4c276606 100644 --- a/src/components/TagPicker/index.tsx +++ b/src/components/TagPicker/index.tsx @@ -52,7 +52,7 @@ function TagPicker({selectedTag, tagListName, policyID, tagListIndex, shouldShow const policyRecentlyUsedTagsList = useMemo(() => policyRecentlyUsedTags?.[tagListName] ?? [], [policyRecentlyUsedTags, tagListName]); const policyTagList = PolicyUtils.getTagList(policyTags, tagListIndex); const policyTagsCount = PolicyUtils.getCountOfEnabledTagsOfList(policyTagList.tags); - const isTagsCountBelowThreshold = policyTagsCount < CONST.TAG_LIST_THRESHOLD; + const isTagsCountBelowThreshold = policyTagsCount < CONST.STANDARD_LIST_ITEM_LIMIT; const shouldShowTextInput = !isTagsCountBelowThreshold; diff --git a/src/components/TaxPicker.tsx b/src/components/TaxPicker.tsx index 78ccb1425e21..bc765a7c63ff 100644 --- a/src/components/TaxPicker.tsx +++ b/src/components/TaxPicker.tsx @@ -69,7 +69,7 @@ function TaxPicker({selectedTaxRate = '', policy, transaction, insets, onSubmit, const taxRates = policy?.taxRates; const taxRatesCount = TransactionUtils.getEnabledTaxRateCount(taxRates?.taxes ?? {}); - const isTaxRatesCountBelowThreshold = taxRatesCount < CONST.TAX_RATES_LIST_THRESHOLD; + const isTaxRatesCountBelowThreshold = taxRatesCount < CONST.STANDARD_LIST_ITEM_LIMIT; const shouldShowTextInput = !isTaxRatesCountBelowThreshold; diff --git a/src/libs/API/parameters/SetCompanyCardExportAccountParams.ts b/src/libs/API/parameters/SetCompanyCardExportAccountParams.ts index 861345ff9c55..09f7b1340a36 100644 --- a/src/libs/API/parameters/SetCompanyCardExportAccountParams.ts +++ b/src/libs/API/parameters/SetCompanyCardExportAccountParams.ts @@ -1,7 +1,7 @@ type SetCompanyCardExportAccountParams = { authToken?: string | null; cardID: number; - exportAccountDetails: Record; + exportAccountDetails: string; }; export default SetCompanyCardExportAccountParams; diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 1296a64e571d..5b86755b62fa 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1126,7 +1126,7 @@ function getCategoryListSections( const selectedOptionNames = selectedOptions.map((selectedOption) => selectedOption.name); const filteredCategories = enabledCategories.filter((category) => !selectedOptionNames.includes(category.name)); - if (numberOfEnabledCategories < CONST.CATEGORY_LIST_THRESHOLD) { + if (numberOfEnabledCategories < CONST.STANDARD_LIST_ITEM_LIMIT) { const data = getCategoryOptionTree(filteredCategories, false, selectedOptionsWithDisabledState); categorySections.push({ // "All" section when items amount less than the threshold @@ -1249,7 +1249,7 @@ function getTagListSections( return tagSections; } - if (numberOfTags < CONST.TAG_LIST_THRESHOLD) { + if (numberOfTags < CONST.STANDARD_LIST_ITEM_LIMIT) { tagSections.push({ // "All" section when items amount less than the threshold title: '', @@ -1456,7 +1456,7 @@ function getTaxRatesSection(policy: OnyxEntry | undefined, selectedOptio return policyRatesSections; } - if (numberOfTaxRates < CONST.TAX_RATES_LIST_THRESHOLD) { + if (numberOfTaxRates < CONST.STANDARD_LIST_ITEM_LIMIT) { policyRatesSections.push({ // "All" section when items amount less than the threshold title: '', diff --git a/src/libs/actions/CompanyCards.ts b/src/libs/actions/CompanyCards.ts index be928bc67f3a..b0758e221257 100644 --- a/src/libs/actions/CompanyCards.ts +++ b/src/libs/actions/CompanyCards.ts @@ -461,13 +461,13 @@ function updateCompanyCardName(workspaceAccountID: number, cardID: string, newCa API.write(WRITE_COMMANDS.UPDATE_COMPANY_CARD_NAME, parameters, {optimisticData, finallyData, failureData}); } -function setCompanyCardExportAccount(workspaceAccountID: number, cardID: string, accountKey: string, newAccount: string, bankName: string) { +function setCompanyCardExportAccount(policyID: string, workspaceAccountID: number, cardID: string, accountKey: string, newAccount: string) { const authToken = NetworkStore.getAuthToken(); const optimisticData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${bankName}`, + key: ONYXKEYS.CARD_LIST, value: { [cardID]: { nameValuePairs: { @@ -489,7 +489,7 @@ function setCompanyCardExportAccount(workspaceAccountID: number, cardID: string, const finallyData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${bankName}`, + key: ONYXKEYS.CARD_LIST, value: { [cardID]: { nameValuePairs: { @@ -504,7 +504,7 @@ function setCompanyCardExportAccount(workspaceAccountID: number, cardID: string, const failureData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${bankName}`, + key: ONYXKEYS.CARD_LIST, value: { [cardID]: { nameValuePairs: { @@ -523,7 +523,7 @@ function setCompanyCardExportAccount(workspaceAccountID: number, cardID: string, const parameters: SetCompanyCardExportAccountParams = { authToken, cardID: Number(cardID), - exportAccountDetails: {[accountKey]: newAccount}, + exportAccountDetails: JSON.stringify({[accountKey]: newAccount, [`${accountKey}_policy_id`]: policyID}), }; API.write(WRITE_COMMANDS.SET_CARD_EXPORT_ACCOUNT, parameters, {optimisticData, finallyData, failureData}); diff --git a/src/pages/ReportParticipantsPage.tsx b/src/pages/ReportParticipantsPage.tsx index 405e1dd688f2..1c91023f2d6f 100755 --- a/src/pages/ReportParticipantsPage.tsx +++ b/src/pages/ReportParticipantsPage.tsx @@ -91,7 +91,7 @@ function ReportParticipantsPage({report, route}: ReportParticipantsPageProps) { }); // Include the search bar when there are 8 or more active members in the selection list - const shouldShowTextInput = activeParticipants.length >= CONST.SHOULD_SHOW_MEMBERS_SEARCH_INPUT_BREAKPOINT; + const shouldShowTextInput = activeParticipants.length >= CONST.STANDARD_LIST_ITEM_LIMIT; useEffect(() => { if (!isFocused) { diff --git a/src/pages/RoomMembersPage.tsx b/src/pages/RoomMembersPage.tsx index 6a89eca6f778..37b96514cb63 100644 --- a/src/pages/RoomMembersPage.tsx +++ b/src/pages/RoomMembersPage.tsx @@ -183,7 +183,7 @@ function RoomMembersPage({report, policies}: RoomMembersPageProps) { // When offline, we want to include the pending members with delete action as they are displayed in the list as well return !pendingMember || isOffline || pendingMember.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE; }); - return activeParticipants.length >= CONST.SHOULD_SHOW_MEMBERS_SEARCH_INPUT_BREAKPOINT; + return activeParticipants.length >= CONST.STANDARD_LIST_ITEM_LIMIT; }, [participants, personalDetails, isOffline, report]); useEffect(() => { diff --git a/src/pages/WorkspaceSwitcherPage/index.tsx b/src/pages/WorkspaceSwitcherPage/index.tsx index 221889b80b49..2f81326805d5 100644 --- a/src/pages/WorkspaceSwitcherPage/index.tsx +++ b/src/pages/WorkspaceSwitcherPage/index.tsx @@ -188,7 +188,7 @@ function WorkspaceSwitcherPage() { ListItem={UserListItem} sections={sections} onSelectRow={selectPolicy} - textInputLabel={usersWorkspaces.length >= CONST.WORKSPACE_SWITCHER.MINIMUM_WORKSPACES_TO_SHOW_SEARCH ? translate('common.search') : undefined} + textInputLabel={usersWorkspaces.length >= CONST.STANDARD_LIST_ITEM_LIMIT ? translate('common.search') : undefined} textInputValue={searchTerm} onChangeText={setSearchTerm} headerMessage={headerMessage} diff --git a/src/pages/workspace/accounting/netsuite/import/NetSuiteImportCustomFieldNew/NetSuiteCustomListSelectorModal.tsx b/src/pages/workspace/accounting/netsuite/import/NetSuiteImportCustomFieldNew/NetSuiteCustomListSelectorModal.tsx index e8f0d9e8315f..0f52f6a11d7c 100644 --- a/src/pages/workspace/accounting/netsuite/import/NetSuiteImportCustomFieldNew/NetSuiteCustomListSelectorModal.tsx +++ b/src/pages/workspace/accounting/netsuite/import/NetSuiteImportCustomFieldNew/NetSuiteCustomListSelectorModal.tsx @@ -61,7 +61,7 @@ function NetSuiteCustomListSelectorModal({isVisible, currentCustomListValue, onC }, ], headerMessage: isEmpty ? translate('common.noResultsFound') : '', - showTextInput: customListData.length > CONST.NETSUITE_CONFIG.NETSUITE_CUSTOM_LIST_LIMIT, + showTextInput: customListData.length > CONST.STANDARD_LIST_ITEM_LIMIT, }; }, [debouncedSearchValue, policy?.connections?.netsuite?.options?.data?.customLists, translate, currentCustomListValue]); diff --git a/src/pages/workspace/companyCards/WorkspaceCompanyCardAccountSelectCardPage.tsx b/src/pages/workspace/companyCards/WorkspaceCompanyCardAccountSelectCardPage.tsx index c32cebd7ba18..670f1d90f5be 100644 --- a/src/pages/workspace/companyCards/WorkspaceCompanyCardAccountSelectCardPage.tsx +++ b/src/pages/workspace/companyCards/WorkspaceCompanyCardAccountSelectCardPage.tsx @@ -33,7 +33,7 @@ function WorkspaceCompanyCardAccountSelectCardPage({route}: WorkspaceCompanyCard const workspaceAccountID = PolicyUtils.getWorkspaceAccountID(policyID); const [searchText, setSearchText] = useState(''); - const [allBankCards] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${bank}`); + const [allBankCards] = useOnyx(`${ONYXKEYS.CARD_LIST}`); const card = allBankCards?.[cardID]; const connectedIntegration = PolicyUtils.getConnectedIntegration(policy) ?? CONST.POLICY.CONNECTIONS.NAME.QBO; const exportMenuItem = getExportMenuItem(connectedIntegration, policyID, translate, policy, card); @@ -63,7 +63,7 @@ function WorkspaceCompanyCardAccountSelectCardPage({route}: WorkspaceCompanyCard if (!exportMenuItem?.exportType) { return; } - CompanyCards.setCompanyCardExportAccount(workspaceAccountID, cardID, exportMenuItem.exportType, value, bank); + CompanyCards.setCompanyCardExportAccount(policyID, workspaceAccountID, cardID, exportMenuItem.exportType, value); Navigation.goBack(ROUTES.WORKSPACE_COMPANY_CARD_DETAILS.getRoute(policyID, cardID, bank)); }, diff --git a/src/pages/workspace/companyCards/WorkspaceCompanyCardDetailsPage.tsx b/src/pages/workspace/companyCards/WorkspaceCompanyCardDetailsPage.tsx index c5fc6e5e6eea..f6c29beaa0b6 100644 --- a/src/pages/workspace/companyCards/WorkspaceCompanyCardDetailsPage.tsx +++ b/src/pages/workspace/companyCards/WorkspaceCompanyCardDetailsPage.tsx @@ -60,6 +60,203 @@ function WorkspaceCompanyCardDetailsPage({route}: WorkspaceCompanyCardDetailsPag const displayName = PersonalDetailsUtils.getDisplayNameOrDefault(cardholder); const exportMenuItem = getExportMenuItem(connectedIntegration, policyID, translate, policy, card); + // useEffect(() => { + // Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, { + // connections: { + // quickbooksOnline: { + // config: { + // companyName: 'test', + // credentials: { + // access_token: + // '2LHOKnH9waofJaMRyrVBUP+4qJsh4u+6E3Ffu73YJFJ6FnzAfsydZVkVFwjQmyxknEXCOYNeqoRljafcUk2sgzeq6002fXY55AEKF36UjaQQskfo4wR192K0v/68BUEzCpghfahoRmupoNq0u1JM8h/NDNIcLEi9ZDBno+7a22wi2jshJtcGL/wGBMUalWFupOmkiJbLPFen+mHFqLI8kF4TydI2a7SC4M4BAkZ2N7cFvp9LC39cLvrL7pZ/0wdIe8d4AMrKdR8M8V+KD8r2X4zXoQhKxSPA+2wRFiXIwOKB2iZqgI19dQHD0QqwbW6a512nOb7Q1Y0/SrF6NtVAaBXwhF2o3VULwFH3cy4QTYxB25wXCU76bhYsvUaQ/xWUVjY2TEi3GXkdTrNN8Ys8MXH3A9kVX7I32whBMfygcjYLtxc4/aVr8gYg8w5XPRRJ5Q/OGy68mX1JlCyWi+1NNAUJVkeRXuOsnivYvvaRisCJ4bng4ZiK9hnSWJ6qyKMWnb/nPpjZfZe25nbXfEG/e3CgwJ3KU4RlWZM+ECSWGcM/KyAGfErbcDBXXQk/6BnMjTqQkP5HotH8BHsUzYsw8D1A8i3gpgU/CStK8b+2PFcoqgTxWmsPgL7O32AFNR6z1yd1Zsrk5cDVHDlTddw1ePxrvfJRuT7gNKlut9oIAjgyR5iagxk/By2AGp0o2S53becAoPRGtuYYxk5WmpfB2q0N0QHI9VtRDJ5p1wn4KPO4twnnkU5YyD/u2UuBCWw9UB1rDWZVpGRUilyF2/0vy7PJHoUCXodz0DIulT+cDSHqf9hmc1pm7LI3Qt17X4uO1YCIQA7qQk1G5aY32HwNVq2VnyZJT64nEJ3JMydI4k74jrGy9Zp+52lAF39AenCaNjbVJg5svd0KEeOdwqr1j9SNkrHZkMmhuAUSI/WfyAhrtmjmRVGBTJ6b9l8fjdzwLwubXdFInG8M7h8Pc0Db7VTvd8Qv8MFRjhomzHbTkVMApKr1EH9WGzf932FlDse9HwKC4c6mA2Uj0BCaxsbnKnqd/I6Ug==;vJoXwrJgPzNOdv28yQHtPA==;eKPhE8t3aDV62W1np/MZoKIYA1bRawdFuttb5yxT44HQWjYgEc5x/Glx+Ye6YZP06Aj3N0A7eMw6rj98Kjpaow==', + // companyID: '934145206296', + // companyName: 'test', + // expires: 1730725016, + // realmId: '934145340296', + // refresh_token: + // 'KwizVqdImwI5kHeImQ2NrXO7rteCSzvtQakR3uhp7Y04X06z3F4Hvt42jw==;fK/XjysVFPC4lYgRXbzi/RpxI1z3aWWpaLSAnT5v1kRtg4ilXX9fjQvA6Wc3LhKqZXnADugm2DbveEmZWAItlg==', + // scope: 'Accounting', + // token_type: 'bearer', + // }, + // realmId: '9341453405206', + // autoSync: { + // enabled: true, + // jobID: '4604867689969023701', + // }, + // syncClasses: 'REPORT_FIELD', + // pendingFields: {}, + // errorFields: {}, + // syncLocations: 'NONE', + // autoCreateVendor: false, + // collectionAccountID: '29', + // enableNewCategories: true, + // export: { + // exporter: 'zhenja3033@gmail.com', + // }, + // exportDate: 'REPORT_EXPORTED', + // hasChosenAutoSyncOption: true, + // lastConfigurationTime: 1730721696740, + // markChecksToBePrinted: false, + // nonReimbursableBillDefaultVendor: 'NONE', + // nonReimbursableExpensesAccount: { + // currency: 'PLN', + // glCode: '', + // id: '29', + // name: 'Cash and cash equivalents', + // }, + // nonReimbursableExpensesExportDestination: 'debit_card', + // reimbursableExpensesAccount: { + // currency: 'PLN', + // glCode: '', + // id: '29', + // name: 'Cash and cash equivalents', + // }, + // reimbursableExpensesExportDestination: 'bill', + // reimbursementAccountID: '29', + // syncCustomers: 'TAG', + // syncItems: false, + // syncPeople: false, + // syncTax: false, + // }, + // data: { + // accountPayable: [], + // accountsReceivable: [], + // bankAccounts: [ + // { + // currency: 'PLN', + // glCode: '', + // id: '29', + // name: 'Cash and cash equivalents', + // }, + // { + // currency: 'PLN', + // glCode: '', + // id: '30', + // name: 'Test 1234', + // }, + // ], + // country: 'PL', + // creditCards: [], + // edition: 'QuickBooks Online Simple Start', + // employees: [], + // homeCurrency: 'PLN', + // isMultiCurrencyEnabled: false, + // journalEntryAccounts: [ + // { + // currency: 'PLN', + // glCode: '', + // id: '32', + // name: 'Accrued liabilities', + // }, + // { + // currency: 'PLN', + // glCode: '', + // id: '70', + // name: 'Allowance for bad debt', + // }, + // { + // currency: 'PLN', + // glCode: '', + // id: '13', + // name: 'Available for sale assets (short-term)', + // }, + // { + // currency: 'PLN', + // glCode: '', + // id: '38', + // name: 'Dividends payable', + // }, + // { + // currency: 'PLN', + // glCode: '', + // id: '26', + // name: 'Income tax payable', + // }, + // { + // currency: 'PLN', + // glCode: '', + // id: '65', + // name: 'Inventory', + // }, + // { + // currency: 'PLN', + // glCode: '', + // id: '74', + // name: 'Payroll Clearing', + // }, + // { + // currency: 'PLN', + // glCode: '', + // id: '73', + // name: 'Payroll liabilities', + // }, + // { + // currency: 'PLN', + // glCode: '', + // id: '47', + // name: 'Prepaid expenses', + // }, + // { + // currency: 'PLN', + // glCode: '', + // id: '71', + // name: 'Short-term debit', + // }, + // { + // currency: 'PLN', + // glCode: '', + // id: '1', + // name: 'Uncategorised Asset', + // }, + // ], + // otherCurrentAssetAccounts: [ + // { + // currency: 'PLN', + // glCode: '', + // id: '70', + // name: 'Allowance for bad debt', + // }, + // { + // currency: 'PLN', + // glCode: '', + // id: '13', + // name: 'Available for sale assets (short-term)', + // }, + // { + // currency: 'PLN', + // glCode: '', + // id: '65', + // name: 'Inventory', + // }, + // { + // currency: 'PLN', + // glCode: '', + // id: '47', + // name: 'Prepaid expenses', + // }, + // { + // currency: 'PLN', + // glCode: '', + // id: '1', + // name: 'Uncategorised Asset', + // }, + // ], + // vendors: [], + // }, + // lastSync: { + // errorDate: '', + // errorMessage: '', + // isAuthenticationError: false, + // isConnected: true, + // isSuccessful: true, + // source: 'NEWEXPENSIFY', + // successfulDate: '2024-11-04T12:01:36+0000', + // }, + // }, + // }, + // }); + // }, [policyID]); + const unassignCard = () => { setIsUnassignModalVisible(false); CompanyCards.unassignWorkspaceCompanyCard(workspaceAccountID, cardID, bank); @@ -128,7 +325,7 @@ function WorkspaceCompanyCardDetailsPage({route}: WorkspaceCompanyCardDetailsPag onPress={() => Navigation.navigate(ROUTES.WORKSPACE_COMPANY_CARD_NAME.getRoute(policyID, cardID, bank))} /> - {!!exportMenuItem && ( + {exportMenuItem?.shouldShowMenuItem ? ( Navigation.navigate(ROUTES.WORKSPACE_COMPANY_CARD_EXPORT.getRoute(policyID, cardID, bank))} /> - )} + ) : null} void; data: SelectorType[]; exportType?: string; + shouldShowMenuItem?: boolean; }; function getExportMenuItem( @@ -32,10 +33,11 @@ function getExportMenuItem( ): ExportIntegration | undefined { const currentConnectionName = PolicyUtils.getCurrentConnectionName(policy); - const {nonReimbursableExpensesExportDestination} = policy?.connections?.quickbooksOnline?.config ?? {}; + const {nonReimbursableExpensesExportDestination, nonReimbursableExpensesAccount} = policy?.connections?.quickbooksOnline?.config ?? {}; const {export: exportConfig} = policy?.connections?.intacct?.config ?? {}; const {export: exportConfiguration} = policy?.connections?.xero?.config ?? {}; const config = policy?.connections?.netsuite?.options.config; + const {bankAccounts} = policy?.connections?.xero?.data ?? {}; const {creditCards, bankAccounts: quickbooksOnlineBankAccounts} = policy?.connections?.quickbooksOnline?.data ?? {}; switch (connectionName) { @@ -43,20 +45,22 @@ function getExportMenuItem( const type = nonReimbursableExpensesExportDestination ? translate(`workspace.qbo.accounts.${nonReimbursableExpensesExportDestination}`) : undefined; const description = currentConnectionName && type ? translate('workspace.moreFeatures.companyCards.integrationExport', {integration: currentConnectionName, type}) : undefined; let data: Account[]; + let shouldShowMenuItem = true; let title: string | undefined = ''; let exportType: string | undefined = ''; switch (nonReimbursableExpensesExportDestination) { case CONST.QUICKBOOKS_NON_REIMBURSABLE_EXPORT_ACCOUNT_TYPE.CREDIT_CARD: data = creditCards ?? []; - title = companyCard?.nameValuePairs?.exportAccountDetails?.quickbooks_desktop_export_account_credit; + title = companyCard?.nameValuePairs?.exportAccountDetails?.quickbooks_desktop_export_account_credit ?? nonReimbursableExpensesAccount?.name; exportType = CONST.COMPANY_CARDS.EXPORT_CARD_TYPES.NVP_QUICKBOOKS_DESKTOP_EXPORT_ACCOUNT_CREDIT; break; case CONST.QUICKBOOKS_NON_REIMBURSABLE_EXPORT_ACCOUNT_TYPE.DEBIT_CARD: data = quickbooksOnlineBankAccounts ?? []; - title = companyCard?.nameValuePairs?.exportAccountDetails?.quickbooks_online_export_account_debit; + title = companyCard?.nameValuePairs?.exportAccountDetails?.quickbooks_online_export_account_debit ?? nonReimbursableExpensesAccount?.name; exportType = CONST.COMPANY_CARDS.EXPORT_CARD_TYPES.NVP_QUICKBOOKS_ONLINE_EXPORT_ACCOUNT_DEBIT; break; default: + shouldShowMenuItem = false; data = []; } @@ -64,6 +68,7 @@ function getExportMenuItem( description, title, exportType, + shouldShowMenuItem, onExportPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_EXPORT.getRoute(policyID)), data: data.map((card) => ({ value: card.name, @@ -77,10 +82,12 @@ function getExportMenuItem( const type = translate('workspace.xero.xeroBankAccount'); const description = currentConnectionName && type ? translate('workspace.moreFeatures.companyCards.integrationExport', {integration: currentConnectionName, type}) : undefined; const exportType = CONST.COMPANY_CARDS.EXPORT_CARD_TYPES.NVP_XERO_EXPORT_BANK_ACCOUNT; + const selectedAccount = (bankAccounts ?? []).find((bank) => bank.id === exportConfiguration?.nonReimbursableAccount); return { description, exportType, - title: companyCard?.nameValuePairs?.exportAccountDetails?.xero_export_bank_account, + shouldShowMenuItem: true, + title: companyCard?.nameValuePairs?.exportAccountDetails?.xero_export_bank_account ?? selectedAccount?.name ?? bankAccounts?.[0]?.name ?? '', onExportPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_XERO_EXPORT.getRoute(policyID)), data: getXeroBankAccounts(policy ?? undefined, exportConfiguration?.nonReimbursableAccount), }; @@ -91,26 +98,28 @@ function getExportMenuItem( : undefined; let title: string | undefined = ''; let exportType: string | undefined = ''; + let shouldShowMenuItem = true; const description = currentConnectionName && type ? translate('workspace.moreFeatures.companyCards.integrationExport', {integration: currentConnectionName, type}) : undefined; let data: SelectorType[]; switch (config?.nonreimbursableExpensesExportDestination) { case CONST.NETSUITE_EXPORT_DESTINATION.VENDOR_BILL: - title = companyCard?.nameValuePairs?.exportAccountDetails?.netsuite_export_vendor; data = getNetSuiteVendorOptions(policy ?? undefined, config?.defaultVendor); + title = companyCard?.nameValuePairs?.exportAccountDetails?.netsuite_export_vendor ?? data.find((exportVendor) => exportVendor.isSelected)?.text; exportType = CONST.COMPANY_CARDS.EXPORT_CARD_TYPES.NVP_NETSUITE_EXPORT_VENDOR; break; case CONST.NETSUITE_EXPORT_DESTINATION.JOURNAL_ENTRY: - title = companyCard?.nameValuePairs?.exportAccountDetails?.netsuite_export_payable_account; data = getNetSuitePayableAccountOptions(policy ?? undefined, config?.payableAcct); + title = companyCard?.nameValuePairs?.exportAccountDetails?.netsuite_export_payable_account ?? data.find((exportPayable) => exportPayable.isSelected)?.text; exportType = CONST.COMPANY_CARDS.EXPORT_CARD_TYPES.NVP_NETSUITE_EXPORT_ACCOUNT; - break; default: + shouldShowMenuItem = false; data = []; } return { description, title, + shouldShowMenuItem, exportType, data, onExportPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_NETSUITE_EXPORT.getRoute(policyID)), @@ -121,13 +130,18 @@ function getExportMenuItem( const type = exportConfig?.nonReimbursable ? translate(`workspace.sageIntacct.nonReimbursableExpenses.values.${exportConfig.nonReimbursable}`) : undefined; const description = currentConnectionName && type ? translate('workspace.moreFeatures.companyCards.integrationExport', {integration: currentConnectionName, type}) : undefined; const activeDefaultVendor = getSageIntacctNonReimbursableActiveDefaultVendor(policy); + const data = isVendor ? getSageIntacctVendors(policy, activeDefaultVendor) : getSageIntacctCreditCards(policy, exportConfig?.nonReimbursableAccount); + const selectedAccount = data.find((account) => account.isSelected)?.text; return { description, + shouldShowMenuItem: true, exportType: isVendor ? CONST.COMPANY_CARDS.EXPORT_CARD_TYPES.NVP_INTACCT_EXPORT_VENDOR : CONST.COMPANY_CARDS.EXPORT_CARD_TYPES.NVP_INTACCT_EXPORT_CHARGE_CARD, - title: isVendor ? companyCard?.nameValuePairs?.exportAccountDetails?.intacct_export_vendor : companyCard?.nameValuePairs?.exportAccountDetails?.intacct_export_charge_card, + title: isVendor + ? companyCard?.nameValuePairs?.exportAccountDetails?.intacct_export_vendor ?? selectedAccount + : companyCard?.nameValuePairs?.exportAccountDetails?.intacct_export_charge_card ?? selectedAccount, onExportPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_EXPORT.getRoute(policyID)), - data: isVendor ? getSageIntacctVendors(policy, activeDefaultVendor) : getSageIntacctCreditCards(policy, exportConfig?.nonReimbursableAccount), + data, }; } default: diff --git a/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsApproverPage.tsx b/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsApproverPage.tsx index 1c952617dab5..2d47ef700e08 100644 --- a/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsApproverPage.tsx +++ b/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsApproverPage.tsx @@ -55,7 +55,7 @@ function WorkspaceWorkflowsApprovalsApproverPage({policy, personalDetails, isLoa const [approvalWorkflow] = useOnyx(ONYXKEYS.APPROVAL_WORKFLOW); const [selectedApproverEmail, setSelectedApproverEmail] = useState(undefined); const [allApprovers, setAllApprovers] = useState([]); - const shouldShowTextInput = allApprovers?.length >= 8; + const shouldShowTextInput = allApprovers?.length >= CONST.STANDARD_LIST_ITEM_LIMIT; // eslint-disable-next-line rulesdir/no-negated-variables const shouldShowNotFoundView = (isEmptyObject(policy) && !isLoadingReportData) || !PolicyUtils.isPolicyAdmin(policy) || PolicyUtils.isPendingDeletePolicy(policy); From 461fddb7011792509061b855898752f055a1df58 Mon Sep 17 00:00:00 2001 From: Nicolay Arefyeu Date: Thu, 7 Nov 2024 15:07:23 +0200 Subject: [PATCH 2/4] remove mock data --- .../WorkspaceCompanyCardDetailsPage.tsx | 197 ------------------ 1 file changed, 197 deletions(-) diff --git a/src/pages/workspace/companyCards/WorkspaceCompanyCardDetailsPage.tsx b/src/pages/workspace/companyCards/WorkspaceCompanyCardDetailsPage.tsx index f6c29beaa0b6..618962c89aca 100644 --- a/src/pages/workspace/companyCards/WorkspaceCompanyCardDetailsPage.tsx +++ b/src/pages/workspace/companyCards/WorkspaceCompanyCardDetailsPage.tsx @@ -60,203 +60,6 @@ function WorkspaceCompanyCardDetailsPage({route}: WorkspaceCompanyCardDetailsPag const displayName = PersonalDetailsUtils.getDisplayNameOrDefault(cardholder); const exportMenuItem = getExportMenuItem(connectedIntegration, policyID, translate, policy, card); - // useEffect(() => { - // Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, { - // connections: { - // quickbooksOnline: { - // config: { - // companyName: 'test', - // credentials: { - // access_token: - // '2LHOKnH9waofJaMRyrVBUP+4qJsh4u+6E3Ffu73YJFJ6FnzAfsydZVkVFwjQmyxknEXCOYNeqoRljafcUk2sgzeq6002fXY55AEKF36UjaQQskfo4wR192K0v/68BUEzCpghfahoRmupoNq0u1JM8h/NDNIcLEi9ZDBno+7a22wi2jshJtcGL/wGBMUalWFupOmkiJbLPFen+mHFqLI8kF4TydI2a7SC4M4BAkZ2N7cFvp9LC39cLvrL7pZ/0wdIe8d4AMrKdR8M8V+KD8r2X4zXoQhKxSPA+2wRFiXIwOKB2iZqgI19dQHD0QqwbW6a512nOb7Q1Y0/SrF6NtVAaBXwhF2o3VULwFH3cy4QTYxB25wXCU76bhYsvUaQ/xWUVjY2TEi3GXkdTrNN8Ys8MXH3A9kVX7I32whBMfygcjYLtxc4/aVr8gYg8w5XPRRJ5Q/OGy68mX1JlCyWi+1NNAUJVkeRXuOsnivYvvaRisCJ4bng4ZiK9hnSWJ6qyKMWnb/nPpjZfZe25nbXfEG/e3CgwJ3KU4RlWZM+ECSWGcM/KyAGfErbcDBXXQk/6BnMjTqQkP5HotH8BHsUzYsw8D1A8i3gpgU/CStK8b+2PFcoqgTxWmsPgL7O32AFNR6z1yd1Zsrk5cDVHDlTddw1ePxrvfJRuT7gNKlut9oIAjgyR5iagxk/By2AGp0o2S53becAoPRGtuYYxk5WmpfB2q0N0QHI9VtRDJ5p1wn4KPO4twnnkU5YyD/u2UuBCWw9UB1rDWZVpGRUilyF2/0vy7PJHoUCXodz0DIulT+cDSHqf9hmc1pm7LI3Qt17X4uO1YCIQA7qQk1G5aY32HwNVq2VnyZJT64nEJ3JMydI4k74jrGy9Zp+52lAF39AenCaNjbVJg5svd0KEeOdwqr1j9SNkrHZkMmhuAUSI/WfyAhrtmjmRVGBTJ6b9l8fjdzwLwubXdFInG8M7h8Pc0Db7VTvd8Qv8MFRjhomzHbTkVMApKr1EH9WGzf932FlDse9HwKC4c6mA2Uj0BCaxsbnKnqd/I6Ug==;vJoXwrJgPzNOdv28yQHtPA==;eKPhE8t3aDV62W1np/MZoKIYA1bRawdFuttb5yxT44HQWjYgEc5x/Glx+Ye6YZP06Aj3N0A7eMw6rj98Kjpaow==', - // companyID: '934145206296', - // companyName: 'test', - // expires: 1730725016, - // realmId: '934145340296', - // refresh_token: - // 'KwizVqdImwI5kHeImQ2NrXO7rteCSzvtQakR3uhp7Y04X06z3F4Hvt42jw==;fK/XjysVFPC4lYgRXbzi/RpxI1z3aWWpaLSAnT5v1kRtg4ilXX9fjQvA6Wc3LhKqZXnADugm2DbveEmZWAItlg==', - // scope: 'Accounting', - // token_type: 'bearer', - // }, - // realmId: '9341453405206', - // autoSync: { - // enabled: true, - // jobID: '4604867689969023701', - // }, - // syncClasses: 'REPORT_FIELD', - // pendingFields: {}, - // errorFields: {}, - // syncLocations: 'NONE', - // autoCreateVendor: false, - // collectionAccountID: '29', - // enableNewCategories: true, - // export: { - // exporter: 'zhenja3033@gmail.com', - // }, - // exportDate: 'REPORT_EXPORTED', - // hasChosenAutoSyncOption: true, - // lastConfigurationTime: 1730721696740, - // markChecksToBePrinted: false, - // nonReimbursableBillDefaultVendor: 'NONE', - // nonReimbursableExpensesAccount: { - // currency: 'PLN', - // glCode: '', - // id: '29', - // name: 'Cash and cash equivalents', - // }, - // nonReimbursableExpensesExportDestination: 'debit_card', - // reimbursableExpensesAccount: { - // currency: 'PLN', - // glCode: '', - // id: '29', - // name: 'Cash and cash equivalents', - // }, - // reimbursableExpensesExportDestination: 'bill', - // reimbursementAccountID: '29', - // syncCustomers: 'TAG', - // syncItems: false, - // syncPeople: false, - // syncTax: false, - // }, - // data: { - // accountPayable: [], - // accountsReceivable: [], - // bankAccounts: [ - // { - // currency: 'PLN', - // glCode: '', - // id: '29', - // name: 'Cash and cash equivalents', - // }, - // { - // currency: 'PLN', - // glCode: '', - // id: '30', - // name: 'Test 1234', - // }, - // ], - // country: 'PL', - // creditCards: [], - // edition: 'QuickBooks Online Simple Start', - // employees: [], - // homeCurrency: 'PLN', - // isMultiCurrencyEnabled: false, - // journalEntryAccounts: [ - // { - // currency: 'PLN', - // glCode: '', - // id: '32', - // name: 'Accrued liabilities', - // }, - // { - // currency: 'PLN', - // glCode: '', - // id: '70', - // name: 'Allowance for bad debt', - // }, - // { - // currency: 'PLN', - // glCode: '', - // id: '13', - // name: 'Available for sale assets (short-term)', - // }, - // { - // currency: 'PLN', - // glCode: '', - // id: '38', - // name: 'Dividends payable', - // }, - // { - // currency: 'PLN', - // glCode: '', - // id: '26', - // name: 'Income tax payable', - // }, - // { - // currency: 'PLN', - // glCode: '', - // id: '65', - // name: 'Inventory', - // }, - // { - // currency: 'PLN', - // glCode: '', - // id: '74', - // name: 'Payroll Clearing', - // }, - // { - // currency: 'PLN', - // glCode: '', - // id: '73', - // name: 'Payroll liabilities', - // }, - // { - // currency: 'PLN', - // glCode: '', - // id: '47', - // name: 'Prepaid expenses', - // }, - // { - // currency: 'PLN', - // glCode: '', - // id: '71', - // name: 'Short-term debit', - // }, - // { - // currency: 'PLN', - // glCode: '', - // id: '1', - // name: 'Uncategorised Asset', - // }, - // ], - // otherCurrentAssetAccounts: [ - // { - // currency: 'PLN', - // glCode: '', - // id: '70', - // name: 'Allowance for bad debt', - // }, - // { - // currency: 'PLN', - // glCode: '', - // id: '13', - // name: 'Available for sale assets (short-term)', - // }, - // { - // currency: 'PLN', - // glCode: '', - // id: '65', - // name: 'Inventory', - // }, - // { - // currency: 'PLN', - // glCode: '', - // id: '47', - // name: 'Prepaid expenses', - // }, - // { - // currency: 'PLN', - // glCode: '', - // id: '1', - // name: 'Uncategorised Asset', - // }, - // ], - // vendors: [], - // }, - // lastSync: { - // errorDate: '', - // errorMessage: '', - // isAuthenticationError: false, - // isConnected: true, - // isSuccessful: true, - // source: 'NEWEXPENSIFY', - // successfulDate: '2024-11-04T12:01:36+0000', - // }, - // }, - // }, - // }); - // }, [policyID]); - const unassignCard = () => { setIsUnassignModalVisible(false); CompanyCards.unassignWorkspaceCompanyCard(workspaceAccountID, cardID, bank); From fabbbd366b3a4807d187b670ab3e400c0d873ed4 Mon Sep 17 00:00:00 2001 From: Nicolay Arefyeu Date: Fri, 8 Nov 2024 15:37:06 +0200 Subject: [PATCH 3/4] fixes after review --- src/components/TaxPicker.tsx | 43 +++++-------------- src/libs/actions/CompanyCards.ts | 23 ++++++---- .../WorkspaceCompanyCardDetailsPage.tsx | 11 +++-- src/pages/workspace/companyCards/utils.tsx | 21 +++++---- src/types/onyx/Card.ts | 13 +++--- 5 files changed, 49 insertions(+), 62 deletions(-) diff --git a/src/components/TaxPicker.tsx b/src/components/TaxPicker.tsx index bc765a7c63ff..a91965811d81 100644 --- a/src/components/TaxPicker.tsx +++ b/src/components/TaxPicker.tsx @@ -1,33 +1,21 @@ import React, {useCallback, useMemo, useState} from 'react'; -import {withOnyx} from 'react-native-onyx'; -import type {OnyxEntry} from 'react-native-onyx'; +import {useOnyx} from 'react-native-onyx'; import type {EdgeInsets} from 'react-native-safe-area-context'; import type {ValueOf} from 'type-fest'; import useLocalize from '@hooks/useLocalize'; import useStyleUtils from '@hooks/useStyleUtils'; import * as IOUUtils from '@libs/IOUUtils'; import * as OptionsListUtils from '@libs/OptionsListUtils'; +import * as PolicyUtils from '@libs/PolicyUtils'; import * as TransactionUtils from '@libs/TransactionUtils'; import CONST from '@src/CONST'; import type {IOUAction} from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {Policy, Transaction} from '@src/types/onyx'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import SelectionList from './SelectionList'; import RadioListItem from './SelectionList/RadioListItem'; -type TaxPickerOnyxProps = { - /** The policy which the user has access to and which the report is tied to */ - policy: OnyxEntry; - - /** All the data for the transaction */ - transaction: OnyxEntry; - - /** The draft transaction that holds data to be persisted on the current split transaction */ - splitDraftTransaction: OnyxEntry; -}; - -type TaxPickerProps = TaxPickerOnyxProps & { +type TaxPickerProps = { /** The selected tax rate of an expense */ selectedTaxRate?: string; @@ -58,10 +46,16 @@ type TaxPickerProps = TaxPickerOnyxProps & { onDismiss: () => void; }; -function TaxPicker({selectedTaxRate = '', policy, transaction, insets, onSubmit, action, splitDraftTransaction, iouType, onDismiss}: TaxPickerProps) { +function TaxPicker({selectedTaxRate = '', policyID, transactionID, insets, onSubmit, action, iouType, onDismiss}: TaxPickerProps) { const StyleUtils = useStyleUtils(); const {translate} = useLocalize(); const [searchValue, setSearchValue] = useState(''); + const policy = PolicyUtils.getPolicy(policyID); + const [draftTransaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}` as `${typeof ONYXKEYS.COLLECTION.TRANSACTION}${string}`); + const [defaultTransaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`); + const [splitDraftTransaction] = useOnyx(`${ONYXKEYS.COLLECTION.SPLIT_TRANSACTION_DRAFT}${transactionID}`); + + const transaction = IOUUtils.shouldUseTransactionDraft(action) ? draftTransaction : defaultTransaction; const isEditing = action === CONST.IOU.ACTION.EDIT; const isEditingSplitBill = isEditing && iouType === CONST.IOU.TYPE.SPLIT; @@ -125,19 +119,4 @@ function TaxPicker({selectedTaxRate = '', policy, transaction, insets, onSubmit, TaxPicker.displayName = 'TaxPicker'; -export default withOnyx({ - policy: { - key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, - }, - transaction: { - key: ({transactionID, action}) => { - if (IOUUtils.shouldUseTransactionDraft(action)) { - return `${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}` as `${typeof ONYXKEYS.COLLECTION.TRANSACTION}${string}`; - } - return `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`; - }, - }, - splitDraftTransaction: { - key: ({transactionID}) => `${ONYXKEYS.COLLECTION.SPLIT_TRANSACTION_DRAFT}${transactionID}`, - }, -})(TaxPicker); +export default TaxPicker; diff --git a/src/libs/actions/CompanyCards.ts b/src/libs/actions/CompanyCards.ts index b0758e221257..9679f050d842 100644 --- a/src/libs/actions/CompanyCards.ts +++ b/src/libs/actions/CompanyCards.ts @@ -472,14 +472,12 @@ function setCompanyCardExportAccount(policyID: string, workspaceAccountID: numbe [cardID]: { nameValuePairs: { pendingFields: { - exportAccountDetails: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, + [accountKey]: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, }, errorFields: { - exportAccountDetails: null, - }, - exportAccountDetails: { - [accountKey]: newAccount, + [accountKey]: null, }, + [accountKey]: newAccount, }, }, }, @@ -494,7 +492,7 @@ function setCompanyCardExportAccount(policyID: string, workspaceAccountID: numbe [cardID]: { nameValuePairs: { pendingFields: { - exportAccountDetails: null, + [accountKey]: null, }, }, }, @@ -509,10 +507,10 @@ function setCompanyCardExportAccount(policyID: string, workspaceAccountID: numbe [cardID]: { nameValuePairs: { pendingFields: { - exportAccountDetails: null, + [accountKey]: newAccount, }, errorFields: { - exportAccountDetails: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'), + [accountKey]: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'), }, }, }, @@ -545,6 +543,15 @@ function clearCompanyCardErrorField(workspaceAccountID: number, cardID: string, }, }, }); + Onyx.merge(ONYXKEYS.CARD_LIST, { + [cardID]: { + nameValuePairs: { + errorFields: { + [fieldName]: null, + }, + }, + }, + }); } function openPolicyCompanyCardsPage(policyID: string, workspaceAccountID: number) { diff --git a/src/pages/workspace/companyCards/WorkspaceCompanyCardDetailsPage.tsx b/src/pages/workspace/companyCards/WorkspaceCompanyCardDetailsPage.tsx index 618962c89aca..4b458ecc503d 100644 --- a/src/pages/workspace/companyCards/WorkspaceCompanyCardDetailsPage.tsx +++ b/src/pages/workspace/companyCards/WorkspaceCompanyCardDetailsPage.tsx @@ -130,10 +130,15 @@ function WorkspaceCompanyCardDetailsPage({route}: WorkspaceCompanyCardDetailsPag {exportMenuItem?.shouldShowMenuItem ? ( CompanyCards.clearCompanyCardErrorField(workspaceAccountID, cardID, bank, 'exportAccountDetails')} + errors={exportMenuItem.exportType ? ErrorUtils.getLatestErrorField(card?.nameValuePairs ?? {}, exportMenuItem.exportType) : undefined} + onClose={() => { + if (!exportMenuItem.exportType) { + return; + } + CompanyCards.clearCompanyCardErrorField(workspaceAccountID, cardID, bank, exportMenuItem.exportType); + }} > void; data: SelectorType[]; - exportType?: string; + exportType?: ValueOf; shouldShowMenuItem?: boolean; }; @@ -47,16 +48,16 @@ function getExportMenuItem( let data: Account[]; let shouldShowMenuItem = true; let title: string | undefined = ''; - let exportType: string | undefined = ''; + let exportType: ValueOf | undefined; switch (nonReimbursableExpensesExportDestination) { case CONST.QUICKBOOKS_NON_REIMBURSABLE_EXPORT_ACCOUNT_TYPE.CREDIT_CARD: data = creditCards ?? []; - title = companyCard?.nameValuePairs?.exportAccountDetails?.quickbooks_desktop_export_account_credit ?? nonReimbursableExpensesAccount?.name; + title = companyCard?.nameValuePairs?.quickbooks_desktop_export_account_credit ?? nonReimbursableExpensesAccount?.name; exportType = CONST.COMPANY_CARDS.EXPORT_CARD_TYPES.NVP_QUICKBOOKS_DESKTOP_EXPORT_ACCOUNT_CREDIT; break; case CONST.QUICKBOOKS_NON_REIMBURSABLE_EXPORT_ACCOUNT_TYPE.DEBIT_CARD: data = quickbooksOnlineBankAccounts ?? []; - title = companyCard?.nameValuePairs?.exportAccountDetails?.quickbooks_online_export_account_debit ?? nonReimbursableExpensesAccount?.name; + title = companyCard?.nameValuePairs?.quickbooks_online_export_account_debit ?? nonReimbursableExpensesAccount?.name; exportType = CONST.COMPANY_CARDS.EXPORT_CARD_TYPES.NVP_QUICKBOOKS_ONLINE_EXPORT_ACCOUNT_DEBIT; break; default: @@ -87,7 +88,7 @@ function getExportMenuItem( description, exportType, shouldShowMenuItem: true, - title: companyCard?.nameValuePairs?.exportAccountDetails?.xero_export_bank_account ?? selectedAccount?.name ?? bankAccounts?.[0]?.name ?? '', + title: companyCard?.nameValuePairs?.xero_export_bank_account ?? selectedAccount?.name ?? bankAccounts?.[0]?.name ?? '', onExportPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_XERO_EXPORT.getRoute(policyID)), data: getXeroBankAccounts(policy ?? undefined, exportConfiguration?.nonReimbursableAccount), }; @@ -97,19 +98,19 @@ function getExportMenuItem( ? translate(`workspace.netsuite.exportDestination.values.${config.nonreimbursableExpensesExportDestination}.label`) : undefined; let title: string | undefined = ''; - let exportType: string | undefined = ''; + let exportType: ValueOf | undefined; let shouldShowMenuItem = true; const description = currentConnectionName && type ? translate('workspace.moreFeatures.companyCards.integrationExport', {integration: currentConnectionName, type}) : undefined; let data: SelectorType[]; switch (config?.nonreimbursableExpensesExportDestination) { case CONST.NETSUITE_EXPORT_DESTINATION.VENDOR_BILL: data = getNetSuiteVendorOptions(policy ?? undefined, config?.defaultVendor); - title = companyCard?.nameValuePairs?.exportAccountDetails?.netsuite_export_vendor ?? data.find((exportVendor) => exportVendor.isSelected)?.text; + title = companyCard?.nameValuePairs?.netsuite_export_vendor ?? data.find((exportVendor) => exportVendor.isSelected)?.text; exportType = CONST.COMPANY_CARDS.EXPORT_CARD_TYPES.NVP_NETSUITE_EXPORT_VENDOR; break; case CONST.NETSUITE_EXPORT_DESTINATION.JOURNAL_ENTRY: data = getNetSuitePayableAccountOptions(policy ?? undefined, config?.payableAcct); - title = companyCard?.nameValuePairs?.exportAccountDetails?.netsuite_export_payable_account ?? data.find((exportPayable) => exportPayable.isSelected)?.text; + title = companyCard?.nameValuePairs?.netsuite_export_payable_account ?? data.find((exportPayable) => exportPayable.isSelected)?.text; exportType = CONST.COMPANY_CARDS.EXPORT_CARD_TYPES.NVP_NETSUITE_EXPORT_ACCOUNT; break; default: @@ -137,9 +138,7 @@ function getExportMenuItem( description, shouldShowMenuItem: true, exportType: isVendor ? CONST.COMPANY_CARDS.EXPORT_CARD_TYPES.NVP_INTACCT_EXPORT_VENDOR : CONST.COMPANY_CARDS.EXPORT_CARD_TYPES.NVP_INTACCT_EXPORT_CHARGE_CARD, - title: isVendor - ? companyCard?.nameValuePairs?.exportAccountDetails?.intacct_export_vendor ?? selectedAccount - : companyCard?.nameValuePairs?.exportAccountDetails?.intacct_export_charge_card ?? selectedAccount, + title: isVendor ? companyCard?.nameValuePairs?.intacct_export_vendor ?? selectedAccount : companyCard?.nameValuePairs?.intacct_export_charge_card ?? selectedAccount, onExportPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_EXPORT.getRoute(policyID)), data, }; diff --git a/src/types/onyx/Card.ts b/src/types/onyx/Card.ts index c1d0e09d9312..8894db2723d1 100644 --- a/src/types/onyx/Card.ts +++ b/src/types/onyx/Card.ts @@ -2,10 +2,6 @@ import type {ValueOf} from 'type-fest'; import type CONST from '@src/CONST'; import type * as OnyxCommon from './OnyxCommon'; -/** Type of export card */ -type ExportCompanyCard = { - [key in ValueOf | ValueOf]: string; -}; /** Model of Expensify card */ type Card = OnyxCommon.OnyxValueWithOfflineFeedback<{ /** Card ID number */ @@ -76,9 +72,6 @@ type Card = OnyxCommon.OnyxValueWithOfflineFeedback<{ /** Type of card spending limits */ limitType?: ValueOf; - /** Type of export card */ - exportAccountDetails?: ExportCompanyCard; - /** User-defined nickname for the card */ cardTitle?: string; @@ -114,7 +107,11 @@ type Card = OnyxCommon.OnyxValueWithOfflineFeedback<{ /** Collection of form field errors */ errorFields?: OnyxCommon.ErrorFields; - }>; + }> & + OnyxCommon.OnyxValueWithOfflineFeedback<{ + /** Type of export card */ + [key in ValueOf | ValueOf]: string; + }>; }>; /** Model of Expensify card details */ From 6e115b20a768d6eb8608d83c14fbc18920dd32bc Mon Sep 17 00:00:00 2001 From: Nicolay Arefyeu Date: Tue, 12 Nov 2024 10:25:04 +0200 Subject: [PATCH 4/4] use correct onyx key to get data from --- src/libs/actions/CompanyCards.ts | 8 ++++---- .../WorkspaceCompanyCardAccountSelectCardPage.tsx | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libs/actions/CompanyCards.ts b/src/libs/actions/CompanyCards.ts index 5810d5dfae30..7ec337610f06 100644 --- a/src/libs/actions/CompanyCards.ts +++ b/src/libs/actions/CompanyCards.ts @@ -493,13 +493,13 @@ function updateCompanyCardName(workspaceAccountID: number, cardID: string, newCa API.write(WRITE_COMMANDS.UPDATE_COMPANY_CARD_NAME, parameters, {optimisticData, finallyData, failureData}); } -function setCompanyCardExportAccount(policyID: string, workspaceAccountID: number, cardID: string, accountKey: string, newAccount: string) { +function setCompanyCardExportAccount(policyID: string, workspaceAccountID: number, cardID: string, accountKey: string, newAccount: string, bank: string) { const authToken = NetworkStore.getAuthToken(); const optimisticData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.CARD_LIST, + key: `${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${bank}`, value: { [cardID]: { nameValuePairs: { @@ -519,7 +519,7 @@ function setCompanyCardExportAccount(policyID: string, workspaceAccountID: numbe const finallyData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.CARD_LIST, + key: `${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${bank}`, value: { [cardID]: { nameValuePairs: { @@ -534,7 +534,7 @@ function setCompanyCardExportAccount(policyID: string, workspaceAccountID: numbe const failureData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.CARD_LIST, + key: `${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${bank}`, value: { [cardID]: { nameValuePairs: { diff --git a/src/pages/workspace/companyCards/WorkspaceCompanyCardAccountSelectCardPage.tsx b/src/pages/workspace/companyCards/WorkspaceCompanyCardAccountSelectCardPage.tsx index 670f1d90f5be..a39a4401cb6e 100644 --- a/src/pages/workspace/companyCards/WorkspaceCompanyCardAccountSelectCardPage.tsx +++ b/src/pages/workspace/companyCards/WorkspaceCompanyCardAccountSelectCardPage.tsx @@ -33,7 +33,7 @@ function WorkspaceCompanyCardAccountSelectCardPage({route}: WorkspaceCompanyCard const workspaceAccountID = PolicyUtils.getWorkspaceAccountID(policyID); const [searchText, setSearchText] = useState(''); - const [allBankCards] = useOnyx(`${ONYXKEYS.CARD_LIST}`); + const [allBankCards] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${bank}`); const card = allBankCards?.[cardID]; const connectedIntegration = PolicyUtils.getConnectedIntegration(policy) ?? CONST.POLICY.CONNECTIONS.NAME.QBO; const exportMenuItem = getExportMenuItem(connectedIntegration, policyID, translate, policy, card); @@ -63,7 +63,7 @@ function WorkspaceCompanyCardAccountSelectCardPage({route}: WorkspaceCompanyCard if (!exportMenuItem?.exportType) { return; } - CompanyCards.setCompanyCardExportAccount(policyID, workspaceAccountID, cardID, exportMenuItem.exportType, value); + CompanyCards.setCompanyCardExportAccount(policyID, workspaceAccountID, cardID, exportMenuItem.exportType, value, bank); Navigation.goBack(ROUTES.WORKSPACE_COMPANY_CARD_DETAILS.getRoute(policyID, cardID, bank)); },