Repository navigation
[TS migration] Migrate 'ConfirmContent.js' component to TypeScript #31699
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
mountiny
merged 12 commits into
Expensify:main
from
fvlvte:25047-migrate-confirmContent
Dec 27, 2023
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ee63ef7
Migrated ConfirmContent to typescript.
fvlvte bf68853
Merge branch 'main' into 25047-migrate-confirmContent
fvlvte c3e34ef
Merge branch 'main' into 25047-migrate-confirmContent
fvlvte e093a4d
Aligned to main.
fvlvte b1e1fda
Review comments resolved.
fvlvte e393892
Merge branch 'main' into 25047-migrate-confirmContent
fvlvte 4b7c67f
Review comments resolved.
fvlvte ef8a3c9
Merge branch 'main' into 25047-migrate-confirmContent
fvlvte 0919f91
Conflicts resolved.
fvlvte a045dfa
Merge branch 'main' into 25047-migrate-confirmContent
fvlvte d1daf2b
Merge branch 'main' into 25047-migrate-confirmContent
fvlvte 9d85314
Applied changes from main.
fvlvte 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 was deleted.
Oops, something went wrong.
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,163 @@ | ||
| import React, {ReactNode} from 'react'; | ||
| import {StyleProp, TextStyle, View, ViewStyle} from 'react-native'; | ||
| import useLocalize from '@hooks/useLocalize'; | ||
| import useNetwork from '@hooks/useNetwork'; | ||
| import useTheme from '@hooks/useTheme'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import variables from '@styles/variables'; | ||
| import IconAsset from '@src/types/utils/IconAsset'; | ||
| import Button from './Button'; | ||
| import Header from './Header'; | ||
| import Icon from './Icon'; | ||
| import Text from './Text'; | ||
|
|
||
| type ConfirmContentProps = { | ||
| /** Title of the modal */ | ||
| title: string; | ||
|
|
||
| /** A callback to call when the form has been submitted */ | ||
| onConfirm: () => void; | ||
|
|
||
| /** A callback to call when the form has been closed */ | ||
| onCancel?: () => void; | ||
|
|
||
| /** Confirm button text */ | ||
| confirmText?: string; | ||
|
|
||
| /** Cancel button text */ | ||
| cancelText?: string; | ||
|
|
||
| /** Modal content text/element */ | ||
| prompt?: string | ReactNode; | ||
|
|
||
| /** Whether we should use the success button color */ | ||
| success?: boolean; | ||
|
|
||
| /** Whether we should use the danger button color. Use if the action is destructive */ | ||
| danger?: boolean; | ||
|
|
||
| /** Whether we should disable the confirm button when offline */ | ||
| shouldDisableConfirmButtonWhenOffline?: boolean; | ||
|
|
||
| /** Whether we should show the cancel button */ | ||
| shouldShowCancelButton?: boolean; | ||
|
|
||
| /** Icon to display above the title */ | ||
| iconSource?: IconAsset; | ||
|
|
||
| /** Whether to center the icon / text content */ | ||
| shouldCenterContent?: boolean; | ||
|
|
||
| /** Whether to stack the buttons */ | ||
| shouldStackButtons?: boolean; | ||
|
|
||
| /** Styles for title */ | ||
| titleStyles?: StyleProp<TextStyle>; | ||
|
|
||
| /** Styles for prompt */ | ||
| promptStyles?: StyleProp<TextStyle>; | ||
|
|
||
| /** Styles for view */ | ||
| contentStyles?: StyleProp<ViewStyle>; | ||
|
|
||
| /** Styles for icon */ | ||
| iconAdditionalStyles?: StyleProp<ViewStyle>; | ||
| }; | ||
|
|
||
| function ConfirmContent({ | ||
| title, | ||
| onConfirm, | ||
| onCancel = () => {}, | ||
| confirmText = '', | ||
| cancelText = '', | ||
| prompt = '', | ||
| success = true, | ||
| danger = false, | ||
| shouldDisableConfirmButtonWhenOffline = false, | ||
| shouldShowCancelButton = false, | ||
| iconSource, | ||
| shouldCenterContent = false, | ||
| shouldStackButtons = true, | ||
| titleStyles, | ||
| promptStyles, | ||
| contentStyles, | ||
| iconAdditionalStyles, | ||
| }: ConfirmContentProps) { | ||
| const styles = useThemeStyles(); | ||
| const {translate} = useLocalize(); | ||
| const theme = useTheme(); | ||
| const {isOffline} = useNetwork(); | ||
|
|
||
| const isCentered = shouldCenterContent; | ||
|
|
||
| return ( | ||
| <View style={[styles.m5, contentStyles]}> | ||
| <View style={isCentered ? [styles.alignItemsCenter, styles.mb6] : []}> | ||
| {typeof iconSource === 'function' && ( | ||
| <View style={[styles.flexRow, styles.mb3]}> | ||
| <Icon | ||
| src={iconSource} | ||
| fill={theme.icon} | ||
| width={variables.appModalAppIconSize} | ||
| height={variables.appModalAppIconSize} | ||
| additionalStyles={iconAdditionalStyles} | ||
| /> | ||
| </View> | ||
| )} | ||
| <View style={[styles.flexRow, isCentered ? {} : styles.mb4]}> | ||
| <Header | ||
| title={title} | ||
| textStyles={titleStyles} | ||
| /> | ||
| </View> | ||
| {typeof prompt === 'string' ? <Text style={[promptStyles, isCentered ? styles.textAlignCenter : {}]}>{prompt}</Text> : prompt} | ||
|
fvlvte marked this conversation as resolved.
|
||
| </View> | ||
|
|
||
| {shouldStackButtons ? ( | ||
| <> | ||
| <Button | ||
| success={success} | ||
| danger={danger} | ||
| style={[styles.mt4]} | ||
| onPress={onConfirm} | ||
| pressOnEnter | ||
| text={confirmText || translate('common.yes')} | ||
| isDisabled={isOffline && shouldDisableConfirmButtonWhenOffline} | ||
| /> | ||
| {shouldShowCancelButton && ( | ||
| <Button | ||
| style={[styles.mt3, styles.noSelect]} | ||
| onPress={onCancel} | ||
| text={cancelText || translate('common.no')} | ||
| /> | ||
| )} | ||
| </> | ||
| ) : ( | ||
| <View style={[styles.flexRow, styles.gap4]}> | ||
| {shouldShowCancelButton && ( | ||
| <Button | ||
| style={[styles.noSelect, styles.flex1]} | ||
| onPress={onCancel} | ||
| text={cancelText || translate('common.no')} | ||
| medium | ||
| /> | ||
| )} | ||
| <Button | ||
| success={success} | ||
| danger={danger} | ||
| style={[styles.flex1]} | ||
| onPress={onConfirm} | ||
| pressOnEnter | ||
| text={confirmText || translate('common.yes')} | ||
| isDisabled={isOffline && shouldDisableConfirmButtonWhenOffline} | ||
| medium | ||
| /> | ||
| </View> | ||
| )} | ||
| </View> | ||
| ); | ||
| } | ||
|
|
||
| ConfirmContent.displayName = 'ConfirmContent'; | ||
|
|
||
| export default ConfirmContent; | ||
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.
Uh oh!
There was an error while loading. Please reload this page.