diff --git a/src/components/FormAlertWithSubmitButton.js b/src/components/FormAlertWithSubmitButton.js new file mode 100644 index 000000000000..b85c77486740 --- /dev/null +++ b/src/components/FormAlertWithSubmitButton.js @@ -0,0 +1,101 @@ +import _ from 'underscore'; +import React from 'react'; +import {View} from 'react-native'; +import PropTypes from 'prop-types'; +import styles from '../styles/styles'; +import Icon from './Icon'; +import {Exclamation} from './Icon/Expensicons'; +import colors from '../styles/colors'; +import Button from './Button'; +import withLocalize, {withLocalizePropTypes} from './withLocalize'; +import TextLink from './TextLink'; +import Text from './Text'; + +const propTypes = { + /** Whether to show the alert text */ + isAlertVisible: PropTypes.bool.isRequired, + + /** Submit function */ + onSubmit: PropTypes.func.isRequired, + + /** Text for the button */ + buttonText: PropTypes.string.isRequired, + + /** Callback fired when the "fix the errors" link is pressed */ + onFixTheErrorsLinkPressed: PropTypes.func.isRequired, + + /** Error message to display above button */ + message: PropTypes.string, + + ...withLocalizePropTypes, +}; + +const defaultProps = { + message: '', +}; + +const FormAlertWithSubmitButton = ({ + isAlertVisible, + onSubmit, + buttonText, + translate, + onFixTheErrorsLinkPressed, + message, +}) => { + /** + * @returns {React.Component} + */ + function getAlertPrompt() { + let error = ''; + + if (!_.isEmpty(message)) { + error = ( + {message} + ); + } else { + error = ( + <> + + {`${translate('common.please')} `} + + + {translate('common.fixTheErrors')} + + + {` ${translate('common.inTheFormBeforeContinuing')}.`} + + + ); + } + + return ( + + {error} + + ); + } + + return ( + + {isAlertVisible && ( + + + {getAlertPrompt()} + + )} +