diff --git a/phone/src/apps/contacts/components/views/ContactInfo.tsx b/phone/src/apps/contacts/components/views/ContactInfo.tsx index 2b30cd0..f6f2beb 100644 --- a/phone/src/apps/contacts/components/views/ContactInfo.tsx +++ b/phone/src/apps/contacts/components/views/ContactInfo.tsx @@ -7,7 +7,7 @@ import { useContactActions } from '../../hooks/useContactActions'; import ArrowBackIcon from '@material-ui/icons/ArrowBack'; import LogDebugEvent from '../../../../os/debug/LogDebugEvents'; import { useQueryParams } from '../../../../common/hooks/useQueryParams'; -import { Contact, ContactEvents } from '../../../../../../typings/contact'; +import { Contact, ContactEvents, ContactsDatabaseLimits } from '../../../../../../typings/contact'; import { TextField } from '../../../../ui/components/Input'; import { fetchNui } from '../../../../utils/fetchNui'; import { ServerPromiseResp } from '../../../../../../typings/common'; @@ -72,6 +72,24 @@ const ContactsInfoPage = () => { const { t } = useTranslation(); + const handleNumberChange: React.ChangeEventHandler = (e) => { + const inputVal = e.target.value; + if (inputVal.length === ContactsDatabaseLimits.number) return; + setNumber(e.target.value); + }; + + const handleDisplayChange: React.ChangeEventHandler = (e) => { + const inputVal = e.target.value; + if (inputVal.length === ContactsDatabaseLimits.display) return; + setName(e.target.value); + }; + + const handleAvatarChange: React.ChangeEventHandler = (e) => { + const inputVal = e.target.value; + if (inputVal.length === ContactsDatabaseLimits.avatar) return; + setAvatar(e.target.value); + }; + useEffect(() => { if (addNumber) { setNumber(addNumber); @@ -173,9 +191,10 @@ const ContactsInfoPage = () => { setName(e.target.value)} + onChange={handleDisplayChange} label={t('APPS_CONTACT_FORM_NAME')} fullWidth inputProps={{ @@ -184,8 +203,8 @@ const ContactsInfoPage = () => { /> setNumber(e.target.value)} + value={number.length === ContactsDatabaseLimits.number} + onChange={handleNumberChange} label={t('APPS_CONTACT_FORM_NUMBER')} fullWidth inputProps={{ @@ -193,11 +212,12 @@ const ContactsInfoPage = () => { }} /> setAvatar(e.target.value)} + onChange={handleAvatarChange} inputProps={{ className: classes.inputProps, }} diff --git a/phone/src/ui/components/Input.tsx b/phone/src/ui/components/Input.tsx index 087d4ca..86e56c1 100644 --- a/phone/src/ui/components/Input.tsx +++ b/phone/src/ui/components/Input.tsx @@ -1,8 +1,9 @@ import React, { useCallback } from 'react'; import MUITextField from '@material-ui/core/TextField'; -import MUIInputBase from '@material-ui/core/InputBase'; +import MUIInputBase, { InputBaseProps } from '@material-ui/core/InputBase'; import { useNuiRequest } from 'fivem-nui-react-lib'; import { PhoneEvents } from '../../../../typings/phone'; +import { TextFieldProps } from '@material-ui/core/TextField/TextField'; const useToggleFocus = () => { const Nui = useNuiRequest(); @@ -16,7 +17,7 @@ const useToggleFocus = () => { ); }; -export const TextField = (props) => { +export const TextField: React.FC = (props) => { const toggleKeys = useToggleFocus(); return ( { ); }; -export const InputBase = (props) => { +export const InputBase: React.FC = (props) => { const toggleKeys = useToggleFocus(); return (