Repository navigation
[QBO Export] Manual exports #44170
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
Merged
arosiclair
merged 59 commits into
Expensify:main
from
software-mansion-labs:@kosmydel/qbo-export/manual-exports
Jul 16, 2024
Merged
[QBO Export] Manual exports #44170
Changes from all commits
Commits
Show all changes
59 commits
Select commit
Hold shift + click to select a range
f48cff1
feat: setup the ReportDetailsExportPage.tsx and navigation
kosmydel 6eb2f4d
feat: add Onyx actions
kosmydel 80389e9
feat: getConnectedIntegration
kosmydel bdb2917
feat: use SelectionScreen in ReportDetailsExportPage
kosmydel 87ea402
feat: add ConfirmModal
kosmydel 01b5268
feat: export in ReportPreview
kosmydel 100e1dc
Merge branch 'main' into @kosmydel/qbo-export/manual-exports
kosmydel e552a93
fix: exporting reports
kosmydel 062f557
cleanup
kosmydel 64620f6
Merge branch 'main' into @kosmydel/qbo-export/manual-exports
kosmydel d00f1f0
feat: spanish translations
kosmydel 095b0cc
feat: add manual button export to MoneyReportHeader
kosmydel 2ea4435
refactor: getConnectedIntegration
kosmydel b8fcea9
refactor: include dropdownOptions in ExportWithDropdownMenu
kosmydel 92949a7
feat: add not ready to export screen
kosmydel 82708fc
feat: add screen wrapper
kosmydel cc0b95a
Merge branch 'main' into @kosmydel/qbo-export/manual-exports
kosmydel cff5d28
feat: empty Export screen translation
kosmydel e8f6379
Merge branch 'main' into @kosmydel/qbo-export/manual-exports
kosmydel f13f1cd
fix: types
kosmydel 2c8ab95
feat: confirmation button in dropdown menu
kosmydel 163718d
feat: add correct illustration
kosmydel 40a1462
feat: dropdown menu clickable button
kosmydel 5e01f89
feat: persist last export method
kosmydel f10a469
Merge branch 'main' into @kosmydel/qbo-export/manual-exports
kosmydel 4c43898
fix displaying integration names
kosmydel 15a26aa
fix: lint & TS
kosmydel 5a35efd
Merge branch 'main' into @kosmydel/qbo-export/manual-exports
kosmydel e3d06bc
fix: buttons style
kosmydel cfddc13
cleanup: rename animation to illustration in ConfirmationPage
kosmydel a50a1f7
refactor: address review
kosmydel d29b2f2
address review
kosmydel 21575e5
fix lint
kosmydel 2ae3022
Merge branch 'main' into @kosmydel/qbo-export/manual-exports
kosmydel f478df7
fix: displaying icons on native
kosmydel 47cb0bf
cleanup: use WRITE_COMMANDS
kosmydel 0488216
Merge branch 'main' into @kosmydel/qbo-export/manual-exports
kosmydel c30c013
cleanup: SelectionScreen
kosmydel 6a1542d
feat: add correct translations
kosmydel 830b5b2
Merge branch 'main' into @kosmydel/qbo-export/manual-exports
kosmydel 5101b6e
Merge branch 'main' into @kosmydel/qbo-export/manual-exports
kosmydel a35f02f
fix: exporting from RHP
kosmydel b106387
fix: display friendly name
kosmydel d2129ed
fix type
kosmydel 1046f09
Merge branch 'main' into @kosmydel/qbo-export/manual-exports
kosmydel a556a02
lint
kosmydel b1b8291
fix: types
kosmydel deb556f
fix lint
kosmydel cfc7995
address review
kosmydel ad2c4cf
Merge branch 'main' into @kosmydel/qbo-export/manual-exports
kosmydel d75044e
fix modals
kosmydel 4a18a1a
Merge branch 'main' into @kosmydel/qbo-export/manual-exports
kosmydel 6863ba2
fix lint
kosmydel 572c763
Merge branch 'main' into @kosmydel/qbo-export/manual-exports
kosmydel c4fbe0a
remove TODO
kosmydel 32396e4
Merge branch 'main' into @kosmydel/qbo-export/manual-exports
kosmydel 4070375
feat: display export buttons when autoSync is enabled
kosmydel 7939596
address review
kosmydel ebb2c20
Merge branch 'main' into @kosmydel/qbo-export/manual-exports
kosmydel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
src/components/ReportActionItem/ExportWithDropdownMenu.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| import React, {useCallback, useMemo, useState} from 'react'; | ||
| import {useOnyx} from 'react-native-onyx'; | ||
| import type {OnyxEntry} from 'react-native-onyx'; | ||
| import ButtonWithDropdownMenu from '@components/ButtonWithDropdownMenu'; | ||
| import type {DropdownOption, ReportExportType} from '@components/ButtonWithDropdownMenu/types'; | ||
| import ConfirmModal from '@components/ConfirmModal'; | ||
| import useLocalize from '@hooks/useLocalize'; | ||
| import useResponsiveLayout from '@hooks/useResponsiveLayout'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import * as PolicyActions from '@libs/actions/Policy/Policy'; | ||
| import * as ReportActions from '@libs/actions/Report'; | ||
|
kosmydel marked this conversation as resolved.
Resolved
|
||
| import * as PolicyUtils from '@libs/PolicyUtils'; | ||
| import * as ReportUtils from '@libs/ReportUtils'; | ||
| import type {ExportType} from '@pages/home/report/ReportDetailsExportPage'; | ||
| import CONST from '@src/CONST'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import type {Policy, Report} from '@src/types/onyx'; | ||
| import type {ConnectionName} from '@src/types/onyx/Policy'; | ||
|
|
||
| type ExportWithDropdownMenuProps = { | ||
| policy: OnyxEntry<Policy>; | ||
|
|
||
| report: OnyxEntry<Report>; | ||
|
|
||
| connectionName: ConnectionName; | ||
| }; | ||
|
|
||
| function ExportWithDropdownMenu({policy, report, connectionName}: ExportWithDropdownMenuProps) { | ||
| const reportID = report?.reportID; | ||
| const styles = useThemeStyles(); | ||
| const {translate} = useLocalize(); | ||
| const {isSmallScreenWidth} = useResponsiveLayout(); | ||
| const [modalStatus, setModalStatus] = useState<ExportType | null>(null); | ||
| const [exportMethods] = useOnyx(ONYXKEYS.LAST_EXPORT_METHOD); | ||
| const [reportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`); | ||
|
|
||
| const iconToDisplay = ReportUtils.getIntegrationIcon(connectionName); | ||
| const canBeExported = ReportUtils.canBeExported(report); | ||
| const isExported = ReportUtils.isExported(reportActions); | ||
| const hasIntegrationAutoSync = PolicyUtils.hasIntegrationAutoSync(policy, connectionName); | ||
|
|
||
| const dropdownOptions: Array<DropdownOption<ReportExportType>> = useMemo(() => { | ||
| const optionTemplate = { | ||
| icon: iconToDisplay, | ||
| disabled: !canBeExported, | ||
| displayInDefaultIconColor: true, | ||
| }; | ||
| const options = [ | ||
| { | ||
| value: CONST.REPORT.EXPORT_OPTIONS.EXPORT_TO_INTEGRATION, | ||
| text: translate('workspace.common.exportIntegrationSelected', connectionName), | ||
| ...optionTemplate, | ||
| }, | ||
| { | ||
| value: CONST.REPORT.EXPORT_OPTIONS.MARK_AS_EXPORTED, | ||
| text: translate('workspace.common.markAsExported'), | ||
| ...optionTemplate, | ||
| }, | ||
| ]; | ||
| const exportMethod = exportMethods?.[report?.policyID ?? ''] ?? null; | ||
| if (exportMethod) { | ||
| options.sort((method) => (method.value === exportMethod ? -1 : 0)); | ||
| } | ||
| return options; | ||
| // We do not include exportMethods not to re-render the component when the preffered export method changes | ||
| // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps | ||
| }, [canBeExported, iconToDisplay, connectionName, report?.policyID, translate]); | ||
|
|
||
| const confirmExport = useCallback(() => { | ||
| setModalStatus(null); | ||
| if (!reportID) { | ||
| return; | ||
| } | ||
| if (modalStatus === CONST.REPORT.EXPORT_OPTIONS.EXPORT_TO_INTEGRATION) { | ||
| ReportActions.exportToIntegration(reportID, connectionName); | ||
| } else if (modalStatus === CONST.REPORT.EXPORT_OPTIONS.MARK_AS_EXPORTED) { | ||
| ReportActions.markAsManuallyExported(reportID); | ||
| } | ||
| }, [connectionName, modalStatus, reportID]); | ||
|
|
||
| const savePreferredExportMethod = (value: ReportExportType) => { | ||
| if (!report?.policyID) { | ||
| return; | ||
| } | ||
| PolicyActions.savePreferredExportMethod(report?.policyID, value); | ||
| }; | ||
|
|
||
| return ( | ||
| <> | ||
| <ButtonWithDropdownMenu<ReportExportType> | ||
| success={!hasIntegrationAutoSync} | ||
| pressOnEnter | ||
| shouldAlwaysShowDropdownMenu | ||
| anchorAlignment={{ | ||
| horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.RIGHT, | ||
| vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.TOP, | ||
| }} | ||
| onPress={(_, value) => { | ||
| if (isExported) { | ||
| setModalStatus(value); | ||
| return; | ||
| } | ||
| if (!reportID) { | ||
| return; | ||
| } | ||
| if (value === CONST.REPORT.EXPORT_OPTIONS.EXPORT_TO_INTEGRATION) { | ||
| ReportActions.exportToIntegration(reportID, connectionName); | ||
| } else if (value === CONST.REPORT.EXPORT_OPTIONS.MARK_AS_EXPORTED) { | ||
| ReportActions.markAsManuallyExported(reportID); | ||
| } | ||
| }} | ||
| onOptionSelected={({value}) => savePreferredExportMethod(value)} | ||
| options={dropdownOptions} | ||
| style={[isSmallScreenWidth && styles.flexGrow1]} | ||
| buttonSize={CONST.DROPDOWN_BUTTON_SIZE.MEDIUM} | ||
| /> | ||
| <ConfirmModal | ||
| title={translate('workspace.exportAgainModal.title')} | ||
| onConfirm={confirmExport} | ||
| onCancel={() => setModalStatus(null)} | ||
| prompt={translate('workspace.exportAgainModal.description', report?.reportName ?? '', connectionName)} | ||
| confirmText={translate('workspace.exportAgainModal.confirmText')} | ||
| cancelText={translate('workspace.exportAgainModal.cancelText')} | ||
| isVisible={!!modalStatus} | ||
| /> | ||
| </> | ||
| ); | ||
| } | ||
|
|
||
| export default ExportWithDropdownMenu; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using connectedIntegration as a condition caused #59813. If the integration connection is invalid, its an empty object rather than being
false.