-
Notifications
You must be signed in to change notification settings - Fork 4k
Implement confirmation modal when user tries to create multiple empty reports #71609
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
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
0b909c6
Implement confirmation modal when user tries to create multiple empty…
ShridharGoel 6457ce2
Update tests
ShridharGoel e2a419c
Lint and other fixes
ShridharGoel 108edd0
Fixes
ShridharGoel 16b50f8
Update based on comments
ShridharGoel f0ec673
Merge branch 'main' into confirmEmpty
ShridharGoel 6bceb39
Prettier updates
ShridharGoel 7da8e89
Update tests
ShridharGoel 032385a
Lint fixes
ShridharGoel 27d2b74
Add translations for other languages
ShridharGoel d03b744
Merge
ShridharGoel e056f50
Remove extra params from hasEmptyReportsForPolicy call in FloatingAct…
ShridharGoel 1d6f017
Prettier and typecheck fixes
ShridharGoel 3a25e52
Merge branch 'main' of https://github.com/Expensify/App into confirmE…
ShridharGoel ab5603c
Use selectors in Onyx
ShridharGoel 6965de3
Merge
ShridharGoel bb03828
Update the selector logic
ShridharGoel 99a2d95
Fixes
ShridharGoel 53ae0ba
Merge
ShridharGoel be4b008
Update to remove unnecessary changes
ShridharGoel 92f1cd5
Fix lint
ShridharGoel 2f5426e
Check for transactions instead of money
ShridharGoel 1ddc053
Merge
ShridharGoel 9b6cae0
Fixes
ShridharGoel 35908ab
Fix lint
ShridharGoel d099a8e
Fix lint
ShridharGoel 8ec4256
Lint fix
ShridharGoel 4eb17d9
Update inferred to defaultChatEnabled
ShridharGoel fa29236
Merge main
ShridharGoel 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
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,106 @@ | ||
| import React, {useCallback, useMemo, useState} from 'react'; | ||
| import type {ReactNode} from 'react'; | ||
| import ConfirmModal from '@components/ConfirmModal'; | ||
| import Text from '@components/Text'; | ||
| import TextLink from '@components/TextLink'; | ||
| import Navigation from '@libs/Navigation/Navigation'; | ||
| import {buildCannedSearchQuery} from '@libs/SearchQueryUtils'; | ||
| import CONST from '@src/CONST'; | ||
| import ROUTES from '@src/ROUTES'; | ||
| import useLocalize from './useLocalize'; | ||
|
|
||
| type UseCreateEmptyReportConfirmationParams = { | ||
| /** The policy ID for which the report is being created */ | ||
| policyID?: string; | ||
| /** The display name of the policy/workspace */ | ||
| policyName?: string; | ||
| /** Callback function to execute when user confirms report creation */ | ||
| onConfirm: () => void; | ||
| /** Optional callback function to execute when user cancels the confirmation */ | ||
| onCancel?: () => void; | ||
| }; | ||
|
|
||
| type UseCreateEmptyReportConfirmationResult = { | ||
| /** Function to open the confirmation modal */ | ||
| openCreateReportConfirmation: () => void; | ||
| /** The confirmation modal React component to render */ | ||
| CreateReportConfirmationModal: ReactNode; | ||
| }; | ||
|
|
||
| /** | ||
| * A React hook that provides a confirmation modal for creating empty reports. | ||
| * When a user attempts to create a new report in a workspace where they already have an empty report, | ||
| * this hook displays a confirmation modal to prevent accidental duplicate empty reports. | ||
| * | ||
| * @param params - Configuration object for the hook | ||
| * @param params.policyName - The display name of the policy/workspace | ||
| * @param params.onConfirm - Callback function to execute when user confirms report creation | ||
| * @returns An object containing: | ||
| * - openCreateReportConfirmation: Function to open the confirmation modal | ||
| * - CreateReportConfirmationModal: The confirmation modal React component to render | ||
| * | ||
| * @example | ||
| * const {openCreateReportConfirmation, CreateReportConfirmationModal} = useCreateEmptyReportConfirmation({ | ||
| * policyID: 'policy123', | ||
| * policyName: 'Engineering Team', | ||
| * onConfirm: handleCreateReport, | ||
| * }); | ||
| * | ||
| */ | ||
| export default function useCreateEmptyReportConfirmation({policyName, onConfirm, onCancel}: UseCreateEmptyReportConfirmationParams): UseCreateEmptyReportConfirmationResult { | ||
| const {translate} = useLocalize(); | ||
| const [isVisible, setIsVisible] = useState(false); | ||
|
|
||
| const workspaceDisplayName = useMemo(() => (policyName?.trim().length ? policyName : translate('report.newReport.genericWorkspaceName')), [policyName, translate]); | ||
|
|
||
| const handleConfirm = useCallback(() => { | ||
| onConfirm(); | ||
| setIsVisible(false); | ||
| }, [onConfirm]); | ||
|
|
||
| const handleCancel = useCallback(() => { | ||
| onCancel?.(); | ||
| setIsVisible(false); | ||
| }, [onCancel]); | ||
|
|
||
| const handleReportsLinkPress = useCallback(() => { | ||
| setIsVisible(false); | ||
| Navigation.navigate(ROUTES.SEARCH_ROOT.getRoute({query: buildCannedSearchQuery({groupBy: CONST.SEARCH.GROUP_BY.REPORTS})})); | ||
| }, []); | ||
|
|
||
| const openCreateReportConfirmation = useCallback(() => { | ||
| // The caller is responsible for determining if empty report confirmation | ||
| // should be shown. We simply open the modal when called. | ||
| setIsVisible(true); | ||
| }, []); | ||
|
|
||
| const prompt = useMemo( | ||
| () => ( | ||
| <Text> | ||
| {translate('report.newReport.emptyReportConfirmationPrompt', {workspaceName: workspaceDisplayName})}{' '} | ||
| <TextLink onPress={handleReportsLinkPress}>{translate('report.newReport.emptyReportConfirmationPromptLink')}.</TextLink> | ||
| </Text> | ||
| ), | ||
| [handleReportsLinkPress, translate, workspaceDisplayName], | ||
| ); | ||
|
|
||
| const CreateReportConfirmationModal = useMemo( | ||
| () => ( | ||
| <ConfirmModal | ||
| confirmText={translate('report.newReport.createReport')} | ||
| cancelText={translate('common.cancel')} | ||
| isVisible={isVisible} | ||
| onConfirm={handleConfirm} | ||
| onCancel={handleCancel} | ||
| prompt={prompt} | ||
| title={translate('report.newReport.emptyReportConfirmationTitle')} | ||
| /> | ||
| ), | ||
| [handleCancel, handleConfirm, isVisible, prompt, translate], | ||
| ); | ||
|
|
||
| return { | ||
| openCreateReportConfirmation, | ||
| CreateReportConfirmationModal, | ||
| }; | ||
| } |
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
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
Oops, something went wrong.
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.
Did we confirm this translation elsewhere?
And I thought we should also generate other transaction files right? Not only es and en.
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.
I think the other translations can be generated by a workflow which can be started by an internal eng.
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.
Added them.