Chore: Migrate containers: FormContainer to Typescript (#3922)

* Chore: Migrate containers: FormContainer to Typescript

* minor tweak

* theme fix

* fix react.reactelement[]

* minor tweak

Co-authored-by: Gleidson Daniel Silva <gleidson10daniel@hotmail.com>
This commit is contained in:
Reinaldo Neto 2022-03-25 14:55:20 -03:00 committed by GitHub
parent 6418803517
commit 744712b8d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 80 additions and 72 deletions

View File

@ -5,15 +5,15 @@ import { themes } from '../constants/colors';
import sharedStyles from '../views/Styles'; import sharedStyles from '../views/Styles';
import scrollPersistTaps from '../utils/scrollPersistTaps'; import scrollPersistTaps from '../utils/scrollPersistTaps';
import KeyboardView from '../presentation/KeyboardView'; import KeyboardView from '../presentation/KeyboardView';
import { useTheme } from '../theme';
import StatusBar from './StatusBar'; import StatusBar from './StatusBar';
import AppVersion from './AppVersion'; import AppVersion from './AppVersion';
import { isTablet } from '../utils/deviceInfo'; import { isTablet } from '../utils/deviceInfo';
import SafeAreaView from './SafeAreaView'; import SafeAreaView from './SafeAreaView';
interface IFormContainer extends ScrollViewProps { interface IFormContainer extends ScrollViewProps {
theme: string;
testID: string; testID: string;
children: React.ReactNode; children: React.ReactElement | React.ReactElement[] | null;
} }
const styles = StyleSheet.create({ const styles = StyleSheet.create({
@ -22,11 +22,14 @@ const styles = StyleSheet.create({
} }
}); });
export const FormContainerInner = ({ children }: { children: React.ReactNode }): JSX.Element => ( export const FormContainerInner = ({ children }: { children: (React.ReactElement | null)[] }) => (
<View style={[sharedStyles.container, isTablet && sharedStyles.tabletScreenContent]}>{children}</View> <View style={[sharedStyles.container, isTablet && sharedStyles.tabletScreenContent]}>{children}</View>
); );
const FormContainer = ({ children, theme, testID, ...props }: IFormContainer): JSX.Element => ( const FormContainer = ({ children, testID, ...props }: IFormContainer) => {
const { theme } = useTheme();
return (
<KeyboardView <KeyboardView
style={{ backgroundColor: themes[theme].backgroundColor }} style={{ backgroundColor: themes[theme].backgroundColor }}
contentContainerStyle={sharedStyles.container} contentContainerStyle={sharedStyles.container}
@ -43,6 +46,7 @@ const FormContainer = ({ children, theme, testID, ...props }: IFormContainer): J
</SafeAreaView> </SafeAreaView>
</ScrollView> </ScrollView>
</KeyboardView> </KeyboardView>
); );
};
export default FormContainer; export default FormContainer;

View File

@ -92,7 +92,7 @@ class ForgotPasswordView extends React.Component<IForgotPasswordViewProps, IForg
const { theme } = this.props; const { theme } = this.props;
return ( return (
<FormContainer theme={theme} testID='forgot-password-view'> <FormContainer testID='forgot-password-view'>
<FormContainerInner> <FormContainerInner>
<Text style={[sharedStyles.loginTitle, sharedStyles.textBold, { color: themes[theme].titleText }]}> <Text style={[sharedStyles.loginTitle, sharedStyles.textBold, { color: themes[theme].titleText }]}>
{I18n.t('Forgot_password')} {I18n.t('Forgot_password')}

View File

@ -229,7 +229,7 @@ class LoginView extends React.Component<ILoginViewProps, any> {
render() { render() {
const { Accounts_ShowFormLogin, theme, navigation } = this.props; const { Accounts_ShowFormLogin, theme, navigation } = this.props;
return ( return (
<FormContainer theme={theme} testID='login-view'> <FormContainer testID='login-view'>
<FormContainerInner> <FormContainerInner>
<LoginServices separator={Accounts_ShowFormLogin} navigation={navigation} theme={theme} /> <LoginServices separator={Accounts_ShowFormLogin} navigation={navigation} theme={theme} />
{this.renderUserForm()} {this.renderUserForm()}

View File

@ -321,7 +321,7 @@ class NewServerView extends React.Component<INewServerViewProps, INewServerViewS
const marginTop = previousServer ? 0 : 35; const marginTop = previousServer ? 0 : 35;
return ( return (
<FormContainer theme={theme} testID='new-server-view' keyboardShouldPersistTaps='never'> <FormContainer testID='new-server-view' keyboardShouldPersistTaps='never'>
<FormContainerInner> <FormContainerInner>
<Image <Image
style={[ style={[

View File

@ -172,7 +172,9 @@ class RegisterView extends React.Component<IProps, any> {
return null; return null;
} }
try { try {
return Object.keys(this.parsedCustomFields).map((key, index, array) => { return (
<>
{Object.keys(this.parsedCustomFields).map((key, index, array) => {
if (this.parsedCustomFields[key].type === 'select') { if (this.parsedCustomFields[key].type === 'select') {
const options = this.parsedCustomFields[key].options.map((option: string) => ({ label: option, value: option })); const options = this.parsedCustomFields[key].options.map((option: string) => ({ label: option, value: option }));
return ( return (
@ -186,7 +188,7 @@ class RegisterView extends React.Component<IProps, any> {
}} }}
value={customFields[key]}> value={customFields[key]}>
<TextInput <TextInput
inputRef={e => { inputRef={(e: any) => {
// @ts-ignore // @ts-ignore
this[key] = e; this[key] = e;
}} }}
@ -201,7 +203,7 @@ class RegisterView extends React.Component<IProps, any> {
return ( return (
<TextInput <TextInput
inputRef={(e: any) => { inputRef={e => {
// @ts-ignore // @ts-ignore
this[key] = e; this[key] = e;
}} }}
@ -225,7 +227,9 @@ class RegisterView extends React.Component<IProps, any> {
theme={theme} theme={theme}
/> />
); );
}); })}
</>
);
} catch (error) { } catch (error) {
return null; return null;
} }
@ -235,7 +239,7 @@ class RegisterView extends React.Component<IProps, any> {
const { saving } = this.state; const { saving } = this.state;
const { theme, showLoginButton, navigation } = this.props; const { theme, showLoginButton, navigation } = this.props;
return ( return (
<FormContainer theme={theme} testID='register-view'> <FormContainer testID='register-view'>
<FormContainerInner> <FormContainerInner>
<LoginServices navigation={navigation} theme={theme} separator /> <LoginServices navigation={navigation} theme={theme} separator />
<Text style={[styles.title, sharedStyles.textBold, { color: themes[theme].titleText }]}>{I18n.t('Sign_Up')}</Text> <Text style={[styles.title, sharedStyles.textBold, { color: themes[theme].titleText }]}>{I18n.t('Sign_Up')}</Text>

View File

@ -62,7 +62,7 @@ const SendEmailConfirmationView = ({ navigation, route }: ISendEmailConfirmation
}, []); }, []);
return ( return (
<FormContainer theme={theme} testID='send-email-confirmation-view'> <FormContainer testID='send-email-confirmation-view'>
<FormContainerInner> <FormContainerInner>
<TextInput <TextInput
autoFocus autoFocus

View File

@ -74,7 +74,7 @@ class WorkspaceView extends React.Component<IWorkSpaceProp, any> {
const { theme, Site_Name, Site_Url, Assets_favicon_512, server, showLoginButton } = this.props; const { theme, Site_Name, Site_Url, Assets_favicon_512, server, showLoginButton } = this.props;
return ( return (
<FormContainer theme={theme} testID='workspace-view'> <FormContainer testID='workspace-view'>
<FormContainerInner> <FormContainerInner>
<View style={styles.alignItemsCenter}> <View style={styles.alignItemsCenter}>
<ServerAvatar theme={theme} url={server} image={Assets_favicon_512?.url ?? Assets_favicon_512?.defaultUrl} /> <ServerAvatar theme={theme} url={server} image={Assets_favicon_512?.url ?? Assets_favicon_512?.defaultUrl} />