-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[TS migration] Migrate 'FormAlertWithSubmitButton.js' component to TypeScript #31303
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
Changes from all commits
76bf131
afce2be
a14c893
5f60d3c
747cc21
fdb2b8a
feab7c5
3ff9bcf
d48e53b
7f17798
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| import React from 'react'; | ||
| import {StyleProp, View, ViewStyle} from 'react-native'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import Button from './Button'; | ||
| import FormAlertWrapper from './FormAlertWrapper'; | ||
|
|
||
| type FormAlertWithSubmitButtonProps = { | ||
| /** Error message to display above button */ | ||
| message?: string; | ||
|
|
||
| /** Whether the button is disabled */ | ||
| isDisabled?: boolean; | ||
|
|
||
| /** Whether message is in html format */ | ||
| isMessageHtml?: boolean; | ||
|
|
||
| /** Styles for container element */ | ||
| containerStyles?: StyleProp<ViewStyle>; | ||
|
|
||
| /** Is the button in a loading state */ | ||
| isLoading?: boolean; | ||
|
|
||
| /** Callback fired when the "fix the errors" link is pressed */ | ||
| onFixTheErrorsLinkPressed?: () => void; | ||
|
|
||
| /** Submit function */ | ||
| onSubmit: () => void; | ||
|
|
||
| /** Should the button be enabled when offline */ | ||
| enabledWhenOffline?: boolean; | ||
|
|
||
| /** Disable press on enter for submit button */ | ||
| disablePressOnEnter?: boolean; | ||
|
|
||
| /** Whether the form submit action is dangerous */ | ||
| isSubmitActionDangerous?: boolean; | ||
|
|
||
| /** Custom content to display in the footer after submit button */ | ||
| footerContent?: React.ReactNode; | ||
|
|
||
| /** Styles for the button */ | ||
| buttonStyles?: StyleProp<ViewStyle>; | ||
|
|
||
| /** Whether to show the alert text */ | ||
| isAlertVisible: boolean; | ||
|
|
||
| /** Text for the button */ | ||
| buttonText: string; | ||
|
|
||
| /** Whether to use a smaller submit button size */ | ||
| useSmallerSubmitButtonSize?: boolean; | ||
|
|
||
| /** Style for the error message for submit button */ | ||
| errorMessageStyle?: StyleProp<ViewStyle>; | ||
| }; | ||
|
|
||
| function FormAlertWithSubmitButton({ | ||
| message = '', | ||
| isDisabled = false, | ||
| isMessageHtml = false, | ||
| containerStyles, | ||
| isLoading = false, | ||
| onFixTheErrorsLinkPressed = () => {}, | ||
| enabledWhenOffline = false, | ||
| disablePressOnEnter = false, | ||
| isSubmitActionDangerous = false, | ||
| footerContent = null, | ||
| buttonStyles, | ||
|
kubabutkiewicz marked this conversation as resolved.
|
||
| buttonText, | ||
| isAlertVisible, | ||
| onSubmit, | ||
| useSmallerSubmitButtonSize = false, | ||
| errorMessageStyle, | ||
| }: FormAlertWithSubmitButtonProps) { | ||
| const styles = useThemeStyles(); | ||
| const style = [!footerContent ? {} : styles.mb3, buttonStyles]; | ||
|
kubabutkiewicz marked this conversation as resolved.
|
||
|
|
||
| return ( | ||
| <FormAlertWrapper | ||
| containerStyles={[styles.mh5, styles.mb5, styles.justifyContentEnd, containerStyles]} | ||
|
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. If
Contributor
Author
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. @pac-guerreiro It will work, look at screenshots
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. The style props are able to handle nested arrays 🙂
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. Nvm then @kubabutkiewicz @fabioh8010, I had the idea that we could not pass nested arrays like that
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.
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.
@rlinoz, eh, I think you are right. However, on main branch, |
||
| isAlertVisible={isAlertVisible} | ||
| isMessageHtml={isMessageHtml} | ||
| message={message} | ||
| onFixTheErrorsLinkPressed={onFixTheErrorsLinkPressed} | ||
| errorMessageStyle={errorMessageStyle} | ||
| > | ||
| {(isOffline: boolean | undefined) => ( | ||
| <View> | ||
| {isOffline && !enabledWhenOffline ? ( | ||
|
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. I know that this is out of scope with this PR purpose but there's code duplication in this ternary and should be addressed
Contributor
Author
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. I see your point but during TS migration we should not do refactors which are not related to migration, maybe you can create a seperate issue for that? |
||
| <Button | ||
| success | ||
| isDisabled | ||
| text={buttonText} | ||
| style={style} | ||
| danger={isSubmitActionDangerous} | ||
| medium={useSmallerSubmitButtonSize} | ||
| /> | ||
| ) : ( | ||
| <Button | ||
| success | ||
| pressOnEnter={!disablePressOnEnter} | ||
| text={buttonText} | ||
| style={style} | ||
| onPress={onSubmit} | ||
| isDisabled={isDisabled} | ||
| isLoading={isLoading} | ||
| danger={isSubmitActionDangerous} | ||
| medium={useSmallerSubmitButtonSize} | ||
| /> | ||
| )} | ||
| {footerContent} | ||
| </View> | ||
| )} | ||
| </FormAlertWrapper> | ||
| ); | ||
| } | ||
|
|
||
| FormAlertWithSubmitButton.displayName = 'FormAlertWithSubmitButton'; | ||
|
|
||
| export default FormAlertWithSubmitButton; | ||



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.
Careful, this prop used to default to array
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.
@pac-guerreiro we agreed earlier that styles props don't need default values here is a conversation
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.
@kubabutkiewicz Oh okay, maybe that discussion should be added to the TS guidelines, what you think @fabioh8010 ?