-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Migrate to new decision modal #80629
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
Draft
sumo-slonik
wants to merge
2
commits into
Expensify:main
Choose a base branch
from
software-mansion-labs:migrate/kuba-nowakowski/migrate_decision_modal
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 |
|---|---|---|
| @@ -1,80 +1,78 @@ | ||
| import type {ReactNode} from 'react'; | ||
| import React from 'react'; | ||
| import {View} from 'react-native'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import CONST from '@src/CONST'; | ||
| import Button from './Button'; | ||
| import Header from './Header'; | ||
| import Modal from './Modal'; | ||
| import Text from './Text'; | ||
| import RenderHTML from './RenderHTML'; | ||
|
|
||
| type DecisionModalProps = { | ||
| /** Title describing purpose of modal */ | ||
| title: string; | ||
|
|
||
| /** Modal subtitle/description */ | ||
| prompt?: string; | ||
|
|
||
| /** Text content used in first button */ | ||
| firstOptionText?: string; | ||
|
|
||
| /** Text content used in second button */ | ||
| secondOptionText: string; | ||
|
|
||
| /** onSubmit callback fired after clicking on first button */ | ||
| onFirstOptionSubmit?: () => void; | ||
|
|
||
| /** onSubmit callback fired after clicking on second button */ | ||
| onSecondOptionSubmit: () => void; | ||
| /** Modal content */ | ||
| children: ReactNode; | ||
|
|
||
| /** Is the window width narrow, like on a mobile device? */ | ||
| isSmallScreenWidth: boolean; | ||
|
|
||
| /** Whether modal is visible */ | ||
| isVisible: boolean; | ||
|
|
||
| /** Callback for closing modal */ | ||
| onClose: () => void; | ||
| }; | ||
|
|
||
| /** Whether modal is visible */ | ||
| isVisible: boolean; | ||
| type DecisionModalHeaderProps = { | ||
| /** Title describing purpose of modal */ | ||
| title: string; | ||
| }; | ||
|
|
||
| function DecisionModal({title, prompt = '', firstOptionText, secondOptionText, onFirstOptionSubmit, onSecondOptionSubmit, isSmallScreenWidth, onClose, isVisible}: DecisionModalProps) { | ||
| const styles = useThemeStyles(); | ||
| type DecisionModalContentProps = { | ||
| /** HTML content to render */ | ||
| html: string; | ||
| }; | ||
|
|
||
| type DecisionModalFooterProps = { | ||
| /** Footer content */ | ||
| children: ReactNode; | ||
| }; | ||
|
|
||
| function DecisionModal({children, isSmallScreenWidth, isVisible, onClose}: DecisionModalProps) { | ||
| const styles = useThemeStyles(); | ||
| return ( | ||
| <Modal | ||
| onClose={onClose} | ||
| isVisible={isVisible} | ||
| type={isSmallScreenWidth ? CONST.MODAL.MODAL_TYPE.BOTTOM_DOCKED : CONST.MODAL.MODAL_TYPE.CONFIRM} | ||
| innerContainerStyle={styles.pv0} | ||
| > | ||
| <View style={[styles.m5]}> | ||
| <View> | ||
| <View style={[styles.flexRow, styles.mb5]}> | ||
| <Header | ||
| title={title} | ||
| containerStyles={[styles.alignItemsCenter]} | ||
| /> | ||
| </View> | ||
| <Text>{prompt}</Text> | ||
| </View> | ||
| {!!firstOptionText && ( | ||
| <Button | ||
| success | ||
| style={[styles.mt5]} | ||
| onPress={onFirstOptionSubmit} | ||
| pressOnEnter | ||
| text={firstOptionText} | ||
| large | ||
| /> | ||
| )} | ||
| <Button | ||
| style={[firstOptionText ? styles.mt3 : styles.mt5, styles.noSelect]} | ||
| onPress={onSecondOptionSubmit} | ||
| text={secondOptionText} | ||
| large | ||
| /> | ||
| </View> | ||
| <View style={styles.m5}>{children}</View> | ||
| </Modal> | ||
| ); | ||
| } | ||
|
|
||
| function DecisionModalHeader({title}: DecisionModalHeaderProps) { | ||
| const styles = useThemeStyles(); | ||
| return ( | ||
| <View style={[styles.flexRow, styles.mb5]}> | ||
| <Header | ||
| title={title} | ||
| containerStyles={styles.alignItemsCenter} | ||
| /> | ||
| </View> | ||
| ); | ||
| } | ||
|
|
||
| function DecisionModalContent({html}: DecisionModalContentProps) { | ||
| return <RenderHTML html={html} />; | ||
| } | ||
|
|
||
| function DecisionModalFooter({children}: DecisionModalFooterProps) { | ||
| const styles = useThemeStyles(); | ||
| return <View style={styles.mt5}>{children}</View>; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
|
|
||
| DecisionModal.Header = DecisionModalHeader; | ||
| DecisionModal.Content = DecisionModalContent; | ||
| DecisionModal.Footer = DecisionModalFooter; | ||
|
|
||
| export default DecisionModal; | ||
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.
Why do we even need that? 🤔
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.
It's not used anywhere