Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 0 additions & 125 deletions src/components/FormAlertWithSubmitButton.js

This file was deleted.

120 changes: 120 additions & 0 deletions src/components/FormAlertWithSubmitButton.tsx
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,

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
Contributor

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 ?

isLoading = false,
onFixTheErrorsLinkPressed = () => {},
enabledWhenOffline = false,
disablePressOnEnter = false,
isSubmitActionDangerous = false,
footerContent = null,
buttonStyles,
Comment thread
kubabutkiewicz marked this conversation as resolved.
buttonText,
isAlertVisible,
onSubmit,
useSmallerSubmitButtonSize = false,
errorMessageStyle,
}: FormAlertWithSubmitButtonProps) {
const styles = useThemeStyles();
const style = [!footerContent ? {} : styles.mb3, buttonStyles];
Comment thread
kubabutkiewicz marked this conversation as resolved.

return (
<FormAlertWrapper
containerStyles={[styles.mh5, styles.mb5, styles.justifyContentEnd, containerStyles]}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If containerStyles is an array, it needs to be spread here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pac-guerreiro It will work, look at screenshots
image
image

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The style props are able to handle nested arrays 🙂

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry if I am being dumb, but I am seeing this console warning and I believe it is related to this change:
image

@ntdiary ntdiary Dec 16, 2023

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am seeing this console warning and I believe it is related to this change

@rlinoz, eh, I think you are right. However, on main branch, FormAlertWrapper has been migrated to tsx , so this error will not appear after merging, we can merge that to this branch to validate it first. :)

isAlertVisible={isAlertVisible}
isMessageHtml={isMessageHtml}
message={message}
onFixTheErrorsLinkPressed={onFixTheErrorsLinkPressed}
errorMessageStyle={errorMessageStyle}
>
{(isOffline: boolean | undefined) => (
<View>
{isOffline && !enabledWhenOffline ? (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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;