Merge pull request #15 from gustavo-em/capitalize

Capitalize
This commit is contained in:
Tiago Jacobs 2022-03-21 17:50:12 -03:00 committed by GitHub
commit 76ca2bb5e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 69 additions and 29 deletions

View File

@ -1,22 +1,42 @@
import React from 'react' import React from 'react';
import { LabelInput, WrapperInputText } from './styles'; import {LabelInput, WrapperInputText} from './styles';
type IInputText = { type IInputText = {
children?: object; children?: object;
placeholder: string; placeholder: string;
label: string; label: string;
onChangeText?: any, onChangeText?: any;
value?: any value?: any;
autoCapitalize?: "none" autoCapitalize?: 'none';
} autoCorrect?: false | true;
export const InputText = (props: IInputText)=>{ autoComplete?: 'off';
allowFontScaling?: true | false;
};
export const InputText = (props: IInputText) => {
const {
children,
placeholder,
label,
onChangeText,
value,
autoCapitalize,
autoCorrect,
autoComplete,
allowFontScaling,
} = props;
const {children, placeholder, label, onChangeText, value, autoCapitalize} = props return (
<>
return ( <LabelInput>{label}</LabelInput>
<> <WrapperInputText
<LabelInput>{props.label}</LabelInput> allowFontScaling={allowFontScaling}
<WrapperInputText autoCapitalize={props.autoCapitalize} value={props.value} onChangeText={props.onChangeText} placeholder={props.placeholder}></WrapperInputText> autoComplete={autoComplete}
</> autoCorrect={autoCorrect}
) autoCapitalize={autoCapitalize}
} value={value}
onChangeText={onChangeText}
placeholder={placeholder}
/>
</>
);
};

View File

@ -15,8 +15,8 @@ import {initTranslation} from '../../translations/index';
import i18next from 'i18next'; import i18next from 'i18next';
export const StorePortals = ({navigation, modalizeRef}: IStore) => { export const StorePortals = ({navigation, modalizeRef}: IStore) => {
initTranslation();; initTranslation();
const {portals, setPortals} = usePortal();; const {portals, setPortals} = usePortal();
const [name, setName] = React.useState(''); const [name, setName] = React.useState('');
const [url, setUrl] = React.useState(''); const [url, setUrl] = React.useState('');
const [emptyFields, setEmptyFields] = React.useState(false); const [emptyFields, setEmptyFields] = React.useState(false);
@ -26,20 +26,20 @@ export const StorePortals = ({navigation, modalizeRef}: IStore) => {
let portalsStorage; let portalsStorage;
portalsStorage = await AsyncStorage.getItem('portal'); portalsStorage = await AsyncStorage.getItem('portal');
portalsStorage = portalsStorage ? JSON.parse(portalsStorage) : null; portalsStorage = portalsStorage ? JSON.parse(portalsStorage) : null;
portalsStorage.push({name, url});; portalsStorage.push({name, url});
AsyncStorage.setItem('portal', JSON.stringify(portalsStorage));; AsyncStorage.setItem('portal', JSON.stringify(portalsStorage));
setPortals(portalsStorage);; setPortals(portalsStorage);
modalizeRef?.current?.close(); modalizeRef?.current?.close();
navigation.navigate(name);; navigation.navigate(name);
} }
async function onPress() { async function onPress() {
//return false; //return false;
if (!name || !url) return setEmptyFields(true);; if (!name || !url) return setEmptyFields(true);
try { try {
let portalsFilter = portals.filter( let portalsFilter = portals.filter(
(portal: {name: string; url: string}) => { (portal: {name: string; url: string}) => {
if (portal.name != name) return false;; if (portal.name != name) return false;
return portal; return portal;
}, },
); );
@ -73,6 +73,23 @@ export const StorePortals = ({navigation, modalizeRef}: IStore) => {
</> </>
);; );;
const textEmptyFields = () => (
<>
{emptyFields ? (
<TextEmptyFileds>
{i18next.t('mobileApp.portals.addPortalPopup.validation.emptyFilds')}
</TextEmptyFileds>
) : null}
{nameAlreadyUsed ? (
<TextEmptyFileds>
{i18next.t(
'mobileApp.portals.addPortalPopup.validation.portalNameAlreadyExists',
)}
</TextEmptyFileds>
) : null}
</>
);
return ( return (
<> <>
<WrapperStoreContainer> <WrapperStoreContainer>
@ -80,6 +97,8 @@ export const StorePortals = ({navigation, modalizeRef}: IStore) => {
{textEmptyFields()} {textEmptyFields()}
<WrapperInput> <WrapperInput>
<InputText <InputText
autoCapitalize={'none'}
autoCorrect={false}
value={name} value={name}
onChangeText={(e: any) => setName(e)} onChangeText={(e: any) => setName(e)}
placeholder={i18next.t( placeholder={i18next.t(
@ -90,7 +109,8 @@ export const StorePortals = ({navigation, modalizeRef}: IStore) => {
</WrapperInput> </WrapperInput>
<WrapperInput> <WrapperInput>
<InputText <InputText
autoCapitalize="none" autoCapitalize={'none'}
autoCorrect={false}
value={url} value={url}
onChangeText={(e: any) => setUrl(e)} onChangeText={(e: any) => setUrl(e)}
placeholder={i18next.t( placeholder={i18next.t(
@ -111,5 +131,5 @@ export const StorePortals = ({navigation, modalizeRef}: IStore) => {
</WrapperStore> </WrapperStore>
</WrapperStoreContainer> </WrapperStoreContainer>
</> </>
);; );
} }